Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for system_root based recoveries #18

Open
wants to merge 2 commits into
base: android10-support
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions META-INF/com/google/android/update-binary
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,31 @@ mkdir $WORK_FOLDER
cd $WORK_FOLDER
unzip -o "$ZIP_FILE"

mount /system
# A/B system-as-root devices have the actual system partition
# mounted under /system/system when in the recovery.
# All Android 10 devices act as system-as-root devices.
SYSTEM_AS_ROOT="$(getprop ro.build.system_root_image)"
if [ "$SYSTEM_AS_ROOT" == "true" ]
then # we are on an Android Pie device with A/B system-as-root layout
SYSTEM_ROOT="/system/system"
elif [ -f "/system/system/build.prop" ]
then # we are on an Android 10 device
SYSTEM_AS_ROOT="true"
SYSTEM_ROOT="/system/system"
if mount /system
then
UMOUNT_FOLDER=/system
# A/B system-as-root devices have the actual system partition
# mounted under /system/system when in the recovery.
# All Android 10 devices act as system-as-root devices.
SYSTEM_AS_ROOT="$(getprop ro.build.system_root_image)"
if [ "$SYSTEM_AS_ROOT" == "true" ]
then # we are on an Android Pie device with A/B system-as-root layout
SYSTEM_ROOT="/system/system"
elif [ -f "/system/system/build.prop" ]
then # we are on an Android 10 device
SYSTEM_AS_ROOT="true"
SYSTEM_ROOT="/system/system"
fi
else
mount /system_root || (echo -n -e 'ui_print Could not mount system_root...\n' > /proc/self/fd/$2; exit 1)
UMOUNT_FOLDER=/system_root
SYSTEM_ROOT="/system_root/system"
fi


echo -n -e 'ui_print Installing apps...\n' > /proc/self/fd/$2

# Prepare work folder
# Prepare directory structure: change source according to target
BUILD_VERSION_SDK="$(grep -F ro.build.version.sdk ${SYSTEM_ROOT}/build.prop)"
BUILD_VERSION_SDK_INT="${BUILD_VERSION_SDK#*=}"
if [ "${BUILD_VERSION_SDK_INT}" -ge 21 ]
Expand All @@ -72,31 +80,29 @@ else # all apks reside in /system/app
rm -rf {} \;
fi

TARGET_APKS="$(find system -name *.apk | sed -e 's/^/\//')"
TARGET_DIRS="$(find system -mindepth 2 -type d | sed -e 's/^/\//')"

# Delete old files and folders
echo "$TARGET_APKS" | xargs -n 1 rm -f
echo "$TARGET_DIRS" | xargs -n 1 rm -rf
TARGET_APKS="$(find system -name "*.apk" | sed -e 's|^system|'"${SYSTEM_ROOT}"'|')"
TARGET_DIRS="$(find system -mindepth 2 -type d | sed -e 's|^system|'"${SYSTEM_ROOT}"'|')"

# Copy new files and fix permissions
cp -r system/* ${SYSTEM_ROOT}/
echo "$TARGET_APKS" | xargs -n 1 chmod 644
echo "$TARGET_DIRS" | xargs -n 1 chmod 755
echo -n "$TARGET_APKS" | xargs -n 1 chmod 644
echo -n "$TARGET_DIRS" | xargs -n 1 chmod 755


echo -n -e 'ui_print Installing OTA survival script...\n' > /proc/self/fd/$2

cp ${ADDOND} ${SYSTEM_ROOT}/addon.d/
chmod 755 ${SYSTEM_ROOT}/addon.d/${ADDOND}
echo -n -e 'ui_print Installed OTA survival script.\n' > /proc/self/fd/$2


if [ "${BUILD_VERSION_SDK_INT}" -ge 27 ]
then # Android 8+ require an explicit permission whitelist file for privileged apps
echo -n -e 'ui_print Whitelisting privapp permissions...\n' > /proc/self/fd/$2

cp ${PRIVAPP_PERMISSIONS} ${SYSTEM_ROOT}/etc/permissions/
chmod 644 ${SYSTEM_ROOT}/etc/permissions/${PRIVAPP_PERMISSIONS}
fi

echo -n -e 'ui_print done\n' > /proc/self/fd/$2
echo -n -e 'ui_print\n' > /proc/self/fd/$2

umount /system
umount $UMOUNT_FOLDER