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
This commit is contained in:
Bartosz Fabianowski
2017-03-30 10:33:28 +02:00
parent 2b37b43821
commit b836da263d
20 changed files with 89 additions and 139 deletions

View File

@@ -100,7 +100,7 @@
android:title="@string/enterprise_privacy_wipe_device" android:title="@string/enterprise_privacy_wipe_device"
settings:multiLine="true"/> settings:multiLine="true"/>
<com.android.settings.DividerPreference <com.android.settings.DividerPreference
android:key="failed_password_wipe_primary_user" android:key="failed_password_wipe_current_user"
android:title="@string/enterprise_privacy_failed_password_wipe_device" android:title="@string/enterprise_privacy_failed_password_wipe_device"
settings:multiLine="true"/> settings:multiLine="true"/>
<com.android.settings.DividerPreference <com.android.settings.DividerPreference

View File

@@ -20,6 +20,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import java.util.List; import java.util.List;
@@ -37,7 +38,7 @@ public abstract class AppCounter extends AsyncTask<Void, Void, Integer> {
@Override @Override
protected Integer doInBackground(Void... params) { protected Integer doInBackground(Void... params) {
int count = 0; int count = 0;
for (UserInfo user : getUsersToCount()) { for (UserInfo user : mUm.getProfiles(UserHandle.myUserId())) {
final List<ApplicationInfo> list = final List<ApplicationInfo> list =
mPm.getInstalledApplicationsAsUser(PackageManager.GET_DISABLED_COMPONENTS mPm.getInstalledApplicationsAsUser(PackageManager.GET_DISABLED_COMPONENTS
| PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS
@@ -62,6 +63,5 @@ public abstract class AppCounter extends AsyncTask<Void, Void, Integer> {
} }
protected abstract void onCountComplete(int num); protected abstract void onCountComplete(int num);
protected abstract List<UserInfo> getUsersToCount();
protected abstract boolean includeInCount(ApplicationInfo info); protected abstract boolean includeInCount(ApplicationInfo info);
} }

View File

@@ -40,8 +40,8 @@ public interface ApplicationFeatureProvider {
View view); View view);
/** /**
* Calculates the total number of apps installed on the device via policy across all users * Calculates the total number of apps installed on the device via policy in the current user
* and managed profiles. * and all its managed profiles.
* *
* @param async Whether to count asynchronously in a background thread * @param async Whether to count asynchronously in a background thread
* @param callback The callback to invoke with the result * @param callback The callback to invoke with the result
@@ -49,9 +49,8 @@ public interface ApplicationFeatureProvider {
void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback); void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback);
/** /**
* Asynchronously calculates the total number of apps installed on the device, across all users * Asynchronously calculates the total number of apps installed in the current user and all its
* and managed profiles, that have been granted one or more of the given permissions by the * managed profiles that have been granted one or more of the given permissions by the admin.
* admin.
* *
* @param permissions Only consider apps that have been granted one or more of these permissions * @param permissions Only consider apps that have been granted one or more of these permissions
* by the admin, either at run-time or install-time * by the admin, either at run-time or install-time

View File

@@ -22,7 +22,6 @@ import android.content.Intent;
import android.content.pm.ComponentInfo; import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
@@ -65,8 +64,8 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
@Override @Override
public void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback) { public void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback) {
final AllUserPolicyInstalledAppCounter counter = final CurrentUserAndManagedProfilePolicyInstalledAppCounter counter =
new AllUserPolicyInstalledAppCounter(mContext, mPm, callback); new CurrentUserAndManagedProfilePolicyInstalledAppCounter(mContext, mPm, callback);
if (async) { if (async) {
counter.execute(); counter.execute();
} else { } else {
@@ -77,9 +76,9 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
@Override @Override
public void calculateNumberOfAppsWithAdminGrantedPermissions(String[] permissions, public void calculateNumberOfAppsWithAdminGrantedPermissions(String[] permissions,
boolean async, NumberOfAppsCallback callback) { boolean async, NumberOfAppsCallback callback) {
final AllUserAppWithAdminGrantedPermissionsCounter counter = final CurrentUserAndManagedProfileAppWithAdminGrantedPermissionsCounter counter =
new AllUserAppWithAdminGrantedPermissionsCounter(mContext, permissions, mPm, mPms, new CurrentUserAndManagedProfileAppWithAdminGrantedPermissionsCounter(mContext,
mDpm, callback); permissions, mPm, mPms, mDpm, callback);
if (async) { if (async) {
counter.execute(); counter.execute();
} else { } else {
@@ -120,11 +119,12 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
return activities; return activities;
} }
private static class AllUserPolicyInstalledAppCounter extends InstalledAppCounter { private static class CurrentUserAndManagedProfilePolicyInstalledAppCounter
extends InstalledAppCounter {
private NumberOfAppsCallback mCallback; private NumberOfAppsCallback mCallback;
AllUserPolicyInstalledAppCounter(Context context, PackageManagerWrapper packageManager, CurrentUserAndManagedProfilePolicyInstalledAppCounter(Context context,
NumberOfAppsCallback callback) { PackageManagerWrapper packageManager, NumberOfAppsCallback callback) {
super(context, PackageManager.INSTALL_REASON_POLICY, packageManager); super(context, PackageManager.INSTALL_REASON_POLICY, packageManager);
mCallback = callback; mCallback = callback;
} }
@@ -133,19 +133,15 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
protected void onCountComplete(int num) { protected void onCountComplete(int num) {
mCallback.onNumberOfAppsResult(num); mCallback.onNumberOfAppsResult(num);
} }
@Override
protected List<UserInfo> getUsersToCount() {
return mUm.getUsers(true /* excludeDying */);
}
} }
private static class AllUserAppWithAdminGrantedPermissionsCounter extends private static class CurrentUserAndManagedProfileAppWithAdminGrantedPermissionsCounter
AppWithAdminGrantedPermissionsCounter { extends AppWithAdminGrantedPermissionsCounter {
private NumberOfAppsCallback mCallback; private NumberOfAppsCallback mCallback;
AllUserAppWithAdminGrantedPermissionsCounter(Context context, String[] permissions, CurrentUserAndManagedProfileAppWithAdminGrantedPermissionsCounter(Context context,
PackageManagerWrapper packageManager, IPackageManagerWrapper packageManagerService, String[] permissions, PackageManagerWrapper packageManager,
IPackageManagerWrapper packageManagerService,
DevicePolicyManagerWrapper devicePolicyManager, NumberOfAppsCallback callback) { DevicePolicyManagerWrapper devicePolicyManager, NumberOfAppsCallback callback) {
super(context, permissions, packageManager, packageManagerService, devicePolicyManager); super(context, permissions, packageManager, packageManagerService, devicePolicyManager);
mCallback = callback; mCallback = callback;
@@ -155,10 +151,5 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
protected void onCountComplete(int num) { protected void onCountComplete(int num) {
mCallback.onNumberOfAppsResult(num); mCallback.onNumberOfAppsResult(num);
} }
@Override
protected List<UserInfo> getUsersToCount() {
return mUm.getUsers(true /* excludeDying */);
}
} }
} }

View File

@@ -23,7 +23,6 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageItemInfo; import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.icu.text.AlphabeticIndex; import android.icu.text.AlphabeticIndex;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
@@ -1417,11 +1416,6 @@ public class ManageApplications extends InstrumentedPreferenceFragment
mLoader.setSummary(SummaryProvider.this, mLoader.setSummary(SummaryProvider.this,
mContext.getString(R.string.apps_summary, num)); mContext.getString(R.string.apps_summary, num));
} }
@Override
protected List<UserInfo> getUsersToCount() {
return mUm.getProfiles(UserHandle.myUserId());
}
}.execute(); }.execute();
} }
} }

View File

@@ -18,16 +18,11 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.os.UserManager;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.dashboard.SummaryLoader; import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.notification.NotificationBackend; import com.android.settings.notification.NotificationBackend;
import java.util.List;
/** /**
* Extension of ManageApplications with no changes other than having its own * Extension of ManageApplications with no changes other than having its own
* SummaryProvider. * SummaryProvider.
@@ -56,11 +51,6 @@ public class NotificationApps extends ManageApplications {
updateSummary(num); updateSummary(num);
} }
@Override
protected List<UserInfo> getUsersToCount() {
return mUm.getProfiles(UserHandle.myUserId());
}
@Override @Override
protected boolean includeInCount(ApplicationInfo info) { protected boolean includeInCount(ApplicationInfo info) {
return mNotificationBackend.getNotificationsBanned(info.packageName, return mNotificationBackend.getNotificationsBanned(info.packageName,

View File

@@ -21,13 +21,13 @@ import com.android.settings.core.DynamicAvailabilityPreferenceController;
import com.android.settings.core.lifecycle.Lifecycle; import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
public class AlwaysOnVpnPrimaryUserPreferenceController public class AlwaysOnVpnCurrentUserPreferenceController
extends DynamicAvailabilityPreferenceController { extends DynamicAvailabilityPreferenceController {
private static final String KEY_ALWAYS_ON_VPN_PRIMARY_USER = "always_on_vpn_primary_user"; private static final String KEY_ALWAYS_ON_VPN_PRIMARY_USER = "always_on_vpn_primary_user";
private final EnterprisePrivacyFeatureProvider mFeatureProvider; private final EnterprisePrivacyFeatureProvider mFeatureProvider;
public AlwaysOnVpnPrimaryUserPreferenceController(Context context, Lifecycle lifecycle) { public AlwaysOnVpnCurrentUserPreferenceController(Context context, Lifecycle lifecycle) {
super(context, lifecycle); super(context, lifecycle);
mFeatureProvider = FeatureFactory.getFactory(context) mFeatureProvider = FeatureFactory.getFactory(context)
.getEnterprisePrivacyFeatureProvider(context); .getEnterprisePrivacyFeatureProvider(context);
@@ -42,7 +42,7 @@ public class AlwaysOnVpnPrimaryUserPreferenceController
@Override @Override
public boolean isAvailable() { public boolean isAvailable() {
return mFeatureProvider.isAlwaysOnVpnSetInPrimaryUser(); return mFeatureProvider.isAlwaysOnVpnSetInCurrentUser();
} }
@Override @Override

View File

@@ -51,13 +51,6 @@ public interface DevicePolicyManagerWrapper {
*/ */
ComponentName getDeviceOwnerComponentOnAnyUser(); ComponentName getDeviceOwnerComponentOnAnyUser();
/**
* Calls {@code DevicePolicyManager.getDeviceOwnerUserId()}.
*
* @see android.app.admin.DevicePolicyManager#getDeviceOwnerUserId
*/
int getDeviceOwnerUserId();
/** /**
* Calls {@code DevicePolicyManager.getProfileOwnerAsUser()}. * Calls {@code DevicePolicyManager.getProfileOwnerAsUser()}.
* *

View File

@@ -46,11 +46,6 @@ public class DevicePolicyManagerWrapperImpl implements DevicePolicyManagerWrappe
return mDpm.getDeviceOwnerComponentOnAnyUser(); return mDpm.getDeviceOwnerComponentOnAnyUser();
} }
@Override
public int getDeviceOwnerUserId() {
return mDpm.getDeviceOwnerUserId();
}
@Override @Override
public @Nullable ComponentName getProfileOwnerAsUser(final int userId) { public @Nullable ComponentName getProfileOwnerAsUser(final int userId) {
return mDpm.getProfileOwnerAsUser(userId); return mDpm.getProfileOwnerAsUser(userId);

View File

@@ -32,9 +32,9 @@ public interface EnterprisePrivacyFeatureProvider {
boolean isInCompMode(); boolean isInCompMode();
/** /**
* Returns the name of the organization managing the device via a Device Owner app. If the device * Returns the name of the organization managing the device via a Device Owner app. If the
* is not managed by a Device Owner app or the name of the managing organization was not set, * device is not managed by a Device Owner app or the name of the managing organization was not
* returns {@code null}. * set, returns {@code null}.
*/ */
String getDeviceOwnerOrganizationName(); String getDeviceOwnerOrganizationName();
@@ -74,12 +74,13 @@ public interface EnterprisePrivacyFeatureProvider {
boolean isNetworkLoggingEnabled(); boolean isNetworkLoggingEnabled();
/** /**
* Returns whether the Device Owner in the primary user set an always-on VPN. * Returns whether the Device Owner or Profile Owner in the current user set an always-on VPN.
*/ */
boolean isAlwaysOnVpnSetInPrimaryUser(); boolean isAlwaysOnVpnSetInCurrentUser();
/** /**
* Returns whether the Profile Owner in the managed profile (if any) set an always-on VPN. * Returns whether the Profile Owner in the current user's managed profile (if any) set an
* always-on VPN.
*/ */
boolean isAlwaysOnVpnSetInManagedProfile(); boolean isAlwaysOnVpnSetInManagedProfile();
@@ -89,10 +90,10 @@ public interface EnterprisePrivacyFeatureProvider {
boolean isGlobalHttpProxySet(); boolean isGlobalHttpProxySet();
/** /**
* Returns the number of failed login attempts that the Device Owner allows before the entire * Returns the number of failed login attempts that the Device Owner or Profile Owner allows
* device is wiped, or zero if no such limit is set. * before the current user is wiped, or zero if no such limit is set.
*/ */
int getMaximumFailedPasswordsBeforeWipeInPrimaryUser(); int getMaximumFailedPasswordsBeforeWipeInCurrentUser();
/** /**
* Returns the number of failed login attempts that the Profile Owner allows before the current * Returns the number of failed login attempts that the Profile Owner allows before the current

View File

@@ -142,7 +142,7 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
} }
@Override @Override
public boolean isAlwaysOnVpnSetInPrimaryUser() { public boolean isAlwaysOnVpnSetInCurrentUser() {
return VpnUtils.isAlwaysOnVpnSet(mCm, MY_USER_ID); return VpnUtils.isAlwaysOnVpnSet(mCm, MY_USER_ID);
} }
@@ -159,12 +159,12 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
} }
@Override @Override
public int getMaximumFailedPasswordsBeforeWipeInPrimaryUser() { public int getMaximumFailedPasswordsBeforeWipeInCurrentUser() {
final ComponentName deviceOwner = mDpm.getDeviceOwnerComponentOnAnyUser(); final ComponentName profileOwner = mDpm.getProfileOwnerAsUser(MY_USER_ID);
if (deviceOwner == null) { if (profileOwner == null) {
return 0; return 0;
} }
return mDpm.getMaximumFailedPasswordsForWipe(deviceOwner, mDpm.getDeviceOwnerUserId()); return mDpm.getMaximumFailedPasswordsForWipe(profileOwner, MY_USER_ID);
} }
@Override @Override

View File

@@ -70,11 +70,11 @@ public class EnterprisePrivacySettings extends DashboardFragment {
controllers.add(new AdminGrantedCameraPermissionPreferenceController(context, lifecycle, controllers.add(new AdminGrantedCameraPermissionPreferenceController(context, lifecycle,
async)); async));
controllers.add(new EnterpriseSetDefaultAppsPreferenceController(context, lifecycle)); controllers.add(new EnterpriseSetDefaultAppsPreferenceController(context, lifecycle));
controllers.add(new AlwaysOnVpnPrimaryUserPreferenceController(context, lifecycle)); controllers.add(new AlwaysOnVpnCurrentUserPreferenceController(context, lifecycle));
controllers.add(new AlwaysOnVpnManagedProfilePreferenceController(context, lifecycle)); controllers.add(new AlwaysOnVpnManagedProfilePreferenceController(context, lifecycle));
controllers.add(new GlobalHttpProxyPreferenceController(context, lifecycle)); controllers.add(new GlobalHttpProxyPreferenceController(context, lifecycle));
controllers.add(new CaCertsPreferenceController(context, lifecycle)); controllers.add(new CaCertsPreferenceController(context, lifecycle));
controllers.add(new FailedPasswordWipePrimaryUserPreferenceController(context, lifecycle)); controllers.add(new FailedPasswordWipeCurrentUserPreferenceController(context, lifecycle));
controllers.add(new FailedPasswordWipeManagedProfilePreferenceController(context, controllers.add(new FailedPasswordWipeManagedProfilePreferenceController(context,
lifecycle)); lifecycle));
controllers.add(new ImePreferenceController(context, lifecycle)); controllers.add(new ImePreferenceController(context, lifecycle));

View File

@@ -17,23 +17,23 @@ import android.content.Context;
import com.android.settings.core.lifecycle.Lifecycle; import com.android.settings.core.lifecycle.Lifecycle;
public class FailedPasswordWipePrimaryUserPreferenceController public class FailedPasswordWipeCurrentUserPreferenceController
extends FailedPasswordWipePreferenceControllerBase { extends FailedPasswordWipePreferenceControllerBase {
private static final String KEY_FAILED_PASSWORD_WIPE_PRIMARY_USER private static final String KEY_FAILED_PASSWORD_WIPE_CURRENT_USER
= "failed_password_wipe_primary_user"; = "failed_password_wipe_current_user";
public FailedPasswordWipePrimaryUserPreferenceController(Context context, Lifecycle lifecycle) { public FailedPasswordWipeCurrentUserPreferenceController(Context context, Lifecycle lifecycle) {
super(context, lifecycle); super(context, lifecycle);
} }
@Override @Override
protected int getMaximumFailedPasswordsBeforeWipe() { protected int getMaximumFailedPasswordsBeforeWipe() {
return mFeatureProvider.getMaximumFailedPasswordsBeforeWipeInPrimaryUser(); return mFeatureProvider.getMaximumFailedPasswordsBeforeWipeInCurrentUser();
} }
@Override @Override
public String getPreferenceKey() { public String getPreferenceKey() {
return KEY_FAILED_PASSWORD_WIPE_PRIMARY_USER; return KEY_FAILED_PASSWORD_WIPE_CURRENT_USER;
} }
} }

View File

@@ -22,6 +22,7 @@ import android.content.pm.PackageManager;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.os.Build; import android.os.Build;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager;
import com.android.settings.SettingsRobolectricTestRunner; import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig; import com.android.settings.TestConfig;
@@ -35,7 +36,6 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication; import org.robolectric.shadows.ShadowApplication;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import static com.android.settings.testutils.ApplicationTestUtils.buildInfo; import static com.android.settings.testutils.ApplicationTestUtils.buildInfo;
import static com.google.common.truth.Truth.assertThat; 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 PERMISSION_2 = "some.permission.2";
private final String[] PERMISSIONS = {PERMISSION_1, PERMISSION_2}; private final String[] PERMISSIONS = {PERMISSION_1, PERMISSION_2};
@Mock private UserManager mUserManager;
@Mock private Context mContext; @Mock private Context mContext;
@Mock private PackageManagerWrapper mPackageManager; @Mock private PackageManagerWrapper mPackageManager;
@Mock private IPackageManagerWrapper mPackageManagerService; @Mock private IPackageManagerWrapper mPackageManagerService;
@Mock private DevicePolicyManagerWrapper mDevicePolicyManager; @Mock private DevicePolicyManagerWrapper mDevicePolicyManager;
private List<UserInfo> mUsersToCount;
private int mAppCount = -1; private int mAppCount = -1;
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); 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. // 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(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: // The first user has five apps installed:
// * app1 uses run-time permissions. It has been granted one of the permissions by the // * 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); assertThat(mAppCount).isEqualTo(3);
// Verify that installed packages were retrieved for the users returned by // Verify that installed packages were retrieved the current user and the user's managed
// InstalledAppCounterTestable.getUsersToCount() only. // profile only.
verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(), eq(MAIN_USER_ID)); verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(), eq(MAIN_USER_ID));
verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(), verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(),
eq(MANAGED_PROFILE_ID)); eq(MANAGED_PROFILE_ID));
@@ -200,13 +201,13 @@ public final class AppWithAdminGrantedPermissionsCounterTest {
} }
@Test @Test
public void testCountInstalledAppsAcrossAllUsersSync() throws Exception { public void testCountInstalledAppsSync() throws Exception {
verifyCountInstalledAppsAcrossAllUsers(false /* async */); verifyCountInstalledApps(false /* async */);
} }
@Test @Test
public void testCountInstalledAppsAcrossAllUsersAync() throws Exception { public void testCountInstalledAppsAync() throws Exception {
verifyCountInstalledAppsAcrossAllUsers(true /* async */); verifyCountInstalledApps(true /* async */);
} }
private class AppWithAdminGrantedPermissionsCounterTestable extends private class AppWithAdminGrantedPermissionsCounterTestable extends
@@ -220,10 +221,5 @@ public final class AppWithAdminGrantedPermissionsCounterTest {
protected void onCountComplete(int num) { protected void onCountComplete(int num) {
mAppCount = num; mAppCount = num;
} }
@Override
protected List<UserInfo> getUsersToCount() {
return mUsersToCount;
}
} }
} }

View File

@@ -190,7 +190,7 @@ public final class ApplicationFeatureProviderImplTest {
} }
private void setUpUsersAndInstalledApps() { 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(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN),
new UserInfo(MANAGED_PROFILE_ID, "managed profile", 0))); new UserInfo(MANAGED_PROFILE_ID, "managed profile", 0)));

View File

@@ -78,7 +78,6 @@ public final class InstalledAppCounterTest {
@Mock private UserManager mUserManager; @Mock private UserManager mUserManager;
@Mock private Context mContext; @Mock private Context mContext;
@Mock private PackageManagerWrapper mPackageManager; @Mock private PackageManagerWrapper mPackageManager;
private List<UserInfo> mUsersToCount;
private int mInstalledAppCount = -1; private int mInstalledAppCount = -1;
@@ -99,9 +98,9 @@ public final class InstalledAppCounterTest {
private void testCountInstalledAppsAcrossAllUsers(boolean async) { private void testCountInstalledAppsAcrossAllUsers(boolean async) {
// There are two users. // 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(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: // The first user has four apps installed:
// * app1 is an updated system app. It should be counted. // * app1 is an updated system app. It should be counted.
@@ -159,8 +158,8 @@ public final class InstalledAppCounterTest {
count(InstalledAppCounter.IGNORE_INSTALL_REASON, async); count(InstalledAppCounter.IGNORE_INSTALL_REASON, async);
assertThat(mInstalledAppCount).isEqualTo(5); assertThat(mInstalledAppCount).isEqualTo(5);
// Verify that installed packages were retrieved for the users returned by // Verify that installed packages were retrieved the current user and the user's managed
// InstalledAppCounterTestable.getUsersToCount() only. // profile only.
verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(), eq(MAIN_USER_ID)); verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(), eq(MAIN_USER_ID));
verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(), verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(),
eq(MANAGED_PROFILE_ID)); eq(MANAGED_PROFILE_ID));
@@ -205,11 +204,6 @@ public final class InstalledAppCounterTest {
protected void onCountComplete(int num) { protected void onCountComplete(int num) {
mInstalledAppCount = num; mInstalledAppCount = num;
} }
@Override
protected List<UserInfo> getUsersToCount() {
return mUsersToCount;
}
} }
private static class IsLaunchIntentFor extends ArgumentMatcher<Intent> { private static class IsLaunchIntentFor extends ArgumentMatcher<Intent> {

View File

@@ -36,11 +36,11 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
/** /**
* Tests for {@link AlwaysOnVpnPrimaryUserPreferenceController}. * Tests for {@link AlwaysOnVpnCurrentUserPreferenceController}.
*/ */
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @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_DEVICE = "VPN set";
private final String VPN_SET_PERSONAL = "VPN set in personal profile"; private final String VPN_SET_PERSONAL = "VPN set in personal profile";
@@ -49,14 +49,14 @@ public final class AlwaysOnVpnPrimaryUserPreferenceControllerTest {
private Context mContext; private Context mContext;
private FakeFeatureFactory mFeatureFactory; private FakeFeatureFactory mFeatureFactory;
private AlwaysOnVpnPrimaryUserPreferenceController mController; private AlwaysOnVpnCurrentUserPreferenceController mController;
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext); FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mController = new AlwaysOnVpnPrimaryUserPreferenceController(mContext, mController = new AlwaysOnVpnCurrentUserPreferenceController(mContext,
null /* lifecycle */); null /* lifecycle */);
when(mContext.getString(R.string.enterprise_privacy_always_on_vpn_device)) when(mContext.getString(R.string.enterprise_privacy_always_on_vpn_device))
.thenReturn(VPN_SET_DEVICE); .thenReturn(VPN_SET_DEVICE);
@@ -68,7 +68,7 @@ public final class AlwaysOnVpnPrimaryUserPreferenceControllerTest {
public void testUpdateState() { public void testUpdateState() {
final Preference preference = new Preference(mContext, null, 0, 0); final Preference preference = new Preference(mContext, null, 0, 0);
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser()) when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInCurrentUser())
.thenReturn(true); .thenReturn(true);
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(false); when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(false);
@@ -82,11 +82,11 @@ public final class AlwaysOnVpnPrimaryUserPreferenceControllerTest {
@Test @Test
public void testIsAvailable() { public void testIsAvailable() {
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser()) when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInCurrentUser())
.thenReturn(false); .thenReturn(false);
assertThat(mController.isAvailable()).isFalse(); assertThat(mController.isAvailable()).isFalse();
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser()) when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInCurrentUser())
.thenReturn(true); .thenReturn(true);
assertThat(mController.isAvailable()).isTrue(); assertThat(mController.isAvailable()).isTrue();
} }

View File

@@ -195,13 +195,13 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
} }
@Test @Test
public void testIsAlwaysOnVpnSetInPrimaryUser() { public void testIsAlwaysOnVpnSetInCurrentUser() {
when(mConnectivityManger.getAlwaysOnVpnPackageForUser(MY_USER_ID)).thenReturn(null); when(mConnectivityManger.getAlwaysOnVpnPackageForUser(MY_USER_ID)).thenReturn(null);
assertThat(mProvider.isAlwaysOnVpnSetInPrimaryUser()).isFalse(); assertThat(mProvider.isAlwaysOnVpnSetInCurrentUser()).isFalse();
when(mConnectivityManger.getAlwaysOnVpnPackageForUser(MY_USER_ID)) when(mConnectivityManger.getAlwaysOnVpnPackageForUser(MY_USER_ID))
.thenReturn(VPN_PACKAGE_ID); .thenReturn(VPN_PACKAGE_ID);
assertThat(mProvider.isAlwaysOnVpnSetInPrimaryUser()).isTrue(); assertThat(mProvider.isAlwaysOnVpnSetInCurrentUser()).isTrue();
} }
@Test @Test
@@ -230,16 +230,14 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
} }
@Test @Test
public void testGetMaximumFailedPasswordsForWipeInPrimaryUser() { public void testGetMaximumFailedPasswordsForWipeInCurrentUser() {
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null); when(mDevicePolicyManager.getProfileOwnerAsUser(MY_USER_ID)).thenReturn(null);
when(mDevicePolicyManager.getDeviceOwnerUserId()).thenReturn(UserHandle.USER_NULL); when(mDevicePolicyManager.getMaximumFailedPasswordsForWipe(OWNER, MY_USER_ID))
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInPrimaryUser()).isEqualTo(0);
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(OWNER);
when(mDevicePolicyManager.getDeviceOwnerUserId()).thenReturn(UserHandle.USER_SYSTEM);
when(mDevicePolicyManager.getMaximumFailedPasswordsForWipe(OWNER, UserHandle.USER_SYSTEM))
.thenReturn(10); .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 @Test
@@ -247,7 +245,6 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
when(mDevicePolicyManager.getProfileOwnerAsUser(MANAGED_PROFILE_USER_ID)).thenReturn(OWNER); when(mDevicePolicyManager.getProfileOwnerAsUser(MANAGED_PROFILE_USER_ID)).thenReturn(OWNER);
when(mDevicePolicyManager.getMaximumFailedPasswordsForWipe(OWNER, MANAGED_PROFILE_USER_ID)) when(mDevicePolicyManager.getMaximumFailedPasswordsForWipe(OWNER, MANAGED_PROFILE_USER_ID))
.thenReturn(10); .thenReturn(10);
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInManagedProfile()).isEqualTo(0); assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInManagedProfile()).isEqualTo(0);
mProfiles.add(new UserInfo(MANAGED_PROFILE_USER_ID, "", "", UserInfo.FLAG_MANAGED_PROFILE)); mProfiles.add(new UserInfo(MANAGED_PROFILE_USER_ID, "", "", UserInfo.FLAG_MANAGED_PROFILE));

View File

@@ -134,7 +134,7 @@ public final class EnterprisePrivacySettingsTest {
assertThat(controllers.get(position++)).isInstanceOf( assertThat(controllers.get(position++)).isInstanceOf(
EnterpriseSetDefaultAppsPreferenceController.class); EnterpriseSetDefaultAppsPreferenceController.class);
assertThat(controllers.get(position++)).isInstanceOf( assertThat(controllers.get(position++)).isInstanceOf(
AlwaysOnVpnPrimaryUserPreferenceController.class); AlwaysOnVpnCurrentUserPreferenceController.class);
assertThat(controllers.get(position++)).isInstanceOf( assertThat(controllers.get(position++)).isInstanceOf(
AlwaysOnVpnManagedProfilePreferenceController.class); AlwaysOnVpnManagedProfilePreferenceController.class);
assertThat(controllers.get(position++)).isInstanceOf( assertThat(controllers.get(position++)).isInstanceOf(
@@ -142,7 +142,7 @@ public final class EnterprisePrivacySettingsTest {
assertThat(controllers.get(position++)).isInstanceOf( assertThat(controllers.get(position++)).isInstanceOf(
CaCertsPreferenceController.class); CaCertsPreferenceController.class);
assertThat(controllers.get(position++)).isInstanceOf( assertThat(controllers.get(position++)).isInstanceOf(
FailedPasswordWipePrimaryUserPreferenceController.class); FailedPasswordWipeCurrentUserPreferenceController.class);
assertThat(controllers.get(position++)).isInstanceOf( assertThat(controllers.get(position++)).isInstanceOf(
FailedPasswordWipeManagedProfilePreferenceController.class); FailedPasswordWipeManagedProfilePreferenceController.class);
assertThat(controllers.get(position++)).isInstanceOf(ImePreferenceController.class); assertThat(controllers.get(position++)).isInstanceOf(ImePreferenceController.class);

View File

@@ -27,29 +27,29 @@ import org.robolectric.annotation.Config;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
/** /**
* Tests for {@link FailedPasswordWipePrimaryUserPreferenceController}. * Tests for {@link FailedPasswordWipeCurrentUserPreferenceController}.
*/ */
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public final class FailedPasswordWipePrimaryUserPreferenceControllerTest extends public final class FailedPasswordWipeCurrentUserPreferenceControllerTest extends
FailedPasswordWipePreferenceControllerTestBase { FailedPasswordWipePreferenceControllerTestBase {
private int mMaximumFailedPasswordsBeforeWipe = 0; private int mMaximumFailedPasswordsBeforeWipe = 0;
public FailedPasswordWipePrimaryUserPreferenceControllerTest() { public FailedPasswordWipeCurrentUserPreferenceControllerTest() {
super("failed_password_wipe_primary_user"); super("failed_password_wipe_current_user");
} }
@Override @Override
public void setUp() { public void setUp() {
super.setUp(); super.setUp();
mController = new FailedPasswordWipePrimaryUserPreferenceController(mContext, mController = new FailedPasswordWipeCurrentUserPreferenceController(mContext,
null /* lifecycle */); null /* lifecycle */);
} }
@Override @Override
public void setMaximumFailedPasswordsBeforeWipe(int maximum) { public void setMaximumFailedPasswordsBeforeWipe(int maximum) {
when(mFeatureFactory.enterprisePrivacyFeatureProvider when(mFeatureFactory.enterprisePrivacyFeatureProvider
.getMaximumFailedPasswordsBeforeWipeInPrimaryUser()).thenReturn(maximum); .getMaximumFailedPasswordsBeforeWipeInCurrentUser()).thenReturn(maximum);
} }
} }