Fix text in notification settings for apps that do not send notifications am: e899b4c96c am: 7f6b3cc7ca

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/20283152

Change-Id: I3b63362fab7d5c532d231b7db82553fc9a7bde4d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Yining Liu
2022-10-28 00:23:19 +00:00
committed by Automerger Merge Worker
4 changed files with 30 additions and 0 deletions

View File

@@ -8163,6 +8163,9 @@
<!-- [CHAR LIMIT=NONE] Text appearing when channel group notifications are off -->
<string name="channel_group_notifications_off_desc">At your request, Android is blocking this group of notifications from appearing on this device</string>
<!-- [CHAR LIMIT=NONE] Text appearing when app does not send notifications -->
<string name="app_notifications_not_send_desc">This app does not send notifications</string>
<!-- [CHAR LIMIT=NONE] App notification settings: channels title -->
<string name="notification_channels">Categories</string>

View File

@@ -117,6 +117,7 @@ public class NotificationBackend {
if (app.requestedPermissions == null || Arrays.stream(app.requestedPermissions)
.noneMatch(p -> p.equals(android.Manifest.permission.POST_NOTIFICATIONS))) {
row.lockedImportance = true;
row.permissionStateLocked = true;
}
}
}
@@ -675,6 +676,9 @@ public class NotificationBackend {
public boolean systemApp;
public boolean lockedImportance;
public boolean showBadge;
// For apps target T but have not but has not requested the permission
// we cannot change the permission state
public boolean permissionStateLocked;
public int bubblePreference = NotificationManager.BUBBLE_PREFERENCE_NONE;
public int userId;
public int blockedChannelCount;

View File

@@ -62,6 +62,8 @@ public class NotificationsOffPreferenceController extends NotificationPreference
preference.setTitle(R.string.channel_notifications_off_desc);
} else if (mChannelGroup != null) {
preference.setTitle(R.string.channel_group_notifications_off_desc);
} else if (mAppRow.permissionStateLocked) {
preference.setTitle(R.string.app_notifications_not_send_desc);
} else {
preference.setTitle(R.string.app_notifications_off_desc);
}

View File

@@ -20,6 +20,7 @@ import static android.app.NotificationManager.IMPORTANCE_NONE;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -32,6 +33,7 @@ import android.os.UserManager;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.notification.NotificationBackend;
import com.google.common.collect.ImmutableList;
@@ -157,4 +159,23 @@ public class NotificationsOffPreferenceControllerTest {
assertThat(pref.getTitle().toString()).contains("app");
assertThat(pref.isSelectable()).isFalse();
}
@Test
public void testUpdateState_whenToggleDisabled() {
// Given: the app does not request to post notifications
// and it's preference toggle is disabled
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
appRow.permissionStateLocked = true;
mController.onResume(appRow, null, null, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
// When: updateState(Preference preference) is called
mController.updateState(pref);
// Then: title of pref should be app_notifications_not_send_desc
assertEquals(
RuntimeEnvironment.application.getString(R.string.app_notifications_not_send_desc),
pref.getTitle().toString());
}
}