Merge "Remove logcat, logd, and logwrapper symlinks"
diff --git a/fastboot/device/fastboot_device.cpp b/fastboot/device/fastboot_device.cpp
index 52ea9f0..35f3de0 100644
--- a/fastboot/device/fastboot_device.cpp
+++ b/fastboot/device/fastboot_device.cpp
@@ -139,7 +139,13 @@
 bool FastbootDevice::HandleData(bool read, std::vector<char>* data) {
     auto read_write_data_size = read ? this->get_transport()->Read(data->data(), data->size())
                                      : this->get_transport()->Write(data->data(), data->size());
-    if (read_write_data_size == -1 || static_cast<size_t>(read_write_data_size) != data->size()) {
+    if (read_write_data_size == -1) {
+        LOG(ERROR) << (read ? "read from" : "write to") << " transport failed";
+        return false;
+    }
+    if (static_cast<size_t>(read_write_data_size) != data->size()) {
+        LOG(ERROR) << (read ? "read" : "write") << " expected " << data->size() << " bytes, got "
+                   << read_write_data_size;
         return false;
     }
     return true;
diff --git a/fastboot/device/usb_client.cpp b/fastboot/device/usb_client.cpp
index c653167..2caced4 100644
--- a/fastboot/device/usb_client.cpp
+++ b/fastboot/device/usb_client.cpp
@@ -248,7 +248,12 @@
 }
 
 ssize_t ClientUsbTransport::Read(void* data, size_t len) {
-    if (handle_ == nullptr || len > SSIZE_MAX) {
+    if (handle_ == nullptr) {
+        LOG(ERROR) << "ClientUsbTransport: no handle";
+        return -1;
+    }
+    if (len > SSIZE_MAX) {
+        LOG(ERROR) << "ClientUsbTransport: maximum length exceeds bounds";
         return -1;
     }
     char* char_data = static_cast<char*>(data);
@@ -258,6 +263,7 @@
         auto bytes_read_now =
                 handle_->read(handle_.get(), char_data, bytes_to_read, true /* allow_partial */);
         if (bytes_read_now < 0) {
+            PLOG(ERROR) << "ClientUsbTransport: read failed";
             return bytes_read_total == 0 ? -1 : bytes_read_total;
         }
         bytes_read_total += bytes_read_now;
diff --git a/healthd/android.hardware.health@2.0-service.rc b/healthd/android.hardware.health@2.0-service.rc
index 6960c5d..762771e 100644
--- a/healthd/android.hardware.health@2.0-service.rc
+++ b/healthd/android.hardware.health@2.0-service.rc
@@ -2,5 +2,5 @@
     class hal
     user system
     group system
-    capabilities WAKE_ALARM
+    capabilities WAKE_ALARM BLOCK_SUSPEND
     file /dev/kmsg w
diff --git a/healthd/api/charger_sysprop-current.txt b/healthd/api/charger_sysprop-current.txt
index 678c847..e69de29 100644
--- a/healthd/api/charger_sysprop-current.txt
+++ b/healthd/api/charger_sysprop-current.txt
@@ -1,29 +0,0 @@
-props {
-  module: "android.sysprop.ChargerProperties"
-  prop {
-    api_name: "disable_init_blank"
-    scope: Internal
-    prop_name: "ro.charger.disable_init_blank"
-  }
-  prop {
-    api_name: "draw_split_offset"
-    type: Long
-    scope: Internal
-    prop_name: "ro.charger.draw_split_offset"
-  }
-  prop {
-    api_name: "draw_split_screen"
-    scope: Internal
-    prop_name: "ro.charger.draw_split_screen"
-  }
-  prop {
-    api_name: "enable_suspend"
-    scope: Internal
-    prop_name: "ro.charger.enable_suspend"
-  }
-  prop {
-    api_name: "no_ui"
-    scope: Internal
-    prop_name: "ro.charger.no_ui"
-  }
-}
diff --git a/init/property_service.cpp b/init/property_service.cpp
index a1e0969..57e82fa 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -860,7 +860,7 @@
     build_fingerprint += '/';
     build_fingerprint += GetProperty("ro.product.device", UNKNOWN);
     build_fingerprint += ':';
-    build_fingerprint += GetProperty("ro.build.version.release", UNKNOWN);
+    build_fingerprint += GetProperty("ro.build.version.release_or_codename", UNKNOWN);
     build_fingerprint += '/';
     build_fingerprint += GetProperty("ro.build.id", UNKNOWN);
     build_fingerprint += '/';
diff --git a/libcutils/Android.bp b/libcutils/Android.bp
index b749d87..0c75dc7 100644
--- a/libcutils/Android.bp
+++ b/libcutils/Android.bp
@@ -158,6 +158,7 @@
         "canned_fs_config.cpp",
         "iosched_policy.cpp",
         "load_file.cpp",
+        "memory.cpp",
         "native_handle.cpp",
         "properties.cpp",
         "record_stream.cpp",
@@ -200,6 +201,9 @@
                 "uevent.cpp",
             ],
         },
+        bionic: {
+            header_libs: ["bionic_libc_platform_headers"],
+        },
 
         android_arm: {
             sanitize: {
diff --git a/libcutils/include/cutils/memory.h b/libcutils/include/cutils/memory.h
index c6476c1..0fba53c 100644
--- a/libcutils/include/cutils/memory.h
+++ b/libcutils/include/cutils/memory.h
@@ -28,6 +28,9 @@
 size_t strlcpy(char *dst, const char *src, size_t size);
 #endif
 
+// Disables memory mitigations for the entire process, and logs appropriately.
+void process_disable_memory_mitigations();
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/libcutils/memory.cpp b/libcutils/memory.cpp
new file mode 100644
index 0000000..f526520
--- /dev/null
+++ b/libcutils/memory.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <cutils/memory.h>
+
+#include <log/log.h>
+
+#ifdef __BIONIC__
+#include <bionic/malloc.h>
+#endif
+
+void process_disable_memory_mitigations() {
+    bool success = false;
+#ifdef __BIONIC__
+    // TODO(b/158870657) is fixed and scudo is used globally, we can assert when an
+    // an error is returned.
+
+    success = android_mallopt(M_DISABLE_MEMORY_MITIGATIONS, nullptr, 0);
+#endif
+
+    if (success) {
+        ALOGI("Disabled memory mitigations for process.");
+    } else {
+        ALOGE("Could not disable memory mitigations for process.");
+    }
+}
diff --git a/rootdir/avb/Android.mk b/rootdir/avb/Android.mk
index f96ffdd..3978593 100644
--- a/rootdir/avb/Android.mk
+++ b/rootdir/avb/Android.mk
@@ -1,5 +1,11 @@
 LOCAL_PATH:= $(call my-dir)
 
+ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
+  my_gsi_avb_keys_path := $(TARGET_RECOVERY_ROOT_OUT)/first_stage_ramdisk/avb
+else
+  my_gsi_avb_keys_path := $(TARGET_RAMDISK_OUT)/avb
+endif
+
 #######################################
 # q-gsi.avbpubkey
 include $(CLEAR_VARS)
@@ -7,11 +13,7 @@
 LOCAL_MODULE := q-gsi.avbpubkey
 LOCAL_MODULE_CLASS := ETC
 LOCAL_SRC_FILES := $(LOCAL_MODULE)
-ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/first_stage_ramdisk/avb
-else
-LOCAL_MODULE_PATH := $(TARGET_RAMDISK_OUT)/avb
-endif
+LOCAL_MODULE_PATH := $(my_gsi_avb_keys_path)
 
 include $(BUILD_PREBUILT)
 
@@ -22,11 +24,7 @@
 LOCAL_MODULE := q-developer-gsi.avbpubkey
 LOCAL_MODULE_CLASS := ETC
 LOCAL_SRC_FILES := $(LOCAL_MODULE)
-ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/first_stage_ramdisk/avb
-else
-LOCAL_MODULE_PATH := $(TARGET_RAMDISK_OUT)/avb
-endif
+LOCAL_MODULE_PATH := $(my_gsi_avb_keys_path)
 
 include $(BUILD_PREBUILT)
 
@@ -37,11 +35,7 @@
 LOCAL_MODULE := r-gsi.avbpubkey
 LOCAL_MODULE_CLASS := ETC
 LOCAL_SRC_FILES := $(LOCAL_MODULE)
-ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/first_stage_ramdisk/avb
-else
-LOCAL_MODULE_PATH := $(TARGET_RAMDISK_OUT)/avb
-endif
+LOCAL_MODULE_PATH := $(my_gsi_avb_keys_path)
 
 include $(BUILD_PREBUILT)
 
@@ -52,11 +46,7 @@
 LOCAL_MODULE := r-developer-gsi.avbpubkey
 LOCAL_MODULE_CLASS := ETC
 LOCAL_SRC_FILES := $(LOCAL_MODULE)
-ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/first_stage_ramdisk/avb
-else
-LOCAL_MODULE_PATH := $(TARGET_RAMDISK_OUT)/avb
-endif
+LOCAL_MODULE_PATH := $(my_gsi_avb_keys_path)
 
 include $(BUILD_PREBUILT)
 
@@ -67,11 +57,7 @@
 LOCAL_MODULE := s-gsi.avbpubkey
 LOCAL_MODULE_CLASS := ETC
 LOCAL_SRC_FILES := $(LOCAL_MODULE)
-ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/first_stage_ramdisk/avb
-else
-LOCAL_MODULE_PATH := $(TARGET_RAMDISK_OUT)/avb
-endif
+LOCAL_MODULE_PATH := $(my_gsi_avb_keys_path)
 
 include $(BUILD_PREBUILT)
 
@@ -82,10 +68,8 @@
 LOCAL_MODULE := s-developer-gsi.avbpubkey
 LOCAL_MODULE_CLASS := ETC
 LOCAL_SRC_FILES := $(LOCAL_MODULE)
-ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/first_stage_ramdisk/avb
-else
-LOCAL_MODULE_PATH := $(TARGET_RAMDISK_OUT)/avb
-endif
+LOCAL_MODULE_PATH := $(my_gsi_avb_keys_path)
 
 include $(BUILD_PREBUILT)
+
+my_gsi_avb_keys_path :=
diff --git a/trusty/utils/rpmb_dev/rpmb_dev.rc b/trusty/utils/rpmb_dev/rpmb_dev.rc
index 9f60e81..9e203b8 100644
--- a/trusty/utils/rpmb_dev/rpmb_dev.rc
+++ b/trusty/utils/rpmb_dev/rpmb_dev.rc
@@ -16,7 +16,7 @@
     disabled
     user root
 
-service rpmb_mock_init /vendor/bin/rpmb_dev --dev /data/vendor/ss/RPMB_DATA --init --key "ea df 64 44 ea 65 5d 1c 87 27 d4 20 71 0d 53 42 dd 73 a3 38 63 e1 d7 94 c3 72 a6 ea e0 64 64 e6" --size 2048
+service rpmb_mock_init /vendor/bin/rpmb_dev --dev /data/vendor/ss/RPMB_DATA --init --size 2048
     disabled
     user system
     group system