Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 98125575 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Start removing N/A DO disclosures from search index"

parents b8710450 5dc168af
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -57,6 +57,10 @@ public abstract class AppCounter extends AsyncTask<Void, Void, Integer> {
        onCountComplete(count);
    }

    void executeInForeground() {
        onPostExecute(doInBackground());
    }

    protected abstract void onCountComplete(int num);
    protected abstract List<UserInfo> getUsersToCount();
    protected abstract boolean includeInCount(ApplicationInfo info);
+5 −3
Original line number Diff line number Diff line
@@ -35,15 +35,17 @@ public interface ApplicationFeatureProvider {
    public static final int IGNORE_INSTALL_REASON = -1;

    /**
     * Asynchronously calculates the total number of apps installed on the device, across all users
     * and managed profiles.
     * 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 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
+9 −2
Original line number Diff line number Diff line
@@ -56,8 +56,15 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
    }

    @Override
    public void calculateNumberOfInstalledApps(int installReason, NumberOfAppsCallback callback) {
        new AllUserInstalledAppCounter(mContext, installReason, mPm, callback).execute();
    public void calculateNumberOfInstalledApps(int installReason, boolean async,
            NumberOfAppsCallback callback) {
        final AllUserInstalledAppCounter counter = new AllUserInstalledAppCounter(mContext,
                installReason, mPm, callback);
        if (async) {
            counter.execute();
        } else {
            counter.executeInForeground();
        }
    }

    @Override
+24 −6
Original line number Diff line number Diff line
@@ -20,25 +20,30 @@ 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.core.DynamicAvailabilityPreferenceController;
import com.android.settings.core.lifecycle.Lifecycle;
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
            = "number_enterprise_installed_packages";
    private final ApplicationFeatureProvider mFeatureProvider;
    private final boolean mAsync;

    public EnterpriseInstalledPackagesPreferenceController(Context context) {
        super(context);
    public EnterpriseInstalledPackagesPreferenceController(Context context, Lifecycle lifecycle,
            boolean async) {
        super(context, lifecycle);
        mFeatureProvider = FeatureFactory.getFactory(context)
                .getApplicationFeatureProvider(context);
        mAsync = async;
    }

    @Override
    public void updateState(Preference preference) {
        mFeatureProvider.calculateNumberOfInstalledApps(
                PackageManager.INSTALL_REASON_POLICY,
                PackageManager.INSTALL_REASON_POLICY, true /* async */,
                (num) -> {
                    if (num == 0) {
                        preference.setVisible(false);
@@ -52,9 +57,22 @@ public class EnterpriseInstalledPackagesPreferenceController extends PreferenceC

    @Override
    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;
        }

        // 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
    public String getPreferenceKey() {
        return KEY_NUMBER_ENTERPRISE_INSTALLED_PACKAGES;
+14 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.provider.SearchIndexableResource;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -51,16 +52,22 @@ public class EnterprisePrivacySettings extends DashboardFragment {

    @Override
    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>();
        controllers.add(new InstalledPackagesPreferenceController(context));
        controllers.add(new NetworkLogsPreferenceController(context));
        controllers.add(new BugReportsPreferenceController(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 AdminGrantedMicrophonePermissionPreferenceController(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 AlwaysOnVpnManagedProfilePreferenceController(context));
        controllers.add(new GlobalHttpProxyPreferenceController(context));
@@ -92,5 +99,10 @@ public class EnterprisePrivacySettings extends DashboardFragment {
                    sir.xmlResId = R.xml.enterprise_privacy_settings;
                    return Arrays.asList(sir);
            }

            @Override
            public List<PreferenceController> getPreferenceControllers(Context context) {
                return buildPreferenceControllers(context, null /* lifecycle */, false /* async */);
                }
            };
}
Loading