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

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

Merge "Rely on PlatformCompat instead of DeviceConfig"

parents 755f7268 a94cbc12
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ import android.app.PackageInstallObserver;
import android.app.admin.DevicePolicyManager;
import android.app.usage.StorageStatsManager;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.compat.annotation.Disabled;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -3379,7 +3379,7 @@ public abstract class PackageManager {
     * @hide
     */
    @ChangeId
    @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q)
    @Disabled
    public static final long FILTER_APPLICATION_QUERY = 135549675L;

    /** {@hide} */
+19 −26
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.util.Slog;
import android.util.SparseArray;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.FgThread;
import com.android.server.compat.PlatformCompat;

@@ -55,14 +56,11 @@ import java.util.Set;
 * The entity responsible for filtering visibility between apps based on declarations in their
 * manifests.
 */
class AppsFilter {
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
public class AppsFilter {

    private static final String TAG = PackageManagerService.TAG;

    // Forces filtering logic to run for debug purposes.
    // STOPSHIP (b/136675067): should be false after development is complete
    private static final boolean DEBUG_RUN_WHEN_DISABLED = false;

    // Logs all filtering instead of enforcing
    private static final boolean DEBUG_ALLOW_ALL = false;

@@ -128,15 +126,13 @@ class AppsFilter {

        /** @return true if the feature is enabled for the given package. */
        boolean packageIsEnabled(PackageParser.Package pkg);

    }

    private static class FeatureConfigImpl implements FeatureConfig {
        private static final String FILTERING_ENABLED_NAME = "package_query_filtering_enabled";

        // STOPSHIP(patb): set this to true if we plan to launch this in R
        private static final boolean DEFAULT_ENABLED_STATE = false;
        private final PackageManagerService.Injector mInjector;
        private volatile boolean mFeatureEnabled = DEFAULT_ENABLED_STATE;
        private volatile boolean mFeatureEnabled = true;

        private FeatureConfigImpl(PackageManagerService.Injector injector) {
            mInjector = injector;
@@ -146,13 +142,13 @@ class AppsFilter {
        public void onSystemReady() {
            mFeatureEnabled = DeviceConfig.getBoolean(
                    NAMESPACE_PACKAGE_MANAGER_SERVICE, FILTERING_ENABLED_NAME,
                    DEFAULT_ENABLED_STATE);
                    true);
            DeviceConfig.addOnPropertiesChangedListener(
                    NAMESPACE_PACKAGE_MANAGER_SERVICE, FgThread.getExecutor(),
                    properties -> {
                        synchronized (FeatureConfigImpl.this) {
                            mFeatureEnabled = properties.getBoolean(
                                    FILTERING_ENABLED_NAME, DEFAULT_ENABLED_STATE);
                                    FILTERING_ENABLED_NAME, true);
                        }
                    });
        }
@@ -353,7 +349,7 @@ class AppsFilter {
    public boolean shouldFilterApplication(int callingUid, @Nullable SettingBase callingSetting,
            PackageSetting targetPkgSetting, int userId) {
        final boolean featureEnabled = mFeatureConfig.isGloballyEnabled();
        if (!featureEnabled && !DEBUG_RUN_WHEN_DISABLED) {
        if (!featureEnabled) {
            if (DEBUG_LOGGING) {
                Slog.d(TAG, "filtering disabled; skipped");
            }
@@ -399,21 +395,12 @@ class AppsFilter {
                return true;
            }
        }
        if (!featureEnabled) {
            return false;
        }
        if (mFeatureConfig.packageIsEnabled(callingPkgSetting.pkg)) {

        if (DEBUG_LOGGING) {
            log(callingPkgSetting, targetPkgSetting,
                    DEBUG_ALLOW_ALL ? "ALLOWED" : "BLOCKED");
        }
        return !DEBUG_ALLOW_ALL;
        } else {
            if (DEBUG_LOGGING) {
                log(callingPkgSetting, targetPkgSetting, "DISABLED");
            }
            return false;
        }
    }

    private boolean shouldFilterApplicationInternal(
@@ -421,6 +408,12 @@ class AppsFilter {
        final String callingName = callingPkgSetting.pkg.packageName;
        final PackageParser.Package targetPkg = targetPkgSetting.pkg;

        if (!mFeatureConfig.packageIsEnabled(callingPkgSetting.pkg)) {
            if (DEBUG_LOGGING) {
                log(callingPkgSetting, targetPkgSetting, "DISABLED");
            }
            return false;
        }
        // This package isn't technically installed and won't be written to settings, so we can
        // treat it as filtered until it's available again.
        if (targetPkg == null) {