blob: f950276090090d3147292d9def4581e152380561 [file] [log] [blame]
Andreas Gampe01ad5982016-03-09 16:27:29 -08001#!/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 Gampe0354bd02016-06-27 14:25:30 -070021TARGET_SLOT="$1"
Andreas Gampe6c05a732016-06-10 15:08:53 -070022STATUS_FD="$2"
23
Andreas Gampe01ad5982016-03-09 16:27:29 -080024# Maximum number of packages/steps.
25MAXIMUM_PACKAGES=1000
26
Andreas Gampe90ba9eb2016-08-16 17:43:33 -070027# First ensure the system is booted. This is to work around issues when cmd would
28# infinitely loop trying to get a service manager (which will never come up in that
29# mode). b/30797145
30BOOT_PROPERTY_NAME="dev.bootcomplete"
31
32BOOT_COMPLETE=$(getprop $BOOT_PROPERTY_NAME)
33if [ "$BOOT_COMPLETE" != "1" ] ; then
34 echo "Error: boot-complete not detected."
35 # We must return 0 to not block sideload.
36 exit 0
37fi
38
39
Andreas Gampe0354bd02016-06-27 14:25:30 -070040# Compute target slot suffix.
41# TODO: Once bootctl is not restricted, we should query from there. Or get this from
42# update_engine as a parameter.
43if [ "$TARGET_SLOT" = "0" ] ; then
44 TARGET_SLOT_SUFFIX="_a"
45elif [ "$TARGET_SLOT" = "1" ] ; then
46 TARGET_SLOT_SUFFIX="_b"
47else
48 echo "Unknown target slot $TARGET_SLOT"
49 exit 1
50fi
51
52
Andreas Gampe01ad5982016-03-09 16:27:29 -080053PREPARE=$(cmd otadexopt prepare)
Andreas Gampe6c05a732016-06-10 15:08:53 -070054# Note: Ignore preparation failures. Step and done will fail and exit this.
55# This is necessary to support suspends - the OTA service will keep
56# the state around for us.
57
58PROGRESS=$(cmd otadexopt progress)
59print -u${STATUS_FD} "global_progress $PROGRESS"
Andreas Gampe01ad5982016-03-09 16:27:29 -080060
61i=0
62while ((i<MAXIMUM_PACKAGES)) ; do
Andreas Gampe0354bd02016-06-27 14:25:30 -070063 DEXOPT_PARAMS=$(cmd otadexopt next)
64
65 /system/bin/otapreopt_chroot $STATUS_FD $TARGET_SLOT_SUFFIX $DEXOPT_PARAMS >&- 2>&-
Andreas Gampe6c05a732016-06-10 15:08:53 -070066
67 PROGRESS=$(cmd otadexopt progress)
68 print -u${STATUS_FD} "global_progress $PROGRESS"
69
Andreas Gampe01ad5982016-03-09 16:27:29 -080070 DONE=$(cmd otadexopt done)
Andreas Gampe6c05a732016-06-10 15:08:53 -070071 if [ "$DONE" = "OTA incomplete." ] ; then
72 sleep 1
73 i=$((i+1))
74 continue
Andreas Gampe01ad5982016-03-09 16:27:29 -080075 fi
Andreas Gampe6c05a732016-06-10 15:08:53 -070076 break
Andreas Gampe01ad5982016-03-09 16:27:29 -080077done
78
79DONE=$(cmd otadexopt done)
80if [ "$DONE" = "OTA incomplete." ] ; then
81 echo "Incomplete."
82else
83 echo "Complete or error."
84fi
85
Andreas Gampe6c05a732016-06-10 15:08:53 -070086print -u${STATUS_FD} "global_progress 1.0"
Andreas Gampe01ad5982016-03-09 16:27:29 -080087cmd otadexopt cleanup
88
89exit 0