Start removing N/A DO disclosures from search index
DO disclosures referring to actions that the admin did not actually take are hidden in the UI, but still show up in the search index. This CL takes the following steps toward fixing this: * Pass the list of PreferenceControllers to the search indexer * Make the first two PrefrenceControllers set isAvailable() correctly There are more disclosures to update, but the difficult work is done as all others will follow the same pattern. Bug: 32692748 Test: m RunSettingsRoboTests Change-Id: I7d3e248b80abe72b79fce7afa11f28a822de6986
This commit is contained in:
@@ -88,8 +88,7 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
mPackageManagerService, mDevicePolicyManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalculateNumberOfInstalledApps() {
|
||||
private void testCalculateNumberOfInstalledApps(boolean async) {
|
||||
setUpUsersAndInstalledApps();
|
||||
|
||||
when(mPackageManager.getInstallReason(APP_1, new UserHandle(MAIN_USER_ID)))
|
||||
@@ -100,22 +99,32 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
// Count all installed apps.
|
||||
mAppCount = -1;
|
||||
mProvider.calculateNumberOfInstalledApps(ApplicationFeatureProvider.IGNORE_INSTALL_REASON,
|
||||
(num) -> {
|
||||
mAppCount = num;
|
||||
});
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
async, (num) -> mAppCount = num);
|
||||
if (async) {
|
||||
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();
|
||||
mProvider.calculateNumberOfInstalledApps(PackageManager.INSTALL_REASON_POLICY, async,
|
||||
(num) -> mAppCount = num);
|
||||
if (async) {
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
}
|
||||
assertThat(mAppCount).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalculateNumberOfInstalledAppsSync() {
|
||||
testCalculateNumberOfInstalledApps(false /* async */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalculateNumberOfInstalledAppsAsync() {
|
||||
testCalculateNumberOfInstalledApps(true /* async */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalculateNumberOfAppsWithAdminGrantedPermissions() throws Exception {
|
||||
setUpUsersAndInstalledApps();
|
||||
|
@@ -97,8 +97,7 @@ public final class InstalledAppCounterTest {
|
||||
: new ArrayList<ResolveInfo>());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountInstalledAppsAcrossAllUsers() {
|
||||
private void testCountInstalledAppsAcrossAllUsers(boolean async) {
|
||||
// There are two users.
|
||||
mUsersToCount = Arrays.asList(
|
||||
new UserInfo(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN),
|
||||
@@ -156,12 +155,8 @@ public final class InstalledAppCounterTest {
|
||||
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();
|
||||
|
||||
// Count the number of all apps installed, irrespective of install reason.
|
||||
count(ApplicationFeatureProvider.IGNORE_INSTALL_REASON, async);
|
||||
assertThat(mInstalledAppCount).isEqualTo(5);
|
||||
|
||||
// Verify that installed packages were retrieved for the users returned by
|
||||
@@ -173,15 +168,34 @@ public final class InstalledAppCounterTest {
|
||||
anyInt());
|
||||
verifyNoMoreInteractions(mPackageManager);
|
||||
|
||||
// Count once more, considering apps installed by enterprise policy only. Wait for the
|
||||
// background task to finish.
|
||||
mInstalledAppCount = -1;
|
||||
(new InstalledAppCounterTestable(PackageManager.INSTALL_REASON_POLICY)).execute();
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
|
||||
// Count once more, considering apps installed by enterprise policy only.
|
||||
count(PackageManager.INSTALL_REASON_POLICY, async);
|
||||
assertThat(mInstalledAppCount).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountInstalledAppsAcrossAllUsersSync() {
|
||||
testCountInstalledAppsAcrossAllUsers(false /* async */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountInstalledAppsAcrossAllUsersAsync() {
|
||||
testCountInstalledAppsAcrossAllUsers(true /* async */);
|
||||
}
|
||||
|
||||
private void count(int installReason, boolean async) {
|
||||
mInstalledAppCount = -1;
|
||||
final InstalledAppCounterTestable counter = new InstalledAppCounterTestable(installReason);
|
||||
if (async) {
|
||||
counter.execute();
|
||||
// Wait for the background task to finish.
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
} else {
|
||||
counter.executeInForeground();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class InstalledAppCounterTestable extends InstalledAppCounter {
|
||||
public InstalledAppCounterTestable(int installReason) {
|
||||
super(mContext, installReason, mPackageManager);
|
||||
|
@@ -62,18 +62,19 @@ public final class EnterpriseInstalledPackagesPreferenceControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mController = new EnterpriseInstalledPackagesPreferenceController(mContext);
|
||||
mController = new EnterpriseInstalledPackagesPreferenceController(mContext,
|
||||
null /* lifecycle */, true /* async */);
|
||||
}
|
||||
|
||||
private void setNumberOfEnterpriseInstalledPackages(int number) {
|
||||
private void setNumberOfEnterpriseInstalledPackages(int number, boolean async) {
|
||||
doAnswer(new Answer() {
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
((ApplicationFeatureProvider.NumberOfAppsCallback)
|
||||
invocation.getArguments()[1]).onNumberOfAppsResult(number);
|
||||
invocation.getArguments()[2]).onNumberOfAppsResult(number);
|
||||
return null;
|
||||
}}).when(mFeatureFactory.applicationFeatureProvider)
|
||||
.calculateNumberOfInstalledApps(eq(PackageManager.INSTALL_REASON_POLICY),
|
||||
anyObject());
|
||||
eq(async), anyObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,11 +82,11 @@ public final class EnterpriseInstalledPackagesPreferenceControllerTest {
|
||||
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||
preference.setVisible(true);
|
||||
|
||||
setNumberOfEnterpriseInstalledPackages(0);
|
||||
setNumberOfEnterpriseInstalledPackages(0, true /* async */);
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.isVisible()).isFalse();
|
||||
|
||||
setNumberOfEnterpriseInstalledPackages(20);
|
||||
setNumberOfEnterpriseInstalledPackages(20, true /* async */);
|
||||
when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_packages,
|
||||
20, 20)).thenReturn("20 packages");
|
||||
mController.updateState(preference);
|
||||
@@ -94,7 +95,24 @@ public final class EnterpriseInstalledPackagesPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
public void testIsAvailableSync() {
|
||||
EnterpriseInstalledPackagesPreferenceController controller
|
||||
= new EnterpriseInstalledPackagesPreferenceController(mContext,
|
||||
null /* lifecycle */, false /* async */);
|
||||
|
||||
setNumberOfEnterpriseInstalledPackages(0, false /* async */);
|
||||
assertThat(controller.isAvailable()).isFalse();
|
||||
|
||||
setNumberOfEnterpriseInstalledPackages(20, false /* async */);
|
||||
assertThat(controller.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailableAsync() {
|
||||
setNumberOfEnterpriseInstalledPackages(0, true /* async */);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
|
||||
setNumberOfEnterpriseInstalledPackages(20, true /* async */);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
|
@@ -104,6 +104,18 @@ public final class EnterprisePrivacySettingsTest {
|
||||
public void getPreferenceControllers() {
|
||||
final List<PreferenceController> controllers = mSettings.getPreferenceControllers(
|
||||
ShadowApplication.getInstance().getApplicationContext());
|
||||
verifyPreferenceControllers(controllers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSearchIndexProviderPreferenceControllers() {
|
||||
final List<PreferenceController> controllers
|
||||
= EnterprisePrivacySettings.SEARCH_INDEX_DATA_PROVIDER.getPreferenceControllers(
|
||||
ShadowApplication.getInstance().getApplicationContext());
|
||||
verifyPreferenceControllers(controllers);
|
||||
}
|
||||
|
||||
private void verifyPreferenceControllers(List<PreferenceController> controllers) {
|
||||
assertThat(controllers).isNotNull();
|
||||
assertThat(controllers.size()).isEqualTo(17);
|
||||
assertThat(controllers.get(0)).isInstanceOf(InstalledPackagesPreferenceController.class);
|
||||
|
@@ -65,7 +65,8 @@ public final class EnterpriseSetDefaultAppsPreferenceControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mController = new EnterpriseSetDefaultAppsPreferenceController(mContext);
|
||||
mController = new EnterpriseSetDefaultAppsPreferenceController(mContext,
|
||||
null /* lifecycle */);
|
||||
}
|
||||
|
||||
private static Intent buildIntent(String action, String category, String protocol,
|
||||
@@ -95,15 +96,6 @@ public final class EnterpriseSetDefaultAppsPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateState() {
|
||||
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||
preference.setVisible(true);
|
||||
|
||||
when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(
|
||||
anyObject())).thenReturn(
|
||||
new ArraySet<ApplicationFeatureProvider.PersistentPreferredActivityInfo>());
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.isVisible()).isFalse();
|
||||
|
||||
setEnterpriseSetDefaultApps(new Intent[] {buildIntent(Intent.ACTION_VIEW,
|
||||
Intent.CATEGORY_BROWSABLE, "http:", null)}, 1);
|
||||
setEnterpriseSetDefaultApps(new Intent[] {new Intent(MediaStore.ACTION_IMAGE_CAPTURE),
|
||||
@@ -120,13 +112,21 @@ public final class EnterpriseSetDefaultAppsPreferenceControllerTest {
|
||||
new Intent(Intent.ACTION_CALL)}, 64);
|
||||
when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_packages,
|
||||
127, 127)).thenReturn("127 apps");
|
||||
|
||||
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.getSummary()).isEqualTo("127 apps");
|
||||
assertThat(preference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(
|
||||
anyObject())).thenReturn(
|
||||
new ArraySet<ApplicationFeatureProvider.PersistentPreferredActivityInfo>());
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
|
||||
setEnterpriseSetDefaultApps(new Intent[] {buildIntent(Intent.ACTION_VIEW,
|
||||
Intent.CATEGORY_BROWSABLE, "http:", null)}, 1);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
|
@@ -68,11 +68,10 @@ public final class InstalledPackagesPreferenceControllerTest {
|
||||
doAnswer(new Answer() {
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
((ApplicationFeatureProvider.NumberOfAppsCallback)
|
||||
invocation.getArguments()[1]).onNumberOfAppsResult(number);
|
||||
invocation.getArguments()[2]).onNumberOfAppsResult(number);
|
||||
return null;
|
||||
}}).when(mFeatureFactory.applicationFeatureProvider)
|
||||
.calculateNumberOfInstalledApps(
|
||||
eq(ApplicationFeatureProvider.IGNORE_INSTALL_REASON), anyObject());
|
||||
}}).when(mFeatureFactory.applicationFeatureProvider).calculateNumberOfInstalledApps(
|
||||
eq(ApplicationFeatureProvider.IGNORE_INSTALL_REASON), eq(true), anyObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user