How do you preinstall APP in userdata (imx-p9.0.0_2.0.0-ga, Android 9.0)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do you preinstall APP in userdata (imx-p9.0.0_2.0.0-ga, Android 9.0)

Jump to solution
2,092 Views
ruei_chang
Contributor III

Dear NXP/contributors:

   I'm using Android 9.0(imx-p9.0.0_2.0.0-ga) and I manage to preinstall the APK during the build of userdata.img but it doesn't work.   

   Same thing apply on Android 6.0 is working. So maybe I miss something configuration on Android 9.0. But I didn't see any solution on NXP community.  Could someone tell me how to preinstall the APK in userdata.img? 

 

 Here is my Android.mk. 

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional


LOCAL_MODULE := myapp
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
include $(BUILD_PREBUILT)

# Use the following include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))

 

And I declared the package name in device/fsl/imx6dq/sabresd_6dq/sabresd_6dq.mk

PRODUCT_PACKAGES += \
     myapp

 

I saw the apk also built into the /data/app

out/target/product/sabresd_6dq/data/app/myapp/myapp.apk

 

 

But after upgrading the image, system go to the Android Recovery mode directly...

S__28205059.jpg

0 Kudos
Reply
1 Solution
2,057 Views
Zhiming_Liu
NXP TechSupport
NXP TechSupport

Hi

 

The android 9 didn not allow preinstall app in user data.So you need change the source code

--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -11394,6 +11394,10 @@
                                     + " but expected at " + known.codePathString
                                     + "; ignoring.");
                         }
                    } /*else {
+                        throw new PackageManagerException(INSTALL_FAILED_INVALID_INSTALL_LOCATION,
+                                "Application package " + pkg.packageName
+                                + " not found; ignoring.");
                     }*/
                 }
             }

View solution in original post

4 Replies
2,060 Views
ruei_chang
Contributor III

I modified the fstab and I can see myapp is installed in userdata.img

--- a/android_build/device/fsl/imx6dq/sabresd_6dq/fstab.freescale
+++ b/android_build/device/fsl/imx6dq/sabresd_6dq/fstab.freescale
@@ -4,10 +4,11 @@
# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK

/devices/soc0/soc/2100000.aips-bus/2198000.usdhc/mmc_host* auto auto defaults voldmanaged=sdcard:auto,encryptable=userdata
+/devices/soc0/soc/2100000.aips-bus/2198000.usdhc/mmc_host* /mnt/media_rw/sdcard1 vfat defaults voldmanaged=sdcard1:auto,encryptable=userdata
/devices/soc0/soc/2100000.aips-bus/2184000.usb/ci_hdrc.0* auto auto defaults voldmanaged=usb:auto
/dev/block/by-name/system /system ext4 ro,barrier=1 wait,avb
/dev/block/by-name/vendor /vendor ext4 ro,barrier=1 wait,avb
-/dev/block/by-name/userdata /data ext4 nosuid,nodev,nodiratime,noatime,nomblk_io_submit,noauto_da_alloc,errors=panic wait,formattable,fileencryption=software,quota,reservedsize=128M,fileencryption=adiantum
+/dev/block/by-name/userdata /data ext4 nosuid,nodev,nodiratime,noatime,nomblk_io_submit,noauto_da_alloc,errors=panic wait,encryptable=/dev/block/mmcblk3p9
/dev/block/by-name/cache /cache ext4 noatime,nosuid,nodev,nomblk_io_submit wait,formattable
/dev/block/by-name/vbmeta /vbmeta emmc defaults defaults
/dev/block/by-name/dtbo /dtbo emmc defaults defaults

 

I can see the apk was existed under /data/app, but after few seconds, the folder  was removed without any log...I have no idea what happened...

zdevice.PNG

0 Kudos
Reply
2,028 Views
ruei_chang
Contributor III

Hello everyone, 

  I modified the content of fstab last time because the system always say my data is corrupted and go to Android Recovery mode. 

    I removed the encryption and added encryptable in fstab then data won't be corrupted. But I noticed that my system will not show encrypted  as well.  (How to check if your system is encrypted:  ro.crypto.state)

 

   So I'm not supposed to take this solution on my project. I found another way to solve it.

 

Here is my fstab's content:

--- a/android_build/device/fsl/imx6dq/sabresd_6dq/fstab.freescale
+++ b/android_build/device/fsl/imx6dq/sabresd_6dq/fstab.freescale
@@ -7,7 +7,7 @@
 /devices/soc0/soc/2100000.aips-bus/2184000.usb/ci_hdrc.0*  auto auto defaults voldmanaged=usb:auto
 /dev/block/by-name/system       /system      ext4    ro,barrier=1                                                                     wait,avb
 /dev/block/by-name/vendor       /vendor      ext4    ro,barrier=1                                                                     wait,avb
-/dev/block/by-name/userdata     /data        ext4    nosuid,nodev,nodiratime,noatime,nomblk_io_submit,noauto_da_alloc,errors=panic    wait,encryptable=/dev/block/mmcblk3p11
+/dev/block/by-name/userdata     /data        ext4    nosuid,nodev,nodiratime,noatime,nomblk_io_submit,noauto_da_alloc,errors=panic    wait,formattable,quota,reservedsize=128M,fileencryption=adiantum
 /dev/block/by-name/cache        /cache       ext4    noatime,nosuid,nodev,nomblk_io_submit                                                    wait,formattable
 /dev/block/by-name/vbmeta       /vbmeta      emmc    defaults                                                                         defaults
 /dev/block/by-name/dtbo         /dtbo        emmc    defaults                                                                         defaults

 

And there is a file which is called ext4_crypt_init_extensions.cpp will check the /data/app encryption mechanism after downloading the image .   If I add the "app" in e4crypt_set_directory_policy function to skip the checking function. Then the system won't be corrupted anymore.

--- a/android_build/system/extras/ext4_utils/ext4_crypt_init_extensions.cpp
+++ b/android_build/system/extras/ext4_utils/ext4_crypt_init_extensions.cpp
@@ -88,7 +88,7 @@ int e4crypt_set_directory_policy(const char* dir)
         "misc_ce", "misc_de",
         "vendor_ce", "vendor_de",
         "media",
-        "data", "user", "user_de",
+        "data", "user", "user_de", "app",
     };
     std::string prefix = "/data/";
     for (auto d: directories_to_exclude) {
@@ -97,6 +97,7 @@ int e4crypt_set_directory_policy(const char* dir)
             return 0;
         }
     }

     return set_system_de_policy_on(dir);

 

The system can preinstall apk and system will show encrypted as well.   This is best solution to fix my problem.

 

 

And here is my Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := myapp
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)

 

If you'd like to preinstall apk in userdata and couldn't make it. Please take my solution and give it a try.

0 Kudos
Reply
2,058 Views
Zhiming_Liu
NXP TechSupport
NXP TechSupport

Hi

 

The android 9 didn not allow preinstall app in user data.So you need change the source code

--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -11394,6 +11394,10 @@
                                     + " but expected at " + known.codePathString
                                     + "; ignoring.");
                         }
                    } /*else {
+                        throw new PackageManagerException(INSTALL_FAILED_INVALID_INSTALL_LOCATION,
+                                "Application package " + pkg.packageName
+                                + " not found; ignoring.");
                     }*/
                 }
             }

2,054 Views
ruei_chang
Contributor III

@Zhiming_Liu  Thank you so much.  Your solution is working fine!  I appreciate.

0 Kudos
Reply