Search in sources :

Example 1 with PreferenceManager

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

the class EnterpriseDisclosurePreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = RuntimeEnvironment.application;
    mController = spy(new EnterpriseDisclosurePreferenceController(mContext));
    mFragment = spy(new ChooseAccountFragment());
    mFooterPreferenceMixin = new FooterPreferenceMixinCompat(mFragment, mFragment.getSettingsLifecycle());
    mPreferenceManager = new PreferenceManager(mContext);
    mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
}
Also used : FooterPreferenceMixinCompat(com.android.settingslib.widget.FooterPreferenceMixinCompat) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 2 with PreferenceManager

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

the class UnrestrictedDataAccessPreferenceControllerTest method onRebuildComplete_restricted_shouldBeDisabled.

@Test
public void onRebuildComplete_restricted_shouldBeDisabled() {
    mFragment = spy(new UnrestrictedDataAccess());
    doNothing().when(mFragment).setLoading(anyBoolean(), anyBoolean());
    mController.setParentFragment(mFragment);
    mPreferenceManager = new PreferenceManager(mContext);
    mPreferenceScreen = spy(mPreferenceManager.createPreferenceScreen(mContext));
    doReturn(mPreferenceManager).when(mFragment).getPreferenceManager();
    doReturn(mPreferenceScreen).when(mFragment).getPreferenceScreen();
    doReturn(0).when(mPreferenceScreen).getPreferenceCount();
    final DataSaverBackend dataSaverBackend = mock(DataSaverBackend.class);
    ReflectionHelpers.setField(mController, "mDataSaverBackend", dataSaverBackend);
    ReflectionHelpers.setField(mController, "mScreen", mPreferenceScreen);
    final String testPkg1 = "com.example.one";
    final String testPkg2 = "com.example.two";
    ShadowRestrictedLockUtilsInternal.setRestrictedPkgs(testPkg2);
    doAnswer((invocation) -> {
        final UnrestrictedDataAccessPreference preference = invocation.getArgument(0);
        final AppEntry entry = preference.getEntry();
        // Verify preference is disabled by admin and the summary is changed accordingly.
        if (testPkg1.equals(entry.info.packageName)) {
            assertThat(preference.isDisabledByAdmin()).isFalse();
            assertThat(preference.getSummary()).isEqualTo("");
        } else if (testPkg2.equals(entry.info.packageName)) {
            assertThat(preference.isDisabledByAdmin()).isTrue();
            assertThat(preference.getSummary()).isEqualTo(mContext.getString(R.string.disabled_by_admin));
        }
        assertThat(preference.isChecked()).isFalse();
        preference.performClick();
        // if the preference is disabled by admin, otherwise the switch is toggled.
        if (testPkg1.equals(entry.info.packageName)) {
            assertThat(preference.isChecked()).isTrue();
            assertThat(ShadowRestrictedLockUtils.hasAdminSupportDetailsIntentLaunched()).isFalse();
        } else if (testPkg2.equals(entry.info.packageName)) {
            assertThat(preference.isChecked()).isFalse();
            assertThat(ShadowRestrictedLockUtils.hasAdminSupportDetailsIntentLaunched()).isTrue();
        }
        ShadowRestrictedLockUtils.clearAdminSupportDetailsIntentLaunch();
        return null;
    }).when(mPreferenceScreen).addPreference(any(UnrestrictedDataAccessPreference.class));
    mController.onRebuildComplete(createAppEntries(testPkg1, testPkg2));
}
Also used : AppEntry(com.android.settingslib.applications.ApplicationsState.AppEntry) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Example 3 with PreferenceManager

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

the class AirplaneModePreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    FakeFeatureFactory.setupForTest();
    mContext = spy(RuntimeEnvironment.application);
    mResolver = RuntimeEnvironment.application.getContentResolver();
    doReturn(mPackageManager).when(mContext).getPackageManager();
    mController = new AirplaneModePreferenceController(mContext, SettingsSlicesContract.KEY_AIRPLANE_MODE);
    mPreferenceManager = new PreferenceManager(mContext);
    mScreen = mPreferenceManager.createPreferenceScreen(mContext);
    mPreference = new RestrictedSwitchPreference(mContext);
    mPreference.setKey(SettingsSlicesContract.KEY_AIRPLANE_MODE);
    mScreen.addPreference(mPreference);
    mController.setFragment(null);
    mLifecycleOwner = () -> mLifecycle;
    mLifecycle = new Lifecycle(mLifecycleOwner);
    mLifecycle.addObserver(mController);
}
Also used : RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 4 with PreferenceManager

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

the class UsbDetailsDataRoleControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = RuntimeEnvironment.application;
    mLifecycle = new Lifecycle(() -> mLifecycle);
    mPreferenceManager = new PreferenceManager(mContext);
    mScreen = mPreferenceManager.createPreferenceScreen(mContext);
    when(mFragment.getActivity()).thenReturn(mActivity);
    when(mActivity.getApplicationContext()).thenReturn(mContext);
    when(mFragment.getContext()).thenReturn(mContext);
    when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
    when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
    mDetailsDataRoleController = new UsbDetailsDataRoleController(mContext, mFragment, mUsbBackend);
    mPreference = new PreferenceCategory(mContext);
    mPreference.setKey(mDetailsDataRoleController.getPreferenceKey());
    mScreen.addPreference(mPreference);
    mDetailsDataRoleController.mHandler = mHandler;
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 5 with PreferenceManager

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

the class UsbDetailsFunctionsControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    mLifecycle = new Lifecycle(() -> mLifecycle);
    mPreferenceManager = new PreferenceManager(mContext);
    mScreen = mPreferenceManager.createPreferenceScreen(mContext);
    when(mFragment.getActivity()).thenReturn(mActivity);
    when(mActivity.getApplicationContext()).thenReturn(mContext);
    when(mFragment.getContext()).thenReturn(mContext);
    when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
    when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
    when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mConnectivityManager);
    mDetailsFunctionsController = new UsbDetailsFunctionsController(mContext, mFragment, mUsbBackend);
    mPreferenceCategory = new PreferenceCategory(mContext);
    mPreferenceCategory.setKey(mDetailsFunctionsController.getPreferenceKey());
    mScreen.addPreference(mPreferenceCategory);
    mDetailsFunctionsController.displayPreference(mScreen);
    mRadioButtonPreference = new RadioButtonPreference(mContext);
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) PreferenceManager(androidx.preference.PreferenceManager) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) 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