privatefinalbooleanattachApplicationLocked(IApplicationThreadthread,intpid,intcallingUid,longstartSeq){ProcessRecordapp;longstartTime=SystemClock.uptimeMillis();longbindApplicationTimeMillis;if(pid!=MY_PID&&pid>=0){synchronized(mPidsSelfLocked){app=mPidsSelfLocked.get(pid);}if(app!=null&&(app.startUid!=callingUid||app.startSeq!=startSeq)){StringprocessName=null;finalProcessRecordpending=mProcessList.mPendingStarts.get(startSeq);if(pending!=null){processName=pending.processName;}finalStringmsg="attachApplicationLocked process:"+processName+" startSeq:"+startSeq+" pid:"+pid+" belongs to another existing app:"+app.processName+" startSeq:"+app.startSeq;cleanUpApplicationRecordLocked(app,false,false,-1,true/*replacingPid*/);mPidsSelfLocked.remove(app);app=null;}}else{app=null;}thread.bindApplication(processName,appInfo,providers,instr2.mClass,profilerInfo,instr2.mArguments,instr2.mWatcher,instr2.mUiAutomationConnection,testMode,mBinderTransactionTrackingEnabled,enableTrackAllocation,isRestrictedBackupMode||!normalMode,app.isPersistent(),newConfiguration(app.getWindowProcessController().getConfiguration()),app.compat,getCommonServicesLocked(app.isolated),mCoreSettingsObserver.getCoreSettingsLocked(),buildSerial,autofillOptions,contentCaptureOptions);returntrue;}
publicfinalvoidbindApplication(StringprocessName,ApplicationInfoappInfo,List<ProviderInfo>providers,ComponentNameinstrumentationName,ProfilerInfoprofilerInfo,BundleinstrumentationArgs,IInstrumentationWatcherinstrumentationWatcher,IUiAutomationConnectioninstrumentationUiConnection,intdebugMode,booleanenableBinderTracking,booleantrackAllocation,booleanisRestrictedBackupMode,booleanpersistent,Configurationconfig,CompatibilityInfocompatInfo,Mapservices,BundlecoreSettings,StringbuildSerial,booleanautofillCompatibilityEnabled){if(services!=null){if(false){// Test code to make sure the app could see the passed-in services.for(Objectoname:services.keySet()){if(services.get(oname)==null){continue;// AM just passed in a null service.}Stringname=(String)oname;// See b/79378449 about the following exemption.switch(name){case"package":caseContext.WINDOW_SERVICE:continue;}if(ServiceManager.getService(name)==null){Log.wtf(TAG,"Service "+name+" should be accessible by this app");}}}// Setup the service cache in the ServiceManagerServiceManager.initServiceCache(services);}setCoreSettings(coreSettings);AppBindDatadata=newAppBindData();data.processName=processName;data.appInfo=appInfo;data.providers=providers;data.instrumentationName=instrumentationName;data.instrumentationArgs=instrumentationArgs;data.instrumentationWatcher=instrumentationWatcher;data.instrumentationUiAutomationConnection=instrumentationUiConnection;data.debugMode=debugMode;data.enableBinderTracking=enableBinderTracking;data.trackAllocation=trackAllocation;data.restrictedBackupMode=isRestrictedBackupMode;data.persistent=persistent;data.config=config;data.compatInfo=compatInfo;data.initProfilerInfo=profilerInfo;data.buildSerial=buildSerial;data.autofillCompatibilityEnabled=autofillCompatibilityEnabled;sendMessage(H.BIND_APPLICATION,data);}publicvoidhandleMessage(Messagemsg){switch(msg.what){caseBIND_APPLICATION:AppBindDatadata=(AppBindData)msg.obj;handleBindApplication(data);break;// ...}}