summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeff Sharkey <jsharkey@google.com> 2020-06-17 22:22:49 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2020-06-17 22:22:49 +0000
commite06c89fa2cddd81e0ef3dd9f070cc71cb5d923be (patch)
tree9a01e24745cbed6d74d66a73e07a7ee20de47e08
parent091f82245cc32616375c4419f85096f193c2b31a (diff)
parentfa9209fe72205c6b1d47f0eae2738c5866f60ed8 (diff)
Merge "Attempt at fixing race condition during boot." into rvc-dev am: e3a6cb22d2 am: 52a5225de6 am: fa9209fe72
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11898403 Change-Id: If678985838cef669eddfe9872d50749248c24bea
-rw-r--r--services/core/java/com/android/server/StorageManagerService.java18
1 files changed, 17 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java
index 1ce3dfe9f3a0..63a984ccdc6f 100644
--- a/services/core/java/com/android/server/StorageManagerService.java
+++ b/services/core/java/com/android/server/StorageManagerService.java
@@ -3535,6 +3535,13 @@ class StorageManagerService extends IStorageManager.Stub
// point
final boolean systemUserUnlocked = isSystemUnlocked(UserHandle.USER_SYSTEM);
+ // When the caller is the app actually hosting external storage, we
+ // should never attempt to augment the actual storage volume state,
+ // otherwise we risk confusing it with race conditions as users go
+ // through various unlocked states
+ final boolean callerIsMediaStore = UserHandle.isSameApp(Binder.getCallingUid(),
+ mMediaStoreAuthorityAppId);
+
final boolean userIsDemo;
final boolean userKeyUnlocked;
final boolean storagePermission;
@@ -3554,6 +3561,7 @@ class StorageManagerService extends IStorageManager.Stub
final ArraySet<String> resUuids = new ArraySet<>();
synchronized (mLock) {
for (int i = 0; i < mVolumes.size(); i++) {
+ final String volId = mVolumes.keyAt(i);
final VolumeInfo vol = mVolumes.valueAt(i);
switch (vol.getType()) {
case VolumeInfo.TYPE_PUBLIC:
@@ -3578,11 +3586,19 @@ class StorageManagerService extends IStorageManager.Stub
if (!match) continue;
boolean reportUnmounted = false;
- if (!systemUserUnlocked) {
+ if (callerIsMediaStore) {
+ // When the caller is the app actually hosting external storage, we
+ // should never attempt to augment the actual storage volume state,
+ // otherwise we risk confusing it with race conditions as users go
+ // through various unlocked states
+ } else if (!systemUserUnlocked) {
reportUnmounted = true;
+ Slog.w(TAG, "Reporting " + volId + " unmounted due to system locked");
} else if ((vol.getType() == VolumeInfo.TYPE_EMULATED) && !userKeyUnlocked) {
reportUnmounted = true;
+ Slog.w(TAG, "Reporting " + volId + "unmounted due to " + userId + " locked");
} else if (!storagePermission && !realState) {
+ Slog.w(TAG, "Reporting " + volId + "unmounted due to missing permissions");
reportUnmounted = true;
}