Add number of enterprise-installed apps to Privacy Settings page

This CL adds information about the number of apps that were installed
by the admin to the Enterprise Privacy Settings page.

Test: make RunSettingsRoboTests
Bug: 32692748

Change-Id: Ib710a1249db6d285da962122fd3dfb35a43752a1
This commit is contained in:
Bartosz Fabianowski
2017-01-13 17:41:38 +01:00
parent 0d22680807
commit 13f569ebd6
16 changed files with 314 additions and 40 deletions

View File

@@ -22,6 +22,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.os.UserManager;
import com.android.settings.SettingsRobolectricTestRunner;
@@ -60,6 +61,13 @@ import static org.mockito.Mockito.when;
shadows = {ShadowUserManager.class})
public final class InstalledAppCounterTest {
private final String APP_1 = "app1";
private final String APP_2 = "app2";
private final String APP_3 = "app3";
private final String APP_4 = "app4";
private final String APP_5 = "app5";
private final String APP_6 = "app6";
private final int MAIN_USER_ID = 0;
private final int MANAGED_PROFILE_ID = 10;
@@ -101,14 +109,25 @@ public final class InstalledAppCounterTest {
| PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS
| PackageManager.MATCH_ANY_USER,
MAIN_USER_ID)).thenReturn(Arrays.asList(
buildInfo(MAIN_USER_ID, "app1", ApplicationInfo.FLAG_UPDATED_SYSTEM_APP),
buildInfo(MAIN_USER_ID, "app2", 0 /* flags */),
buildInfo(MAIN_USER_ID, "app3", ApplicationInfo.FLAG_SYSTEM),
buildInfo(MAIN_USER_ID, "app4", ApplicationInfo.FLAG_SYSTEM)));
buildInfo(MAIN_USER_ID, APP_1, ApplicationInfo.FLAG_UPDATED_SYSTEM_APP),
buildInfo(MAIN_USER_ID, APP_2, 0 /* flags */),
buildInfo(MAIN_USER_ID, APP_3, ApplicationInfo.FLAG_SYSTEM),
buildInfo(MAIN_USER_ID, APP_4, ApplicationInfo.FLAG_SYSTEM)));
// For system apps, InstalledAppCounter checks whether they handle the default launcher
// intent to decide whether to include them in the count of installed apps or not.
expectQueryIntentActivities(MAIN_USER_ID, "app3", true /* launchable */);
expectQueryIntentActivities(MAIN_USER_ID, "app4", false /* launchable */);
expectQueryIntentActivities(MAIN_USER_ID, APP_3, true /* launchable */);
expectQueryIntentActivities(MAIN_USER_ID, APP_4, false /* launchable */);
// app1, app3 and app4 are installed by enterprise policy.
final UserHandle mainUser = new UserHandle(MAIN_USER_ID);
when(mPackageManager.getInstallReason(APP_1, mainUser))
.thenReturn(PackageManager.INSTALL_REASON_POLICY);
when(mPackageManager.getInstallReason(APP_2, mainUser))
.thenReturn(PackageManager.INSTALL_REASON_UNKNOWN);
when(mPackageManager.getInstallReason(APP_3, mainUser))
.thenReturn(PackageManager.INSTALL_REASON_POLICY);
when(mPackageManager.getInstallReason(APP_4, mainUser))
.thenReturn(PackageManager.INSTALL_REASON_POLICY);
// The second user has four apps installed:
// * app5 is a user-installed app. It should be counted.
@@ -116,12 +135,21 @@ public final class InstalledAppCounterTest {
when(mPackageManager.getInstalledApplicationsAsUser(PackageManager.GET_DISABLED_COMPONENTS
| PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
MANAGED_PROFILE_ID)).thenReturn(Arrays.asList(
buildInfo(MANAGED_PROFILE_ID, "app5", 0 /* flags */),
buildInfo(MANAGED_PROFILE_ID, "app6", ApplicationInfo.FLAG_SYSTEM)));
expectQueryIntentActivities(MANAGED_PROFILE_ID, "app6", true /* launchable */);
buildInfo(MANAGED_PROFILE_ID, APP_5, 0 /* flags */),
buildInfo(MANAGED_PROFILE_ID, APP_6, ApplicationInfo.FLAG_SYSTEM)));
expectQueryIntentActivities(MANAGED_PROFILE_ID, APP_6, true /* launchable */);
// Count the number of apps installed. Wait for the background task to finish.
(new InstalledAppCounterTestable()).execute();
// app5 is installed by enterprise policy.
final UserHandle managedProfileUser = new UserHandle(MANAGED_PROFILE_ID);
when(mPackageManager.getInstallReason(APP_5, managedProfileUser))
.thenReturn(PackageManager.INSTALL_REASON_POLICY);
when(mPackageManager.getInstallReason(APP_6, managedProfileUser))
.thenReturn(PackageManager.INSTALL_REASON_UNKNOWN);
// Count the number of all apps installed, irrespective of install reason. Wait for the
// background task to finish.
(new InstalledAppCounterTestable(ApplicationFeatureProvider.IGNORE_INSTALL_REASON))
.execute();
ShadowApplication.runBackgroundTasks();
assertThat(mInstalledAppCount).isEqualTo(5);
@@ -134,11 +162,19 @@ public final class InstalledAppCounterTest {
verify(mPackageManager, atLeast(0)).queryIntentActivitiesAsUser(anyObject(), anyInt(),
anyInt());
verifyNoMoreInteractions(mPackageManager);
// Count once more, considering apps installed by enterprise policy only. Wait for the
// background task to finish.
mInstalledAppCount = 0;
(new InstalledAppCounterTestable(PackageManager.INSTALL_REASON_POLICY)).execute();
ShadowApplication.runBackgroundTasks();
assertThat(mInstalledAppCount).isEqualTo(3);
}
private class InstalledAppCounterTestable extends InstalledAppCounter {
public InstalledAppCounterTestable() {
super(mContext, mPackageManager);
public InstalledAppCounterTestable(int installReason) {
super(mContext, installReason, mPackageManager);
}
@Override