Android 8.0 platform presets third-party apk to the Data directory, so that it can be uninstalled and restored to factory settings.

The third-party apk is pre-installed on the Mstar 8.0 platform, and there are many pits.

Normally, it is very simple to preset the apk to the Data directory. After searching a lot on the Internet, the code will not be posted here, but there will be a problem here.
1 If you preset the apk to the Data directory without changing the apk signature, you can do it after compilation. I see that there is indeed this apk in the out directory, but after the flashing system runs, it will be automatically deleted by the system because the signature is not verified (the APK Signature Scheme v2 added after android 7.0).
2 If you change the apk's signature to the system signature and preset it to the data directory, it can run normally after compiling and flashing, but generally the apk has the function of online upgrade. Once the apk has a new version, it will not be upgraded because the apk signature is changed.
 

After several attempts, it is found that if the apk is directly pushed into the data directory and the apk can run normally, then this is easy, we will build the apk in this way, which can not only make the apk uninstall, but also make the apk upgradeable. And it can be restored by restoring the factory settings, how to do it, below I take the preset Tencent video conference apk as an example
1 First, prepare the built-in apk, and copy the apk to a location when compiling the code (you can define the location yourself ), ps: If the apk has a lib, remember to unzip it


PRODUCT_COPY_FILES += \
       $(call find-copy-subdir-files,*,$(LOCAL_PATH)/dataApps/TenxunConference,data/nodelete/pre_install/TenxunConference)

2 Then prepare a script copy_apps.sh, execute the script to copy the apk to the data directory at the first boot, remember to
grant permissions to these apk files

#!/system/bin/sh

FILE_DIR=/data/nodelete/pre_install/TenxunConference
FILE_DIR2=/data/app
TARGET_DIR=/data/app/TenxunConference


echo "$FILE_DIR copy start!!!"
mstarsu
cp $FILE_DIR $FILE_DIR2 -rf
chmod 777 $TARGET_DIR
chmod 777 $TARGET_DIR -R
echo "$FILE_DIR copy end!!!"

Copy the script to the system/etc directory

PRODUCT_COPY_FILES += \
    $(LOCAL_PATH)/copy_apps.sh:system/etc/copy_apps.sh	

Remember to add permissions to the script

yixiang.gao@ubuntu:~/code/public-8386/system$ git diff
diff --git a/core/libcutils/fs_config.c b/core/libcutils/fs_config.c
index 954680c..fd7b6a8 100755
--- a/core/libcutils/fs_config.c
+++ b/core/libcutils/fs_config.c
@@ -184,6 +184,7 @@ static const struct fs_path_config android_files[] = {
     { 00444, AID_ROOT,      AID_ROOT,      0, ven_conf_dir + 1 },
     { 00444, AID_ROOT,      AID_ROOT,      0, ven_conf_file + 1 },
     { 00755, AID_ROOT,      AID_ROOT,      0, "system/etc/rp_update_file.sh" },
+       { 00755, AID_ROOT,      AID_ROOT,      0, "system/etc/copy_apps.sh" },
        { 00755, AID_ROOT,      AID_ROOT,      0, "system/etc/jms_change_permission.sh" },
 


Define a service in init.rc

#for copy apps
service copy_apps /system/bin/sh /system/etc/copy_apps.sh
    class main
    user root
    group root
    disabled
    oneshot
    seclabel u:r:shell:s0

on property:persist.rp.first_boot=1
   start copy_apps	

Start this service in SystenServer

diff --git a/base/services/java/com/android/server/SystemServer.java b/base/services/java/com/android/server/SystemServer.java
index 64b35db..f0a7666 100755
--- a/base/services/java/com/android/server/SystemServer.java
+++ b/base/services/java/com/android/server/SystemServer.java
@@ -122,6 +122,7 @@ import java.util.Timer;
 import java.util.TimerTask;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Future;
+import android.util.Log;
 
 import static android.view.Display.DEFAULT_DISPLAY;
 
@@ -505,6 +506,16 @@ public final class SystemServer {
      * the other functions.
      */
     private void startBootstrapServices() {
+               //add by gyx
+               boolean isFirstBoot = SystemProperties.get("persist.rp.first_boot_flag","0").equals("0");
+               if(isFirstBoot){
+                       Log.i("gyx","isFirstBoot");
+                       SystemProperties.set("persist.rp.first_boot_flag","1");
+                       SystemProperties.set("persist.rp.first_boot","1");
+                       SystemProperties.set("persist.rp.first_boot","0");
+               }
+               //end
+

This is basically done, there is no problem personally.

Guess you like

Origin blog.csdn.net/weixin_35649059/article/details/113045541