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:
@@ -100,7 +100,7 @@
|
||||
android:title="@string/enterprise_privacy_wipe_device"
|
||||
settings:multiLine="true"/>
|
||||
<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"
|
||||
settings:multiLine="true"/>
|
||||
<com.android.settings.DividerPreference
|
||||
|
@@ -20,6 +20,7 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import java.util.List;
|
||||
@@ -37,7 +38,7 @@ public abstract class AppCounter extends AsyncTask<Void, Void, Integer> {
|
||||
@Override
|
||||
protected Integer doInBackground(Void... params) {
|
||||
int count = 0;
|
||||
for (UserInfo user : getUsersToCount()) {
|
||||
for (UserInfo user : mUm.getProfiles(UserHandle.myUserId())) {
|
||||
final List<ApplicationInfo> list =
|
||||
mPm.getInstalledApplicationsAsUser(PackageManager.GET_DISABLED_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 List<UserInfo> getUsersToCount();
|
||||
protected abstract boolean includeInCount(ApplicationInfo info);
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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<UserInfo> 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<UserInfo> getUsersToCount() {
|
||||
return mUm.getUsers(true /* excludeDying */);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
@@ -1404,11 +1403,6 @@ public class ManageApplications extends InstrumentedPreferenceFragment
|
||||
mLoader.setSummary(SummaryProvider.this,
|
||||
mContext.getString(R.string.apps_summary, num));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<UserInfo> getUsersToCount() {
|
||||
return mUm.getProfiles(UserHandle.myUserId());
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
|
@@ -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<UserInfo> getUsersToCount() {
|
||||
return mUm.getProfiles(UserHandle.myUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean includeInCount(ApplicationInfo info) {
|
||||
return mNotificationBackend.getNotificationsBanned(info.packageName,
|
||||
|
@@ -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
|
@@ -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()}.
|
||||
*
|
||||
|
@@ -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);
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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));
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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