Search in sources :

Example 46 with PreferenceScreen

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

the class BasePreferenceControllerTest method disabledDependentSetting_disabledOnDisplayPreference_preferenceDisabled.

@Test
public void disabledDependentSetting_disabledOnDisplayPreference_preferenceDisabled() {
    final PreferenceScreen screen = mock(PreferenceScreen.class);
    final Preference preference = new Preference(mContext);
    preference.setEnabled(true);
    when(screen.findPreference(anyString())).thenReturn(preference);
    mPreferenceController.setAvailability(DISABLED_DEPENDENT_SETTING);
    mPreferenceController.displayPreference(screen);
    assertThat(preference.isEnabled()).isFalse();
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) Test(org.junit.Test)

Example 47 with PreferenceScreen

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

the class ConnectedDeviceGroupControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = RuntimeEnvironment.application;
    mPreference = new Preference(mContext);
    mPreference.setKey(PREFERENCE_KEY_1);
    mPackageManager = (ShadowApplicationPackageManager) Shadows.shadowOf(mContext.getPackageManager());
    mPreferenceGroup = spy(new PreferenceScreen(mContext, null));
    when(mPreferenceGroup.getPreferenceManager()).thenReturn(mPreferenceManager);
    doReturn(mContext).when(mDashboardFragment).getContext();
    mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
    mConnectedDeviceGroupController = new ConnectedDeviceGroupController(mContext);
    mConnectedDeviceGroupController.init(mConnectedBluetoothDeviceUpdater, mConnectedUsbDeviceUpdater, mConnectedDockUpdater);
    mConnectedDeviceGroupController.mPreferenceGroup = mPreferenceGroup;
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) Before(org.junit.Before)

Example 48 with PreferenceScreen

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

the class RestrictAppPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    final List<AppOpsManager.OpEntry> allowOps = new ArrayList<>();
    allowOps.add(new AppOpsManager.OpEntry(AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, AppOpsManager.MODE_ALLOWED, Collections.emptyMap()));
    final List<AppOpsManager.OpEntry> restrictedOps = new ArrayList<>();
    restrictedOps.add(new AppOpsManager.OpEntry(AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, AppOpsManager.MODE_IGNORED, Collections.emptyMap()));
    mAllowedPackageOps = new AppOpsManager.PackageOps(ALLOWED_PACKAGE_NAME, ALLOWED_UID, allowOps);
    mRestrictedPackageOps = new AppOpsManager.PackageOps(RESTRICTED_PACKAGE_NAME, RESTRICTED_UID, restrictedOps);
    mOtherUserPackageOps = new AppOpsManager.PackageOps(RESTRICTED_PACKAGE_NAME, OTHER_USER_UID, restrictedOps);
    mContext = spy(Robolectric.setupActivity(Activity.class));
    doReturn(mAppOpsManager).when(mContext).getSystemService(Context.APP_OPS_SERVICE);
    doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
    doReturn(mContext).when(mFragment).getContext();
    mPackageOpsList = new ArrayList<>();
    mPreference = new Preference(mContext);
    mPreference.setKey(RestrictAppPreferenceController.KEY_RESTRICT_APP);
    mPreferenceScreen = spy(new PreferenceScreen(mContext, null));
    when(mPreferenceScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
    when(mPreferenceScreen.getContext()).thenReturn(mContext);
    when(mPreferenceScreen.findPreference(RestrictAppPreferenceController.KEY_RESTRICT_APP)).thenReturn(mPreference);
    final List<UserHandle> userHandles = new ArrayList<>();
    userHandles.add(new UserHandle(0));
    doReturn(userHandles).when(mUserManager).getUserProfiles();
}
Also used : AppOpsManager(android.app.AppOpsManager) PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 49 with PreferenceScreen

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

the class HighlightablePreferenceGroupAdapterTest method adjustInitialExpandedChildCount_hasCountOverride_shouldDoNothing.

@Test
public void adjustInitialExpandedChildCount_hasCountOverride_shouldDoNothing() {
    when(mFragment.getInitialExpandedChildCount()).thenReturn(10);
    final PreferenceScreen screen = mock(PreferenceScreen.class);
    when(mFragment.getPreferenceScreen()).thenReturn(screen);
    HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(mFragment);
    verify(mFragment).getInitialExpandedChildCount();
    verify(screen).setInitialExpandedChildrenCount(10);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Test(org.junit.Test)

Example 50 with PreferenceScreen

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

the class HighlightablePreferenceGroupAdapterTest method adjustInitialExpandedChildCount_noKeyOrChildCountOverride_shouldDoNothing.

@Test
public void adjustInitialExpandedChildCount_noKeyOrChildCountOverride_shouldDoNothing() {
    final Bundle args = new Bundle();
    when(mFragment.getArguments()).thenReturn(args);
    when(mFragment.getInitialExpandedChildCount()).thenReturn(-1);
    final PreferenceScreen screen = mock(PreferenceScreen.class);
    when(mFragment.getPreferenceScreen()).thenReturn(screen);
    HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(mFragment);
    verify(mFragment).getInitialExpandedChildCount();
    verifyZeroInteractions(screen);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Bundle(android.os.Bundle) Test(org.junit.Test)

Aggregations

PreferenceScreen (androidx.preference.PreferenceScreen)244 Preference (androidx.preference.Preference)81 Test (org.junit.Test)60 Context (android.content.Context)36 PreferenceManager (androidx.preference.PreferenceManager)36 ContentResolver (android.content.ContentResolver)25 PreferenceCategory (androidx.preference.PreferenceCategory)24 Bundle (android.os.Bundle)20 ArrayList (java.util.ArrayList)20 SwitchPreference (androidx.preference.SwitchPreference)19 Resources (android.content.res.Resources)18 Before (org.junit.Before)17 ListPreference (androidx.preference.ListPreference)14 PackageManager (android.content.pm.PackageManager)13 PreferenceGroup (androidx.preference.PreferenceGroup)13 ApplicationInfo (android.content.pm.ApplicationInfo)9 VisibleForTesting (androidx.annotation.VisibleForTesting)9 List (java.util.List)9 UserManager (android.os.UserManager)8 StorageItemPreference (com.android.settings.deviceinfo.StorageItemPreference)8