From 02989bec7b681fa85b14b24fe2ae885c02cc6232 Mon Sep 17 00:00:00 2001 From: Jiakai Zhang Date: Wed, 28 Aug 2024 15:23:11 +0000 Subject: Revert "Disable Pre-reboot Dexopt." This reverts commit 3efe8ed909fefbd8207ec8b523a5eddbfcf549bf. Reason for revert: Problem fixed Bug: 356858364 Change-Id: I8e976a4e3f8120d672861b967a7765d23d1099a1 --- cmds/installd/otapreopt_script.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cmds/installd/otapreopt_script.sh b/cmds/installd/otapreopt_script.sh index 28bd7932a2..b7ad33144b 100644 --- a/cmds/installd/otapreopt_script.sh +++ b/cmds/installd/otapreopt_script.sh @@ -50,6 +50,37 @@ else exit 1 fi +# A source that infinitely emits arbitrary lines. +# When connected to STDIN of another process, this source keeps STDIN open until +# the consumer process closes STDIN or this script dies. +function infinite_source { + while echo .; do + sleep 1 + done +} + +PR_DEXOPT_JOB_VERSION="$(pm art pr-dexopt-job --version)" +if (( $? == 0 )) && (( $PR_DEXOPT_JOB_VERSION >= 3 )); then + # Delegate to Pre-reboot Dexopt, a feature of ART Service. + # ART Service decides what to do with this request: + # - If Pre-reboot Dexopt is disabled or unsupported, the command returns + # non-zero. This is always the case if the current system is Android 14 or + # earlier. + # - If Pre-reboot Dexopt is enabled in synchronous mode, the command blocks + # until Pre-reboot Dexopt finishes, and returns zero no matter it succeeds or + # not. This is the default behavior if the current system is Android 15. + # - If Pre-reboot Dexopt is enabled in asynchronous mode, the command schedules + # an asynchronous job and returns 0 immediately. The job will then run by the + # job scheduler when the device is idle and charging. + if infinite_source | pm art on-ota-staged --slot "$TARGET_SLOT_SUFFIX"; then + # Handled by Pre-reboot Dexopt. + exit 0 + fi + echo "Pre-reboot Dexopt not enabled. Fall back to otapreopt." +else + echo "Pre-reboot Dexopt is too old. Fall back to otapreopt." +fi + if [ "$(/system/bin/otapreopt_chroot --version)" != 2 ]; then # We require an updated chroot wrapper that reads dexopt commands from stdin. # Even if we kept compat with the old binary, the OTA preopt wouldn't work due -- cgit v1.2.3-59-g8ed1b