Disable app toggle for some T+ apps

Specifically, apps that haven't requested the notif permission
in their manifest, as we cannot grant/revoke the permission unless
they do

Test: NotificationBackendTest, AppStateNotificationBridgeTest
Fixes: 218315122

Change-Id: Icd936de806d7642809ef6c79d2d169bd673c2659
This commit is contained in:
Julia Reynolds
2022-02-22 11:08:08 -05:00
parent 1d15b24da2
commit f56aa26b2e
4 changed files with 75 additions and 25 deletions

View File

@@ -99,7 +99,7 @@ public class AppStateNotificationBridgeTest {
when(mState.newSession(any())).thenReturn(mSession);
when(mState.getBackgroundLooper()).thenReturn(mock(Looper.class));
when(mBackend.getNotificationsBanned(anyString(), anyInt())).thenReturn(true);
when(mBackend.isSystemApp(any(), any())).thenReturn(true);
when(mBackend.enableSwitch(any(), any())).thenReturn(true);
// most tests assume no work profile
when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
mContext = RuntimeEnvironment.application.getApplicationContext();
@@ -245,7 +245,6 @@ public class AppStateNotificationBridgeTest {
assertThat(((NotificationsSentState) apps.get(0).extraInfo).avgSentDaily).isEqualTo(1);
assertThat(((NotificationsSentState) apps.get(0).extraInfo).avgSentWeekly).isEqualTo(0);
assertThat(((NotificationsSentState) apps.get(0).extraInfo).blocked).isTrue();
assertThat(((NotificationsSentState) apps.get(0).extraInfo).systemApp).isTrue();
assertThat(((NotificationsSentState) apps.get(0).extraInfo).blockable).isTrue();
}
@@ -376,7 +375,6 @@ public class AppStateNotificationBridgeTest {
assertThat(((NotificationsSentState) entry.extraInfo).avgSentDaily).isEqualTo(2);
assertThat(((NotificationsSentState) entry.extraInfo).avgSentWeekly).isEqualTo(0);
assertThat(((NotificationsSentState) entry.extraInfo).blocked).isTrue();
assertThat(((NotificationsSentState) entry.extraInfo).systemApp).isTrue();
assertThat(((NotificationsSentState) entry.extraInfo).blockable).isTrue();
}
@@ -563,11 +561,11 @@ public class AppStateNotificationBridgeTest {
entry.extraInfo = new NotificationsSentState();
CompoundButton.OnCheckedChangeListener listener = mBridge.getSwitchOnCheckedListener(entry);
listener.onCheckedChanged(toggle, true);
listener.onCheckedChanged(toggle, false);
verify(mBackend).setNotificationsEnabledForPackage(
entry.info.packageName, entry.info.uid, true);
assertThat(((NotificationsSentState) entry.extraInfo).blocked).isFalse();
entry.info.packageName, entry.info.uid, false);
assertThat(((NotificationsSentState) entry.extraInfo).blocked).isTrue();
}
@Test

View File

@@ -37,7 +37,9 @@ import android.content.ComponentName;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.net.MacAddress;
import android.os.Build;
import android.os.Parcel;
import android.provider.Settings;
@@ -177,6 +179,51 @@ public class NotificationBackendTest {
assertFalse(appRow.lockedImportance);
}
@Test
public void testMarkAppRow_targetsT_noPermissionRequest() throws Exception {
Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(),
Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM);
PackageInfo pi = new PackageInfo();
pi.packageName = "test";
pi.applicationInfo = new ApplicationInfo();
pi.applicationInfo.packageName = "test";
pi.applicationInfo.uid = 123;
pi.applicationInfo.targetSdkVersion= Build.VERSION_CODES.TIRAMISU;
pi.requestedPermissions = new String[] {"something"};
when(mInm.isPermissionFixed(pi.packageName, 0)).thenReturn(false);
AppRow appRow = new NotificationBackend().loadAppRow(RuntimeEnvironment.application,
mock(PackageManager.class), mock(RoleManager.class), pi);
assertFalse(appRow.systemApp);
assertTrue(appRow.lockedImportance);
}
@Test
public void testMarkAppRow_targetsT_permissionRequest() throws Exception {
Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(),
Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM);
PackageInfo pi = new PackageInfo();
pi.packageName = "test";
pi.applicationInfo = new ApplicationInfo();
pi.applicationInfo.packageName = "test";
pi.applicationInfo.uid = 123;
pi.applicationInfo.targetSdkVersion= Build.VERSION_CODES.TIRAMISU;
pi.requestedPermissions = new String[] {"something",
android.Manifest.permission.POST_NOTIFICATIONS};
when(mInm.isPermissionFixed(pi.packageName, 0)).thenReturn(false);
AppRow appRow = new NotificationBackend().loadAppRow(RuntimeEnvironment.application,
mock(PackageManager.class), mock(RoleManager.class), pi);
assertFalse(appRow.systemApp);
assertFalse(appRow.lockedImportance);
}
@Test
public void testMarkAppRow_notDefaultPackage() {
PackageInfo pi = new PackageInfo();