Search in sources :

Example 6 with ShadowUserManager

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

the class ExternalSourcesDetailsTest method refreshUi_userRestrictionsUnknownSourcesGlobally_disablesSwitchPreference.

@Test
public void refreshUi_userRestrictionsUnknownSourcesGlobally_disablesSwitchPreference() {
    // 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);
    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(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)

Example 7 with ShadowUserManager

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

the class ExternalSourcesDetailsTest method refreshUi_userRestrictionsUnknownSources_disablesSwitchPreference.

@Test
public void refreshUi_userRestrictionsUnknownSources_disablesSwitchPreference() {
    // 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, true);
    doAnswer((answer) -> {
        when(mSwitchPref.isDisabledByAdmin()).thenReturn(true);
        return null;
    }).when(mSwitchPref).checkRestrictionAndSetDisabled(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES);
    // Code execution
    assertThat(fragment.refreshUi()).isTrue();
    // Assertions
    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)

Example 8 with ShadowUserManager

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

the class ActionDisabledByAdminDialogHelperTest method testMaybeSetLearnMoreButton.

@Test
public void testMaybeSetLearnMoreButton() {
    final UserManager userManager = RuntimeEnvironment.application.getSystemService(UserManager.class);
    final ShadowUserManager userManagerShadow = Shadow.extract(userManager);
    final ComponentName component = new ComponentName("some.package.name", "some.package.name.SomeClass");
    mHelper.mEnforcedAdmin = new EnforcedAdmin(component, UserHandle.of(123));
    // Set up for shadow call.
    userManagerShadow.getSameProfileGroupIds().put(123, 0);
    // Test that the button is shown when user IDs are in the same profile group
    AlertDialog.Builder builder = mock(AlertDialog.Builder.class);
    mHelper.maybeSetLearnMoreButton(builder);
    verify(builder).setNeutralButton(anyInt(), any());
    // Test that the button is not shown when user IDs are not in the same profile group
    userManagerShadow.getSameProfileGroupIds().clear();
    builder = mock(AlertDialog.Builder.class);
    mHelper.maybeSetLearnMoreButton(builder);
    verify(builder, never()).setNeutralButton(anyInt(), any());
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) UserManager(android.os.UserManager) ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) ComponentName(android.content.ComponentName) EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin) Test(org.junit.Test)

Example 9 with ShadowUserManager

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

the class ActionDisabledByAdminDialogHelperTest method testSetAdminSupportDetailsNotAdmin.

@Test
public void testSetAdminSupportDetailsNotAdmin() {
    final ShadowDevicePolicyManager dpmShadow = ShadowDevicePolicyManager.getShadow();
    final UserManager userManager = RuntimeEnvironment.application.getSystemService(UserManager.class);
    final ShadowUserManager userManagerShadow = Shadow.extract(userManager);
    final ComponentName component = new ComponentName("some.package.name", "some.package.name.SomeClass");
    final EnforcedAdmin admin = new EnforcedAdmin(component, UserHandle.of(123));
    dpmShadow.setShortSupportMessageForUser(component, 123, "some message");
    dpmShadow.setIsAdminActiveAsUser(false);
    userManagerShadow.addProfile(new UserInfo(123, null, 0));
    mHelper.setAdminSupportDetails(mActivity, null, admin);
    assertNull(admin.component);
}
Also used : ShadowDevicePolicyManager(com.android.settings.testutils.shadow.ShadowDevicePolicyManager) ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) UserManager(android.os.UserManager) ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) ComponentName(android.content.ComponentName) EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin) UserInfo(android.content.pm.UserInfo) Test(org.junit.Test)

Example 10 with ShadowUserManager

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

the class ActionDisabledByAdminDialogHelperTest method testSetAdminSupportDetails.

@Test
public void testSetAdminSupportDetails() {
    final ShadowDevicePolicyManager dpmShadow = ShadowDevicePolicyManager.getShadow();
    final UserManager userManager = RuntimeEnvironment.application.getSystemService(UserManager.class);
    final ShadowUserManager userManagerShadow = Shadow.extract(userManager);
    final ViewGroup view = new FrameLayout(mActivity);
    final ComponentName component = new ComponentName("some.package.name", "some.package.name.SomeClass");
    final EnforcedAdmin admin = new EnforcedAdmin(component, UserHandle.of(123));
    final TextView textView = new TextView(mActivity);
    textView.setId(R.id.admin_support_msg);
    view.addView(textView);
    dpmShadow.setShortSupportMessageForUser(component, 123, "some message");
    dpmShadow.setIsAdminActiveAsUser(true);
    userManagerShadow.addProfile(new UserInfo(123, null, 0));
    userManagerShadow.addUserProfile(new UserHandle(123));
    ShadowProcess.setUid(Process.SYSTEM_UID);
    mHelper.setAdminSupportDetails(mActivity, view, admin);
    assertNotNull(admin.component);
    assertEquals("some message", Shadows.shadowOf(textView).innerText());
}
Also used : ShadowDevicePolicyManager(com.android.settings.testutils.shadow.ShadowDevicePolicyManager) ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) UserManager(android.os.UserManager) ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) UserHandle(android.os.UserHandle) ComponentName(android.content.ComponentName) EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin) TextView(android.widget.TextView) UserInfo(android.content.pm.UserInfo) Test(org.junit.Test)

Aggregations

UserManager (android.os.UserManager)22 ShadowUserManager (com.android.settings.testutils.shadow.ShadowUserManager)22 Test (org.junit.Test)21 UserHandle (android.os.UserHandle)7 ComponentName (android.content.ComponentName)6 ContextWrapper (android.content.ContextWrapper)6 ApplicationInfo (android.content.pm.ApplicationInfo)6 AppStateInstallAppsBridge (com.android.settings.applications.AppStateInstallAppsBridge)6 InstallAppsState (com.android.settings.applications.AppStateInstallAppsBridge.InstallAppsState)6 EnforcedAdmin (com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)6 ShadowDevicePolicyManager (com.android.settings.testutils.shadow.ShadowDevicePolicyManager)5 Account (android.accounts.Account)4 UserInfo (android.content.pm.UserInfo)4 ViewGroup (android.view.ViewGroup)4 FrameLayout (android.widget.FrameLayout)4 TextView (android.widget.TextView)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 ConnectivityManager (android.net.ConnectivityManager)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 ShadowConnectivityManager (com.android.settings.testutils.shadow.ShadowConnectivityManager)2