1.什么是persist应用? 在AndroidManifest.xml中的applicationtag中定义:android:persistent="true"
在解析此应用时,给它增加一个flag:ApplicationInfo.FLAG_PERSISTENT
【persist应用】
// PackageParser.java parseBaseApplication
if ((flags&PARSE_IS_SYSTEM) != 0) {
if (sa.getBoolean(
com.android.internal.R.styleable.AndroidManifestApplication_persistent,
false)) {
ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
}
}// ApplicationInfo.java
/**
* Value for {@link #flags}: set to true if this application is persistent.
* Comes from {@link android.R.styleable#AndroidManifestApplication_persistent
* android:persistent} of the <
application>
tag.
*/
public static final int FLAG_PERSISTENT = 1<<3;
从注释可知,这代表此应用为persist app。
2.如何查询persit应用以及谁会去查询? PackageManagerService.java提供了方法public List getPersistentApplications(int flags)可供查询.
依据就是查看哪个Application包含这个前面提到的flag:ApplicationInfo.FLAG_PERSISTENT
谁会查询或关注这点?
AMS会关注,在它的systemReady方法中调用,目的就是在system ready后启动这些persist应用。所以,他们会由系统自动启动,在BOOT_COMPLETED之前。
具体流程如下:
startOtherServices() //SystemServer.java
systemReady(final Runnable goingCallback) // ActivityManagerService.java
addAppLocked(info, false, null /* ABI override */);
startProcessLocked(app, "added application", app.processName, abiOverride, null /* entryPoint */, null /* entryPointArgs */);
Process.start(...)
3.log信息
// system ready
06-05 21:14:29.620509763763 I SystemServer: Making services ready
06-05 21:14:29.640944763763 I ActivityManager: Start proc com.android.systemui for service com.android.systemui/.SystemUIService: pid=864 uid=10022 gids={50022, 1028, 1015, 1035, 3002, 3001, 3003, 1007}
06-05 21:14:29.641193763817 I MountService: handleSystemReady
06-05 21:14:29.943741763763 D UsbDeviceManager: systemReady
06-05 21:14:29.949129763763 D AppWidgetService: systemRunning
06-05 21:14:29.949196763763 I AppWidgetServiceImpl: u=0: systemReady
06-05 21:14:29.979798763763 V WallpaperManagerService: systemReady
06-05 21:14:30.069004763763 I RecoveryManagerService: systemReady()
// start persist app
06-05 21:14:30.243268763763 I ActivityManager: Start proc com.android.phone for added application com.android.phone: pid=1007 uid=1001 gids={41001, 3002, 3001, 3003, 1028, 1015, 1013, 1006, 1004, 2002, 1023}
06-05 21:14:30.262986763763 I ActivityManager: Start proc com.mediatek.voicecommand for added application com.mediatek.voicecommand: pid=1019 uid=10084 gids={50084, 1028, 1015, 1013, 1006}
06-05 21:14:30.273884763763 I ActivityManager: Start proc com.mediatek.bluetooth for added application com.mediatek.bluetooth: pid=1033 uid=1002 gids={41002, 3003, 3002, 3001, 1028, 1015, 3005, 1016, 3008, 1023, 1035}
06-05 21:14:30.322054763763 I ActivityManager: Start proc com.mediatek.voiceextension for added application com.mediatek.voiceextension: pid=1047 uid=1000 gids={41000, 1007, 1028, 1015, 3005, 3003, 3006, 1023, 3002, 3001}
06-05 21:14:30.416317763763 I ActivityManager: Start proc android.process.acore for added application android.process.acore: pid=1125 uid=10008 gids={50008, 3003, 1028, 1015}
06-05 21:14:30.434718763763 I ActivityManager: Start proc com.android.incallui for added application com.android.incallui: pid=1139 uid=10049 gids={50049, 3003, 1028, 1015}
// BOOT_COMPLETED
06-05 21:14:33.0215437631046 V ActivityManager: Broadcast: Intent { act=android.intent.action.BOOT_COMPLETED flg=0x8000010 (has extras) } ordered=true userid=0 callerApp=null