Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f094406d authored by Zim's avatar Zim Committed by Zimuzo Ezeozue
Browse files

Add isAppIoBlocked TestApi

This allows us test the notifyAppIoBlocked and notifyAppIoResumed APIs

Also fixed isAppIoBlocked bug where a uid with a blocked counter of
'0' would incorrectly result in returning true.

Test: m
Bug: 181222557
Change-Id: I3e8f040cd0e08cb0765fec0cfafab6428d6a3a00
parent c2f195bb
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -1827,6 +1827,7 @@ package android.os.storage {
  public class StorageManager {
  public class StorageManager {
    method @NonNull public static java.util.UUID convert(@NonNull String);
    method @NonNull public static java.util.UUID convert(@NonNull String);
    method @NonNull public static String convert(@NonNull java.util.UUID);
    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);
    method public static boolean isUserKeyUnlocked(int);
  }
  }


+2 −1
Original line number Original line Diff line number Diff line
@@ -202,4 +202,5 @@ interface IStorageManager {
    void notifyAppIoBlocked(in String volumeUuid, int uid, int tid, int reason) = 92;
    void notifyAppIoBlocked(in String volumeUuid, int uid, int tid, int reason) = 92;
    void notifyAppIoResumed(in String volumeUuid, int uid, int tid, int reason) = 93;
    void notifyAppIoResumed(in String volumeUuid, int uid, int tid, int reason) = 93;
    int getExternalStorageMountMode(int uid, in String packageName) = 94;
    int getExternalStorageMountMode(int uid, in String packageName) = 94;
    boolean isAppIoBlocked(in String volumeUuid, int uid, int tid, int reason) = 95;
}
}
 No newline at end of file
+24 −0
Original line number Original line Diff line number Diff line
@@ -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();
    private final Object mFuseAppLoopLock = new Object();


    @GuardedBy("mFuseAppLoopLock")
    @GuardedBy("mFuseAppLoopLock")
+8 −1
Original line number Original line Diff line number Diff line
@@ -3375,7 +3375,7 @@ class StorageManagerService extends IStorageManager.Stub
        }
        }
    }
    }


    /*
    /**
     * Returns PendingIntent which can be used by Apps with MANAGE_EXTERNAL_STORAGE permission
     * Returns PendingIntent which can be used by Apps with MANAGE_EXTERNAL_STORAGE permission
     * to launch the manageSpaceActivity of the App specified by packageName.
     * 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);
        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) {
    private boolean isAppIoBlocked(int uid) {
        return mStorageSessionController.isAppIoBlocked(uid);
        return mStorageSessionController.isAppIoBlocked(uid);
    }
    }
+4 −0
Original line number Original line Diff line number Diff line
@@ -265,6 +265,10 @@ public final class StorageUserConnection {
        synchronized (mSessionsLock) {
        synchronized (mSessionsLock) {
            int ioBlockedCounter = mUidsBlockedOnIo.get(uid, 0);
            int ioBlockedCounter = mUidsBlockedOnIo.get(uid, 0);
            if (ioBlockedCounter == 0) {
            if (ioBlockedCounter == 0) {
                Slog.w(TAG, "Unexpected app IO resumption for uid: " + uid);
            }

            if (ioBlockedCounter <= 1) {
                mUidsBlockedOnIo.remove(uid);
                mUidsBlockedOnIo.remove(uid);
            } else {
            } else {
                mUidsBlockedOnIo.put(uid, --ioBlockedCounter);
                mUidsBlockedOnIo.put(uid, --ioBlockedCounter);