盒子
盒子
文章目录
  1. 启动AMS
  2. startBootstrapServices
    1. initPowerManagement
    2. setSystemProcess
  3. startCoreServices
  4. startOtherServices
    1. installSystemProviders
    2. WindowManagerService
    3. systemReady
  5. 项目

ActivityManagerService 启动初探

在之前的Android SystemServer启动(二)中,分析到在SystemServer中会启动大量的Service,其中就有一个比较特殊的Service,它就是ActivityManagerService。

今天我们就来了解一下ActivityManageerService的启动,下面都将其简称为AMS。

启动AMS

AMS的启动发生在SystemServer启动过程中的BootPhase 0阶段。

在三大分类服务的启动服务中,即startBootstrapServices方法中

1
2
3
4
5
6
7
8
9
10
11
12
13
private void startBootstrapServices() {
...

ActivityTaskManagerService atm = mSystemServiceManager.startService(
ActivityTaskManagerService.Lifecycle.class).getService();
mActivityManagerService = ActivityManagerService.Lifecycle.startService(
mSystemServiceManager, atm);
mActivityManagerService.setSystemServiceManager(mSystemServiceManager);
mActivityManagerService.setInstaller(installer);
mWindowManagerGlobalLock = atm.getGlobalLock();

...
}

AMS的是通过AMS的内部类Lifecycle来创建的,同时调用Lifecycle.onStart()来启动AMS。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public static final class Lifecycle extends SystemService {
private final ActivityManagerService mService;
private static ActivityTaskManagerService sAtm;

public Lifecycle(Context context) {
super(context);
mService = new ActivityManagerService(context, sAtm);
}

public static ActivityManagerService startService(
SystemServiceManager ssm, ActivityTaskManagerService atm) {
sAtm = atm;
return ssm.startService(ActivityManagerService.Lifecycle.class).getService();
}

@Override
public void onStart() {
mService.start();
}

...
}

Lifecycle继承于SystemService,通过ssm即SystemServiceManager来启动这个Service。

内部是通过反射来创建Lifecycle实例,而在Lifecycle实例的过程中会创建AMS。

所以接下来我们来看下AMS实例化过程中做了什么

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
public ActivityManagerService(Context systemContext, ActivityTaskManagerService atm) {
...

// 创建名为ActivityManager的线程,并创建MainHandler
// 处理各种状态信息的线程(GC、service_timeout、update_time_zone、kill_application、kill_zygote)
mHandlerThread = new ServiceThread(TAG,
THREAD_PRIORITY_FOREGROUND, false /*allowIo*/);
mHandlerThread.start();
mHandler = new MainHandler(mHandlerThread.getLooper());
// 获取UiHandler
mUiHandler = mInjector.getUiHandler(this);

// 创建与启动proc线程
mProcStartHandlerThread = new ServiceThread(TAG + ":procStart",
THREAD_PRIORITY_FOREGROUND, false /* allowIo */);
mProcStartHandlerThread.start();
mProcStartHandler = new Handler(mProcStartHandlerThread.getLooper());

// 定义一些常量,管理ActivityManager的行为
mConstants = new ActivityManagerConstants(mContext, this, mHandler);
// 追踪活跃的uid
final ActiveUids activeUids = new ActiveUids(this, true /* postChangesToAtm */);
mProcessList.init(this, activeUids);
// 低内存探测器
mLowMemDetector = new LowMemDetector(this);
mOomAdjuster = new OomAdjuster(this, mProcessList, activeUids);

// 前台广播接收器
final BroadcastConstants foreConstants = new BroadcastConstants(
Settings.Global.BROADCAST_FG_CONSTANTS);
foreConstants.TIMEOUT = BROADCAST_FG_TIMEOUT;

// 后台广播接收器
final BroadcastConstants backConstants = new BroadcastConstants(
Settings.Global.BROADCAST_BG_CONSTANTS);
backConstants.TIMEOUT = BROADCAST_BG_TIMEOUT;

// 卸载广播接收器
final BroadcastConstants offloadConstants = new BroadcastConstants(
Settings.Global.BROADCAST_OFFLOAD_CONSTANTS);
offloadConstants.TIMEOUT = BROADCAST_BG_TIMEOUT;

offloadConstants.SLOW_TIME = Integer.MAX_VALUE;

mEnableOffloadQueue = SystemProperties.getBoolean(
"persist.device_config.activity_manager_native_boot.offload_queue_enabled", false);

mFgBroadcastQueue = new BroadcastQueue(this, mHandler,
"foreground", foreConstants, false);
mBgBroadcastQueue = new BroadcastQueue(this, mHandler,
"background", backConstants, true);
mOffloadBroadcastQueue = new BroadcastQueue(this, mHandler,
"offload", offloadConstants, true);
mBroadcastQueues[0] = mFgBroadcastQueue;
mBroadcastQueues[1] = mBgBroadcastQueue;
mBroadcastQueues[2] = mOffloadBroadcastQueue;

mServices = new ActiveServices(this);
mProviderMap = new ProviderMap(this);
mPackageWatchdog = PackageWatchdog.getInstance(mUiContext);
mAppErrors = new AppErrors(mUiContext, this, mPackageWatchdog);

final File systemDir = SystemServiceManager.ensureSystemDir();

// 电池状态
mBatteryStatsService = new BatteryStatsService(systemContext, systemDir,
BackgroundThread.get().getHandler());
mBatteryStatsService.getActiveStatistics().readLocked();
mBatteryStatsService.scheduleWriteToDisk();
mOnBattery = DEBUG_POWER ? true
: mBatteryStatsService.getActiveStatistics().getIsOnBattery();
mBatteryStatsService.getActiveStatistics().setCallback(this);
mOomAdjProfiler.batteryPowerChanged(mOnBattery);

// 进程状态
mProcessStats = new ProcessStatsService(this, new File(systemDir, "procstats"));

mAppOpsService = mInjector.getAppOpsService(new File(systemDir, "appops.xml"), mHandler);

...

mActivityTaskManager = atm;
mActivityTaskManager.initialize(mIntentFirewall, mPendingIntentController,
DisplayThread.get().getLooper());
mAtmInternal = LocalServices.getService(ActivityTaskManagerInternal.class);

// 进程cpu统计线程
mProcessCpuThread = new Thread("CpuTracker") {
@Override
public void run() {
synchronized (mProcessCpuTracker) {
mProcessCpuInitLatch.countDown();
mProcessCpuTracker.init();
}
while (true) {
try {
try {
synchronized(this) {
final long now = SystemClock.uptimeMillis();
long nextCpuDelay = (mLastCpuTime.get()+MONITOR_CPU_MAX_TIME)-now;
long nextWriteDelay = (mLastWriteTime+BATTERY_STATS_TIME)-now;
//Slog.i(TAG, "Cpu delay=" + nextCpuDelay
// + ", write delay=" + nextWriteDelay);
if (nextWriteDelay < nextCpuDelay) {
nextCpuDelay = nextWriteDelay;
}
if (nextCpuDelay > 0) {
mProcessCpuMutexFree.set(true);
this.wait(nextCpuDelay);
}
}
} catch (InterruptedException e) {
}
// 更新cpu的信息
updateCpuStatsNow();
} catch (Exception e) {
Slog.e(TAG, "Unexpected exception collecting process stats", e);
}
}
}
};

...
}

所以这里主要做的事是创建ActivityManager、proc与CpuTracker线程;同时创建对应的广播接收器。

创建完AMS实例之后会调用start()方法来启动AMS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
private void start() {
// 移除所有进程组
removeAllProcessGroups();
// 开启进程cpu统计线程
mProcessCpuThread.start();

// 启动电池统计服务
mBatteryStatsService.publish();
mAppOpsService.publish(mContext);

// 添加到本地LocalServices中
LocalServices.addService(ActivityManagerInternal.class, new LocalService());
mActivityTaskManager.onActivityManagerInternalAdded();
mUgmInternal.onActivityManagerInternalAdded();
mPendingIntentController.onActivityManagerInternalAdded();

try {
// 等待进程cpu统计线程运行
mProcessCpuInitLatch.await();
} catch (InterruptedException e) {
Slog.wtf(TAG, "Interrupted wait during start", e);
Thread.currentThread().interrupt();
throw new IllegalStateException("Interrupted wait during start");
}
}

这个时候AMS就已经启动完毕。

下面我们在来看下AMS在SystemServer中都干了什么

startBootstrapServices

1
2
3
4
5
6
7
8
9
private void startBootstrapServices() {
...

mActivityManagerService.initPowerManagement();
...

mActivityManagerService.setSystemProcess();
...
}

initPowerManagement

首先会初始化PowerManagement

1
2
3
4
5
public void initPowerManagement() {
mActivityTaskManager.onInitPowerManagement();
mBatteryStatsService.initPowerManagement();
mLocalPowerManager = LocalServices.getService(PowerManagerInternal.class);
}

最终会通过BatterStateService来初始化PowerManagement。

setSystemProcess

接下来是setSystemProcess,注册相关的服务。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public void setSystemProcess() {
try {
// 注册ActivityManagerService
ServiceManager.addService(Context.ACTIVITY_SERVICE, this, /* allowIsolated= */ true,
DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PROTO);
// 注册 ProcessStatsService
ServiceManager.addService(ProcessStats.SERVICE_NAME, mProcessStats);
// 注册MemBinder
ServiceManager.addService("meminfo", new MemBinder(this), /* allowIsolated= */ false,
DUMP_FLAG_PRIORITY_HIGH);
// 注册GraphicsBinder
ServiceManager.addService("gfxinfo", new GraphicsBinder(this));
// 注册DbBinder
ServiceManager.addService("dbinfo", new DbBinder(this));
if (MONITOR_CPU_USAGE) {
// 注册CpuBinder
ServiceManager.addService("cpuinfo", new CpuBinder(this),
/* allowIsolated= */ false, DUMP_FLAG_PRIORITY_CRITICAL);
}
// 注册PermissionController
ServiceManager.addService("permission", new PermissionController(this));
// 注册ProcessInfoService
ServiceManager.addService("processinfo", new ProcessInfoService(this));

// 加载包名为android的包,最终通过LoadedApk来加载
ApplicationInfo info = mContext.getPackageManager().getApplicationInfo(
"android", STOCK_PM_FLAGS | MATCH_SYSTEM_ONLY);
mSystemThread.installSystemApplicationInfo(info, getClass().getClassLoader());

...
}

需要注意的是,这里将AMS注册到ServiceManager中,后续通过ActivityManager来获取注册的AMS。

接下来就进入了startCoreServices,启动核心服务

startCoreServices

1
2
3
4
5
6
private void startCoreServices() {
...
mActivityManagerService.setUsageStatsManager(
LocalServices.getService(UsageStatsManagerInternal.class));
...
}

这里做的事情很简单,设置UsageStateManager

startOtherServices

继续来到启动其它的服务模块

1
2
3
4
5
6
7
8
9
private void startOtherServices() {
...
mActivityManagerService.installSystemProviders();

mActivityManagerService.setWindowManager(wm);

mActivityManagerService.systemReady(...)
...
}

在这里主要做的是安装系统的Provider、设置WindowManagerService与systemReady的准备工作。

installSystemProviders

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public final void installSystemProviders() {
List<ProviderInfo> providers;
synchronized (this) {
ProcessRecord app = mProcessList.mProcessNames.get("system", SYSTEM_UID);
// 获取Providers
providers = generateApplicationProvidersLocked(app);
if (providers != null) {
for (int i=providers.size()-1; i>=0; i--) {
ProviderInfo pi = (ProviderInfo)providers.get(i);
// 清除非系统的Providers
if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) {
providers.remove(i);
}
}
}
}
// 通过ActivityThread来安装系统的Providers
if (providers != null) {
mSystemThread.installSystemProviders(providers);
}

synchronized (this) {
mSystemProvidersInstalled = true;
}
mConstants.start(mContext.getContentResolver());
mCoreSettingsObserver = new CoreSettingsObserver(this);
mActivityTaskManager.installSystemProviders();
mDevelopmentSettingsObserver = new DevelopmentSettingsObserver();
SettingsToPropertiesMapper.start(mContext.getContentResolver());
mOomAdjuster.initSettings();
}

这里主要做的就是安装系统的Providers

WindowManagerService

1
2
3
4
5
6
public void setWindowManager(WindowManagerService wm) {
synchronized (this) {
mWindowManager = wm;
mActivityTaskManager.setWindowManager(wm);
}
}

设置WindowManagerService服务

systemReady

systemReady的逻辑比较多,我们拆开来说

1
2
3
4
5
6
7
public void systemReady(final Runnable goingCallback, TimingsTraceLog traceLog) {
goingCallback before

if (goingCallback != null) goingCallback.run();

goingCallback after
}

在调用goingCallback.run之前

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
public void systemReady(final Runnable goingCallback, TimingsTraceLog traceLog) {
synchronized(this) {
// 第一次进来为false,跳过
if (mSystemReady) {
if (goingCallback != null) {
goingCallback.run();
}
return;
}

...

mSystemReady = true;
}

...

ArrayList<ProcessRecord> procsToKill = null;
synchronized(mPidsSelfLocked) {
for (int i=mPidsSelfLocked.size()-1; i>=0; i--) {
ProcessRecord proc = mPidsSelfLocked.valueAt(i);
// 非president进程
if (!isAllowedWhileBooting(proc.info)){
if (procsToKill == null) {
procsToKill = new ArrayList<ProcessRecord>();
}
// 加入到procsTokill中
procsToKill.add(proc);
}
}
}

synchronized(this) {
if (procsToKill != null) {
// kill procsToKill中的进程
for (int i=procsToKill.size()-1; i>=0; i--) {
ProcessRecord proc = procsToKill.get(i);
mProcessList.removeProcessLocked(proc, true, false, "system update done");
}
}

mProcessesReady = true;
}

...

if (goingCallback != null) goingCallback.run();

...
}

主要做的事情杀掉procsToKill中的进程,此时系统与进程都已经准备就绪

之后再调用goingCallback.run

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
mActivityManagerService.systemReady(() -> {

// BootPhase 550
mSystemServiceManager.startBootPhase(
SystemService.PHASE_ACTIVITY_MANAGER_READY);

try {
mActivityManagerService.startObservingNativeCrashes();
} catch (Throwable e) {
reportWtf("observing native crashes", e);
}

traceBeginAndSlog("MakeConnectivityServiceReady");
try {
if (connectivityF != null) {
connectivityF.systemReady();
}
} catch (Throwable e) {
reportWtf("making Connectivity Service ready", e);
}

...

// BootPhase 600
mSystemServiceManager.startBootPhase(
SystemService.PHASE_THIRD_PARTY_APPS_CAN_START);

try {
if (locationF != null) {
locationF.systemRunning();
}
} catch (Throwable e) {
reportWtf("Notifying Location Service running", e);
}

try {
if (countryDetectorF != null) {
countryDetectorF.systemRunning();
}
} catch (Throwable e) {
reportWtf("Notifying CountryDetectorService running", e);
}

...

}, BOOT_TIMINGS_TRACE_LOG);

这个在Android SystemServer启动(二)中已经分析了,这里就不多介绍了。

主要是对一些服务进行systemReady与systemRuning操作。

最后来到systemReady的最后一个步骤

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
public void systemReady(final Runnable goingCallback, TimingsTraceLog traceLog) {
...

if (goingCallback != null) goingCallback.run();

final int currentUserId = mUserController.getCurrentUserId();
if (currentUserId != UserHandle.USER_SYSTEM && !mUserController.isSystemUserStarted()) {
throw new RuntimeException("System user not started while current user is:"
+ currentUserId);
}
mBatteryStatsService.noteEvent(BatteryStats.HistoryItem.EVENT_USER_RUNNING_START,
Integer.toString(currentUserId), currentUserId);
mBatteryStatsService.noteEvent(BatteryStats.HistoryItem.EVENT_USER_FOREGROUND_START,
Integer.toString(currentUserId), currentUserId);

// 调用所有SystemService的onStartUser方法
mSystemServiceManager.startUser(currentUserId);

synchronized (this) {
// 开启Persistent app
startPersistentApps(PackageManager.MATCH_DIRECT_BOOT_AWARE);

mBooting = true;
if (UserManager.isSplitSystemUser() &&
Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.USER_SETUP_COMPLETE, 0) != 0) {
ComponentName cName = new ComponentName(mContext, SystemUserHomeActivity.class);
try {
AppGlobals.getPackageManager().setComponentEnabledSetting(cName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0,
UserHandle.USER_SYSTEM);
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
// 启动系统桌面Activity
mAtmInternal.startHomeOnAllDisplays(currentUserId, "systemReady");

mAtmInternal.showSystemReadyErrorDialogsIfNeeded();

final int callingUid = Binder.getCallingUid();
final int callingPid = Binder.getCallingPid();
long ident = Binder.clearCallingIdentity();
try {
// 发送USER_STARTED广播
Intent intent = new Intent(Intent.ACTION_USER_STARTED);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
| Intent.FLAG_RECEIVER_FOREGROUND);
intent.putExtra(Intent.EXTRA_USER_HANDLE, currentUserId);
broadcastIntentLocked(null, null, intent,
null, null, 0, null, null, null, OP_NONE,
null, false, false, MY_PID, SYSTEM_UID, callingUid, callingPid,
currentUserId);

// 发送USER_STARTING广播
intent = new Intent(Intent.ACTION_USER_STARTING);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
intent.putExtra(Intent.EXTRA_USER_HANDLE, currentUserId);
broadcastIntentLocked(null, null, intent,
null, new IIntentReceiver.Stub() {
@Override
public void performReceive(Intent intent, int resultCode, String data,
Bundle extras, boolean ordered, boolean sticky, int sendingUser)
throws RemoteException {
}
}, 0, null, null,
new String[] {INTERACT_ACROSS_USERS}, OP_NONE,
null, true, false, MY_PID, SYSTEM_UID, callingUid, callingPid,
UserHandle.USER_ALL);
} catch (Throwable t) {
Slog.wtf(TAG, "Failed sending first user broadcasts", t);
} finally {
Binder.restoreCallingIdentity(ident);
}
mAtmInternal.resumeTopActivities(false /* scheduleIdle */);
mUserController.sendUserSwitchBroadcasts(-1, currentUserId);

BinderInternal.nSetBinderProxyCountWatermarks(BINDER_PROXY_HIGH_WATERMARK,
BINDER_PROXY_LOW_WATERMARK);
BinderInternal.nSetBinderProxyCountEnabled(true);
BinderInternal.setBinderProxyCountCallback(
new BinderInternal.BinderProxyLimitListener() {
@Override
public void onLimitReached(int uid) {
Slog.wtf(TAG, "Uid " + uid + " sent too many Binders to uid "
+ Process.myUid());
BinderProxy.dumpProxyDebugInfo();
if (uid == Process.SYSTEM_UID) {
Slog.i(TAG, "Skipping kill (uid is SYSTEM)");
} else {
killUid(UserHandle.getAppId(uid), UserHandle.getUserId(uid),
"Too many Binders sent to SYSTEM");
}
}
}, mHandler);

// 恢复栈顶Activity
mAtmInternal.resumeTopActivities(false /* scheduleIdle */);
// 发送User_SWITCH 广播
mUserController.sendUserSwitchBroadcasts(-1, currentUserId);

...
}
}

其中startUser会回调之前的SystemService的onStartUser方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public void startUser(final int userHandle) {
final int serviceLen = mServices.size();
// 遍历mServices
for (int i = 0; i < serviceLen; i++) {
final SystemService service = mServices.get(i);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "onStartUser "
+ service.getClass().getName());
long time = SystemClock.elapsedRealtime();
try {
// 回调onStartUser
service.onStartUser(userHandle);
} catch (Exception ex) {
Slog.wtf(TAG, "Failure reporting start of user " + userHandle
+ " to service " + service.getClass().getName(), ex);
}
}
}

startHomeOnAllDisplays最终会来到RootActivityContainer的startHomeOnDisplay方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
boolean startHomeOnDisplay(int userId, String reason, int displayId, boolean allowInstrumenting,
boolean fromHomeKey) {
if (displayId == INVALID_DISPLAY) {
displayId = getTopDisplayFocusedStack().mDisplayId;
}

Intent homeIntent = null;
ActivityInfo aInfo = null;
if (displayId == DEFAULT_DISPLAY) {
homeIntent = mService.getHomeIntent();
aInfo = resolveHomeActivity(userId, homeIntent);
} else if (shouldPlaceSecondaryHomeOnDisplay(displayId)) {
Pair<ActivityInfo, Intent> info = resolveSecondaryHomeActivity(userId, displayId);
aInfo = info.first;
homeIntent = info.second;
}
if (aInfo == null || homeIntent == null) {
return false;
}

if (!canStartHomeOnDisplay(aInfo, displayId, allowInstrumenting)) {
return false;
}

// 设置home Intent 的Component信息
homeIntent.setComponent(new ComponentName(aInfo.applicationInfo.packageName, aInfo.name));
homeIntent.setFlags(homeIntent.getFlags() | FLAG_ACTIVITY_NEW_TASK);

// 设置extra
if (fromHomeKey) {
homeIntent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, true);
}

final String myReason = reason + ":" + userId + ":" + UserHandle.getUserId(
aInfo.applicationInfo.uid) + ":" + displayId;

// 启动桌面Activity
mService.getActivityStartController().startHomeActivity(homeIntent, aInfo, myReason,
displayId);
return true;
}

总结一下,在goingCallback.run之后,该阶段主要做的事情是:

  1. 调用所有之前添加的SystemService的onStartUser方法
  2. 启动Persistent进程
  3. 启动系统桌面Activity
  4. 发送USER_STARTED广播
  5. 发送USER_STARTING广播
  6. 恢复栈顶Activity
  7. 发送User_SWITCH广播

以上就是AMS在SystemServer中的全部过程, 也是AMS的启动过程。

整个过程主要做的事情是:

  1. 通过Lifecycle创建AMS实例,同时调用onStart()方法启动AMS
  2. 通过setSystemProcess注册AMS、meminfo、gfxinfo、dbinfo、cpuinfo等服务到ServiceManager中
  3. 通过installSystemProviders来加载系统的providers
  4. 通过systemReady来ready与running各种服务,同时启动桌面应用,发送相关广播与恢复栈顶Activity

项目

android_startup: 提供一种在应用启动时能够更加简单、高效的方式来初始化组件,优化启动速度。不仅支持Jetpack App Startup的全部功能,还提供额外的同步与异步等待、线程控制与多进程支持等功能。

AwesomeGithub: 基于Github的客户端,纯练习项目,支持组件化开发,支持账户密码与认证登陆。使用Kotlin语言进行开发,项目架构是基于JetPack&DataBinding的MVVM;项目中使用了Arouter、Retrofit、Coroutine、Glide、Dagger与Hilt等流行开源技术。

flutter_github: 基于Flutter的跨平台版本Github客户端,与AwesomeGithub相对应。

android-api-analysis: 结合详细的Demo来全面解析Android相关的知识点, 帮助读者能够更快的掌握与理解所阐述的要点。

daily_algorithm: 每日一算法,由浅入深,欢迎加入一起共勉。

支持一下
赞赏是一门艺术