Search in sources :

Example 1 with NotificationsSentState

use of com.android.settings.notification.NotificationBackend.NotificationsSentState in project android_packages_apps_Settings by omnirom.

the class ChannelListPreferenceControllerTest method testUpdateFullList_channelUpdates.

@Test
@UiThreadTest
public void testUpdateFullList_channelUpdates() {
    List<NotificationChannelGroup> inGroups = new ArrayList<>();
    NotificationChannelGroup inGroup = new NotificationChannelGroup("group", "Group");
    NotificationChannel channelA = new NotificationChannel("channelA", "Channel A", IMPORTANCE_HIGH);
    NotificationChannel channelB = new NotificationChannel("channelB", "Channel B", IMPORTANCE_NONE);
    inGroup.addChannel(channelA);
    inGroup.addChannel(channelB);
    inGroups.add(inGroup);
    NotificationsSentState sentA = new NotificationsSentState();
    sentA.avgSentDaily = 2;
    sentA.avgSentWeekly = 10;
    NotificationsSentState sentB = new NotificationsSentState();
    sentB.avgSentDaily = 0;
    sentB.avgSentWeekly = 2;
    mAppRow.sentByChannel.put("channelA", sentA);
    // Test that the channels' properties are reflected in the preference
    mController.updateFullList(mGroupList, inGroups);
    {
        assertEquals(1, mGroupList.getPreferenceCount());
        PreferenceGroup group = (PreferenceGroup) mGroupList.getPreference(0);
        assertEquals("group", group.getKey());
        assertEquals(3, group.getPreferenceCount());
        assertNull(group.getPreference(0).getKey());
        assertEquals("All \"Group\" notifications", group.getPreference(0).getTitle());
        PrimarySwitchPreference channelAPref = (PrimarySwitchPreference) group.getPreference(1);
        assertEquals("channelA", channelAPref.getKey());
        assertEquals("Channel A", channelAPref.getTitle());
        assertEquals(Boolean.TRUE, channelAPref.getCheckedState());
        assertEquals("~2 notifications per day", channelAPref.getSummary());
        assertNotNull(channelAPref.getIcon());
        PrimarySwitchPreference channelBPref = (PrimarySwitchPreference) group.getPreference(2);
        assertEquals("channelB", channelBPref.getKey());
        assertEquals("Channel B", channelBPref.getTitle());
        assertEquals(Boolean.FALSE, channelBPref.getCheckedState());
        assertNull(channelBPref.getSummary());
        assertNull(channelBPref.getIcon());
    }
    channelA.setImportance(IMPORTANCE_NONE);
    channelB.setImportance(IMPORTANCE_DEFAULT);
    mAppRow.sentByChannel.remove("channelA");
    mAppRow.sentByChannel.put("channelB", sentB);
    // Test that changing the channels' properties correctly updates the preference
    mController.updateFullList(mGroupList, inGroups);
    {
        assertEquals(1, mGroupList.getPreferenceCount());
        PreferenceGroup group = (PreferenceGroup) mGroupList.getPreference(0);
        assertEquals("group", group.getKey());
        assertEquals(3, group.getPreferenceCount());
        assertNull(group.getPreference(0).getKey());
        assertEquals("All \"Group\" notifications", group.getPreference(0).getTitle());
        PrimarySwitchPreference channelAPref = (PrimarySwitchPreference) group.getPreference(1);
        assertEquals("channelA", channelAPref.getKey());
        assertEquals("Channel A", channelAPref.getTitle());
        assertEquals(Boolean.FALSE, channelAPref.getCheckedState());
        assertNull(channelAPref.getSummary());
        assertNull(channelAPref.getIcon());
        PrimarySwitchPreference channelBPref = (PrimarySwitchPreference) group.getPreference(2);
        assertEquals("channelB", channelBPref.getKey());
        assertEquals("Channel B", channelBPref.getTitle());
        assertEquals(Boolean.TRUE, channelBPref.getCheckedState());
        assertEquals("~2 notifications per week", channelBPref.getSummary());
        assertNotNull(channelBPref.getIcon());
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) NotificationsSentState(com.android.settings.notification.NotificationBackend.NotificationsSentState) ArrayList(java.util.ArrayList) PreferenceGroup(androidx.preference.PreferenceGroup) PrimarySwitchPreference(com.android.settings.widget.PrimarySwitchPreference) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 2 with NotificationsSentState

use of com.android.settings.notification.NotificationBackend.NotificationsSentState in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationChannelSliceTest method buildAppRow.

private AppRow buildAppRow(int channelCount, int sentCount, boolean banned) {
    final AppRow appRow = new AppRow();
    appRow.pkg = PACKAGE_NAME;
    appRow.uid = UID;
    appRow.banned = banned;
    appRow.channelCount = channelCount;
    appRow.sentByApp = new NotificationsSentState();
    appRow.sentByApp.sentCount = sentCount;
    appRow.sentByChannel = buildNotificationSentStates(channelCount, sentCount);
    return appRow;
}
Also used : AppRow(com.android.settings.notification.NotificationBackend.AppRow) NotificationsSentState(com.android.settings.notification.NotificationBackend.NotificationsSentState)

Example 3 with NotificationsSentState

use of com.android.settings.notification.NotificationBackend.NotificationsSentState in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationChannelSliceTest method buildNotificationSentStates.

private Map<String, NotificationsSentState> buildNotificationSentStates(int channelCount, int sentCount) {
    final Map<String, NotificationBackend.NotificationsSentState> states = new ArrayMap<>();
    for (int i = 0; i < channelCount; i++) {
        final NotificationsSentState state = new NotificationsSentState();
        // Set the avgSentWeekly for each channel: channel0 is 1, channel1: 2, channel2: 3.
        state.avgSentWeekly = i + 1;
        state.sentCount = sentCount;
        states.put(CHANNEL_NAME_PREFIX + i, state);
    }
    return states;
}
Also used : NotificationsSentState(com.android.settings.notification.NotificationBackend.NotificationsSentState) ArrayMap(android.util.ArrayMap)

Example 4 with NotificationsSentState

use of com.android.settings.notification.NotificationBackend.NotificationsSentState in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationChannelSlice method getDisplayableChannels.

private List<NotificationChannel> getDisplayableChannels(NotificationBackend.AppRow appRow) {
    final List<NotificationChannelGroup> channelGroupList = mNotificationBackend.getGroups(appRow.pkg, appRow.uid).getList();
    final List<NotificationChannel> channels = channelGroupList.stream().flatMap(group -> group.getChannels().stream().filter(channel -> isChannelEnabled(group, channel, appRow))).collect(Collectors.toList());
    // Pack the notification channel with notification sent state for sorting.
    final List<NotificationChannelState> channelStates = new ArrayList<>();
    for (NotificationChannel channel : channels) {
        NotificationsSentState sentState = appRow.sentByChannel.get(channel.getId());
        if (sentState == null) {
            sentState = new NotificationsSentState();
        }
        channelStates.add(new NotificationChannelState(sentState, channel));
    }
    // Sort the notification channels with notification sent count by descending.
    return channelStates.stream().sorted(CHANNEL_STATE_COMPARATOR).map(state -> state.getNotificationChannel()).limit(DEFAULT_EXPANDED_ROW_COUNT).collect(Collectors.toList());
}
Also used : NotificationChannel(android.app.NotificationChannel) Bundle(android.os.Bundle) EXTRA_TOGGLE_STATE(android.app.slice.Slice.EXTRA_TOGGLE_STATE) PackageManager(android.content.pm.PackageManager) ListBuilder(androidx.slice.builders.ListBuilder) Uri(android.net.Uri) TimeoutException(java.util.concurrent.TimeoutException) PendingIntent(android.app.PendingIntent) Drawable(android.graphics.drawable.Drawable) SubSettings(com.android.settings.SubSettings) Future(java.util.concurrent.Future) NotificationChannel(android.app.NotificationChannel) Log(android.util.Log) R(com.android.settings.R) SliceAction(androidx.slice.builders.SliceAction) Collectors(java.util.stream.Collectors) CustomSliceable(com.android.settings.slices.CustomSliceable) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) List(java.util.List) Application(android.app.Application) Utils(com.android.settings.Utils) RestrictedLockUtilsInternal(com.android.settingslib.RestrictedLockUtilsInternal) NotificationBackend(com.android.settings.notification.NotificationBackend) AppNotificationSettings(com.android.settings.notification.AppNotificationSettings) IMPORTANCE_NONE(android.app.NotificationManager.IMPORTANCE_NONE) Context(android.content.Context) Slice(androidx.slice.Slice) Intent(android.content.Intent) NotificationsSentState(com.android.settings.notification.NotificationBackend.NotificationsSentState) PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) AppInfoBase(com.android.settings.applications.AppInfoBase) IMPORTANCE_LOW(android.app.NotificationManager.IMPORTANCE_LOW) ChannelNotificationSettings(com.android.settings.notification.ChannelNotificationSettings) AppAndNotificationDashboardFragment(com.android.settings.applications.AppAndNotificationDashboardFragment) UserHandle(android.os.UserHandle) SliceBroadcastReceiver(com.android.settings.slices.SliceBroadcastReceiver) Settings(android.provider.Settings) SliceBuilderUtils(com.android.settings.slices.SliceBuilderUtils) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) RestrictedLockUtils(com.android.settingslib.RestrictedLockUtils) SettingsEnums(android.app.settings.SettingsEnums) TextUtils(android.text.TextUtils) NotificationChannelGroup(android.app.NotificationChannelGroup) ApplicationsState(com.android.settingslib.applications.ApplicationsState) ThreadUtils(com.android.settingslib.utils.ThreadUtils) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) IconCompat(androidx.core.graphics.drawable.IconCompat) CustomSliceRegistry(com.android.settings.slices.CustomSliceRegistry) Comparator(java.util.Comparator) NotificationChannelGroup(android.app.NotificationChannelGroup) NotificationsSentState(com.android.settings.notification.NotificationBackend.NotificationsSentState) ArrayList(java.util.ArrayList)

Aggregations

NotificationsSentState (com.android.settings.notification.NotificationBackend.NotificationsSentState)4 NotificationChannel (android.app.NotificationChannel)2 NotificationChannelGroup (android.app.NotificationChannelGroup)2 ArrayList (java.util.ArrayList)2 Application (android.app.Application)1 IMPORTANCE_LOW (android.app.NotificationManager.IMPORTANCE_LOW)1 IMPORTANCE_NONE (android.app.NotificationManager.IMPORTANCE_NONE)1 PendingIntent (android.app.PendingIntent)1 SettingsEnums (android.app.settings.SettingsEnums)1 EXTRA_TOGGLE_STATE (android.app.slice.Slice.EXTRA_TOGGLE_STATE)1 Context (android.content.Context)1 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 UserHandle (android.os.UserHandle)1 Settings (android.provider.Settings)1 TextUtils (android.text.TextUtils)1