5

Can I (As an AOSP builder) pre install some apps so after burning on device, they can easily be uninstalled (like regular downloaded apps)?

I am already familiar with system apps and priv-apps but as they lie in system partition they can not be removed! (only disabled in settings menu)

P.S. I know huawei for example uses /system/delapp to install such apps. But I seek for a general way or for AMLogic platform specifically which I am working on!

Saleh
  • 1,819
  • 1
  • 17
  • 44
  • An app is removable only if it is in /data. So I got an idea, install all the apps you want on a device and make the data partition an image. But this may not as easy what I think. –  Nov 29 '18 at 15:32
  • I think this not the way other vendors try to put their apps... @reavenisadesk – Saleh Nov 29 '18 at 20:46

1 Answers1

2

You can do that by configuring your build to produce a userdata.img file with your app(s) included, which you can then flash with fastboot flash userdata.

The Android.mk file for these apps that go in userdata.img roughly looks like the following:

include $(CLEAR_VARS)
LOCAL_MODULE := myapp1
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/app
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)

And add the apps to product packages in device.mk:

PRODUCT_PACKAGES += myapp1 myapp2 ...

You should be able to find plenty of examples on GitHub, e.g., https://github.com/search?l=Makefile&q=TARGET_OUT_DATA+BUILD_PREBUILT&type=Code


Since you are building the image from scratch, you can put your apps in a custom directory under and package a script to install them on boot time if they are not already installed. You can invoke that script by editing the init.rc file as follows:

on property:dev.bootcomplete=1
    exec - system system -- /system/bin/sh /path/to/installer/script.sh

The installer script can be as simple as:

for apkfile in /path/to/custom/apps/*.apk; do
   /system/bin/pm install "$apkfile"
done
MEE
  • 2,114
  • 17
  • 21
  • Can you please explain how to create userdata.img ? and also how to pack this new partition with other partitions when packing image in AOSP build environment – Saleh Dec 06 '18 at 23:07
  • Just add that make file and call `make` as usual and it will generate the userdata.img partition for you (because of `BUILD_PREBUILT` and `$TARGET_OUT_DATA`). You pack it along with other partitions as usual (system.img, userdata.img, recovery.img, etc., in same directory). – MEE Dec 07 '18 at 22:41
  • I saw userdata.img and for now I don't know exactly how to pack this new partition with other ones (Because the default AOSP behavior is to not pack this partition into final image).... But anyway this solution at its ultimate is not perfect. Because once user does a factory reset the app is gone! (because there is not a version of APK in system partition to install it at first boot) @John – Saleh Dec 13 '18 at 19:50
  • That is how it is supposed to work. You cannot make user data survive factory resets. What you can do instead is pack a 'stub' app with system.img, put the full app on the play store, and make the stub app prompt the user to update to the full app. Check for example how Facebook ships a stub app on some devices. – MEE Dec 13 '18 at 20:00
  • But huawei instead used this [patent](https://patents.google.com/patent/US9690561) to handle the problem more elegantly. you can uninstall apps preinstalled but they go back if you do a factory reset! – Saleh Dec 13 '18 at 20:07
  • Yes, but Huawei is not just building AOSP.. You can modify the AOSP code in whatever way you want to achieve what you want (e.g., modify the init.rc file to call a script to install apps from some directory that you pack in the ramdisk). But it may not be worth it. A Stub app consumes minimal space. – MEE Dec 13 '18 at 20:14
  • Hello John, I hope you do good. You said we can install APK though shell script and put it in init. Can you explain some details or refer to some relevant material about the problem? Specially about installing APK via script in android. Thanks @John – Saleh Dec 31 '18 at 19:06
  • My main Problem is with priviliges. Init script do not run with root privilege and I don't how to grant a script this privileges. – Saleh Dec 31 '18 at 20:27
  • The installer script only needs to be run as `system`. See my edits. – MEE Jan 08 '19 at 18:46