方法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))