Merge "Support monitoring the subprocess in edit monitor" into main
diff --git a/core/dex_preopt.mk b/core/dex_preopt.mk
index 906d7f0..88e0cc7 100644
--- a/core/dex_preopt.mk
+++ b/core/dex_preopt.mk
@@ -13,28 +13,6 @@
 install-on-system-other = $(filter-out $(PRODUCT_DEXPREOPT_SPEED_APPS) $(PRODUCT_SYSTEM_SERVER_APPS),$(basename $(notdir $(filter $(foreach f,$(SYSTEM_OTHER_ODEX_FILTER),$(TARGET_OUT)/$(f)),$(1)))))
 endif
 
-# Install boot images for testing on host. We exclude framework image as it is not part of art manifest.
-my_boot_image_arch := HOST_ARCH
-my_boot_image_out := $(HOST_OUT)
-my_boot_image_syms := $(HOST_OUT)/symbols
-HOST_BOOT_IMAGE_MODULE := \
-  $(foreach my_boot_image_name,art_host,$(strip \
-    $(eval include $(BUILD_SYSTEM)/dex_preopt_libart.mk) \
-    $(my_boot_image_module)))
-HOST_BOOT_IMAGE := $(call module-installed-files,$(HOST_BOOT_IMAGE_MODULE))
-ifdef HOST_2ND_ARCH
-  my_boot_image_arch := HOST_2ND_ARCH
-  2ND_HOST_BOOT_IMAGE_MODULE := \
-    $(foreach my_boot_image_name,art_host,$(strip \
-      $(eval include $(BUILD_SYSTEM)/dex_preopt_libart.mk) \
-      $(my_boot_image_module)))
-  2ND_HOST_BOOT_IMAGE := $(call module-installed-files,$(2ND_HOST_BOOT_IMAGE_MODULE))
-endif
-my_boot_image_arch :=
-my_boot_image_out :=
-my_boot_image_syms :=
-my_boot_image_module :=
-
 # Build the boot.zip which contains the boot jars and their compilation output
 # We can do this only if preopt is enabled and if the product uses libart config (which sets the
 # default properties for preopting).
diff --git a/core/dex_preopt_libart.mk b/core/dex_preopt_libart.mk
deleted file mode 100644
index a2c9942..0000000
--- a/core/dex_preopt_libart.mk
+++ /dev/null
@@ -1,109 +0,0 @@
-####################################
-# ART boot image installation
-# Input variables:
-#   my_boot_image_name: the boot image to install
-#   my_boot_image_arch: the architecture to install (e.g. TARGET_ARCH, not expanded)
-#   my_boot_image_out:  the install directory (e.g. $(PRODUCT_OUT))
-#   my_boot_image_syms: the symbols director (e.g. $(TARGET_OUT_UNSTRIPPED))
-#
-# Output variables:
-#   my_boot_image_module: the created module name. Empty if no module is created.
-#
-# Install the boot images compiled by Soong.
-# Create a module named dexpreopt_bootjar.$(my_boot_image_name)_$($(my_boot_image_arch))
-# that installs all of boot image files.
-# If there is no file to install for $(my_boot_image_name), for example when
-# building an unbundled build, then no module is created.
-#
-####################################
-
-# Takes a list of src:dest install pairs and returns a new list with a path
-# prefixed to each dest value.
-# $(1): list of src:dest install pairs
-# $(2): path to prefix to each dest value
-define prefix-copy-many-files-dest
-$(foreach v,$(1),$(call word-colon,1,$(v)):$(2)$(call word-colon,2,$(v)))
-endef
-
-# Converts an architecture-specific vdex path into a location that can be shared
-# between architectures.
-define vdex-shared-install-path
-$(dir $(patsubst %/,%,$(dir $(1))))$(notdir $(1))
-endef
-
-# Takes a list of src:dest install pairs of vdex files and returns a new list
-# where each dest has been rewritten to the shared location for vdex files.
-define vdex-copy-many-files-shared-dest
-$(foreach v,$(1),$(call word-colon,1,$(v)):$(call vdex-shared-install-path,$(call word-colon,2,$(v))))
-endef
-
-# Creates a rule to symlink an architecture specific vdex file to the shared
-# location for that vdex file.
-define symlink-vdex-file
-$(strip \
-  $(call symlink-file,\
-    $(call vdex-shared-install-path,$(1)),\
-    ../$(notdir $(1)),\
-    $(1))\
-  $(1))
-endef
-
-# Takes a list of src:dest install pairs of vdex files and creates rules to
-# symlink each dest to the shared location for that vdex file.
-define symlink-vdex-files
-$(foreach v,$(1),$(call symlink-vdex-file,$(call word-colon,2,$(v))))
-endef
-
-my_boot_image_module :=
-
-my_suffix := $(my_boot_image_name)_$($(my_boot_image_arch))
-my_copy_pairs := $(call prefix-copy-many-files-dest,$(DEXPREOPT_IMAGE_BUILT_INSTALLED_$(my_suffix)),$(my_boot_image_out))
-my_vdex_copy_pairs := $(call prefix-copy-many-files-dest,$(DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_$(my_suffix)),$(my_boot_image_out))
-my_vdex_copy_shared_pairs := $(call vdex-copy-many-files-shared-dest,$(my_vdex_copy_pairs))
-ifeq (,$(filter %_2ND_ARCH,$(my_boot_image_arch)))
-  # Only install the vdex to the shared location for the primary architecture.
-  my_copy_pairs += $(my_vdex_copy_shared_pairs)
-endif
-
-my_unstripped_copy_pairs := $(call prefix-copy-many-files-dest,$(DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_$(my_suffix)),$(my_boot_image_syms))
-
-# Generate the boot image module only if there is any file to install.
-ifneq (,$(strip $(my_copy_pairs)))
-  my_first_pair := $(firstword $(my_copy_pairs))
-  my_rest_pairs := $(wordlist 2,$(words $(my_copy_pairs)),$(my_copy_pairs))
-
-  my_first_src := $(call word-colon,1,$(my_first_pair))
-  my_first_dest := $(call word-colon,2,$(my_first_pair))
-
-  my_installed := $(call copy-many-files,$(my_copy_pairs))
-  my_unstripped_installed := $(call copy-many-files,$(my_unstripped_copy_pairs))
-
-  my_symlinks := $(call symlink-vdex-files,$(my_vdex_copy_pairs))
-
-  # We don't have a LOCAL_PATH for the auto-generated modules, so let it be the $(BUILD_SYSTEM).
-  LOCAL_PATH := $(BUILD_SYSTEM)
-  # Hack to let these pseudo-modules wrapped around Soong modules use LOCAL_SOONG_INSTALLED_MODULE.
-  LOCAL_MODULE_MAKEFILE := $(SOONG_ANDROID_MK)
-
-  include $(CLEAR_VARS)
-  LOCAL_MODULE := dexpreopt_bootjar.$(my_suffix)
-  LOCAL_PREBUILT_MODULE_FILE := $(my_first_src)
-  LOCAL_MODULE_PATH := $(dir $(my_first_dest))
-  LOCAL_MODULE_STEM := $(notdir $(my_first_dest))
-  LOCAL_SOONG_INSTALL_PAIRS := $(my_copy_pairs)
-  LOCAL_SOONG_INSTALL_SYMLINKS := $(my_symlinks)
-  LOCAL_SOONG_INSTALLED_MODULE := $(my_first_dest)
-  LOCAL_SOONG_LICENSE_METADATA := $(DEXPREOPT_IMAGE_LICENSE_METADATA_$(my_suffix))
-  ifneq (,$(strip $(filter HOST_%,$(my_boot_image_arch))))
-    LOCAL_IS_HOST_MODULE := true
-  endif
-  LOCAL_MODULE_CLASS := ETC
-  include $(BUILD_PREBUILT)
-  $(LOCAL_BUILT_MODULE): | $(my_unstripped_installed)
-  # Installing boot.art causes all boot image bits to be installed.
-  # Keep this old behavior in case anyone still needs it.
-  $(LOCAL_INSTALLED_MODULE): $(wordlist 2,$(words $(my_installed)),$(my_installed)) $(my_symlinks)
-  $(my_all_targets): $(my_installed) $(my_symlinks)
-
-  my_boot_image_module := $(LOCAL_MODULE)
-endif  # my_copy_pairs != empty
diff --git a/core/product.mk b/core/product.mk
index b07e6e0..93a656d 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -390,20 +390,6 @@
 # If set, Java module in product partition cannot use hidden APIs.
 _product_single_value_vars += PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE
 
-# If set, only java_sdk_library can be used at inter-partition dependency.
-# Note: Build error if BOARD_VNDK_VERSION is not set while
-#       PRODUCT_ENFORCE_INTER_PARTITION_JAVA_SDK_LIBRARY is true, because
-#       PRODUCT_ENFORCE_INTER_PARTITION_JAVA_SDK_LIBRARY has no meaning if
-#       BOARD_VNDK_VERSION is not set.
-# Note: When PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is not set, there are
-#       no restrictions at dependency between system and product partition.
-_product_single_value_vars += PRODUCT_ENFORCE_INTER_PARTITION_JAVA_SDK_LIBRARY
-
-# Allowlist for PRODUCT_ENFORCE_INTER_PARTITION_JAVA_SDK_LIBRARY option.
-# Listed modules are allowed at inter-partition dependency even if it isn't
-# a java_sdk_library module.
-_product_list_vars += PRODUCT_INTER_PARTITION_JAVA_LIBRARY_ALLOWLIST
-
 # Install a copy of the debug policy to the system_ext partition, and allow
 # init-second-stage to load debug policy from system_ext.
 # This option is only meant to be set by compliance GSI targets.
diff --git a/core/soong_config.mk b/core/soong_config.mk
index 1e6388a..97b707f 100644
--- a/core/soong_config.mk
+++ b/core/soong_config.mk
@@ -265,9 +265,6 @@
 $(call add_json_bool, EnforceProductPartitionInterface,  $(filter true,$(PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE)))
 $(call add_json_str,  DeviceCurrentApiLevelForVendorModules,  $(BOARD_CURRENT_API_LEVEL_FOR_VENDOR_MODULES))
 
-$(call add_json_bool, EnforceInterPartitionJavaSdkLibrary, $(filter true,$(PRODUCT_ENFORCE_INTER_PARTITION_JAVA_SDK_LIBRARY)))
-$(call add_json_list, InterPartitionJavaLibraryAllowList, $(PRODUCT_INTER_PARTITION_JAVA_LIBRARY_ALLOWLIST))
-
 $(call add_json_bool, CompressedApex, $(filter true,$(PRODUCT_COMPRESSED_APEX)))
 
 ifndef APEX_BUILD_FOR_PRE_S_DEVICES
diff --git a/shell_utils.sh b/shell_utils.sh
index 6cc8c9e..c4a6756 100644
--- a/shell_utils.sh
+++ b/shell_utils.sh
@@ -109,16 +109,11 @@
 
   local link_destination="${HOME}/.cog/android-build-out"
 
-  # if there's a local out/ dir, prompt the user to remove it.
-  # fail out if they say no.
-  local answer
+  # remove existing out/ dir if it exists
   if [[ -d "$out_dir" ]]; then
-    echo "Detected existing out/ directory in the Cog workspace which is not supported. Can we repair your workspace by removing it and creating the symlink to ~/.cog/android-build-out instead? (y/N): "
-    read -r answer
-    if [[ $answer =~ ^[Yy]$ ]]; then
-      rm -rf "$out_dir"
-    else
-      echo "Exiting due to unsupported out/ directory."
+    echo "Detected existing out/ directory in the Cog workspace which is not supported. Repairing workspace by removing it and creating the symlink to ~/.cog/android-build-out"
+    if ! rm -rf "$out_dir"; then
+      echo "Failed to remove existing out/ directory: $out_dir" >&2
       kill -INT $$ # exits the script without exiting the user's shell
     fi
   fi
diff --git a/tools/aconfig/aconfig_device_paths/partition_aconfig_flags_paths.txt b/tools/aconfig/aconfig_device_paths/partition_aconfig_flags_paths.txt
index 140cd21..e997e3d 100644
--- a/tools/aconfig/aconfig_device_paths/partition_aconfig_flags_paths.txt
+++ b/tools/aconfig/aconfig_device_paths/partition_aconfig_flags_paths.txt
@@ -1,4 +1,3 @@
 "/system/etc/aconfig_flags.pb",
-"/system_ext/etc/aconfig_flags.pb",
 "/product/etc/aconfig_flags.pb",
 "/vendor/etc/aconfig_flags.pb",
diff --git a/tools/aconfig/aconfig_storage_file/srcs/android/aconfig/storage/FlagTable.java b/tools/aconfig/aconfig_storage_file/srcs/android/aconfig/storage/FlagTable.java
index 9838a7c..757844a 100644
--- a/tools/aconfig/aconfig_storage_file/srcs/android/aconfig/storage/FlagTable.java
+++ b/tools/aconfig/aconfig_storage_file/srcs/android/aconfig/storage/FlagTable.java
@@ -37,9 +37,16 @@
     public Node get(int packageId, String flagName) {
         int numBuckets = (mHeader.mNodeOffset - mHeader.mBucketOffset) / 4;
         int bucketIndex = TableUtils.getBucketIndex(makeKey(packageId, flagName), numBuckets);
+        int newPosition = mHeader.mBucketOffset + bucketIndex * 4;
+        if (newPosition >= mHeader.mNodeOffset) {
+            return null;
+        }
 
-        mReader.position(mHeader.mBucketOffset + bucketIndex * 4);
+        mReader.position(newPosition);
         int nodeIndex = mReader.readInt();
+        if (nodeIndex < mHeader.mNodeOffset || nodeIndex >= mHeader.mFileSize) {
+            return null;
+        }
 
         while (nodeIndex != -1) {
             mReader.position(nodeIndex);
@@ -50,7 +57,7 @@
             nodeIndex = node.mNextOffset;
         }
 
-        throw new AconfigStorageException("get cannot find flag: " + flagName);
+        return null;
     }
 
     public Header getHeader() {
diff --git a/tools/aconfig/aconfig_storage_file/srcs/android/aconfig/storage/PackageTable.java b/tools/aconfig/aconfig_storage_file/srcs/android/aconfig/storage/PackageTable.java
index 773b882..dc1c583 100644
--- a/tools/aconfig/aconfig_storage_file/srcs/android/aconfig/storage/PackageTable.java
+++ b/tools/aconfig/aconfig_storage_file/srcs/android/aconfig/storage/PackageTable.java
@@ -35,13 +35,19 @@
     }
 
     public Node get(String packageName) {
-
         int numBuckets = (mHeader.mNodeOffset - mHeader.mBucketOffset) / 4;
         int bucketIndex = TableUtils.getBucketIndex(packageName.getBytes(UTF_8), numBuckets);
-
-        mReader.position(mHeader.mBucketOffset + bucketIndex * 4);
+        int newPosition = mHeader.mBucketOffset + bucketIndex * 4;
+        if (newPosition >= mHeader.mNodeOffset) {
+            return null;
+        }
+        mReader.position(newPosition);
         int nodeIndex = mReader.readInt();
 
+        if (nodeIndex < mHeader.mNodeOffset || nodeIndex >= mHeader.mFileSize) {
+            return null;
+        }
+
         while (nodeIndex != -1) {
             mReader.position(nodeIndex);
             Node node = Node.fromBytes(mReader);
@@ -51,7 +57,7 @@
             nodeIndex = node.mNextOffset;
         }
 
-        throw new AconfigStorageException("get cannot find package: " + packageName);
+        return null;
     }
 
     public Header getHeader() {
diff --git a/tools/aconfig/aconfig_storage_read_api/srcs/android/aconfig/storage/StorageInternalReader.java b/tools/aconfig/aconfig_storage_read_api/srcs/android/aconfig/storage/StorageInternalReader.java
index 29ebee5..6fbcdb3 100644
--- a/tools/aconfig/aconfig_storage_read_api/srcs/android/aconfig/storage/StorageInternalReader.java
+++ b/tools/aconfig/aconfig_storage_read_api/srcs/android/aconfig/storage/StorageInternalReader.java
@@ -53,9 +53,6 @@
     @UnsupportedAppUsage
     public boolean getBooleanFlagValue(int index) {
         index += mPackageBooleanStartOffset;
-        if (index >= mFlagValueList.size()) {
-            throw new AconfigStorageException("Fail to get boolean flag value");
-        }
         return mFlagValueList.getBoolean(index);
     }
 
diff --git a/tools/aconfig/fake_device_config/Android.bp b/tools/aconfig/fake_device_config/Android.bp
index 7704742..1f17e6b 100644
--- a/tools/aconfig/fake_device_config/Android.bp
+++ b/tools/aconfig/fake_device_config/Android.bp
@@ -15,9 +15,7 @@
 java_library {
     name: "fake_device_config",
     srcs: [
-        "src/android/util/Log.java",
-        "src/android/provider/DeviceConfig.java",
-        "src/android/os/StrictMode.java",
+        "src/**/*.java",
     ],
     sdk_version: "none",
     system_modules: "core-all-system-modules",
diff --git a/tools/aconfig/fake_device_config/src/android/provider/AconfigPackage.java b/tools/aconfig/fake_device_config/src/android/provider/AconfigPackage.java
new file mode 100644
index 0000000..2f01b8c
--- /dev/null
+++ b/tools/aconfig/fake_device_config/src/android/provider/AconfigPackage.java
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+package android.provider;
+
+/*
+ * This class allows generated aconfig code to compile independently of the framework.
+ */
+public class AconfigPackage {
+
+    /** Flag value is true */
+    public static final int FLAG_BOOLEAN_VALUE_TRUE = 1;
+
+    /** Flag value is false */
+    public static final int FLAG_BOOLEAN_VALUE_FALSE = 0;
+
+    /** Flag value doesn't exist */
+    public static final int FLAG_BOOLEAN_VALUE_NOT_EXIST = 2;
+
+    public static int getBooleanFlagValue(String packageName, String flagName) {
+        return 0;
+    }
+
+    public AconfigPackage(String packageName) {}
+
+    public int getBooleanFlagValue(String flagName) {
+        return 0;
+    }
+}
\ No newline at end of file
diff --git a/tools/filelistdiff/allowlist b/tools/filelistdiff/allowlist
index b3ae819..10bc8d5 100644
--- a/tools/filelistdiff/allowlist
+++ b/tools/filelistdiff/allowlist
@@ -4,32 +4,9 @@
 framework/oat/x86_64/apex@com.android.compos@javalib@service-compos.jar@classes.odex.fsv_meta
 framework/oat/x86_64/apex@com.android.compos@javalib@service-compos.jar@classes.vdex
 framework/oat/x86_64/apex@com.android.compos@javalib@service-compos.jar@classes.vdex.fsv_meta
-lib/aaudio-aidl-cpp.so
-lib/android.hardware.biometrics.fingerprint@2.1.so
-lib/android.hardware.radio.config@1.0.so
-lib/android.hardware.radio.deprecated@1.0.so
-lib/android.hardware.radio@1.0.so
-lib/android.hardware.radio@1.1.so
-lib/android.hardware.radio@1.2.so
-lib/android.hardware.radio@1.3.so
-lib/android.hardware.radio@1.4.so
-lib/android.hardware.secure_element@1.0.so
-lib/com.android.media.aaudio-aconfig-cc.so
-lib/heapprofd_client.so
-lib/heapprofd_client_api.so
-lib/libaaudio.so
-lib/libaaudio_internal.so
-lib/libalarm_jni.so
-lib/libamidi.so
-lib/libcups.so
-lib/libjni_deviceAsWebcam.so
-lib/libprintspooler_jni.so
 lib/libvendorsupport.so
-lib/libwfds.so
-lib/libyuv.so
 
-# b/351258461
-adb_keys
+# b/353429422
 init.environ.rc
 
 # Known diffs only in the Soong system image
@@ -37,16 +14,4 @@
 lib/libuinputcommand_jni.so
 
 # Known diffs in internal source
-bin/uprobestats
-etc/aconfig/flag.map
-etc/aconfig/flag.val
-etc/aconfig/package.map
 etc/aconfig/flag.info
-etc/bpf/uprobestats/BitmapAllocation.o
-etc/bpf/uprobestats/GenericInstrumentation.o
-etc/bpf/uprobestats/ProcessManagement.o
-etc/init/UprobeStats.rc
-lib/libuprobestats_client.so
-lib64/libuprobestats_client.so
-priv-app/DeviceDiagnostics/DeviceDiagnostics.apk
-