Snap for 8564071 from 2ffd44fb8d76df8c5e0f9832bc8e731c842f2d03 to mainline-sdkext-release

Change-Id: Ica5f35a3e678568670f06602fdf9763fa779d1af
diff --git a/Android.bp b/Android.bp
index 6f2869c..1ca91b3 100644
--- a/Android.bp
+++ b/Android.bp
@@ -121,7 +121,6 @@
     defaults: [
         "libhwbinder_defaults",
         "libhwbinder-impl-shared-libs",
-        "hwbinder_pgo",
         "hwbinder_lto",
     ],
     host_supported: true,
@@ -133,7 +132,7 @@
     apex_available: [
         "//apex_available:platform",
         "com.android.neuralnetworks",
-        "com.android.bluetooth.updatable",
+        "com.android.bluetooth",
         "com.android.media",
         "com.android.media.swcodec",
         "com.android.tethering",
@@ -141,41 +140,6 @@
     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 b90639f..6d26414 100644
--- a/Binder.cpp
+++ b/Binder.cpp
@@ -129,20 +129,12 @@
         }
     }
 
-    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;
+    return onTransact(code, data, reply, flags, [&](auto& replyParcel) {
+      replyParcel.setDataPosition(0);
+      if (callback != nullptr) {
+        callback(replyParcel);
+      }
+    });
 }
 
 status_t BHwBinder::linkToDeath(
diff --git a/OWNERS b/OWNERS
index dc0f56c..46996a2 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,5 +1,4 @@
 smoreland@google.com
 maco@google.com
 malchev@google.com
-hridya@google.com
 elsk@google.com
diff --git a/Parcel.cpp b/Parcel.cpp
index b5648a5..a20d98c 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 %p", who, obj.cookie);
+                LOG_REFS("Parcel %p acquiring reference on local %llu", 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 %p", who, obj.cookie);
+                LOG_REFS("Parcel %p releasing reference on local %llu", who, obj.cookie);
                 reinterpret_cast<IBinder*>(obj.cookie)->decStrong(who);
             }
             return;
@@ -1333,11 +1333,17 @@
             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**>(
@@ -1464,8 +1470,8 @@
         return status;
     }
 
-    if (nativeHandleSize < sizeof(native_handle_t)) {
-        ALOGE("Received a native_handle_t size that was too small.");
+    if (nativeHandleSize < sizeof(native_handle_t) || nativeHandleSize > std::numeric_limits<uint32_t>::max()) {
+        ALOGE("Invalid native_handle_t size: %" PRIu64, nativeHandleSize);
         return BAD_VALUE;
     }
 
diff --git a/ProcessState.cpp b/ProcessState.cpp
index dbd6c87..c2284f8 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) {
-            ALOGD("Binder ioctl to enable oneway spam detection failed: %s", strerror(errno));
+            ALOGV("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 9508c83..fbb9f34 100644
--- a/vts/performance/Android.bp
+++ b/vts/performance/Android.bp
@@ -24,7 +24,6 @@
 
 cc_defaults {
     name: "libhwbinder_test_defaults",
-    defaults: ["hwbinder_benchmark_pgo",],
 
     cflags: [
         "-Wall",
@@ -40,7 +39,7 @@
 
     static_libs: [
         "android.hardware.tests.libhwbinder@1.0",
-        "libhidlbase_pgo",
+        "libhidlbase",
     ],
 
     // Allow dlsym'ing self for statically linked passthrough implementations
diff --git a/vts/performance/Benchmark.cpp b/vts/performance/Benchmark.cpp
index f995ec7..87185f5 100644
--- a/vts/performance/Benchmark.cpp
+++ b/vts/performance/Benchmark.cpp
@@ -82,7 +82,6 @@
 }
 
 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.");
@@ -94,7 +93,7 @@
 }
 
 static void BM_sendVec_binderize(benchmark::State& state) {
-    // getService automatically retries
+    android::hardware::details::waitForHwService(IBenchmark::descriptor, gServiceName);
     sp<IBenchmark> service = IBenchmark::getService(gServiceName);
     if (service == nullptr) {
         state.SkipWithError("Failed to retrieve benchmark service.");