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

Commit 2714f2ba authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Permission changes for DND Add Rule page.

Don't whitelist CPs when visiting the Add Rule Page; update
the permission CPs are tracked by; don't show CPs in the add
rule dialog if the user hasn't whitelisted them.

Bug: 22977552
Change-Id: I8b363d7106de088e68b9659e3f0098848c6d3153
parent f8f52df7
Loading
Loading
Loading
Loading
+1 −23
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceClickListener;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.Log;
import android.view.View;

import com.android.internal.logging.MetricsLogger;
@@ -47,8 +46,6 @@ import com.android.settings.notification.ManagedServiceSettings.Config;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;

public class ZenModeAutomationSettings extends ZenModeSettingsBase {

@@ -63,7 +60,6 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
        addPreferencesFromResource(R.xml.zen_mode_automation_settings);
        mPm = mContext.getPackageManager();
        mServiceListing = new ServiceListing(mContext, CONFIG);
        mServiceListing.addCallback(mServiceListingCallback);
        mServiceListing.reload();
        mServiceListing.setListening(true);
    }
@@ -72,7 +68,6 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
    public void onDestroy() {
        super.onDestroy();
        mServiceListing.setListening(false);
        mServiceListing.removeCallback(mServiceListingCallback);
    }

    @Override
@@ -198,7 +193,7 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
    private static Config getConditionProviderConfig() {
        final Config c = new Config();
        c.tag = TAG;
        c.setting = Settings.Secure.ENABLED_CONDITION_PROVIDERS;
        c.setting = Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES;
        c.intentAction = ConditionProviderService.SERVICE_INTERFACE;
        c.permission = android.Manifest.permission.BIND_CONDITION_PROVIDER_SERVICE;
        c.noun = "condition provider";
@@ -218,23 +213,6 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
        }
    }

    private final ServiceListing.Callback mServiceListingCallback = new ServiceListing.Callback() {
        @Override
        public void onServicesReloaded(List<ServiceInfo> services) {
            for (ServiceInfo service : services) {
                final ZenRuleInfo ri = getRuleInfo(mPm, service);
                if (ri != null && ri.serviceComponent != null
                        && Objects.equals(ri.settingsAction,
                        Settings.ACTION_ZEN_MODE_EXTERNAL_RULE_SETTINGS)) {
                    if (!mServiceListing.isEnabled(ri.serviceComponent)) {
                        Log.i(TAG, "Enabling external condition provider: " + ri.serviceComponent);
                        mServiceListing.setEnabled(ri.serviceComponent, true);
                    }
                }
            }
        }
    };

    public static ZenRuleInfo getRuleInfo(PackageManager pm, ServiceInfo si) {
        if (si == null || si.metaData == null) return null;
        final String ruleType = si.metaData.getString(ConditionProviderService.META_DATA_RULE_TYPE);
+10 −7
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.settings.notification;

import android.app.AlertDialog;
import android.app.AutomaticZenRule;
import android.app.NotificationManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
@@ -39,7 +39,7 @@ import com.android.settings.R;
import java.lang.ref.WeakReference;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@@ -49,6 +49,7 @@ public abstract class ZenRuleSelectionDialog {

    private final Context mContext;
    private final PackageManager mPm;
    private NotificationManager mNm;
    private final AlertDialog mDialog;
    private final LinearLayout mRuleContainer;
    private final ServiceListing mServiceListing;
@@ -56,6 +57,7 @@ public abstract class ZenRuleSelectionDialog {
    public ZenRuleSelectionDialog(Context context, ServiceListing serviceListing) {
        mContext = context;
        mPm = context.getPackageManager();
        mNm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mServiceListing = serviceListing;
        final View v =
                LayoutInflater.from(context).inflate(R.layout.zen_rule_type_selection, null, false);
@@ -149,8 +151,8 @@ public abstract class ZenRuleSelectionDialog {
        return rt;
    }

    private void bindExternalRules(ZenRuleInfo[] externalRuleTypes) {
        Arrays.sort(externalRuleTypes, RULE_TYPE_COMPARATOR);
    private void bindExternalRules(List<ZenRuleInfo> externalRuleTypes) {
        Collections.sort(externalRuleTypes, RULE_TYPE_COMPARATOR);
        for (ZenRuleInfo ri : externalRuleTypes) {
            bindType(ri);
        }
@@ -160,11 +162,12 @@ public abstract class ZenRuleSelectionDialog {
        @Override
        public void onServicesReloaded(List<ServiceInfo> services) {
            if (DEBUG) Log.d(TAG, "Services reloaded: count=" + services.size());
            ZenRuleInfo[] externalRuleTypes = new ZenRuleInfo[services.size()];
            List<ZenRuleInfo> externalRuleTypes = new ArrayList<>();
            for (int i = 0; i < services.size(); i++) {
                final ZenRuleInfo ri = ZenModeAutomationSettings.getRuleInfo(mPm, services.get(i));
                if (ri != null && ri.configurationActivity != null) {
                    externalRuleTypes[i] = ri;
                if (ri != null && ri.configurationActivity != null
                        && mNm.isNotificationPolicyAccessGrantedForPackage(ri.packageName)) {
                    externalRuleTypes.add(ri);
                }
            }
            bindExternalRules(externalRuleTypes);