每个进程的启动都会经过startProcessLocked 这个函数。为了加快启动速度,某些应用可以后续再启动
if (NWD_SPEED_UP) { final String pkgName=app.info.packageName; Slog.d(TAG,"=====james====pkgName:"+pkgName+",mBootCompleted:"+mBootCompleted+",app:"+app); if(isOtherApp(pkgName) && !mBootCompleted){ // pacakge com.android.vending must start at least once if yout want to add google account, by liuhualiang if(pkgName.indexOf("cn.kuwo.kwmusic")>-1 || pkgName.indexOf("com.kugou")>-1 || pkgName.equals("com.google.android.gsf")) return; OtherAppProcessInfo procInfo=new OtherAppProcessInfo(app,hostingType,hostingNameStr); mOtherAppProcessInfos.add(procInfo); return; } }
//added by james for shorten boot time boolean mBootCompleted=false; private static final int START_OTHER_APP_SLEEP_TIME = 8000; private static final String ACTION_AFTER_BOOT_COMPLETED = "com.nwd.ACTION_AFTER_BOOT_COMPLETED"; ArrayList<String> otherApps=new ArrayList<String>(Arrays.asList( "com.iflytek.inputmethod", "com.iflytek.cmcc", "com.iflytek.inputmethod.pad", "cn.kuwo.kwmusichd", "com.kugou.fm", "cn.etouch.ecalendar", "com.android.smspush", "com.android.vending" ));
ArrayList<OtherAppProcessInfo> mOtherAppProcessInfos=new ArrayList<OtherAppProcessInfo>(); private class OtherAppProcessInfo { public ProcessRecord app; public String hostingType; public String hostingNameStr;
public OtherAppProcessInfo(ProcessRecord _app,String _hostingType,String _hostingNameStr) { app=_app; hostingType=_hostingType; hostingNameStr=_hostingNameStr; } }
private final class BootCompletedReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String action=intent.getAction(); Slog.d(TAG,"====james====action:"+action); if(action.equals(Intent.ACTION_UI_BOOT_FINISH)){ delayStartApp(); } } }
//delay start app and init private void delayStartApp(){ SystemProperties.set("sys.nwd.boot.completed", "1"); new Thread(new Runnable(){ public void run(){ try { Slog.d(TAG,"==james==delay "+(START_OTHER_APP_SLEEP_TIME/1000)+"s start other app service====="); Thread.sleep(START_OTHER_APP_SLEEP_TIME); }catch(InterruptedException e){ e.printStackTrace(); } Slog.d(TAG,"==james==start other app....."); mBootCompleted=true; for(OtherAppProcessInfo procInfo:mOtherAppProcessInfos){ startProcessLocked(procInfo.app, procInfo.hostingType, procInfo.hostingNameStr); } checkStartPrintLogToFile(); checkRemoveSystemSdcardDir(); sendDelayBootCompletedBroadcast(); } }).start(); }
再systemReady准备完成后,需要注册和发送广播。
IntentFilter filter = new IntentFilter(); filter.addAction("start.other.app.service"); filter.addAction(Intent.ACTION_UI_BOOT_FINISH); mContext.registerReceiver(new BootCompletedReceiver(), filter);
sendBootCompletedBroadcast();