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

Commit a26037f8 authored by Hassan Ali's avatar Hassan Ali Committed by Android (Google) Code Review
Browse files

Merge "Remove ActivityThread from deviceconfig.java"

parents 5e515d64 4dc91d8e
Loading
Loading
Loading
Loading
+12 −24
Original line number Diff line number Diff line
@@ -25,9 +25,6 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.app.ActivityThread;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
import android.database.ContentObserver;
import android.net.Uri;
@@ -882,9 +879,8 @@ public final class DeviceConfig {
    @NonNull
    @RequiresPermission(READ_DEVICE_CONFIG)
    public static Properties getProperties(@NonNull String namespace, @NonNull String ... names) {
        ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
        return new Properties(namespace,
                Settings.Config.getStrings(contentResolver, namespace, Arrays.asList(names)));
                Settings.Config.getStrings(namespace, Arrays.asList(names)));
    }

    /**
@@ -1023,8 +1019,7 @@ public final class DeviceConfig {
    @RequiresPermission(WRITE_DEVICE_CONFIG)
    public static boolean setProperty(@NonNull String namespace, @NonNull String name,
            @Nullable String value, boolean makeDefault) {
        ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
        return Settings.Config.putString(contentResolver, namespace, name, value, makeDefault);
        return Settings.Config.putString(namespace, name, value, makeDefault);
    }

    /**
@@ -1045,8 +1040,7 @@ public final class DeviceConfig {
    @SystemApi
    @RequiresPermission(WRITE_DEVICE_CONFIG)
    public static boolean setProperties(@NonNull Properties properties) throws BadConfigException {
        ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
        return Settings.Config.setStrings(contentResolver, properties.getNamespace(),
        return Settings.Config.setStrings(properties.getNamespace(),
                properties.mMap);
    }

@@ -1062,8 +1056,7 @@ public final class DeviceConfig {
    @SystemApi
    @RequiresPermission(WRITE_DEVICE_CONFIG)
    public static boolean deleteProperty(@NonNull String namespace, @NonNull String name) {
        ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
        return Settings.Config.deleteString(contentResolver, namespace, name);
        return Settings.Config.deleteString(namespace, name);
    }

    /**
@@ -1094,8 +1087,7 @@ public final class DeviceConfig {
    @SystemApi
    @RequiresPermission(WRITE_DEVICE_CONFIG)
    public static void resetToDefaults(@ResetMode int resetMode, @Nullable String namespace) {
        ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
        Settings.Config.resetToDefaults(contentResolver, resetMode, namespace);
        Settings.Config.resetToDefaults(resetMode, namespace);
    }

    /**
@@ -1112,8 +1104,7 @@ public final class DeviceConfig {
     */
    @RequiresPermission(WRITE_DEVICE_CONFIG)
    public static void setSyncDisabledMode(@SyncDisabledMode int syncDisabledMode) {
        ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
        Settings.Config.setSyncDisabledMode(contentResolver, syncDisabledMode);
        Settings.Config.setSyncDisabledMode(syncDisabledMode);
    }

    /**
@@ -1124,8 +1115,7 @@ public final class DeviceConfig {
     */
    @RequiresPermission(WRITE_DEVICE_CONFIG)
    public static @SyncDisabledMode int getSyncDisabledMode() {
        ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
        return Settings.Config.getSyncDisabledMode(contentResolver);
        return Settings.Config.getSyncDisabledMode();
    }

    /**
@@ -1148,8 +1138,7 @@ public final class DeviceConfig {
            @NonNull String namespace,
            @NonNull @CallbackExecutor Executor executor,
            @NonNull OnPropertiesChangedListener onPropertiesChangedListener) {
        enforceReadPermission(ActivityThread.currentApplication().getApplicationContext(),
                namespace);
        enforceReadPermission(namespace);
        synchronized (sLock) {
            Pair<String, Executor> oldNamespace = sListeners.get(onPropertiesChangedListener);
            if (oldNamespace == null) {
@@ -1216,7 +1205,7 @@ public final class DeviceConfig {
                    }
                }
            };
            ActivityThread.currentApplication().getContentResolver()
            Settings.Config
                    .registerContentObserver(createNamespaceUri(namespace), true, contentObserver);
            sNamespaces.put(namespace, new Pair<>(contentObserver, 1));
        }
@@ -1240,8 +1229,7 @@ public final class DeviceConfig {
            sNamespaces.put(namespace, new Pair<>(namespaceCount.first, namespaceCount.second - 1));
        } else {
            // Decrementing a namespace to zero means we no longer need its ContentObserver.
            ActivityThread.currentApplication().getContentResolver()
                    .unregisterContentObserver(namespaceCount.first);
            Settings.Config.unregisterContentObserver(namespaceCount.first);
            sNamespaces.remove(namespace);
        }
    }
@@ -1281,8 +1269,8 @@ public final class DeviceConfig {
     * Enforces READ_DEVICE_CONFIG permission if namespace is not one of public namespaces.
     * @hide
     */
    public static void enforceReadPermission(Context context, String namespace) {
        if (context.checkCallingOrSelfPermission(READ_DEVICE_CONFIG)
    public static void enforceReadPermission(String namespace) {
        if (Settings.Config.checkCallingOrSelfPermission(READ_DEVICE_CONFIG)
                != PackageManager.PERMISSION_GRANTED) {
            if (!PUBLIC_NAMESPACES.contains(namespace)) {
                throw new SecurityException("Permission denial: reading from settings requires:"
+96 −13
Original line number Diff line number Diff line
@@ -47,9 +47,11 @@ import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionName;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.SQLException;
import android.location.ILocationManager;
@@ -3344,7 +3346,7 @@ public final class Settings {
        public ArrayMap<String, String> getStringsForPrefix(ContentResolver cr, String prefix,
                List<String> names) {
            String namespace = prefix.substring(0, prefix.length() - 1);
            DeviceConfig.enforceReadPermission(ActivityThread.currentApplication(), namespace);
            DeviceConfig.enforceReadPermission(namespace);
            ArrayMap<String, String> keyValues = new ArrayMap<>();
            int currentGeneration = -1;
@@ -18002,17 +18004,33 @@ public final class Settings {
        /**
         * Look up a name in the database.
         * @param resolver to access the database with
         * @param name to look up in the table
         * @return the corresponding value, or null if not present
         *
         * @hide
         */
        @RequiresPermission(Manifest.permission.READ_DEVICE_CONFIG)
        static String getString(ContentResolver resolver, String name) {
        static String getString(String name) {
            ContentResolver resolver = getContentResolver();
            return sNameValueCache.getStringForUser(resolver, name, resolver.getUserId());
        }
        /**
         * Look up a list of names in the database, within the specified namespace.
         *
         * @param namespace to which the names belong
         * @param names to look up in the table
         * @return a non null, but possibly empty, map from name to value for any of the names that
         *         were found during lookup.
         *
         * @hide
         */
        @RequiresPermission(Manifest.permission.READ_DEVICE_CONFIG)
        public static Map<String, String> getStrings(@NonNull String namespace,
                @NonNull List<String> names) {
            return getStrings(getContentResolver(), namespace, names);
        }
        /**
         * Look up a list of names in the database, within the specified namespace.
         *
@@ -18053,7 +18071,6 @@ public final class Settings {
         * <strong>not</strong> be set as the default.
         * </p>
         *
         * @param resolver to access the database with.
         * @param namespace to store the name/value pair in.
         * @param name to store.
         * @param value to associate with the name.
@@ -18065,13 +18082,31 @@ public final class Settings {
         * @hide
         */
        @RequiresPermission(Manifest.permission.WRITE_DEVICE_CONFIG)
        static boolean putString(@NonNull ContentResolver resolver, @NonNull String namespace,
        public static boolean putString(@NonNull String namespace,
                @NonNull String name, @Nullable String value, boolean makeDefault) {
            ContentResolver resolver = getContentResolver();
            return sNameValueCache.putStringForUser(resolver, createCompositeName(namespace, name),
                    value, null, makeDefault, resolver.getUserId(),
                    DEFAULT_OVERRIDEABLE_BY_RESTORE);
        }
        /**
         * Clear all name/value pairs for the provided namespace and save new name/value pairs in
         * their place.
         *
         * @param namespace to which the names should be set.
         * @param keyValues map of key names (without the prefix) to values.
         * @return true if the name/value pairs were set, false if setting was blocked
         *
         * @hide
         */
        @RequiresPermission(Manifest.permission.WRITE_DEVICE_CONFIG)
        public static boolean setStrings(@NonNull String namespace,
                @NonNull Map<String, String> keyValues)
                throws DeviceConfig.BadConfigException {
            return setStrings(getContentResolver(), namespace, keyValues);
        }
        /**
         * Clear all name/value pairs for the provided namespace and save new name/value pairs in
         * their place.
@@ -18106,7 +18141,6 @@ public final class Settings {
        /**
         * Delete a name/value pair from the database for the specified namespace.
         *
         * @param resolver to access the database with.
         * @param namespace to delete the name/value pair from.
         * @param name to delete.
         * @return true if the value was deleted, false on database errors. If the name/value pair
@@ -18117,8 +18151,9 @@ public final class Settings {
         * @hide
         */
        @RequiresPermission(Manifest.permission.WRITE_DEVICE_CONFIG)
        static boolean deleteString(@NonNull ContentResolver resolver, @NonNull String namespace,
        static boolean deleteString(@NonNull String namespace,
                @NonNull String name) {
            ContentResolver resolver = getContentResolver();
            return sNameValueCache.deleteStringForUser(resolver,
                    createCompositeName(namespace, name), resolver.getUserId());
        }
@@ -18129,7 +18164,6 @@ public final class Settings {
         * The method accepts an optional prefix parameter. If provided, only pairs with a name that
         * starts with the exact prefix will be reset. Otherwise all will be reset.
         *
         * @param resolver Handle to the content resolver.
         * @param resetMode The reset mode to use.
         * @param namespace Optionally, to limit which which namespace is reset.
         *
@@ -18138,9 +18172,10 @@ public final class Settings {
         * @hide
         */
        @RequiresPermission(Manifest.permission.WRITE_DEVICE_CONFIG)
        static void resetToDefaults(@NonNull ContentResolver resolver, @ResetMode int resetMode,
        static void resetToDefaults(@ResetMode int resetMode,
                @Nullable String namespace) {
            try {
                ContentResolver resolver = getContentResolver();
                Bundle arg = new Bundle();
                arg.putInt(CALL_METHOD_USER_KEY, resolver.getUserId());
                arg.putInt(CALL_METHOD_RESET_MODE_KEY, resetMode);
@@ -18163,9 +18198,9 @@ public final class Settings {
         */
        @SuppressLint("AndroidFrameworkRequiresPermission")
        @RequiresPermission(Manifest.permission.WRITE_DEVICE_CONFIG)
        static void setSyncDisabledMode(
                @NonNull ContentResolver resolver, @SyncDisabledMode int disableSyncMode) {
        static void setSyncDisabledMode(@SyncDisabledMode int disableSyncMode) {
            try {
                ContentResolver resolver = getContentResolver();
                Bundle args = new Bundle();
                args.putInt(CALL_METHOD_SYNC_DISABLED_MODE_KEY, disableSyncMode);
                IContentProvider cp = sProviderHolder.getProvider(resolver);
@@ -18184,8 +18219,9 @@ public final class Settings {
         */
        @SuppressLint("AndroidFrameworkRequiresPermission")
        @RequiresPermission(Manifest.permission.WRITE_DEVICE_CONFIG)
        static int getSyncDisabledMode(@NonNull ContentResolver resolver) {
        static int getSyncDisabledMode() {
            try {
                ContentResolver resolver = getContentResolver();
                Bundle args = Bundle.EMPTY;
                IContentProvider cp = sProviderHolder.getProvider(resolver);
                Bundle bundle = cp.call(resolver.getAttributionSource(),
@@ -18202,7 +18238,6 @@ public final class Settings {
        /**
         * Register callback for monitoring Config table.
         *
         * @param resolver Handle to the content resolver.
         * @param callback callback to register
         *
         * @hide
@@ -18213,6 +18248,50 @@ public final class Settings {
            registerMonitorCallbackAsUser(resolver, resolver.getUserId(), callback);
        }
        /**
         * Register a content observer
         *
         * @hide
         */
        public static void registerContentObserver(@NonNull Uri uri, boolean notifyForDescendants,
                @NonNull ContentObserver observer) {
            ActivityThread.currentApplication().getContentResolver()
               .registerContentObserver(uri, notifyForDescendants, observer);
        }
        /**
         * Unregister a content observer
         *
         * @hide
         */
        public static void unregisterContentObserver(@NonNull ContentObserver observer) {
            ActivityThread.currentApplication().getContentResolver()
              .unregisterContentObserver(observer);
        }
        /**
         * Determine whether the calling process of an IPC <em>or you</em> have been
         * granted a particular permission.  This is the same as
         * {@link #checkCallingPermission}, except it grants your own permissions
         * if you are not currently processing an IPC.  Use with care!
         *
         * @param permission The name of the permission being checked.
         *
         * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
         * pid/uid is allowed that permission, or
         * {@link PackageManager#PERMISSION_DENIED} if it is not.
         *
         * @see PackageManager#checkPermission(String, String)
         * @see #checkPermission
         * @see #checkCallingPermission
         * @hide
         */
        public static int checkCallingOrSelfPermission(@NonNull @PermissionName String permission) {
            return ActivityThread.currentApplication()
               .getApplicationContext().checkCallingOrSelfPermission(permission);
        }
        private static void registerMonitorCallbackAsUser(
                @NonNull ContentResolver resolver, @UserIdInt int userHandle,
                @NonNull RemoteCallback callback) {
@@ -18245,6 +18324,10 @@ public final class Settings {
            Preconditions.checkNotNull(namespace);
            return namespace + "/";
        }
        private static ContentResolver getContentResolver() {
            return ActivityThread.currentApplication().getContentResolver();
        }
    }
    /**
+0 −2
Original line number Diff line number Diff line
@@ -91,7 +91,6 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.UiThread;
import android.annotation.WorkerThread;
import android.app.ActivityThread;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
@@ -417,7 +416,6 @@ public class InteractionJankMonitor {
    public InteractionJankMonitor(@NonNull HandlerThread worker) {
        // Check permission early.
        DeviceConfig.enforceReadPermission(
            ActivityThread.currentApplication().getApplicationContext(),
            DeviceConfig.NAMESPACE_INTERACTION_JANK_MONITOR);

        mRunningTrackers = new SparseArray<>();
+4 −4
Original line number Diff line number Diff line
@@ -112,10 +112,10 @@ import com.android.internal.os.BackgroundThread;
import com.android.internal.util.FrameworkStatsLog;
import com.android.providers.settings.SettingsState.Setting;

import libcore.util.HexEncoding;

import com.google.android.collect.Sets;

import libcore.util.HexEncoding;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
@@ -1144,7 +1144,7 @@ public class SettingsProvider extends ContentProvider {
            Slog.v(LOG_TAG, "getConfigSetting(" + name + ")");
        }

        DeviceConfig.enforceReadPermission(getContext(), /*namespace=*/name.split("/")[0]);
        DeviceConfig.enforceReadPermission(/*namespace=*/name.split("/")[0]);

        // Get the value.
        synchronized (mLock) {
@@ -1317,7 +1317,7 @@ public class SettingsProvider extends ContentProvider {
            Slog.v(LOG_TAG, "getAllConfigFlags() for " + prefix);
        }

        DeviceConfig.enforceReadPermission(getContext(),
        DeviceConfig.enforceReadPermission(
                prefix != null ? prefix.split("/")[0] : null);

        synchronized (mLock) {
+2 −3
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.util;
import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.provider.DeviceConfig;
import android.provider.Settings;

@@ -53,8 +52,8 @@ public class DeviceConfigProxy {
    /**
     * Wrapped version of {@link DeviceConfig#enforceReadPermission}.
     */
    public void enforceReadPermission(Context context, String namespace) {
        DeviceConfig.enforceReadPermission(context, namespace);
    public void enforceReadPermission(String namespace) {
        DeviceConfig.enforceReadPermission(namespace);
    }

    /**
Loading