DO Disclosure: add UI that lists apps that were managed by owner:
- had permissions granted by admin - were installed by owner via policy Bug: 32692748 Test: m RunSettingsRoboTests Change-Id: I365e2f8f351671e68f83cceb7c0ca241d7a5a588
This commit is contained in:
@@ -22,12 +22,14 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
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.testutils.shadow.ShadowUserManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -75,16 +77,38 @@ public final class InstalledAppCounterTest {
|
||||
private final int MAIN_USER_APP_UID = MAIN_USER_ID * PER_USER_UID_RANGE;
|
||||
private final int MANAGED_PROFILE_APP_UID = MANAGED_PROFILE_ID * PER_USER_UID_RANGE;
|
||||
|
||||
@Mock private UserManager mUserManager;
|
||||
@Mock private Context mContext;
|
||||
@Mock private PackageManagerWrapper mPackageManager;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private PackageManagerWrapper mPackageManager;
|
||||
|
||||
private int mInstalledAppCount = -1;
|
||||
private ApplicationInfo mApp1;
|
||||
private ApplicationInfo mApp2;
|
||||
private ApplicationInfo mApp3;
|
||||
private ApplicationInfo mApp4;
|
||||
private ApplicationInfo mApp5;
|
||||
private ApplicationInfo mApp6;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
|
||||
mApp1 = buildInfo(MAIN_USER_APP_UID, APP_1,
|
||||
ApplicationInfo.FLAG_UPDATED_SYSTEM_APP, 0 /* targetSdkVersion */);
|
||||
mApp2 = buildInfo(MAIN_USER_APP_UID, APP_2, 0 /* flags */,
|
||||
0 /* targetSdkVersion */);
|
||||
mApp3 = buildInfo(MAIN_USER_APP_UID, APP_3, ApplicationInfo.FLAG_SYSTEM,
|
||||
0 /* targetSdkVersion */);
|
||||
mApp4 = buildInfo(MAIN_USER_APP_UID, APP_4, ApplicationInfo.FLAG_SYSTEM,
|
||||
0 /* targetSdkVersion */);
|
||||
mApp5 = buildInfo(MANAGED_PROFILE_APP_UID, APP_5, 0 /* flags */,
|
||||
0 /* targetSdkVersion */);
|
||||
mApp6 = buildInfo(MANAGED_PROFILE_APP_UID, APP_6, ApplicationInfo.FLAG_SYSTEM,
|
||||
0 /* targetSdkVersion */);
|
||||
}
|
||||
|
||||
private void expectQueryIntentActivities(int userId, String packageName, boolean launchable) {
|
||||
@@ -93,7 +117,7 @@ public final class InstalledAppCounterTest {
|
||||
eq(PackageManager.GET_DISABLED_COMPONENTS | PackageManager.MATCH_DIRECT_BOOT_AWARE
|
||||
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE),
|
||||
eq(userId))).thenReturn(launchable ? Arrays.asList(new ResolveInfo())
|
||||
: new ArrayList<ResolveInfo>());
|
||||
: new ArrayList<ResolveInfo>());
|
||||
}
|
||||
|
||||
private void testCountInstalledAppsAcrossAllUsers(boolean async) {
|
||||
@@ -101,58 +125,7 @@ public final class InstalledAppCounterTest {
|
||||
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)));
|
||||
|
||||
// The first user has four apps installed:
|
||||
// * app1 is an updated system app. It should be counted.
|
||||
// * app2 is a user-installed app. It should be counted.
|
||||
// * app3 is a system app that provides a launcher icon. It should be counted.
|
||||
// * app4 is a system app that provides no launcher icon. It should not be counted.
|
||||
when(mPackageManager.getInstalledApplicationsAsUser(PackageManager.GET_DISABLED_COMPONENTS
|
||||
| PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS
|
||||
| PackageManager.MATCH_ANY_USER,
|
||||
MAIN_USER_ID)).thenReturn(Arrays.asList(
|
||||
buildInfo(MAIN_USER_APP_UID, APP_1,
|
||||
ApplicationInfo.FLAG_UPDATED_SYSTEM_APP, 0 /* targetSdkVersion */),
|
||||
buildInfo(MAIN_USER_APP_UID, APP_2, 0 /* flags */,
|
||||
0 /* targetSdkVersion */),
|
||||
buildInfo(MAIN_USER_APP_UID, APP_3, ApplicationInfo.FLAG_SYSTEM,
|
||||
0 /* targetSdkVersion */),
|
||||
buildInfo(MAIN_USER_APP_UID, APP_4, ApplicationInfo.FLAG_SYSTEM,
|
||||
0 /* targetSdkVersion */)));
|
||||
// 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, 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 two apps installed:
|
||||
// * app5 is a user-installed app. It should be counted.
|
||||
// * app6 is a system app that provides a launcher icon. It should be counted.
|
||||
when(mPackageManager.getInstalledApplicationsAsUser(PackageManager.GET_DISABLED_COMPONENTS
|
||||
| PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
|
||||
MANAGED_PROFILE_ID)).thenReturn(Arrays.asList(
|
||||
buildInfo(MANAGED_PROFILE_APP_UID, APP_5, 0 /* flags */,
|
||||
0 /* targetSdkVersion */),
|
||||
buildInfo(MANAGED_PROFILE_APP_UID, APP_6, ApplicationInfo.FLAG_SYSTEM,
|
||||
0 /* targetSdkVersion */)));
|
||||
expectQueryIntentActivities(MANAGED_PROFILE_ID, APP_6, true /* launchable */);
|
||||
|
||||
// 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);
|
||||
configurePackageManager();
|
||||
|
||||
// Count the number of all apps installed, irrespective of install reason.
|
||||
count(InstalledAppCounter.IGNORE_INSTALL_REASON, async);
|
||||
@@ -172,6 +145,36 @@ public final class InstalledAppCounterTest {
|
||||
assertThat(mInstalledAppCount).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncludeInCount() {
|
||||
configurePackageManager();
|
||||
assertThat(InstalledAppCounter.includeInCount(InstalledAppCounter.IGNORE_INSTALL_REASON,
|
||||
mPackageManager, mApp1)).isTrue();
|
||||
assertThat(InstalledAppCounter.includeInCount(InstalledAppCounter.IGNORE_INSTALL_REASON,
|
||||
mPackageManager, mApp2)).isTrue();
|
||||
assertThat(InstalledAppCounter.includeInCount(InstalledAppCounter.IGNORE_INSTALL_REASON,
|
||||
mPackageManager, mApp3)).isTrue();
|
||||
assertThat(InstalledAppCounter.includeInCount(InstalledAppCounter.IGNORE_INSTALL_REASON,
|
||||
mPackageManager, mApp4)).isFalse();
|
||||
assertThat(InstalledAppCounter.includeInCount(InstalledAppCounter.IGNORE_INSTALL_REASON,
|
||||
mPackageManager, mApp5)).isTrue();
|
||||
assertThat(InstalledAppCounter.includeInCount(InstalledAppCounter.IGNORE_INSTALL_REASON,
|
||||
mPackageManager, mApp6)).isTrue();
|
||||
|
||||
assertThat(InstalledAppCounter.includeInCount(PackageManager.INSTALL_REASON_POLICY,
|
||||
mPackageManager, mApp1)).isTrue();
|
||||
assertThat(InstalledAppCounter.includeInCount(PackageManager.INSTALL_REASON_POLICY,
|
||||
mPackageManager, mApp2)).isFalse();
|
||||
assertThat(InstalledAppCounter.includeInCount(PackageManager.INSTALL_REASON_POLICY,
|
||||
mPackageManager, mApp3)).isTrue();
|
||||
assertThat(InstalledAppCounter.includeInCount(PackageManager.INSTALL_REASON_POLICY,
|
||||
mPackageManager, mApp4)).isFalse();
|
||||
assertThat(InstalledAppCounter.includeInCount(PackageManager.INSTALL_REASON_POLICY,
|
||||
mPackageManager, mApp5)).isTrue();
|
||||
assertThat(InstalledAppCounter.includeInCount(PackageManager.INSTALL_REASON_POLICY,
|
||||
mPackageManager, mApp6)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountInstalledAppsAcrossAllUsersSync() {
|
||||
testCountInstalledAppsAcrossAllUsers(false /* async */);
|
||||
@@ -194,6 +197,48 @@ public final class InstalledAppCounterTest {
|
||||
}
|
||||
}
|
||||
|
||||
private void configurePackageManager() {
|
||||
// The first user has four apps installed:
|
||||
// * app1 is an updated system app. It should be counted.
|
||||
// * app2 is a user-installed app. It should be counted.
|
||||
// * app3 is a system app that provides a launcher icon. It should be counted.
|
||||
// * app4 is a system app that provides no launcher icon. It should not be counted.
|
||||
when(mPackageManager.getInstalledApplicationsAsUser(PackageManager.GET_DISABLED_COMPONENTS
|
||||
| PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS
|
||||
| PackageManager.MATCH_ANY_USER,
|
||||
MAIN_USER_ID)).thenReturn(Arrays.asList(mApp1, mApp2, mApp3, mApp4));
|
||||
// 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, 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 two apps installed:
|
||||
// * app5 is a user-installed app. It should be counted.
|
||||
// * app6 is a system app that provides a launcher icon. It should be counted.
|
||||
when(mPackageManager.getInstalledApplicationsAsUser(PackageManager.GET_DISABLED_COMPONENTS
|
||||
| PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,MANAGED_PROFILE_ID))
|
||||
.thenReturn(Arrays.asList(mApp5, mApp6));
|
||||
expectQueryIntentActivities(MANAGED_PROFILE_ID, APP_6, true /* launchable */);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
private class InstalledAppCounterTestable extends InstalledAppCounter {
|
||||
public InstalledAppCounterTestable(int installReason) {
|
||||
|
Reference in New Issue
Block a user