Merge tag 'android-15.0.0_r14' of https://android.googlesource.com/platform/system/core into HEAD

Android 15.0.0 Release 14 (AP4A.250205.002)

Change-Id: Ifb193c2cb5765bc833e4bf33ba1d6ae645423f02

# -----BEGIN PGP SIGNATURE-----
#
# iF0EABECAB0WIQRDQNE1cO+UXoOBCWTorT+BmrEOeAUCZ6KKkQAKCRDorT+BmrEO
# eJGvAJ9LFzDH9Bc8ZfcBE7rlzaCpbSgoJQCeImt0uAic0coI65/qnUCfwUwToQw=
# =vwD5
# -----END PGP SIGNATURE-----
# gpg: Signature faite le mar 04 fév 2025 16:45:53 EST
# gpg:                avec la clef DSA 4340D13570EF945E83810964E8AD3F819AB10E78
# gpg: Impossible de vérifier la signature : Pas de clef publique
diff --git a/fastboot/device/utility.cpp b/fastboot/device/utility.cpp
index e12ee64..0652d93 100644
--- a/fastboot/device/utility.cpp
+++ b/fastboot/device/utility.cpp
@@ -195,7 +195,7 @@
 }
 
 bool GetDeviceLockStatus() {
-    return android::base::GetProperty("ro.boot.verifiedbootstate", "") != "orange";
+    return false;
 }
 
 bool UpdateAllPartitionMetadata(FastbootDevice* device, const std::string& super_name,
diff --git a/fs_mgr/fs_mgr_remount.cpp b/fs_mgr/fs_mgr_remount.cpp
index f91d232..30a111a 100644
--- a/fs_mgr/fs_mgr_remount.cpp
+++ b/fs_mgr/fs_mgr_remount.cpp
@@ -635,10 +635,12 @@
         return EXIT_FAILURE;
     }
 
+#if ALLOW_ADBD_DISABLE_VERITY == 0  // "user" build
     if (android::base::GetProperty("ro.boot.verifiedbootstate", "") != "orange") {
         LOG(ERROR) << "Device must be bootloader unlocked";
         return EXIT_FAILURE;
     }
+#endif
 
     // Start a threadpool to service waitForService() callbacks as
     // fs_mgr_overlayfs_* might call waitForService() to get the image service.
diff --git a/fs_mgr/libfstab/fstab.cpp b/fs_mgr/libfstab/fstab.cpp
index d344b2d..45ffdc8 100644
--- a/fs_mgr/libfstab/fstab.cpp
+++ b/fs_mgr/libfstab/fstab.cpp
@@ -211,6 +211,7 @@
         CheckFlag("metadata_csum", ext_meta_csum);
         CheckFlag("fscompress", fs_compress);
         CheckFlag("overlayfs_remove_missing_lowerdir", overlayfs_remove_missing_lowerdir);
+        CheckFlag("wrappedkey", wrapped_key);
 
 #undef CheckFlag
 
diff --git a/fs_mgr/libfstab/include/fstab/fstab.h b/fs_mgr/libfstab/include/fstab/fstab.h
index 21fe017..368804f 100644
--- a/fs_mgr/libfstab/include/fstab/fstab.h
+++ b/fs_mgr/libfstab/include/fstab/fstab.h
@@ -86,6 +86,7 @@
         bool fs_compress : 1;
         bool overlayfs_remove_missing_lowerdir : 1;
         bool is_zoned : 1;
+        bool wrapped_key : 1;
     } fs_mgr_flags = {};
 
     bool is_encryptable() const { return fs_mgr_flags.crypt; }
diff --git a/healthd/Android.bp b/healthd/Android.bp
index e158e07..1228b23 100644
--- a/healthd/Android.bp
+++ b/healthd/Android.bp
@@ -73,7 +73,10 @@
 
 cc_library_static {
     name: "libbatterymonitor",
-    defaults: ["libbatterymonitor_defaults"],
+    defaults: [
+        "libbatterymonitor_defaults",
+        "use_battery_info_defaults",
+    ],
     srcs: ["BatteryMonitor.cpp"],
     static_libs: [
         "android.hardware.health-V3-ndk",
@@ -88,7 +91,10 @@
 // TODO(b/251425963): remove when android.hardware.health is upgraded to V2.
 cc_library_static {
     name: "libbatterymonitor-V1",
-    defaults: ["libbatterymonitor_defaults"],
+    defaults: [
+        "libbatterymonitor_defaults",
+        "use_battery_info_defaults",
+    ],
     srcs: ["BatteryMonitor_v1.cpp"],
     static_libs: [
         "android.hardware.health-V1-ndk",
diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp
index b8bb586..799bbea 100644
--- a/healthd/BatteryMonitor.cpp
+++ b/healthd/BatteryMonitor.cpp
@@ -50,6 +50,10 @@
 #define FAKE_BATTERY_TEMPERATURE 424
 #define MILLION 1.0e6
 #define DEFAULT_VBUS_VOLTAGE 5000000
+#ifdef HEALTHD_USE_BATTERY_INFO
+#define SYSFS_BATTERY_CURRENT "/sys/class/power_supply/battery/current_now"
+#define SYSFS_BATTERY_VOLTAGE "/sys/class/power_supply/battery/voltage_now"
+#endif
 
 using HealthInfo_1_0 = android::hardware::health::V1_0::HealthInfo;
 using HealthInfo_2_0 = android::hardware::health::V2_0::HealthInfo;
@@ -306,6 +310,7 @@
             {"USB", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_USB},
             {"USB_DCP", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_AC},
             {"USB_HVDCP", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_AC},
+            {"USB_HVDCP_3", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_AC},
             {"USB_CDP", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_AC},
             {"USB_ACA", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_AC},
             {"USB_C", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_AC},
@@ -313,6 +318,7 @@
             {"USB_PD_DRP", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_USB},
             {"Wireless", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_WIRELESS},
             {"Dock", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_DOCK},
+            {"DASH", BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_AC},
             {NULL, 0},
     };
     std::string buf;
@@ -322,10 +328,8 @@
     }
 
     auto ret = mapSysfsString(buf.c_str(), supplyTypeMap);
-    if (!ret) {
-        KLOG_WARNING(LOG_TAG, "Unknown power supply type '%s'\n", buf.c_str());
+    if (!ret)
         *ret = BatteryMonitor::ANDROID_POWER_SUPPLY_TYPE_UNKNOWN;
-    }
 
     return static_cast<BatteryMonitor::PowerSupplyType>(*ret);
 }
@@ -444,6 +448,52 @@
 
     double MaxPower = 0;
 
+    // Rescan for the available charger types
+    std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(POWER_SUPPLY_SYSFS_PATH), closedir);
+    if (dir == NULL) {
+        KLOG_ERROR(LOG_TAG, "Could not open %s\n", POWER_SUPPLY_SYSFS_PATH);
+    } else {
+        struct dirent* entry;
+        String8 path;
+
+        mChargerNames.clear();
+
+        while ((entry = readdir(dir.get()))) {
+            const char* name = entry->d_name;
+
+            if (!strcmp(name, ".") || !strcmp(name, ".."))
+                continue;
+
+            // Look for "type" file in each subdirectory
+            path.clear();
+            path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, name);
+            switch(readPowerSupplyType(path)) {
+            case ANDROID_POWER_SUPPLY_TYPE_AC:
+            case ANDROID_POWER_SUPPLY_TYPE_USB:
+            case ANDROID_POWER_SUPPLY_TYPE_WIRELESS:
+            case ANDROID_POWER_SUPPLY_TYPE_DOCK:
+                path.clear();
+                path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name);
+                if (access(path.c_str(), R_OK) == 0)
+                    mChargerNames.add(String8(name));
+                break;
+            default:
+                break;
+            }
+
+            // Look for "is_dock" file
+            path.clear();
+            path.appendFormat("%s/%s/is_dock", POWER_SUPPLY_SYSFS_PATH, name);
+            if (access(path.c_str(), R_OK) == 0) {
+                path.clear();
+                path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name);
+                if (access(path.c_str(), R_OK) == 0)
+                    mChargerNames.add(String8(name));
+
+            }
+        }
+    }
+
     for (size_t i = 0; i < mChargerNames.size(); i++) {
         String8 path;
         path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].c_str());
@@ -473,6 +523,14 @@
                     KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n",
                                  mChargerNames[i].c_str());
             }
+
+#ifdef HEALTHD_USE_BATTERY_INFO
+            int ChargingCurrent = (access(SYSFS_BATTERY_CURRENT, R_OK) == 0) ?
+                    abs(getIntField(String8(SYSFS_BATTERY_CURRENT))) : 0;
+
+            int ChargingVoltage = (access(SYSFS_BATTERY_VOLTAGE, R_OK) == 0) ?
+                    getIntField(String8(SYSFS_BATTERY_VOLTAGE)) : DEFAULT_VBUS_VOLTAGE;
+#else
             path.clear();
             path.appendFormat("%s/%s/current_max", POWER_SUPPLY_SYSFS_PATH,
                               mChargerNames[i].c_str());
@@ -484,6 +542,7 @@
 
             int ChargingVoltage =
                     (access(path.c_str(), R_OK) == 0) ? getIntField(path) : DEFAULT_VBUS_VOLTAGE;
+#endif
 
             double power = ((double)ChargingCurrent / MILLION) *
                            ((double)ChargingVoltage / MILLION);
diff --git a/healthd/healthd_draw.cpp b/healthd/healthd_draw.cpp
index 7c79319..481f785 100644
--- a/healthd/healthd_draw.cpp
+++ b/healthd/healthd_draw.cpp
@@ -224,9 +224,28 @@
     int x, y;
     determine_xy(field, str.size(), &x, &y);
 
-    LOGV("drawing percent %s %d %d\n", str.c_str(), x, y);
-    gr_color(field.color_r, field.color_g, field.color_b, field.color_a);
-    draw_text(field.font, x, y, str.c_str());
+  int batt_height = 0;
+  // get height of battery image to draw text below
+  const animation::frame& frame = anim->frames[anim->cur_frame];
+  if (anim->num_frames != 0) {
+      // nothing else should happen actually
+      batt_height = gr_get_height(frame.surface);
+  }
+  // draw it below the battery image
+  y = (gr_fb_height() + batt_height) / 2 + char_height_ * 2;
+
+  if (cur_level < 15) {
+      gr_color(255, 0, 0, 255); // red
+  } else if (cur_level < 50) {
+      gr_color(255, 128, 0, 255); // orange
+  } else if (cur_level < 90) {
+      gr_color(field.color_r, field.color_g, field.color_b, field.color_a);
+  } else { // cur_level >= 90
+      gr_color(0, 255, 0, 255); // green
+  }
+
+  LOGV("drawing percent %s %d %d\n", str.c_str(), x, y);
+  draw_text(field.font, x, y, str.c_str());
 }
 
 void HealthdDraw::draw_battery(const animation* anim) {
diff --git a/init/Android.bp b/init/Android.bp
index 18a79d6..d2f3915 100644
--- a/init/Android.bp
+++ b/init/Android.bp
@@ -212,6 +212,7 @@
     defaults: [
         "init_defaults",
         "selinux_policy_version",
+        "vendor_init_defaults",
     ],
     srcs: init_common_sources + init_device_sources,
     export_include_dirs: ["."],
@@ -245,6 +246,15 @@
 }
 
 cc_library_static {
+    name: "vendor_init",
+    ramdisk_available: true,
+    recovery_available: true,
+    srcs: [
+        "vendor_init.cpp",
+    ],
+}
+
+cc_library_static {
     name: "libinit",
     defaults: ["libinit_defaults"],
 }
@@ -270,7 +280,10 @@
     name: "init_second_stage_defaults",
     recovery_available: true,
     stem: "init",
-    defaults: ["init_defaults"],
+    defaults: [
+        "init_defaults",
+        "vendor_init_defaults",
+    ],
     srcs: ["main.cpp"],
     symlinks: ["ueventd"],
 }
@@ -461,7 +474,10 @@
 
 cc_binary {
     name: "init_first_stage",
-    defaults: ["init_first_stage_defaults"],
+    defaults: [
+        "init_first_stage_defaults",
+        "vendor_init_defaults",
+    ],
 }
 
 cc_binary {
@@ -469,6 +485,7 @@
     defaults: [
         "avf_build_flags_cc",
         "init_first_stage_defaults",
+        "vendor_init_defaults",
     ],
     cflags: ["-DMICRODROID=1"],
     no_full_install: true,
diff --git a/init/devices.cpp b/init/devices.cpp
index f2bb9d2..7d5a442 100644
--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -42,6 +42,10 @@
 #include "selabel.h"
 #include "util.h"
 
+#ifdef TARGET_CREATE_DEVICE_SYMLINKS
+#include "vendor_init.h"
+#endif
+
 using namespace std::chrono_literals;
 
 using android::base::Basename;
@@ -438,6 +442,10 @@
         links.emplace_back("/dev/sys/block/by-name/zoned_device");
     }
 
+#ifdef TARGET_CREATE_DEVICE_SYMLINKS
+    vendor_create_device_symlinks(uevent.partition_num, uevent.device_name, links);
+#endif
+
     auto last_slash = uevent.path.rfind('/');
     links.emplace_back(link_path + "/" + uevent.path.substr(last_slash + 1));
 
diff --git a/init/first_stage_mount.cpp b/init/first_stage_mount.cpp
index c26b31e..6d85c58 100644
--- a/init/first_stage_mount.cpp
+++ b/init/first_stage_mount.cpp
@@ -456,9 +456,14 @@
             return false;
         }
     }
-    if (!SetUpDmVerity(&(*begin))) {
-        PLOG(ERROR) << "Failed to setup verity for '" << begin->mount_point << "'";
-        return false;
+
+    if (begin->fs_mgr_flags.avb) {
+        if (!SetUpDmVerity(&(*begin))) {
+            PLOG(ERROR) << "Failed to setup verity for '" << begin->mount_point << "'";
+            return false;
+        }
+    } else {
+        LOG(INFO) << "AVB is not enabled, skip verity setup for '" << begin->mount_point << "'";
     }
 
     bool mounted = (fs_mgr_do_mount_one(*begin) == 0);
diff --git a/init/property_service.cpp b/init/property_service.cpp
index f2606e3..e7c719c 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -74,6 +74,7 @@
 #include "subcontext.h"
 #include "system/core/init/property_service.pb.h"
 #include "util.h"
+#include "vendor_init.h"
 
 static constexpr char APPCOMPAT_OVERRIDE_PROP_FOLDERNAME[] =
         "/dev/__properties__/appcompat_override";
@@ -1465,6 +1466,10 @@
             }
             InitPropertySet("ro.persistent_properties.ready", "true");
             persistent_properties_loaded = true;
+
+            /* vendor-specific properties
+            */
+            vendor_load_properties();
             break;
         }
         default:
diff --git a/init/reboot.cpp b/init/reboot.cpp
index ef9db9f..56226e8 100644
--- a/init/reboot.cpp
+++ b/init/reboot.cpp
@@ -869,16 +869,18 @@
                 }
             } else if (reboot_target == "recovery") {
                 bootloader_message boot = {};
-                if (std::string err; !read_bootloader_message(&boot, &err)) {
-                    LOG(ERROR) << "Failed to read bootloader message: " << err;
-                }
-                // Update the boot command field if it's empty, and preserve
-                // the other arguments in the bootloader message.
-                if (!CommandIsPresent(&boot)) {
-                    strlcpy(boot.command, "boot-recovery", sizeof(boot.command));
-                    if (std::string err; !write_bootloader_message(boot, &err)) {
-                        LOG(ERROR) << "Failed to set bootloader message: " << err;
-                        return;
+                if (std::string err; !get_misc_blk_device(&err).empty()) {
+                    if (std::string err; !read_bootloader_message(&boot, &err)) {
+                        LOG(ERROR) << "Failed to read bootloader message: " << err;
+                    }
+                    // Update the boot command field if it's empty, and preserve
+                    // the other arguments in the bootloader message.
+                    if (!CommandIsPresent(&boot)) {
+                        strlcpy(boot.command, "boot-recovery", sizeof(boot.command));
+                        if (std::string err; !write_bootloader_message(boot, &err)) {
+                            LOG(ERROR) << "Failed to set bootloader message: " << err;
+                            return;
+                        }
                     }
                 }
             } else if (std::find(cmd_params.begin(), cmd_params.end(), "quiescent")
diff --git a/init/service.cpp b/init/service.cpp
index d76a5d5..102423a 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -99,13 +99,16 @@
         free(new_con);
     }
     if (rc == 0 && computed_context == mycon.get()) {
-        return Error() << "File " << service_path << "(labeled \"" << filecon.get()
-                       << "\") has incorrect label or no domain transition from " << mycon.get()
-                       << " to another SELinux domain defined. Have you configured your "
-                          "service correctly? https://source.android.com/security/selinux/"
-                          "device-policy#label_new_services_and_address_denials. Note: this "
-                          "error shows up even in permissive mode in order to make auditing "
-                          "denials possible.";
+        std::string error = StringPrintf(
+                "File %s (labeled \"%s\") has incorrect label or no domain transition from %s to "
+                "another SELinux domain defined. Have you configured your "
+                "service correctly? https://source.android.com/security/selinux/"
+                "device-policy#label_new_services_and_address_denials",
+                service_path.c_str(), filecon.get(), mycon.get());
+        if (security_getenforce() != 0) {
+            return Error() << error;
+        }
+        LOG(ERROR) << error;
     }
     if (rc < 0) {
         return Error() << "Could not get process context";
diff --git a/init/vendor_init.cpp b/init/vendor_init.cpp
new file mode 100644
index 0000000..e4b1268
--- /dev/null
+++ b/init/vendor_init.cpp
@@ -0,0 +1,48 @@
+/*
+Copyright (c) 2013, The Linux Foundation. All rights reserved.
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+    * Neither the name of The Linux Foundation nor the names of its
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "vendor_init.h"
+
+namespace android {
+namespace init {
+
+/* init vendor override stubs */
+
+__attribute__ ((weak))
+void vendor_load_properties()
+{
+}
+
+#ifdef TARGET_CREATE_DEVICE_SYMLINKS
+__attribute__ ((weak))
+void vendor_create_device_symlinks(int, std::string, std::vector<std::string>&)
+{
+}
+#endif
+
+}
+}
diff --git a/init/vendor_init.h b/init/vendor_init.h
new file mode 100644
index 0000000..0bae2db
--- /dev/null
+++ b/init/vendor_init.h
@@ -0,0 +1,44 @@
+/*
+Copyright (c) 2013, The Linux Foundation. All rights reserved.
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+    * Neither the name of The Linux Foundation nor the names of its
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __INIT_VENDOR__H__
+#define __INIT_VENDOR__H__
+
+#include <string>
+
+namespace android {
+namespace init {
+
+extern void vendor_load_properties(void);
+
+#ifdef TARGET_CREATE_DEVICE_SYMLINKS
+extern void vendor_create_device_symlinks(int partNum, std::string partName, std::vector<std::string>& links);
+#endif
+
+}
+}
+#endif /* __INIT_VENDOR__H__ */
diff --git a/libcutils/canned_fs_config.cpp b/libcutils/canned_fs_config.cpp
index b677949..0e0f871 100644
--- a/libcutils/canned_fs_config.cpp
+++ b/libcutils/canned_fs_config.cpp
@@ -86,7 +86,7 @@
             // Historical: there can be tokens like "selabel=..." here. They have been ignored.
             // It's not an error because selabels are applied separately in e2fsdroid using the
             // file_contexts files set via -S option.
-            std::cerr << "info: ignored token \"" << sv << "\" in " << fn << std::endl;
+            // std::cerr << "info: ignored token \"" << sv << "\" in " << fn << std::endl;
         }
 
         canned_data.emplace_back(std::move(e));