Search in sources :

Example 16 with PreferenceManager

use of androidx.preference.PreferenceManager in project android_packages_apps_Settings by omnirom.

the class SubscriptionsPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(ApplicationProvider.getApplicationContext());
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    mLifecycleRegistry = new LifecycleRegistry(mLifecycleOwner);
    when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
    when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mConnectivityManager);
    when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
    when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
    when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
    when(mConnectivityManager.getActiveNetwork()).thenReturn(mActiveNetwork);
    when(mConnectivityManager.getNetworkCapabilities(mActiveNetwork)).thenReturn(mNetworkCapabilities);
    when(mUserManager.isAdminUser()).thenReturn(true);
    when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry);
    mPreferenceManager = new PreferenceManager(mContext);
    mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
    mPreferenceScreen.setInitialExpandedChildrenCount(3);
    mPreferenceCategory = new PreferenceCategory(mContext);
    mPreferenceCategory.setKey(KEY);
    mPreferenceCategory.setOrderingAsAdded(true);
    mPreferenceScreen.addPreference(mPreferenceCategory);
    mOnChildUpdatedCount = 0;
    mUpdateListener = () -> mOnChildUpdatedCount++;
    sInjector = spy(new SubsPrefCtrlInjector());
    initializeMethod(true, 1, 1, 1, false, false);
    mController = new FakeSubscriptionsPreferenceController(mContext, mLifecycle, mUpdateListener, KEY, 5);
    Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0);
}
Also used : LifecycleRegistry(androidx.lifecycle.LifecycleRegistry) PreferenceCategory(androidx.preference.PreferenceCategory) SubsPrefCtrlInjector(com.android.settings.network.SubscriptionsPreferenceController.SubsPrefCtrlInjector) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 17 with PreferenceManager

use of androidx.preference.PreferenceManager in project android_packages_apps_Settings by omnirom.

the class NetworkProviderCallsSmsControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(ApplicationProvider.getApplicationContext());
    when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    mPreferenceManager = new PreferenceManager(mContext);
    mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
    mPreference = new RestrictedPreference(mContext);
    mPreference.setKey(KEY_PREFERENCE_CALLS_SMS);
    mController = new MockNetworkProviderCallsSmsController(mContext, mLifecycle);
    mController.setInService(true);
    mLifecycleRegistry = new LifecycleRegistry(mLifecycleOwner);
    when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry);
}
Also used : LifecycleRegistry(androidx.lifecycle.LifecycleRegistry) RestrictedPreference(com.android.settingslib.RestrictedPreference) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 18 with PreferenceManager

use of androidx.preference.PreferenceManager in project android_packages_apps_Settings by omnirom.

the class EnabledNetworkModePreferenceControllerTest method preferredNetworkModeNotification_preferenceUpdates.

@UiThreadTest
@Test
public void preferredNetworkModeNotification_preferenceUpdates() {
    final PreferenceManager preferenceManager = new PreferenceManager(mContext);
    PreferenceScreen screen = preferenceManager.createPreferenceScreen(mContext);
    mPreference.setKey(KEY);
    screen.addPreference(mPreference);
    mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA);
    // NETWORK_MODE_TDSCDMA_GSM_WCDMA = RAF_TD_SCDMA | GSM | WCDMA
    when(mTelephonyManager.getAllowedNetworkTypesForReason(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER)).thenReturn((long) (RAF_TD_SCDMA | GSM | WCDMA));
    mController.displayPreference(screen);
    mController.updateState(mPreference);
    mLifecycle.handleLifecycleEvent(ON_START);
    assertThat(Integer.parseInt(mPreference.getValue())).isEqualTo(TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA);
    assertThat(mPreference.getSummary()).isEqualTo("3G");
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 19 with PreferenceManager

use of androidx.preference.PreferenceManager in project android_packages_apps_Settings by omnirom.

the class MultiNetworkHeaderControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(ApplicationProvider.getApplicationContext());
    when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
    mHeaderController = new MultiNetworkHeaderController(mContext, KEY_HEADER) {

        @Override
        WifiConnectionPreferenceController createWifiController(Lifecycle lifecycle) {
            return mWifiController;
        }

        @Override
        SubscriptionsPreferenceController createSubscriptionsController(Lifecycle lifecycle) {
            return mSubscriptionsController;
        }
    };
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    mPreferenceManager = new PreferenceManager(mContext);
    mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
    mPreferenceScreen.setInitialExpandedChildrenCount(EXPANDED_CHILDREN_COUNT);
    when(mPreferenceCategory.getKey()).thenReturn(KEY_HEADER);
    when(mPreferenceCategory.getPreferenceCount()).thenReturn(3);
    mPreferenceScreen.addPreference(mPreferenceCategory);
}
Also used : Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) WifiConnectionPreferenceController(com.android.settings.wifi.WifiConnectionPreferenceController) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 20 with PreferenceManager

use of androidx.preference.PreferenceManager in project android_packages_apps_Settings by omnirom.

the class NetworkMobileProviderControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    when(mPreferenceCategory.getKey()).thenReturn(PREF_KEY_PROVIDER_MOBILE_NETWORK);
    when(mPreferenceCategory.getPreferenceCount()).thenReturn(3);
    mContext = ApplicationProvider.getApplicationContext();
    mNetworkMobileProviderController = new NetworkMobileProviderController(mContext, PREF_KEY_PROVIDER_MOBILE_NETWORK) {

        @Override
        SubscriptionsPreferenceController createSubscriptionsController(Lifecycle lifecycle) {
            return mSubscriptionsController;
        }
    };
    mPreferenceManager = new PreferenceManager(mContext);
    mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
    mPreferenceScreen.setInitialExpandedChildrenCount(EXPANDED_CHILDREN_COUNT);
    mPreferenceScreen.addPreference(mPreferenceCategory);
}
Also used : Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Aggregations

PreferenceManager (androidx.preference.PreferenceManager)87 Before (org.junit.Before)67 Preference (androidx.preference.Preference)23 PreferenceCategory (androidx.preference.PreferenceCategory)22 PreferenceScreen (androidx.preference.PreferenceScreen)19 Test (org.junit.Test)18 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)15 Context (android.content.Context)5 LifecycleRegistry (androidx.lifecycle.LifecycleRegistry)5 ArrayList (java.util.ArrayList)5 NotificationChannel (android.app.NotificationChannel)4 ShortcutInfo (android.content.pm.ShortcutInfo)4 View (android.view.View)4 NotificationChannelGroup (android.app.NotificationChannelGroup)3 ConversationChannel (android.app.people.ConversationChannel)3 PackageInfo (android.content.pm.PackageInfo)3 PersistableBundle (android.os.PersistableBundle)3 BluetoothManager (android.bluetooth.BluetoothManager)2 SoftApConfiguration (android.net.wifi.SoftApConfiguration)2 WifiManager (android.net.wifi.WifiManager)2