Search in sources :

Example 1 with ShadowUserManager

use of com.android.settings.testutils.shadow.ShadowUserManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AccountDetailDashboardFragmentTest method onResume_accountMissing_shouldFinish.

@Test
public void onResume_accountMissing_shouldFinish() {
    ShadowUserManager userManager = Shadow.extract(mContext.getSystemService(UserManager.class));
    userManager.addUserProfile(new UserHandle(1));
    ShadowAccountManager.addAccountForUser(1, new Account("test@test.com", "com.test"));
    mFragment.finishIfAccountMissing();
    verify(mFragment).finish();
}
Also used : ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) Account(android.accounts.Account) UserManager(android.os.UserManager) ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) UserHandle(android.os.UserHandle) Test(org.junit.Test)

Example 2 with ShadowUserManager

use of com.android.settings.testutils.shadow.ShadowUserManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class MobileNetworkPreferenceControllerTest method wifiOnly_prefIsNotAvailable.

@Test
public void wifiOnly_prefIsNotAvailable() {
    ShadowUserManager userManager = extract(mContext.getSystemService(UserManager.class));
    userManager.setIsAdminUser(true);
    ShadowConnectivityManager connectivityManager = extract(mContext.getSystemService(ConnectivityManager.class));
    connectivityManager.setNetworkSupported(ConnectivityManager.TYPE_MOBILE, false);
    mController = new MobileNetworkPreferenceController(mContext);
    assertThat(mController.isAvailable()).isFalse();
}
Also used : ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) UserManager(android.os.UserManager) ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) ConnectivityManager(android.net.ConnectivityManager) ShadowConnectivityManager(com.android.settings.testutils.shadow.ShadowConnectivityManager) ShadowConnectivityManager(com.android.settings.testutils.shadow.ShadowConnectivityManager) Test(org.junit.Test)

Example 3 with ShadowUserManager

use of com.android.settings.testutils.shadow.ShadowUserManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class MobileNetworkPreferenceControllerTest method secondaryUser_prefIsNotAvailable.

@Test
public void secondaryUser_prefIsNotAvailable() {
    ShadowUserManager userManager = extract(mContext.getSystemService(UserManager.class));
    userManager.setIsAdminUser(false);
    ShadowConnectivityManager connectivityManager = extract(mContext.getSystemService(ConnectivityManager.class));
    connectivityManager.setNetworkSupported(ConnectivityManager.TYPE_MOBILE, true);
    mController = new MobileNetworkPreferenceController(mContext);
    assertThat(mController.isAvailable()).isFalse();
}
Also used : ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) UserManager(android.os.UserManager) ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) ConnectivityManager(android.net.ConnectivityManager) ShadowConnectivityManager(com.android.settings.testutils.shadow.ShadowConnectivityManager) ShadowConnectivityManager(com.android.settings.testutils.shadow.ShadowConnectivityManager) Test(org.junit.Test)

Example 4 with ShadowUserManager

use of com.android.settings.testutils.shadow.ShadowUserManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PermissionBarChartPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    final Context context = RuntimeEnvironment.application;
    final UserManager userManager = context.getSystemService(UserManager.class);
    final ShadowUserManager shadowUserManager = Shadow.extract(userManager);
    final ShadowAccessibilityManager accessibilityManager = Shadow.extract(AccessibilityManager.getInstance(context));
    accessibilityManager.setEnabledAccessibilityServiceList(new ArrayList<>());
    shadowUserManager.addProfile(new UserInfo(123, null, 0));
    when(FakeFeatureFactory.setupForTest().securityFeatureProvider.getLockPatternUtils(any(Context.class))).thenReturn(mLockPatternUtils);
    mController = spy(new PermissionBarChartPreferenceController(context, "test_key"));
    mFragment = spy(FragmentController.of(new PrivacyDashboardFragment()).create().start().get());
    mController.setFragment(mFragment);
    mPreference = spy(new BarChartPreference(context));
    when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn((BarChartPreference) mPreference);
}
Also used : Context(android.content.Context) ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) ShadowAccessibilityManager(org.robolectric.shadows.ShadowAccessibilityManager) BarChartPreference(com.android.settingslib.widget.BarChartPreference) UserManager(android.os.UserManager) ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) UserInfo(android.content.pm.UserInfo) Before(org.junit.Before)

Example 5 with ShadowUserManager

use of com.android.settings.testutils.shadow.ShadowUserManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ExternalSourcesDetailsTest method refreshUi_bothUnknownSourcesUserRestrictions_disableSwitchPreference.

@Test
public void refreshUi_bothUnknownSourcesUserRestrictions_disableSwitchPreference() {
    // Mocks set up
    final ExternalSourcesDetails fragment = new ExternalSourcesDetails();
    final ContextWrapper context = RuntimeEnvironment.application;
    final UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    final ShadowUserManager shadowUserManager = Shadow.extract(userManager);
    ReflectionHelpers.setField(fragment, "mSwitchPref", mSwitchPref);
    ReflectionHelpers.setField(fragment, "mPackageInfo", mPackageInfo);
    mPackageInfo.applicationInfo = new ApplicationInfo();
    ReflectionHelpers.setField(fragment, "mUserManager", userManager);
    ReflectionHelpers.setField(mSwitchPref, "mHelper", mHelper);
    final AppStateInstallAppsBridge appBridge = mock(AppStateInstallAppsBridge.class);
    ReflectionHelpers.setField(fragment, "mAppBridge", appBridge);
    when(appBridge.createInstallAppsStateFor(nullable(String.class), anyInt())).thenReturn(mock(InstallAppsState.class));
    // Test restriction set up
    shadowUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()), UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY, true);
    shadowUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()), UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, true);
    doAnswer((answer) -> {
        when(mSwitchPref.isDisabledByAdmin()).thenReturn(true);
        return null;
    }).when(mSwitchPref).checkRestrictionAndSetDisabled(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY);
    // Code execution
    assertThat(fragment.refreshUi()).isTrue();
    // Assertions
    assertThat(userManager.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY, UserHandle.of(UserHandle.myUserId()))).isTrue();
    assertThat(userManager.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, UserHandle.of(UserHandle.myUserId()))).isTrue();
    assertThat(mSwitchPref.isDisabledByAdmin()).isTrue();
}
Also used : ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) AppStateInstallAppsBridge(com.android.settings.applications.AppStateInstallAppsBridge) UserManager(android.os.UserManager) ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) ApplicationInfo(android.content.pm.ApplicationInfo) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ContextWrapper(android.content.ContextWrapper) InstallAppsState(com.android.settings.applications.AppStateInstallAppsBridge.InstallAppsState) Test(org.junit.Test)

Aggregations

UserManager (android.os.UserManager)12 ShadowUserManager (com.android.settings.testutils.shadow.ShadowUserManager)12 Test (org.junit.Test)11 UserHandle (android.os.UserHandle)4 ComponentName (android.content.ComponentName)3 ContextWrapper (android.content.ContextWrapper)3 ApplicationInfo (android.content.pm.ApplicationInfo)3 UserInfo (android.content.pm.UserInfo)3 AppStateInstallAppsBridge (com.android.settings.applications.AppStateInstallAppsBridge)3 InstallAppsState (com.android.settings.applications.AppStateInstallAppsBridge.InstallAppsState)3 EnforcedAdmin (com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Account (android.accounts.Account)2 ConnectivityManager (android.net.ConnectivityManager)2 ShadowConnectivityManager (com.android.settings.testutils.shadow.ShadowConnectivityManager)2 ShadowDevicePolicyManager (com.android.settings.testutils.shadow.ShadowDevicePolicyManager)2 Context (android.content.Context)1 ViewGroup (android.view.ViewGroup)1 FrameLayout (android.widget.FrameLayout)1 TextView (android.widget.TextView)1