Andreas Gampe | 01ad598 | 2016-03-09 16:27:29 -0800 | [diff] [blame] | 1 | #!/system/bin/sh |
| 2 | |
| 3 | # |
| 4 | # Copyright (C) 2016 The Android Open Source Project |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | |
| 19 | # This script will run as a postinstall step to drive otapreopt. |
| 20 | |
Andreas Gampe | 0354bd0 | 2016-06-27 14:25:30 -0700 | [diff] [blame] | 21 | TARGET_SLOT="$1" |
Andreas Gampe | 6c05a73 | 2016-06-10 15:08:53 -0700 | [diff] [blame] | 22 | STATUS_FD="$2" |
| 23 | |
Andreas Gampe | 01ad598 | 2016-03-09 16:27:29 -0800 | [diff] [blame] | 24 | # Maximum number of packages/steps. |
| 25 | MAXIMUM_PACKAGES=1000 |
| 26 | |
Andreas Gampe | 0354bd0 | 2016-06-27 14:25:30 -0700 | [diff] [blame] | 27 | # Compute target slot suffix. |
| 28 | # TODO: Once bootctl is not restricted, we should query from there. Or get this from |
| 29 | # update_engine as a parameter. |
| 30 | if [ "$TARGET_SLOT" = "0" ] ; then |
| 31 | TARGET_SLOT_SUFFIX="_a" |
| 32 | elif [ "$TARGET_SLOT" = "1" ] ; then |
| 33 | TARGET_SLOT_SUFFIX="_b" |
| 34 | else |
| 35 | echo "Unknown target slot $TARGET_SLOT" |
| 36 | exit 1 |
| 37 | fi |
| 38 | |
| 39 | |
Andreas Gampe | 01ad598 | 2016-03-09 16:27:29 -0800 | [diff] [blame] | 40 | PREPARE=$(cmd otadexopt prepare) |
Andreas Gampe | 6c05a73 | 2016-06-10 15:08:53 -0700 | [diff] [blame] | 41 | # Note: Ignore preparation failures. Step and done will fail and exit this. |
| 42 | # This is necessary to support suspends - the OTA service will keep |
| 43 | # the state around for us. |
| 44 | |
| 45 | PROGRESS=$(cmd otadexopt progress) |
| 46 | print -u${STATUS_FD} "global_progress $PROGRESS" |
Andreas Gampe | 01ad598 | 2016-03-09 16:27:29 -0800 | [diff] [blame] | 47 | |
| 48 | i=0 |
| 49 | while ((i<MAXIMUM_PACKAGES)) ; do |
Andreas Gampe | 0354bd0 | 2016-06-27 14:25:30 -0700 | [diff] [blame] | 50 | DEXOPT_PARAMS=$(cmd otadexopt next) |
| 51 | |
| 52 | /system/bin/otapreopt_chroot $STATUS_FD $TARGET_SLOT_SUFFIX $DEXOPT_PARAMS >&- 2>&- |
Andreas Gampe | 6c05a73 | 2016-06-10 15:08:53 -0700 | [diff] [blame] | 53 | |
| 54 | PROGRESS=$(cmd otadexopt progress) |
| 55 | print -u${STATUS_FD} "global_progress $PROGRESS" |
| 56 | |
Andreas Gampe | 01ad598 | 2016-03-09 16:27:29 -0800 | [diff] [blame] | 57 | DONE=$(cmd otadexopt done) |
Andreas Gampe | 6c05a73 | 2016-06-10 15:08:53 -0700 | [diff] [blame] | 58 | if [ "$DONE" = "OTA incomplete." ] ; then |
| 59 | sleep 1 |
| 60 | i=$((i+1)) |
| 61 | continue |
Andreas Gampe | 01ad598 | 2016-03-09 16:27:29 -0800 | [diff] [blame] | 62 | fi |
Andreas Gampe | 6c05a73 | 2016-06-10 15:08:53 -0700 | [diff] [blame] | 63 | break |
Andreas Gampe | 01ad598 | 2016-03-09 16:27:29 -0800 | [diff] [blame] | 64 | done |
| 65 | |
| 66 | DONE=$(cmd otadexopt done) |
| 67 | if [ "$DONE" = "OTA incomplete." ] ; then |
| 68 | echo "Incomplete." |
| 69 | else |
| 70 | echo "Complete or error." |
| 71 | fi |
| 72 | |
Andreas Gampe | 6c05a73 | 2016-06-10 15:08:53 -0700 | [diff] [blame] | 73 | print -u${STATUS_FD} "global_progress 1.0" |
Andreas Gampe | 01ad598 | 2016-03-09 16:27:29 -0800 | [diff] [blame] | 74 | cmd otadexopt cleanup |
| 75 | |
| 76 | exit 0 |