diff --git a/res/values/strings.xml b/res/values/strings.xml index 11aa84cbd9f..ee80a3eb2b9 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -8270,7 +8270,7 @@ List of apps on your device - Time and data spent in each app on your device + Amount of time and data spent in each app Network traffic logs on your device @@ -8281,6 +8281,8 @@ None Apps installed + + Number of apps is estimated. It may not include apps installed outside of the Play Store. Minimum %d app diff --git a/res/xml/enterprise_privacy_settings.xml b/res/xml/enterprise_privacy_settings.xml index e6246c2c43b..be51caea45d 100644 --- a/res/xml/enterprise_privacy_settings.xml +++ b/res/xml/enterprise_privacy_settings.xml @@ -32,7 +32,6 @@ android:title="@string/enterprise_privacy_enterprise_data" settings:multiLine="true"/> { if (num == 0) { preference.setVisible(false); @@ -69,8 +66,8 @@ public class EnterpriseInstalledPackagesPreferenceController // changes to the pref's visibility made in updateState() would not be seen by the indexer. // We block and return synchronously whether there are enterprise-installed apps or not. final Boolean[] haveEnterpriseInstalledPackages = { null }; - mFeatureProvider.calculateNumberOfInstalledApps(PackageManager.INSTALL_REASON_POLICY, - false /* async */, (num) -> haveEnterpriseInstalledPackages[0] = num > 0); + mFeatureProvider.calculateNumberOfPolicyInstalledApps(false /* async */, + (num) -> haveEnterpriseInstalledPackages[0] = num > 0); return haveEnterpriseInstalledPackages[0]; } diff --git a/src/com/android/settings/enterprise/EnterprisePrivacySettings.java b/src/com/android/settings/enterprise/EnterprisePrivacySettings.java index 55ec3ea2886..9649d849ce8 100644 --- a/src/com/android/settings/enterprise/EnterprisePrivacySettings.java +++ b/src/com/android/settings/enterprise/EnterprisePrivacySettings.java @@ -58,7 +58,6 @@ public class EnterprisePrivacySettings extends DashboardFragment { private static List buildPreferenceControllers(Context context, Lifecycle lifecycle, boolean async) { final List controllers = new ArrayList(); - controllers.add(new InstalledPackagesPreferenceController(context)); controllers.add(new NetworkLogsPreferenceController(context)); controllers.add(new BugReportsPreferenceController(context)); controllers.add(new SecurityLogsPreferenceController(context)); diff --git a/src/com/android/settings/enterprise/InstalledPackagesPreferenceController.java b/src/com/android/settings/enterprise/InstalledPackagesPreferenceController.java deleted file mode 100644 index 43436b147d1..00000000000 --- a/src/com/android/settings/enterprise/InstalledPackagesPreferenceController.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ -package com.android.settings.enterprise; - -import android.content.Context; -import android.content.res.Resources; -import android.support.v7.preference.Preference; - -import com.android.settings.R; -import com.android.settings.applications.ApplicationFeatureProvider; -import com.android.settings.core.PreferenceController; -import com.android.settings.overlay.FeatureFactory; - -public class InstalledPackagesPreferenceController extends PreferenceController { - - private static final String KEY_INSTALLED_PACKAGES = "installed_packages"; - private final ApplicationFeatureProvider mFeatureProvider; - - public InstalledPackagesPreferenceController(Context context) { - super(context); - mFeatureProvider = FeatureFactory.getFactory(context) - .getApplicationFeatureProvider(context); - } - - @Override - public void updateState(Preference preference) { - mFeatureProvider.calculateNumberOfInstalledApps( - ApplicationFeatureProvider.IGNORE_INSTALL_REASON, true /* async */, - (num) -> { - if (num == 0) { - preference.setSummary(""); - } else { - preference.setSummary(mContext.getResources().getQuantityString( - R.plurals.enterprise_privacy_number_packages, num, num)); - } - }); - } - - @Override - public boolean isAvailable() { - return true; - } - - @Override - public String getPreferenceKey() { - return KEY_INSTALLED_PACKAGES; - } -} diff --git a/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java index a513f71b0a0..f946780f222 100644 --- a/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java +++ b/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java @@ -88,7 +88,7 @@ public final class ApplicationFeatureProviderImplTest { mPackageManagerService, mDevicePolicyManager); } - private void verifyCalculateNumberOfInstalledApps(boolean async) { + private void verifyCalculateNumberOfPolicyInstalledApps(boolean async) { setUpUsersAndInstalledApps(); when(mPackageManager.getInstallReason(APP_1, new UserHandle(MAIN_USER_ID))) @@ -96,18 +96,8 @@ public final class ApplicationFeatureProviderImplTest { 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, - 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, async, + mProvider.calculateNumberOfPolicyInstalledApps(async, (num) -> mAppCount = num); if (async) { ShadowApplication.runBackgroundTasks(); @@ -117,12 +107,12 @@ public final class ApplicationFeatureProviderImplTest { @Test public void testCalculateNumberOfInstalledAppsSync() { - verifyCalculateNumberOfInstalledApps(false /* async */); + verifyCalculateNumberOfPolicyInstalledApps(false /* async */); } @Test public void testCalculateNumberOfInstalledAppsAsync() { - verifyCalculateNumberOfInstalledApps(true /* async */); + verifyCalculateNumberOfPolicyInstalledApps(true /* async */); } private void verifyCalculateNumberOfAppsWithAdminGrantedPermissions(boolean async) diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java index 8b1c9c9e0ab..1134ec58c23 100644 --- a/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java +++ b/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java @@ -156,7 +156,7 @@ public final class InstalledAppCounterTest { .thenReturn(PackageManager.INSTALL_REASON_UNKNOWN); // Count the number of all apps installed, irrespective of install reason. - count(ApplicationFeatureProvider.IGNORE_INSTALL_REASON, async); + count(InstalledAppCounter.IGNORE_INSTALL_REASON, async); assertThat(mInstalledAppCount).isEqualTo(5); // Verify that installed packages were retrieved for the users returned by diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java index ff884e4474d..4255d963e93 100644 --- a/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java @@ -17,8 +17,6 @@ package com.android.settings.enterprise; import android.content.Context; -import android.content.pm.PackageManager; -import android.content.res.Resources; import android.support.v7.preference.Preference; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; @@ -70,11 +68,10 @@ public final class EnterpriseInstalledPackagesPreferenceControllerTest { doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { ((ApplicationFeatureProvider.NumberOfAppsCallback) - invocation.getArguments()[2]).onNumberOfAppsResult(number); + invocation.getArguments()[1]).onNumberOfAppsResult(number); return null; }}).when(mFeatureFactory.applicationFeatureProvider) - .calculateNumberOfInstalledApps(eq(PackageManager.INSTALL_REASON_POLICY), - eq(async), anyObject()); + .calculateNumberOfPolicyInstalledApps(eq(async), anyObject()); } @Test diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java index 8a117794d34..22256877168 100644 --- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java +++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java @@ -117,31 +117,34 @@ public final class EnterprisePrivacySettingsTest { private void verifyPreferenceControllers(List controllers) { assertThat(controllers).isNotNull(); - assertThat(controllers.size()).isEqualTo(16); - assertThat(controllers.get(0)).isInstanceOf(InstalledPackagesPreferenceController.class); - assertThat(controllers.get(1)).isInstanceOf(NetworkLogsPreferenceController.class); - assertThat(controllers.get(2)).isInstanceOf(BugReportsPreferenceController.class); - assertThat(controllers.get(3)).isInstanceOf(SecurityLogsPreferenceController.class); - assertThat(controllers.get(4)).isInstanceOf( + assertThat(controllers.size()).isEqualTo(15); + int position = 0; + assertThat(controllers.get(position++)).isInstanceOf(NetworkLogsPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf(BugReportsPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + SecurityLogsPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( EnterpriseInstalledPackagesPreferenceController.class); - assertThat(controllers.get(5)).isInstanceOf( + assertThat(controllers.get(position++)).isInstanceOf( AdminGrantedLocationPermissionsPreferenceController.class); - assertThat(controllers.get(6)).isInstanceOf( + assertThat(controllers.get(position++)).isInstanceOf( AdminGrantedMicrophonePermissionPreferenceController.class); - assertThat(controllers.get(7)).isInstanceOf( + assertThat(controllers.get(position++)).isInstanceOf( AdminGrantedCameraPermissionPreferenceController.class); - assertThat(controllers.get(8)).isInstanceOf( + assertThat(controllers.get(position++)).isInstanceOf( EnterpriseSetDefaultAppsPreferenceController.class); - assertThat(controllers.get(9)).isInstanceOf( + assertThat(controllers.get(position++)).isInstanceOf( AlwaysOnVpnPrimaryUserPreferenceController.class); - assertThat(controllers.get(10)).isInstanceOf( + assertThat(controllers.get(position++)).isInstanceOf( AlwaysOnVpnManagedProfilePreferenceController.class); - assertThat(controllers.get(11)).isInstanceOf(GlobalHttpProxyPreferenceController.class); - assertThat(controllers.get(12)).isInstanceOf(CaCertsPreferenceController.class); - assertThat(controllers.get(13)).isInstanceOf( + assertThat(controllers.get(position++)).isInstanceOf( + GlobalHttpProxyPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( + CaCertsPreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf( FailedPasswordWipePrimaryUserPreferenceController.class); - assertThat(controllers.get(14)).isInstanceOf( + assertThat(controllers.get(position++)).isInstanceOf( FailedPasswordWipeManagedProfilePreferenceController.class); - assertThat(controllers.get(15)).isInstanceOf(ImePreferenceController.class); + assertThat(controllers.get(position++)).isInstanceOf(ImePreferenceController.class); } } diff --git a/tests/robotests/src/com/android/settings/enterprise/InstalledPackagesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/InstalledPackagesPreferenceControllerTest.java deleted file mode 100644 index 4a5a183d4a5..00000000000 --- a/tests/robotests/src/com/android/settings/enterprise/InstalledPackagesPreferenceControllerTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.enterprise; - -import android.content.Context; -import android.content.res.Resources; -import android.support.v7.preference.Preference; - -import com.android.internal.logging.nano.MetricsProto.MetricsEvent; -import com.android.settings.R; -import com.android.settings.SettingsRobolectricTestRunner; -import com.android.settings.TestConfig; -import com.android.settings.applications.ApplicationFeatureProvider; -import com.android.settings.testutils.FakeFeatureFactory; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Answers; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.robolectric.annotation.Config; - -import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Mockito.anyObject; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.when; - -/** - * Tests for {@link InstalledPackagesPreferenceController}. - */ -@RunWith(SettingsRobolectricTestRunner.class) -@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) -public final class InstalledPackagesPreferenceControllerTest { - - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private Context mContext; - private FakeFeatureFactory mFeatureFactory; - - private InstalledPackagesPreferenceController mController; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - FakeFeatureFactory.setupForTest(mContext); - mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); - mController = new InstalledPackagesPreferenceController(mContext); - } - - private void setNumberOfInstalledPackages(int number) { - doAnswer(new Answer() { - public Object answer(InvocationOnMock invocation) { - ((ApplicationFeatureProvider.NumberOfAppsCallback) - invocation.getArguments()[2]).onNumberOfAppsResult(number); - return null; - }}).when(mFeatureFactory.applicationFeatureProvider).calculateNumberOfInstalledApps( - eq(ApplicationFeatureProvider.IGNORE_INSTALL_REASON), eq(true), anyObject()); - } - - @Test - public void testUpdateState() { - final Preference preference = new Preference(mContext, null, 0, 0); - - setNumberOfInstalledPackages(0); - mController.updateState(preference); - assertThat(preference.getSummary()).isEqualTo(""); - - setNumberOfInstalledPackages(20); - when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_packages, - 20, 20)).thenReturn("20 packages"); - mController.updateState(preference); - assertThat(preference.getSummary()).isEqualTo("20 packages"); - } - - @Test - public void testIsAvailable() { - assertThat(mController.isAvailable()).isTrue(); - } - - @Test - public void testHandlePreferenceTreeClick() { - assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0))) - .isFalse(); - } - - @Test - public void testGetPreferenceKey() { - assertThat(mController.getPreferenceKey()).isEqualTo("installed_packages"); - } -}