Add device config to enable PhotoPickerUserSelectActivity

PhotoPickerUserSelectActivity is disabled in mainline development
branch. Add device config flag to support enabling / disabling the
activity.

Enable the flag:
adb shell device_config put storage_native_boot  user_select_for_app
true

Bug: 251783841
Test: Manual.
Change-Id: If8acf263f4492f9631aec7ac59659a70fab4ed98
diff --git a/src/com/android/providers/media/ConfigStore.java b/src/com/android/providers/media/ConfigStore.java
index 5ffacf5..93a1d14 100644
--- a/src/com/android/providers/media/ConfigStore.java
+++ b/src/com/android/providers/media/ConfigStore.java
@@ -41,6 +41,7 @@
  */
 public interface ConfigStore {
     boolean DEFAULT_TAKE_OVER_GET_CONTENT = false;
+    boolean DEFAULT_USER_SELECT_FOR_APP = true;
     boolean DEFAULT_STABILISE_VOLUME_INTERNAL = false;
     boolean DEFAULT_STABILIZE_VOLUME_EXTERNAL = false;
 
@@ -117,6 +118,13 @@
     }
 
     /**
+     * @return if PhotoPickerUserSelectActivity should be enabled
+     */
+    default boolean isUserSelectForAppEnabled() {
+        return DEFAULT_USER_SELECT_FOR_APP;
+    }
+
+    /**
      * @return if stable URI are enabled for the internal volume.
      */
     default boolean isStableUrisForInternalVolumeEnabled() {
@@ -168,6 +176,7 @@
      */
     class ConfigStoreImpl implements ConfigStore {
         private static final String KEY_TAKE_OVER_GET_CONTENT = "take_over_get_content";
+        private static final String KEY_USER_SELECT_FOR_APP = "user_select_for_app";
 
         @VisibleForTesting
         public static final String KEY_STABILISE_VOLUME_INTERNAL = "stablise_volume_internal";
@@ -229,6 +238,11 @@
         }
 
         @Override
+        public boolean isUserSelectForAppEnabled() {
+            return getBooleanDeviceConfig(KEY_USER_SELECT_FOR_APP, DEFAULT_USER_SELECT_FOR_APP);
+        }
+
+        @Override
         public boolean isStableUrisForInternalVolumeEnabled() {
             return getBooleanDeviceConfig(
                     KEY_STABILISE_VOLUME_INTERNAL, DEFAULT_STABILISE_VOLUME_INTERNAL);
diff --git a/src/com/android/providers/media/MediaProvider.java b/src/com/android/providers/media/MediaProvider.java
index 14691bd..8920250 100644
--- a/src/com/android/providers/media/MediaProvider.java
+++ b/src/com/android/providers/media/MediaProvider.java
@@ -1397,20 +1397,11 @@
 
     @VisibleForTesting
     protected void storageNativeBootPropertyChangeListener() {
-        final String photoPickerGetContentActivity =
-                PhotoPickerActivity.class.getPackage().getName() + ".PhotoPickerGetContentActivity";
-        final ComponentName componentName = new ComponentName(getContext().getPackageName(),
-                photoPickerGetContentActivity);
+        setComponentEnabledSetting("PhotoPickerGetContentActivity",
+                mConfigStore.isGetContentTakeOverEnabled());
 
-        final int expectedState = mConfigStore.isGetContentTakeOverEnabled()
-                ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
-                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
-
-        Log.i(TAG, "Changed PhotoPickerGetContentActivity component state to "
-                + componentStateToString(expectedState));
-
-        getContext().getPackageManager().setComponentEnabledSetting(componentName, expectedState,
-                PackageManager.DONT_KILL_APP);
+        setComponentEnabledSetting("PhotoPickerUserSelectActivity",
+                mConfigStore.isUserSelectForAppEnabled());
 
         if (mConfigStore.isStableUrisForInternalVolumeEnabled()
                 && mVolumeCache.getExternalVolumeNames().contains(
@@ -1422,6 +1413,23 @@
         }
     }
 
+    private void setComponentEnabledSetting(@NonNull String activityName, boolean isEnabled) {
+        final String activityFullName =
+                PhotoPickerActivity.class.getPackage().getName() + "." + activityName;
+        final ComponentName componentName = new ComponentName(getContext().getPackageName(),
+                activityFullName);
+
+        final int expectedState = isEnabled
+                ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
+                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
+
+        Log.i(TAG, "Changed " + activityName + " component state to "
+                + componentStateToString(expectedState));
+
+        getContext().getPackageManager().setComponentEnabledSetting(componentName, expectedState,
+                PackageManager.DONT_KILL_APP);
+    }
+
     Optional<DatabaseHelper> getDatabaseHelper(String dbName) {
         if (dbName.equalsIgnoreCase(INTERNAL_DATABASE_NAME)) {
             return Optional.of(mInternalDatabase);