Hide notification listeners setting if no listeners.
Hide the new notification listeners management setting when no listeners using this API are available. Bug: 8454150 Change-Id: Iae9f975e7b5a3cdf55ff7d0c6aea7e84166d53b3
This commit is contained in:
@@ -195,13 +195,26 @@ public class NotificationAccessSettings extends ListFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateList() {
|
void updateList() {
|
||||||
mList.clear();
|
|
||||||
|
|
||||||
loadEnabledListeners();
|
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();
|
final int user = ActivityManager.getCurrentUser();
|
||||||
|
|
||||||
List<ResolveInfo> installedServices = mPM.queryIntentServicesAsUser(
|
List<ResolveInfo> installedServices = pm.queryIntentServicesAsUser(
|
||||||
new Intent(NotificationListenerService.SERVICE_INTERFACE),
|
new Intent(NotificationListenerService.SERVICE_INTERFACE),
|
||||||
PackageManager.GET_SERVICES | PackageManager.GET_META_DATA,
|
PackageManager.GET_SERVICES | PackageManager.GET_META_DATA,
|
||||||
user);
|
user);
|
||||||
@@ -218,13 +231,12 @@ public class NotificationAccessSettings extends ListFragment {
|
|||||||
+ android.Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE);
|
+ android.Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (adapter != null) {
|
||||||
mList.add(info);
|
adapter.add(info);
|
||||||
|
}
|
||||||
|
listeners++;
|
||||||
}
|
}
|
||||||
|
return listeners;
|
||||||
mList.sort(new PackageItemInfo.DisplayNameComparator(mPM));
|
|
||||||
|
|
||||||
getListView().setAdapter(mList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isListenerEnabled(ServiceInfo info) {
|
boolean isListenerEnabled(ServiceInfo info) {
|
||||||
|
@@ -82,6 +82,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
private static final String KEY_NOTIFICATION_ACCESS = "manage_notification_access";
|
private static final String KEY_NOTIFICATION_ACCESS = "manage_notification_access";
|
||||||
private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
|
private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
|
||||||
|
|
||||||
|
private PackageManager mPM;
|
||||||
DevicePolicyManager mDPM;
|
DevicePolicyManager mDPM;
|
||||||
|
|
||||||
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
|
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
|
||||||
@@ -111,6 +112,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
mLockPatternUtils = new LockPatternUtils(getActivity());
|
mLockPatternUtils = new LockPatternUtils(getActivity());
|
||||||
|
|
||||||
|
mPM = getActivity().getPackageManager();
|
||||||
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
|
|
||||||
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
|
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
|
||||||
@@ -281,15 +283,24 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final int n = getNumEnabledNotificationListeners();
|
|
||||||
mNotificationAccess = findPreference(KEY_NOTIFICATION_ACCESS);
|
mNotificationAccess = findPreference(KEY_NOTIFICATION_ACCESS);
|
||||||
if (n == 0) {
|
if (mNotificationAccess != null) {
|
||||||
mNotificationAccess.setSummary(getResources().getString(
|
final int total = NotificationAccessSettings.getListenersCount(mPM);
|
||||||
R.string.manage_notification_access_summary_zero));
|
if (total == 0) {
|
||||||
} else {
|
if (deviceAdminCategory != null) {
|
||||||
mNotificationAccess.setSummary(String.format(getResources().getQuantityString(
|
deviceAdminCategory.removePreference(mNotificationAccess);
|
||||||
R.plurals.manage_notification_access_summary_nonzero,
|
}
|
||||||
n, n)));
|
} 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;
|
return root;
|
||||||
|
Reference in New Issue
Block a user