From 1c0cf347f19ac48ff28c19ce9f9821ef9a3efd93 Mon Sep 17 00:00:00 2001 From: Dipankar Bhardwaj Date: Fri, 7 Feb 2025 16:58:52 +0000 Subject: Fix for legacy storage app op There is a bug in AppOpsManager that keeps legacy storage granted even when an app updates its targetSdkVersion from value <30 to >=30. If an app upgrades from targetSdk 29 to targetSdk 33, legacy storage remains granted and in targetSdk 33, app are required to replace R_E_S with R_M_*. If an app updates its manifest with R_M_*, permission check in MediaProvider will look for R_E_S and will not grant read access as the app would be still treated as legacy. Test: atest PermissionUtilsTest Bug: 315914683 Flag: EXEMPT bug fix Change-Id: I22d0a329fbea5afe9dea2bc5179596db7a2ef402 --- tests/Android.bp | 20 +++++++++ tests/AndroidManifest.xml | 1 + tests/AndroidTest.xml | 1 + .../providers/media/util/PermissionUtilsTest.java | 49 ++++++++++++++++++++++ tests/test_app/LegacyTestAppWithTargetSdk33.xml | 40 ++++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 tests/test_app/LegacyTestAppWithTargetSdk33.xml (limited to 'tests') diff --git a/tests/Android.bp b/tests/Android.bp index cdb44b814..3de35a077 100644 --- a/tests/Android.bp +++ b/tests/Android.bp @@ -155,6 +155,25 @@ android_test_helper_app { ], } +android_test_helper_app { + name: "LegacyMediaProviderTestAppFor33", + manifest: "test_app/LegacyTestAppWithTargetSdk33.xml", + srcs: [ + "test_app/src/**/*.java", + "src/com/android/providers/media/util/TestUtils.java", + ], + static_libs: [ + "cts-install-lib", + ], + sdk_version: "test_current", + target_sdk_version: "33", + min_sdk_version: "30", + test_suites: [ + "general-tests", + "mts-mediaprovider", + ], +} + // This looks a bit awkward, but we need our tests to run against either // MediaProvider or MediaProviderGoogle, and we don't know which one is // on the device being tested, so we can't sign our tests with a key that @@ -250,6 +269,7 @@ android_test { data: [ ":LegacyMediaProviderTestApp", + ":LegacyMediaProviderTestAppFor33", ":LegacyMediaProviderTestAppFor35", ":MediaProviderTestAppForPermissionActivity", ":MediaProviderTestAppForPermissionActivity33", diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml index acd1a21af..e3902d6eb 100644 --- a/tests/AndroidManifest.xml +++ b/tests/AndroidManifest.xml @@ -13,6 +13,7 @@ + diff --git a/tests/AndroidTest.xml b/tests/AndroidTest.xml index 31d9e1535..44fb27930 100644 --- a/tests/AndroidTest.xml +++ b/tests/AndroidTest.xml @@ -30,6 +30,7 @@