summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/notification/ManagedServiceSettings.java
diff options
context:
space:
mode:
authorJohn Spurlock <jspurlock@google.com>2015-04-10 11:59:54 -0400
committerJohn Spurlock <jspurlock@google.com>2015-04-13 12:19:55 -0400
commitc96a5dcbfc3f37f71e8b3e8b962f9571b1e7ceaf (patch)
treef705752a83dc3bcabcea1d9ac69e0682d13251dd /src/com/android/settings/notification/ManagedServiceSettings.java
parent3b1a4c6cc2afe590407819fc66c30e9361862950 (diff)
downloadpackages_apps_Settings-c96a5dcbfc3f37f71e8b3e8b962f9571b1e7ceaf.zip
packages_apps_Settings-c96a5dcbfc3f37f71e8b3e8b962f9571b1e7ceaf.tar.gz
packages_apps_Settings-c96a5dcbfc3f37f71e8b3e8b962f9571b1e7ceaf.tar.bz2
Settings: External automatic rule settings.
- Add external automatic rule settings page with the common settings for all rules (enabled, name, zen mode). - Pull common rule-instance settings into settings base class, share with existing schedule rule settings. - New page not searchable since it is at the rule-instance level. - Obtain external rule information from existing conditions provider metadata. Includes rule type caption, sub-configuration activity, and default condition id. - If external condition providers exist with the appropriate metadata, display the external rule types as options in the new rule dialog. (max of 3 external types) - Pull common managed service listing code out of common settings base class and into a more reusable helper class. Bug: 20064962 Change-Id: Ibc13607490b7312a7d9f7f3bd61c3cfcf71a2794
Diffstat (limited to 'src/com/android/settings/notification/ManagedServiceSettings.java')
-rw-r--r--src/com/android/settings/notification/ManagedServiceSettings.java233
1 files changed, 61 insertions, 172 deletions
diff --git a/src/com/android/settings/notification/ManagedServiceSettings.java b/src/com/android/settings/notification/ManagedServiceSettings.java
index 7be644e..cc9e734 100644
--- a/src/com/android/settings/notification/ManagedServiceSettings.java
+++ b/src/com/android/settings/notification/ManagedServiceSettings.java
@@ -16,28 +16,17 @@
package com.android.settings.notification;
-import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.ListFragment;
-import android.content.BroadcastReceiver;
import android.content.ComponentName;
-import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.IntentFilter;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
-import android.database.ContentObserver;
-import android.net.Uri;
import android.os.Bundle;
-import android.os.Handler;
-import android.provider.Settings;
-import android.util.Slog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -49,17 +38,15 @@ import android.widget.TextView;
import com.android.settings.R;
-import java.util.HashSet;
import java.util.List;
public abstract class ManagedServiceSettings extends ListFragment {
private static final boolean SHOW_PACKAGE_NAME = false;
private final Config mConfig;
- private PackageManager mPM;
- private ContentResolver mCR;
- private final HashSet<ComponentName> mEnabledServices = new HashSet<ComponentName>();
+ private PackageManager mPM;
+ private ServiceListing mServiceListing;
private ServiceListAdapter mListAdapter;
abstract protected Config getConfig();
@@ -68,68 +55,18 @@ public abstract class ManagedServiceSettings extends ListFragment {
mConfig = getConfig();
}
- private final ContentObserver mSettingsObserver = new ContentObserver(new Handler()) {
- @Override
- public void onChange(boolean selfChange, Uri uri) {
- updateList();
- }
- };
-
- private final BroadcastReceiver mPackageReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- updateList();
- }
- };
-
- public class ScaryWarningDialogFragment extends DialogFragment {
- static final String KEY_COMPONENT = "c";
- static final String KEY_LABEL = "l";
-
- public ScaryWarningDialogFragment setServiceInfo(ComponentName cn, String label) {
- Bundle args = new Bundle();
- args.putString(KEY_COMPONENT, cn.flattenToString());
- args.putString(KEY_LABEL, label);
- setArguments(args);
- return this;
- }
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- final Bundle args = getArguments();
- final String label = args.getString(KEY_LABEL);
- final ComponentName cn = ComponentName.unflattenFromString(args.getString(KEY_COMPONENT));
-
- final String title = getResources().getString(mConfig.warningDialogTitle, label);
- final String summary = getResources().getString(mConfig.warningDialogSummary, label);
- return new AlertDialog.Builder(getActivity())
- .setMessage(summary)
- .setTitle(title)
- .setCancelable(true)
- .setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- mEnabledServices.add(cn);
- saveEnabledServices();
- }
- })
- .setNegativeButton(android.R.string.cancel,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- // pass
- }
- })
- .create();
- }
- }
-
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mPM = getActivity().getPackageManager();
- mCR = getActivity().getContentResolver();
+ mServiceListing = new ServiceListing(getActivity(), mConfig);
+ mServiceListing.addCallback(new ServiceListing.Callback() {
+ @Override
+ public void onServicesReloaded(List<ServiceInfo> services) {
+ updateList(services);
+ }
+ });
mListAdapter = new ServiceListAdapter(getActivity());
}
@@ -145,122 +82,31 @@ public abstract class ManagedServiceSettings extends ListFragment {
@Override
public void onResume() {
super.onResume();
- updateList();
-
- // listen for package changes
- IntentFilter filter = new IntentFilter();
- filter.addAction(Intent.ACTION_PACKAGE_ADDED);
- filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
- filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
- filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
- filter.addDataScheme("package");
- getActivity().registerReceiver(mPackageReceiver, filter);
-
- mCR.registerContentObserver(Settings.Secure.getUriFor(mConfig.setting),
- false, mSettingsObserver);
+ mServiceListing.reload();
+ mServiceListing.setListening(true);
}
@Override
public void onPause() {
super.onPause();
-
- getActivity().unregisterReceiver(mPackageReceiver);
- mCR.unregisterContentObserver(mSettingsObserver);
- }
-
- private void loadEnabledServices() {
- mEnabledServices.clear();
- final String flat = Settings.Secure.getString(mCR, mConfig.setting);
- if (flat != null && !"".equals(flat)) {
- final String[] names = flat.split(":");
- for (int i = 0; i < names.length; i++) {
- final ComponentName cn = ComponentName.unflattenFromString(names[i]);
- if (cn != null) {
- mEnabledServices.add(cn);
- }
- }
- }
- }
-
- private void saveEnabledServices() {
- StringBuilder sb = null;
- for (ComponentName cn : mEnabledServices) {
- if (sb == null) {
- sb = new StringBuilder();
- } else {
- sb.append(':');
- }
- sb.append(cn.flattenToString());
- }
- Settings.Secure.putString(mCR,
- mConfig.setting,
- sb != null ? sb.toString() : "");
+ mServiceListing.setListening(false);
}
- private void updateList() {
- loadEnabledServices();
-
- getServices(mConfig, mListAdapter, mPM);
+ private void updateList(List<ServiceInfo> services) {
+ mListAdapter.clear();
+ mListAdapter.addAll(services);
mListAdapter.sort(new PackageItemInfo.DisplayNameComparator(mPM));
getListView().setAdapter(mListAdapter);
}
- protected static int getEnabledServicesCount(Config config, Context context) {
- final String flat = Settings.Secure.getString(context.getContentResolver(), config.setting);
- if (flat == null || "".equals(flat)) return 0;
- final String[] components = flat.split(":");
- return components.length;
- }
-
- protected static int getServicesCount(Config c, PackageManager pm) {
- return getServices(c, null, pm);
- }
-
- private static int getServices(Config c, ArrayAdapter<ServiceInfo> adapter, PackageManager pm) {
- int services = 0;
- if (adapter != null) {
- adapter.clear();
- }
- final int user = ActivityManager.getCurrentUser();
-
- List<ResolveInfo> installedServices = pm.queryIntentServicesAsUser(
- new Intent(c.intentAction),
- PackageManager.GET_SERVICES | PackageManager.GET_META_DATA,
- user);
-
- for (int i = 0, count = installedServices.size(); i < count; i++) {
- ResolveInfo resolveInfo = installedServices.get(i);
- ServiceInfo info = resolveInfo.serviceInfo;
-
- if (!c.permission.equals(info.permission)) {
- Slog.w(c.tag, "Skipping " + c.noun + " service "
- + info.packageName + "/" + info.name
- + ": it does not require the permission "
- + c.permission);
- continue;
- }
- if (adapter != null) {
- adapter.add(info);
- }
- services++;
- }
- return services;
- }
-
- private boolean isServiceEnabled(ServiceInfo info) {
- final ComponentName cn = new ComponentName(info.packageName, info.name);
- return mEnabledServices.contains(cn);
- }
-
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
ServiceInfo info = mListAdapter.getItem(position);
final ComponentName cn = new ComponentName(info.packageName, info.name);
- if (mEnabledServices.contains(cn)) {
+ if (mServiceListing.isEnabled(cn)) {
// the simple version: disabling
- mEnabledServices.remove(cn);
- saveEnabledServices();
+ mServiceListing.setEnabled(cn, false);
} else {
// show a scary dialog
new ScaryWarningDialogFragment()
@@ -269,6 +115,48 @@ public abstract class ManagedServiceSettings extends ListFragment {
}
}
+ public class ScaryWarningDialogFragment extends DialogFragment {
+ static final String KEY_COMPONENT = "c";
+ static final String KEY_LABEL = "l";
+
+ public ScaryWarningDialogFragment setServiceInfo(ComponentName cn, String label) {
+ Bundle args = new Bundle();
+ args.putString(KEY_COMPONENT, cn.flattenToString());
+ args.putString(KEY_LABEL, label);
+ setArguments(args);
+ return this;
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ final Bundle args = getArguments();
+ final String label = args.getString(KEY_LABEL);
+ final ComponentName cn = ComponentName.unflattenFromString(args
+ .getString(KEY_COMPONENT));
+
+ final String title = getResources().getString(mConfig.warningDialogTitle, label);
+ final String summary = getResources().getString(mConfig.warningDialogSummary, label);
+ return new AlertDialog.Builder(getActivity())
+ .setMessage(summary)
+ .setTitle(title)
+ .setCancelable(true)
+ .setPositiveButton(android.R.string.ok,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ mServiceListing.setEnabled(cn, true);
+ }
+ })
+ .setNegativeButton(android.R.string.cancel,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ // pass
+ }
+ })
+ .create();
+ }
+ }
+
private static class ViewHolder {
ImageView icon;
TextView name;
@@ -327,7 +215,8 @@ public abstract class ManagedServiceSettings extends ListFragment {
} else {
vh.description.setVisibility(View.GONE);
}
- vh.checkbox.setChecked(isServiceEnabled(info));
+ final ComponentName cn = new ComponentName(info.packageName, info.name);
+ vh.checkbox.setChecked(mServiceListing.isEnabled(cn));
}
}