android 添加预装的方法

方法1:

 frameworks/base/services/java/com/android/server/pm/PackageManagerService.java

      synchronized (mPackages) {

            mHandlerThread.start();
            mHandler = new PackageHandler(mHandlerThread.getLooper());


+            if(SystemProperties.getBoolean("persist.sys.firstRun", true)){
+                File targetDir = new File("/data/app");
+            File dir  = new File("/system/media/app");
+            if(dir.exists()){
+                for(File file : dir.listFiles()){
+                    File targetFile =  new File(targetDir,file.getName());
+           FileUtils.copyFile(file,targetFile);
+            FileUtils.setPermissions(targetFile.getAbsolutePath(), FileUtils.S_IRUSR| FileUtils.S_IWUSR | FileUtils.S_IRGRP| FileUtils.S_IROTH, -1, -1);
+                }
+           }
+            SystemProperties.set("persist.sys.firstRun","false");
+        }

            File dataDir = Environment.getDataDirectory();

方法二:

init.rc中添加:

+chmod 0777 /system/bin/preinstall.sh


+service preinstall /system/bin/preinstall.sh

+       class main
+        user root
+        group root
+        oneshot
+        console
+        disabled


on property:dev.bootcomplete=1
    chown media media /sys/class/vm/mirror
    chmod 0664 /sys/class/vm/mirror
+    start preinstall
    write /sys/class/vm/mirror 0
    start usbpm


preinstall.sh

#!/system/xbin/busybox sh

echo "do preinstall job"        

if [ ! -e /data/system.notfirstrun ]; then
  echo "do preinstall job"        

        pm install /system/preinstall/xxx.apk

        touch /data/system.notfirstrun

else
   echo "do nothing"
fi

xx.mk

PRODUCT_COPY_FILES += \

$(LOCAL_PATH)/preinstall.sh:system/bin/preinstall.sh


# pre-installed apks
PRODUCT_COPY_FILES += \
        $(call find-copy-subdir-files,*.apk,$(LOCAL_PATH)/apk,system/preinstall)

 

方法二(二)

init.rc

on property:init.svc.bootanim=stopped
    start preinstall

service preinstall /system/bin/preinstall.sh
    user root
    group root
    disabled
    oneshot


xx.mk

ifeq ($(BUILD_WITH_THIRDPART_APK),true)

PRODUCT_PACKAGES += \
    preinstall.sh \
  $(patsubst vendor/amlogic/prebuilt/preinstallation/%,%,$(wildcard vendor/amlogic/prebuilt/preinstallation/*.apk))
endif


preinstall.sh

#!/system/bin/sh


MARK=/data/local/symbol_thirdpart_apks_installed
PKGS=/system/preinstall/


if [ ! -e $MARK ]; then
echo "booting the first time, so pre-install some APKs."


busybox find $PKGS -name "*\.apk" -exec sh /system/bin/pm install {} \;


# NO NEED to delete these APKs since we keep a mark under data partition.^M
# And the mark will be wiped out after doing factory reset, so you can install^M
# these APKs again if files are still there.^M
# busybox rm -rf $PKGS^M


touch $MARK
echo "OK, installation complete."
fi



Android.mk


LOCAL_PATH:= $(call my-dir)


include $(CLEAR_VARS)
LOCAL_MODULE := preinstall.sh
LOCAL_SRC_FILES := preinstall.sh
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT)/bin
include $(BUILD_PREBUILT)

manager_apk := $(patsubst $(LOCAL_PATH)/%,%,$(wildcard $(LOCAL_PATH)/*.apk))
$(foreach t,$(manager_apk), \
$(eval include $(CLEAR_VARS)) \
$(eval LOCAL_MODULE     := $(notdir $(t))) \
$(eval LOCAL_MODULE_TAGS := optional) \
$(eval LOCAL_MODULE_CLASS := ETC) \
$(eval LOCAL_MODULE_PATH := $(TARGET_OUT)/preinstall) \
$(eval LOCAL_SRC_FILES   := $(t)) \
$(eval LOCAL_CERTIFICATE := shared) \
$(eval include $(BUILD_PREBUILT)) \
)
$(LOCAL_INSTALLED_MODULE): $(notdir $(manager_apk))


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Keep Coding...

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值