Device management info: Refer to current user, not primary user
The device management info page should show information about the
current user's policies, not the primary user's.
Bug: 32692748
Test: m RunSettingsRoboTests
Change-Id: I5d8afa7fae1c0f3a4da78b085365882827e6721b
(cherry picked from commit b836da263d
)
This commit is contained in:
@@ -22,6 +22,7 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.Build;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
@@ -35,7 +36,6 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.android.settings.testutils.ApplicationTestUtils.buildInfo;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
@@ -76,24 +76,25 @@ public final class AppWithAdminGrantedPermissionsCounterTest {
|
||||
private final String PERMISSION_2 = "some.permission.2";
|
||||
private final String[] PERMISSIONS = {PERMISSION_1, PERMISSION_2};
|
||||
|
||||
@Mock private UserManager mUserManager;
|
||||
@Mock private Context mContext;
|
||||
@Mock private PackageManagerWrapper mPackageManager;
|
||||
@Mock private IPackageManagerWrapper mPackageManagerService;
|
||||
@Mock private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
private List<UserInfo> mUsersToCount;
|
||||
|
||||
private int mAppCount = -1;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
}
|
||||
|
||||
private void verifyCountInstalledAppsAcrossAllUsers(boolean async) throws Exception {
|
||||
private void verifyCountInstalledApps(boolean async) throws Exception {
|
||||
// There are two users.
|
||||
mUsersToCount = Arrays.asList(
|
||||
when(mUserManager.getProfiles(UserHandle.myUserId())).thenReturn(Arrays.asList(
|
||||
new UserInfo(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN),
|
||||
new UserInfo(MANAGED_PROFILE_ID, "managed profile", 0));
|
||||
new UserInfo(MANAGED_PROFILE_ID, "managed profile", 0)));
|
||||
|
||||
// The first user has five apps installed:
|
||||
// * app1 uses run-time permissions. It has been granted one of the permissions by the
|
||||
@@ -190,8 +191,8 @@ public final class AppWithAdminGrantedPermissionsCounterTest {
|
||||
}
|
||||
assertThat(mAppCount).isEqualTo(3);
|
||||
|
||||
// Verify that installed packages were retrieved for the users returned by
|
||||
// InstalledAppCounterTestable.getUsersToCount() only.
|
||||
// Verify that installed packages were retrieved the current user and the user's managed
|
||||
// profile only.
|
||||
verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(), eq(MAIN_USER_ID));
|
||||
verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(),
|
||||
eq(MANAGED_PROFILE_ID));
|
||||
@@ -200,13 +201,13 @@ public final class AppWithAdminGrantedPermissionsCounterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountInstalledAppsAcrossAllUsersSync() throws Exception {
|
||||
verifyCountInstalledAppsAcrossAllUsers(false /* async */);
|
||||
public void testCountInstalledAppsSync() throws Exception {
|
||||
verifyCountInstalledApps(false /* async */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountInstalledAppsAcrossAllUsersAync() throws Exception {
|
||||
verifyCountInstalledAppsAcrossAllUsers(true /* async */);
|
||||
public void testCountInstalledAppsAync() throws Exception {
|
||||
verifyCountInstalledApps(true /* async */);
|
||||
}
|
||||
|
||||
private class AppWithAdminGrantedPermissionsCounterTestable extends
|
||||
@@ -220,10 +221,5 @@ public final class AppWithAdminGrantedPermissionsCounterTest {
|
||||
protected void onCountComplete(int num) {
|
||||
mAppCount = num;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<UserInfo> getUsersToCount() {
|
||||
return mUsersToCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -190,7 +190,7 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
private void setUpUsersAndInstalledApps() {
|
||||
when(mUserManager.getUsers(true)).thenReturn(Arrays.asList(
|
||||
when(mUserManager.getProfiles(UserHandle.myUserId())).thenReturn(Arrays.asList(
|
||||
new UserInfo(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN),
|
||||
new UserInfo(MANAGED_PROFILE_ID, "managed profile", 0)));
|
||||
|
||||
|
@@ -78,7 +78,6 @@ public final class InstalledAppCounterTest {
|
||||
@Mock private UserManager mUserManager;
|
||||
@Mock private Context mContext;
|
||||
@Mock private PackageManagerWrapper mPackageManager;
|
||||
private List<UserInfo> mUsersToCount;
|
||||
|
||||
private int mInstalledAppCount = -1;
|
||||
|
||||
@@ -99,9 +98,9 @@ public final class InstalledAppCounterTest {
|
||||
|
||||
private void testCountInstalledAppsAcrossAllUsers(boolean async) {
|
||||
// There are two users.
|
||||
mUsersToCount = Arrays.asList(
|
||||
when(mUserManager.getProfiles(UserHandle.myUserId())).thenReturn(Arrays.asList(
|
||||
new UserInfo(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN),
|
||||
new UserInfo(MANAGED_PROFILE_ID, "managed profile", 0));
|
||||
new UserInfo(MANAGED_PROFILE_ID, "managed profile", 0)));
|
||||
|
||||
// The first user has four apps installed:
|
||||
// * app1 is an updated system app. It should be counted.
|
||||
@@ -159,8 +158,8 @@ public final class InstalledAppCounterTest {
|
||||
count(InstalledAppCounter.IGNORE_INSTALL_REASON, async);
|
||||
assertThat(mInstalledAppCount).isEqualTo(5);
|
||||
|
||||
// Verify that installed packages were retrieved for the users returned by
|
||||
// InstalledAppCounterTestable.getUsersToCount() only.
|
||||
// Verify that installed packages were retrieved the current user and the user's managed
|
||||
// profile only.
|
||||
verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(), eq(MAIN_USER_ID));
|
||||
verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(),
|
||||
eq(MANAGED_PROFILE_ID));
|
||||
@@ -205,11 +204,6 @@ public final class InstalledAppCounterTest {
|
||||
protected void onCountComplete(int num) {
|
||||
mInstalledAppCount = num;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<UserInfo> getUsersToCount() {
|
||||
return mUsersToCount;
|
||||
}
|
||||
}
|
||||
|
||||
private static class IsLaunchIntentFor extends ArgumentMatcher<Intent> {
|
||||
|
@@ -36,11 +36,11 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link AlwaysOnVpnPrimaryUserPreferenceController}.
|
||||
* Tests for {@link AlwaysOnVpnCurrentUserPreferenceController}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class AlwaysOnVpnPrimaryUserPreferenceControllerTest {
|
||||
public final class AlwaysOnVpnCurrentUserPreferenceControllerTest {
|
||||
|
||||
private final String VPN_SET_DEVICE = "VPN set";
|
||||
private final String VPN_SET_PERSONAL = "VPN set in personal profile";
|
||||
@@ -49,14 +49,14 @@ public final class AlwaysOnVpnPrimaryUserPreferenceControllerTest {
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
private AlwaysOnVpnPrimaryUserPreferenceController mController;
|
||||
private AlwaysOnVpnCurrentUserPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mController = new AlwaysOnVpnPrimaryUserPreferenceController(mContext,
|
||||
mController = new AlwaysOnVpnCurrentUserPreferenceController(mContext,
|
||||
null /* lifecycle */);
|
||||
when(mContext.getString(R.string.enterprise_privacy_always_on_vpn_device))
|
||||
.thenReturn(VPN_SET_DEVICE);
|
||||
@@ -68,7 +68,7 @@ public final class AlwaysOnVpnPrimaryUserPreferenceControllerTest {
|
||||
public void testUpdateState() {
|
||||
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInCurrentUser())
|
||||
.thenReturn(true);
|
||||
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(false);
|
||||
@@ -82,11 +82,11 @@ public final class AlwaysOnVpnPrimaryUserPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInCurrentUser())
|
||||
.thenReturn(false);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInCurrentUser())
|
||||
.thenReturn(true);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
@@ -195,13 +195,13 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAlwaysOnVpnSetInPrimaryUser() {
|
||||
public void testIsAlwaysOnVpnSetInCurrentUser() {
|
||||
when(mConnectivityManger.getAlwaysOnVpnPackageForUser(MY_USER_ID)).thenReturn(null);
|
||||
assertThat(mProvider.isAlwaysOnVpnSetInPrimaryUser()).isFalse();
|
||||
assertThat(mProvider.isAlwaysOnVpnSetInCurrentUser()).isFalse();
|
||||
|
||||
when(mConnectivityManger.getAlwaysOnVpnPackageForUser(MY_USER_ID))
|
||||
.thenReturn(VPN_PACKAGE_ID);
|
||||
assertThat(mProvider.isAlwaysOnVpnSetInPrimaryUser()).isTrue();
|
||||
assertThat(mProvider.isAlwaysOnVpnSetInCurrentUser()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -230,16 +230,14 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMaximumFailedPasswordsForWipeInPrimaryUser() {
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null);
|
||||
when(mDevicePolicyManager.getDeviceOwnerUserId()).thenReturn(UserHandle.USER_NULL);
|
||||
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInPrimaryUser()).isEqualTo(0);
|
||||
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(OWNER);
|
||||
when(mDevicePolicyManager.getDeviceOwnerUserId()).thenReturn(UserHandle.USER_SYSTEM);
|
||||
when(mDevicePolicyManager.getMaximumFailedPasswordsForWipe(OWNER, UserHandle.USER_SYSTEM))
|
||||
public void testGetMaximumFailedPasswordsForWipeInCurrentUser() {
|
||||
when(mDevicePolicyManager.getProfileOwnerAsUser(MY_USER_ID)).thenReturn(null);
|
||||
when(mDevicePolicyManager.getMaximumFailedPasswordsForWipe(OWNER, MY_USER_ID))
|
||||
.thenReturn(10);
|
||||
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInPrimaryUser()).isEqualTo(10);
|
||||
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInCurrentUser()).isEqualTo(0);
|
||||
|
||||
when(mDevicePolicyManager.getProfileOwnerAsUser(MY_USER_ID)).thenReturn(OWNER);
|
||||
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInCurrentUser()).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -247,7 +245,6 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
when(mDevicePolicyManager.getProfileOwnerAsUser(MANAGED_PROFILE_USER_ID)).thenReturn(OWNER);
|
||||
when(mDevicePolicyManager.getMaximumFailedPasswordsForWipe(OWNER, MANAGED_PROFILE_USER_ID))
|
||||
.thenReturn(10);
|
||||
|
||||
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInManagedProfile()).isEqualTo(0);
|
||||
|
||||
mProfiles.add(new UserInfo(MANAGED_PROFILE_USER_ID, "", "", UserInfo.FLAG_MANAGED_PROFILE));
|
||||
|
@@ -134,7 +134,7 @@ public final class EnterprisePrivacySettingsTest {
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
EnterpriseSetDefaultAppsPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
AlwaysOnVpnPrimaryUserPreferenceController.class);
|
||||
AlwaysOnVpnCurrentUserPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
AlwaysOnVpnManagedProfilePreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
@@ -142,7 +142,7 @@ public final class EnterprisePrivacySettingsTest {
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
CaCertsPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
FailedPasswordWipePrimaryUserPreferenceController.class);
|
||||
FailedPasswordWipeCurrentUserPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
FailedPasswordWipeManagedProfilePreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(ImePreferenceController.class);
|
||||
|
@@ -27,29 +27,29 @@ import org.robolectric.annotation.Config;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link FailedPasswordWipePrimaryUserPreferenceController}.
|
||||
* Tests for {@link FailedPasswordWipeCurrentUserPreferenceController}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class FailedPasswordWipePrimaryUserPreferenceControllerTest extends
|
||||
public final class FailedPasswordWipeCurrentUserPreferenceControllerTest extends
|
||||
FailedPasswordWipePreferenceControllerTestBase {
|
||||
|
||||
private int mMaximumFailedPasswordsBeforeWipe = 0;
|
||||
|
||||
public FailedPasswordWipePrimaryUserPreferenceControllerTest() {
|
||||
super("failed_password_wipe_primary_user");
|
||||
public FailedPasswordWipeCurrentUserPreferenceControllerTest() {
|
||||
super("failed_password_wipe_current_user");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
mController = new FailedPasswordWipePrimaryUserPreferenceController(mContext,
|
||||
mController = new FailedPasswordWipeCurrentUserPreferenceController(mContext,
|
||||
null /* lifecycle */);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaximumFailedPasswordsBeforeWipe(int maximum) {
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider
|
||||
.getMaximumFailedPasswordsBeforeWipeInPrimaryUser()).thenReturn(maximum);
|
||||
.getMaximumFailedPasswordsBeforeWipeInCurrentUser()).thenReturn(maximum);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user