|
23 | 23 | TARGET_SLOT="$1" |
24 | 24 | STATUS_FD="$2" |
25 | 25 |
|
| 26 | +# "1" if the script is triggered by the `UpdateEngine.triggerPostinstall` API. Empty otherwise. |
| 27 | +TRIGGERED_BY_API="$3" |
| 28 | + |
26 | 29 | # Maximum number of packages/steps. |
27 | 30 | MAXIMUM_PACKAGES=1000 |
28 | 31 |
|
|
53 | 56 | # A source that infinitely emits arbitrary lines. |
54 | 57 | # When connected to STDIN of another process, this source keeps STDIN open until |
55 | 58 | # 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. |
56 | 61 | function infinite_source { |
57 | 62 | while echo .; do |
58 | 63 | sleep 1 |
59 | 64 | done |
60 | 65 | } |
61 | 66 |
|
| 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 | + |
62 | 79 | PR_DEXOPT_JOB_VERSION="$(pm art pr-dexopt-job --version)" |
63 | 80 | if (( $? == 0 )) && (( $PR_DEXOPT_JOB_VERSION >= 3 )); then |
64 | 81 | # Delegate to Pre-reboot Dexopt, a feature of ART Service. |
65 | 82 | # ART Service decides what to do with this request: |
66 | 83 | # - 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. |
69 | 86 | # - 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. |
75 | 96 | if infinite_source | pm art on-ota-staged --slot "$TARGET_SLOT_SUFFIX"; then |
76 | 97 | # Handled by Pre-reboot Dexopt. |
77 | 98 | exit 0 |
|
0 commit comments