Update List of apps on device string,
remove "XX apps" string. Bug: 32692748 Test: m RunSettingsRoboTests Change-Id: I64f833497b5362f95cfc56a1057d97d9539ff029
This commit is contained in:
@@ -8270,7 +8270,7 @@
|
|||||||
<!-- Label explaining that the admin can see apps installed on the device. [CHAR LIMIT=NONE] -->
|
<!-- Label explaining that the admin can see apps installed on the device. [CHAR LIMIT=NONE] -->
|
||||||
<string name="enterprise_privacy_installed_packages">List of apps on your device</string>
|
<string name="enterprise_privacy_installed_packages">List of apps on your device</string>
|
||||||
<!-- Label explaining that the admin can see app usage statistics. [CHAR LIMIT=NONE] -->
|
<!-- Label explaining that the admin can see app usage statistics. [CHAR LIMIT=NONE] -->
|
||||||
<string name="enterprise_privacy_usage_stats">Time and data spent in each app on your device</string>
|
<string name="enterprise_privacy_usage_stats">Amount of time and data spent in each app</string>
|
||||||
<!-- Label explaining that the admin can retrieve network logs on the device. [CHAR LIMIT=NONE] -->
|
<!-- Label explaining that the admin can retrieve network logs on the device. [CHAR LIMIT=NONE] -->
|
||||||
<string name="enterprise_privacy_network_logs">Network traffic logs on your device</string>
|
<string name="enterprise_privacy_network_logs">Network traffic logs on your device</string>
|
||||||
<!-- Label explaining that the admin can request bug reports on the device. [CHAR LIMIT=NONE] -->
|
<!-- Label explaining that the admin can request bug reports on the device. [CHAR LIMIT=NONE] -->
|
||||||
@@ -8281,6 +8281,8 @@
|
|||||||
<string name="enterprise_privacy_none">None</string>
|
<string name="enterprise_privacy_none">None</string>
|
||||||
<!-- Label indicating that the admin installed one or more apps on the device. -->
|
<!-- Label indicating that the admin installed one or more apps on the device. -->
|
||||||
<string name="enterprise_privacy_enterprise_installed_packages">Apps installed</string>
|
<string name="enterprise_privacy_enterprise_installed_packages">Apps installed</string>
|
||||||
|
<!-- Label explaining that the the number of apps is an estimation. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="enterprise_privacy_apps_count_estimation_info">Number of apps is estimated. It may not include apps installed outside of the Play Store.</string>
|
||||||
<!-- Summary indicating the number of apps that a label (e.g. installed apps or apps granted a particular permission) refers to. The number shown is a minimum as there may be additional apps we do not know about. [CHAR LIMIT=NONE] -->
|
<!-- Summary indicating the number of apps that a label (e.g. installed apps or apps granted a particular permission) refers to. The number shown is a minimum as there may be additional apps we do not know about. [CHAR LIMIT=NONE] -->
|
||||||
<plurals name="enterprise_privacy_number_packages_lower_bound">
|
<plurals name="enterprise_privacy_number_packages_lower_bound">
|
||||||
<item quantity="one">Minimum <xliff:g id="count">%d</xliff:g> app</item>
|
<item quantity="one">Minimum <xliff:g id="count">%d</xliff:g> app</item>
|
||||||
|
@@ -32,7 +32,6 @@
|
|||||||
android:title="@string/enterprise_privacy_enterprise_data"
|
android:title="@string/enterprise_privacy_enterprise_data"
|
||||||
settings:multiLine="true"/>
|
settings:multiLine="true"/>
|
||||||
<com.android.settings.DividerPreference
|
<com.android.settings.DividerPreference
|
||||||
android:key="installed_packages"
|
|
||||||
android:title="@string/enterprise_privacy_installed_packages"
|
android:title="@string/enterprise_privacy_installed_packages"
|
||||||
settings:multiLine="true"/>
|
settings:multiLine="true"/>
|
||||||
<com.android.settings.DividerPreference
|
<com.android.settings.DividerPreference
|
||||||
|
@@ -30,22 +30,13 @@ public interface ApplicationFeatureProvider {
|
|||||||
AppHeaderController newAppHeaderController(Fragment fragment, View appHeader);
|
AppHeaderController newAppHeaderController(Fragment fragment, View appHeader);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count all installed packages, irrespective of install reason.
|
* Calculates the total number of apps installed on the device via policy across all users
|
||||||
*/
|
* and managed profiles.
|
||||||
public static final int IGNORE_INSTALL_REASON = -1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the total number of apps installed on the device, across all users and managed
|
|
||||||
* profiles.
|
|
||||||
*
|
*
|
||||||
* @param installReason Only consider apps with this install reason; may be any install reason
|
|
||||||
* defined in {@link android.content.pm.PackageManager} or
|
|
||||||
* {@link #IGNORE_INSTALL_REASON} to count all apps, irrespective of install reason.
|
|
||||||
* @param async Whether to count asynchronously in a background thread
|
* @param async Whether to count asynchronously in a background thread
|
||||||
* @param callback The callback to invoke with the result
|
* @param callback The callback to invoke with the result
|
||||||
*/
|
*/
|
||||||
void calculateNumberOfInstalledApps(int installReason, boolean async,
|
void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback);
|
||||||
NumberOfAppsCallback callback);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously calculates the total number of apps installed on the device, across all users
|
* Asynchronously calculates the total number of apps installed on the device, across all users
|
||||||
|
@@ -20,6 +20,7 @@ import android.app.Fragment;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ComponentInfo;
|
import android.content.pm.ComponentInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
@@ -56,10 +57,9 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculateNumberOfInstalledApps(int installReason, boolean async,
|
public void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback) {
|
||||||
NumberOfAppsCallback callback) {
|
final AllUserPolicyInstalledAppCounter counter =
|
||||||
final AllUserInstalledAppCounter counter = new AllUserInstalledAppCounter(mContext,
|
new AllUserPolicyInstalledAppCounter(mContext, mPm, callback);
|
||||||
installReason, mPm, callback);
|
|
||||||
if (async) {
|
if (async) {
|
||||||
counter.execute();
|
counter.execute();
|
||||||
} else {
|
} else {
|
||||||
@@ -113,12 +113,12 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
|
|||||||
return activities;
|
return activities;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class AllUserInstalledAppCounter extends InstalledAppCounter {
|
private static class AllUserPolicyInstalledAppCounter extends InstalledAppCounter {
|
||||||
private NumberOfAppsCallback mCallback;
|
private NumberOfAppsCallback mCallback;
|
||||||
|
|
||||||
AllUserInstalledAppCounter(Context context, int installReason,
|
AllUserPolicyInstalledAppCounter(Context context, PackageManagerWrapper packageManager,
|
||||||
PackageManagerWrapper packageManager, NumberOfAppsCallback callback) {
|
NumberOfAppsCallback callback) {
|
||||||
super(context, installReason, packageManager);
|
super(context, PackageManager.INSTALL_REASON_POLICY, packageManager);
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,6 +25,11 @@ import java.util.List;
|
|||||||
|
|
||||||
public abstract class InstalledAppCounter extends AppCounter {
|
public abstract class InstalledAppCounter extends AppCounter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count all installed packages, irrespective of install reason.
|
||||||
|
*/
|
||||||
|
public static final int IGNORE_INSTALL_REASON = -1;
|
||||||
|
|
||||||
private final int mInstallReason;
|
private final int mInstallReason;
|
||||||
private final PackageManagerWrapper mPackageManager;
|
private final PackageManagerWrapper mPackageManager;
|
||||||
|
|
||||||
@@ -38,7 +43,7 @@ public abstract class InstalledAppCounter extends AppCounter {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean includeInCount(ApplicationInfo info) {
|
protected boolean includeInCount(ApplicationInfo info) {
|
||||||
final int userId = UserHandle.getUserId(info.uid);
|
final int userId = UserHandle.getUserId(info.uid);
|
||||||
if (mInstallReason != ApplicationFeatureProvider.IGNORE_INSTALL_REASON
|
if (mInstallReason != IGNORE_INSTALL_REASON
|
||||||
&& mPackageManager.getInstallReason(info.packageName,
|
&& mPackageManager.getInstallReason(info.packageName,
|
||||||
new UserHandle(userId)) != mInstallReason) {
|
new UserHandle(userId)) != mInstallReason) {
|
||||||
return false;
|
return false;
|
||||||
|
@@ -69,7 +69,6 @@ import com.android.settings.Settings.WriteSettingsActivity;
|
|||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.applications.AppStateAppOpsBridge.PermissionState;
|
import com.android.settings.applications.AppStateAppOpsBridge.PermissionState;
|
||||||
import com.android.settings.applications.AppStateInstallAppsBridge.InstallAppsState;
|
|
||||||
import com.android.settings.applications.AppStateUsageBridge.UsageState;
|
import com.android.settings.applications.AppStateUsageBridge.UsageState;
|
||||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||||
import com.android.settings.dashboard.SummaryLoader;
|
import com.android.settings.dashboard.SummaryLoader;
|
||||||
@@ -1398,7 +1397,7 @@ public class ManageApplications extends InstrumentedPreferenceFragment
|
|||||||
@Override
|
@Override
|
||||||
public void setListening(boolean listening) {
|
public void setListening(boolean listening) {
|
||||||
if (listening) {
|
if (listening) {
|
||||||
new InstalledAppCounter(mContext, ApplicationFeatureProvider.IGNORE_INSTALL_REASON,
|
new InstalledAppCounter(mContext, InstalledAppCounter.IGNORE_INSTALL_REASON,
|
||||||
new PackageManagerWrapperImpl(mContext.getPackageManager())) {
|
new PackageManagerWrapperImpl(mContext.getPackageManager())) {
|
||||||
@Override
|
@Override
|
||||||
protected void onCountComplete(int num) {
|
protected void onCountComplete(int num) {
|
||||||
|
@@ -14,8 +14,6 @@
|
|||||||
package com.android.settings.enterprise;
|
package com.android.settings.enterprise;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -42,8 +40,7 @@ public class EnterpriseInstalledPackagesPreferenceController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
mFeatureProvider.calculateNumberOfInstalledApps(
|
mFeatureProvider.calculateNumberOfPolicyInstalledApps(true /* async */,
|
||||||
PackageManager.INSTALL_REASON_POLICY, true /* async */,
|
|
||||||
(num) -> {
|
(num) -> {
|
||||||
if (num == 0) {
|
if (num == 0) {
|
||||||
preference.setVisible(false);
|
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.
|
// 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.
|
// We block and return synchronously whether there are enterprise-installed apps or not.
|
||||||
final Boolean[] haveEnterpriseInstalledPackages = { null };
|
final Boolean[] haveEnterpriseInstalledPackages = { null };
|
||||||
mFeatureProvider.calculateNumberOfInstalledApps(PackageManager.INSTALL_REASON_POLICY,
|
mFeatureProvider.calculateNumberOfPolicyInstalledApps(false /* async */,
|
||||||
false /* async */, (num) -> haveEnterpriseInstalledPackages[0] = num > 0);
|
(num) -> haveEnterpriseInstalledPackages[0] = num > 0);
|
||||||
return haveEnterpriseInstalledPackages[0];
|
return haveEnterpriseInstalledPackages[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -58,7 +58,6 @@ public class EnterprisePrivacySettings extends DashboardFragment {
|
|||||||
private static List<PreferenceController> buildPreferenceControllers(Context context,
|
private static List<PreferenceController> buildPreferenceControllers(Context context,
|
||||||
Lifecycle lifecycle, boolean async) {
|
Lifecycle lifecycle, boolean async) {
|
||||||
final List controllers = new ArrayList<PreferenceController>();
|
final List controllers = new ArrayList<PreferenceController>();
|
||||||
controllers.add(new InstalledPackagesPreferenceController(context));
|
|
||||||
controllers.add(new NetworkLogsPreferenceController(context));
|
controllers.add(new NetworkLogsPreferenceController(context));
|
||||||
controllers.add(new BugReportsPreferenceController(context));
|
controllers.add(new BugReportsPreferenceController(context));
|
||||||
controllers.add(new SecurityLogsPreferenceController(context));
|
controllers.add(new SecurityLogsPreferenceController(context));
|
||||||
|
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -88,7 +88,7 @@ public final class ApplicationFeatureProviderImplTest {
|
|||||||
mPackageManagerService, mDevicePolicyManager);
|
mPackageManagerService, mDevicePolicyManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyCalculateNumberOfInstalledApps(boolean async) {
|
private void verifyCalculateNumberOfPolicyInstalledApps(boolean async) {
|
||||||
setUpUsersAndInstalledApps();
|
setUpUsersAndInstalledApps();
|
||||||
|
|
||||||
when(mPackageManager.getInstallReason(APP_1, new UserHandle(MAIN_USER_ID)))
|
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)))
|
when(mPackageManager.getInstallReason(APP_2, new UserHandle(MANAGED_PROFILE_ID)))
|
||||||
.thenReturn(PackageManager.INSTALL_REASON_POLICY);
|
.thenReturn(PackageManager.INSTALL_REASON_POLICY);
|
||||||
|
|
||||||
// Count all installed apps.
|
|
||||||
mAppCount = -1;
|
mAppCount = -1;
|
||||||
mProvider.calculateNumberOfInstalledApps(ApplicationFeatureProvider.IGNORE_INSTALL_REASON,
|
mProvider.calculateNumberOfPolicyInstalledApps(async,
|
||||||
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,
|
|
||||||
(num) -> mAppCount = num);
|
(num) -> mAppCount = num);
|
||||||
if (async) {
|
if (async) {
|
||||||
ShadowApplication.runBackgroundTasks();
|
ShadowApplication.runBackgroundTasks();
|
||||||
@@ -117,12 +107,12 @@ public final class ApplicationFeatureProviderImplTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCalculateNumberOfInstalledAppsSync() {
|
public void testCalculateNumberOfInstalledAppsSync() {
|
||||||
verifyCalculateNumberOfInstalledApps(false /* async */);
|
verifyCalculateNumberOfPolicyInstalledApps(false /* async */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCalculateNumberOfInstalledAppsAsync() {
|
public void testCalculateNumberOfInstalledAppsAsync() {
|
||||||
verifyCalculateNumberOfInstalledApps(true /* async */);
|
verifyCalculateNumberOfPolicyInstalledApps(true /* async */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyCalculateNumberOfAppsWithAdminGrantedPermissions(boolean async)
|
private void verifyCalculateNumberOfAppsWithAdminGrantedPermissions(boolean async)
|
||||||
|
@@ -156,7 +156,7 @@ public final class InstalledAppCounterTest {
|
|||||||
.thenReturn(PackageManager.INSTALL_REASON_UNKNOWN);
|
.thenReturn(PackageManager.INSTALL_REASON_UNKNOWN);
|
||||||
|
|
||||||
// Count the number of all apps installed, irrespective of install reason.
|
// 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);
|
assertThat(mInstalledAppCount).isEqualTo(5);
|
||||||
|
|
||||||
// Verify that installed packages were retrieved for the users returned by
|
// Verify that installed packages were retrieved for the users returned by
|
||||||
|
@@ -17,8 +17,6 @@
|
|||||||
package com.android.settings.enterprise;
|
package com.android.settings.enterprise;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
@@ -70,11 +68,10 @@ public final class EnterpriseInstalledPackagesPreferenceControllerTest {
|
|||||||
doAnswer(new Answer() {
|
doAnswer(new Answer() {
|
||||||
public Object answer(InvocationOnMock invocation) {
|
public Object answer(InvocationOnMock invocation) {
|
||||||
((ApplicationFeatureProvider.NumberOfAppsCallback)
|
((ApplicationFeatureProvider.NumberOfAppsCallback)
|
||||||
invocation.getArguments()[2]).onNumberOfAppsResult(number);
|
invocation.getArguments()[1]).onNumberOfAppsResult(number);
|
||||||
return null;
|
return null;
|
||||||
}}).when(mFeatureFactory.applicationFeatureProvider)
|
}}).when(mFeatureFactory.applicationFeatureProvider)
|
||||||
.calculateNumberOfInstalledApps(eq(PackageManager.INSTALL_REASON_POLICY),
|
.calculateNumberOfPolicyInstalledApps(eq(async), anyObject());
|
||||||
eq(async), anyObject());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -117,31 +117,34 @@ public final class EnterprisePrivacySettingsTest {
|
|||||||
|
|
||||||
private void verifyPreferenceControllers(List<PreferenceController> controllers) {
|
private void verifyPreferenceControllers(List<PreferenceController> controllers) {
|
||||||
assertThat(controllers).isNotNull();
|
assertThat(controllers).isNotNull();
|
||||||
assertThat(controllers.size()).isEqualTo(16);
|
assertThat(controllers.size()).isEqualTo(15);
|
||||||
assertThat(controllers.get(0)).isInstanceOf(InstalledPackagesPreferenceController.class);
|
int position = 0;
|
||||||
assertThat(controllers.get(1)).isInstanceOf(NetworkLogsPreferenceController.class);
|
assertThat(controllers.get(position++)).isInstanceOf(NetworkLogsPreferenceController.class);
|
||||||
assertThat(controllers.get(2)).isInstanceOf(BugReportsPreferenceController.class);
|
assertThat(controllers.get(position++)).isInstanceOf(BugReportsPreferenceController.class);
|
||||||
assertThat(controllers.get(3)).isInstanceOf(SecurityLogsPreferenceController.class);
|
assertThat(controllers.get(position++)).isInstanceOf(
|
||||||
assertThat(controllers.get(4)).isInstanceOf(
|
SecurityLogsPreferenceController.class);
|
||||||
|
assertThat(controllers.get(position++)).isInstanceOf(
|
||||||
EnterpriseInstalledPackagesPreferenceController.class);
|
EnterpriseInstalledPackagesPreferenceController.class);
|
||||||
assertThat(controllers.get(5)).isInstanceOf(
|
assertThat(controllers.get(position++)).isInstanceOf(
|
||||||
AdminGrantedLocationPermissionsPreferenceController.class);
|
AdminGrantedLocationPermissionsPreferenceController.class);
|
||||||
assertThat(controllers.get(6)).isInstanceOf(
|
assertThat(controllers.get(position++)).isInstanceOf(
|
||||||
AdminGrantedMicrophonePermissionPreferenceController.class);
|
AdminGrantedMicrophonePermissionPreferenceController.class);
|
||||||
assertThat(controllers.get(7)).isInstanceOf(
|
assertThat(controllers.get(position++)).isInstanceOf(
|
||||||
AdminGrantedCameraPermissionPreferenceController.class);
|
AdminGrantedCameraPermissionPreferenceController.class);
|
||||||
assertThat(controllers.get(8)).isInstanceOf(
|
assertThat(controllers.get(position++)).isInstanceOf(
|
||||||
EnterpriseSetDefaultAppsPreferenceController.class);
|
EnterpriseSetDefaultAppsPreferenceController.class);
|
||||||
assertThat(controllers.get(9)).isInstanceOf(
|
assertThat(controllers.get(position++)).isInstanceOf(
|
||||||
AlwaysOnVpnPrimaryUserPreferenceController.class);
|
AlwaysOnVpnPrimaryUserPreferenceController.class);
|
||||||
assertThat(controllers.get(10)).isInstanceOf(
|
assertThat(controllers.get(position++)).isInstanceOf(
|
||||||
AlwaysOnVpnManagedProfilePreferenceController.class);
|
AlwaysOnVpnManagedProfilePreferenceController.class);
|
||||||
assertThat(controllers.get(11)).isInstanceOf(GlobalHttpProxyPreferenceController.class);
|
assertThat(controllers.get(position++)).isInstanceOf(
|
||||||
assertThat(controllers.get(12)).isInstanceOf(CaCertsPreferenceController.class);
|
GlobalHttpProxyPreferenceController.class);
|
||||||
assertThat(controllers.get(13)).isInstanceOf(
|
assertThat(controllers.get(position++)).isInstanceOf(
|
||||||
|
CaCertsPreferenceController.class);
|
||||||
|
assertThat(controllers.get(position++)).isInstanceOf(
|
||||||
FailedPasswordWipePrimaryUserPreferenceController.class);
|
FailedPasswordWipePrimaryUserPreferenceController.class);
|
||||||
assertThat(controllers.get(14)).isInstanceOf(
|
assertThat(controllers.get(position++)).isInstanceOf(
|
||||||
FailedPasswordWipeManagedProfilePreferenceController.class);
|
FailedPasswordWipeManagedProfilePreferenceController.class);
|
||||||
assertThat(controllers.get(15)).isInstanceOf(ImePreferenceController.class);
|
assertThat(controllers.get(position++)).isInstanceOf(ImePreferenceController.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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");
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user