项目需要,需要预安装GSM
1.framework增加preinstall方法
--- a/cmds/pm/src/com/android/commands/pm/Pm.java
+++ b/cmds/pm/src/com/android/commands/pm/Pm.java
@@ -145,6 +145,11 @@ public final class Pm {
if ("dump".equals(op)) {
return runDump();
}
+
+ if ("preinstall".equals(op)) {
+ preInstall();
+ return;
+ }
if ("install".equals(op)) {
return runInstall();
@@ -1034,6 +1039,50 @@ public final class Pm {
return 1;
}
}
+
+ private void preInstall() {
+ String path = nextArg();
+ int i;
+
+ System.err.println("\t preInstall path: " + path);
+ if (path == null) {
+ System.err.println("Error: no package specified");
+ showUsage();
+ return;
+ }
+
+ File[] files = new File(path).listFiles();
+ for(File apkFilePath : files) {
+ System.err.println("\tpkg: " + apkFilePath);
+ PackageInstallObserver obs = new PackageInstallObserver();
+ try {
+ mPm.installPackage(Uri.fromFile(apkFilePath), obs, 0,null);
+ System.err.println("\t pkg----1------: ");
+ synchronized (obs) {
+ while (!obs.finished) {
+ try {
+ System.err.println("\t pkg----2------: ");
+ obs.wait();
+ System.err.println("\t pkg----3------: ");
+ } catch (InterruptedException e) {
+ System.err.println("\t pkg----4------: ");
+ }
+ }
+ if (obs.result == PackageManager.INSTALL_SUCCEEDED) {
+ System.out.println("Success");
+ } else {
+ System.err.println("Failure ["
+ + installFailureToString(obs.result)
+ + "]");
+ }
+ }
+ } catch (RemoteException e) {
+ System.err.println(e.toString());
+ System.err.println(PM_NOT_RUNNING_ERR);
+ }
+ }
+ System.err.println("\t preInstall path: " + path + " ok");
+ }
private int runInstall() {
int installFlags = 0;
2.device/rockchip/rk3368/preinstall_product目录新建preinstall.mk
cat ../rk3368/preinstall_product/preinstall.mk
PRODUCT_PACKAGES += Netflix
PRODUCT_PACKAGES += National.Geographic
PRODUCT_PACKAGES += HuluPlus
PRODUCT_PACKAGES += Pandora
PRODUCT_PACKAGES += WeChat
PRODUCT_PACKAGES += MXPlayer
PRODUCT_PACKAGES += Fitbit
PRODUCT_PACKAGES += Twitter
PRODUCT_PACKAGES += Facebook
PRODUCT_PACKAGES += YouTube
3.开机自动执行批处理安装
device/rockchip/common/device.mk
+$(shell python $(LOCAL_PATH)/auto_generator.py $(TARGET_PRODUCT) preinstall_product)
+include device/rockchip/rk3368/preinstall_product/preinstall.mk
4.修改auto_generator.py文件
cat common/auto_generator.py
#!/usr/bin/env python
import sys
import os
import re
templet = """include $(CLEAR_VARS)
LOCAL_MODULE := %s
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_PATH := $(TARGET_OUT)/preinstall
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_DEX_PREOPT := false
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
"""
def main(argv):
preinstall_dir = os.path.dirname(argv[0])
preinstall_dir = os.path.join(preinstall_dir, '../' + argv[1] + '/' + argv[2])
if os.path.exists(preinstall_dir):
#Use to define modules for install
makefile_path = preinstall_dir + '/Android.mk'
#Use to include modules
include_path = preinstall_dir + '/preinstall.mk'
if os.path.exists(makefile_path):
os.remove(makefile_path)
if os.path.exists(include_path):
os.remove(include_path)
makefile = file(makefile_path, 'w')
includefile = file(include_path, 'w')
makefile.write("LOCAL_PATH := $(my-dir)\n\n")
for root, dirs, files in os.walk(preinstall_dir):
for file_name in files:
p = re.compile(r'\S*(?=.apk\b)')
found = p.search(file_name)
if found:
makefile.write(templet %found.group())
includefile.write('PRODUCT_PACKAGES += %s\n' %found.group())
makefile.close()
includefile.close()
if __name__=="__main__":