Search in sources :

Example 41 with Preference

use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class MobileNetworkListControllerTest method onSubscriptionsChanged_startWithThreeSubsAndRemoveOne_correctPreferenceRemoved.

@Test
public void onSubscriptionsChanged_startWithThreeSubsAndRemoveOne_correctPreferenceRemoved() {
    final SubscriptionInfo sub1 = createMockSubscription(1, "sub1");
    final SubscriptionInfo sub2 = createMockSubscription(2, "sub2");
    final SubscriptionInfo sub3 = createMockSubscription(3, "sub3");
    SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2, sub3));
    mController.displayPreference(mPreferenceScreen);
    mController.onResume();
    final ArgumentCaptor<Preference> preferenceCaptor = ArgumentCaptor.forClass(Preference.class);
    verify(mPreferenceScreen, times(3)).addPreference(preferenceCaptor.capture());
    // remove sub2, and check that the second pref was removed from the screen
    SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub3));
    mController.onSubscriptionsChanged();
    final ArgumentCaptor<Preference> removedPrefCaptor = ArgumentCaptor.forClass(Preference.class);
    verify(mPreferenceScreen).removePreference(removedPrefCaptor.capture());
    assertThat(removedPrefCaptor.getValue().getTitle()).isEqualTo("sub2");
}
Also used : Preference(androidx.preference.Preference) SubscriptionInfo(android.telephony.SubscriptionInfo) Test(org.junit.Test)

Example 42 with Preference

use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class MobileNetworkListControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(Robolectric.setupActivity(Activity.class));
    when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
    when(mContext.getSystemService(EuiccManager.class)).thenReturn(mEuiccManager);
    Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.EUICC_PROVISIONED, 1);
    when(mPreferenceScreen.getContext()).thenReturn(mContext);
    mAddMorePreference = new Preference(mContext);
    when(mPreferenceScreen.findPreference(MobileNetworkListController.KEY_ADD_MORE)).thenReturn(mAddMorePreference);
    mController = new MobileNetworkListController(mContext, mLifecycle);
}
Also used : Preference(androidx.preference.Preference) Before(org.junit.Before)

Example 43 with Preference

use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class MobileNetworkListControllerTest method onSubscriptionsChanged_twoSubscriptionsOneChangesName_preferenceUpdated.

@Test
public void onSubscriptionsChanged_twoSubscriptionsOneChangesName_preferenceUpdated() {
    final SubscriptionInfo sub1 = createMockSubscription(1, "sub1");
    final SubscriptionInfo sub2 = createMockSubscription(2, "sub2");
    SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
    mController.displayPreference(mPreferenceScreen);
    mController.onResume();
    final ArgumentCaptor<Preference> preferenceCaptor = ArgumentCaptor.forClass(Preference.class);
    verify(mPreferenceScreen, times(2)).addPreference(preferenceCaptor.capture());
    when(sub2.getDisplayName()).thenReturn("new name");
    mController.onSubscriptionsChanged();
    assertThat(preferenceCaptor.getAllValues().get(1).getTitle()).isEqualTo("new name");
}
Also used : Preference(androidx.preference.Preference) SubscriptionInfo(android.telephony.SubscriptionInfo) Test(org.junit.Test)

Example 44 with Preference

use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class MobileNetworkPreferenceControllerTest method serviceStateChange_shouldUpdatePrefSummary.

@Test
public void serviceStateChange_shouldUpdatePrefSummary() {
    final String testCarrierName = "test";
    final Preference mPreference = mock(Preference.class);
    mController = spy(new MobileNetworkPreferenceController(mContext));
    mLifecycle.addObserver(mController);
    when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
    doReturn(true).when(mController).isAvailable();
    // Display pref and go through lifecycle to set up listener.
    mController.displayPreference(mScreen);
    mLifecycle.handleLifecycleEvent(ON_START);
    verify(mController).onStart();
    verify(mTelephonyManager).listen(mController.mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
    // Trigger listener update
    when(mTelephonyManager.getNetworkOperatorName()).thenReturn(testCarrierName);
    mController.mPhoneStateListener.onServiceStateChanged(null);
    // Carrier name should be set.
    verify(mPreference).setSummary(testCarrierName);
}
Also used : RestrictedPreference(com.android.settingslib.RestrictedPreference) Preference(androidx.preference.Preference) Test(org.junit.Test)

Example 45 with Preference

use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NetworkScorerPickerPreferenceControllerTest method updateState_preferenceSetSummaryAsActiveScorerLabel.

@Test
public void updateState_preferenceSetSummaryAsActiveScorerLabel() {
    ComponentName scorer = new ComponentName(TEST_SCORER_PACKAGE, TEST_SCORER_CLASS);
    NetworkScorerAppData scorerAppData = new NetworkScorerAppData(0, scorer, TEST_SCORER_LABEL, null, /* enableUseOpenWifiActivity */
    null);
    when(mNetworkScorer.getAllValidScorers()).thenReturn(Collections.singletonList(scorerAppData));
    when(mNetworkScorer.getActiveScorer()).thenReturn(scorerAppData);
    Preference preference = mock(Preference.class);
    mController.updateState(preference);
    verify(preference).setSummary(TEST_SCORER_LABEL);
}
Also used : Preference(androidx.preference.Preference) ComponentName(android.content.ComponentName) NetworkScorerAppData(android.net.NetworkScorerAppData) Test(org.junit.Test)

Aggregations

Preference (androidx.preference.Preference)860 Test (org.junit.Test)343 Before (org.junit.Before)164 Intent (android.content.Intent)81 PreferenceScreen (androidx.preference.PreferenceScreen)81 NotificationChannel (android.app.NotificationChannel)77 SwitchPreference (androidx.preference.SwitchPreference)75 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)69 Context (android.content.Context)60 ArrayList (java.util.ArrayList)50 NotificationBackend (com.android.settings.notification.NotificationBackend)45 ListPreference (androidx.preference.ListPreference)41 Tile (com.android.settingslib.drawer.Tile)40 PreferenceCategory (androidx.preference.PreferenceCategory)39 PreferenceManager (androidx.preference.PreferenceManager)39 Activity (android.app.Activity)27 UserHandle (android.os.UserHandle)27 FooterPreference (com.android.settingslib.widget.FooterPreference)27 PackageManager (android.content.pm.PackageManager)26 Bundle (android.os.Bundle)24