packages\services\Telephony\AndroidManifest.xml
<application android:name="PhoneApp"
android:persistent="true"
android:label="@string/phoneAppLabel"
android:icon="@mipmap/ic_launcher_phone"
android:allowBackup="false"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:defaultToDeviceProtectedStorage="true"
android:directBootAware="true">
Android Telephony应用的application为PhoneApp,属于com.android.phone进程。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
package="com.android.phone"
coreApp="true"
android:sharedUserId="android.uid.phone"
android:sharedUserLabel="@string/phoneAppLabel"
>
PhoneApp的启动
众所周知,系统会在开机时弄一个SystemServer出来。
然后靠SystemServer启动各种系统服务。
\frameworks\base\services\java\com\android\server\SystemServer.java
// Activity manager runs the show.
traceBeginAndSlog("StartActivityManager");
mActivityManagerService = mSystemServiceManager.startService(
ActivityManagerService.Lifecycle.class).getService();
mActivityManagerService.setSystemServiceManager(mSystemServiceManager);
mActivityManagerService.setInstaller(installer);
其中就有大名鼎鼎的ActivityManagerService的启动。
\frameworks\base\services\core\java\com\android\server\am\ActivityManagerService.java
而ActivityManagerService的SystemReady方法中就有一个启动PersistentApps的方法。
这个应用还需要MATCH_DIRECT_BOOT_AWARE。
public void systemReady(final Runnable goingCallback, TimingsTraceLog traceLog) {
//...
synchronized (this) {
// Only start up encryption-aware persistent apps; once user is
// unlocked we'll come back around and start unaware apps
startPersistentApps(PackageManager.MATCH_DIRECT_BOOT_AWARE);
//...
}
PhoneApp正巧配置了android:persistent="true"和android:directBootAware="true"。
被启动后,PhoneApp的onCreate方法会被调用。
@Override
public void onCreate() {
MtkFactory.createInstance(getApplicationContext());
if (UserHandle.myUserId() == 0) {
// We are running as the primary user, so should bring up the
// global phone state.
mPhoneGlobals = MtkFactory.getInstance().makePhoneGlobals(this);
mPhoneGlobals.onCreate();
mTelephonyGlobals = new TelephonyGlobals(this);
mTelephonyGlobals.onCreate();
}
}