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

Commit e86dc768 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Use preexisting DND access setting for condition providers."

parents 86089b06 c279b996
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -5604,11 +5604,6 @@ public final class Settings {
        public static final String ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES =
                "enabled_notification_policy_access_packages";

        /**
         * @hide
         */
        public static final String ENABLED_CONDITION_PROVIDERS = "enabled_condition_providers";

        /** @hide */
        public static final String BAR_SERVICE_COMPONENT = "bar_service_component";

+2 −1
Original line number Diff line number Diff line
@@ -35,7 +35,8 @@ import android.util.Log;
 * the {@link android.Manifest.permission#BIND_CONDITION_PROVIDER_SERVICE} permission
 * and include an intent filter with the {@link #SERVICE_INTERFACE} action. If you want users to be
 * able to create and update conditions for this service to monitor, include the
 * {@link #META_DATA_RULE_TYPE} and {@link #META_DATA_CONFIGURATION_ACTIVITY} tags. For example:</p>
 * {@link #META_DATA_RULE_TYPE} and {@link #META_DATA_CONFIGURATION_ACTIVITY} tags and request the
 * {@link android.Manifest.permission#ACCESS_NOTIFICATION_POLICY} permission. For example:</p>
 * <pre>
 * &lt;service android:name=".MyConditionProvider"
 *          android:label="&#64;string/service_name"
+23 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.notification;

import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.os.Handler;
@@ -29,6 +30,7 @@ import android.service.notification.Condition;
import android.service.notification.ConditionProviderService;
import android.service.notification.IConditionListener;
import android.service.notification.IConditionProvider;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Slog;
@@ -79,7 +81,7 @@ public class ConditionProviders extends ManagedServices {
        final Config c = new Config();
        c.caption = "condition provider";
        c.serviceInterface = ConditionProviderService.SERVICE_INTERFACE;
        c.secureSettingName = Settings.Secure.ENABLED_CONDITION_PROVIDERS;
        c.secureSettingName = Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES;
        c.bindPermission = android.Manifest.permission.BIND_CONDITION_PROVIDER_SERVICE;
        c.settingsAction = Settings.ACTION_CONDITION_PROVIDER_SETTINGS;
        c.clientLabel = R.string.condition_provider_service_binding_label;
@@ -280,6 +282,26 @@ public class ConditionProviders extends ManagedServices {
        }
    }

    @Override
    protected ArraySet<ComponentName> loadComponentNamesFromSetting(String settingName,
            int userId) {
        final ContentResolver cr = mContext.getContentResolver();
        String settingValue = Settings.Secure.getStringForUser(
                cr,
                settingName,
                userId);
        if (TextUtils.isEmpty(settingValue))
            return null;
        String[] packages = settingValue.split(ENABLED_SERVICES_SEPARATOR);
        ArraySet<ComponentName> result = new ArraySet<>(packages.length);
        for (int i = 0; i < packages.length; i++) {
            if (!TextUtils.isEmpty(packages[i])) {
                result.addAll(queryPackageForServices(packages[i], userId));
            }
        }
        return result;
    }

    public boolean subscribeIfNecessary(ComponentName component, Uri conditionId) {
        synchronized (mMutex) {
            final ConditionRecord r = getRecordLocked(conditionId, component, false /*create*/);
+21 −12
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ abstract public class ManagedServices {
    protected final String TAG = getClass().getSimpleName();
    protected final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    private static final String ENABLED_SERVICES_SEPARATOR = ":";
    protected static final String ENABLED_SERVICES_SEPARATOR = ":";

    protected final Context mContext;
    protected final Object mMutex;
@@ -279,7 +279,8 @@ abstract public class ManagedServices {
    }


    private ArraySet<ComponentName> loadComponentNamesFromSetting(String settingName, int userId) {
    protected ArraySet<ComponentName> loadComponentNamesFromSetting(String settingName,
            int userId) {
        final ContentResolver cr = mContext.getContentResolver();
        String settingValue = Settings.Secure.getStringForUser(
                cr,
@@ -319,7 +320,6 @@ abstract public class ManagedServices {
                userId);
    }


    /**
     * Remove access for any services that no longer exist.
     */
@@ -332,18 +332,15 @@ abstract public class ManagedServices {
        rebuildRestoredPackages();
    }

    private void updateSettingsAccordingToInstalledServices(int userId) {
        boolean restoredChanged = false;
        boolean currentChanged = false;
        Set<ComponentName> restored =
                loadComponentNamesFromSetting(restoredSettingName(mConfig), userId);
        Set<ComponentName> current =
                loadComponentNamesFromSetting(mConfig.secureSettingName, userId);
    protected Set<ComponentName> queryPackageForServices(String packageName, int userId) {
        Set<ComponentName> installed = new ArraySet<>();

        final PackageManager pm = mContext.getPackageManager();
        Intent queryIntent = new Intent(mConfig.serviceInterface);
        if (!TextUtils.isEmpty(packageName)) {
            queryIntent.setPackage(packageName);
        }
        List<ResolveInfo> installedServices = pm.queryIntentServicesAsUser(
                new Intent(mConfig.serviceInterface),
                queryIntent,
                PackageManager.GET_SERVICES | PackageManager.GET_META_DATA,
                userId);
        if (DEBUG)
@@ -363,6 +360,18 @@ abstract public class ManagedServices {
            }
            installed.add(component);
        }
        return installed;
    }

    private void updateSettingsAccordingToInstalledServices(int userId) {
        boolean restoredChanged = false;
        boolean currentChanged = false;
        Set<ComponentName> restored =
                loadComponentNamesFromSetting(restoredSettingName(mConfig), userId);
        Set<ComponentName> current =
                loadComponentNamesFromSetting(mConfig.secureSettingName, userId);
        // Load all services for all packages.
        Set<ComponentName> installed = queryPackageForServices(null, userId);

        ArraySet<ComponentName> retained = new ArraySet<>();