Don't hide approved NLSes in Settings
Note that an NLS that shouldn't be approvable (because its name is too long) but was already approved (either before the max length check was introduced, or through other means) will disappear from the list if the user revokes its access. This might be somewhat confusing, but since this is a very-edge case already it's fine. Bug: 282932362 Test: manual Change-Id: I4c9faea68e6d16b1a4ec7f472b5433cac1704c06
This commit is contained in:
@@ -40,6 +40,7 @@ import android.widget.Toast;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.applications.AppInfoBase;
|
||||
@@ -60,8 +61,8 @@ import java.util.List;
|
||||
@SearchIndexable
|
||||
public class NotificationAccessSettings extends EmptyTextSettings {
|
||||
private static final String TAG = "NotifAccessSettings";
|
||||
private static final String ALLOWED_KEY = "allowed";
|
||||
private static final String NOT_ALLOWED_KEY = "not_allowed";
|
||||
static final String ALLOWED_KEY = "allowed";
|
||||
static final String NOT_ALLOWED_KEY = "not_allowed";
|
||||
private static final int MAX_CN_LENGTH = 500;
|
||||
|
||||
private static final ManagedServiceSettings.Config CONFIG =
|
||||
@@ -77,9 +78,9 @@ public class NotificationAccessSettings extends EmptyTextSettings {
|
||||
.setEmptyText(R.string.no_notification_listeners)
|
||||
.build();
|
||||
|
||||
private NotificationManager mNm;
|
||||
@VisibleForTesting NotificationManager mNm;
|
||||
protected Context mContext;
|
||||
private PackageManager mPm;
|
||||
@VisibleForTesting PackageManager mPm;
|
||||
private DevicePolicyManager mDpm;
|
||||
private ServiceListing mServiceListing;
|
||||
private IconDrawableFactory mIconDrawableFactory;
|
||||
@@ -99,12 +100,6 @@ public class NotificationAccessSettings extends EmptyTextSettings {
|
||||
.setNoun(CONFIG.noun)
|
||||
.setSetting(CONFIG.setting)
|
||||
.setTag(CONFIG.tag)
|
||||
.setValidator(info -> {
|
||||
if (info.getComponentName().flattenToString().length() > MAX_CN_LENGTH) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.build();
|
||||
mServiceListing.addCallback(this::updateList);
|
||||
|
||||
@@ -135,7 +130,8 @@ public class NotificationAccessSettings extends EmptyTextSettings {
|
||||
mServiceListing.setListening(false);
|
||||
}
|
||||
|
||||
private void updateList(List<ServiceInfo> services) {
|
||||
@VisibleForTesting
|
||||
void updateList(List<ServiceInfo> services) {
|
||||
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
final int managedProfileId = Utils.getManagedProfileId(um, UserHandle.myUserId());
|
||||
|
||||
@@ -148,6 +144,11 @@ public class NotificationAccessSettings extends EmptyTextSettings {
|
||||
services.sort(new PackageItemInfo.DisplayNameComparator(mPm));
|
||||
for (ServiceInfo service : services) {
|
||||
final ComponentName cn = new ComponentName(service.packageName, service.name);
|
||||
boolean isAllowed = mNm.isNotificationListenerAccessGranted(cn);
|
||||
if (!isAllowed && cn.flattenToString().length() > MAX_CN_LENGTH) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CharSequence title = null;
|
||||
try {
|
||||
title = mPm.getApplicationInfoAsUser(
|
||||
@@ -192,7 +193,7 @@ public class NotificationAccessSettings extends EmptyTextSettings {
|
||||
return true;
|
||||
});
|
||||
pref.setKey(cn.flattenToString());
|
||||
if (mNm.isNotificationListenerAccessGranted(cn)) {
|
||||
if (isAllowed) {
|
||||
allowedCategory.addPreference(pref);
|
||||
} else {
|
||||
notAllowedCategory.addPreference(pref);
|
||||
|
Reference in New Issue
Block a user