Initial C library for libbinder.

This creates a simple wrapper around libbinder with a stable C ABI. It
also embeds the concept of an IBinder and IBinder transactions into the
ABI so that parts of their transactions can be changed and considered
implementation details of libbinder. With this basic class, you can
create a service, use it with primitive data types, but it does not yet
suppport the entire range of binder objects.

Follow-up items to handle/things still to consider
- b/112664205: make aidl-gen produce interfaces that use these (and
    think about interoperation with existing interfaces).
- using onServiceConnected/onServiceDisconnected in the NDK
- if libbinder/libbinder_ndk classes use the same descriptor, there will
  be problems in the same process (libbinder{_ndk} assumes binder class)
- sometimes getService takes 1s since there is a race for it getting
  registered
- add generic class which allows for easy implementation of a class like
  IFoo in this test.
- Parcel for additional types (and additional APIs, like data available)
- addition of APIs like AIBinder_ping/linkToDeath which all binders have
- embed Status into this API layer (so EX_HAS_REPLY_HEADER is handled)
- make remoteBinder/localBinder is const (and therefore isRemote)
- okay with associateClass or should just use interfaceDescriptor
- potentially changing out incStrong/decStrong
- adding @file/@addtogroup to comments

Bug: 111445392
Test: ndk/runtests.sh

Change-Id: Ifbca8f0fdf70a3213fe0d94320fc31eeb62408c4
diff --git a/libs/binder/ndk/AServiceManager.cpp b/libs/binder/ndk/AServiceManager.cpp
new file mode 100644
index 0000000..f61b914
--- /dev/null
+++ b/libs/binder/ndk/AServiceManager.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <android/binder_manager.h>
+#include "AIBinder_internal.h"
+
+#include <binder/IServiceManager.h>
+
+using ::android::defaultServiceManager;
+using ::android::IBinder;
+using ::android::IServiceManager;
+using ::android::sp;
+using ::android::String16;
+
+binder_status_t AServiceManager_addService(AIBinder* binder, const char* instance) {
+    if (binder == nullptr || instance == nullptr) {
+        return EX_NULL_POINTER;
+    }
+
+    sp<IServiceManager> sm = defaultServiceManager();
+    return sm->addService(String16(instance), binder->getBinder());
+}
+AIBinder* AServiceManager_getService(const char* instance) {
+    if (instance == nullptr) {
+        return nullptr;
+    }
+
+    sp<IServiceManager> sm = defaultServiceManager();
+    sp<IBinder> binder = sm->getService(String16(instance));
+
+    AIBinder* ret = new ABpBinder(binder);
+    AIBinder_incStrong(ret);
+    return ret;
+}