}
void updateList() {
- mList.clear();
-
loadEnabledListeners();
+ getListeners(mList, mPM);
+ mList.sort(new PackageItemInfo.DisplayNameComparator(mPM));
+
+ getListView().setAdapter(mList);
+ }
+
+ static int getListenersCount(PackageManager pm) {
+ return getListeners(null, pm);
+ }
+
+ private static int getListeners(ArrayAdapter<ServiceInfo> adapter, PackageManager pm) {
+ int listeners = 0;
+ if (adapter != null) {
+ adapter.clear();
+ }
final int user = ActivityManager.getCurrentUser();
- List<ResolveInfo> installedServices = mPM.queryIntentServicesAsUser(
+ List<ResolveInfo> installedServices = pm.queryIntentServicesAsUser(
new Intent(NotificationListenerService.SERVICE_INTERFACE),
PackageManager.GET_SERVICES | PackageManager.GET_META_DATA,
user);
+ android.Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE);
continue;
}
-
- mList.add(info);
+ if (adapter != null) {
+ adapter.add(info);
+ }
+ listeners++;
}
-
- mList.sort(new PackageItemInfo.DisplayNameComparator(mPM));
-
- getListView().setAdapter(mList);
+ return listeners;
}
boolean isListenerEnabled(ServiceInfo info) {
private static final String KEY_NOTIFICATION_ACCESS = "manage_notification_access";
private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
+ private PackageManager mPM;
DevicePolicyManager mDPM;
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
mLockPatternUtils = new LockPatternUtils(getActivity());
+ mPM = getActivity().getPackageManager();
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
}
}
- final int n = getNumEnabledNotificationListeners();
mNotificationAccess = findPreference(KEY_NOTIFICATION_ACCESS);
- if (n == 0) {
- mNotificationAccess.setSummary(getResources().getString(
- R.string.manage_notification_access_summary_zero));
- } else {
- mNotificationAccess.setSummary(String.format(getResources().getQuantityString(
- R.plurals.manage_notification_access_summary_nonzero,
- n, n)));
+ if (mNotificationAccess != null) {
+ final int total = NotificationAccessSettings.getListenersCount(mPM);
+ if (total == 0) {
+ if (deviceAdminCategory != null) {
+ deviceAdminCategory.removePreference(mNotificationAccess);
+ }
+ } else {
+ final int n = getNumEnabledNotificationListeners();
+ if (n == 0) {
+ mNotificationAccess.setSummary(getResources().getString(
+ R.string.manage_notification_access_summary_zero));
+ } else {
+ mNotificationAccess.setSummary(String.format(getResources().getQuantityString(
+ R.plurals.manage_notification_access_summary_nonzero,
+ n, n)));
+ }
+ }
}
return root;