Merge "Add isAppIoBlocked TestApi"

This commit is contained in:
TreeHugger Robot
2021-03-23 18:12:43 +00:00
committed by Android (Google) Code Review
5 changed files with 39 additions and 2 deletions

View File

@@ -1843,6 +1843,7 @@ package android.os.storage {
public class StorageManager {
method @NonNull public static java.util.UUID convert(@NonNull String);
method @NonNull public static String convert(@NonNull java.util.UUID);
method public boolean isAppIoBlocked(@NonNull java.util.UUID, int, int, int);
method public static boolean isUserKeyUnlocked(int);
}

View File

@@ -202,4 +202,5 @@ interface IStorageManager {
void notifyAppIoBlocked(in String volumeUuid, int uid, int tid, int reason) = 92;
void notifyAppIoResumed(in String volumeUuid, int uid, int tid, int reason) = 93;
int getExternalStorageMountMode(int uid, in String packageName) = 94;
}
boolean isAppIoBlocked(in String volumeUuid, int uid, int tid, int reason) = 95;
}

View File

@@ -2871,6 +2871,30 @@ public class StorageManager {
}
}
/**
* Check if {@code uid} with {@code tid} is blocked on IO for {@code reason}.
*
* This requires {@link ExternalStorageService} the
* {@link android.Manifest.permission#WRITE_MEDIA_STORAGE} permission.
*
* @param volumeUuid the UUID of the storage volume to check IO blocked status
* @param uid the UID of the app to check IO blocked status
* @param tid the tid of the app to check IO blocked status
* @param reason the reason to check IO blocked status for
*
* @hide
*/
@TestApi
public boolean isAppIoBlocked(@NonNull UUID volumeUuid, int uid, int tid,
@AppIoBlockedReason int reason) {
Objects.requireNonNull(volumeUuid);
try {
return mStorageManager.isAppIoBlocked(convert(volumeUuid), uid, tid, reason);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
private final Object mFuseAppLoopLock = new Object();
@GuardedBy("mFuseAppLoopLock")

View File

@@ -3375,7 +3375,7 @@ class StorageManagerService extends IStorageManager.Stub
}
}
/*
/**
* Returns PendingIntent which can be used by Apps with MANAGE_EXTERNAL_STORAGE permission
* to launch the manageSpaceActivity of the App specified by packageName.
*/
@@ -3437,6 +3437,13 @@ class StorageManagerService extends IStorageManager.Stub
mStorageSessionController.notifyAppIoResumed(volumeUuid, uid, tid, reason);
}
@Override
public boolean isAppIoBlocked(String volumeUuid, int uid, int tid,
@StorageManager.AppIoBlockedReason int reason) {
return isAppIoBlocked(uid);
}
private boolean isAppIoBlocked(int uid) {
return mStorageSessionController.isAppIoBlocked(uid);
}

View File

@@ -265,6 +265,10 @@ public final class StorageUserConnection {
synchronized (mSessionsLock) {
int ioBlockedCounter = mUidsBlockedOnIo.get(uid, 0);
if (ioBlockedCounter == 0) {
Slog.w(TAG, "Unexpected app IO resumption for uid: " + uid);
}
if (ioBlockedCounter <= 1) {
mUidsBlockedOnIo.remove(uid);
} else {
mUidsBlockedOnIo.put(uid, --ioBlockedCounter);