Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e899b4c9 authored by Yining Liu's avatar Yining Liu
Browse files

Fix text in notification settings for apps that do not send notifications

Added a new string to show for apps apps that target T, but do not declare the POST_NOTIFICATIONS permission in notification settings.

Bug: 229108007
Test: `croot` `make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.notification.app.NotificationsOffPreferenceControllerTest"` and manual: open Settings-Notifications-App Settings, check the text for apps that does not post notifications with toggle disabled. Text should be: "This app does not send notifications" when system language is English.
Change-Id: I9822b6f983e00c5982522099e339d86fae45aefe
parent f5a97660
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -9895,6 +9895,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>
+4 −0
Original line number Diff line number Diff line
@@ -126,6 +126,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;
            }
        }
    }
@@ -684,6 +685,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;
+2 −0
Original line number Diff line number Diff line
@@ -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);
            }
+21 −0
Original line number Diff line number Diff line
@@ -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());
    }
}