From e9fcabcaa188dc00e3d8dda0165f04f9c29d1831 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Thu, 4 Apr 2019 11:19:22 -0600 Subject: [PATCH] Fix isExternalStorageSandboxed() bug. It needs to use the same STOPSHIP logic for consistency with the two other enforcement sites across the OS. Bug: 129487770 Test: atest android.appsecurity.cts.ExternalStorageHostTest Change-Id: I7a3fa836e0795912c264aae58a55472ffae3d8c3 --- core/java/android/os/Environment.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/java/android/os/Environment.java b/core/java/android/os/Environment.java index f7e927e488634..9e9e68dbf3fe4 100644 --- a/core/java/android/os/Environment.java +++ b/core/java/android/os/Environment.java @@ -1147,9 +1147,16 @@ public class Environment { public static boolean isExternalStorageSandboxed(@NonNull File path) { final Context context = AppGlobals.getInitialApplication(); final AppOpsManager appOps = context.getSystemService(AppOpsManager.class); - return appOps.noteOpNoThrow(AppOpsManager.OP_LEGACY_STORAGE, + + final boolean hasLegacy = appOps.noteOpNoThrow(AppOpsManager.OP_LEGACY_STORAGE, context.getApplicationInfo().uid, - context.getPackageName()) != AppOpsManager.MODE_ALLOWED; + context.getPackageName()) == AppOpsManager.MODE_ALLOWED; + + // STOPSHIP: only use app-op once permission model has fully landed + final boolean requestedLegacy = !AppGlobals.getInitialApplication().getApplicationInfo() + .isExternalStorageSandboxAllowed(); + + return !(hasLegacy || requestedLegacy); } static File getDirectory(String variableName, String defaultPath) {