Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1d9b83ed authored by Hassan Ali's avatar Hassan Ali
Browse files

Expose Setting.Config APIs

As part of moving DeviceConfig.java to packages/modules/ConfigInfrastructure.
Need to expose setting.config hidden apis to be able to access it
ConfigInfrastructure module.

Test: atest CtsProviderTestCases:android.provider.cts.settings.Settings_ConfigTest
Bug: 258220607
Change-Id: Ia9935e6b4a9b42841f1ece69c0f4ec230e56bd99
parent d063f916
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -425,6 +425,26 @@ package android.provider {
    field public static final String NAMESPACE_DEVICE_IDLE = "device_idle";
  }

  public final class Settings {
    field public static final int RESET_MODE_PACKAGE_DEFAULTS = 1; // 0x1
    field public static final int RESET_MODE_TRUSTED_DEFAULTS = 4; // 0x4
    field public static final int RESET_MODE_UNTRUSTED_CHANGES = 3; // 0x3
    field public static final int RESET_MODE_UNTRUSTED_DEFAULTS = 2; // 0x2
  }

  public static final class Settings.Config extends android.provider.Settings.NameValueTable {
    method @RequiresPermission(android.Manifest.permission.WRITE_DEVICE_CONFIG) public static boolean deleteString(@NonNull String, @NonNull String);
    method @Nullable @RequiresPermission(android.Manifest.permission.READ_DEVICE_CONFIG) public static String getString(@NonNull String);
    method @NonNull @RequiresPermission(android.Manifest.permission.READ_DEVICE_CONFIG) public static java.util.Map<java.lang.String,java.lang.String> getStrings(@NonNull String, @NonNull java.util.List<java.lang.String>);
    method @RequiresPermission(android.Manifest.permission.WRITE_DEVICE_CONFIG) public static int getSyncDisabledMode();
    method @RequiresPermission(android.Manifest.permission.WRITE_DEVICE_CONFIG) public static boolean putString(@NonNull String, @NonNull String, @Nullable String, boolean);
    method public static void registerContentObserver(@Nullable String, boolean, @NonNull android.database.ContentObserver);
    method @RequiresPermission(android.Manifest.permission.WRITE_DEVICE_CONFIG) public static void resetToDefaults(int, @Nullable String);
    method @RequiresPermission(android.Manifest.permission.WRITE_DEVICE_CONFIG) public static boolean setStrings(@NonNull String, @NonNull java.util.Map<java.lang.String,java.lang.String>) throws android.provider.DeviceConfig.BadConfigException;
    method @RequiresPermission(android.Manifest.permission.WRITE_DEVICE_CONFIG) public static void setSyncDisabledMode(int);
    method public static void unregisterContentObserver(@NonNull android.database.ContentObserver);
  }

  public static final class Settings.Global extends android.provider.Settings.NameValueTable {
    field public static final String BLE_SCAN_ALWAYS_AVAILABLE = "ble_scan_always_enabled";
    field public static final String BLE_SCAN_BACKGROUND_MODE = "ble_scan_background_mode";
+1 −13
Original line number Diff line number Diff line
@@ -54,13 +54,6 @@ import java.util.concurrent.Executor;
 */
@SystemApi
public final class DeviceConfig {
    /**
     * The content:// style URL for the config table.
     *
     * @hide
     */
    public static final Uri CONTENT_URI = Uri.parse("content://" + Settings.AUTHORITY + "/config");

    /**
     * Namespace for activity manager related features. These features will be applied
     * immediately upon change.
@@ -1194,11 +1187,6 @@ public final class DeviceConfig {
        }
    }

    private static Uri createNamespaceUri(@NonNull String namespace) {
        Preconditions.checkNotNull(namespace);
        return CONTENT_URI.buildUpon().appendPath(namespace).build();
    }

    /**
     * Increment the count used to represent the number of listeners subscribed to the given
     * namespace. If this is the first (i.e. incrementing from 0 to 1) for the given namespace, a
@@ -1223,7 +1211,7 @@ public final class DeviceConfig {
                }
            };
            Settings.Config
                    .registerContentObserver(createNamespaceUri(namespace), true, contentObserver);
                    .registerContentObserver(namespace, true, contentObserver);
            sNamespaces.put(namespace, new Pair<>(contentObserver, 1));
        }
    }
+51 −15
Original line number Diff line number Diff line
@@ -2819,6 +2819,7 @@ public final class Settings {
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    @TestApi
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    public static final int RESET_MODE_PACKAGE_DEFAULTS = 1;
    /**
@@ -2828,6 +2829,7 @@ public final class Settings {
     * the setting will be deleted. This mode is only available to the system.
     * @hide
     */
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    public static final int RESET_MODE_UNTRUSTED_DEFAULTS = 2;
    /**
@@ -2838,6 +2840,7 @@ public final class Settings {
     * This mode is only available to the system.
     * @hide
     */
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    public static final int RESET_MODE_UNTRUSTED_CHANGES = 3;
    /**
@@ -2849,6 +2852,7 @@ public final class Settings {
     * to the system.
     * @hide
     */
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    public static final int RESET_MODE_TRUSTED_DEFAULTS = 4;
    /** @hide */
@@ -17986,6 +17990,7 @@ public final class Settings {
     *
     * @hide
     */
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    public static final class Config extends NameValueTable {
        /**
@@ -18020,12 +18025,19 @@ public final class Settings {
         */
        public static final int SYNC_DISABLED_MODE_UNTIL_REBOOT = 2;
        /**
         * The content:// style URL for the config table.
         *
         * @hide
         */
        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/config");
        private static final ContentProviderHolder sProviderHolder =
                new ContentProviderHolder(DeviceConfig.CONTENT_URI);
                new ContentProviderHolder(CONTENT_URI);
        // Populated lazily, guarded by class object:
        private static final NameValueCache sNameValueCache = new NameValueCache(
                DeviceConfig.CONTENT_URI,
                CONTENT_URI,
                CALL_METHOD_GET_CONFIG,
                CALL_METHOD_PUT_CONFIG,
                CALL_METHOD_DELETE_CONFIG,
@@ -18034,6 +18046,10 @@ public final class Settings {
                sProviderHolder,
                Config.class);
        // Should never be invoked
        private Config() {
        }
        /**
         * Look up a name in the database.
         * @param name to look up in the table
@@ -18041,8 +18057,10 @@ public final class Settings {
         *
         * @hide
         */
        @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
        @Nullable
        @RequiresPermission(Manifest.permission.READ_DEVICE_CONFIG)
        static String getString(String name) {
        public static String getString(@NonNull String name) {
            ContentResolver resolver = getContentResolver();
            return sNameValueCache.getStringForUser(resolver, name, resolver.getUserId());
        }
@@ -18057,6 +18075,8 @@ public final class Settings {
         *
         * @hide
         */
        @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
        @NonNull
        @RequiresPermission(Manifest.permission.READ_DEVICE_CONFIG)
        public static Map<String, String> getStrings(@NonNull String namespace,
                @NonNull List<String> names) {
@@ -18113,6 +18133,7 @@ public final class Settings {
         *
         * @hide
         */
        @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
        @RequiresPermission(Manifest.permission.WRITE_DEVICE_CONFIG)
        public static boolean putString(@NonNull String namespace,
                @NonNull String name, @Nullable String value, boolean makeDefault) {
@@ -18132,6 +18153,7 @@ public final class Settings {
         *
         * @hide
         */
        @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
        @RequiresPermission(Manifest.permission.WRITE_DEVICE_CONFIG)
        public static boolean setStrings(@NonNull String namespace,
                @NonNull Map<String, String> keyValues)
@@ -18182,8 +18204,9 @@ public final class Settings {
         *
         * @hide
         */
        @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
        @RequiresPermission(Manifest.permission.WRITE_DEVICE_CONFIG)
        static boolean deleteString(@NonNull String namespace,
        public static boolean deleteString(@NonNull String namespace,
                @NonNull String name) {
            ContentResolver resolver = getContentResolver();
            return sNameValueCache.deleteStringForUser(resolver,
@@ -18203,8 +18226,9 @@ public final class Settings {
         *
         * @hide
         */
        @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
        @RequiresPermission(Manifest.permission.WRITE_DEVICE_CONFIG)
        static void resetToDefaults(@ResetMode int resetMode,
        public static void resetToDefaults(@ResetMode int resetMode,
                @Nullable String namespace) {
            try {
                ContentResolver resolver = getContentResolver();
@@ -18218,7 +18242,7 @@ public final class Settings {
                cp.call(resolver.getAttributionSource(),
                        sProviderHolder.mUri.getAuthority(), CALL_METHOD_RESET_CONFIG, null, arg);
            } catch (RemoteException e) {
                Log.w(TAG, "Can't reset to defaults for " + DeviceConfig.CONTENT_URI, e);
                Log.w(TAG, "Can't reset to defaults for " + CONTENT_URI, e);
            }
        }
@@ -18228,9 +18252,10 @@ public final class Settings {
         *
         * @hide
         */
        @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
        @SuppressLint("AndroidFrameworkRequiresPermission")
        @RequiresPermission(Manifest.permission.WRITE_DEVICE_CONFIG)
        static void setSyncDisabledMode(@SyncDisabledMode int disableSyncMode) {
        public static void setSyncDisabledMode(@SyncDisabledMode int disableSyncMode) {
            try {
                ContentResolver resolver = getContentResolver();
                Bundle args = new Bundle();
@@ -18239,7 +18264,7 @@ public final class Settings {
                cp.call(resolver.getAttributionSource(), sProviderHolder.mUri.getAuthority(),
                        CALL_METHOD_SET_SYNC_DISABLED_MODE_CONFIG, null, args);
            } catch (RemoteException e) {
                Log.w(TAG, "Can't set sync disabled mode " + DeviceConfig.CONTENT_URI, e);
                Log.w(TAG, "Can't set sync disabled mode " + CONTENT_URI, e);
            }
        }
@@ -18249,9 +18274,10 @@ public final class Settings {
         *
         * @hide
         */
        @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
        @SuppressLint("AndroidFrameworkRequiresPermission")
        @RequiresPermission(Manifest.permission.WRITE_DEVICE_CONFIG)
        static int getSyncDisabledMode() {
        public static int getSyncDisabledMode() {
            try {
                ContentResolver resolver = getContentResolver();
                Bundle args = Bundle.EMPTY;
@@ -18262,7 +18288,7 @@ public final class Settings {
                        null, args);
                return bundle.getInt(KEY_CONFIG_GET_SYNC_DISABLED_MODE_RETURN);
            } catch (RemoteException e) {
                Log.w(TAG, "Can't query sync disabled mode " + DeviceConfig.CONTENT_URI, e);
                Log.w(TAG, "Can't query sync disabled mode " + CONTENT_URI, e);
            }
            return -1;
        }
@@ -18282,21 +18308,26 @@ public final class Settings {
        /**
         * Register a content observer
         * Register a content observer.
         *
         * @hide
         */
        public static void registerContentObserver(@NonNull Uri uri, boolean notifyForDescendants,
                @NonNull ContentObserver observer) {
        @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
        public static void registerContentObserver(@Nullable String namespace,
                boolean notifyForDescendants, @NonNull ContentObserver observer) {
            ActivityThread.currentApplication().getContentResolver()
               .registerContentObserver(uri, notifyForDescendants, observer);
                    .registerContentObserver(createNamespaceUri(namespace),
                         notifyForDescendants, observer);
        }
        /**
         * Unregister a content observer
         * Unregister a content observer.
         * this may only be used with content observers registered through
         * {@link Config#registerContentObserver}
         *
         * @hide
         */
        @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
        public static void unregisterContentObserver(@NonNull ContentObserver observer) {
            ActivityThread.currentApplication().getContentResolver()
              .unregisterContentObserver(observer);
@@ -18357,6 +18388,11 @@ public final class Settings {
            return namespace + "/";
        }
        private static Uri createNamespaceUri(@NonNull String namespace) {
            Preconditions.checkNotNull(namespace);
            return CONTENT_URI.buildUpon().appendPath(namespace).build();
        }
        private static ContentResolver getContentResolver() {
            return ActivityThread.currentApplication().getContentResolver();
        }
+4 −1
Original line number Diff line number Diff line
@@ -857,7 +857,10 @@ public class DeviceConfigTest {
        ContentResolver resolver = InstrumentationRegistry.getContext().getContentResolver();
        String compositeName = namespace + "/" + key;
        Bundle result = resolver.call(
                DeviceConfig.CONTENT_URI, Settings.CALL_METHOD_DELETE_CONFIG, compositeName, null);
                Settings.Config.CONTENT_URI,
                Settings.CALL_METHOD_DELETE_CONFIG,
                compositeName,
                null);
        assertThat(result).isNotNull();
        return compositeName.equals(result.getString(Settings.NameValueTable.VALUE));
    }
+3 −3
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ public class NameValueCacheTest {
        when(mMockContentProvider.getIContentProvider()).thenReturn(mMockIContentProvider);
        mMockContentResolver = new MockContentResolver(InstrumentationRegistry
                .getInstrumentation().getContext());
        mMockContentResolver.addProvider(DeviceConfig.CONTENT_URI.getAuthority(),
        mMockContentResolver.addProvider(Settings.Config.CONTENT_URI.getAuthority(),
                mMockContentProvider);
        mCacheGenerationStore = new MemoryIntArray(1);
        mStorage = new HashMap<>();
@@ -84,7 +84,7 @@ public class NameValueCacheTest {
        // Stores keyValues for a given prefix and increments the generation. (Note that this
        // increments the generation no matter what, it doesn't pay attention to if anything
        // actually changed).
        when(mMockIContentProvider.call(any(), eq(DeviceConfig.CONTENT_URI.getAuthority()),
        when(mMockIContentProvider.call(any(), eq(Settings.Config.CONTENT_URI.getAuthority()),
                eq(Settings.CALL_METHOD_SET_ALL_CONFIG),
                any(), any(Bundle.class))).thenAnswer(invocationOnMock -> {
                    Bundle incomingBundle = invocationOnMock.getArgument(4);
@@ -104,7 +104,7 @@ public class NameValueCacheTest {
        // Returns the keyValues corresponding to a namespace, or an empty map if the namespace
        // doesn't have anything stored for it. Returns the generation key if the caller asked
        // for one.
        when(mMockIContentProvider.call(any(), eq(DeviceConfig.CONTENT_URI.getAuthority()),
        when(mMockIContentProvider.call(any(), eq(Settings.Config.CONTENT_URI.getAuthority()),
                eq(Settings.CALL_METHOD_LIST_CONFIG),
                any(), any(Bundle.class))).thenAnswer(invocationOnMock -> {
                    Bundle incomingBundle = invocationOnMock.getArgument(4);
Loading