Skip to content

Commit 26ff662

Browse files
committed
Delay AccountManagerService initialization
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
1 parent 47db02b commit 26ff662

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

core/java/android/accounts/AccountManagerService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ public AccountManagerService(Context context, PackageManager packageManager,
220220

221221
sThis.set(this);
222222

223-
UserAccounts accounts = initUser(0);
224-
225223
IntentFilter intentFilter = new IntentFilter();
226224
intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
227225
intentFilter.addDataScheme("package");
@@ -242,6 +240,11 @@ public void onReceive(Context context, Intent intent) {
242240
}, userFilter);
243241
}
244242

243+
public void systemReady() {
244+
mAuthenticatorCache.generateServicesMap();
245+
initUser(0);
246+
}
247+
245248
private UserAccounts initUser(int userId) {
246249
synchronized (mUsers) {
247250
UserAccounts accounts = mUsers.get(userId);

core/java/android/accounts/IAccountAuthenticatorCache.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,9 @@ RegisteredServicesCache.ServiceInfo<AuthenticatorDescription> getServiceInfo(
6060
*/
6161
void setListener(RegisteredServicesCacheListener<AuthenticatorDescription> listener,
6262
Handler handler);
63+
64+
/**
65+
* Refreshes the authenticator cache.
66+
*/
67+
void generateServicesMap();
6368
}

core/java/android/content/ContentService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
132132
/*package*/ ContentService(Context context, boolean factoryTest) {
133133
mContext = context;
134134
mFactoryTest = factoryTest;
135+
}
136+
137+
public void systemReady() {
135138
getSyncManager();
136139
}
137140

@@ -524,7 +527,7 @@ public void removeStatusChangeListener(ISyncStatusObserver callback) {
524527
}
525528
}
526529

527-
public static IContentService main(Context context, boolean factoryTest) {
530+
public static ContentService main(Context context, boolean factoryTest) {
528531
ContentService service = new ContentService(context, factoryTest);
529532
ServiceManager.addService(ContentResolver.CONTENT_SERVICE_NAME, service);
530533
return service;

core/java/android/content/pm/RegisteredServicesCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ private boolean inSystemImage(int callerUid) {
251251
return false;
252252
}
253253

254-
void generateServicesMap() {
254+
public void generateServicesMap() {
255255
PackageManager pm = mContext.getPackageManager();
256256
ArrayList<ServiceInfo<V>> serviceInfos = new ArrayList<ServiceInfo<V>>();
257257
List<ResolveInfo> resolveInfos = pm.queryIntentServices(new Intent(mInterfaceName),

services/java/com/android/server/SystemServer.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ public void run() {
114114
: Integer.parseInt(factoryTestStr);
115115
final boolean headless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
116116

117+
AccountManagerService accountManager = null;
118+
ContentService contentService = null;
117119
LightsService lights = null;
118120
PowerManagerService power = null;
119121
BatteryService battery = null;
@@ -190,14 +192,14 @@ public void run() {
190192
// The AccountManager must come before the ContentService
191193
try {
192194
Slog.i(TAG, "Account Manager");
193-
ServiceManager.addService(Context.ACCOUNT_SERVICE,
194-
new AccountManagerService(context));
195+
accountManager = new AccountManagerService(context);
196+
ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager);
195197
} catch (Throwable e) {
196198
Slog.e(TAG, "Failure starting Account Manager", e);
197199
}
198200

199201
Slog.i(TAG, "Content Manager");
200-
ContentService.main(context,
202+
contentService = ContentService.main(context,
201203
factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
202204

203205
Slog.i(TAG, "System Content Providers");
@@ -465,6 +467,20 @@ public void run() {
465467
mountService.waitForAsecScan();
466468
}
467469

470+
try {
471+
if (accountManager != null)
472+
accountManager.systemReady();
473+
} catch (Throwable e) {
474+
reportWtf("making Account Manager Service ready", e);
475+
}
476+
477+
try {
478+
if (contentService != null)
479+
contentService.systemReady();
480+
} catch (Throwable e) {
481+
reportWtf("making Content Service ready", e);
482+
}
483+
468484
try {
469485
Slog.i(TAG, "Notification Manager");
470486
notification = new NotificationManagerService(context, statusBar, lights);

0 commit comments

Comments
 (0)