Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ca9d2427 authored by Jiakai Zhang's avatar Jiakai Zhang
Browse files

Remove old otapreopt code in otapreopt_script.sh.

otapreopt uses the legacy dexopt code in Package Manager and is replaced
by Pre-reboot Dexopt since Android V. This change is the first step to
completely remove the legacy dexopt code from Package Manager.

Bug: 258223472
Bug: 6527146
Test: Presubmit
Flag: EXEMPT cleanup

Change-Id: Iedee5eed940e68ea2f3bd051e0cc6002e2a2c12c
parent 8fa1c4c4
Loading
Loading
Loading
Loading
+4 −65
Original line number Diff line number Diff line
@@ -16,9 +16,8 @@
# limitations under the License.
#

# This script runs as a postinstall step to drive otapreopt. It comes with the
# OTA package, but runs /system/bin/otapreopt_chroot in the (old) active system
# image. See system/extras/postinst/postinst.sh for some docs.
# This script runs as a postinstall step to drive Pre-reboot Dexopt. During Pre-reboot Dexopt, the
# new version of this code is run. See system/extras/postinst/postinst.sh for some docs.

TARGET_SLOT="$1"
STATUS_FD="$2"
@@ -26,9 +25,6 @@ STATUS_FD="$2"
# "1" if the script is triggered by the `UpdateEngine.triggerPostinstall` API. Empty otherwise.
TRIGGERED_BY_API="$3"

# Maximum number of packages/steps.
MAXIMUM_PACKAGES=1000

# First ensure the system is booted. This is to work around issues when cmd would
# infinitely loop trying to get a service manager (which will never come up in that
# mode). b/30797145
@@ -97,64 +93,7 @@ if (( $? == 0 )) && (( $PR_DEXOPT_JOB_VERSION >= 3 )); then
    # Handled by Pre-reboot Dexopt.
    exit 0
  fi
  echo "Pre-reboot Dexopt not enabled. Fall back to otapreopt."
  echo "Pre-reboot Dexopt not enabled. Exiting."
else
  echo "Pre-reboot Dexopt is too old. Fall back to otapreopt."
fi

if [ "$(/system/bin/otapreopt_chroot --version)" != 2 ]; then
  # We require an updated chroot wrapper that reads dexopt commands from stdin.
  # Even if we kept compat with the old binary, the OTA preopt wouldn't work due
  # to missing sepolicy rules, so there's no use spending time trying to dexopt
  # (b/291974157).
  echo "$0: Current system image is too old to work with OTA preopt - skipping."
  exit 0
fi

PREPARE=$(cmd otadexopt prepare)
# Note: Ignore preparation failures. Step and done will fail and exit this.
#       This is necessary to support suspends - the OTA service will keep
#       the state around for us.

# Create an array with all dexopt commands in advance, to know how many there are.
otadexopt_cmds=()
while (( ${#otadexopt_cmds[@]} < MAXIMUM_PACKAGES )) ; do
  DONE=$(cmd otadexopt done)
  if [ "$DONE" = "OTA complete." ] ; then
    break
  echo "Pre-reboot Dexopt is too old. Exiting."
fi
  otadexopt_cmds+=("$(cmd otadexopt next)")
done

DONE=$(cmd otadexopt done)
cmd otadexopt cleanup

echo "$0: Using streaming otapreopt_chroot on ${#otadexopt_cmds[@]} packages"

function print_otadexopt_cmds {
  for cmd in "${otadexopt_cmds[@]}" ; do
    print "$cmd"
  done
}

function report_progress {
  while read count ; do
    # mksh can't do floating point arithmetic, so emulate a fixed point calculation.
    (( permilles = 1000 * count / ${#otadexopt_cmds[@]} ))
    printf 'global_progress %d.%03d\n' $((permilles / 1000)) $((permilles % 1000)) >&${STATUS_FD}
  done
}

print_otadexopt_cmds | \
  /system/bin/otapreopt_chroot $STATUS_FD $TARGET_SLOT_SUFFIX | \
  report_progress

if [ "$DONE" = "OTA incomplete." ] ; then
  echo "$0: Incomplete."
else
  echo "$0: Complete or error."
fi

print -u${STATUS_FD} "global_progress 1.0"

exit 0