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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user