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

Commit ea72b46d authored by Shikha Malhotra's avatar Shikha Malhotra
Browse files

Replace noteOp call to checkOp

Also memoize the legacy storage and no isolated storage app op, to avoid calling AppOpManager multiple number of times.
detail can be found

https://buganizer.corp.google.com/issues/323574186#comment13 and https://buganizer.corp.google.com/issues/323574186#comment16
Bug: b/323574186
Flag: EXEMPT bugfix
Change-Id: I0d98a6c323253a99065f564ad4c8beb94e63e14c
parent b44a5d6c
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -159,6 +159,8 @@ public class Environment {
    @UnsupportedAppUsage
    private static UserEnvironment sCurrentUser;
    private static boolean sUserRequired;
    private static Boolean sLegacyStorageAppOp;
    private static Boolean sNoIsolatedStorageAppOp;

    static {
        initForCurrentUser();
@@ -1459,16 +1461,24 @@ public class Environment {
        final AppOpsManager appOps = context.getSystemService(AppOpsManager.class);
        final String opPackageName = context.getOpPackageName();

        if (appOps.noteOpNoThrow(AppOpsManager.OP_LEGACY_STORAGE, uid,
                opPackageName) == AppOpsManager.MODE_ALLOWED) {
            return true;
        if (sLegacyStorageAppOp == null) {
            sLegacyStorageAppOp =
              appOps.checkOpNoThrow(AppOpsManager.OP_LEGACY_STORAGE, uid, opPackageName) ==
                              AppOpsManager.MODE_ALLOWED;
        }
        if (sLegacyStorageAppOp) {
            return sLegacyStorageAppOp;
        }

        // Legacy external storage access is granted to instrumentations invoked with
        // "--no-isolated-storage" flag.
        return appOps.noteOpNoThrow(AppOpsManager.OP_NO_ISOLATED_STORAGE, uid,
        if (sNoIsolatedStorageAppOp == null) {
            sNoIsolatedStorageAppOp =
              appOps.checkOpNoThrow(AppOpsManager.OP_NO_ISOLATED_STORAGE, uid,
                                    opPackageName) == AppOpsManager.MODE_ALLOWED;
        }
        return sNoIsolatedStorageAppOp;
    }

    private static boolean isScopedStorageEnforced(boolean defaultScopedStorage,
            boolean forceEnableScopedStorage) {