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
This commit is contained in:
Julia Reynolds
2015-10-30 08:26:12 -04:00
parent f8f52df702
commit 2714f2ba07
2 changed files with 11 additions and 30 deletions

View File

@@ -37,7 +37,6 @@ import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceClickListener; import android.support.v7.preference.Preference.OnPreferenceClickListener;
import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.PreferenceViewHolder; import android.support.v7.preference.PreferenceViewHolder;
import android.util.Log;
import android.view.View; import android.view.View;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
@@ -47,8 +46,6 @@ import com.android.settings.notification.ManagedServiceSettings.Config;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
import java.util.Objects;
public class ZenModeAutomationSettings extends ZenModeSettingsBase { public class ZenModeAutomationSettings extends ZenModeSettingsBase {
@@ -63,7 +60,6 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
addPreferencesFromResource(R.xml.zen_mode_automation_settings); addPreferencesFromResource(R.xml.zen_mode_automation_settings);
mPm = mContext.getPackageManager(); mPm = mContext.getPackageManager();
mServiceListing = new ServiceListing(mContext, CONFIG); mServiceListing = new ServiceListing(mContext, CONFIG);
mServiceListing.addCallback(mServiceListingCallback);
mServiceListing.reload(); mServiceListing.reload();
mServiceListing.setListening(true); mServiceListing.setListening(true);
} }
@@ -72,7 +68,6 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
mServiceListing.setListening(false); mServiceListing.setListening(false);
mServiceListing.removeCallback(mServiceListingCallback);
} }
@Override @Override
@@ -198,7 +193,7 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
private static Config getConditionProviderConfig() { private static Config getConditionProviderConfig() {
final Config c = new Config(); final Config c = new Config();
c.tag = TAG; 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.intentAction = ConditionProviderService.SERVICE_INTERFACE;
c.permission = android.Manifest.permission.BIND_CONDITION_PROVIDER_SERVICE; c.permission = android.Manifest.permission.BIND_CONDITION_PROVIDER_SERVICE;
c.noun = "condition provider"; 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) { public static ZenRuleInfo getRuleInfo(PackageManager pm, ServiceInfo si) {
if (si == null || si.metaData == null) return null; if (si == null || si.metaData == null) return null;
final String ruleType = si.metaData.getString(ConditionProviderService.META_DATA_RULE_TYPE); final String ruleType = si.metaData.getString(ConditionProviderService.META_DATA_RULE_TYPE);

View File

@@ -17,7 +17,7 @@
package com.android.settings.notification; package com.android.settings.notification;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AutomaticZenRule; import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener; import android.content.DialogInterface.OnDismissListener;
@@ -39,7 +39,7 @@ import com.android.settings.R;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
@@ -49,6 +49,7 @@ public abstract class ZenRuleSelectionDialog {
private final Context mContext; private final Context mContext;
private final PackageManager mPm; private final PackageManager mPm;
private NotificationManager mNm;
private final AlertDialog mDialog; private final AlertDialog mDialog;
private final LinearLayout mRuleContainer; private final LinearLayout mRuleContainer;
private final ServiceListing mServiceListing; private final ServiceListing mServiceListing;
@@ -56,6 +57,7 @@ public abstract class ZenRuleSelectionDialog {
public ZenRuleSelectionDialog(Context context, ServiceListing serviceListing) { public ZenRuleSelectionDialog(Context context, ServiceListing serviceListing) {
mContext = context; mContext = context;
mPm = context.getPackageManager(); mPm = context.getPackageManager();
mNm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mServiceListing = serviceListing; mServiceListing = serviceListing;
final View v = final View v =
LayoutInflater.from(context).inflate(R.layout.zen_rule_type_selection, null, false); LayoutInflater.from(context).inflate(R.layout.zen_rule_type_selection, null, false);
@@ -149,8 +151,8 @@ public abstract class ZenRuleSelectionDialog {
return rt; return rt;
} }
private void bindExternalRules(ZenRuleInfo[] externalRuleTypes) { private void bindExternalRules(List<ZenRuleInfo> externalRuleTypes) {
Arrays.sort(externalRuleTypes, RULE_TYPE_COMPARATOR); Collections.sort(externalRuleTypes, RULE_TYPE_COMPARATOR);
for (ZenRuleInfo ri : externalRuleTypes) { for (ZenRuleInfo ri : externalRuleTypes) {
bindType(ri); bindType(ri);
} }
@@ -160,11 +162,12 @@ public abstract class ZenRuleSelectionDialog {
@Override @Override
public void onServicesReloaded(List<ServiceInfo> services) { public void onServicesReloaded(List<ServiceInfo> services) {
if (DEBUG) Log.d(TAG, "Services reloaded: count=" + services.size()); 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++) { for (int i = 0; i < services.size(); i++) {
final ZenRuleInfo ri = ZenModeAutomationSettings.getRuleInfo(mPm, services.get(i)); final ZenRuleInfo ri = ZenModeAutomationSettings.getRuleInfo(mPm, services.get(i));
if (ri != null && ri.configurationActivity != null) { if (ri != null && ri.configurationActivity != null
externalRuleTypes[i] = ri; && mNm.isNotificationPolicyAccessGrantedForPackage(ri.packageName)) {
externalRuleTypes.add(ri);
} }
} }
bindExternalRules(externalRuleTypes); bindExternalRules(externalRuleTypes);