Merge "Start removing N/A DO disclosures from search index"
This commit is contained in:
committed by
Android (Google) Code Review
commit
9812557561
@@ -57,6 +57,10 @@ public abstract class AppCounter extends AsyncTask<Void, Void, Integer> {
|
|||||||
onCountComplete(count);
|
onCountComplete(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void executeInForeground() {
|
||||||
|
onPostExecute(doInBackground());
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract void onCountComplete(int num);
|
protected abstract void onCountComplete(int num);
|
||||||
protected abstract List<UserInfo> getUsersToCount();
|
protected abstract List<UserInfo> getUsersToCount();
|
||||||
protected abstract boolean includeInCount(ApplicationInfo info);
|
protected abstract boolean includeInCount(ApplicationInfo info);
|
||||||
|
@@ -35,15 +35,17 @@ public interface ApplicationFeatureProvider {
|
|||||||
public static final int IGNORE_INSTALL_REASON = -1;
|
public static final int IGNORE_INSTALL_REASON = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously calculates the total number of apps installed on the device, across all users
|
* Calculates the total number of apps installed on the device, across all users and managed
|
||||||
* and managed profiles.
|
* profiles.
|
||||||
*
|
*
|
||||||
* @param installReason Only consider apps with this install reason; may be any install reason
|
* @param installReason Only consider apps with this install reason; may be any install reason
|
||||||
* defined in {@link android.content.pm.PackageManager} or
|
* defined in {@link android.content.pm.PackageManager} or
|
||||||
* {@link #IGNORE_INSTALL_REASON} to count all apps, irrespective of install reason.
|
* {@link #IGNORE_INSTALL_REASON} to count all apps, irrespective of install reason.
|
||||||
|
* @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, NumberOfAppsCallback callback);
|
void calculateNumberOfInstalledApps(int installReason, boolean async,
|
||||||
|
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
|
||||||
|
@@ -56,8 +56,15 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculateNumberOfInstalledApps(int installReason, NumberOfAppsCallback callback) {
|
public void calculateNumberOfInstalledApps(int installReason, boolean async,
|
||||||
new AllUserInstalledAppCounter(mContext, installReason, mPm, callback).execute();
|
NumberOfAppsCallback callback) {
|
||||||
|
final AllUserInstalledAppCounter counter = new AllUserInstalledAppCounter(mContext,
|
||||||
|
installReason, mPm, callback);
|
||||||
|
if (async) {
|
||||||
|
counter.execute();
|
||||||
|
} else {
|
||||||
|
counter.executeInForeground();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -20,25 +20,30 @@ import android.support.v7.preference.Preference;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||||
import com.android.settings.core.PreferenceController;
|
import com.android.settings.core.DynamicAvailabilityPreferenceController;
|
||||||
|
import com.android.settings.core.lifecycle.Lifecycle;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
public class EnterpriseInstalledPackagesPreferenceController extends PreferenceController {
|
public class EnterpriseInstalledPackagesPreferenceController
|
||||||
|
extends DynamicAvailabilityPreferenceController {
|
||||||
|
|
||||||
private static final String KEY_NUMBER_ENTERPRISE_INSTALLED_PACKAGES
|
private static final String KEY_NUMBER_ENTERPRISE_INSTALLED_PACKAGES
|
||||||
= "number_enterprise_installed_packages";
|
= "number_enterprise_installed_packages";
|
||||||
private final ApplicationFeatureProvider mFeatureProvider;
|
private final ApplicationFeatureProvider mFeatureProvider;
|
||||||
|
private final boolean mAsync;
|
||||||
|
|
||||||
public EnterpriseInstalledPackagesPreferenceController(Context context) {
|
public EnterpriseInstalledPackagesPreferenceController(Context context, Lifecycle lifecycle,
|
||||||
super(context);
|
boolean async) {
|
||||||
|
super(context, lifecycle);
|
||||||
mFeatureProvider = FeatureFactory.getFactory(context)
|
mFeatureProvider = FeatureFactory.getFactory(context)
|
||||||
.getApplicationFeatureProvider(context);
|
.getApplicationFeatureProvider(context);
|
||||||
|
mAsync = async;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
mFeatureProvider.calculateNumberOfInstalledApps(
|
mFeatureProvider.calculateNumberOfInstalledApps(
|
||||||
PackageManager.INSTALL_REASON_POLICY,
|
PackageManager.INSTALL_REASON_POLICY, true /* async */,
|
||||||
(num) -> {
|
(num) -> {
|
||||||
if (num == 0) {
|
if (num == 0) {
|
||||||
preference.setVisible(false);
|
preference.setVisible(false);
|
||||||
@@ -52,9 +57,22 @@ public class EnterpriseInstalledPackagesPreferenceController extends PreferenceC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
|
if (mAsync) {
|
||||||
|
// When called on the main UI thread, we must not block. Since calculating the number of
|
||||||
|
// enterprise-installed apps takes a bit of time, we always return true here and
|
||||||
|
// determine the pref's actual visibility asynchronously in updateState().
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When called by the search indexer, we are on a background thread that we can block. Also,
|
||||||
|
// 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);
|
||||||
|
return haveEnterpriseInstalledPackages[0];
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return KEY_NUMBER_ENTERPRISE_INSTALLED_PACKAGES;
|
return KEY_NUMBER_ENTERPRISE_INSTALLED_PACKAGES;
|
||||||
|
@@ -22,6 +22,7 @@ import android.provider.SearchIndexableResource;
|
|||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.PreferenceController;
|
import com.android.settings.core.PreferenceController;
|
||||||
|
import com.android.settings.core.lifecycle.Lifecycle;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
@@ -51,16 +52,22 @@ public class EnterprisePrivacySettings extends DashboardFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||||
|
return buildPreferenceControllers(context, getLifecycle(), true /* async */);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<PreferenceController> buildPreferenceControllers(Context context,
|
||||||
|
Lifecycle lifecycle, boolean async) {
|
||||||
final List controllers = new ArrayList<PreferenceController>();
|
final List controllers = new ArrayList<PreferenceController>();
|
||||||
controllers.add(new InstalledPackagesPreferenceController(context));
|
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));
|
||||||
controllers.add(new EnterpriseInstalledPackagesPreferenceController(context));
|
controllers.add(new EnterpriseInstalledPackagesPreferenceController(context, lifecycle,
|
||||||
|
async));
|
||||||
controllers.add(new AdminGrantedLocationPermissionsPreferenceController(context));
|
controllers.add(new AdminGrantedLocationPermissionsPreferenceController(context));
|
||||||
controllers.add(new AdminGrantedMicrophonePermissionPreferenceController(context));
|
controllers.add(new AdminGrantedMicrophonePermissionPreferenceController(context));
|
||||||
controllers.add(new AdminGrantedCameraPermissionPreferenceController(context));
|
controllers.add(new AdminGrantedCameraPermissionPreferenceController(context));
|
||||||
controllers.add(new EnterpriseSetDefaultAppsPreferenceController(context));
|
controllers.add(new EnterpriseSetDefaultAppsPreferenceController(context, lifecycle));
|
||||||
controllers.add(new AlwaysOnVpnPrimaryUserPreferenceController(context));
|
controllers.add(new AlwaysOnVpnPrimaryUserPreferenceController(context));
|
||||||
controllers.add(new AlwaysOnVpnManagedProfilePreferenceController(context));
|
controllers.add(new AlwaysOnVpnManagedProfilePreferenceController(context));
|
||||||
controllers.add(new GlobalHttpProxyPreferenceController(context));
|
controllers.add(new GlobalHttpProxyPreferenceController(context));
|
||||||
@@ -92,5 +99,10 @@ public class EnterprisePrivacySettings extends DashboardFragment {
|
|||||||
sir.xmlResId = R.xml.enterprise_privacy_settings;
|
sir.xmlResId = R.xml.enterprise_privacy_settings;
|
||||||
return Arrays.asList(sir);
|
return Arrays.asList(sir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PreferenceController> getPreferenceControllers(Context context) {
|
||||||
|
return buildPreferenceControllers(context, null /* lifecycle */, false /* async */);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -22,22 +22,40 @@ import android.support.v7.preference.Preference;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||||
import com.android.settings.core.PreferenceController;
|
import com.android.settings.core.DynamicAvailabilityPreferenceController;
|
||||||
|
import com.android.settings.core.lifecycle.Lifecycle;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
public class EnterpriseSetDefaultAppsPreferenceController extends PreferenceController {
|
public class EnterpriseSetDefaultAppsPreferenceController
|
||||||
|
extends DynamicAvailabilityPreferenceController {
|
||||||
|
|
||||||
private static final String KEY_DEFAULT_APPS = "number_enterprise_set_default_apps";
|
private static final String KEY_DEFAULT_APPS = "number_enterprise_set_default_apps";
|
||||||
private final ApplicationFeatureProvider mFeatureProvider;
|
private final ApplicationFeatureProvider mFeatureProvider;
|
||||||
|
|
||||||
public EnterpriseSetDefaultAppsPreferenceController(Context context) {
|
public EnterpriseSetDefaultAppsPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
super(context);
|
super(context, lifecycle);
|
||||||
mFeatureProvider = FeatureFactory.getFactory(context)
|
mFeatureProvider = FeatureFactory.getFactory(context)
|
||||||
.getApplicationFeatureProvider(context);
|
.getApplicationFeatureProvider(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
|
final int num = getNumberOfEnterpriseSetDefaultApps();
|
||||||
|
preference.setSummary(mContext.getResources().getQuantityString(
|
||||||
|
R.plurals.enterprise_privacy_number_packages, num, num));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return getNumberOfEnterpriseSetDefaultApps() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_DEFAULT_APPS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getNumberOfEnterpriseSetDefaultApps() {
|
||||||
// Browser
|
// Browser
|
||||||
int num = mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
|
int num = mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
|
||||||
buildIntent(Intent.ACTION_VIEW, Intent.CATEGORY_BROWSABLE, "http:", null)}).size();
|
buildIntent(Intent.ACTION_VIEW, Intent.CATEGORY_BROWSABLE, "http:", null)}).size();
|
||||||
@@ -64,23 +82,7 @@ public class EnterpriseSetDefaultAppsPreferenceController extends PreferenceCont
|
|||||||
num += mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
|
num += mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
|
||||||
new Intent(Intent.ACTION_DIAL), new Intent(Intent.ACTION_CALL)}).size();
|
new Intent(Intent.ACTION_DIAL), new Intent(Intent.ACTION_CALL)}).size();
|
||||||
|
|
||||||
if (num == 0) {
|
return num;
|
||||||
preference.setVisible(false);
|
|
||||||
} else {
|
|
||||||
preference.setVisible(true);
|
|
||||||
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_DEFAULT_APPS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Intent buildIntent(String action, String category, String protocol,
|
private static Intent buildIntent(String action, String category, String protocol,
|
||||||
|
@@ -36,7 +36,7 @@ public class InstalledPackagesPreferenceController extends PreferenceController
|
|||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
mFeatureProvider.calculateNumberOfInstalledApps(
|
mFeatureProvider.calculateNumberOfInstalledApps(
|
||||||
ApplicationFeatureProvider.IGNORE_INSTALL_REASON,
|
ApplicationFeatureProvider.IGNORE_INSTALL_REASON, true /* async */,
|
||||||
(num) -> {
|
(num) -> {
|
||||||
if (num == 0) {
|
if (num == 0) {
|
||||||
preference.setSummary("");
|
preference.setSummary("");
|
||||||
|
@@ -88,8 +88,7 @@ public final class ApplicationFeatureProviderImplTest {
|
|||||||
mPackageManagerService, mDevicePolicyManager);
|
mPackageManagerService, mDevicePolicyManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private void testCalculateNumberOfInstalledApps(boolean async) {
|
||||||
public void testCalculateNumberOfInstalledApps() {
|
|
||||||
setUpUsersAndInstalledApps();
|
setUpUsersAndInstalledApps();
|
||||||
|
|
||||||
when(mPackageManager.getInstallReason(APP_1, new UserHandle(MAIN_USER_ID)))
|
when(mPackageManager.getInstallReason(APP_1, new UserHandle(MAIN_USER_ID)))
|
||||||
@@ -100,22 +99,32 @@ public final class ApplicationFeatureProviderImplTest {
|
|||||||
// Count all installed apps.
|
// Count all installed apps.
|
||||||
mAppCount = -1;
|
mAppCount = -1;
|
||||||
mProvider.calculateNumberOfInstalledApps(ApplicationFeatureProvider.IGNORE_INSTALL_REASON,
|
mProvider.calculateNumberOfInstalledApps(ApplicationFeatureProvider.IGNORE_INSTALL_REASON,
|
||||||
(num) -> {
|
async, (num) -> mAppCount = num);
|
||||||
mAppCount = num;
|
if (async) {
|
||||||
});
|
|
||||||
ShadowApplication.runBackgroundTasks();
|
ShadowApplication.runBackgroundTasks();
|
||||||
|
}
|
||||||
assertThat(mAppCount).isEqualTo(2);
|
assertThat(mAppCount).isEqualTo(2);
|
||||||
|
|
||||||
// Count apps with specific install reason only.
|
// Count apps with specific install reason only.
|
||||||
mAppCount = -1;
|
mAppCount = -1;
|
||||||
mProvider.calculateNumberOfInstalledApps(PackageManager.INSTALL_REASON_POLICY,
|
mProvider.calculateNumberOfInstalledApps(PackageManager.INSTALL_REASON_POLICY, async,
|
||||||
(num) -> {
|
(num) -> mAppCount = num);
|
||||||
mAppCount = num;
|
if (async) {
|
||||||
});
|
|
||||||
ShadowApplication.runBackgroundTasks();
|
ShadowApplication.runBackgroundTasks();
|
||||||
|
}
|
||||||
assertThat(mAppCount).isEqualTo(1);
|
assertThat(mAppCount).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCalculateNumberOfInstalledAppsSync() {
|
||||||
|
testCalculateNumberOfInstalledApps(false /* async */);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCalculateNumberOfInstalledAppsAsync() {
|
||||||
|
testCalculateNumberOfInstalledApps(true /* async */);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCalculateNumberOfAppsWithAdminGrantedPermissions() throws Exception {
|
public void testCalculateNumberOfAppsWithAdminGrantedPermissions() throws Exception {
|
||||||
setUpUsersAndInstalledApps();
|
setUpUsersAndInstalledApps();
|
||||||
|
@@ -97,8 +97,7 @@ public final class InstalledAppCounterTest {
|
|||||||
: new ArrayList<ResolveInfo>());
|
: new ArrayList<ResolveInfo>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private void testCountInstalledAppsAcrossAllUsers(boolean async) {
|
||||||
public void testCountInstalledAppsAcrossAllUsers() {
|
|
||||||
// There are two users.
|
// There are two users.
|
||||||
mUsersToCount = Arrays.asList(
|
mUsersToCount = Arrays.asList(
|
||||||
new UserInfo(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN),
|
new UserInfo(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN),
|
||||||
@@ -156,12 +155,8 @@ public final class InstalledAppCounterTest {
|
|||||||
when(mPackageManager.getInstallReason(APP_6, managedProfileUser))
|
when(mPackageManager.getInstallReason(APP_6, managedProfileUser))
|
||||||
.thenReturn(PackageManager.INSTALL_REASON_UNKNOWN);
|
.thenReturn(PackageManager.INSTALL_REASON_UNKNOWN);
|
||||||
|
|
||||||
// Count the number of all apps installed, irrespective of install reason. Wait for the
|
// Count the number of all apps installed, irrespective of install reason.
|
||||||
// background task to finish.
|
count(ApplicationFeatureProvider.IGNORE_INSTALL_REASON, async);
|
||||||
(new InstalledAppCounterTestable(ApplicationFeatureProvider.IGNORE_INSTALL_REASON))
|
|
||||||
.execute();
|
|
||||||
ShadowApplication.runBackgroundTasks();
|
|
||||||
|
|
||||||
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
|
||||||
@@ -173,15 +168,34 @@ public final class InstalledAppCounterTest {
|
|||||||
anyInt());
|
anyInt());
|
||||||
verifyNoMoreInteractions(mPackageManager);
|
verifyNoMoreInteractions(mPackageManager);
|
||||||
|
|
||||||
// Count once more, considering apps installed by enterprise policy only. Wait for the
|
// Count once more, considering apps installed by enterprise policy only.
|
||||||
// background task to finish.
|
count(PackageManager.INSTALL_REASON_POLICY, async);
|
||||||
mInstalledAppCount = -1;
|
|
||||||
(new InstalledAppCounterTestable(PackageManager.INSTALL_REASON_POLICY)).execute();
|
|
||||||
ShadowApplication.runBackgroundTasks();
|
|
||||||
|
|
||||||
assertThat(mInstalledAppCount).isEqualTo(3);
|
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 {
|
private class InstalledAppCounterTestable extends InstalledAppCounter {
|
||||||
public InstalledAppCounterTestable(int installReason) {
|
public InstalledAppCounterTestable(int installReason) {
|
||||||
super(mContext, installReason, mPackageManager);
|
super(mContext, installReason, mPackageManager);
|
||||||
|
@@ -62,18 +62,19 @@ public final class EnterpriseInstalledPackagesPreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
FakeFeatureFactory.setupForTest(mContext);
|
FakeFeatureFactory.setupForTest(mContext);
|
||||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(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() {
|
doAnswer(new Answer() {
|
||||||
public Object answer(InvocationOnMock invocation) {
|
public Object answer(InvocationOnMock invocation) {
|
||||||
((ApplicationFeatureProvider.NumberOfAppsCallback)
|
((ApplicationFeatureProvider.NumberOfAppsCallback)
|
||||||
invocation.getArguments()[1]).onNumberOfAppsResult(number);
|
invocation.getArguments()[2]).onNumberOfAppsResult(number);
|
||||||
return null;
|
return null;
|
||||||
}}).when(mFeatureFactory.applicationFeatureProvider)
|
}}).when(mFeatureFactory.applicationFeatureProvider)
|
||||||
.calculateNumberOfInstalledApps(eq(PackageManager.INSTALL_REASON_POLICY),
|
.calculateNumberOfInstalledApps(eq(PackageManager.INSTALL_REASON_POLICY),
|
||||||
anyObject());
|
eq(async), anyObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -81,11 +82,11 @@ public final class EnterpriseInstalledPackagesPreferenceControllerTest {
|
|||||||
final Preference preference = new Preference(mContext, null, 0, 0);
|
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||||
preference.setVisible(true);
|
preference.setVisible(true);
|
||||||
|
|
||||||
setNumberOfEnterpriseInstalledPackages(0);
|
setNumberOfEnterpriseInstalledPackages(0, true /* async */);
|
||||||
mController.updateState(preference);
|
mController.updateState(preference);
|
||||||
assertThat(preference.isVisible()).isFalse();
|
assertThat(preference.isVisible()).isFalse();
|
||||||
|
|
||||||
setNumberOfEnterpriseInstalledPackages(20);
|
setNumberOfEnterpriseInstalledPackages(20, true /* async */);
|
||||||
when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_packages,
|
when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_packages,
|
||||||
20, 20)).thenReturn("20 packages");
|
20, 20)).thenReturn("20 packages");
|
||||||
mController.updateState(preference);
|
mController.updateState(preference);
|
||||||
@@ -94,7 +95,24 @@ public final class EnterpriseInstalledPackagesPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -104,6 +104,18 @@ public final class EnterprisePrivacySettingsTest {
|
|||||||
public void getPreferenceControllers() {
|
public void getPreferenceControllers() {
|
||||||
final List<PreferenceController> controllers = mSettings.getPreferenceControllers(
|
final List<PreferenceController> controllers = mSettings.getPreferenceControllers(
|
||||||
ShadowApplication.getInstance().getApplicationContext());
|
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).isNotNull();
|
||||||
assertThat(controllers.size()).isEqualTo(17);
|
assertThat(controllers.size()).isEqualTo(17);
|
||||||
assertThat(controllers.get(0)).isInstanceOf(InstalledPackagesPreferenceController.class);
|
assertThat(controllers.get(0)).isInstanceOf(InstalledPackagesPreferenceController.class);
|
||||||
|
@@ -65,7 +65,8 @@ public final class EnterpriseSetDefaultAppsPreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
FakeFeatureFactory.setupForTest(mContext);
|
FakeFeatureFactory.setupForTest(mContext);
|
||||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(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,
|
private static Intent buildIntent(String action, String category, String protocol,
|
||||||
@@ -95,15 +96,6 @@ public final class EnterpriseSetDefaultAppsPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState() {
|
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,
|
setEnterpriseSetDefaultApps(new Intent[] {buildIntent(Intent.ACTION_VIEW,
|
||||||
Intent.CATEGORY_BROWSABLE, "http:", null)}, 1);
|
Intent.CATEGORY_BROWSABLE, "http:", null)}, 1);
|
||||||
setEnterpriseSetDefaultApps(new Intent[] {new Intent(MediaStore.ACTION_IMAGE_CAPTURE),
|
setEnterpriseSetDefaultApps(new Intent[] {new Intent(MediaStore.ACTION_IMAGE_CAPTURE),
|
||||||
@@ -120,13 +112,21 @@ public final class EnterpriseSetDefaultAppsPreferenceControllerTest {
|
|||||||
new Intent(Intent.ACTION_CALL)}, 64);
|
new Intent(Intent.ACTION_CALL)}, 64);
|
||||||
when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_packages,
|
when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_packages,
|
||||||
127, 127)).thenReturn("127 apps");
|
127, 127)).thenReturn("127 apps");
|
||||||
|
|
||||||
|
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||||
mController.updateState(preference);
|
mController.updateState(preference);
|
||||||
assertThat(preference.getSummary()).isEqualTo("127 apps");
|
assertThat(preference.getSummary()).isEqualTo("127 apps");
|
||||||
assertThat(preference.isVisible()).isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable() {
|
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();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -68,11 +68,10 @@ public final class InstalledPackagesPreferenceControllerTest {
|
|||||||
doAnswer(new Answer() {
|
doAnswer(new Answer() {
|
||||||
public Object answer(InvocationOnMock invocation) {
|
public Object answer(InvocationOnMock invocation) {
|
||||||
((ApplicationFeatureProvider.NumberOfAppsCallback)
|
((ApplicationFeatureProvider.NumberOfAppsCallback)
|
||||||
invocation.getArguments()[1]).onNumberOfAppsResult(number);
|
invocation.getArguments()[2]).onNumberOfAppsResult(number);
|
||||||
return null;
|
return null;
|
||||||
}}).when(mFeatureFactory.applicationFeatureProvider)
|
}}).when(mFeatureFactory.applicationFeatureProvider).calculateNumberOfInstalledApps(
|
||||||
.calculateNumberOfInstalledApps(
|
eq(ApplicationFeatureProvider.IGNORE_INSTALL_REASON), eq(true), anyObject());
|
||||||
eq(ApplicationFeatureProvider.IGNORE_INSTALL_REASON), anyObject());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user