Merge "Add filtering to notification channel settings" into sc-dev

This commit is contained in:
Julia Reynolds
2021-02-17 14:12:04 +00:00
committed by Android (Google) Code Review
66 changed files with 1067 additions and 333 deletions

View File

@@ -22,7 +22,9 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationChannel;
import android.content.Context;
import android.content.pm.ShortcutInfo;
@@ -30,6 +32,8 @@ import androidx.preference.Preference;
import com.android.settings.notification.NotificationBackend;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -38,12 +42,16 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class AddToHomeScreenPreferenceControllerTest {
private Context mContext;
@Mock
private NotificationBackend mBackend;
@Mock
private NotificationChannel mNc;
private AddToHomeScreenPreferenceController mController;
@@ -52,6 +60,7 @@ public class AddToHomeScreenPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new AddToHomeScreenPreferenceController(mContext, mBackend);
when(mNc.getImportance()).thenReturn(4);
}
@Test
@@ -62,21 +71,41 @@ public class AddToHomeScreenPreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null, null, null);
mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable() {
ShortcutInfo si = mock(ShortcutInfo.class);
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, si, null);
mController.onResume(mock(NotificationBackend.AppRow.class),
mNc, null, null, si, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
ShortcutInfo si = mock(ShortcutInfo.class);
mController.onResume(mock(NotificationBackend.AppRow.class),
mNc, null, null, si, null,
ImmutableList.of(NotificationChannel.EDIT_LAUNCHER));
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
ShortcutInfo si = mock(ShortcutInfo.class);
mController.onResume(mock(NotificationBackend.AppRow.class),
mNc, null, null, si, null, new ArrayList<>());
assertFalse(mController.isAvailable());
}
@Test
public void testHandlePreferenceTreeClick() {
ShortcutInfo si = mock(ShortcutInfo.class);
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, si, null);
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, si, null,
null);
Preference pref = new Preference(RuntimeEnvironment.application);
pref.setKey("add_to_home");

View File

@@ -44,6 +44,8 @@ import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -54,6 +56,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class AllowSoundPreferenceControllerTest {
@@ -92,10 +96,11 @@ public class AllowSoundPreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, mock(NotificationChannel.class), null, null, null, null);
mController.onResume(null, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, null, null);
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, null, null,
null);
assertFalse(mController.isAvailable());
}
@@ -103,7 +108,7 @@ public class AllowSoundPreferenceControllerTest {
public void testIsAvailable_notIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -112,7 +117,7 @@ public class AllowSoundPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something new");
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -122,16 +127,37 @@ public class AllowSoundPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null, null, null, ImmutableList.of(
NotificationChannel.EDIT_SOUND));
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
assertFalse(mController.isAvailable());
}
@Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -145,7 +171,7 @@ public class AllowSoundPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("");
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -158,7 +184,7 @@ public class AllowSoundPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -170,7 +196,8 @@ public class AllowSoundPreferenceControllerTest {
public void testUpdateState_checkedForHighImportanceChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -181,7 +208,8 @@ public class AllowSoundPreferenceControllerTest {
public void testUpdateState_checkedForUnspecifiedImportanceChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_UNSPECIFIED);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -192,7 +220,8 @@ public class AllowSoundPreferenceControllerTest {
public void testUpdateState_notCheckedForLowImportanceChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -203,7 +232,8 @@ public class AllowSoundPreferenceControllerTest {
public void testOnPreferenceChange_on() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -220,7 +250,8 @@ public class AllowSoundPreferenceControllerTest {
public void testOnPreferenceChange_off() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);

View File

@@ -104,7 +104,7 @@ public class AppBubbleListPreferenceControllerTest {
public void isAvailable_BUBBLE_PREFERENCE_NONE_false() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertThat(mController.isAvailable()).isFalse();
}
@@ -113,7 +113,7 @@ public class AppBubbleListPreferenceControllerTest {
public void isAvailable_BUBBLE_PREFERENCE_SELECTED_true() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertThat(mController.isAvailable()).isTrue();
}
@@ -122,7 +122,7 @@ public class AppBubbleListPreferenceControllerTest {
public void isAvailable_BUBBLE_PREFERENCE_ALL_true() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertThat(mController.isAvailable()).isTrue();
}
@@ -131,7 +131,7 @@ public class AppBubbleListPreferenceControllerTest {
public void filterAndSortConversations_BUBBLE_PREFERENCE_SELECTED_filtersAllowedBubbles() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
List<ConversationChannelWrapper> result =
mController.filterAndSortConversations(mConvoList.getList());
@@ -144,7 +144,7 @@ public class AppBubbleListPreferenceControllerTest {
public void filterAndSortConversations_BUBBLE_PREFERENCE_ALL_filtersExcludedBubbles() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
List<ConversationChannelWrapper> result =
mController.filterAndSortConversations(mConvoList.getList());
@@ -158,7 +158,7 @@ public class AppBubbleListPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
appRow.pkg = "PKG";
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
mController.mPreference = new PreferenceCategory(mContext);
ConversationChannelWrapper ccw = mConvoList.getList().get(0);

View File

@@ -75,7 +75,7 @@ public class AppLinkPreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null, null, null);
mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -83,7 +83,7 @@ public class AppLinkPreferenceControllerTest {
public void testIsAvailable_notIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -92,7 +92,7 @@ public class AppLinkPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -102,7 +102,7 @@ public class AppLinkPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -113,16 +113,21 @@ public class AppLinkPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_alwaysFiltered() {
assertFalse(mController.isIncludedInFilter());
}
@Test
public void testUpdateState() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
Intent intent = new Intent("action");
appRow.settingsIntent = intent;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);

View File

@@ -47,6 +47,8 @@ import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -57,6 +59,9 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
public class BadgePreferenceControllerTest {
@@ -93,7 +98,7 @@ public class BadgePreferenceControllerTest {
public void testIsAvailable_notIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -102,7 +107,7 @@ public class BadgePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -112,7 +117,7 @@ public class BadgePreferenceControllerTest {
appRow.showBadge = false;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -122,7 +127,7 @@ public class BadgePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 0);
assertFalse(mController.isAvailable());
@@ -131,7 +136,7 @@ public class BadgePreferenceControllerTest {
@Test
public void testIsAvailable_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
assertTrue(mController.isAvailable());
@@ -144,7 +149,7 @@ public class BadgePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
assertTrue(mController.isAvailable());
@@ -156,7 +161,7 @@ public class BadgePreferenceControllerTest {
appRow.showBadge = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
assertTrue(mController.isAvailable());
@@ -168,18 +173,43 @@ public class BadgePreferenceControllerTest {
appRow.showBadge = false;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.showBadge = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.showBadge = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null,
ImmutableList.of(NotificationChannel.EDIT_LAUNCHER));
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
assertTrue(mController.isAvailable());
}
@Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null,
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -193,7 +223,7 @@ public class BadgePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("");
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -206,7 +236,7 @@ public class BadgePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.canShowBadge()).thenReturn(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -214,7 +244,7 @@ public class BadgePreferenceControllerTest {
assertTrue(pref.isChecked());
when(channel.canShowBadge()).thenReturn(false);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(pref);
assertFalse(pref.isChecked());
@@ -224,14 +254,14 @@ public class BadgePreferenceControllerTest {
public void testUpdateState_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.showBadge = true;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
assertTrue(pref.isChecked());
appRow.showBadge = false;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
mController.updateState(pref);
assertFalse(pref.isChecked());
@@ -244,7 +274,7 @@ public class BadgePreferenceControllerTest {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
channel.setShowBadge(false);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -263,7 +293,7 @@ public class BadgePreferenceControllerTest {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
channel.setShowBadge(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -279,7 +309,7 @@ public class BadgePreferenceControllerTest {
public void testOnPreferenceChange_on_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.showBadge = false;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -296,7 +326,7 @@ public class BadgePreferenceControllerTest {
public void testOnPreferenceChange_off_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.showBadge = true;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);

View File

@@ -59,6 +59,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class BlockPreferenceControllerTest {
@@ -102,7 +104,7 @@ public class BlockPreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null, null, null);
mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -112,7 +114,7 @@ public class BlockPreferenceControllerTest {
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -122,7 +124,7 @@ public class BlockPreferenceControllerTest {
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -132,7 +134,7 @@ public class BlockPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -140,7 +142,8 @@ public class BlockPreferenceControllerTest {
public void testIsAvailable_GroupNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null);
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null,
null);
assertTrue(mController.isAvailable());
}
@@ -148,7 +151,7 @@ public class BlockPreferenceControllerTest {
public void testIsAvailable_AppNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -158,17 +161,41 @@ public class BlockPreferenceControllerTest {
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_nonSystemApp() {
public void testIsAvailable_nonSystemApp_noFilter() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = false;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = false;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
ArrayList<String> filter = new ArrayList<>();
filter.add("no");
mController.onResume(appRow, channel, null, null, null, null, filter);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = false;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
ArrayList<String> filter = new ArrayList<>();
filter.add(NotificationChannel.EDIT_IMPORTANCE);
mController.onResume(appRow, channel, null, null, null, null, filter);
assertTrue(mController.isAvailable());
}
@@ -177,7 +204,7 @@ public class BlockPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedImportance = true;
appRow.systemApp = true;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mPreference.getSwitchBar().isEnabled());
}
@@ -186,7 +213,8 @@ public class BlockPreferenceControllerTest {
public void testIsEnabled_GroupNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null);
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null,
null);
mController.updateState(mPreference);
assertFalse(mPreference.getSwitchBar().isEnabled());
}
@@ -195,7 +223,7 @@ public class BlockPreferenceControllerTest {
public void testIsEnabled_systemAppNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mPreference.getSwitchBar().isEnabled());
}
@@ -206,7 +234,7 @@ public class BlockPreferenceControllerTest {
appRow.systemApp = true;
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setBlockable(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
assertTrue(mPreference.getSwitchBar().isEnabled());
}
@@ -217,7 +245,7 @@ public class BlockPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
@@ -230,7 +258,7 @@ public class BlockPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
@@ -242,7 +270,7 @@ public class BlockPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
@@ -252,7 +280,7 @@ public class BlockPreferenceControllerTest {
@Test
public void testIsEnabled_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
mController.updateState(mPreference);
@@ -263,13 +291,13 @@ public class BlockPreferenceControllerTest {
public void testUpdateState_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mPreference.isChecked());
appRow.banned = false;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
mController.updateState(mPreference);
assertTrue(mPreference.isChecked());
@@ -280,20 +308,20 @@ public class BlockPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
mController.onResume(appRow, null, group, null, null, null);
mController.onResume(appRow, null, group, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mPreference.isChecked());
appRow.banned = true;
mController.onResume(appRow, null, group, null, null, null);
mController.onResume(appRow, null, group, null, null, null, null);
when(group.isBlocked()).thenReturn(true);
mController.updateState(mPreference);
assertFalse(mPreference.isChecked());
appRow.banned = false;
mController.onResume(appRow, null, group, null, null, null);
mController.onResume(appRow, null, group, null, null, null, null);
when(group.isBlocked()).thenReturn(false);
mController.updateState(mPreference);
@@ -304,21 +332,21 @@ public class BlockPreferenceControllerTest {
public void testUpdateState_channelBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mPreference.isChecked());
appRow.banned = true;
channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mPreference.isChecked());
appRow.banned = false;
channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
assertTrue(mPreference.isChecked());
@@ -328,7 +356,7 @@ public class BlockPreferenceControllerTest {
public void testUpdateState_noCrashIfCalledTwice() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
mController.updateState(mPreference);
}
@@ -337,7 +365,7 @@ public class BlockPreferenceControllerTest {
public void testUpdateState_doesNotResetImportance() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
assertEquals(IMPORTANCE_LOW, channel.getImportance());
@@ -350,7 +378,7 @@ public class BlockPreferenceControllerTest {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_UNSPECIFIED);
when(mBackend.onlyHasDefaultChannel(anyString(), anyInt())).thenReturn(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
mController.onSwitchChanged(null, false);
@@ -372,7 +400,7 @@ public class BlockPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
channel.setOriginalImportance(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
mController.onSwitchChanged(null, false);

View File

@@ -60,6 +60,8 @@ import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -125,7 +127,7 @@ public class BubblePreferenceControllerTest {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -135,7 +137,7 @@ public class BubblePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -146,7 +148,7 @@ public class BubblePreferenceControllerTest {
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -154,7 +156,7 @@ public class BubblePreferenceControllerTest {
@Test
public void isNotAvailable_ifOffGlobally_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
@@ -164,7 +166,7 @@ public class BubblePreferenceControllerTest {
@Test
public void isNotAvailable_ifLowRam() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
final ShadowActivityManager activityManager =
Shadow.extract(mContext.getSystemService(ActivityManager.class));
@@ -178,7 +180,7 @@ public class BubblePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
@@ -188,7 +190,7 @@ public class BubblePreferenceControllerTest {
@Test
public void isAvailable_ifNotLowRam() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
final ShadowActivityManager activityManager =
@@ -200,7 +202,7 @@ public class BubblePreferenceControllerTest {
@Test
public void isAvailable_app_evenIfOffGlobally() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mAppPageController.onResume(appRow, null, null, null, null, null);
mAppPageController.onResume(appRow, null, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
@@ -210,7 +212,7 @@ public class BubblePreferenceControllerTest {
@Test
public void isAvailable_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertTrue(mController.isAvailable());
@@ -223,7 +225,7 @@ public class BubblePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertTrue(mController.isAvailable());
@@ -235,18 +237,43 @@ public class BubblePreferenceControllerTest {
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertTrue(mController.isAvailable());
}
@Test
public void isAvailable_filteredIn() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null,
ImmutableList.of(NotificationChannel.EDIT_CONVERSATION));
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertTrue(mController.isAvailable());
}
@Test
public void isAvailable_filteredOut() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertFalse(mController.isAvailable());
}
@Test
public void updateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null,
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -261,7 +288,7 @@ public class BubblePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "a";
mAppPageController.onResume(appRow, channel, null,
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class), null);
BubblePreference pref = new BubblePreference(mContext);
mAppPageController.updateState(pref);
@@ -276,7 +303,7 @@ public class BubblePreferenceControllerTest {
appRow.pkg = "a";
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -291,7 +318,7 @@ public class BubblePreferenceControllerTest {
appRow.pkg = "a";
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.canBubble()).thenReturn(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -299,7 +326,7 @@ public class BubblePreferenceControllerTest {
assertTrue(pref.isChecked());
when(channel.canBubble()).thenReturn(false);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(pref);
assertFalse(pref.isChecked());
@@ -312,20 +339,20 @@ public class BubblePreferenceControllerTest {
appRow.pkg = "a";
appRow.label = "App!";
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
mAppPageController.onResume(appRow, null, null, null, null, null);
mAppPageController.onResume(appRow, null, null, null, null, null, null);
BubblePreference pref = new BubblePreference(mContext);
mAppPageController.updateState(pref);
assertEquals(BUBBLE_PREFERENCE_ALL, pref.getSelectedPreference());
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
mAppPageController.onResume(appRow, null, null, null, null, null);
mAppPageController.onResume(appRow, null, null, null, null, null, null);
mAppPageController.updateState(pref);
assertEquals(BUBBLE_PREFERENCE_NONE, pref.getSelectedPreference());
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
mAppPageController.onResume(appRow, null, null, null, null, null);
mAppPageController.onResume(appRow, null, null, null, null, null, null);
mAppPageController.updateState(pref);
assertEquals(BUBBLE_PREFERENCE_SELECTED, pref.getSelectedPreference());
@@ -339,7 +366,7 @@ public class BubblePreferenceControllerTest {
appRow.pkg = "a";
appRow.label = "App!";
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
mAppPageController.onResume(appRow, null, null, null, null, null);
mAppPageController.onResume(appRow, null, null, null, null, null, null);
BubblePreference pref = new BubblePreference(mContext);
mAppPageController.updateState(pref);
@@ -354,7 +381,7 @@ public class BubblePreferenceControllerTest {
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -374,7 +401,7 @@ public class BubblePreferenceControllerTest {
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -393,7 +420,7 @@ public class BubblePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "a";
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
mAppPageController.onResume(appRow, null, null, null, null, null);
mAppPageController.onResume(appRow, null, null, null, null, null, null);
BubblePreference pref = new BubblePreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -413,7 +440,7 @@ public class BubblePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "a";
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
mAppPageController.onResume(appRow, null, null, null, null, null);
mAppPageController.onResume(appRow, null, null, null, null, null, null);
BubblePreference pref = new BubblePreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -433,7 +460,7 @@ public class BubblePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "a";
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
mAppPageController.onResume(appRow, null, null, null, null, null);
mAppPageController.onResume(appRow, null, null, null, null, null, null);
BubblePreference pref = new BubblePreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -452,7 +479,7 @@ public class BubblePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "a";
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
mAppPageController.onResume(appRow, null, null, null, null, null);
mAppPageController.onResume(appRow, null, null, null, null, null, null);
BubblePreference pref = new BubblePreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -471,7 +498,7 @@ public class BubblePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "a";
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
mAppPageController.onResume(appRow, null, null, null, null, null);
mAppPageController.onResume(appRow, null, null, null, null, null, null);
BubblePreference pref = new BubblePreference(mContext);
mAppPageController.onPreferenceChange(pref, BUBBLE_PREFERENCE_NONE);

View File

@@ -23,8 +23,6 @@ import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.android.settings.notification.app.BubblePreferenceController.SYSTEM_WIDE_OFF;
import static com.android.settings.notification.app.BubblePreferenceController.SYSTEM_WIDE_ON;
@@ -92,14 +90,14 @@ public class BubbleSummaryPreferenceControllerTest {
public void isAvailable_appBlocked_shouldReturnFalse() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_NOTIFICATION_BUBBLESisOn_shouldReturnTrue() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
mController.onResume(mAppRow, null, null, null, null, null);
mController.onResume(mAppRow, null, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -107,7 +105,7 @@ public class BubbleSummaryPreferenceControllerTest {
@Test
public void isAvailable_NOTIFICATION_BUBBLESisOn_neverSentMsg_shouldReturnFalse() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
mController.onResume(mAppRow, null, null, null, null, null);
mController.onResume(mAppRow, null, null, null, null, null, null);
when(mBackend.hasSentValidMsg(anyString(), anyInt())).thenReturn(false);
assertFalse(mController.isAvailable());
@@ -117,7 +115,7 @@ public class BubbleSummaryPreferenceControllerTest {
public void isAvailable_NOTIFICATION_BUBBLESisOff_shouldReturnFalse() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
SYSTEM_WIDE_OFF);
mController.onResume(mAppRow, null, null, null, null, null);
mController.onResume(mAppRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -128,7 +126,7 @@ public class BubbleSummaryPreferenceControllerTest {
SYSTEM_WIDE_OFF);
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(mAppRow, channel, null, null, null, null);
mController.onResume(mAppRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -139,7 +137,7 @@ public class BubbleSummaryPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(mAppRow, channel, null, null, null, null);
mController.onResume(mAppRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -147,7 +145,7 @@ public class BubbleSummaryPreferenceControllerTest {
@Test
public void isAvailable_lowRam_shouldReturnFalse() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
mController.onResume(mAppRow, null, null, null, null, null);
mController.onResume(mAppRow, null, null, null, null, null, null);
final ShadowActivityManager activityManager =
Shadow.extract(mContext.getSystemService(ActivityManager.class));
@@ -158,7 +156,7 @@ public class BubbleSummaryPreferenceControllerTest {
@Test
public void isAvailable_notLowRam_shouldReturnTrue() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
mController.onResume(mAppRow, null, null, null, null, null);
mController.onResume(mAppRow, null, null, null, null, null, null);
final ShadowActivityManager activityManager =
Shadow.extract(mContext.getSystemService(ActivityManager.class));
@@ -169,7 +167,7 @@ public class BubbleSummaryPreferenceControllerTest {
@Test
public void updateState_setsIntent() {
mAppRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
mController.onResume(mAppRow, null, null, null, null, null);
mController.onResume(mAppRow, null, null, null, null, null, null);
Preference pref = new Preference(mContext);
mController.updateState(pref);
@@ -182,7 +180,7 @@ public class BubbleSummaryPreferenceControllerTest {
SYSTEM_WIDE_OFF);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
String noneString = mContext.getString(R.string.bubble_app_setting_none);
assertEquals(noneString, mController.getSummary());
@@ -195,7 +193,7 @@ public class BubbleSummaryPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
String noneString = mContext.getString(R.string.bubble_app_setting_none);
assertEquals(noneString, mController.getSummary());
@@ -208,7 +206,7 @@ public class BubbleSummaryPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
String allString = mContext.getString(R.string.bubble_app_setting_all);
assertEquals(allString, mController.getSummary());
@@ -221,7 +219,7 @@ public class BubbleSummaryPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
String selectedString = mContext.getString(R.string.bubble_app_setting_selected);
assertEquals(selectedString, mController.getSummary());

View File

@@ -36,6 +36,8 @@ import androidx.preference.Preference;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.notification.NotificationBackend;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -46,6 +48,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class ConversationDemotePreferenceControllerTest {
@@ -79,7 +83,7 @@ public class ConversationDemotePreferenceControllerTest {
public void testIsAvailable_notConversation() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -89,7 +93,7 @@ public class ConversationDemotePreferenceControllerTest {
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -99,17 +103,38 @@ public class ConversationDemotePreferenceControllerTest {
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(false);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(false);
mController.onResume(appRow, channel, null, null, null, null,
ImmutableList.of(NotificationChannel.EDIT_CONVERSATION));
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(false);
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
assertFalse(mController.isAvailable());
}
@Test
public void testHandlePreferenceClick() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(false);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = mock(Preference.class);
when(pref.getKey()).thenReturn("demote");

View File

@@ -49,6 +49,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class ConversationHeaderPreferenceControllerTest {
@@ -88,7 +90,7 @@ public class ConversationHeaderPreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null, null, null);
mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -96,7 +98,15 @@ public class ConversationHeaderPreferenceControllerTest {
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_ignoresFilter() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null, null, null, new ArrayList<>());
assertTrue(mController.isAvailable());
}
@@ -105,11 +115,11 @@ public class ConversationHeaderPreferenceControllerTest {
ShortcutInfo si = mock(ShortcutInfo.class);
when(si.getLabel()).thenReturn("hello");
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, si, null);
mController.onResume(appRow, null, null, null, si, null, null);
assertEquals(si.getLabel(), mController.getLabel());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertEquals(channel.getName(), mController.getLabel());
}
@@ -117,25 +127,25 @@ public class ConversationHeaderPreferenceControllerTest {
public void testGetSummary() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.label = "bananas";
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertEquals("", mController.getSummary());
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
mController.onResume(appRow, null, group, null, null, null);
mController.onResume(appRow, null, group, null, null, null, null);
assertEquals(appRow.label, mController.getSummary());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
mController.onResume(appRow, channel, group, null, null, null);
mController.onResume(appRow, channel, group, null, null, null, null);
assertTrue(mController.getSummary().toString().contains(group.getName()));
assertTrue(mController.getSummary().toString().contains(appRow.label));
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.getSummary().toString().contains(group.getName()));
assertTrue(mController.getSummary().toString().contains(appRow.label));
NotificationChannel defaultChannel = new NotificationChannel(
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
mController.onResume(appRow, defaultChannel, null, null, null, null);
mController.onResume(appRow, defaultChannel, null, null, null, null, null);
assertEquals("", mController.getSummary());
}
}

View File

@@ -34,7 +34,6 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
@@ -47,6 +46,8 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -57,6 +58,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class ConversationPriorityPreferenceControllerTest {
@@ -95,7 +98,7 @@ public class ConversationPriorityPreferenceControllerTest {
@Test
public void testIsAvailable_notChannelNull() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -103,16 +106,37 @@ public class ConversationPriorityPreferenceControllerTest {
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null,
ImmutableList.of(NotificationChannel.EDIT_IMPORTANCE));
assertTrue(mController.isAvailable());
mController.onResume(appRow, channel, null, null, null, null,
ImmutableList.of(NotificationChannel.EDIT_CONVERSATION));
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
assertFalse(mController.isAvailable());
}
@Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new ConversationPriorityPreference(mContext, null);
mController.updateState(pref);
@@ -126,7 +150,7 @@ public class ConversationPriorityPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new ConversationPriorityPreference(mContext, null);
mController.updateState(pref);
@@ -141,7 +165,7 @@ public class ConversationPriorityPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new ConversationPriorityPreference(mContext, null);
mController.updateState(pref);
@@ -156,7 +180,7 @@ public class ConversationPriorityPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new ConversationPriorityPreference(mContext, null);
mController.updateState(pref);
@@ -170,7 +194,7 @@ public class ConversationPriorityPreferenceControllerTest {
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
channel.setImportantConversation(true);
channel.setOriginalImportance(IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
ConversationPriorityPreference pref = mock(ConversationPriorityPreference.class);
mController.updateState(pref);
@@ -185,7 +209,8 @@ public class ConversationPriorityPreferenceControllerTest {
public void testImportanceLowToImportant() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -203,7 +228,8 @@ public class ConversationPriorityPreferenceControllerTest {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
channel.setAllowBubbles(false);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -222,7 +248,8 @@ public class ConversationPriorityPreferenceControllerTest {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
channel.setAllowBubbles(false);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -241,7 +268,8 @@ public class ConversationPriorityPreferenceControllerTest {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
channel.setAllowBubbles(true);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -261,7 +289,8 @@ public class ConversationPriorityPreferenceControllerTest {
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
channel.setAllowBubbles(true);
channel.setImportantConversation(true);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);

View File

@@ -38,6 +38,8 @@ import androidx.preference.Preference;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.notification.NotificationBackend;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -48,6 +50,9 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.sql.Array;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class ConversationPromotePreferenceControllerTest {
@@ -81,7 +86,7 @@ public class ConversationPromotePreferenceControllerTest {
public void testIsAvailable_notConversation() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -90,7 +95,7 @@ public class ConversationPromotePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -100,10 +105,31 @@ public class ConversationPromotePreferenceControllerTest {
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(true);
mController.onResume(appRow, channel, null, null, null, null,
ImmutableList.of(NotificationChannel.EDIT_CONVERSATION));
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(true);
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
assertFalse(mController.isAvailable());
}
@Test
public void testHandlePreferenceClick() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
@@ -111,7 +137,7 @@ public class ConversationPromotePreferenceControllerTest {
channel.setConversationId("a", "a");
channel.setDemoted(true);
channel.setBypassDnd(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = mock(Preference.class);
when(pref.getKey()).thenReturn("convo_promote");
@@ -133,7 +159,7 @@ public class ConversationPromotePreferenceControllerTest {
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = mock(Preference.class);
when(pref.getKey()).thenReturn("wrong");

View File

@@ -46,6 +46,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class DeletedChannelsPreferenceControllerTest {
@@ -79,14 +81,15 @@ public class DeletedChannelsPreferenceControllerTest {
public void isAvailable_appScreen_notIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_groupScreen_never() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null);
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null,
null);
assertFalse(mController.isAvailable());
}
@@ -94,28 +97,29 @@ public class DeletedChannelsPreferenceControllerTest {
public void isAvailable_channelScreen_never() {
mController.onResume(
new NotificationBackend.AppRow(), mock(NotificationChannel.class), null, null, null,
null);
null, null);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_appScreen_notIfNoDeletedChannels() {
when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(0);
mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_appScreen() {
when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(1);
mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null);
mController.onResume(
new NotificationBackend.AppRow(), null, null, null, null, null, new ArrayList<>());
assertTrue(mController.isAvailable());
}
@Test
public void updateState() {
when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(1);
mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null, null);
Preference pref = mock(Preference.class);
mController.updateState(pref);

View File

@@ -74,7 +74,7 @@ public class DescriptionPreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null, null, null);
mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -82,7 +82,7 @@ public class DescriptionPreferenceControllerTest {
public void testIsAvailable_notIfChannelGroupBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
mController.onResume(appRow, null, group, null, null, null);
mController.onResume(appRow, null, group, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -91,7 +91,7 @@ public class DescriptionPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -100,7 +100,7 @@ public class DescriptionPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -108,7 +108,7 @@ public class DescriptionPreferenceControllerTest {
public void testIsAvailable_notIfNoChannelGroupDesc() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
mController.onResume(appRow, null, group, null, null, null);
mController.onResume(appRow, null, group, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -118,7 +118,7 @@ public class DescriptionPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getDescription()).thenReturn("AAA");
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -128,17 +128,22 @@ public class DescriptionPreferenceControllerTest {
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.getDescription()).thenReturn("something");
when(group.isBlocked()).thenReturn(false);
mController.onResume(appRow, null, group, null, null, null);
mController.onResume(appRow, null, group, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_alwaysFiltered() {
assertFalse(mController.isIncludedInFilter());
}
@Test
public void testUpdateState_channel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getDescription()).thenReturn("AAA");
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -153,7 +158,7 @@ public class DescriptionPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.getDescription()).thenReturn("something");
mController.onResume(appRow, null, group, null, null, null);
mController.onResume(appRow, null, group, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);

View File

@@ -44,6 +44,8 @@ import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -54,6 +56,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class DndPreferenceControllerTest {
@@ -83,7 +87,7 @@ public class DndPreferenceControllerTest {
public void testIsAvailable_app() {
when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 0));
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -93,16 +97,37 @@ public class DndPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_MIN);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 1));
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_MIN);
mController.onResume(appRow, channel, null, null, null, null,
ImmutableList.of(NotificationChannel.EDIT_ZEN));
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 1));
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_MIN);
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
assertFalse(mController.isAvailable());
}
@Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -115,7 +140,7 @@ public class DndPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -128,7 +153,7 @@ public class DndPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -140,7 +165,8 @@ public class DndPreferenceControllerTest {
public void testUpdateState_bypassDnd() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.canBypassDnd()).thenReturn(true);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -152,7 +178,8 @@ public class DndPreferenceControllerTest {
public void testUpdateState_noBypassDnd() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.canBypassDnd()).thenReturn(false);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -164,7 +191,8 @@ public class DndPreferenceControllerTest {
public void testOnPreferenceChange_on() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -182,7 +210,8 @@ public class DndPreferenceControllerTest {
public void testOnPreferenceChange_off() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);

View File

@@ -48,6 +48,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class HeaderPreferenceControllerTest {
@@ -87,7 +89,7 @@ public class HeaderPreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null, null, null);
mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -95,7 +97,15 @@ public class HeaderPreferenceControllerTest {
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_ignoredFilter() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null, null, null, new ArrayList<>());
assertTrue(mController.isAvailable());
}
@@ -103,20 +113,20 @@ public class HeaderPreferenceControllerTest {
public void testGetLabel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.label = "bananas";
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertEquals(appRow.label, mController.getLabel());
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
mController.onResume(appRow, null, group, null, null, null);
mController.onResume(appRow, null, group, null, null, null, null);
assertEquals(group.getName(), mController.getLabel());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
mController.onResume(appRow, channel, group, null, null, null);
mController.onResume(appRow, channel, group, null, null, null, null);
assertEquals(channel.getName(), mController.getLabel());
NotificationChannel defaultChannel = new NotificationChannel(
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
mController.onResume(appRow, defaultChannel, null, null, null, null);
mController.onResume(appRow, defaultChannel, null, null, null, null, null);
assertEquals(appRow.label, mController.getLabel());
}
@@ -124,25 +134,25 @@ public class HeaderPreferenceControllerTest {
public void testGetSummary() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.label = "bananas";
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertEquals("", mController.getSummary());
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
mController.onResume(appRow, null, group, null, null, null);
mController.onResume(appRow, null, group, null, null, null, null);
assertEquals(appRow.label, mController.getSummary());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
mController.onResume(appRow, channel, group, null, null, null);
mController.onResume(appRow, channel, group, null, null, null, null);
assertTrue(mController.getSummary().toString().contains(group.getName()));
assertTrue(mController.getSummary().toString().contains(appRow.label));
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.getSummary().toString().contains(group.getName()));
assertTrue(mController.getSummary().toString().contains(appRow.label));
NotificationChannel defaultChannel = new NotificationChannel(
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
mController.onResume(appRow, defaultChannel, null, null, null, null);
mController.onResume(appRow, defaultChannel, null, null, null, null, null);
assertEquals("", mController.getSummary());
}
}

View File

@@ -52,6 +52,10 @@ import org.robolectric.shadows.ShadowApplication;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class HighImportancePreferenceControllerTest {
@@ -88,7 +92,7 @@ public class HighImportancePreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null, null, null);
mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -96,7 +100,7 @@ public class HighImportancePreferenceControllerTest {
public void testIsAvailable_ifAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -105,7 +109,7 @@ public class HighImportancePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -115,7 +119,7 @@ public class HighImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -124,16 +128,35 @@ public class HighImportancePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null,
ImmutableList.of(NotificationChannel.EDIT_IMPORTANCE));
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
assertFalse(mController.isAvailable());
}
@Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -147,7 +170,7 @@ public class HighImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -162,7 +185,7 @@ public class HighImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -177,7 +200,7 @@ public class HighImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -189,7 +212,7 @@ public class HighImportancePreferenceControllerTest {
public void testUpdateState_high() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -201,7 +224,7 @@ public class HighImportancePreferenceControllerTest {
public void testUpdateState_default() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -213,7 +236,8 @@ public class HighImportancePreferenceControllerTest {
public void onPreferenceChange() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);

View File

@@ -48,6 +48,8 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,6 +60,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class ImportancePreferenceControllerTest {
@@ -94,7 +98,7 @@ public class ImportancePreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null, null, null);
mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -102,7 +106,7 @@ public class ImportancePreferenceControllerTest {
public void testIsAvailable_ifAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -113,7 +117,7 @@ public class ImportancePreferenceControllerTest {
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
mController.onResume(appRow, channel, group, null, null, null);
mController.onResume(appRow, channel, group, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -122,7 +126,7 @@ public class ImportancePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -132,7 +136,7 @@ public class ImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -141,16 +145,35 @@ public class ImportancePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null,
ImmutableList.of(NotificationChannel.EDIT_IMPORTANCE));
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
assertFalse(mController.isAvailable());
}
@Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new ImportancePreference(mContext, null);
mController.updateState(pref);
@@ -164,7 +187,7 @@ public class ImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new ImportancePreference(mContext, null);
mController.updateState(pref);
@@ -179,7 +202,7 @@ public class ImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new ImportancePreference(mContext, null);
mController.updateState(pref);
@@ -194,7 +217,7 @@ public class ImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new ImportancePreference(mContext, null);
mController.updateState(pref);
@@ -206,7 +229,7 @@ public class ImportancePreferenceControllerTest {
public void testUpdateState() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
ImportancePreference pref = mock(ImportancePreference.class);
mController.updateState(pref);
@@ -221,7 +244,8 @@ public class ImportancePreferenceControllerTest {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
channel.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
ImportancePreference pref = new ImportancePreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -239,7 +263,8 @@ public class ImportancePreferenceControllerTest {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
channel.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
ImportancePreference pref = new ImportancePreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);

View File

@@ -24,6 +24,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.UserManager;
@@ -34,6 +35,8 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.google.common.collect.ImmutableList;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -46,6 +49,8 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = SettingsShadowResources.class)
public class InvalidConversationInfoPreferenceControllerTest {
@@ -90,7 +95,7 @@ public class InvalidConversationInfoPreferenceControllerTest {
appRow.pkg = "hi";
appRow.uid = 0;
appRow.banned = true;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -100,7 +105,7 @@ public class InvalidConversationInfoPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "hi";
appRow.uid = 0;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -110,10 +115,31 @@ public class InvalidConversationInfoPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "hi";
appRow.uid = 0;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "hi";
appRow.uid = 0;
mController.onResume(appRow, null, null, null, null, null, ImmutableList.of(
NotificationChannel.EDIT_CONVERSATION));
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "hi";
appRow.uid = 0;
mController.onResume(appRow, null, null, null, null, null, new ArrayList<>());
assertFalse(mController.isAvailable());
}
@Test
public void testUpdateState() {
when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
@@ -121,7 +147,7 @@ public class InvalidConversationInfoPreferenceControllerTest {
appRow.pkg = "hi";
appRow.uid = 0;
appRow.label = "plum";
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
Preference pref = new Preference(mContext);
mController.updateState(pref);
assertTrue(pref.getSummary().toString().contains(appRow.label));

View File

@@ -16,10 +16,6 @@
package com.android.settings.notification.app;
import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -45,6 +41,8 @@ import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
import com.google.common.collect.ImmutableList;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -57,6 +55,8 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = SettingsShadowResources.class)
public class InvalidConversationPreferenceControllerTest {
@@ -102,7 +102,7 @@ public class InvalidConversationPreferenceControllerTest {
appRow.pkg = "hi";
appRow.uid = 0;
appRow.banned = true;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -112,7 +112,7 @@ public class InvalidConversationPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "hi";
appRow.uid = 0;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -122,17 +122,38 @@ public class InvalidConversationPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "hi";
appRow.uid = 0;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "hi";
appRow.uid = 0;
mController.onResume(appRow, null, null, null, null, null, ImmutableList.of(
NotificationChannel.EDIT_CONVERSATION));
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "hi";
appRow.uid = 0;
mController.onResume(appRow, null, null, null, null, null, new ArrayList<>());
assertFalse(mController.isAvailable());
}
@Test
public void testUpdateState_disabledByAdmin() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "hi";
appRow.uid = 0;
mController.onResume(appRow, null, null,
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -144,7 +165,7 @@ public class InvalidConversationPreferenceControllerTest {
public void testUpdateState_notChecked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "pkg";
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(false);
@@ -157,7 +178,7 @@ public class InvalidConversationPreferenceControllerTest {
public void testUpdateState_checked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "pkg";
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(true);
@@ -170,7 +191,7 @@ public class InvalidConversationPreferenceControllerTest {
public void testOnPreferenceChange_toggleEnabled() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "pkg";
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(true);
@@ -189,7 +210,7 @@ public class InvalidConversationPreferenceControllerTest {
public void testOnPreferenceChange_toggleDisabled() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "pkg";
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(false);

View File

@@ -46,6 +46,8 @@ import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
import com.google.common.collect.ImmutableList;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -58,6 +60,10 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
import javax.annotation.concurrent.Immutable;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = SettingsShadowResources.class)
public class LightsPreferenceControllerTest {
@@ -107,7 +113,7 @@ public class LightsPreferenceControllerTest {
com.android.internal.R.bool.config_intrusiveNotificationLed, false);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -116,7 +122,7 @@ public class LightsPreferenceControllerTest {
Settings.System.putInt(mContext.getContentResolver(), NOTIFICATION_LIGHT_PULSE, 0);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -124,7 +130,7 @@ public class LightsPreferenceControllerTest {
public void testIsAvailable_notIfNotImportant() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -133,7 +139,7 @@ public class LightsPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -141,16 +147,33 @@ public class LightsPreferenceControllerTest {
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null,
ImmutableList.of(NotificationChannel.EDIT_LOCKED_DEVICE));
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
assertFalse(mController.isAvailable());
}
@Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null,
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -163,7 +186,7 @@ public class LightsPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -175,7 +198,8 @@ public class LightsPreferenceControllerTest {
public void testUpdateState_lightsOn() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.shouldShowLights()).thenReturn(true);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -186,7 +210,8 @@ public class LightsPreferenceControllerTest {
public void testUpdateState_lightsOff() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.shouldShowLights()).thenReturn(false);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -197,7 +222,8 @@ public class LightsPreferenceControllerTest {
public void testOnPreferenceChange_on() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -214,7 +240,8 @@ public class LightsPreferenceControllerTest {
public void testOnPreferenceChange_off() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(mContext);

View File

@@ -52,6 +52,10 @@ import org.robolectric.shadows.ShadowApplication;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class MinImportancePreferenceControllerTest {
@@ -88,7 +92,7 @@ public class MinImportancePreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null, null, null);
mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -96,7 +100,7 @@ public class MinImportancePreferenceControllerTest {
public void testIsAvailable_ifAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -105,7 +109,7 @@ public class MinImportancePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -115,7 +119,7 @@ public class MinImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -124,16 +128,35 @@ public class MinImportancePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null,
ImmutableList.of(NotificationChannel.EDIT_IMPORTANCE));
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
assertFalse(mController.isAvailable());
}
@Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -147,7 +170,7 @@ public class MinImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -162,7 +185,7 @@ public class MinImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -177,7 +200,7 @@ public class MinImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -189,7 +212,7 @@ public class MinImportancePreferenceControllerTest {
public void testUpdateState_min() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_MIN);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -201,7 +224,7 @@ public class MinImportancePreferenceControllerTest {
public void testUpdateState_low() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -213,7 +236,8 @@ public class MinImportancePreferenceControllerTest {
public void onPreferenceChange() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);

View File

@@ -54,6 +54,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class NotificationPreferenceControllerTest {
@@ -90,7 +92,7 @@ public class NotificationPreferenceControllerTest {
@Test
public void isAvailable_notIfNull() {
mController.onResume(null, null, null, null, null, null);
mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -99,7 +101,7 @@ public class NotificationPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class),
mock(NotificationChannelGroup.class), null, null, null);
mock(NotificationChannelGroup.class), null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -111,7 +113,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, group, null, null, null);
mController.onResume(appRow, channel, group, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -122,11 +124,25 @@ public class NotificationPreferenceControllerTest {
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
mController.onResume(appRow, channel, group, null, null, null);
mController.onResume(appRow, channel, group, null, null, null, null);
when(group.isBlocked()).thenReturn(true);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_notIfFailsFilterCheck() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(false);
ArrayList<String> filter = new ArrayList<>();
filter.add("something");
mController.onResume(appRow, channel, group, null, null, null, filter);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
@@ -135,7 +151,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(false);
mController.onResume(appRow, channel, group, null, null, null);
mController.onResume(appRow, channel, group, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -146,7 +162,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
RestrictedLockUtils.EnforcedAdmin admin = mock(RestrictedLockUtils.EnforcedAdmin.class);
mController.onResume(appRow, channel, group, null, null, admin);
mController.onResume(appRow, channel, group, null, null, admin, null);
assertEquals(appRow, mController.mAppRow);
assertEquals(channel, mController.mChannel);
@@ -160,7 +176,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_UNSPECIFIED);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.checkCanBeVisible(IMPORTANCE_MIN));
}
@@ -170,7 +186,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.checkCanBeVisible(IMPORTANCE_LOW));
}
@@ -180,7 +196,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.checkCanBeVisible(IMPORTANCE_MIN));
}
@@ -190,7 +206,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.checkCanBeVisible(IMPORTANCE_DEFAULT));
}
@@ -200,7 +216,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
mController.saveChannel();
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
}
@@ -212,11 +228,11 @@ public class NotificationPreferenceControllerTest {
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isChannelBlockable());
when(channel.isImportanceLockedByOEM()).thenReturn(false);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isChannelBlockable());
}
@@ -227,7 +243,7 @@ public class NotificationPreferenceControllerTest {
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isChannelBlockable());
}
@@ -238,7 +254,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isBlockable()).thenReturn(false);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isChannelBlockable());
}
@@ -250,7 +266,7 @@ public class NotificationPreferenceControllerTest {
when(channel.isBlockable()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isChannelBlockable());
}
@@ -261,7 +277,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isBlockable()).thenReturn(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isChannelBlockable());
}
@@ -273,7 +289,7 @@ public class NotificationPreferenceControllerTest {
when(channel.isBlockable()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isChannelBlockable());
}
@@ -284,7 +300,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(false);
mController.onResume(appRow, null, group, null, null, null);
mController.onResume(appRow, null, group, null, null, null, null);
assertTrue(mController.isChannelGroupBlockable());
}
@@ -296,7 +312,7 @@ public class NotificationPreferenceControllerTest {
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isChannelBlockable());
}
@@ -308,7 +324,7 @@ public class NotificationPreferenceControllerTest {
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isChannelBlockable());
}
@@ -319,7 +335,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(false);
mController.onResume(appRow, null, group, null, null, null);
mController.onResume(appRow, null, group, null, null, null, null);
assertFalse(mController.isChannelGroupBlockable());
}
@@ -330,13 +346,14 @@ public class NotificationPreferenceControllerTest {
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
mController.onResume(appRow, null, group, null, null, null);
mController.onResume(appRow, null, group, null, null, null, null);
assertTrue(mController.isChannelGroupBlockable());
}
@Test
public void testIsDefaultChannel_noChannel() {
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, null, null);
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, null, null,
null);
assertFalse(mController.isDefaultChannel());
}
@@ -344,7 +361,8 @@ public class NotificationPreferenceControllerTest {
@Test
public void testIsDefaultChannel_nonDefaultChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null, null, null);
mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null, null,
null, null);
assertFalse(mController.isDefaultChannel());
}
@@ -353,7 +371,8 @@ public class NotificationPreferenceControllerTest {
public void testIsDefaultChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(NotificationChannel.DEFAULT_CHANNEL_ID);
mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null, null, null);
mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null, null,
null, null);
assertTrue(mController.isDefaultChannel());
}
@@ -364,6 +383,11 @@ public class NotificationPreferenceControllerTest {
super(context, backend);
}
@Override
boolean isIncludedInFilter() {
return false;
}
@Override
public String getPreferenceKey() {
return null;

View File

@@ -34,6 +34,8 @@ import androidx.preference.Preference;
import com.android.settings.notification.NotificationBackend;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -43,6 +45,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class NotificationsOffPreferenceControllerTest {
@@ -72,7 +76,7 @@ public class NotificationsOffPreferenceControllerTest {
public void testIsAvailable_yesIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertThat(mController.isAvailable()).isTrue();
}
@@ -81,7 +85,7 @@ public class NotificationsOffPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
mController.onResume(appRow, null, group, null, null, null);
mController.onResume(appRow, null, group, null, null, null, null);
assertThat(mController.isAvailable()).isTrue();
}
@@ -90,16 +94,35 @@ public class NotificationsOffPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void testIsAvailable_filteredIn() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null,
ImmutableList.of(NotificationChannel.EDIT_IMPORTANCE));
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void testIsAvailable_filteredOut() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void testUpdateState_channel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -113,7 +136,7 @@ public class NotificationsOffPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
mController.onResume(appRow, null, group, null, null, null);
mController.onResume(appRow, null, group, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -126,7 +149,7 @@ public class NotificationsOffPreferenceControllerTest {
public void testUpdateState_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);

View File

@@ -53,6 +53,8 @@ import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -65,6 +67,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class SoundPreferenceControllerTest {
@@ -108,7 +112,7 @@ public class SoundPreferenceControllerTest {
@Test
public void testIsAvailable_notIfChannelNull() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -116,7 +120,7 @@ public class SoundPreferenceControllerTest {
public void testIsAvailable_notIfNotImportant() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -125,7 +129,7 @@ public class SoundPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -133,10 +137,27 @@ public class SoundPreferenceControllerTest {
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null,
ImmutableList.of(NotificationChannel.EDIT_SOUND));
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
assertFalse(mController.isAvailable());
}
@Test
public void testDisplayPreference_savesPreference() {
NotificationSoundPreference pref = mock(NotificationSoundPreference.class);
@@ -152,7 +173,7 @@ public class SoundPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
RestrictedLockUtils.EnforcedAdmin.class), null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
Preference pref = new NotificationSoundPreference(mContext, attributeSet);
@@ -166,7 +187,7 @@ public class SoundPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
Preference pref = new NotificationSoundPreference(mContext, attributeSet);
@@ -182,7 +203,7 @@ public class SoundPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
when(channel.getSound()).thenReturn(sound);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
NotificationSoundPreference pref = new NotificationSoundPreference(mContext, attributeSet);
@@ -198,7 +219,7 @@ public class SoundPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
channel.setSound(sound, Notification.AUDIO_ATTRIBUTES_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
NotificationSoundPreference pref =
@@ -238,7 +259,7 @@ public class SoundPreferenceControllerTest {
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
channel.setSound(null, new AudioAttributes.Builder().setUsage(
AudioAttributes.USAGE_ALARM).build());
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
NotificationSoundPreference pref =
@@ -259,7 +280,7 @@ public class SoundPreferenceControllerTest {
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
channel.setSound(null, new AudioAttributes.Builder().setUsage(
AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build());
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
NotificationSoundPreference pref =
@@ -280,7 +301,7 @@ public class SoundPreferenceControllerTest {
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
channel.setSound(null, new AudioAttributes.Builder().setUsage(
AudioAttributes.USAGE_UNKNOWN).build());
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
NotificationSoundPreference pref =

View File

@@ -45,6 +45,8 @@ import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -55,6 +57,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
public class VibrationPreferenceControllerTest {
@@ -98,7 +102,7 @@ public class VibrationPreferenceControllerTest {
when(mVibrator.hasVibrator()).thenReturn(false);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -106,7 +110,7 @@ public class VibrationPreferenceControllerTest {
public void testIsAvailable_notIfNotImportant() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -115,7 +119,7 @@ public class VibrationPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -123,16 +127,33 @@ public class VibrationPreferenceControllerTest {
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null,
ImmutableList.of(NotificationChannel.EDIT_VIBRATION));
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
assertFalse(mController.isAvailable());
}
@Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -145,7 +166,7 @@ public class VibrationPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -158,7 +179,7 @@ public class VibrationPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -170,7 +191,8 @@ public class VibrationPreferenceControllerTest {
public void testUpdateState_vibrateOn() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.shouldVibrate()).thenReturn(true);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -182,7 +204,8 @@ public class VibrationPreferenceControllerTest {
public void testUpdateState_vibrateOff() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.shouldVibrate()).thenReturn(false);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -194,7 +217,8 @@ public class VibrationPreferenceControllerTest {
public void testOnPreferenceChange_on() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -210,7 +234,8 @@ public class VibrationPreferenceControllerTest {
public void testOnPreferenceChange_off() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);

View File

@@ -51,6 +51,8 @@ import com.android.settings.notification.NotificationBackend;
import com.android.settings.testutils.shadow.ShadowRestrictionUtils;
import com.android.settingslib.RestrictedLockUtils;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -121,7 +123,7 @@ public class VisibilityPreferenceControllerTest {
when(mLockUtils.isSecure(anyInt())).thenReturn(false);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -129,7 +131,7 @@ public class VisibilityPreferenceControllerTest {
public void testIsAvailable_notIfNotImportant() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_MIN);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -138,14 +140,31 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredIn() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null,
ImmutableList.of(NotificationChannel.EDIT_LOCKED_DEVICE));
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_filteredOut() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
assertFalse(mController.isAvailable());
}
@Test
public void testUpdateState_disabledByAdmin_disableSecure() {
ShadowRestrictionUtils.setRestricted(true);
@@ -160,7 +179,7 @@ public class VisibilityPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
RestrictedLockUtils.EnforcedAdmin.class), null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -182,7 +201,7 @@ public class VisibilityPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
RestrictedLockUtils.EnforcedAdmin.class), null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -197,7 +216,7 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -222,7 +241,7 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -245,7 +264,7 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -262,7 +281,7 @@ public class VisibilityPreferenceControllerTest {
public void testUpdateState_noGlobalRestriction() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -293,7 +312,7 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getLockscreenVisibility()).thenReturn(VISIBILITY_NO_OVERRIDE);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -312,7 +331,7 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getLockscreenVisibility()).thenReturn(Notification.VISIBILITY_SECRET);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -331,7 +350,7 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", 4);
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -350,7 +369,7 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", 4);
channel.setLockscreenVisibility(VISIBILITY_NO_OVERRIDE);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);