Opening GApps

Let's look at another famous open source update package, GApps. The GApps project provides Google Mobile Services (GMS) replacement using its update packages. There are many Android devices shipped without GMS. If the users of these devices want to use Google applications, GApps is one of the major choices for them. They can download a version of a GApps package suitable for their device and flash an update package using recovery.

The GApps packages can be downloaded at the following URL:

http://opengapps.org

There are many choices of GApps packages at their website based on platform, Android version, and variant of packages (super, stock, full, mini, micro, nano, or pico, and so on).

We will use a small size pico variant to test in our environment. As we did for the Xposed update package, we want to look at update-binary and updater-script first. After we extract the package to a temporary space, we can see that the updater-script is just a dummy file and update-binary is a shell script:

$ cat updater-script 
# Dummy file; update-binary is a shell script.

If we look at update-binary in the following snippet, we can see that it is a shell script using /sbin/sh to interpret it. We will create a symbolic link, /sbin/sh, to the busybox in the start up script so we don't have any problems with running it:

#!/sbin/sh 
...
export OPENGAZIP="$3"
export OUTFD="/proc/self/fd/$2"
export TMP="/tmp"
case "$(uname -m)" in
*86*) export BINARCH="x86";; # e.g. Zenfone is i686
*ar*) export BINARCH="arm";; # i.e. armv7l and aarch64
esac
bb="$TMP/busybox-$BINARCH"
l="$TMP/bin"
setenforce 0
for f in app_densities.txt app_sizes.txt bkup_tail.sh gapps-remove.txt g.prop installer.sh busybox-x86 tar-x86 unzip-x86 zip-x86; do
unzip -o "$OPENGAZIP" "$f" -d "$TMP";
done
for f in busybox-x86 tar-x86 unzip-x86 zip-x86; do
chmod +x "$TMP/$f";
done
if [ -e "$bb" ]; then
install -d "$l"
for i in $($bb --list); do
if ! ln -sf "$bb" "$l/$i" && ! $bb ln -sf "$bb" "$l/$i" && ! $bb
ln -f "$bb" "$l/$i" ; then
# create script wrapper if symlinking and hardlinking failed
because of restrictive selinux policy
if ! echo "#!$bb" > "$l/$i" || ! chmod +x "$l/$i" ; then
echo "ui_print ERROR 10: Failed to set-up Open GApps' pre-
bundled busybox" > "$OUTFD"
echo "ui_print" > "$OUTFD"
echo "ui_print Please use TWRP as recovery instead" > "$OUTFD"
echo "ui_print" > "$OUTFD"
exit 1
fi
fi
done
PATH="$l:$PATH" $bb ash "$TMP/installer.sh" "$@"
exit "$?"
else
echo "ui_print ERROR 64: Wrong architecture to set-up Open GApps'
pre-bundled busybox" > "$OUTFD"
echo "ui_print" > "$OUTFD"
exit 1
fi

This script expects the same list of arguments, which recovery will pass to update-binary. It uses the arguments to find the update package ZIP file and extracts a setup of files to /tmp:

# ls -1 /tmp                                                                  
app_densities.txt
app_sizes.txt
bin
bkup_tail.sh
busybox-x86
g.prop
gapps-remove.txt
installer.sh
last_install
recovery.log
tar-x86
unzip-x86
update_binary
zip-x86

These files are the tools that the GApps package needed for the next stage of installation, as we can see in the preceding snippet. It includes its own version of busybox and compression tools. After it extracts all the files, it fixes the permission for executables and installs the symbol links for busybox. After that, it executes the real installation script, installer.sh. This is a very complicated shell script, so we won't do further analysis on it. We can apply the GApps package to our system without any problem, as we can see from the following screenshot:

The following screenshot shows the screen after we install GApps successfully:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.169.197