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

Commit bf99a790 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Replace noteOp call to checkOp" into main

parents 720223e2 ea72b46d
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) {