Obey rule instance limit.
Do not show a rule type in the 'Add rule' dialog if the number of current instances of that rule equals the max number of instances allowed by that rule type. Bug: 25563007 Change-Id: I18f2598c6d92aec93c27755bb6b04c460ee294d0
This commit is contained in:
@@ -35,6 +35,7 @@ import android.util.Slog;
|
||||
import com.android.settings.notification.ManagedServiceSettings.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
@@ -45,6 +46,7 @@ public class ServiceListing {
|
||||
private final HashSet<ComponentName> mEnabledServices = new HashSet<ComponentName>();
|
||||
private final List<ServiceInfo> mServices = new ArrayList<ServiceInfo>();
|
||||
private final List<Callback> mCallbacks = new ArrayList<Callback>();
|
||||
private final List<ServiceInfo> mApprovedServices = new ArrayList<ServiceInfo>();
|
||||
|
||||
private boolean mListening;
|
||||
|
||||
@@ -93,10 +95,9 @@ public class ServiceListing {
|
||||
return getServices(c, null, pm);
|
||||
}
|
||||
|
||||
public static ServiceInfo findService(Context context, Config config, final ComponentName cn) {
|
||||
public ServiceInfo findService(Context context, Config config, final ComponentName cn) {
|
||||
final ServiceListing listing = new ServiceListing(context, config);
|
||||
final List<ServiceInfo> services = listing.reload();
|
||||
for (ServiceInfo service : services) {
|
||||
for (ServiceInfo service : mApprovedServices) {
|
||||
final ComponentName serviceCN = new ComponentName(service.packageName, service.name);
|
||||
if (serviceCN.equals(cn)) {
|
||||
return service;
|
||||
@@ -173,6 +174,26 @@ public class ServiceListing {
|
||||
return mServices;
|
||||
}
|
||||
|
||||
public void reloadApprovedServices() {
|
||||
mApprovedServices.clear();
|
||||
final String flat = Settings.Secure.getString(mContentResolver, mConfig.setting);
|
||||
if (flat != null && !"".equals(flat)) {
|
||||
final List<String> names = Arrays.asList(flat.split(":"));
|
||||
List<ServiceInfo> services = new ArrayList<>();
|
||||
getServices(mConfig, services, mContext.getPackageManager());
|
||||
for (ServiceInfo service : services) {
|
||||
final ComponentName componentName = service.getComponentName();
|
||||
String flatCn = service.getComponentName().flattenToString();
|
||||
if (names.contains(flatCn) || names.contains(componentName.getPackageName())) {
|
||||
mApprovedServices.add(service);
|
||||
}
|
||||
}
|
||||
for (Callback callback : mCallbacks) {
|
||||
callback.onServicesReloaded(mApprovedServices);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEnabled(ComponentName cn) {
|
||||
return mEnabledServices.contains(cn);
|
||||
}
|
||||
|
@@ -60,14 +60,12 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
|
||||
addPreferencesFromResource(R.xml.zen_mode_automation_settings);
|
||||
mPm = mContext.getPackageManager();
|
||||
mServiceListing = new ServiceListing(mContext, CONFIG);
|
||||
mServiceListing.reload();
|
||||
mServiceListing.setListening(true);
|
||||
mServiceListing.reloadApprovedServices();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
mServiceListing.setListening(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -228,7 +226,8 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
|
||||
ri.packageName = si.packageName;
|
||||
ri.configurationActivity = getSettingsActivity(si);
|
||||
ri.packageLabel = si.applicationInfo.loadLabel(pm);
|
||||
|
||||
ri.ruleInstanceLimit =
|
||||
si.metaData.getInt(ConditionProviderService.META_DATA_RULE_INSTANCE_LIMIT, -1);
|
||||
return ri;
|
||||
}
|
||||
return null;
|
||||
|
@@ -12,4 +12,5 @@ public class ZenRuleInfo {
|
||||
public ComponentName serviceComponent;
|
||||
public boolean isSystem;
|
||||
public CharSequence packageLabel;
|
||||
public int ruleInstanceLimit = -1;
|
||||
}
|
||||
|
@@ -67,7 +67,7 @@ public abstract class ZenRuleSelectionDialog {
|
||||
bindType(defaultNewEvent());
|
||||
bindType(defaultNewSchedule());
|
||||
mServiceListing.addCallback(mServiceListingCallback);
|
||||
mServiceListing.reload();
|
||||
mServiceListing.reloadApprovedServices();
|
||||
}
|
||||
mDialog = new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.zen_mode_choose_rule_type)
|
||||
@@ -166,7 +166,9 @@ public abstract class ZenRuleSelectionDialog {
|
||||
for (int i = 0; i < services.size(); i++) {
|
||||
final ZenRuleInfo ri = ZenModeAutomationSettings.getRuleInfo(mPm, services.get(i));
|
||||
if (ri != null && ri.configurationActivity != null
|
||||
&& mNm.isNotificationPolicyAccessGrantedForPackage(ri.packageName)) {
|
||||
&& mNm.isNotificationPolicyAccessGrantedForPackage(ri.packageName)
|
||||
&& (ri.ruleInstanceLimit <= 0 || ri.ruleInstanceLimit
|
||||
>= (mNm.getRuleInstanceCount(services.get(i).getComponentName()) + 1))) {
|
||||
externalRuleTypes.add(ri);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user