Merge "Attempt at fixing race condition during boot." into rvc-dev am: e3a6cb22d2 am: 5c25d09202

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11898403

Change-Id: Ib215e27b1a9702f7d2e2b86fca4698c29a93642b
This commit is contained in:
Jeff Sharkey
2020-06-18 14:44:28 +00:00
committed by Automerger Merge Worker

View File

@@ -3535,6 +3535,13 @@ class StorageManagerService extends IStorageManager.Stub
// point // point
final boolean systemUserUnlocked = isSystemUnlocked(UserHandle.USER_SYSTEM); 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 userIsDemo;
final boolean userKeyUnlocked; final boolean userKeyUnlocked;
final boolean storagePermission; final boolean storagePermission;
@@ -3554,6 +3561,7 @@ class StorageManagerService extends IStorageManager.Stub
final ArraySet<String> resUuids = new ArraySet<>(); final ArraySet<String> resUuids = new ArraySet<>();
synchronized (mLock) { synchronized (mLock) {
for (int i = 0; i < mVolumes.size(); i++) { for (int i = 0; i < mVolumes.size(); i++) {
final String volId = mVolumes.keyAt(i);
final VolumeInfo vol = mVolumes.valueAt(i); final VolumeInfo vol = mVolumes.valueAt(i);
switch (vol.getType()) { switch (vol.getType()) {
case VolumeInfo.TYPE_PUBLIC: case VolumeInfo.TYPE_PUBLIC:
@@ -3578,11 +3586,19 @@ class StorageManagerService extends IStorageManager.Stub
if (!match) continue; if (!match) continue;
boolean reportUnmounted = false; 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; reportUnmounted = true;
Slog.w(TAG, "Reporting " + volId + " unmounted due to system locked");
} else if ((vol.getType() == VolumeInfo.TYPE_EMULATED) && !userKeyUnlocked) { } else if ((vol.getType() == VolumeInfo.TYPE_EMULATED) && !userKeyUnlocked) {
reportUnmounted = true; reportUnmounted = true;
Slog.w(TAG, "Reporting " + volId + "unmounted due to " + userId + " locked");
} else if (!storagePermission && !realState) { } else if (!storagePermission && !realState) {
Slog.w(TAG, "Reporting " + volId + "unmounted due to missing permissions");
reportUnmounted = true; reportUnmounted = true;
} }