Skip to content

Commit 46f66ef

Browse files
Merge "Update otapreopt_script to support Async Pre-reboot Dexopt." into main am: cf5a4f1
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/3465700 Change-Id: Icc842295bdcb8d3cb0931abfd12c5d9fc20ebf0c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2 parents cbec8f7 + cf5a4f1 commit 46f66ef

1 file changed

Lines changed: 28 additions & 7 deletions

File tree

cmds/installd/otapreopt_script.sh

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
TARGET_SLOT="$1"
2424
STATUS_FD="$2"
2525

26+
# "1" if the script is triggered by the `UpdateEngine.triggerPostinstall` API. Empty otherwise.
27+
TRIGGERED_BY_API="$3"
28+
2629
# Maximum number of packages/steps.
2730
MAXIMUM_PACKAGES=1000
2831

@@ -53,25 +56,43 @@ fi
5356
# A source that infinitely emits arbitrary lines.
5457
# When connected to STDIN of another process, this source keeps STDIN open until
5558
# the consumer process closes STDIN or this script dies.
59+
# In practice, the pm command keeps consuming STDIN, so we don't need to worry
60+
# about running out of buffer space.
5661
function infinite_source {
5762
while echo .; do
5863
sleep 1
5964
done
6065
}
6166

67+
if [[ "$TRIGGERED_BY_API" = "1" ]]; then
68+
# During OTA installation, the script is called the first time, and
69+
# `TRIGGERED_BY_API` can never be "1". `TRIGGERED_BY_API` being "1" means this
70+
# is the second call to this script, through the
71+
# `UpdateEngine.triggerPostinstall` API.
72+
# When we reach here, it means Pre-reboot Dexopt is enabled in asynchronous
73+
# mode and the job scheduler determined that it's the time to run the job.
74+
# Start Pre-reboot Dexopt now and wait for it to finish.
75+
infinite_source | pm art on-ota-staged --start
76+
exit $?
77+
fi
78+
6279
PR_DEXOPT_JOB_VERSION="$(pm art pr-dexopt-job --version)"
6380
if (( $? == 0 )) && (( $PR_DEXOPT_JOB_VERSION >= 3 )); then
6481
# Delegate to Pre-reboot Dexopt, a feature of ART Service.
6582
# ART Service decides what to do with this request:
6683
# - If Pre-reboot Dexopt is disabled or unsupported, the command returns
67-
# non-zero. This is always the case if the current system is Android 14 or
68-
# earlier.
84+
# non-zero.
85+
# This is always the case if the current system is Android 14 or earlier.
6986
# - If Pre-reboot Dexopt is enabled in synchronous mode, the command blocks
70-
# until Pre-reboot Dexopt finishes, and returns zero no matter it succeeds or
71-
# not. This is the default behavior if the current system is Android 15.
72-
# - If Pre-reboot Dexopt is enabled in asynchronous mode, the command schedules
73-
# an asynchronous job and returns 0 immediately. The job will then run by the
74-
# job scheduler when the device is idle and charging.
87+
# until Pre-reboot Dexopt finishes, and returns zero no matter it succeeds
88+
# or not.
89+
# This is the default behavior if the current system is Android 15.
90+
# - If Pre-reboot Dexopt is enabled in asynchronous mode, the command
91+
# schedules an asynchronous job and returns 0 immediately.
92+
# Later, when the device is idle and charging, the job will be run by the
93+
# job scheduler. It will call this script again through the
94+
# `UpdateEngine.triggerPostinstall` API, with `TRIGGERED_BY_API` being "1".
95+
# This is always the case if the current system is Android 16 or later.
7596
if infinite_source | pm art on-ota-staged --slot "$TARGET_SLOT_SUFFIX"; then
7697
# Handled by Pre-reboot Dexopt.
7798
exit 0

0 commit comments

Comments
 (0)