Search in sources :

Example 1 with AppStateInstallAppsBridge

use of com.android.settings.applications.AppStateInstallAppsBridge 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)

Example 2 with AppStateInstallAppsBridge

use of com.android.settings.applications.AppStateInstallAppsBridge 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 3 with AppStateInstallAppsBridge

use of com.android.settings.applications.AppStateInstallAppsBridge 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 4 with AppStateInstallAppsBridge

use of com.android.settings.applications.AppStateInstallAppsBridge in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ExternalSourcesDetailsTest method refreshUi_hasApplicationInfo_shouldReturnTrue.

@Test
public void refreshUi_hasApplicationInfo_shouldReturnTrue() {
    ReflectionHelpers.setField(mFragment, "mPackageInfo", mPackageInfo);
    mPackageInfo.applicationInfo = new ApplicationInfo();
    final AppStateInstallAppsBridge appBridge = mock(AppStateInstallAppsBridge.class);
    ReflectionHelpers.setField(mFragment, "mAppBridge", appBridge);
    when(appBridge.createInstallAppsStateFor(nullable(String.class), anyInt())).thenReturn(mock(InstallAppsState.class));
    mFragment.refreshUi();
    assertThat(mFragment.refreshUi()).isTrue();
    assertThat(mSwitchPref.isDisabledByAdmin()).isFalse();
}
Also used : AppStateInstallAppsBridge(com.android.settings.applications.AppStateInstallAppsBridge) ApplicationInfo(android.content.pm.ApplicationInfo) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InstallAppsState(com.android.settings.applications.AppStateInstallAppsBridge.InstallAppsState) Test(org.junit.Test)

Example 5 with AppStateInstallAppsBridge

use of com.android.settings.applications.AppStateInstallAppsBridge in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ExternalSourceDetailPreferenceController method isPotentialAppSource.

@VisibleForTesting
boolean isPotentialAppSource() {
    final PackageInfo packageInfo = mParent.getPackageInfo();
    if (packageInfo == null) {
        return false;
    }
    AppStateInstallAppsBridge.InstallAppsState appState = new AppStateInstallAppsBridge(mContext, null, null).createInstallAppsStateFor(mPackageName, packageInfo.applicationInfo.uid);
    return appState.isPotentialAppSource();
}
Also used : AppStateInstallAppsBridge(com.android.settings.applications.AppStateInstallAppsBridge) PackageInfo(android.content.pm.PackageInfo) VisibleForTesting(androidx.annotation.VisibleForTesting)

Aggregations

AppStateInstallAppsBridge (com.android.settings.applications.AppStateInstallAppsBridge)7 InstallAppsState (com.android.settings.applications.AppStateInstallAppsBridge.InstallAppsState)5 ApplicationInfo (android.content.pm.ApplicationInfo)4 UserManager (android.os.UserManager)4 Test (org.junit.Test)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 ContextWrapper (android.content.ContextWrapper)3 ShadowUserManager (com.android.settings.testutils.shadow.ShadowUserManager)3 ActivityManager (android.app.ActivityManager)1 Context (android.content.Context)1 PackageInfo (android.content.pm.PackageInfo)1 UserHandle (android.os.UserHandle)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1