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);
}
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));
}
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);
}
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;
}
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);
}
Aggregations