Settings: don't try to allow NLSes with too-long component names

* NotificationAccessConfirmationActivity (triggered through CompanionDeviceManager) -> Don't show the dialog, bail out early similarly to other invalid inputs.
* NotificationAccessSettings (from Special App Access) -> No changes, but use the canonical constant now.
* ApprovalPreferenceController (used in NotificationAccessDetails) -> Disable the toggle, unless the NLS was previously approved (in which case it can still be removed).

Fixes: 260570119
Fixes: 286043036
Test: atest + manually
Change-Id: Ifc048311746c027e3683cdcf65f1079d04cf7c56
Merged-In: Ifc048311746c027e3683cdcf65f1079d04cf7c56
This commit is contained in:
Matías Hernández
2023-06-15 18:37:52 +02:00
parent 78a4048eac
commit f0367c98d0
4 changed files with 27 additions and 3 deletions

View File

@@ -77,6 +77,25 @@ public class ApprovalPreferenceControllerTest {
mController.setPkgInfo(mPkgInfo);
}
@Test
public void updateState_enabled() {
SwitchPreference pref = new SwitchPreference(mContext);
mController.updateState(pref);
assertThat(pref.isEnabled()).isTrue();
}
@Test
public void updateState_invalidCn_disabled() {
ComponentName longCn = new ComponentName("com.example.package",
com.google.common.base.Strings.repeat("Blah", 150));
mController.setCn(longCn);
SwitchPreference pref = new SwitchPreference(mContext);
mController.updateState(pref);
assertThat(pref.isEnabled()).isFalse();
}
@Test
public void updateState_checked() {
when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);