Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4ee8d6de authored by Kholoud Mohamed's avatar Kholoud Mohamed Committed by Android (Google) Code Review
Browse files

Merge "Fix failing tests" into sc-dev

parents 970e76fd be0a96bd
Loading
Loading
Loading
Loading
+10 −20
Original line number Diff line number Diff line
@@ -20,11 +20,10 @@ import static com.google.common.truth.Truth.assertThat;

import static org.robolectric.Shadows.shadowOf;

import android.app.AppOpsManager;
import android.content.Context;
import android.content.PermissionChecker;
import android.content.pm.CrossProfileApps;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.content.pm.UserInfo;
import android.os.UserManager;

@@ -37,19 +36,18 @@ import com.google.common.collect.ImmutableList;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.shadows.ShadowPermissionChecker;

@RunWith(RobolectricTestRunner.class)
public class InteractAcrossProfilesDetailsTest {

    private static final int PERSONAL_PROFILE_ID = 0;
    private static final int WORK_PROFILE_ID = 10;
    private static final int PACKAGE_UID = 0;
    private static final String CROSS_PROFILE_PACKAGE_NAME = "crossProfilePackage";
    public static final String INTERACT_ACROSS_PROFILES_PERMISSION =
            "android.permission.INTERACT_ACROSS_PROFILES";

    private final Context mContext = ApplicationProvider.getApplicationContext();
    private final AppOpsManager mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
    private final PackageManager mPackageManager = mContext.getPackageManager();
    private final UserManager mUserManager = mContext.getSystemService(UserManager.class);
    private final CrossProfileApps mCrossProfileApps = mContext.getSystemService(
@@ -68,10 +66,10 @@ public class InteractAcrossProfilesDetailsTest {
                WORK_PROFILE_ID, ImmutableList.of(CROSS_PROFILE_PACKAGE_NAME));
        shadowOf(mCrossProfileApps).addCrossProfilePackage(
                CROSS_PROFILE_PACKAGE_NAME);
        String appOp = AppOpsManager.permissionToOp(INTERACT_ACROSS_PROFILES_PERMISSION);
        shadowOf(mAppOpsManager).setMode(
                appOp, PACKAGE_UID, CROSS_PROFILE_PACKAGE_NAME, AppOpsManager.MODE_ALLOWED);
        shadowOf(mPackageManager).addPermissionInfo(createCrossProfilesPermissionInfo());
        ShadowPermissionChecker.setResult(
                CROSS_PROFILE_PACKAGE_NAME,
                INTERACT_ACROSS_PROFILES_PERMISSION,
                PermissionChecker.PERMISSION_GRANTED);

        assertThat(InteractAcrossProfilesDetails.getPreferenceSummary(
                mContext, CROSS_PROFILE_PACKAGE_NAME))
@@ -91,11 +89,10 @@ public class InteractAcrossProfilesDetailsTest {
                WORK_PROFILE_ID, ImmutableList.of(CROSS_PROFILE_PACKAGE_NAME));
        shadowOf(mCrossProfileApps).addCrossProfilePackage(
                CROSS_PROFILE_PACKAGE_NAME);
        String appOp = AppOpsManager.permissionToOp(INTERACT_ACROSS_PROFILES_PERMISSION);
        shadowOf(mAppOpsManager).setMode(
                appOp, PACKAGE_UID, CROSS_PROFILE_PACKAGE_NAME, AppOpsManager.MODE_IGNORED);
        shadowOf(mPackageManager).addPermissionInfo(createCrossProfilesPermissionInfo());

        ShadowPermissionChecker.setResult(
                CROSS_PROFILE_PACKAGE_NAME,
                INTERACT_ACROSS_PROFILES_PERMISSION,
                PermissionChecker.PERMISSION_SOFT_DENIED);
        assertThat(InteractAcrossProfilesDetails.getPreferenceSummary(
                mContext, CROSS_PROFILE_PACKAGE_NAME))
                .isEqualTo(mContext.getString(
@@ -114,11 +111,4 @@ public class InteractAcrossProfilesDetailsTest {
                .isEqualTo(mContext.getString(
                        R.string.interact_across_profiles_summary_not_allowed));
    }

    private PermissionInfo createCrossProfilesPermissionInfo() {
        PermissionInfo permissionInfo = new PermissionInfo();
        permissionInfo.name = INTERACT_ACROSS_PROFILES_PERMISSION;
        permissionInfo.protectionLevel = PermissionInfo.PROTECTION_FLAG_APPOP;
        return permissionInfo;
    }
}
+8 −12
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertTrue;
import static org.robolectric.Shadows.shadowOf;

import android.app.AppOpsManager;
import android.content.Context;
import android.content.PermissionChecker;
import android.content.pm.ApplicationInfo;
@@ -51,7 +50,6 @@ public class InteractAcrossProfilesSettingsTest {
    private static final int PERSONAL_PROFILE_ID = 0;
    private static final int WORK_PROFILE_ID = 10;
    private static final int WORK_UID = UserHandle.PER_USER_RANGE * WORK_PROFILE_ID;
    private static final int PACKAGE_UID = 0;

    private static final String PERSONAL_CROSS_PROFILE_PACKAGE = "personalCrossProfilePackage";
    private static final String PERSONAL_NON_CROSS_PROFILE_PACKAGE =
@@ -71,7 +69,6 @@ public class InteractAcrossProfilesSettingsTest {
    private final UserManager mUserManager = mContext.getSystemService(UserManager.class);
    private final CrossProfileApps mCrossProfileApps =
            mContext.getSystemService(CrossProfileApps.class);
    private final AppOpsManager mAppOpsManager = mContext.getSystemService(AppOpsManager.class);

    @Test
    public void collectConfigurableApps_fromPersonal_returnsCombinedPackages() {
@@ -84,8 +81,8 @@ public class InteractAcrossProfilesSettingsTest {
                PERSONAL_PROFILE_ID, PERSONAL_PROFILE_INSTALLED_PACKAGES);
        shadowOf(mPackageManager).setInstalledPackagesForUserId(
                WORK_PROFILE_ID, WORK_PROFILE_INSTALLED_PACKAGES);
        installCrossProfilePackage(PERSONAL_PROFILE_ID, PERSONAL_CROSS_PROFILE_PACKAGE);
        installCrossProfilePackage(WORK_PROFILE_ID, WORK_CROSS_PROFILE_PACKAGE);
        installCrossProfilePackage(PERSONAL_CROSS_PROFILE_PACKAGE);
        installCrossProfilePackage(WORK_CROSS_PROFILE_PACKAGE);

        List<Pair<ApplicationInfo, UserHandle>> apps =
                InteractAcrossProfilesSettings.collectConfigurableApps(
@@ -110,8 +107,8 @@ public class InteractAcrossProfilesSettingsTest {
                PERSONAL_PROFILE_ID, PERSONAL_PROFILE_INSTALLED_PACKAGES);
        shadowOf(mPackageManager).setInstalledPackagesForUserId(
                WORK_PROFILE_ID, WORK_PROFILE_INSTALLED_PACKAGES);
        installCrossProfilePackage(PERSONAL_PROFILE_ID, PERSONAL_CROSS_PROFILE_PACKAGE);
        installCrossProfilePackage(WORK_PROFILE_ID, WORK_CROSS_PROFILE_PACKAGE);
        installCrossProfilePackage(PERSONAL_CROSS_PROFILE_PACKAGE);
        installCrossProfilePackage(WORK_CROSS_PROFILE_PACKAGE);

        List<Pair<ApplicationInfo, UserHandle>> apps =
                InteractAcrossProfilesSettings.collectConfigurableApps(
@@ -130,7 +127,7 @@ public class InteractAcrossProfilesSettingsTest {
                PERSONAL_PROFILE_ID, "personal-profile"/* name */, 0/* flags */);
        shadowOf(mPackageManager).setInstalledPackagesForUserId(
                PERSONAL_PROFILE_ID, PERSONAL_PROFILE_INSTALLED_PACKAGES);
        installCrossProfilePackage(PERSONAL_PROFILE_ID, PERSONAL_CROSS_PROFILE_PACKAGE);
        installCrossProfilePackage(PERSONAL_CROSS_PROFILE_PACKAGE);

        List<Pair<ApplicationInfo, UserHandle>> apps =
                InteractAcrossProfilesSettings.collectConfigurableApps(
@@ -150,10 +147,9 @@ public class InteractAcrossProfilesSettingsTest {
                PERSONAL_PROFILE_ID, PERSONAL_PROFILE_INSTALLED_PACKAGES);
        shadowOf(mPackageManager).setInstalledPackagesForUserId(
                WORK_PROFILE_ID, WORK_PROFILE_INSTALLED_PACKAGES);
        installCrossProfilePackage(PERSONAL_PROFILE_ID, PERSONAL_CROSS_PROFILE_PACKAGE);
        installCrossProfilePackage(WORK_PROFILE_ID, WORK_CROSS_PROFILE_PACKAGE);
        installCrossProfilePackage(PERSONAL_CROSS_PROFILE_PACKAGE);
        installCrossProfilePackage(WORK_CROSS_PROFILE_PACKAGE);
        shadowOf(mCrossProfileApps).addCrossProfilePackage(PERSONAL_CROSS_PROFILE_PACKAGE);
        String appOp = AppOpsManager.permissionToOp(INTERACT_ACROSS_PROFILES_PERMISSION);
        ShadowPermissionChecker.setResult(
                PERSONAL_CROSS_PROFILE_PACKAGE,
                INTERACT_ACROSS_PROFILES_PERMISSION,
@@ -169,7 +165,7 @@ public class InteractAcrossProfilesSettingsTest {
        assertThat(numOfApps).isEqualTo(1);
    }

    private void installCrossProfilePackage(int profileId, String packageName) {
    private void installCrossProfilePackage(String packageName) {
        PackageInfo personalPackageInfo = shadowOf(mPackageManager).getInternalMutablePackageInfo(
                packageName);
        personalPackageInfo.requestedPermissions = new String[]{