diff options
author | 2024-05-17 08:54:35 +0100 | |
---|---|---|
committer | 2024-05-22 17:54:51 +0100 | |
commit | 2cf9576f19b8d88c3eb2f33bde96b6324ddb2c75 (patch) | |
tree | a0d9153659c4e7307956a8f05de474c3257b8c7d | |
parent | cd5f2fafa29c88f9231c48367542710a1433bbc5 (diff) |
Add ConfigStore flag for MODERN_PICKER_ENABLED
This flag will switch on the modern photopicker when enabled.
Bug: b/303779617
Test: atest MediaProviderTests:ConfigStoreTest
Change-Id: I71aac9b196a385b8010ed2a34fa4b8771d695499
-rw-r--r-- | AndroidManifest.xml | 2 | ||||
-rw-r--r-- | photopicker/AndroidManifest.xml | 6 | ||||
-rw-r--r-- | src/com/android/providers/media/ConfigStore.java | 28 | ||||
-rw-r--r-- | src/com/android/providers/media/MediaProvider.java | 34 | ||||
-rw-r--r-- | tests/src/com/android/providers/media/ConfigStoreTest.java | 30 |
5 files changed, 87 insertions, 13 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 5206504a8..67bc84865 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -274,7 +274,7 @@ android:exported="true" android:excludeFromRecents="true" android:enabled="true"> - <intent-filter android:priority="101" > + <intent-filter android:priority="105" > <action android:name="android.intent.action.GET_CONTENT" /> <category android:name="android.intent.category.OPENABLE" /> <category android:name="android.intent.category.DEFAULT" /> diff --git a/photopicker/AndroidManifest.xml b/photopicker/AndroidManifest.xml index a653b2f5f..900f53380 100644 --- a/photopicker/AndroidManifest.xml +++ b/photopicker/AndroidManifest.xml @@ -50,13 +50,13 @@ android:windowSoftInputMode="adjustResize" android:excludeFromRecents="true"> - <intent-filter android:priority="105" > + <intent-filter android:priority="95" > <action android:name="android.provider.action.PICK_IMAGES"/> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /> <data android:mimeType="video/*" /> </intent-filter> - <intent-filter android:priority="105" > + <intent-filter android:priority="95" > <action android:name="android.provider.action.PICK_IMAGES"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> @@ -68,7 +68,7 @@ android:exported="true" android:excludeFromRecents="true" android:enabled="true"> - <intent-filter android:priority="105" > + <intent-filter android:priority="101" > <action android:name="android.intent.action.GET_CONTENT"/> <category android:name="android.intent.category.OPENABLE"/> <category android:name="android.intent.category.DEFAULT"/> diff --git a/src/com/android/providers/media/ConfigStore.java b/src/com/android/providers/media/ConfigStore.java index 2082f20ec..3e28054ff 100644 --- a/src/com/android/providers/media/ConfigStore.java +++ b/src/com/android/providers/media/ConfigStore.java @@ -62,6 +62,8 @@ public interface ConfigStore { boolean DEFAULT_TRANSCODE_OPT_OUT_STRATEGY_ENABLED = false; int DEFAULT_TRANSCODE_MAX_DURATION = 60 * 1000; // 1 minute + boolean DEFAULT_MODERN_PICKER_ENABLED = false; + boolean DEFAULT_PICKER_GET_CONTENT_PRELOAD = true; boolean DEFAULT_PICKER_PICK_IMAGES_PRELOAD = true; boolean DEFAULT_PICKER_PICK_IMAGES_RESPECT_PRELOAD_ARG = false; @@ -71,6 +73,14 @@ public interface ConfigStore { boolean DEFAULT_PICKER_CHOICE_MANAGED_SELECTION_ENABLED = true; boolean DEFAULT_PICKER_PRIVATE_SPACE_ENABLED = true; + + /** + * @return if the modern photopicker experience is enabled. + */ + default boolean isModernPickerEnabled() { + return DEFAULT_MODERN_PICKER_ENABLED; + } + /** * @return if the Cloud-Media-in-Photo-Picker enabled (e.g. platform will recognize and * "plug-in" {@link android.provider.CloudMediaProvider}s. @@ -305,6 +315,8 @@ public interface ConfigStore { "persist.sys.fuse.transcode_max_file_duration_ms"; private static final int TRANSCODE_MAX_DURATION_INVALID = 0; + private static final String KEY_MODERN_PICKER_ENABLED = "enable_modern_picker"; + private static final String KEY_PICKER_GET_CONTENT_PRELOAD = "picker_get_content_preload_selected"; private static final String KEY_PICKER_PICK_IMAGES_PRELOAD = @@ -335,6 +347,22 @@ public interface ConfigStore { } @Override + public boolean isModernPickerEnabled() { + + // The modern photopicker can only be enabled on T+ such that it can acquire all + // of the necessary runtime permissions it needs. For devices running a platform + // prior to T, the modern picker is always disabled. + if (SdkLevel.isAtLeastT()) { + return getBooleanDeviceConfig( + NAMESPACE_MEDIAPROVIDER, + KEY_MODERN_PICKER_ENABLED, + DEFAULT_MODERN_PICKER_ENABLED); + } else { + return false; + } + } + + @Override public boolean isCloudMediaInPhotoPickerEnabled() { Boolean isEnabled = getBooleanDeviceConfig( diff --git a/src/com/android/providers/media/MediaProvider.java b/src/com/android/providers/media/MediaProvider.java index 095afe8a7..9ef92d950 100644 --- a/src/com/android/providers/media/MediaProvider.java +++ b/src/com/android/providers/media/MediaProvider.java @@ -1469,16 +1469,34 @@ public class MediaProvider extends ContentProvider { @VisibleForTesting protected void storageNativeBootPropertyChangeListener() { - boolean isGetContentTakeoverEnabled; - if (SdkLevel.isAtLeastT()) { - isGetContentTakeoverEnabled = true; - } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) { - isGetContentTakeoverEnabled = true; - } else { - isGetContentTakeoverEnabled = mConfigStore.isGetContentTakeOverEnabled(); + + // Enable various Photopicker activities based on ConfigStore state. + boolean isModernPickerEnabled = mConfigStore.isModernPickerEnabled(); + + // ACTION_PICK_IMAGES + setComponentEnabledSetting( + "PhotoPickerActivity", /* isEnabled= */ !isModernPickerEnabled); + + // ACTION_GET_CONTENT + boolean isGetContentTakeoverEnabled = false; + + // If the modern picker is enabled, allow it to handle GET_CONTENT. + // This logic only exists to check for specific S device settings + // and the modern picker is T+ only. + if (!isModernPickerEnabled) { + if (SdkLevel.isAtLeastT()) { + isGetContentTakeoverEnabled = true; + } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) { + isGetContentTakeoverEnabled = true; + } else { + isGetContentTakeoverEnabled = mConfigStore.isGetContentTakeOverEnabled(); + } } - setComponentEnabledSetting("PhotoPickerGetContentActivity", isGetContentTakeoverEnabled); + setComponentEnabledSetting( + "PhotoPickerGetContentActivity", isGetContentTakeoverEnabled); + // ACTION_USER_SELECT_FOR_APP + // The modern picker does not yet handle USER_SELECT_FOR_APP. setComponentEnabledSetting("PhotoPickerUserSelectActivity", mConfigStore.isUserSelectForAppEnabled()); } diff --git a/tests/src/com/android/providers/media/ConfigStoreTest.java b/tests/src/com/android/providers/media/ConfigStoreTest.java index de0baef3e..8ed38c4e7 100644 --- a/tests/src/com/android/providers/media/ConfigStoreTest.java +++ b/tests/src/com/android/providers/media/ConfigStoreTest.java @@ -20,10 +20,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeFalse; +import static org.junit.Assume.assumeTrue; import androidx.annotation.NonNull; import androidx.test.ext.junit.runners.AndroidJUnit4; +import com.android.modules.utils.build.SdkLevel; + import org.junit.Test; import org.junit.runner.RunWith; @@ -55,7 +59,30 @@ public class ConfigStoreTest { }; @Test - public void test_defaultValueConfigStore_allCorrect() { + public void test_defaultValueConfigStore_allCorrect_TPlus() { + assumeTrue(SdkLevel.isAtLeastT()); + assertTrue(mConfigStore.getAllowedCloudProviderPackages().isEmpty()); + assertNull(mConfigStore.getDefaultCloudProviderPackage()); + assertEquals(60000, mConfigStore.getTranscodeMaxDurationMs()); + assertTrue(mConfigStore.isCloudMediaInPhotoPickerEnabled()); + assertFalse(mConfigStore.isGetContentTakeOverEnabled()); + assertTrue(mConfigStore.isPickerChoiceManagedSelectionEnabled()); + assertFalse(mConfigStore.isStableUrisForExternalVolumeEnabled()); + assertFalse(mConfigStore.isStableUrisForInternalVolumeEnabled()); + assertTrue(mConfigStore.isTranscodeEnabled()); + assertTrue(mConfigStore.isUserSelectForAppEnabled()); + assertTrue(mConfigStore.shouldEnforceCloudProviderAllowlist()); + assertTrue(mConfigStore.shouldPickerPreloadForGetContent()); + assertTrue(mConfigStore.shouldPickerPreloadForPickImages()); + assertFalse(mConfigStore.shouldPickerRespectPreloadArgumentForPickImages()); + assertFalse(mConfigStore.shouldTranscodeDefault()); + assertTrue(mConfigStore.isPrivateSpaceInPhotoPickerEnabled()); + assertFalse(mConfigStore.isModernPickerEnabled()); + } + + @Test + public void test_defaultValueConfigStore_allCorrect_SMinus() { + assumeFalse(SdkLevel.isAtLeastT()); assertTrue(mConfigStore.getAllowedCloudProviderPackages().isEmpty()); assertNull(mConfigStore.getDefaultCloudProviderPackage()); assertEquals(60000, mConfigStore.getTranscodeMaxDurationMs()); @@ -72,5 +99,6 @@ public class ConfigStoreTest { assertFalse(mConfigStore.shouldPickerRespectPreloadArgumentForPickImages()); assertFalse(mConfigStore.shouldTranscodeDefault()); assertTrue(mConfigStore.isPrivateSpaceInPhotoPickerEnabled()); + assertFalse(mConfigStore.isModernPickerEnabled()); } } |