Search in sources :

Example 46 with RestrictedSwitchPreference

use of com.android.settingslib.RestrictedSwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class MinImportancePreferenceControllerTest method testUpdateState_notConfigurable.

@Test
public void testUpdateState_notConfigurable() {
    NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
    NotificationChannel channel = mock(NotificationChannel.class);
    when(channel.isImportanceLockedByOEM()).thenReturn(true);
    when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
    mController.onResume(appRow, channel, null, null);
    Preference pref = new RestrictedSwitchPreference(mContext, null);
    mController.updateState(pref);
    assertFalse(pref.isEnabled());
}
Also used : NotificationChannel(android.app.NotificationChannel) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(androidx.preference.Preference) Test(org.junit.Test)

Example 47 with RestrictedSwitchPreference

use of com.android.settingslib.RestrictedSwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class MinImportancePreferenceControllerTest method testUpdateState_defaultApp.

@Test
public void testUpdateState_defaultApp() {
    NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
    appRow.systemApp = true;
    NotificationChannel channel = mock(NotificationChannel.class);
    when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
    when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
    mController.onResume(appRow, channel, null, null);
    Preference pref = new RestrictedSwitchPreference(mContext, null);
    mController.updateState(pref);
    assertTrue(pref.isEnabled());
}
Also used : NotificationChannel(android.app.NotificationChannel) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(androidx.preference.Preference) Test(org.junit.Test)

Example 48 with RestrictedSwitchPreference

use of com.android.settingslib.RestrictedSwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class TrustAgentsPreferenceControllerTest method onStart_hasRestrictedTructAgent_shouldAddThreeUnchangeablePreferences.

@Test
public void onStart_hasRestrictedTructAgent_shouldAddThreeUnchangeablePreferences() {
    final List<ResolveInfo> availableAgents = createFakeAvailableAgents();
    for (ResolveInfo rInfo : availableAgents) {
        ShadowTrustAgentManager.grantPermissionToResolveInfo(rInfo);
    }
    mPackageManager.setResolveInfosForIntent(TEST_INTENT, availableAgents);
    ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS);
    mController.displayPreference(mPreferenceScreen);
    mController.onStart();
    assertThat(mPreferenceScreen.getPreferenceCount()).isEqualTo(3);
    for (int i = 0; i < mPreferenceScreen.getPreferenceCount(); i++) {
        RestrictedSwitchPreference preference = (RestrictedSwitchPreference) mPreferenceScreen.getPreference(i);
        assertThat(preference.isDisabledByAdmin()).isTrue();
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Test(org.junit.Test)

Example 49 with RestrictedSwitchPreference

use of com.android.settingslib.RestrictedSwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class TrustAgentsPreferenceControllerTest method onStart_hasUnrestrictedTrustAgent_shouldAddThreeChangeablePreferences.

@Test
public void onStart_hasUnrestrictedTrustAgent_shouldAddThreeChangeablePreferences() {
    ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(0);
    final List<ResolveInfo> availableAgents = createFakeAvailableAgents();
    for (ResolveInfo rInfo : availableAgents) {
        ShadowTrustAgentManager.grantPermissionToResolveInfo(rInfo);
    }
    mPackageManager.setResolveInfosForIntent(TEST_INTENT, availableAgents);
    mController.displayPreference(mPreferenceScreen);
    mController.onStart();
    assertThat(mPreferenceScreen.getPreferenceCount()).isEqualTo(3);
    for (int i = 0; i < mPreferenceScreen.getPreferenceCount(); i++) {
        RestrictedSwitchPreference preference = (RestrictedSwitchPreference) mPreferenceScreen.getPreference(i);
        assertThat(preference.isDisabledByAdmin()).isFalse();
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Test(org.junit.Test)

Example 50 with RestrictedSwitchPreference

use of com.android.settingslib.RestrictedSwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AllowSoundPreferenceControllerTest method testOnPreferenceChange_off.

@Test
public void testOnPreferenceChange_off() {
    NotificationChannel channel = new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
    mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
    RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
    when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
    mController.displayPreference(mScreen);
    mController.updateState(pref);
    pref.setChecked(false);
    mController.onPreferenceChange(pref, false);
    verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
    assertEquals(IMPORTANCE_LOW, mController.mChannel.getImportance());
    verify(mImportanceListener, times(1)).onImportanceChanged();
}
Also used : NotificationChannel(android.app.NotificationChannel) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Test(org.junit.Test)

Aggregations

RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)146 Test (org.junit.Test)101 NotificationChannel (android.app.NotificationChannel)52 Preference (androidx.preference.Preference)23 PreferenceGroup (android.support.v7.preference.PreferenceGroup)15 Preference (android.support.v7.preference.Preference)14 EnforcedAdmin (com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)10 Before (org.junit.Before)10 SwitchPreference (android.support.v14.preference.SwitchPreference)8 Context (android.content.Context)7 IBinder (android.os.IBinder)7 RemoteException (android.os.RemoteException)7 ListPreference (android.support.v7.preference.ListPreference)7 LockPatternUtils (com.android.internal.widget.LockPatternUtils)7 IStorageManager (android.os.storage.IStorageManager)6 WebViewAppPreferenceController (com.android.settings.webview.WebViewAppPreferenceController)6 AbstractEnableAdbPreferenceController (com.android.settingslib.development.AbstractEnableAdbPreferenceController)6 ContentResolver (android.content.ContentResolver)2 ResolveInfo (android.content.pm.ResolveInfo)2 PersistableBundle (android.os.PersistableBundle)2