Search in sources :

Example 1 with RestrictedListPreference

use of com.android.settings.RestrictedListPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class VisibilityPreferenceControllerTest method testUpdateState_disabledByAdmin_disableUnredacted.

@Test
public void testUpdateState_disabledByAdmin_disableUnredacted() {
    ShadowRestrictionUtils.setRestricted(true);
    UserInfo userInfo = new UserInfo(2, "user 2", UserInfo.FLAG_MANAGED_PROFILE);
    when(mUm.getUserInfo(anyInt())).thenReturn(userInfo);
    List<ComponentName> components = new ArrayList<>();
    components.add(new ComponentName("", ""));
    when(mDm.getActiveAdminsAsUser(anyInt())).thenReturn(components);
    when(mDm.getKeyguardDisabledFeatures(any(), anyInt())).thenReturn(KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
    NotificationChannel channel = mock(NotificationChannel.class);
    when(channel.getId()).thenReturn("something");
    mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
    RestrictedListPreference pref = mock(RestrictedListPreference.class);
    mController.updateState(pref);
    verify(pref, times(1)).addRestrictedItem(any());
}
Also used : NotificationChannel(android.app.NotificationChannel) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) ComponentName(android.content.ComponentName) RestrictedListPreference(com.android.settings.RestrictedListPreference) Test(org.junit.Test)

Example 2 with RestrictedListPreference

use of com.android.settings.RestrictedListPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class VisibilityPreferenceControllerTest method testOnPreferenceChange_override.

@Test
public void testOnPreferenceChange_override() {
    Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0);
    NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
    NotificationChannel channel = new NotificationChannel("", "", 4);
    channel.setLockscreenVisibility(VISIBILITY_NO_OVERRIDE);
    mController.onResume(appRow, channel, null, null);
    RestrictedListPreference pref = mock(RestrictedListPreference.class);
    mController.updateState(pref);
    mController.onPreferenceChange(pref, String.valueOf(Notification.VISIBILITY_SECRET));
    assertEquals(Notification.VISIBILITY_SECRET, channel.getLockscreenVisibility());
    verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
}
Also used : NotificationChannel(android.app.NotificationChannel) RestrictedListPreference(com.android.settings.RestrictedListPreference) Test(org.junit.Test)

Example 3 with RestrictedListPreference

use of com.android.settings.RestrictedListPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class VisibilityPreferenceControllerTest method testUpdateState_disabledByAdmin_disableSecure.

@Test
public void testUpdateState_disabledByAdmin_disableSecure() {
    ShadowRestrictionUtils.setRestricted(true);
    UserInfo userInfo = new UserInfo(2, "user 2", UserInfo.FLAG_MANAGED_PROFILE);
    when(mUm.getUserInfo(anyInt())).thenReturn(userInfo);
    List<ComponentName> components = new ArrayList<>();
    components.add(new ComponentName("", ""));
    when(mDm.getActiveAdminsAsUser(anyInt())).thenReturn(components);
    when(mDm.getKeyguardDisabledFeatures(any(), anyInt())).thenReturn(KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
    NotificationChannel channel = mock(NotificationChannel.class);
    when(channel.getId()).thenReturn("something");
    mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
    RestrictedListPreference pref = mock(RestrictedListPreference.class);
    mController.updateState(pref);
    verify(pref, times(2)).addRestrictedItem(any());
}
Also used : NotificationChannel(android.app.NotificationChannel) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) ComponentName(android.content.ComponentName) RestrictedListPreference(com.android.settings.RestrictedListPreference) Test(org.junit.Test)

Example 4 with RestrictedListPreference

use of com.android.settings.RestrictedListPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class VisibilityPreferenceControllerTest method testUpdateState_noChannelOverride.

@Test
public void testUpdateState_noChannelOverride() {
    Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0);
    NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
    NotificationChannel channel = mock(NotificationChannel.class);
    when(channel.getLockscreenVisibility()).thenReturn(VISIBILITY_NO_OVERRIDE);
    mController.onResume(appRow, channel, null, null);
    RestrictedListPreference pref = mock(RestrictedListPreference.class);
    mController.updateState(pref);
    ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
    verify(pref, times(1)).setValue(argumentCaptor.capture());
    assertEquals(String.valueOf(VISIBILITY_PRIVATE), argumentCaptor.getValue());
}
Also used : NotificationChannel(android.app.NotificationChannel) RestrictedListPreference(com.android.settings.RestrictedListPreference) Test(org.junit.Test)

Example 5 with RestrictedListPreference

use of com.android.settings.RestrictedListPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ShowOnLockscreenNotificationPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = RuntimeEnvironment.application;
    mController = new ShowOnLockScreenNotificationPreferenceController(mContext, KEY);
    mPreference = new RestrictedListPreference(mContext, Robolectric.buildAttributeSet().build());
    mPreference.setKey(mController.getPreferenceKey());
    when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
    mController.setDpm(mDpm);
}
Also used : RestrictedListPreference(com.android.settings.RestrictedListPreference) Before(org.junit.Before)

Aggregations

RestrictedListPreference (com.android.settings.RestrictedListPreference)14 NotificationChannel (android.app.NotificationChannel)10 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)4 UserInfo (android.content.pm.UserInfo)3 ComponentName (android.content.ComponentName)2 Before (org.junit.Before)1