Add admin-granted permissions to Enterprise Privacy Settings page
This CL adds information about the number of apps that have been granted particularly sensitive permissions (location, microphone, camera) by the admin. Bug: 32692748 Test: make RunSettingsRoboTests Change-Id: I650d3e1ed3950960c58722b0c035a76daeb36478
This commit is contained in:
@@ -16,14 +16,18 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.IPackageManager;
|
||||
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;
|
||||
import com.android.settings.enterprise.DevicePolicyManagerWrapper;
|
||||
import com.android.settings.testutils.ApplicationTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import org.junit.Before;
|
||||
@@ -50,15 +54,25 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
private final int MAIN_USER_ID = 0;
|
||||
private final int MANAGED_PROFILE_ID = 10;
|
||||
|
||||
private final int PER_USER_UID_RANGE = 100000;
|
||||
private final int APP_1_UID = MAIN_USER_ID * PER_USER_UID_RANGE + 1;
|
||||
private final int APP_2_UID = MANAGED_PROFILE_ID * PER_USER_UID_RANGE + 1;
|
||||
|
||||
private final String APP_1 = "app1";
|
||||
private final String APP_2 = "app2";
|
||||
|
||||
private final String PERMISSION = "some.permission";
|
||||
|
||||
private @Mock UserManager mUserManager;
|
||||
private @Mock Context mContext;
|
||||
private @Mock PackageManagerWrapper mPackageManager;
|
||||
@Mock private IPackageManager mPackageManagerService;
|
||||
@Mock private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
|
||||
private ApplicationFeatureProvider mProvider;
|
||||
|
||||
private int mAppCount = -1;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
@@ -66,14 +80,66 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
|
||||
mProvider = new ApplicationFeatureProviderImpl(mContext, mPackageManager);
|
||||
mProvider = new ApplicationFeatureProviderImpl(mContext, mPackageManager,
|
||||
mPackageManagerService, mDevicePolicyManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalculateNumberOfInstalledApps() {
|
||||
final Integer[] numberOfInstalledApps = new Integer[1];
|
||||
numberOfInstalledApps[0] = null;
|
||||
setUpUsersAndInstalledApps();
|
||||
|
||||
when(mPackageManager.getInstallReason(APP_1, new UserHandle(MAIN_USER_ID)))
|
||||
.thenReturn(PackageManager.INSTALL_REASON_UNKNOWN);
|
||||
when(mPackageManager.getInstallReason(APP_2, new UserHandle(MANAGED_PROFILE_ID)))
|
||||
.thenReturn(PackageManager.INSTALL_REASON_POLICY);
|
||||
|
||||
// Count all installed apps.
|
||||
mAppCount = -1;
|
||||
mProvider.calculateNumberOfInstalledApps(ApplicationFeatureProvider.IGNORE_INSTALL_REASON,
|
||||
(num) -> {
|
||||
mAppCount = num;
|
||||
});
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
assertThat(mAppCount).isEqualTo(2);
|
||||
|
||||
// Count apps with specific install reason only.
|
||||
mAppCount = -1;
|
||||
mProvider.calculateNumberOfInstalledApps(PackageManager.INSTALL_REASON_POLICY,
|
||||
(num) -> {
|
||||
mAppCount = num;
|
||||
});
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
assertThat(mAppCount).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalculateNumberOfAppsWithAdminGrantedPermissions() throws Exception {
|
||||
setUpUsersAndInstalledApps();
|
||||
|
||||
when(mDevicePolicyManager.getPermissionGrantState(null, APP_1, PERMISSION))
|
||||
.thenReturn(DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED);
|
||||
when(mDevicePolicyManager.getPermissionGrantState(null, APP_2, PERMISSION))
|
||||
.thenReturn(DevicePolicyManager.PERMISSION_GRANT_STATE_DENIED);
|
||||
when(mPackageManagerService.checkUidPermission(PERMISSION, APP_1_UID))
|
||||
.thenReturn(PackageManager.PERMISSION_DENIED);
|
||||
when(mPackageManagerService.checkUidPermission(PERMISSION, APP_2_UID))
|
||||
.thenReturn(PackageManager.PERMISSION_GRANTED);
|
||||
when(mPackageManager.getInstallReason(APP_1, new UserHandle(MAIN_USER_ID)))
|
||||
.thenReturn(PackageManager.INSTALL_REASON_UNKNOWN);
|
||||
when(mPackageManager.getInstallReason(APP_2, new UserHandle(MANAGED_PROFILE_ID)))
|
||||
.thenReturn(PackageManager.INSTALL_REASON_POLICY);
|
||||
|
||||
mAppCount = -1;
|
||||
mProvider.calculateNumberOfAppsWithAdminGrantedPermissions(new String[] {PERMISSION},
|
||||
(num) -> {
|
||||
mAppCount = num;
|
||||
});
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
assertThat(mAppCount).isEqualTo(2);
|
||||
|
||||
}
|
||||
|
||||
private void setUpUsersAndInstalledApps() {
|
||||
when(mUserManager.getUsers(true)).thenReturn(Arrays.asList(
|
||||
new UserInfo(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN),
|
||||
new UserInfo(MANAGED_PROFILE_ID, "managed profile", 0)));
|
||||
@@ -82,32 +148,12 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
| PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS
|
||||
| PackageManager.MATCH_ANY_USER,
|
||||
MAIN_USER_ID)).thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(MAIN_USER_ID, APP_1, 0 /* flags */)));
|
||||
when(mPackageManager.getInstallReason(APP_1, new UserHandle(MAIN_USER_ID)))
|
||||
.thenReturn(PackageManager.INSTALL_REASON_UNKNOWN);
|
||||
|
||||
ApplicationTestUtils.buildInfo(APP_1_UID, APP_1, 0 /* flags */,
|
||||
Build.VERSION_CODES.M)));
|
||||
when(mPackageManager.getInstalledApplicationsAsUser(PackageManager.GET_DISABLED_COMPONENTS
|
||||
| PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
|
||||
MANAGED_PROFILE_ID)).thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(MANAGED_PROFILE_ID, APP_2, 0 /* flags */)));
|
||||
when(mPackageManager.getInstallReason(APP_2, new UserHandle(MANAGED_PROFILE_ID)))
|
||||
.thenReturn(PackageManager.INSTALL_REASON_POLICY);
|
||||
|
||||
// Count all installed apps.
|
||||
mProvider.calculateNumberOfInstalledApps(ApplicationFeatureProvider.IGNORE_INSTALL_REASON,
|
||||
(num) -> {
|
||||
numberOfInstalledApps[0] = num;
|
||||
});
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
assertThat(numberOfInstalledApps[0]).isEqualTo(2);
|
||||
|
||||
// Count apps with specific install reason only.
|
||||
numberOfInstalledApps[0] = null;
|
||||
mProvider.calculateNumberOfInstalledApps(PackageManager.INSTALL_REASON_POLICY,
|
||||
(num) -> {
|
||||
numberOfInstalledApps[0] = num;
|
||||
});
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
assertThat(numberOfInstalledApps[0]).isEqualTo(1);
|
||||
ApplicationTestUtils.buildInfo(APP_2_UID, APP_2, 0 /* flags */,
|
||||
Build.VERSION_CODES.LOLLIPOP)));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user