From 3630083720d9a1fa852fb32c3e61b119a13d0c6b Mon Sep 17 00:00:00 2001 From: Theresa Sullivan Date: Tue, 19 Apr 2022 19:46:46 +0000 Subject: [PATCH] Temporarily disable opening file:// on Android TM In Android TM for apps targeting API 33, READ_EXTERNAL_STORAGE is split into specific permissions for READ_MEDIA_*. For now, skip requesting READ_EXTERNAL_STORAGE when the user navigates to file:// URLs. Opening the file:// will still fail, but the user won't first be prompted to accept a permission that has no effect. (cherry picked from commit 9501a425bd47b74df5006d2ac18e4c6bf3a1440d) Bug: 1316672 Change-Id: I6fbcd6466f9ecda544712151bb3cdc2e04496897 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3587279 Reviewed-by: Ted Choc Commit-Queue: Theresa Sullivan Cr-Original-Commit-Position: refs/heads/main@{#993351} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3594606 Bot-Commit: Rubber Stamper Cr-Commit-Position: refs/branch-heads/5005@{#35} Cr-Branched-From: 5b4d9450fee01f821b6400e947b3839727643a71-refs/heads/main@{#992738} --- .../external_intents/ExternalNavigationHandler.java | 5 +++++ .../external_intents/ExternalNavigationHandlerTest.java | 2 ++ 2 files changed, 7 insertions(+) diff --git a/components/external_intents/android/java/src/org/chromium/components/external_intents/ExternalNavigationHandler.java b/components/external_intents/android/java/src/org/chromium/components/external_intents/ExternalNavigationHandler.java index 6e998c8979f3e8..7c354a6efbca44 100644 --- a/components/external_intents/android/java/src/org/chromium/components/external_intents/ExternalNavigationHandler.java +++ b/components/external_intents/android/java/src/org/chromium/components/external_intents/ExternalNavigationHandler.java @@ -38,6 +38,7 @@ import androidx.annotation.VisibleForTesting; import androidx.appcompat.app.AlertDialog; +import org.chromium.base.BuildInfo; import org.chromium.base.CommandLine; import org.chromium.base.ContextUtils; import org.chromium.base.IntentUtils; @@ -2064,6 +2065,10 @@ protected GURL getLastCommittedUrl() { */ @VisibleForTesting protected boolean shouldRequestFileAccess(GURL url) { + // TODO(https://crbug.com/1316672): Replace READ_EXTERNAL_STORAGE with READ_MEDIA_* + // permissions to restore capability to open file:// on Android T. + if (BuildInfo.isAtLeastT()) return false; + // If the tab is null, then do not attempt to prompt for access. if (!mDelegate.hasValidTab()) return false; assert url.getScheme().equals(UrlConstants.FILE_SCHEME); diff --git a/components/external_intents/android/javatests/src/org/chromium/components/external_intents/ExternalNavigationHandlerTest.java b/components/external_intents/android/javatests/src/org/chromium/components/external_intents/ExternalNavigationHandlerTest.java index 5730aa7f01f776..394c48c8c241e6 100644 --- a/components/external_intents/android/javatests/src/org/chromium/components/external_intents/ExternalNavigationHandlerTest.java +++ b/components/external_intents/android/javatests/src/org/chromium/components/external_intents/ExternalNavigationHandlerTest.java @@ -47,6 +47,7 @@ import org.chromium.base.ThreadUtils; import org.chromium.base.test.BaseJUnit4ClassRunner; import org.chromium.base.test.util.Batch; +import org.chromium.base.test.util.MaxAndroidSdkLevel; import org.chromium.components.external_intents.ExternalNavigationDelegate.IntentToAutofillAllowingAppResult; import org.chromium.components.external_intents.ExternalNavigationHandler.OverrideUrlLoadingAsyncActionType; import org.chromium.components.external_intents.ExternalNavigationHandler.OverrideUrlLoadingResult; @@ -1835,6 +1836,7 @@ public void testNavigationWithForwardBack() { @Test @SuppressLint("SdCardPath") @SmallTest + @MaxAndroidSdkLevel(Build.VERSION_CODES.S) public void testFileAccess() { String fileUrl = "file:///sdcard/Downloads/test.html";