libbinder_ndk: Expose UTF-8 interface descriptor string

We want to be able to expose the original char* interface descriptor
string from AIBinder_Class to NDK clients. Rather than converting the
String16 representation, which presents difficulties regarding
allocation cleanup, we just store an extra copy of the string for now.

Eventually, we would like to transition interface descriptors to UTF-8
and avoid String16 entirely, so this change is a partial step in that
direction and avoids exposing a UTF-16 string through the NDK API.

Bug: 167723746
Test: atest libbinder_ndk_unit_test CtsBinderNdkTestCases
Change-Id: I79d11f26245e229acde753f8c76c53cd0970c8ed
diff --git a/libs/binder/ndk/ibinder_internal.h b/libs/binder/ndk/ibinder_internal.h
index 6236e81..6824306 100644
--- a/libs/binder/ndk/ibinder_internal.h
+++ b/libs/binder/ndk/ibinder_internal.h
@@ -112,7 +112,8 @@
     AIBinder_Class(const char* interfaceDescriptor, AIBinder_Class_onCreate onCreate,
                    AIBinder_Class_onDestroy onDestroy, AIBinder_Class_onTransact onTransact);
 
-    const ::android::String16& getInterfaceDescriptor() const { return mInterfaceDescriptor; }
+    const ::android::String16& getInterfaceDescriptor() const { return mWideInterfaceDescriptor; }
+    const char* getInterfaceDescriptorUtf8() const { return mInterfaceDescriptor.c_str(); }
 
     // required to be non-null, implemented for every class
     const AIBinder_Class_onCreate onCreate = nullptr;
@@ -124,9 +125,11 @@
     AIBinder_handleShellCommand handleShellCommand = nullptr;
 
    private:
+    // Copy of the raw char string for when we don't have to return UTF-16
+    const std::string mInterfaceDescriptor;
     // This must be a String16 since BBinder virtual getInterfaceDescriptor returns a reference to
     // one.
-    const ::android::String16 mInterfaceDescriptor;
+    const ::android::String16 mWideInterfaceDescriptor;
 };
 
 // Ownership is like this (when linked to death):