From 99e2b263dd0df71b55e86f0aec6657eb38b334e1 Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Sat, 9 Jul 2016 11:44:12 -0700 Subject: [PATCH] Otapreopt: Add init script for A/B artifact move Move the /data/ota -> /data/dalvik-cache move from the zygote into a minimal shell script. Add an init rc file to execute the script once /data is mounted. Add Makefile rules to pull these files in with the rest of the A/B OTA dexopt components. The move is motivated by the new naming scheme that includes the slot name. Passing the slot name to the zygote would complicate the process, while the value is immediately available in the script through a simple getprop call. Bug: 25612095 Bug: 28069686 Change-Id: I63e718d488662e1b1de2ce857629cb90aa4f611d --- cmds/installd/Android.mk | 17 ++++++++++++++--- cmds/installd/otapreopt.rc | 8 ++++++++ cmds/installd/otapreopt_slot.sh | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 cmds/installd/otapreopt.rc create mode 100644 cmds/installd/otapreopt_slot.sh diff --git a/cmds/installd/Android.mk b/cmds/installd/Android.mk index d35099a837..86df596c64 100644 --- a/cmds/installd/Android.mk +++ b/cmds/installd/Android.mk @@ -96,6 +96,17 @@ LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk LOCAL_CLANG := true include $(BUILD_EXECUTABLE) +# OTA slot script + +include $(CLEAR_VARS) +LOCAL_MODULE:= otapreopt_slot +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := EXECUTABLES +LOCAL_SRC_FILES := otapreopt_slot.sh +LOCAL_INIT_RC := otapreopt.rc + +include $(BUILD_PREBUILT) + # OTA postinstall script include $(CLEAR_VARS) @@ -104,9 +115,9 @@ LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := EXECUTABLES LOCAL_SRC_FILES := otapreopt_script.sh -# Let this depend on otapreopt and the chroot tool, so we just have to mention one in a -# configuration. -LOCAL_REQUIRED_MODULES := otapreopt otapreopt_chroot +# Let this depend on otapreopt, the chroot tool and the slot script, so we just have to mention one +# in a configuration. +LOCAL_REQUIRED_MODULES := otapreopt otapreopt_chroot otapreopt_slot include $(BUILD_PREBUILT) diff --git a/cmds/installd/otapreopt.rc b/cmds/installd/otapreopt.rc new file mode 100644 index 0000000000..059ae752e7 --- /dev/null +++ b/cmds/installd/otapreopt.rc @@ -0,0 +1,8 @@ +# When /data is available, look for A/B artifacts for the current slot and move them +# into the dalvik-cache (relabeling them). +on post-fs-data + exec - root -- /system/bin/otapreopt_slot + # The dalvik-cache was not moved itself, so as to restrict the rights of otapreopt_slot. + # But now the relabeling is annoying as there is no force option available here. So + # explicitly list all the ISAs we know. + restorecon_recursive /data/dalvik-cache/arm /data/dalvik-cache/arm64 /data/dalvik-cache/mips /data/dalvik-cache/mips64 /data/dalvik-cache/x86 /data/dalvik-cache/x86_64 diff --git a/cmds/installd/otapreopt_slot.sh b/cmds/installd/otapreopt_slot.sh new file mode 100644 index 0000000000..d51ab706e6 --- /dev/null +++ b/cmds/installd/otapreopt_slot.sh @@ -0,0 +1,36 @@ +#!/system/bin/sh + +# +# Copyright (C) 2016 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# This script will move artifacts for the currently active slot. + +SLOT_SUFFIX=$(getprop ro.boot.slot_suffix) +if test -n "$SLOT_SUFFIX" ; then + if test -d /data/ota/$SLOT_SUFFIX/dalvik-cache ; then + log -p i -t otapreopt_slot "Moving A/B artifacts for slot ${SLOT_SUFFIX}." + rm -rf /data/dalvik-cache/* + mv /data/ota/$SLOT_SUFFIX/dalvik-cache/* /data/dalvik-cache/ + rmdir /data/ota/$SLOT_SUFFIX/dalvik-cache + rmdir /data/ota/$SLOT_SUFFIX + else + log -p i -t otapreopt_slot "No A/B artifacts found for slot ${SLOT_SUFFIX}." + fi + exit 0 +else + log -p w -t otapreopt_slot "Slot property empty." + exit 1 +fi -- 2.11.0