Keep lock while binding the storage service

Test: atest ManagedProfileLifecycleStressTest; atest --iterations 100 AdoptableHostTest
BUG: 156533724
Change-Id: I007a406daaeaf2637ce472ee3d7e97ebeebed35f

Change-Id: Ie8c15c7e1c4bc6065e1ccdfad3d56e1a6d631360
This commit is contained in:
Corina
2020-06-03 11:47:09 +01:00
parent df98b27008
commit 63f037cd2f

View File

@@ -413,20 +413,18 @@ public final class StorageUserConnection {
resetUserSessions();
}
};
}
Slog.i(TAG, "Binding to the ExternalStorageService for user " + mUserId);
if (mContext.bindServiceAsUser(new Intent().setComponent(name), mServiceConnection,
Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT,
UserHandle.of(mUserId))) {
Slog.i(TAG, "Bound to the ExternalStorageService for user " + mUserId);
return mLatch;
} else {
synchronized (mLock) {
Slog.i(TAG, "Binding to the ExternalStorageService for user " + mUserId);
if (mContext.bindServiceAsUser(new Intent().setComponent(name), mServiceConnection,
Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT,
UserHandle.of(mUserId))) {
Slog.i(TAG, "Bound to the ExternalStorageService for user " + mUserId);
return mLatch;
} else {
mIsConnecting = false;
throw new ExternalStorageServiceException(
"Failed to bind to the ExternalStorageService for user " + mUserId);
}
throw new ExternalStorageServiceException(
"Failed to bind to the ExternalStorageService for user " + mUserId);
}
}
}