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

Commit 8f8d9205 authored by Yi-Yo Chiang's avatar Yi-Yo Chiang
Browse files

adb-remount-test: Refactor restore()

The redefining of cleanup hooks are making the script rather difficult
to read. Instead of redefining restore() just to skip some parts of it,
let restore() check flags and conditionally execute cleanup code.

Bug: 243116800
Test: adb-remount-test
Change-Id: If9d627618b54e215200455e8133492670737571d
parent 1a0e4d0b
Loading
Loading
Loading
Loading
+37 −37
Original line number Diff line number Diff line
@@ -985,46 +985,53 @@ adb_sh ls -l /dev/block/by-name/ /dev/block/mapper/ </dev/null 2>/dev/null |
      LOG INFO "partition ${name} device ${device} size ${size}K"
  done

# If reboot too soon after fresh flash, could trip device update failure logic
if ${screen_wait}; then
  LOG WARNING "waiting for screen to come up. Consider --no-wait-screen option"
fi
if ! wait_for_screen && ${screen_wait}; then
  screen_wait=false
  LOG WARNING "not healthy, no launcher, skipping wait for screen"
fi

# Can we test remount -R command?
overlayfs_supported=true
if [ "orange" != "`get_property ro.boot.verifiedbootstate`" -o \
     "2" != "`get_property partition.system.verified`" ]; then
can_restore_verity=false

restore() {
  LOG INFO "restoring device"
  ${overlayfs_supported} || return 0
  inFastboot &&
    fastboot reboot &&
      adb_wait ${ADB_WAIT} ||
    adb_wait "${ADB_WAIT}" ||
    true
    if inAdb; then
  if ! inAdb; then
    LOG ERROR "expect adb device"
    return 1
  fi
  adb_root || true
  local reboot=false
  if surgically_wipe_overlayfs; then
        adb_reboot &&
        adb_wait ${ADB_WAIT}
    reboot=true
  fi
  if ${can_restore_verity}; then
    if ! adb enable-verity; then
      LOG ERROR "adb enable-verity"
      return 1
    fi
  }
else
  restore() {
    ${overlayfs_supported} || return 0
    inFastboot &&
      fastboot reboot &&
      adb_wait ${ADB_WAIT} ||
      true
    inAdb &&
      adb_root &&
      adb enable-verity >/dev/null 2>/dev/null &&
    LOG INFO "restored verity"
    reboot=true
  fi >&2
  if ${reboot}; then
    adb_reboot &&
      adb_wait ${ADB_WAIT}
      adb_wait "${ADB_WAIT}"
  fi
}

# If reboot too soon after fresh flash, could trip device update failure logic
if ${screen_wait}; then
  LOG WARNING "waiting for screen to come up. Consider --no-wait-screen option"
fi
if ! wait_for_screen && ${screen_wait}; then
  screen_wait=false
  LOG WARNING "not healthy, no launcher, skipping wait for screen"
fi

# Can we test remount -R command?
if [ "orange" = "$(get_property ro.boot.verifiedbootstate)" ] &&
   [ "2" = "$(get_property partition.system.verified)" ]; then
  can_restore_verity=true

  LOG RUN "Testing adb shell su root remount -R command"

  avc_check
@@ -1118,14 +1125,7 @@ echo "${D}" >&2
if [ X"${D}" = X"${D##* 100[%] }" ] && ${no_dedupe} ; then
  overlayfs_needed=false
  # if device does not need overlays, then adb enable-verity will brick device
  restore() {
    ${overlayfs_supported} || return 0
    inFastboot &&
      fastboot reboot &&
      adb_wait ${ADB_WAIT}
    inAdb &&
      adb_wait ${ADB_WAIT}
  }
  can_restore_verity=false
elif ! ${overlayfs_supported}; then
  die "need overlayfs, but do not have it"
fi