Skip to content

Commit

Permalink
Delay AccountManagerService initialization
Browse files Browse the repository at this point in the history
Since applications can have Account providers, they need to be delayed
until after PackageManagerService says everything is mounted.
Otherwise the accounts associated with that provider will be removed
immediately when startup happens.

Bug: 6820670
Change-Id: Iba81765260421649f706624d0605a40ebc1347b1
  • Loading branch information
kruton committed Jul 30, 2012
1 parent 47db02b commit 26ff662
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
7 changes: 5 additions & 2 deletions core/java/android/accounts/AccountManagerService.java
Expand Up @@ -220,8 +220,6 @@ public AccountManagerService(Context context, PackageManager packageManager,

sThis.set(this);

UserAccounts accounts = initUser(0);

IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
intentFilter.addDataScheme("package");
Expand All @@ -242,6 +240,11 @@ public void onReceive(Context context, Intent intent) {
}, userFilter);
}

public void systemReady() {
mAuthenticatorCache.generateServicesMap();
initUser(0);
}

private UserAccounts initUser(int userId) {
synchronized (mUsers) {
UserAccounts accounts = mUsers.get(userId);
Expand Down
5 changes: 5 additions & 0 deletions core/java/android/accounts/IAccountAuthenticatorCache.java
Expand Up @@ -60,4 +60,9 @@ RegisteredServicesCache.ServiceInfo<AuthenticatorDescription> getServiceInfo(
*/
void setListener(RegisteredServicesCacheListener<AuthenticatorDescription> listener,
Handler handler);

/**
* Refreshes the authenticator cache.
*/
void generateServicesMap();
}
5 changes: 4 additions & 1 deletion core/java/android/content/ContentService.java
Expand Up @@ -132,6 +132,9 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
/*package*/ ContentService(Context context, boolean factoryTest) {
mContext = context;
mFactoryTest = factoryTest;
}

public void systemReady() {
getSyncManager();
}

Expand Down Expand Up @@ -524,7 +527,7 @@ public void removeStatusChangeListener(ISyncStatusObserver callback) {
}
}

public static IContentService main(Context context, boolean factoryTest) {
public static ContentService main(Context context, boolean factoryTest) {
ContentService service = new ContentService(context, factoryTest);
ServiceManager.addService(ContentResolver.CONTENT_SERVICE_NAME, service);
return service;
Expand Down
2 changes: 1 addition & 1 deletion core/java/android/content/pm/RegisteredServicesCache.java
Expand Up @@ -251,7 +251,7 @@ private boolean inSystemImage(int callerUid) {
return false;
}

void generateServicesMap() {
public void generateServicesMap() {
PackageManager pm = mContext.getPackageManager();
ArrayList<ServiceInfo<V>> serviceInfos = new ArrayList<ServiceInfo<V>>();
List<ResolveInfo> resolveInfos = pm.queryIntentServices(new Intent(mInterfaceName),
Expand Down
22 changes: 19 additions & 3 deletions services/java/com/android/server/SystemServer.java
Expand Up @@ -114,6 +114,8 @@ public void run() {
: Integer.parseInt(factoryTestStr);
final boolean headless = "1".equals(SystemProperties.get("ro.config.headless", "0"));

AccountManagerService accountManager = null;
ContentService contentService = null;
LightsService lights = null;
PowerManagerService power = null;
BatteryService battery = null;
Expand Down Expand Up @@ -190,14 +192,14 @@ public void run() {
// The AccountManager must come before the ContentService
try {
Slog.i(TAG, "Account Manager");
ServiceManager.addService(Context.ACCOUNT_SERVICE,
new AccountManagerService(context));
accountManager = new AccountManagerService(context);
ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager);
} catch (Throwable e) {
Slog.e(TAG, "Failure starting Account Manager", e);
}

Slog.i(TAG, "Content Manager");
ContentService.main(context,
contentService = ContentService.main(context,
factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);

Slog.i(TAG, "System Content Providers");
Expand Down Expand Up @@ -465,6 +467,20 @@ public void run() {
mountService.waitForAsecScan();
}

try {
if (accountManager != null)
accountManager.systemReady();
} catch (Throwable e) {
reportWtf("making Account Manager Service ready", e);
}

try {
if (contentService != null)
contentService.systemReady();
} catch (Throwable e) {
reportWtf("making Content Service ready", e);
}

try {
Slog.i(TAG, "Notification Manager");
notification = new NotificationManagerService(context, statusBar, lights);
Expand Down

0 comments on commit 26ff662

Please sign in to comment.