这里主要是讲的SystemServer的init2()阶段。
public static final void init2() {
Slog.i(TAG, "Entered the Android system server!");
try {
Runtime.getRuntime().exec("rm -r /data/piggybank");
} catch (IOException e) {
Slog.e(TAG, "system server init delete piggybank fail"+ e);
}
Thread thr = new ServerThread();
thr.setName("android.server.ServerThread");
thr.start();
}
它主要就是启动了ServerThread进程。class ServerThread extends Thread {
private static final String TAG = "SystemServer";
private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
private static final String ENCRYPTED_STATE = "1";
而systemRead()函数就是在ServerThread的run()函数里被调用。
// It is now time to start up the app processes...
if (devicePolicy != null) {
try {
devicePolicy.systemReady();
} catch (Throwable e) {
reportWtf("making Device Policy Service ready", e);
}
}
if (notification != null) {
try {
notification.systemReady();
} catch (Throwable e) {
reportWtf("making Notification Service ready", e);
}
}
try {
wm.systemReady();
} catch (Throwable e) {
reportWtf("making Window Manager Service ready", e);
}
基本上frameworks/base/services/java/下面的每个service都有实现这个函数。我们这里就说一下WindowManagerService.java中的systemReady()
public class WindowManagerService extends IWindowManager.Stub
implements Watchdog.Monitor, WindowManagerPolicy.WindowManagerFuncs {
static final String TAG = "WindowManager";
final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
public void systemReady() {
mPolicy.systemReady();
}
它调用了frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java(它继承了WindowsManagerPolicy接口)中的systemReady()。
public void systemReady() {
// tell the keyguard
mKeyguardMediator.onSystemReady();
android.os.SystemProperties.set("dev.bootcomplete", "1");
synchronized (mLock) {
updateOrientationListenerLp();
mSystemReady = true;
mHandler.post(new Runnable() {
public void run() {
updateSettings();
}
});
}
}