otapreopt_script.sh 2.4 KB

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