某些進程延遲啓動

每個進程的啓動都會經過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();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章