Snap for 8730993 from 141103d189a92ffe72038f0c7b5dc7b22e91bdd2 to mainline-tzdata3-release

Change-Id: Idb0bf65006254f4495202949ad14d4e705931855
diff --git a/Android.bp b/Android.bp
index 1ca91b3..6f2869c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -121,6 +121,7 @@
     defaults: [
         "libhwbinder_defaults",
         "libhwbinder-impl-shared-libs",
+        "hwbinder_pgo",
         "hwbinder_lto",
     ],
     host_supported: true,
@@ -132,7 +133,7 @@
     apex_available: [
         "//apex_available:platform",
         "com.android.neuralnetworks",
-        "com.android.bluetooth",
+        "com.android.bluetooth.updatable",
         "com.android.media",
         "com.android.media.swcodec",
         "com.android.tethering",
@@ -140,6 +141,41 @@
     min_sdk_version: "29",
 }
 
+// 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",
+    ],
+}
+
+// Provide pgo property to build hwbinder with PGO
+cc_defaults {
+    name: "hwbinder_pgo",
+    pgo: {
+        instrumentation: true,
+        profile_file: "hwbinder/hwbinder.profdata",
+        benchmarks: ["hwbinder"],
+        enable_profile_use: true,
+    },
+}
+
+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 6d26414..b90639f 100644
--- a/Binder.cpp
+++ b/Binder.cpp
@@ -129,12 +129,20 @@
         }
     }
 
-    return onTransact(code, data, reply, flags, [&](auto& replyParcel) {
-      replyParcel.setDataPosition(0);
-      if (callback != nullptr) {
-        callback(replyParcel);
-      }
-    });
+    status_t err = NO_ERROR;
+    switch (code) {
+        default:
+            err = onTransact(code, data, reply, flags,
+                    [&](auto &replyParcel) {
+                        replyParcel.setDataPosition(0);
+                        if (callback != nullptr) {
+                            callback(replyParcel);
+                        }
+                    });
+            break;
+    }
+
+    return err;
 }
 
 status_t BHwBinder::linkToDeath(
diff --git a/OWNERS b/OWNERS
index 46996a2..dc0f56c 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,4 +1,5 @@
 smoreland@google.com
 maco@google.com
 malchev@google.com
+hridya@google.com
 elsk@google.com
diff --git a/Parcel.cpp b/Parcel.cpp
index a20d98c..b5648a5 100644
--- a/Parcel.cpp
+++ b/Parcel.cpp
@@ -87,7 +87,7 @@
     switch (obj.hdr.type) {
         case BINDER_TYPE_BINDER:
             if (obj.binder) {
-                LOG_REFS("Parcel %p acquiring reference on local %llu", who, obj.cookie);
+                LOG_REFS("Parcel %p acquiring reference on local %p", who, obj.cookie);
                 reinterpret_cast<IBinder*>(obj.cookie)->incStrong(who);
             }
             return;
@@ -133,7 +133,7 @@
     switch (obj.hdr.type) {
         case BINDER_TYPE_BINDER:
             if (obj.binder) {
-                LOG_REFS("Parcel %p releasing reference on local %llu", who, obj.cookie);
+                LOG_REFS("Parcel %p releasing reference on local %p", who, obj.cookie);
                 reinterpret_cast<IBinder*>(obj.cookie)->decStrong(who);
             }
             return;
@@ -1333,17 +1333,11 @@
             return false;
         }
         if (buffer_obj->parent_offset != parentOffset) {
-            ALOGE("Buffer parent offset %" PRIu64 " does not match expected offset %zu.",
+              ALOGE("Buffer parent offset %" PRIu64 " does not match expected offset %zu.",
                   static_cast<uint64_t>(buffer_obj->parent_offset), parentOffset);
             return false;
         }
 
-        // checked by kernel driver, but needed for fuzzer
-        if (parent >= mObjectsSize) {
-            ALOGE("Parent index %zu but only have %zu objects", parent, mObjectsSize);
-            return false;
-        }
-
         binder_buffer_object *parentBuffer =
             reinterpret_cast<binder_buffer_object*>(mData + mObjects[parent]);
         void* bufferInParent = *reinterpret_cast<void**>(
@@ -1470,8 +1464,8 @@
         return status;
     }
 
-    if (nativeHandleSize < sizeof(native_handle_t) || nativeHandleSize > std::numeric_limits<uint32_t>::max()) {
-        ALOGE("Invalid native_handle_t size: %" PRIu64, nativeHandleSize);
+    if (nativeHandleSize < sizeof(native_handle_t)) {
+        ALOGE("Received a native_handle_t size that was too small.");
         return BAD_VALUE;
     }
 
diff --git a/ProcessState.cpp b/ProcessState.cpp
index c2284f8..dbd6c87 100644
--- a/ProcessState.cpp
+++ b/ProcessState.cpp
@@ -385,7 +385,7 @@
         uint32_t enable = DEFAULT_ENABLE_ONEWAY_SPAM_DETECTION;
         result = ioctl(fd, BINDER_ENABLE_ONEWAY_SPAM_DETECTION, &enable);
         if (result == -1) {
-            ALOGV("Binder ioctl to enable oneway spam detection failed: %s", strerror(errno));
+            ALOGD("Binder ioctl to enable oneway spam detection failed: %s", strerror(errno));
         }
     } else {
         ALOGW("Opening '/dev/hwbinder' failed: %s\n", strerror(errno));
diff --git a/vts/performance/Android.bp b/vts/performance/Android.bp
index fbb9f34..9508c83 100644
--- a/vts/performance/Android.bp
+++ b/vts/performance/Android.bp
@@ -24,6 +24,7 @@
 
 cc_defaults {
     name: "libhwbinder_test_defaults",
+    defaults: ["hwbinder_benchmark_pgo",],
 
     cflags: [
         "-Wall",
@@ -39,7 +40,7 @@
 
     static_libs: [
         "android.hardware.tests.libhwbinder@1.0",
-        "libhidlbase",
+        "libhidlbase_pgo",
     ],
 
     // Allow dlsym'ing self for statically linked passthrough implementations
diff --git a/vts/performance/Benchmark.cpp b/vts/performance/Benchmark.cpp
index 87185f5..f995ec7 100644
--- a/vts/performance/Benchmark.cpp
+++ b/vts/performance/Benchmark.cpp
@@ -82,6 +82,7 @@
 }
 
 static void BM_sendVec_passthrough(benchmark::State& state) {
+    // getService automatically retries
     sp<IBenchmark> service = IBenchmark::getService(gServiceName, true /* getStub */);
     if (service == nullptr) {
         state.SkipWithError("Failed to retrieve benchmark service.");
@@ -93,7 +94,7 @@
 }
 
 static void BM_sendVec_binderize(benchmark::State& state) {
-    android::hardware::details::waitForHwService(IBenchmark::descriptor, gServiceName);
+    // getService automatically retries
     sp<IBenchmark> service = IBenchmark::getService(gServiceName);
     if (service == nullptr) {
         state.SkipWithError("Failed to retrieve benchmark service.");