[automerger skipped] DO NOT MERGE - Merge pie-platform-release (PPRL.190801.002) into master
am: 089be984e1 -s ours
am skip reason: subject contains skip directive

Change-Id: I987141372f384074445bc4671458407861ceb080
diff --git a/Android.bp b/Android.bp
index 47b3b3f..69e52d7 100644
--- a/Android.bp
+++ b/Android.bp
@@ -14,27 +14,10 @@
 
 cc_defaults {
     name: "libhwbinder_defaults",
-    shared_libs: [
-        "libbase",
-        "liblog",
-        "libcutils",
-        "libutils",
-        "libbinderthreadstate",
-    ],
-    export_shared_lib_headers: [
-        "libbase",
-        "libutils",
-    ],
+
     export_include_dirs: ["include"],
     include_dirs: ["frameworks/native/include"],
 
-    recovery_available: true,
-    vendor_available: true,
-    vndk: {
-        enabled: true,
-        support_system_process: true,
-    },
-    clang: true,
     sanitize: {
         misc_undefined: ["integer"],
     },
@@ -63,22 +46,87 @@
     ],
 }
 
+cc_defaults {
+    name: "libhwbinder-impl-shared-libs",
+    defaults: ["libhwbinder-impl-shared-libs-no-vndk-private"],
+    shared_libs: [
+        "libbinderthreadstate",
+    ],
+}
+
+cc_defaults {
+    name: "libhwbinder-impl-shared-libs-no-vndk-private",
+    shared_libs: [
+        "libbase",
+        "liblog",
+        "libcutils",
+        "libutils",
+    ],
+    export_shared_lib_headers: [
+        "libbase",
+        "libutils",
+    ],
+}
+
+// WARNING: this should no longer be used
 cc_library {
     name: "libhwbinder",
+    recovery_available: true,
+    vendor_available: true,
+    vndk: {
+        enabled: true,
+        support_system_process: true,
+    },
+
+    export_include_dirs: ["include"],
+}
+
+// Combined into libhidlbase for efficiency.
+// Used as shared library to provide headers for libhidltransport-impl-internal.
+cc_library_static {
+    name: "libhwbinder-impl-internal",
+    // TODO(b/135299443): allow this library to link against vndk-private libs
+    // and instead rely on the fact that users of this static library must be
+    // vndk (since they must use libbinderthreadstate).
+    include_dirs: ["frameworks/native/libs/binderthreadstate/include/"],
     defaults: [
         "libhwbinder_defaults",
+        "libhwbinder-impl-shared-libs-no-vndk-private",
         "hwbinder_pgo",
         "hwbinder_lto",
     ],
+    recovery_available: true,
+    vendor_available: true,
 }
 
 // Explicitly provide a no lto, no PGO variant, to workaround the issue that we
 // can't detect non-lto users of the module in Android.mk.
-// http://b/77320844
+// TODO(b/135558503): remove
 cc_library {
     name: "libhwbinder_noltopgo",
     defaults: [
         "libhwbinder_defaults",
+        "libhwbinder-impl-shared-libs",
+    ],
+    recovery_available: true,
+    vendor_available: true,
+    vndk: {
+        enabled: true,
+        support_system_process: true,
+    },
+}
+
+// Only libhwbinder_benchmark needs to have pgo enabled. When all places
+// support having PGO selectively enabled, all places can use libhwbinder.
+//
+// http://b/77320844
+cc_library_static {
+    name: "libhwbinder_pgo-impl-internal",
+    defaults: [
+        "libhwbinder_defaults",
+        "libhwbinder-impl-shared-libs",
+        "hwbinder_benchmark_pgo",
+        "hwbinder_lto",
     ],
 }
 
@@ -93,6 +141,16 @@
     },
 }
 
+cc_defaults {
+    name: "hwbinder_benchmark_pgo",
+    pgo: {
+        instrumentation: true,
+        profile_file: "hwbinder/hwbinder.profdata",
+        benchmarks: ["hwbinder_benchmark"],
+        enable_profile_use: true,
+    },
+}
+
 // Provide lto property to build hwbinder with LTO
 cc_defaults {
     name: "hwbinder_lto",
diff --git a/Binder.cpp b/Binder.cpp
index 72884f0..87bc143 100644
--- a/Binder.cpp
+++ b/Binder.cpp
@@ -102,7 +102,7 @@
         if (!e) return; // out of memory
     }
 
-    e->mRequestingSid = true;
+    e->mRequestingSid = requestingSid;
 }
 
 status_t BHwBinder::transact(
diff --git a/Parcel.cpp b/Parcel.cpp
index 1e556fa..33d841e 100644
--- a/Parcel.cpp
+++ b/Parcel.cpp
@@ -376,11 +376,11 @@
 bool Parcel::enforceInterface(const char* interface) const
 {
     const char* str = readCString();
-    if (strcmp(str, interface) == 0) {
+    if (str != nullptr && strcmp(str, interface) == 0) {
         return true;
     } else {
         ALOGW("**** enforceInterface() expected '%s' but read '%s'",
-                String8(interface).string(), String8(str).string());
+                interface, (str ? str : "<empty string>"));
         return false;
     }
 }
diff --git a/vts/performance/Android.bp b/vts/performance/Android.bp
index c6b74cf..675d157 100644
--- a/vts/performance/Android.bp
+++ b/vts/performance/Android.bp
@@ -22,9 +22,7 @@
         "-Werror",
     ],
     shared_libs: [
-        "libhidlbase",
-        "libhidltransport",
-        "libhwbinder",
+        "libhidlbase_pgo",
         "liblog",
         "libutils",
         "libcutils",