|
50 | 50 | exit 1 |
51 | 51 | fi |
52 | 52 |
|
| 53 | +# A source that infinitely emits arbitrary lines. |
| 54 | +# When connected to STDIN of another process, this source keeps STDIN open until |
| 55 | +# the consumer process closes STDIN or this script dies. |
| 56 | +function infinite_source { |
| 57 | + while echo .; do |
| 58 | + sleep 1 |
| 59 | + done |
| 60 | +} |
| 61 | + |
| 62 | +PR_DEXOPT_JOB_VERSION="$(pm art pr-dexopt-job --version)" |
| 63 | +if (( $? == 0 )) && (( $PR_DEXOPT_JOB_VERSION >= 3 )); then |
| 64 | + # Delegate to Pre-reboot Dexopt, a feature of ART Service. |
| 65 | + # ART Service decides what to do with this request: |
| 66 | + # - 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. |
| 69 | + # - 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. |
| 75 | + if infinite_source | pm art on-ota-staged --slot "$TARGET_SLOT_SUFFIX"; then |
| 76 | + # Handled by Pre-reboot Dexopt. |
| 77 | + exit 0 |
| 78 | + fi |
| 79 | + echo "Pre-reboot Dexopt not enabled. Fall back to otapreopt." |
| 80 | +else |
| 81 | + echo "Pre-reboot Dexopt is too old. Fall back to otapreopt." |
| 82 | +fi |
| 83 | + |
53 | 84 | if [ "$(/system/bin/otapreopt_chroot --version)" != 2 ]; then |
54 | 85 | # We require an updated chroot wrapper that reads dexopt commands from stdin. |
55 | 86 | # Even if we kept compat with the old binary, the OTA preopt wouldn't work due |
|
0 commit comments