[automerger skipped] Merge RQ3A.210705.001 to stage-aosp-master - DO NOT MERGE am: a4ce3dc7b5 -s ours

am skip reason: Merged-In I911a64b80804f1f34415ee1fad44dc27d5d84e00 with SHA-1 841be7a5ff is already in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/system/libhwbinder/+/15256465

Change-Id: I31c6f6c15fc2c6ecf390aa90ad3c971883d6bd7e
diff --git a/Binder.cpp b/Binder.cpp
index d86795c..b90639f 100644
--- a/Binder.cpp
+++ b/Binder.cpp
@@ -16,15 +16,21 @@
 
 #include <hwbinder/Binder.h>
 
-#include <atomic>
-#include <utils/misc.h>
+#include <android-base/macros.h>
+#include <cutils/android_filesystem_config.h>
+#include <cutils/multiuser.h>
 #include <hwbinder/BpHwBinder.h>
 #include <hwbinder/IInterface.h>
+#include <hwbinder/IPCThreadState.h>
 #include <hwbinder/Parcel.h>
+#include <utils/Log.h>
+#include <utils/misc.h>
 
 #include <linux/sched.h>
 #include <stdio.h>
 
+#include <atomic>
+
 namespace android {
 namespace hardware {
 
@@ -114,6 +120,15 @@
         reply->markSensitive();
     }
 
+    // extra comment to try to force running all tests
+    if (UNLIKELY(code == HIDL_DEBUG_TRANSACTION)) {
+        uid_t uid = IPCThreadState::self()->getCallingUid();
+        if (multiuser_get_app_id(uid) >= AID_APP_START) {
+            ALOGE("Can not call IBase::debug from apps");
+            return PERMISSION_DENIED;
+        }
+    }
+
     status_t err = NO_ERROR;
     switch (code) {
         default:
diff --git a/Parcel.cpp b/Parcel.cpp
index adafaab..b5648a5 100644
--- a/Parcel.cpp
+++ b/Parcel.cpp
@@ -1786,7 +1786,7 @@
 
     releaseObjects();
 
-    if (data) {
+    if (data || desired == 0) {
         LOG_ALLOC("Parcel %p: restart from %zu to %zu capacity", this, mDataCapacity, desired);
         if (mDataCapacity > desired) {
             gParcelGlobalAllocSize -= (mDataCapacity - desired);
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 2bd0463..dfede5a 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -2,6 +2,14 @@
   "presubmit": [
     {
       "name": "libbinderthreadstateutils_test"
+    },
+    {
+      "name": "SettingsGoogleUnitTests",
+      "options": [
+        {
+          "exclude-annotation": "androidx.test.filters.FlakyTest"
+        }
+      ]
     }
   ]
 }