Merge "storageproxy: set a property when secure storage becomes rw" into main
diff --git a/fs_mgr/libfstab/fstab.cpp b/fs_mgr/libfstab/fstab.cpp
index f00e0dc..21d2e2e 100644
--- a/fs_mgr/libfstab/fstab.cpp
+++ b/fs_mgr/libfstab/fstab.cpp
@@ -520,6 +520,24 @@
 
 }  // namespace
 
+// Return the path to the recovery fstab file.  There may be multiple fstab files;
+// the one that is returned will be the first that exists of recovery.fstab.<fstab_suffix>,
+// recovery.fstab.<hardware>, and recovery.fstab.<hardware.platform>.
+std::string GetRecoveryFstabPath() {
+    for (const char* prop : {"fstab_suffix", "hardware", "hardware.platform"}) {
+        std::string suffix;
+
+        if (!fs_mgr_get_boot_config(prop, &suffix)) continue;
+
+        std::string fstab_path = "/etc/recovery.fstab." + suffix;
+        if (access(fstab_path.c_str(), F_OK) == 0) {
+            return fstab_path;
+        }
+    }
+
+    return "/etc/recovery.fstab";
+}
+
 // Return the path to the fstab file.  There may be multiple fstab files; the
 // one that is returned will be the first that exists of fstab.<fstab_suffix>,
 // fstab.<hardware>, and fstab.<hardware.platform>.  The fstab is searched for
@@ -529,7 +547,7 @@
 // the system/etc directory is supported too and is the preferred location.
 std::string GetFstabPath() {
     if (InRecovery()) {
-        return "/etc/recovery.fstab";
+        return GetRecoveryFstabPath();
     }
     for (const char* prop : {"fstab_suffix", "hardware", "hardware.platform"}) {
         std::string suffix;
diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp
index 4d55315..6674378 100644
--- a/fs_mgr/libsnapshot/snapshot.cpp
+++ b/fs_mgr/libsnapshot/snapshot.cpp
@@ -21,6 +21,7 @@
 #include <sys/types.h>
 #include <sys/unistd.h>
 
+#include <chrono>
 #include <filesystem>
 #include <optional>
 #include <thread>
@@ -2865,10 +2866,12 @@
 }
 
 bool SnapshotManager::UnmapAllSnapshots(LockedFile* lock) {
+    LOG(INFO) << "Lock acquired for " << __FUNCTION__;
     std::vector<std::string> snapshots;
     if (!ListSnapshots(lock, &snapshots)) {
         return false;
     }
+    LOG(INFO) << "Found " << snapshots.size() << " partitions with snapshots";
 
     for (const auto& snapshot : snapshots) {
         if (!UnmapPartitionWithSnapshot(lock, snapshot)) {
@@ -2892,6 +2895,7 @@
 
 auto SnapshotManager::OpenFile(const std::string& file,
                                int lock_flags) -> std::unique_ptr<LockedFile> {
+    const auto start = std::chrono::system_clock::now();
     unique_fd fd(open(file.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW));
     if (fd < 0) {
         PLOG(ERROR) << "Open failed: " << file;
@@ -2904,6 +2908,11 @@
     // For simplicity, we want to CHECK that lock_mode == LOCK_EX, in some
     // calls, so strip extra flags.
     int lock_mode = lock_flags & (LOCK_EX | LOCK_SH);
+    const auto end = std::chrono::system_clock::now();
+    const auto duration_ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
+    if (duration_ms >= 1000ms) {
+        LOG(INFO) << "Taking lock on " << file << " took " << duration_ms.count() << "ms";
+    }
     return std::make_unique<LockedFile>(file, std::move(fd), lock_mode);
 }
 
diff --git a/init/block_dev_initializer.cpp b/init/block_dev_initializer.cpp
index a686d05..8f52158 100644
--- a/init/block_dev_initializer.cpp
+++ b/init/block_dev_initializer.cpp
@@ -139,6 +139,10 @@
     return InitDevice("/sys/devices/platform", dev_name);
 }
 
+bool BlockDevInitializer::InitHvcDevice(const std::string& dev_name) {
+    return InitDevice("/sys/devices/virtual/tty", dev_name);
+}
+
 bool BlockDevInitializer::InitDevice(const std::string& syspath, const std::string& device_name) {
     bool found = false;
 
diff --git a/init/block_dev_initializer.h b/init/block_dev_initializer.h
index d5b1f60..cb1d365 100644
--- a/init/block_dev_initializer.h
+++ b/init/block_dev_initializer.h
@@ -34,6 +34,7 @@
     bool InitDevices(std::set<std::string> devices);
     bool InitDmDevice(const std::string& device);
     bool InitPlatformDevice(const std::string& device);
+    bool InitHvcDevice(const std::string& device);
 
   private:
     ListenerAction HandleUevent(const Uevent& uevent, std::set<std::string>* devices);
diff --git a/rootdir/Android.bp b/rootdir/Android.bp
index e8f7627..7105ed5 100644
--- a/rootdir/Android.bp
+++ b/rootdir/Android.bp
@@ -114,10 +114,23 @@
     sub_dir: "init",
 }
 
+prebuilt_etc {
+    name: "asan.options",
+    src: "asan.options",
+}
+
+sh_binary {
+    name: "asan_extract",
+    src: "asan_extract.sh",
+    init_rc: ["asan_extract.rc"],
+    // We need bzip2 on device for extraction.
+    required: ["bzip2"],
+}
+
 llndk_libraries_txt {
     name: "llndk.libraries.txt",
 }
 
 sanitizer_libraries_txt {
     name: "sanitizer.libraries.txt",
-}
\ No newline at end of file
+}
diff --git a/rootdir/Android.mk b/rootdir/Android.mk
index 4c1f2e4..e6ccda7 100644
--- a/rootdir/Android.mk
+++ b/rootdir/Android.mk
@@ -3,39 +3,12 @@
 $(eval $(call declare-1p-copy-files,system/core/rootdir,))
 
 #######################################
-# asan.options
 ifneq ($(filter address,$(SANITIZE_TARGET)),)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := asan.options
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_MODULE_CLASS := ETC
-LOCAL_SRC_FILES := $(LOCAL_MODULE)
-LOCAL_MODULE_PATH := $(TARGET_OUT)
-
-include $(BUILD_PREBUILT)
-
-# ASAN extration.
 ASAN_EXTRACT_FILES :=
 ifeq ($(SANITIZE_TARGET_SYSTEM),true)
-include $(CLEAR_VARS)
-LOCAL_MODULE:= asan_extract
-LOCAL_LICENSE_KINDS:= SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS:= notice
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_CLASS := EXECUTABLES
-LOCAL_SRC_FILES := asan_extract.sh
-LOCAL_INIT_RC := asan_extract.rc
-# We need bzip2 on device for extraction.
-LOCAL_REQUIRED_MODULES := bzip2
-include $(BUILD_PREBUILT)
 ASAN_EXTRACT_FILES := asan_extract
 endif
-
 endif
-
 #######################################
 # init.environ.rc
 
diff --git a/rootdir/avb/Android.bp b/rootdir/avb/Android.bp
new file mode 100644
index 0000000..a584e3e
--- /dev/null
+++ b/rootdir/avb/Android.bp
@@ -0,0 +1,71 @@
+// Copyright (C) 2024 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.
+
+soong_config_module_type {
+    name: "avb_keys_prebuilt_avb",
+    module_type: "prebuilt_avb",
+    config_namespace: "ANDROID",
+    bool_variables: [
+        "BOARD_MOVE_GSI_AVB_KEYS_TO_VENDOR_BOOT",
+    ],
+    properties: [
+        "ramdisk",
+        "vendor_ramdisk",
+    ],
+}
+
+avb_keys_prebuilt_avb {
+    name: "q-developer-gsi.avbpubkey",
+    src: "q-developer-gsi.avbpubkey",
+    soong_config_variables: {
+        BOARD_MOVE_GSI_AVB_KEYS_TO_VENDOR_BOOT: {
+            ramdisk: false,
+            vendor_ramdisk: true,
+            conditions_default: {
+                ramdisk: true,
+                vendor_ramdisk: false,
+            },
+        },
+    },
+}
+
+avb_keys_prebuilt_avb {
+    name: "r-developer-gsi.avbpubkey",
+    src: "r-developer-gsi.avbpubkey",
+    soong_config_variables: {
+        BOARD_MOVE_GSI_AVB_KEYS_TO_VENDOR_BOOT: {
+            ramdisk: false,
+            vendor_ramdisk: true,
+            conditions_default: {
+                ramdisk: true,
+                vendor_ramdisk: false,
+            },
+        },
+    },
+}
+
+avb_keys_prebuilt_avb {
+    name: "s-developer-gsi.avbpubkey",
+    src: "s-developer-gsi.avbpubkey",
+    soong_config_variables: {
+        BOARD_MOVE_GSI_AVB_KEYS_TO_VENDOR_BOOT: {
+            ramdisk: false,
+            vendor_ramdisk: true,
+            conditions_default: {
+                ramdisk: true,
+                vendor_ramdisk: false,
+            },
+        },
+    },
+}
diff --git a/rootdir/avb/Android.mk b/rootdir/avb/Android.mk
deleted file mode 100644
index 8cf3172..0000000
--- a/rootdir/avb/Android.mk
+++ /dev/null
@@ -1,56 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-ifeq ($(BOARD_MOVE_GSI_AVB_KEYS_TO_VENDOR_BOOT),true) # AVB keys are installed to vendor ramdisk
-  ifeq ($(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT),true) # no dedicated recovery partition
-    my_gsi_avb_keys_path := $(TARGET_VENDOR_RAMDISK_OUT)/first_stage_ramdisk/avb
-  else # device has a dedicated recovery partition
-    my_gsi_avb_keys_path := $(TARGET_VENDOR_RAMDISK_OUT)/avb
-  endif
-else
-  ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true) # no dedicated recovery partition
-    my_gsi_avb_keys_path := $(TARGET_RECOVERY_ROOT_OUT)/first_stage_ramdisk/avb
-  else # device has a dedicated recovery partition
-    my_gsi_avb_keys_path := $(TARGET_RAMDISK_OUT)/avb
-  endif
-endif
-
-#######################################
-# q-developer-gsi.avbpubkey
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := q-developer-gsi.avbpubkey
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_MODULE_CLASS := ETC
-LOCAL_SRC_FILES := $(LOCAL_MODULE)
-LOCAL_MODULE_PATH := $(my_gsi_avb_keys_path)
-
-include $(BUILD_PREBUILT)
-
-#######################################
-# r-developer-gsi.avbpubkey
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := r-developer-gsi.avbpubkey
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_MODULE_CLASS := ETC
-LOCAL_SRC_FILES := $(LOCAL_MODULE)
-LOCAL_MODULE_PATH := $(my_gsi_avb_keys_path)
-
-include $(BUILD_PREBUILT)
-
-#######################################
-# s-developer-gsi.avbpubkey
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := s-developer-gsi.avbpubkey
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_MODULE_CLASS := ETC
-LOCAL_SRC_FILES := $(LOCAL_MODULE)
-LOCAL_MODULE_PATH := $(my_gsi_avb_keys_path)
-
-include $(BUILD_PREBUILT)
-
-my_gsi_avb_keys_path :=