Fiddle system boot ordering.
This makes the system a little more careful to not start third party
code until it is ready to.
Also fix a little bug in SyncManager that would cause it to crash
during boot if sync was in a failure state.
Change-Id: Ib2d287d8441d155d393fe740a5f98690895fd358
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index 52d6891..213f26e 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -941,13 +941,6 @@
return true;
}
- case SYSTEM_READY_TRANSACTION: {
- data.enforceInterface(IActivityManager.descriptor);
- systemReady();
- reply.writeNoException();
- return true;
- }
-
case HANDLE_APPLICATION_ERROR_TRANSACTION: {
data.enforceInterface(IActivityManager.descriptor);
IBinder app = data.readStrongBinder();
@@ -2248,16 +2241,6 @@
data.recycle();
reply.recycle();
}
- public void systemReady() throws RemoteException
- {
- Parcel data = Parcel.obtain();
- Parcel reply = Parcel.obtain();
- data.writeInterfaceToken(IActivityManager.descriptor);
- mRemote.transact(SYSTEM_READY_TRANSACTION, data, reply, 0);
- reply.readException();
- data.recycle();
- reply.recycle();
- }
public boolean testIsSystemReady()
{
/* this base class version is never called */
diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java
index 98a8481..a7bef54 100644
--- a/core/java/android/app/IActivityManager.java
+++ b/core/java/android/app/IActivityManager.java
@@ -233,7 +233,6 @@
// Special low-level communication with activity manager.
public void startRunning(String pkg, String cls, String action,
String data) throws RemoteException;
- public void systemReady() throws RemoteException;
// Returns 1 if the user wants to debug.
public int handleApplicationError(IBinder app,
int flags, /* 1 == can debug */
@@ -368,7 +367,7 @@
int PUBLISH_CONTENT_PROVIDERS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+29;
int SET_PERSISTENT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+30;
int FINISH_SUB_ACTIVITY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+31;
- int SYSTEM_READY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+32;
+
int START_SERVICE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+33;
int STOP_SERVICE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+34;
int BIND_SERVICE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+35;
diff --git a/core/java/android/content/SyncManager.java b/core/java/android/content/SyncManager.java
index 1f3fbf6..5ffe962 100644
--- a/core/java/android/content/SyncManager.java
+++ b/core/java/android/content/SyncManager.java
@@ -2035,6 +2035,7 @@
private void sendSyncStateIntent() {
Intent syncStateIntent = new Intent(Intent.ACTION_SYNC_STATE_CHANGED);
+ syncStateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
syncStateIntent.putExtra("active", mNeedSyncActiveNotification);
syncStateIntent.putExtra("failing", mNeedSyncErrorNotification);
mContext.sendBroadcast(syncStateIntent);
diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java
index 4198154..3c37b49 100644
--- a/services/java/com/android/server/InputMethodManagerService.java
+++ b/services/java/com/android/server/InputMethodManagerService.java
@@ -180,6 +180,11 @@
= new HashMap<IBinder, ClientState>();
/**
+ * Set once the system is ready to run third party code.
+ */
+ boolean mSystemReady;
+
+ /**
* Id of the currently selected input method.
*/
String mCurMethodId;
@@ -508,6 +513,12 @@
}
public void systemReady() {
+ synchronized (mMethodMap) {
+ if (!mSystemReady) {
+ mSystemReady = true;
+ startInputInnerLocked();
+ }
+ }
}
public List<InputMethodInfo> getInputMethodList() {
@@ -727,6 +738,20 @@
}
}
+ return startInputInnerLocked();
+ }
+
+ InputBindResult startInputInnerLocked() {
+ if (mCurMethodId == null) {
+ return mNoBinding;
+ }
+
+ if (!mSystemReady) {
+ // If the system is not yet ready, we shouldn't be running third
+ // party code.
+ return new InputBindResult(null, mCurId, mCurSeq);
+ }
+
InputMethodInfo info = mMethodMap.get(mCurMethodId);
if (info == null) {
throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index df01c61..1158a71 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -92,22 +92,22 @@
// Critical services...
try {
- Log.i(TAG, "Starting Entropy Service.");
+ Log.i(TAG, "Entropy Service");
ServiceManager.addService("entropy", new EntropyService());
- Log.i(TAG, "Starting Power Manager.");
+ Log.i(TAG, "Power Manager");
power = new PowerManagerService();
ServiceManager.addService(Context.POWER_SERVICE, power);
- Log.i(TAG, "Starting Activity Manager.");
+ Log.i(TAG, "Activity Manager");
context = ActivityManagerService.main(factoryTest);
- Log.i(TAG, "Starting telephony registry");
+ Log.i(TAG, "Telephony Registry");
ServiceManager.addService("telephony.registry", new TelephonyRegistry(context));
AttributeCache.init(context);
- Log.i(TAG, "Starting Package Manager.");
+ Log.i(TAG, "Package Manager");
pm = PackageManagerService.main(context,
factoryTest != SystemServer.FACTORY_TEST_OFF);
@@ -116,25 +116,25 @@
mContentResolver = context.getContentResolver();
try {
- Log.i(TAG, "Starting Account Manager.");
+ Log.i(TAG, "Account Manager");
ServiceManager.addService(Context.ACCOUNT_SERVICE,
new AccountManagerService(context));
} catch (Throwable e) {
Log.e(TAG, "Failure starting Account Manager", e);
}
- Log.i(TAG, "Starting Content Manager.");
+ Log.i(TAG, "Content Manager");
ContentService.main(context,
factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
- Log.i(TAG, "Starting System Content Providers.");
+ Log.i(TAG, "System Content Providers");
ActivityManagerService.installSystemProviders();
- Log.i(TAG, "Starting Battery Service.");
+ Log.i(TAG, "Battery Service");
battery = new BatteryService(context);
ServiceManager.addService("battery", battery);
- Log.i(TAG, "Starting Hardware Service.");
+ Log.i(TAG, "Hardware Service");
hardware = new HardwareService(context);
ServiceManager.addService("hardware", hardware);
@@ -142,18 +142,19 @@
// hardware service, content providers and the battery service.
power.init(context, hardware, ActivityManagerService.getDefault(), battery);
- Log.i(TAG, "Starting Alarm Manager.");
+ Log.i(TAG, "Alarm Manager");
AlarmManagerService alarm = new AlarmManagerService(context);
ServiceManager.addService(Context.ALARM_SERVICE, alarm);
+ Log.i(TAG, "Init Watchdog");
Watchdog.getInstance().init(context, battery, power, alarm,
ActivityManagerService.self());
// Sensor Service is needed by Window Manager, so this goes first
- Log.i(TAG, "Starting Sensor Service.");
+ Log.i(TAG, "Sensor Service");
ServiceManager.addService(Context.SENSOR_SERVICE, new SensorService(context));
- Log.i(TAG, "Starting Window Manager.");
+ Log.i(TAG, "Window Manager");
wm = WindowManagerService.main(context, power,
factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL);
ServiceManager.addService(Context.WINDOW_SERVICE, wm);
@@ -171,7 +172,7 @@
Log.i(TAG, "Registering null Bluetooth Service (factory test)");
ServiceManager.addService(Context.BLUETOOTH_SERVICE, null);
} else {
- Log.i(TAG, "Starting Bluetooth Service.");
+ Log.i(TAG, "Bluetooth Service");
bluetooth = new BluetoothService(context);
ServiceManager.addService(Context.BLUETOOTH_SERVICE, bluetooth);
bluetooth.initAfterRegistration();
@@ -198,7 +199,7 @@
if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
try {
- Log.i(TAG, "Starting Status Bar Service.");
+ Log.i(TAG, "Status Bar");
statusBar = new StatusBarService(context);
ServiceManager.addService("statusbar", statusBar);
} catch (Throwable e) {
@@ -206,14 +207,14 @@
}
try {
- Log.i(TAG, "Starting Clipboard Service.");
+ Log.i(TAG, "Clipboard Service");
ServiceManager.addService("clipboard", new ClipboardService(context));
} catch (Throwable e) {
Log.e(TAG, "Failure starting Clipboard Service", e);
}
try {
- Log.i(TAG, "Starting Input Method Service.");
+ Log.i(TAG, "Input Method Service");
imm = new InputMethodManagerService(context, statusBar);
ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
} catch (Throwable e) {
@@ -221,14 +222,14 @@
}
try {
- Log.i(TAG, "Starting NetStat Service.");
+ Log.i(TAG, "NetStat Service");
ServiceManager.addService("netstat", new NetStatService(context));
} catch (Throwable e) {
Log.e(TAG, "Failure starting NetStat Service", e);
}
try {
- Log.i(TAG, "Starting Connectivity Service.");
+ Log.i(TAG, "Connectivity Service");
connectivity = ConnectivityService.getInstance(context);
ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
} catch (Throwable e) {
@@ -236,7 +237,7 @@
}
try {
- Log.i(TAG, "Starting Accessibility Manager.");
+ Log.i(TAG, "Accessibility Manager");
ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
new AccessibilityManagerService(context));
} catch (Throwable e) {
@@ -244,7 +245,7 @@
}
try {
- Log.i(TAG, "Starting Notification Manager.");
+ Log.i(TAG, "Notification Manager");
notification = new NotificationManagerService(context, statusBar, hardware);
ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
} catch (Throwable e) {
@@ -253,14 +254,14 @@
try {
// MountService must start after NotificationManagerService
- Log.i(TAG, "Starting Mount Service.");
+ Log.i(TAG, "Mount Service");
ServiceManager.addService("mount", new MountService(context));
} catch (Throwable e) {
Log.e(TAG, "Failure starting Mount Service", e);
}
try {
- Log.i(TAG, "Starting DeviceStorageMonitor service");
+ Log.i(TAG, "Device Storage Monitor");
ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
new DeviceStorageMonitorService(context));
} catch (Throwable e) {
@@ -268,14 +269,14 @@
}
try {
- Log.i(TAG, "Starting Location Manager.");
+ Log.i(TAG, "Location Manager");
ServiceManager.addService(Context.LOCATION_SERVICE, new LocationManagerService(context));
} catch (Throwable e) {
Log.e(TAG, "Failure starting Location Manager", e);
}
try {
- Log.i(TAG, "Starting Search Service.");
+ Log.i(TAG, "Search Service");
ServiceManager.addService( Context.SEARCH_SERVICE, new SearchManagerService(context) );
} catch (Throwable e) {
Log.e(TAG, "Failure starting Search Service", e);
@@ -287,7 +288,7 @@
}
try {
- Log.i(TAG, "Starting Checkin Service.");
+ Log.i(TAG, "Checkin Service");
Intent intent = new Intent().setComponent(new ComponentName(
"com.google.android.server.checkin",
"com.google.android.server.checkin.CheckinService"));
@@ -300,7 +301,7 @@
}
try {
- Log.i(TAG, "Starting Wallpaper Service");
+ Log.i(TAG, "Wallpaper Service");
wallpaper = new WallpaperManagerService(context);
ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
} catch (Throwable e) {
@@ -308,14 +309,14 @@
}
try {
- Log.i(TAG, "Starting Audio Service");
+ Log.i(TAG, "Audio Service");
ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
} catch (Throwable e) {
Log.e(TAG, "Failure starting Audio Service", e);
}
try {
- Log.i(TAG, "Starting HeadsetObserver");
+ Log.i(TAG, "Headset Observer");
// Listen for wired headset changes
headset = new HeadsetObserver(context);
} catch (Throwable e) {
@@ -323,7 +324,7 @@
}
try {
- Log.i(TAG, "Starting DockObserver");
+ Log.i(TAG, "Dock Observer");
// Listen for dock station changes
dock = new DockObserver(context);
} catch (Throwable e) {
@@ -331,14 +332,14 @@
}
try {
- Log.i(TAG, "Starting Backup Service");
+ Log.i(TAG, "Backup Service");
ServiceManager.addService(Context.BACKUP_SERVICE, new BackupManagerService(context));
} catch (Throwable e) {
Log.e(TAG, "Failure starting Backup Service", e);
}
try {
- Log.i(TAG, "Starting AppWidget Service");
+ Log.i(TAG, "AppWidget Service");
appWidget = new AppWidgetService(context);
ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
} catch (Throwable e) {
@@ -361,7 +362,7 @@
false, new AdbSettingsObserver());
// It is now time to start up the app processes...
- boolean safeMode = wm.detectSafeMode();
+ final boolean safeMode = wm.detectSafeMode();
if (notification != null) {
notification.systemReady();
@@ -370,31 +371,45 @@
if (statusBar != null) {
statusBar.systemReady();
}
- if (imm != null) {
- imm.systemReady();
- }
wm.systemReady();
power.systemReady();
try {
pm.systemReady();
} catch (RemoteException e) {
}
- if (appWidget != null) {
- appWidget.systemReady(safeMode);
- }
- // After making the following code, third party code may be running...
- try {
- ActivityManagerNative.getDefault().systemReady();
- } catch (RemoteException e) {
- }
+ // These are needed to propagate to the runnable below.
+ final BatteryService batteryF = battery;
+ final ConnectivityService connectivityF = connectivity;
+ final DockObserver dockF = dock;
+ final AppWidgetService appWidgetF = appWidget;
+ final WallpaperManagerService wallpaperF = wallpaper;
+ final InputMethodManagerService immF = imm;
+
+ // We now tell the activity manager it is okay to run third party
+ // code. It will call back into us once it has gotten to the state
+ // where third party code can really run (but before it has actually
+ // started launching the initial applications), for us to complete our
+ // initialization.
+ ((ActivityManagerService)ActivityManagerNative.getDefault())
+ .systemReady(new Runnable() {
+ public void run() {
+ Log.i(TAG, "Making services ready");
+
+ if (batteryF != null) batteryF.systemReady();
+ if (connectivityF != null) connectivityF.systemReady();
+ if (dockF != null) dockF.systemReady();
+ Watchdog.getInstance().start();
- if (wallpaper != null) wallpaper.systemReady();
- if (battery != null) battery.systemReady();
- if (connectivity != null) connectivity.systemReady();
- if (dock != null) dock.systemReady();
- Watchdog.getInstance().start();
-
+ // It is now okay to let the various system services start their
+ // third party code...
+
+ if (appWidgetF != null) appWidgetF.systemReady(safeMode);
+ if (wallpaperF != null) wallpaperF.systemReady();
+ if (immF != null) immF.systemReady();
+ }
+ });
+
Looper.loop();
Log.d(TAG, "System ServerThread is exiting!");
}
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 8ea6699..03ebf0c 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -8188,7 +8188,7 @@
}
}
- systemReady();
+ systemReady(null);
}
private void retrieveSettings() {
@@ -8218,7 +8218,7 @@
return mSystemReady;
}
- public void systemReady() {
+ public void systemReady(final Runnable goingCallback) {
// In the simulator, startRunning will never have been called, which
// normally sets a few crucial variables. Do it here instead.
if (!Process.supportsProcesses()) {
@@ -8228,6 +8228,7 @@
synchronized(this) {
if (mSystemReady) {
+ if (goingCallback != null) goingCallback.run();
return;
}
@@ -8263,7 +8264,7 @@
synchronized (ActivityManagerService.this) {
mDidUpdate = true;
}
- systemReady();
+ systemReady(goingCallback);
}
};
}
@@ -8310,7 +8311,7 @@
}
}
- if (Config.LOGD) Log.d(TAG, "Start running!");
+ Log.i(TAG, "System now ready");
EventLog.writeEvent(LOG_BOOT_PROGRESS_AMS_READY,
SystemClock.uptimeMillis());
@@ -8352,6 +8353,8 @@
retrieveSettings();
+ if (goingCallback != null) goingCallback.run();
+
synchronized (this) {
if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
try {