From 63f037cd2f35cddf76714fa2140f4233d371f3a4 Mon Sep 17 00:00:00 2001 From: Corina Date: Wed, 3 Jun 2020 11:47:09 +0100 Subject: [PATCH] Keep lock while binding the storage service Test: atest ManagedProfileLifecycleStressTest; atest --iterations 100 AdoptableHostTest BUG: 156533724 Change-Id: I007a406daaeaf2637ce472ee3d7e97ebeebed35f Change-Id: Ie8c15c7e1c4bc6065e1ccdfad3d56e1a6d631360 --- .../server/storage/StorageUserConnection.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/services/core/java/com/android/server/storage/StorageUserConnection.java b/services/core/java/com/android/server/storage/StorageUserConnection.java index c18a6ebc32ef4..94a250236200c 100644 --- a/services/core/java/com/android/server/storage/StorageUserConnection.java +++ b/services/core/java/com/android/server/storage/StorageUserConnection.java @@ -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); } } }