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
21# Maximum number of packages/steps.
22MAXIMUM_PACKAGES=1000
23
24PREPARE=$(cmd otadexopt prepare)
25if [ "$PREPARE" != "Success" ] ; then
26  echo "Failed to prepare."
27  exit 1
28fi
29
30i=0
31while ((i<MAXIMUM_PACKAGES)) ; do
32  cmd otadexopt step
33  DONE=$(cmd otadexopt done)
34  if [ "$DONE" = "OTA complete." ] ; then
35    break
36  fi
37  sleep 1
38  i=$((i+1))
39done
40
41DONE=$(cmd otadexopt done)
42if [ "$DONE" = "OTA incomplete." ] ; then
43  echo "Incomplete."
44else
45  echo "Complete or error."
46fi
47
48cmd otadexopt cleanup
49
50exit 0
51