diff --git a/res/xml/enterprise_privacy_settings.xml b/res/xml/enterprise_privacy_settings.xml index 15e4e222825..3ea0860912e 100644 --- a/res/xml/enterprise_privacy_settings.xml +++ b/res/xml/enterprise_privacy_settings.xml @@ -100,7 +100,7 @@ android:title="@string/enterprise_privacy_wipe_device" settings:multiLine="true"/> { @Override protected Integer doInBackground(Void... params) { int count = 0; - for (UserInfo user : getUsersToCount()) { + for (UserInfo user : mUm.getProfiles(UserHandle.myUserId())) { final List list = mPm.getInstalledApplicationsAsUser(PackageManager.GET_DISABLED_COMPONENTS | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS @@ -62,6 +63,5 @@ public abstract class AppCounter extends AsyncTask { } protected abstract void onCountComplete(int num); - protected abstract List getUsersToCount(); protected abstract boolean includeInCount(ApplicationInfo info); } diff --git a/src/com/android/settings/applications/ApplicationFeatureProvider.java b/src/com/android/settings/applications/ApplicationFeatureProvider.java index 181679300c9..ef8cb232c6c 100644 --- a/src/com/android/settings/applications/ApplicationFeatureProvider.java +++ b/src/com/android/settings/applications/ApplicationFeatureProvider.java @@ -40,8 +40,8 @@ public interface ApplicationFeatureProvider { View view); /** - * Calculates the total number of apps installed on the device via policy across all users - * and managed profiles. + * Calculates the total number of apps installed on the device via policy in the current user + * and all its managed profiles. * * @param async Whether to count asynchronously in a background thread * @param callback The callback to invoke with the result @@ -49,9 +49,8 @@ public interface ApplicationFeatureProvider { void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback); /** - * Asynchronously calculates the total number of apps installed on the device, across all users - * and managed profiles, that have been granted one or more of the given permissions by the - * admin. + * Asynchronously calculates the total number of apps installed in the current user and all its + * managed profiles that have been granted one or more of the given permissions by the admin. * * @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 diff --git a/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java b/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java index 7cc899b76b5..124a8dea265 100644 --- a/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java +++ b/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java @@ -22,7 +22,6 @@ import android.content.Intent; import android.content.pm.ComponentInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.content.pm.UserInfo; import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; @@ -65,8 +64,8 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide @Override public void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback) { - final AllUserPolicyInstalledAppCounter counter = - new AllUserPolicyInstalledAppCounter(mContext, mPm, callback); + final CurrentUserAndManagedProfilePolicyInstalledAppCounter counter = + new CurrentUserAndManagedProfilePolicyInstalledAppCounter(mContext, mPm, callback); if (async) { counter.execute(); } else { @@ -77,9 +76,9 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide @Override public void calculateNumberOfAppsWithAdminGrantedPermissions(String[] permissions, boolean async, NumberOfAppsCallback callback) { - final AllUserAppWithAdminGrantedPermissionsCounter counter = - new AllUserAppWithAdminGrantedPermissionsCounter(mContext, permissions, mPm, mPms, - mDpm, callback); + final CurrentUserAndManagedProfileAppWithAdminGrantedPermissionsCounter counter = + new CurrentUserAndManagedProfileAppWithAdminGrantedPermissionsCounter(mContext, + permissions, mPm, mPms, mDpm, callback); if (async) { counter.execute(); } else { @@ -120,11 +119,12 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide return activities; } - private static class AllUserPolicyInstalledAppCounter extends InstalledAppCounter { + private static class CurrentUserAndManagedProfilePolicyInstalledAppCounter + extends InstalledAppCounter { private NumberOfAppsCallback mCallback; - AllUserPolicyInstalledAppCounter(Context context, PackageManagerWrapper packageManager, - NumberOfAppsCallback callback) { + CurrentUserAndManagedProfilePolicyInstalledAppCounter(Context context, + PackageManagerWrapper packageManager, NumberOfAppsCallback callback) { super(context, PackageManager.INSTALL_REASON_POLICY, packageManager); mCallback = callback; } @@ -133,19 +133,15 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide protected void onCountComplete(int num) { mCallback.onNumberOfAppsResult(num); } - - @Override - protected List getUsersToCount() { - return mUm.getUsers(true /* excludeDying */); - } } - private static class AllUserAppWithAdminGrantedPermissionsCounter extends - AppWithAdminGrantedPermissionsCounter { + private static class CurrentUserAndManagedProfileAppWithAdminGrantedPermissionsCounter + extends AppWithAdminGrantedPermissionsCounter { private NumberOfAppsCallback mCallback; - AllUserAppWithAdminGrantedPermissionsCounter(Context context, String[] permissions, - PackageManagerWrapper packageManager, IPackageManagerWrapper packageManagerService, + CurrentUserAndManagedProfileAppWithAdminGrantedPermissionsCounter(Context context, + String[] permissions, PackageManagerWrapper packageManager, + IPackageManagerWrapper packageManagerService, DevicePolicyManagerWrapper devicePolicyManager, NumberOfAppsCallback callback) { super(context, permissions, packageManager, packageManagerService, devicePolicyManager); mCallback = callback; @@ -155,10 +151,5 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide protected void onCountComplete(int num) { mCallback.onNumberOfAppsResult(num); } - - @Override - protected List getUsersToCount() { - return mUm.getUsers(true /* excludeDying */); - } } } diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java index 3499df66b6e..4d873a363f8 100644 --- a/src/com/android/settings/applications/ManageApplications.java +++ b/src/com/android/settings/applications/ManageApplications.java @@ -23,7 +23,6 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageItemInfo; import android.content.pm.PackageManager; -import android.content.pm.UserInfo; import android.icu.text.AlphabeticIndex; import android.os.Bundle; import android.os.Environment; @@ -1417,11 +1416,6 @@ public class ManageApplications extends InstrumentedPreferenceFragment mLoader.setSummary(SummaryProvider.this, mContext.getString(R.string.apps_summary, num)); } - - @Override - protected List getUsersToCount() { - return mUm.getProfiles(UserHandle.myUserId()); - } }.execute(); } } diff --git a/src/com/android/settings/applications/NotificationApps.java b/src/com/android/settings/applications/NotificationApps.java index 7aaa36e1ac0..c54363aa735 100644 --- a/src/com/android/settings/applications/NotificationApps.java +++ b/src/com/android/settings/applications/NotificationApps.java @@ -18,16 +18,11 @@ import android.app.Activity; import android.content.Context; import android.content.pm.ApplicationInfo; 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.dashboard.SummaryLoader; import com.android.settings.notification.NotificationBackend; -import java.util.List; - /** * Extension of ManageApplications with no changes other than having its own * SummaryProvider. @@ -56,11 +51,6 @@ public class NotificationApps extends ManageApplications { updateSummary(num); } - @Override - protected List getUsersToCount() { - return mUm.getProfiles(UserHandle.myUserId()); - } - @Override protected boolean includeInCount(ApplicationInfo info) { return mNotificationBackend.getNotificationsBanned(info.packageName, diff --git a/src/com/android/settings/enterprise/AlwaysOnVpnPrimaryUserPreferenceController.java b/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceController.java similarity index 90% rename from src/com/android/settings/enterprise/AlwaysOnVpnPrimaryUserPreferenceController.java rename to src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceController.java index e5823fe7654..e98ece8068b 100644 --- a/src/com/android/settings/enterprise/AlwaysOnVpnPrimaryUserPreferenceController.java +++ b/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceController.java @@ -21,13 +21,13 @@ import com.android.settings.core.DynamicAvailabilityPreferenceController; import com.android.settings.core.lifecycle.Lifecycle; import com.android.settings.overlay.FeatureFactory; -public class AlwaysOnVpnPrimaryUserPreferenceController +public class AlwaysOnVpnCurrentUserPreferenceController extends DynamicAvailabilityPreferenceController { private static final String KEY_ALWAYS_ON_VPN_PRIMARY_USER = "always_on_vpn_primary_user"; private final EnterprisePrivacyFeatureProvider mFeatureProvider; - public AlwaysOnVpnPrimaryUserPreferenceController(Context context, Lifecycle lifecycle) { + public AlwaysOnVpnCurrentUserPreferenceController(Context context, Lifecycle lifecycle) { super(context, lifecycle); mFeatureProvider = FeatureFactory.getFactory(context) .getEnterprisePrivacyFeatureProvider(context); @@ -42,7 +42,7 @@ public class AlwaysOnVpnPrimaryUserPreferenceController @Override public boolean isAvailable() { - return mFeatureProvider.isAlwaysOnVpnSetInPrimaryUser(); + return mFeatureProvider.isAlwaysOnVpnSetInCurrentUser(); } @Override diff --git a/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java b/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java index a154a2fb932..babf90e1955 100644 --- a/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java +++ b/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java @@ -51,13 +51,6 @@ public interface DevicePolicyManagerWrapper { */ ComponentName getDeviceOwnerComponentOnAnyUser(); - /** - * Calls {@code DevicePolicyManager.getDeviceOwnerUserId()}. - * - * @see android.app.admin.DevicePolicyManager#getDeviceOwnerUserId - */ - int getDeviceOwnerUserId(); - /** * Calls {@code DevicePolicyManager.getProfileOwnerAsUser()}. * diff --git a/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java b/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java index 95a154bff53..7906310682d 100644 --- a/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java +++ b/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java @@ -46,11 +46,6 @@ public class DevicePolicyManagerWrapperImpl implements DevicePolicyManagerWrappe return mDpm.getDeviceOwnerComponentOnAnyUser(); } - @Override - public int getDeviceOwnerUserId() { - return mDpm.getDeviceOwnerUserId(); - } - @Override public @Nullable ComponentName getProfileOwnerAsUser(final int userId) { return mDpm.getProfileOwnerAsUser(userId); diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java index 4ad0f2e796c..391db836f27 100644 --- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java +++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java @@ -32,9 +32,9 @@ public interface EnterprisePrivacyFeatureProvider { boolean isInCompMode(); /** - * Returns the name of the organization managing the device via a Device Owner app. If the device - * is not managed by a Device Owner app or the name of the managing organization was not set, - * returns {@code null}. + * Returns the name of the organization managing the device via a Device Owner app. If the + * device is not managed by a Device Owner app or the name of the managing organization was not + * set, returns {@code null}. */ String getDeviceOwnerOrganizationName(); @@ -74,12 +74,13 @@ public interface EnterprisePrivacyFeatureProvider { 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(); @@ -89,10 +90,10 @@ public interface EnterprisePrivacyFeatureProvider { boolean isGlobalHttpProxySet(); /** - * Returns the number of failed login attempts that the Device Owner allows before the entire - * device is wiped, or zero if no such limit is set. + * Returns the number of failed login attempts that the Device Owner or Profile Owner allows + * 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 diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java index 6d038dc0407..5817cf2ae59 100644 --- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java +++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java @@ -142,7 +142,7 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe } @Override - public boolean isAlwaysOnVpnSetInPrimaryUser() { + public boolean isAlwaysOnVpnSetInCurrentUser() { return VpnUtils.isAlwaysOnVpnSet(mCm, MY_USER_ID); } @@ -159,12 +159,12 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe } @Override - public int getMaximumFailedPasswordsBeforeWipeInPrimaryUser() { - final ComponentName deviceOwner = mDpm.getDeviceOwnerComponentOnAnyUser(); - if (deviceOwner == null) { + public int getMaximumFailedPasswordsBeforeWipeInCurrentUser() { + final ComponentName profileOwner = mDpm.getProfileOwnerAsUser(MY_USER_ID); + if (profileOwner == null) { return 0; } - return mDpm.getMaximumFailedPasswordsForWipe(deviceOwner, mDpm.getDeviceOwnerUserId()); + return mDpm.getMaximumFailedPasswordsForWipe(profileOwner, MY_USER_ID); } @Override diff --git a/src/com/android/settings/enterprise/EnterprisePrivacySettings.java b/src/com/android/settings/enterprise/EnterprisePrivacySettings.java index 9649d849ce8..a80dec015ad 100644 --- a/src/com/android/settings/enterprise/EnterprisePrivacySettings.java +++ b/src/com/android/settings/enterprise/EnterprisePrivacySettings.java @@ -70,11 +70,11 @@ public class EnterprisePrivacySettings extends DashboardFragment { controllers.add(new AdminGrantedCameraPermissionPreferenceController(context, lifecycle, async)); 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 GlobalHttpProxyPreferenceController(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, lifecycle)); controllers.add(new ImePreferenceController(context, lifecycle)); diff --git a/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceController.java b/src/com/android/settings/enterprise/FailedPasswordWipeCurrentUserPreferenceController.java similarity index 77% rename from src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceController.java rename to src/com/android/settings/enterprise/FailedPasswordWipeCurrentUserPreferenceController.java index 2e18f899fa3..d3f9a98245c 100644 --- a/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceController.java +++ b/src/com/android/settings/enterprise/FailedPasswordWipeCurrentUserPreferenceController.java @@ -17,23 +17,23 @@ import android.content.Context; import com.android.settings.core.lifecycle.Lifecycle; -public class FailedPasswordWipePrimaryUserPreferenceController +public class FailedPasswordWipeCurrentUserPreferenceController extends FailedPasswordWipePreferenceControllerBase { - private static final String KEY_FAILED_PASSWORD_WIPE_PRIMARY_USER - = "failed_password_wipe_primary_user"; + private static final String KEY_FAILED_PASSWORD_WIPE_CURRENT_USER + = "failed_password_wipe_current_user"; - public FailedPasswordWipePrimaryUserPreferenceController(Context context, Lifecycle lifecycle) { + public FailedPasswordWipeCurrentUserPreferenceController(Context context, Lifecycle lifecycle) { super(context, lifecycle); } @Override protected int getMaximumFailedPasswordsBeforeWipe() { - return mFeatureProvider.getMaximumFailedPasswordsBeforeWipeInPrimaryUser(); + return mFeatureProvider.getMaximumFailedPasswordsBeforeWipeInCurrentUser(); } @Override public String getPreferenceKey() { - return KEY_FAILED_PASSWORD_WIPE_PRIMARY_USER; + return KEY_FAILED_PASSWORD_WIPE_CURRENT_USER; } } diff --git a/tests/robotests/src/com/android/settings/applications/AppWithAdminGrantedPermissionsCounterTest.java b/tests/robotests/src/com/android/settings/applications/AppWithAdminGrantedPermissionsCounterTest.java index dfef3b865fe..aeb38266b27 100644 --- a/tests/robotests/src/com/android/settings/applications/AppWithAdminGrantedPermissionsCounterTest.java +++ b/tests/robotests/src/com/android/settings/applications/AppWithAdminGrantedPermissionsCounterTest.java @@ -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 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 getUsersToCount() { - return mUsersToCount; - } } } diff --git a/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java index f946780f222..f46bb902043 100644 --- a/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java +++ b/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java @@ -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))); diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java index 1134ec58c23..46a3359c530 100644 --- a/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java +++ b/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java @@ -78,7 +78,6 @@ public final class InstalledAppCounterTest { @Mock private UserManager mUserManager; @Mock private Context mContext; @Mock private PackageManagerWrapper mPackageManager; - private List 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 getUsersToCount() { - return mUsersToCount; - } } private static class IsLaunchIntentFor extends ArgumentMatcher { diff --git a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnPrimaryUserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceControllerTest.java similarity index 91% rename from tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnPrimaryUserPreferenceControllerTest.java rename to tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceControllerTest.java index 12fdb4f58b7..9d1bd582446 100644 --- a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnPrimaryUserPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceControllerTest.java @@ -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(); } diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java index 8d78ef7ef2a..5e46216b84c 100644 --- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java +++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java @@ -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)); diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java index 22256877168..d41be75767b 100644 --- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java +++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java @@ -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); diff --git a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeCurrentUserPreferenceControllerTest.java similarity index 80% rename from tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceControllerTest.java rename to tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeCurrentUserPreferenceControllerTest.java index d74b9b86089..b2f4fa72992 100644 --- a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeCurrentUserPreferenceControllerTest.java @@ -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); } }