Finish 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 switches the remaining PreferenceControllers from setting visibility
to implementing isAvailable() instead.

Bug: 32692748
Test: m RunSettingsRoboTests

Change-Id: I54360698f28b549b18cdc230e3b9087cf4e9ff4a
This commit is contained in:
Bartosz Fabianowski
2017-03-20 15:27:28 +01:00
parent 4a19625286
commit b076e00c5e
32 changed files with 255 additions and 217 deletions

View File

@@ -89,8 +89,7 @@ public final class AppWithAdminGrantedPermissionsCounterTest {
MockitoAnnotations.initMocks(this);
}
@Test
public void testCountInstalledAppsAcrossAllUsers() throws Exception {
private void verifyCountInstalledAppsAcrossAllUsers(boolean async) throws Exception {
// There are two users.
mUsersToCount = Arrays.asList(
new UserInfo(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN),
@@ -181,10 +180,14 @@ public final class AppWithAdminGrantedPermissionsCounterTest {
.thenReturn(PackageManager.INSTALL_REASON_UNKNOWN);
// Count the number of all apps installed that were granted on or more permissions by the
// admin. Wait for the background task to finish.
(new AppWithAdminGrantedPermissionsCounterTestable(PERMISSIONS)).execute();
ShadowApplication.runBackgroundTasks();
// admin.
if (async) {
(new AppWithAdminGrantedPermissionsCounterTestable(PERMISSIONS)).execute();
// Wait for the background task to finish.
ShadowApplication.runBackgroundTasks();
} else {
(new AppWithAdminGrantedPermissionsCounterTestable(PERMISSIONS)).executeInForeground();
}
assertThat(mAppCount).isEqualTo(3);
// Verify that installed packages were retrieved for the users returned by
@@ -194,7 +197,16 @@ public final class AppWithAdminGrantedPermissionsCounterTest {
eq(MANAGED_PROFILE_ID));
verify(mPackageManager, atLeast(0)).getInstallReason(anyObject(), anyObject());
verifyNoMoreInteractions(mPackageManager);
}
@Test
public void testCountInstalledAppsAcrossAllUsersSync() throws Exception {
verifyCountInstalledAppsAcrossAllUsers(false /* async */);
}
@Test
public void testCountInstalledAppsAcrossAllUsersAync() throws Exception {
verifyCountInstalledAppsAcrossAllUsers(true /* async */);
}
private class AppWithAdminGrantedPermissionsCounterTestable extends

View File

@@ -88,7 +88,7 @@ public final class ApplicationFeatureProviderImplTest {
mPackageManagerService, mDevicePolicyManager);
}
private void testCalculateNumberOfInstalledApps(boolean async) {
private void verifyCalculateNumberOfInstalledApps(boolean async) {
setUpUsersAndInstalledApps();
when(mPackageManager.getInstallReason(APP_1, new UserHandle(MAIN_USER_ID)))
@@ -117,16 +117,16 @@ public final class ApplicationFeatureProviderImplTest {
@Test
public void testCalculateNumberOfInstalledAppsSync() {
testCalculateNumberOfInstalledApps(false /* async */);
verifyCalculateNumberOfInstalledApps(false /* async */);
}
@Test
public void testCalculateNumberOfInstalledAppsAsync() {
testCalculateNumberOfInstalledApps(true /* async */);
verifyCalculateNumberOfInstalledApps(true /* async */);
}
@Test
public void testCalculateNumberOfAppsWithAdminGrantedPermissions() throws Exception {
private void verifyCalculateNumberOfAppsWithAdminGrantedPermissions(boolean async)
throws Exception {
setUpUsersAndInstalledApps();
when(mDevicePolicyManager.getPermissionGrantState(null, APP_1, PERMISSION))
@@ -143,15 +143,25 @@ public final class ApplicationFeatureProviderImplTest {
.thenReturn(PackageManager.INSTALL_REASON_POLICY);
mAppCount = -1;
mProvider.calculateNumberOfAppsWithAdminGrantedPermissions(new String[] {PERMISSION},
(num) -> {
mAppCount = num;
});
ShadowApplication.runBackgroundTasks();
mProvider.calculateNumberOfAppsWithAdminGrantedPermissions(new String[] {PERMISSION}, async,
(num) -> mAppCount = num);
if (async) {
ShadowApplication.runBackgroundTasks();
}
assertThat(mAppCount).isEqualTo(2);
}
@Test
public void testCalculateNumberOfAppsWithAdminGrantedPermissionsSync() throws Exception {
verifyCalculateNumberOfAppsWithAdminGrantedPermissions(false /* async */);
}
@Test
public void testCalculateNumberOfAppsWithAdminGrantedPermissionsAsync() throws Exception {
verifyCalculateNumberOfAppsWithAdminGrantedPermissions(true /* async */);
}
@Test
public void testFindPersistentPreferredActivities() throws Exception {
when(mUserManager.getUserProfiles()).thenReturn(Arrays.asList(new UserHandle(MAIN_USER_ID),

View File

@@ -39,8 +39,8 @@ public final class AdminGrantedCameraPermissionPreferenceControllerTest extends
}
@Override
public void setUp() {
super.setUp();
mController = new AdminGrantedCameraPermissionPreferenceController(mContext);
protected AdminGrantedPermissionsPreferenceControllerBase createController(boolean async) {
return new AdminGrantedCameraPermissionPreferenceController(mContext,null /* lifecycle */,
async);
}
}

View File

@@ -40,8 +40,8 @@ public final class AdminGrantedLocationPermissionsPreferenceControllerTest exten
}
@Override
public void setUp() {
super.setUp();
mController = new AdminGrantedLocationPermissionsPreferenceController(mContext);
protected AdminGrantedPermissionsPreferenceControllerBase createController(boolean async) {
return new AdminGrantedLocationPermissionsPreferenceController(mContext,
null /* lifecycle */, async);
}
}

View File

@@ -39,8 +39,8 @@ public final class AdminGrantedMicrophonePermissionPreferenceControllerTest exte
}
@Override
public void setUp() {
super.setUp();
mController = new AdminGrantedMicrophonePermissionPreferenceController(mContext);
protected AdminGrantedPermissionsPreferenceControllerBase createController(boolean async) {
return new AdminGrantedMicrophonePermissionPreferenceController(mContext,
null /* lifecycle */, async);
}
}

View File

@@ -40,17 +40,16 @@ public final class AdminGrantedPermissionsPreferenceControllerBaseTest extends
}
@Override
public void setUp() {
super.setUp();
mController = new AdminGrantedPermissionsPreferenceControllerBaseTestable();
protected AdminGrantedPermissionsPreferenceControllerBase createController(boolean async) {
return new AdminGrantedPermissionsPreferenceControllerBaseTestable(async);
}
private class AdminGrantedPermissionsPreferenceControllerBaseTestable extends
AdminGrantedPermissionsPreferenceControllerBase {
AdminGrantedPermissionsPreferenceControllerBaseTestable() {
super(AdminGrantedPermissionsPreferenceControllerBaseTest.this.mContext, mPermissions,
mPermissionGroup);
AdminGrantedPermissionsPreferenceControllerBaseTestable(boolean async) {
super(AdminGrantedPermissionsPreferenceControllerBaseTest.this.mContext,
null /* lifecycle */, async, mPermissions, mPermissionGroup);
}
@Override

View File

@@ -68,39 +68,56 @@ public abstract class AdminGrantedPermissionsPreferenceControllerTestBase {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mController = createController(true /* async */);
}
private void setNumberOfPackagesWithAdminGrantedPermissions(int number) {
private void setNumberOfPackagesWithAdminGrantedPermissions(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)
.calculateNumberOfAppsWithAdminGrantedPermissions(eq(mPermissions),
anyObject());
eq(async), anyObject());
}
@Test
public void testUpdateState() {
final Preference preference = new Preference(mContext, null, 0, 0);
preference.setVisible(false);
preference.setVisible(true);
setNumberOfPackagesWithAdminGrantedPermissions(20);
setNumberOfPackagesWithAdminGrantedPermissions(0, true /* async */);
mController.updateState(preference);
assertThat(preference.isVisible()).isFalse();
setNumberOfPackagesWithAdminGrantedPermissions(20, true /* async */);
when(mContext.getResources().getQuantityString(
R.plurals.enterprise_privacy_number_packages_actionable,20, 20))
.thenReturn("20 packages");
mController.updateState(preference);
assertThat(preference.getSummary()).isEqualTo("20 packages");
assertThat(preference.isVisible()).isTrue();
setNumberOfPackagesWithAdminGrantedPermissions(0);
mController.updateState(preference);
assertThat(preference.isVisible()).isFalse();
}
@Test
public void testIsAvailable() {
public void testIsAvailableSync() {
final AdminGrantedPermissionsPreferenceControllerBase controller
= createController(false /* async */);
setNumberOfPackagesWithAdminGrantedPermissions(0, false /* async */);
assertThat(controller.isAvailable()).isFalse();
setNumberOfPackagesWithAdminGrantedPermissions(20, false /* async */);
assertThat(controller.isAvailable()).isTrue();
}
@Test
public void testIsAvailableAsync() {
setNumberOfPackagesWithAdminGrantedPermissions(0, true /* async */);
assertThat(mController.isAvailable()).isTrue();
setNumberOfPackagesWithAdminGrantedPermissions(20, true /* async */);
assertThat(mController.isAvailable()).isTrue();
}
@@ -125,4 +142,7 @@ public abstract class AdminGrantedPermissionsPreferenceControllerTestBase {
public void testGetPreferenceKey() {
assertThat(mController.getPreferenceKey()).isEqualTo(mKey);
}
protected abstract AdminGrantedPermissionsPreferenceControllerBase createController(
boolean async);
}

View File

@@ -52,27 +52,18 @@ public final class AlwaysOnVpnManagedProfilePreferenceControllerTest {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mController = new AlwaysOnVpnManagedProfilePreferenceController(mContext);
}
@Test
public void testUpdateState() {
final Preference preference = new Preference(mContext, null, 0, 0);
preference.setVisible(true);
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInManagedProfile())
.thenReturn(false);
mController.updateState(preference);
assertThat(preference.isVisible()).isFalse();
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInManagedProfile())
.thenReturn(true);
mController.updateState(preference);
assertThat(preference.isVisible()).isTrue();
mController = new AlwaysOnVpnManagedProfilePreferenceController(mContext,
null /* lifecycle */);
}
@Test
public void testIsAvailable() {
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInManagedProfile())
.thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInManagedProfile())
.thenReturn(true);
assertThat(mController.isAvailable()).isTrue();
}

View File

@@ -56,7 +56,8 @@ public final class AlwaysOnVpnPrimaryUserPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mController = new AlwaysOnVpnPrimaryUserPreferenceController(mContext);
mController = new AlwaysOnVpnPrimaryUserPreferenceController(mContext,
null /* lifecycle */);
when(mContext.getString(R.string.enterprise_privacy_always_on_vpn_device))
.thenReturn(VPN_SET_DEVICE);
when(mContext.getString(R.string.enterprise_privacy_always_on_vpn_personal))
@@ -66,37 +67,27 @@ public final class AlwaysOnVpnPrimaryUserPreferenceControllerTest {
@Test
public void testUpdateState() {
final Preference preference = new Preference(mContext, null, 0, 0);
preference.setVisible(true);
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(false);
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
.thenReturn(false);
mController.updateState(preference);
assertThat(preference.isVisible()).isFalse();
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
.thenReturn(true);
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(false);
mController.updateState(preference);
assertThat(preference.isVisible()).isTrue();
assertThat(preference.getTitle()).isEqualTo(VPN_SET_DEVICE);
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(true);
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
.thenReturn(false);
mController.updateState(preference);
assertThat(preference.isVisible()).isFalse();
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
.thenReturn(true);
mController.updateState(preference);
assertThat(preference.isVisible()).isTrue();
assertThat(preference.getTitle()).isEqualTo(VPN_SET_PERSONAL);
}
@Test
public void testIsAvailable() {
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
.thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
.thenReturn(true);
assertThat(mController.isAvailable()).isTrue();
}

View File

@@ -54,32 +54,29 @@ public final class CaCertsPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mController = new CaCertsPreferenceController(mContext);
when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_ca_certs,
10, 10)).thenReturn("10 certs");
mController = new CaCertsPreferenceController(mContext, null /* lifecycle */);
}
@Test
public void testUpdateState() {
final Preference preference = new Preference(mContext, null, 0, 0);
preference.setVisible(true);
when(mFeatureFactory.enterprisePrivacyFeatureProvider
.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()).thenReturn(0);
mController.updateState(preference);
assertThat(preference.isVisible()).isFalse();
preference.setVisible(false);
when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_ca_certs,
10, 10)).thenReturn("10 certs");
when(mFeatureFactory.enterprisePrivacyFeatureProvider
.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()).thenReturn(10);
mController.updateState(preference);
assertThat(preference.isVisible()).isTrue();
assertThat(preference.getSummary()).isEqualTo("10 certs");
}
@Test
public void testIsAvailable() {
when(mFeatureFactory.enterprisePrivacyFeatureProvider
.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()).thenReturn(0);
assertThat(mController.isAvailable()).isFalse();
when(mFeatureFactory.enterprisePrivacyFeatureProvider
.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()).thenReturn(10);
assertThat(mController.isAvailable()).isTrue();
}

View File

@@ -96,7 +96,7 @@ public final class EnterpriseInstalledPackagesPreferenceControllerTest {
@Test
public void testIsAvailableSync() {
EnterpriseInstalledPackagesPreferenceController controller
final EnterpriseInstalledPackagesPreferenceController controller
= new EnterpriseInstalledPackagesPreferenceController(mContext,
null /* lifecycle */, false /* async */);

View File

@@ -43,7 +43,8 @@ public final class FailedPasswordWipeManagedProfilePreferenceControllerTest exte
@Override
public void setUp() {
super.setUp();
mController = new FailedPasswordWipeManagedProfilePreferenceController(mContext);
mController = new FailedPasswordWipeManagedProfilePreferenceController(mContext,
null /* lifecycle */);
}
@Override

View File

@@ -50,7 +50,8 @@ public final class FailedPasswordWipePreferenceControllerBaseTest extends
private class FailedPasswordWipePreferenceControllerBaseTestable extends
FailedPasswordWipePreferenceControllerBase {
FailedPasswordWipePreferenceControllerBaseTestable() {
super(FailedPasswordWipePreferenceControllerBaseTest.this.mContext);
super(FailedPasswordWipePreferenceControllerBaseTest.this.mContext,
null /* lifecycle */);
}
@Override

View File

@@ -61,7 +61,6 @@ public abstract class FailedPasswordWipePreferenceControllerTestBase {
@Test
public void testUpdateState() {
final Preference preference = new Preference(mContext, null, 0, 0);
preference.setVisible(false);
setMaximumFailedPasswordsBeforeWipe(10);
when(mContext.getResources().getQuantityString(
@@ -69,14 +68,14 @@ public abstract class FailedPasswordWipePreferenceControllerTestBase {
.thenReturn("10 attempts");
mController.updateState(preference);
assertThat(preference.getSummary()).isEqualTo("10 attempts");
setMaximumFailedPasswordsBeforeWipe(0);
mController.updateState(preference);
assertThat(preference.isVisible()).isFalse();
}
@Test
public void testIsAvailable() {
setMaximumFailedPasswordsBeforeWipe(0);
assertThat(mController.isAvailable()).isFalse();
setMaximumFailedPasswordsBeforeWipe(10);
assertThat(mController.isAvailable()).isTrue();
}

View File

@@ -43,7 +43,8 @@ public final class FailedPasswordWipePrimaryUserPreferenceControllerTest extends
@Override
public void setUp() {
super.setUp();
mController = new FailedPasswordWipePrimaryUserPreferenceController(mContext);
mController = new FailedPasswordWipePrimaryUserPreferenceController(mContext,
null /* lifecycle */);
}
@Override

View File

@@ -51,27 +51,17 @@ public final class GlobalHttpProxyPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mController = new GlobalHttpProxyPreferenceController(mContext);
}
@Test
public void testUpdateState() {
final Preference preference = new Preference(mContext, null, 0, 0);
preference.setVisible(true);
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isGlobalHttpProxySet())
.thenReturn(false);
mController.updateState(preference);
assertThat(preference.isVisible()).isFalse();
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isGlobalHttpProxySet())
.thenReturn(true);
mController.updateState(preference);
assertThat(preference.isVisible()).isTrue();
mController = new GlobalHttpProxyPreferenceController(mContext, null /* lifecycle */);
}
@Test
public void testIsAvailable() {
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isGlobalHttpProxySet())
.thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isGlobalHttpProxySet())
.thenReturn(true);
assertThat(mController.isAvailable()).isTrue();
}

View File

@@ -57,7 +57,7 @@ public final class ImePreferenceControllerTest {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mController = new ImePreferenceController(mContext);
mController = new ImePreferenceController(mContext, null /* lifecycle */);
when(mContext.getResources().getString(R.string.enterprise_privacy_input_method_name,
DEFAULT_IME_LABEL)).thenReturn(DEFAULT_IME_TEXT);
}
@@ -65,22 +65,21 @@ public final class ImePreferenceControllerTest {
@Test
public void testUpdateState() {
final Preference preference = new Preference(mContext, null, 0, 0);
preference.setVisible(true);
when(mFeatureFactory.enterprisePrivacyFeatureProvider.getImeLabelIfOwnerSet())
.thenReturn(null);
mController.updateState(preference);
assertThat(preference.isVisible()).isFalse();
when(mFeatureFactory.enterprisePrivacyFeatureProvider.getImeLabelIfOwnerSet())
.thenReturn(DEFAULT_IME_LABEL);
mController.updateState(preference);
assertThat(preference.isVisible()).isTrue();
assertThat(preference.getSummary()).isEqualTo(DEFAULT_IME_TEXT);
}
@Test
public void testIsAvailable() {
when(mFeatureFactory.enterprisePrivacyFeatureProvider.getImeLabelIfOwnerSet())
.thenReturn(null);
assertThat(mController.isAvailable()).isFalse();
when(mFeatureFactory.enterprisePrivacyFeatureProvider.getImeLabelIfOwnerSet())
.thenReturn(DEFAULT_IME_LABEL);
assertThat(mController.isAvailable()).isTrue();
}