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

Android 15.0.0 Release 32 (BP1A.250505.005)

Change-Id: I289076d5f255623ceb3bc67b7ec8d8a120c416ee

# -----BEGIN PGP SIGNATURE-----
#
# iF0EABECAB0WIQRDQNE1cO+UXoOBCWTorT+BmrEOeAUCaBqG7wAKCRDorT+BmrEO
# eIvuAJ9+WvHO4Lqn+2pvGsw9vgZEnqr+XwCeJqVT+9TpFAqBLShgGwY0pygbUfs=
# =B498
# -----END PGP SIGNATURE-----
# gpg: Signature faite le mar 06 mai 2025 18:02:23 EDT
# gpg:                avec la clef DSA 4340D13570EF945E83810964E8AD3F819AB10E78
# gpg: Impossible de vérifier la signature : Pas de clef publique
diff --git a/Android.bp b/Android.bp
index dd9b02e..759b9e2 100644
--- a/Android.bp
+++ b/Android.bp
@@ -211,6 +211,7 @@
         "libfec",
         "liblz4",
         "libziparchive",
+        "libselinux",
     ],
 }
 
@@ -293,6 +294,7 @@
         "ue_defaults",
         "libpayload_consumer_exports",
         "libpayload_consumer_defaults",
+        "omni_weekly_build_defaults",
     ],
 }
 
@@ -302,6 +304,7 @@
         "ue_defaults",
         "libpayload_consumer_exports_proto-full",
         "libpayload_consumer_defaults",
+        "omni_weekly_build_defaults",
     ],
 }
 
diff --git a/payload_consumer/postinstall_runner_action.cc b/payload_consumer/postinstall_runner_action.cc
index 5a6eeab..1f423a9 100644
--- a/payload_consumer/postinstall_runner_action.cc
+++ b/payload_consumer/postinstall_runner_action.cc
@@ -19,6 +19,7 @@
 #include <fcntl.h>
 #include <signal.h>
 #include <stdlib.h>
+#include <selinux/selinux.h>
 #include <sys/mount.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -179,6 +180,75 @@
   EnsureUnmounted();
 
 #ifdef __ANDROID__
+#ifdef USE_WEEKLY_BUILD
+  // Check the currently installed /system partition to see if it's ever
+  // been mounted R/W. If it has, we'll run backuptool scripts for it
+  // since we can safely assume something on the partition has been
+  // changed and we won't be breaking verity (since it's already been
+  // broken). If it hasn't ever been mounted R/W, we can assume that
+  // the rom that the user is upgrading to will have everything they
+  // need and no addon.d scripts will need to be run to retain stuff
+  // after the upgrade.
+  //
+  // Use the following disk layout info to make the determination
+  // https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout
+  // Super block starts from block 0, offset 0x400
+  //   0x2C: len32 Mount time
+  //   0x30: len32 Write time
+  //   0x34: len16 Number of mounts since the last fsck
+  //   0x38: len16 Magic signature 0xEF53
+
+  string source_path;
+
+  if (install_plan_.source_slot != BootControlInterface::kInvalidSlot) {
+    boot_control_->GetPartitionDevice(partition.name, install_plan_.source_slot, &source_path);
+  }
+
+  uint16_t mount_count = 0;
+
+  if (!source_path.empty()) {
+    brillo::Blob chunk;
+
+    utils::ReadFileChunk(source_path, 0x400 + 0x34, sizeof(uint16_t), &chunk);
+    mount_count = *reinterpret_cast<uint16_t*>(chunk.data());
+  }
+
+  LOG(INFO) << source_path << " has been mounted R/W " << mount_count << " times.";
+
+  if (mount_count > 0) {
+    if (!utils::SetBlockDeviceReadOnly(mountable_device, false)) {
+      LOG(ERROR) << "Error marking the device " << mountable_device << " writeable.";
+      return false;
+    }
+    // Mount the target partition R/W
+    LOG(INFO) << "Running backuptool scripts";
+    utils::MountFilesystem(mountable_device, fs_mount_dir_, MS_NOATIME | MS_NODEV | MS_NODIRATIME,
+                           partition.filesystem_type, "seclabel");
+
+    // Switch to a permissive domain
+    if (setexeccon("u:r:backuptool:s0")) {
+      LOG(ERROR) << "Failed to set backuptool context";
+      return false;
+    }
+
+    // Run backuptool script
+    int ret = system("/postinstall/system/bin/backuptool_postinstall.sh");
+    if (ret == -1 || WEXITSTATUS(ret) != 0) {
+      LOG(ERROR) << "Backuptool postinstall step failed. ret=" << ret;
+    }
+
+    // Switch back to update_engine domain
+    if (setexeccon(nullptr)) {
+      LOG(ERROR) << "Failed to set update_engine context";
+      return false;
+    }
+  } else {
+    LOG(INFO) << "Skipping backuptool scripts";
+  }
+
+  utils::UnmountFilesystem(fs_mount_dir_);
+#endif  // USE_WEEKLY_BUILD
+
   // In Chromium OS, the postinstall step is allowed to write to the block
   // device on the target image, so we don't mark it as read-only and should
   // be read-write since we just wrote to it during the update.
diff --git a/update_engine.rc b/update_engine.rc
index 45f05af..4f497a7 100644
--- a/update_engine.rc
+++ b/update_engine.rc
@@ -3,7 +3,7 @@
     class late_start
     user root
     group root system wakelock inet cache media_rw
-    task_profiles OtaProfiles
+    task_profiles ProcessCapacityMax HighIoPriority MaxPerformance
     disabled
 
 on property:ro.boot.slot_suffix=*