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

Commit d63ec172 authored by Winson Chiu's avatar Winson Chiu Committed by Android (Google) Code Review
Browse files

Merge "Migrate PackageSetting usages to PackageStateInternal"

parents 8d1a673e b049d95e
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -51,6 +51,7 @@ import com.android.server.pm.PackageSetting;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.pkg.AndroidPackageApi;
import com.android.server.pm.pkg.AndroidPackageApi;
import com.android.server.pm.pkg.PackageState;
import com.android.server.pm.pkg.PackageState;
import com.android.server.pm.pkg.PackageStateInternal;


import java.io.IOException;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
@@ -657,7 +658,8 @@ public abstract class PackageManagerInternal implements PackageSettingsSnapshotP
    @Nullable
    @Nullable
    public abstract AndroidPackageApi getAndroidPackage(@NonNull String packageName);
    public abstract AndroidPackageApi getAndroidPackage(@NonNull String packageName);


    public abstract @Nullable PackageSetting getPackageSetting(@NonNull String packageName);
    @Nullable
    public abstract PackageStateInternal getPackageStateInternal(@NonNull String packageName);


    public abstract @Nullable PackageState getPackageState(@NonNull String packageName);
    public abstract @Nullable PackageState getPackageState(@NonNull String packageName);


+9 −7
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.NonNull;
import com.android.internal.util.FunctionalUtils;
import com.android.internal.util.FunctionalUtils;
import com.android.server.pm.PackageManagerService;
import com.android.server.pm.PackageManagerService;
import com.android.server.pm.PackageSetting;
import com.android.server.pm.PackageSetting;
import com.android.server.pm.pkg.PackageStateInternal;


import java.util.function.Consumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Function;
@@ -29,28 +30,28 @@ import java.util.function.Function;
public interface PackageSettingsSnapshotProvider {
public interface PackageSettingsSnapshotProvider {


    /**
    /**
     * Run a function block that requires access to {@link PackageSetting} data. This will
     * Run a function block that requires access to {@link PackageStateInternal} data. This will
     * ensure the {@link PackageManagerService} lock is taken before any caller's internal lock
     * ensure the {@link PackageManagerService} lock is taken before any caller's internal lock
     * to avoid deadlock. Note that this method may or may not lock. If a snapshot is available
     * to avoid deadlock. Note that this method may or may not lock. If a snapshot is available
     * and valid, it will iterate the snapshot set of data.
     * and valid, it will iterate the snapshot set of data.
     */
     */
    void withPackageSettingsSnapshot(
    void withPackageSettingsSnapshot(
            @NonNull Consumer<Function<String, PackageSetting>> block);
            @NonNull Consumer<Function<String, PackageStateInternal>> block);


    /**
    /**
     * Variant which returns a value to the caller.
     * Variant which returns a value to the caller.
     * @see #withPackageSettingsSnapshot(Consumer)
     * @see #withPackageSettingsSnapshot(Consumer)
     */
     */
    <Output> Output withPackageSettingsSnapshotReturning(
    <Output> Output withPackageSettingsSnapshotReturning(
            @NonNull FunctionalUtils.ThrowingFunction<Function<String, PackageSetting>, Output>
            @NonNull FunctionalUtils.ThrowingFunction<Function<String, PackageStateInternal>,
                    block);
                    Output> block);


    /**
    /**
     * Variant which throws.
     * Variant which throws.
     * @see #withPackageSettingsSnapshot(Consumer)
     * @see #withPackageSettingsSnapshot(Consumer)
     */
     */
    <ExceptionType extends Exception> void withPackageSettingsSnapshotThrowing(
    <ExceptionType extends Exception> void withPackageSettingsSnapshotThrowing(
            @NonNull FunctionalUtils.ThrowingCheckedConsumer<Function<String, PackageSetting>,
            @NonNull FunctionalUtils.ThrowingCheckedConsumer<Function<String, PackageStateInternal>,
                    ExceptionType> block) throws ExceptionType;
                    ExceptionType> block) throws ExceptionType;


    /**
    /**
@@ -60,7 +61,8 @@ public interface PackageSettingsSnapshotProvider {
    <ExceptionOne extends Exception, ExceptionTwo extends Exception> void
    <ExceptionOne extends Exception, ExceptionTwo extends Exception> void
            withPackageSettingsSnapshotThrowing2(
            withPackageSettingsSnapshotThrowing2(
                    @NonNull FunctionalUtils.ThrowingChecked2Consumer<
                    @NonNull FunctionalUtils.ThrowingChecked2Consumer<
                            Function<String, PackageSetting>, ExceptionOne, ExceptionTwo> block)
                            Function<String, PackageStateInternal>,
                            ExceptionOne, ExceptionTwo> block)
            throws ExceptionOne, ExceptionTwo;
            throws ExceptionOne, ExceptionTwo;


    /**
    /**
@@ -70,6 +72,6 @@ public interface PackageSettingsSnapshotProvider {
    <Output, ExceptionType extends Exception> Output
    <Output, ExceptionType extends Exception> Output
            withPackageSettingsSnapshotReturningThrowing(
            withPackageSettingsSnapshotReturningThrowing(
                    @NonNull FunctionalUtils.ThrowingCheckedFunction<
                    @NonNull FunctionalUtils.ThrowingCheckedFunction<
                            Function<String, PackageSetting>, Output, ExceptionType> block)
                            Function<String, PackageStateInternal>, Output, ExceptionType> block)
            throws ExceptionType;
            throws ExceptionType;
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -3321,7 +3321,7 @@ public class AppOpsService extends IAppOpsService.Stub {


    private boolean isPackageExisted(String packageName) {
    private boolean isPackageExisted(String packageName) {
        return LocalServices.getService(PackageManagerInternal.class)
        return LocalServices.getService(PackageManagerInternal.class)
                .getPackageSetting(packageName) != null;
                .getPackageStateInternal(packageName) != null;
    }
    }


    /**
    /**
+57 −50
Original line number Original line Diff line number Diff line
@@ -61,6 +61,7 @@ import com.android.server.compat.CompatChange;
import com.android.server.om.OverlayReferenceMapper;
import com.android.server.om.OverlayReferenceMapper;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
import com.android.server.pm.pkg.PackageStateInternal;
import com.android.server.utils.Snappable;
import com.android.server.utils.Snappable;
import com.android.server.utils.SnapshotCache;
import com.android.server.utils.SnapshotCache;
import com.android.server.utils.Snapshots;
import com.android.server.utils.Snapshots;
@@ -166,7 +167,7 @@ public class AppsFilter implements Watchable, Snappable {
    /**
    /**
     * This structure maps uid -> uid and indicates whether access from the first should be
     * This structure maps uid -> uid and indicates whether access from the first should be
     * filtered to the second. It's essentially a cache of the
     * filtered to the second. It's essentially a cache of the
     * {@link #shouldFilterApplicationInternal(int, SettingBase, PackageSetting, int)} call.
     * {@link #shouldFilterApplicationInternal(int, Object, PackageStateInternal, int)} call.
     * NOTE: It can only be relied upon after the system is ready to avoid unnecessary update on
     * NOTE: It can only be relied upon after the system is ready to avoid unnecessary update on
     * initial scam and is null until {@link #onSystemReady()} is called.
     * initial scam and is null until {@link #onSystemReady()} is called.
     */
     */
@@ -311,7 +312,8 @@ public class AppsFilter implements Watchable, Snappable {
        void runWithState(CurrentStateCallback callback);
        void runWithState(CurrentStateCallback callback);


        interface CurrentStateCallback {
        interface CurrentStateCallback {
            void currentState(ArrayMap<String, PackageSetting> settings, UserInfo[] users);
            void currentState(ArrayMap<String, ? extends PackageStateInternal> settings,
                    UserInfo[] users);
        }
        }
    }
    }


@@ -343,7 +345,7 @@ public class AppsFilter implements Watchable, Snappable {
         *
         *
         * @param removed true if adding, false if removing
         * @param removed true if adding, false if removing
         */
         */
        void updatePackageState(PackageSetting setting, boolean removed);
        void updatePackageState(PackageStateInternal setting, boolean removed);
    }
    }


    private static class FeatureConfigImpl implements FeatureConfig, CompatChange.ChangeListener {
    private static class FeatureConfigImpl implements FeatureConfig, CompatChange.ChangeListener {
@@ -467,7 +469,7 @@ public class AppsFilter implements Watchable, Snappable {
        }
        }


        @Override
        @Override
        public void updatePackageState(PackageSetting setting, boolean removed) {
        public void updatePackageState(PackageStateInternal setting, boolean removed) {
            final boolean enableLogging = setting.getPkg() != null &&
            final boolean enableLogging = setting.getPkg() != null &&
                    !removed && (setting.getPkg().isTestOnly() || setting.getPkg().isDebuggable());
                    !removed && (setting.getPkg().isTestOnly() || setting.getPkg().isDebuggable());
            enableLogging(setting.getAppId(), enableLogging);
            enableLogging(setting.getAppId(), enableLogging);
@@ -538,7 +540,7 @@ public class AppsFilter implements Watchable, Snappable {
                && querying.getQueriesPackages().contains(potentialTarget.getPackageName());
                && querying.getQueriesPackages().contains(potentialTarget.getPackageName());
    }
    }


    private static boolean canQueryAsInstaller(PackageSetting querying,
    private static boolean canQueryAsInstaller(PackageStateInternal querying,
            AndroidPackage potentialTarget) {
            AndroidPackage potentialTarget) {
        final InstallSource installSource = querying.getInstallSource();
        final InstallSource installSource = querying.getInstallSource();
        if (potentialTarget.getPackageName().equals(installSource.installerPackageName)) {
        if (potentialTarget.getPackageName().equals(installSource.installerPackageName)) {
@@ -689,7 +691,7 @@ public class AppsFilter implements Watchable, Snappable {
     * @param newPkgSetting the new setting being added
     * @param newPkgSetting the new setting being added
     * @param isReplace if the package is being replaced and may need extra cleanup.
     * @param isReplace if the package is being replaced and may need extra cleanup.
     */
     */
    public void addPackage(PackageSetting newPkgSetting, boolean isReplace) {
    public void addPackage(PackageStateInternal newPkgSetting, boolean isReplace) {
        if (DEBUG_TRACING) {
        if (DEBUG_TRACING) {
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "filter.addPackage");
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "filter.addPackage");
        }
        }
@@ -708,7 +710,8 @@ public class AppsFilter implements Watchable, Snappable {
                        if (additionalChangedPackages != null) {
                        if (additionalChangedPackages != null) {
                            for (int index = 0; index < additionalChangedPackages.size(); index++) {
                            for (int index = 0; index < additionalChangedPackages.size(); index++) {
                                String changedPackage = additionalChangedPackages.valueAt(index);
                                String changedPackage = additionalChangedPackages.valueAt(index);
                                PackageSetting changedPkgSetting = settings.get(changedPackage);
                                PackageStateInternal changedPkgSetting =
                                        settings.get(changedPackage);
                                if (changedPkgSetting == null) {
                                if (changedPkgSetting == null) {
                                    // It's possible for the overlay mapper to know that an actor
                                    // It's possible for the overlay mapper to know that an actor
                                    // package changed via an explicit reference, even if the actor
                                    // package changed via an explicit reference, even if the actor
@@ -737,14 +740,14 @@ public class AppsFilter implements Watchable, Snappable {
     * to be updated in the cache. Returns null if there are no additional packages.
     * to be updated in the cache. Returns null if there are no additional packages.
     */
     */
    @Nullable
    @Nullable
    private ArraySet<String> addPackageInternal(PackageSetting newPkgSetting,
    private ArraySet<String> addPackageInternal(PackageStateInternal newPkgSetting,
            ArrayMap<String, PackageSetting> existingSettings) {
            ArrayMap<String, ? extends PackageStateInternal> existingSettings) {
        if (Objects.equals("android", newPkgSetting.getPackageName())) {
        if (Objects.equals("android", newPkgSetting.getPackageName())) {
            // let's set aside the framework signatures
            // let's set aside the framework signatures
            mSystemSigningDetails = newPkgSetting.getSigningDetails();
            mSystemSigningDetails = newPkgSetting.getSigningDetails();
            // and since we add overlays before we add the framework, let's revisit already added
            // and since we add overlays before we add the framework, let's revisit already added
            // packages for signature matches
            // packages for signature matches
            for (PackageSetting setting : existingSettings.values()) {
            for (PackageStateInternal setting : existingSettings.values()) {
                if (isSystemSigned(mSystemSigningDetails, setting)) {
                if (isSystemSigned(mSystemSigningDetails, setting)) {
                    mForceQueryable.add(setting.getAppId());
                    mForceQueryable.add(setting.getAppId());
                }
                }
@@ -775,7 +778,7 @@ public class AppsFilter implements Watchable, Snappable {
        }
        }


        for (int i = existingSettings.size() - 1; i >= 0; i--) {
        for (int i = existingSettings.size() - 1; i >= 0; i--) {
            final PackageSetting existingSetting = existingSettings.valueAt(i);
            final PackageStateInternal existingSetting = existingSettings.valueAt(i);
            if (existingSetting.getAppId() == newPkgSetting.getAppId() || existingSetting.getPkg()
            if (existingSetting.getAppId() == newPkgSetting.getAppId() || existingSetting.getPkg()
                    == null) {
                    == null) {
                continue;
                continue;
@@ -823,7 +826,7 @@ public class AppsFilter implements Watchable, Snappable {
        int existingSize = existingSettings.size();
        int existingSize = existingSettings.size();
        ArrayMap<String, AndroidPackage> existingPkgs = new ArrayMap<>(existingSize);
        ArrayMap<String, AndroidPackage> existingPkgs = new ArrayMap<>(existingSize);
        for (int index = 0; index < existingSize; index++) {
        for (int index = 0; index < existingSize; index++) {
            PackageSetting pkgSetting = existingSettings.valueAt(index);
            PackageStateInternal pkgSetting = existingSettings.valueAt(index);
            if (pkgSetting.getPkg() != null) {
            if (pkgSetting.getPkg() != null) {
                existingPkgs.put(pkgSetting.getPackageName(), pkgSetting.getPkg());
                existingPkgs.put(pkgSetting.getPackageName(), pkgSetting.getPkg());
            }
            }
@@ -881,7 +884,8 @@ public class AppsFilter implements Watchable, Snappable {
    }
    }


    private WatchedSparseBooleanMatrix updateEntireShouldFilterCacheInner(
    private WatchedSparseBooleanMatrix updateEntireShouldFilterCacheInner(
            ArrayMap<String, PackageSetting> settings, UserInfo[] users, int subjectUserId) {
            ArrayMap<String, ? extends PackageStateInternal> settings, UserInfo[] users,
            int subjectUserId) {
        final WatchedSparseBooleanMatrix cache;
        final WatchedSparseBooleanMatrix cache;
        if (subjectUserId == USER_ALL) {
        if (subjectUserId == USER_ALL) {
            cache = new WatchedSparseBooleanMatrix(users.length * settings.size());
            cache = new WatchedSparseBooleanMatrix(users.length * settings.size());
@@ -900,7 +904,7 @@ public class AppsFilter implements Watchable, Snappable {


    private void updateEntireShouldFilterCacheAsync() {
    private void updateEntireShouldFilterCacheAsync() {
        mBackgroundExecutor.execute(() -> {
        mBackgroundExecutor.execute(() -> {
            final ArrayMap<String, PackageSetting> settingsCopy = new ArrayMap<>();
            final ArrayMap<String, PackageStateInternal> settingsCopy = new ArrayMap<>();
            final ArrayMap<String, AndroidPackage> packagesCache = new ArrayMap<>();
            final ArrayMap<String, AndroidPackage> packagesCache = new ArrayMap<>();
            final UserInfo[][] usersRef = new UserInfo[1][];
            final UserInfo[][] usersRef = new UserInfo[1][];
            mStateProvider.runWithState((settings, users) -> {
            mStateProvider.runWithState((settings, users) -> {
@@ -977,10 +981,11 @@ public class AppsFilter implements Watchable, Snappable {
    }
    }


    private void updateShouldFilterCacheForPackage(WatchedSparseBooleanMatrix cache,
    private void updateShouldFilterCacheForPackage(WatchedSparseBooleanMatrix cache,
            @Nullable String skipPackageName, PackageSetting subjectSetting, ArrayMap<String,
            @Nullable String skipPackageName, PackageStateInternal subjectSetting, ArrayMap<String,
            PackageSetting> allSettings, UserInfo[] allUsers, int subjectUserId, int maxIndex) {
            ? extends PackageStateInternal> allSettings, UserInfo[] allUsers, int subjectUserId,
            int maxIndex) {
        for (int i = Math.min(maxIndex, allSettings.size() - 1); i >= 0; i--) {
        for (int i = Math.min(maxIndex, allSettings.size() - 1); i >= 0; i--) {
            PackageSetting otherSetting = allSettings.valueAt(i);
            PackageStateInternal otherSetting = allSettings.valueAt(i);
            if (subjectSetting.getAppId() == otherSetting.getAppId()) {
            if (subjectSetting.getAppId() == otherSetting.getAppId()) {
                continue;
                continue;
            }
            }
@@ -1002,8 +1007,8 @@ public class AppsFilter implements Watchable, Snappable {
    }
    }


    private void updateShouldFilterCacheForUser(WatchedSparseBooleanMatrix cache,
    private void updateShouldFilterCacheForUser(WatchedSparseBooleanMatrix cache,
            PackageSetting subjectSetting, UserInfo[] allUsers, PackageSetting otherSetting,
            PackageStateInternal subjectSetting, UserInfo[] allUsers,
            int subjectUserId) {
            PackageStateInternal otherSetting, int subjectUserId) {
        for (int ou = 0; ou < allUsers.length; ou++) {
        for (int ou = 0; ou < allUsers.length; ou++) {
            int otherUser = allUsers[ou].id;
            int otherUser = allUsers[ou].id;
            int subjectUid = UserHandle.getUid(subjectUserId, subjectSetting.getAppId());
            int subjectUid = UserHandle.getUid(subjectUserId, subjectSetting.getAppId());
@@ -1041,16 +1046,17 @@ public class AppsFilter implements Watchable, Snappable {
    }
    }


    private static boolean isSystemSigned(@NonNull SigningDetails sysSigningDetails,
    private static boolean isSystemSigned(@NonNull SigningDetails sysSigningDetails,
            PackageSetting pkgSetting) {
            PackageStateInternal pkgSetting) {
        return pkgSetting.isSystem()
        return pkgSetting.isSystem()
                && pkgSetting.getSigningDetails().signaturesMatchExactly(sysSigningDetails);
                && pkgSetting.getSigningDetails().signaturesMatchExactly(sysSigningDetails);
    }
    }


    private ArraySet<String> collectProtectedBroadcasts(
    private ArraySet<String> collectProtectedBroadcasts(
            ArrayMap<String, PackageSetting> existingSettings, @Nullable String excludePackage) {
            ArrayMap<String, ? extends PackageStateInternal> existingSettings,
            @Nullable String excludePackage) {
        ArraySet<String> ret = new ArraySet<>();
        ArraySet<String> ret = new ArraySet<>();
        for (int i = existingSettings.size() - 1; i >= 0; i--) {
        for (int i = existingSettings.size() - 1; i >= 0; i--) {
            PackageSetting setting = existingSettings.valueAt(i);
            PackageStateInternal setting = existingSettings.valueAt(i);
            if (setting.getPkg() == null || setting.getPkg().getPackageName().equals(
            if (setting.getPkg() == null || setting.getPkg().getPackageName().equals(
                    excludePackage)) {
                    excludePackage)) {
                continue;
                continue;
@@ -1065,13 +1071,13 @@ public class AppsFilter implements Watchable, Snappable {


    /**
    /**
     * This method recomputes all component / intent-based visibility and is intended to match the
     * This method recomputes all component / intent-based visibility and is intended to match the
     * relevant logic of {@link #addPackageInternal(PackageSetting, ArrayMap)}
     * relevant logic of {@link #addPackageInternal(PackageStateInternal, ArrayMap)}
     */
     */
    private void recomputeComponentVisibility(
    private void recomputeComponentVisibility(
            ArrayMap<String, PackageSetting> existingSettings) {
            ArrayMap<String, ? extends PackageStateInternal> existingSettings) {
        mQueriesViaComponent.clear();
        mQueriesViaComponent.clear();
        for (int i = existingSettings.size() - 1; i >= 0; i--) {
        for (int i = existingSettings.size() - 1; i >= 0; i--) {
            PackageSetting setting = existingSettings.valueAt(i);
            PackageStateInternal setting = existingSettings.valueAt(i);
            if (setting.getPkg() == null || requestsQueryAllPackages(setting.getPkg())) {
            if (setting.getPkg() == null || requestsQueryAllPackages(setting.getPkg())) {
                continue;
                continue;
            }
            }
@@ -1079,7 +1085,7 @@ public class AppsFilter implements Watchable, Snappable {
                if (i == j) {
                if (i == j) {
                    continue;
                    continue;
                }
                }
                final PackageSetting otherSetting = existingSettings.valueAt(j);
                final PackageStateInternal otherSetting = existingSettings.valueAt(j);
                if (otherSetting.getPkg() == null || mForceQueryable.contains(
                if (otherSetting.getPkg() == null || mForceQueryable.contains(
                        otherSetting.getAppId())) {
                        otherSetting.getAppId())) {
                    continue;
                    continue;
@@ -1108,8 +1114,8 @@ public class AppsFilter implements Watchable, Snappable {
     * applied.
     * applied.
     */
     */
    @Nullable
    @Nullable
    public SparseArray<int[]> getVisibilityAllowList(PackageSetting setting, int[] users,
    public SparseArray<int[]> getVisibilityAllowList(PackageStateInternal setting, int[] users,
            ArrayMap<String, PackageSetting> existingSettings) {
            ArrayMap<String, ? extends PackageStateInternal> existingSettings) {
        if (mForceQueryable.contains(setting.getAppId())) {
        if (mForceQueryable.contains(setting.getAppId())) {
            return null;
            return null;
        }
        }
@@ -1121,7 +1127,7 @@ public class AppsFilter implements Watchable, Snappable {
            int[] buffer = null;
            int[] buffer = null;
            int allowListSize = 0;
            int allowListSize = 0;
            for (int i = existingSettings.size() - 1; i >= 0; i--) {
            for (int i = existingSettings.size() - 1; i >= 0; i--) {
                final PackageSetting existingSetting = existingSettings.valueAt(i);
                final PackageStateInternal existingSetting = existingSettings.valueAt(i);
                final int existingAppId = existingSetting.getAppId();
                final int existingAppId = existingSetting.getAppId();
                if (existingAppId < Process.FIRST_APPLICATION_UID) {
                if (existingAppId < Process.FIRST_APPLICATION_UID) {
                    continue;
                    continue;
@@ -1152,17 +1158,17 @@ public class AppsFilter implements Watchable, Snappable {
     */
     */
    @VisibleForTesting(visibility = PRIVATE)
    @VisibleForTesting(visibility = PRIVATE)
    @Nullable
    @Nullable
    SparseArray<int[]> getVisibilityAllowList(PackageSetting setting, int[] users,
    SparseArray<int[]> getVisibilityAllowList(PackageStateInternal setting, int[] users,
            WatchedArrayMap<String, PackageSetting> existingSettings) {
            WatchedArrayMap<String, ? extends PackageStateInternal> existingSettings) {
        return getVisibilityAllowList(setting, users, existingSettings.untrackedStorage());
        return getVisibilityAllowList(setting, users, existingSettings.untrackedStorage());
    }
    }


    /**
    /**
     * Equivalent to calling {@link #addPackage(PackageSetting, boolean)} with {@code isReplace}
     * Equivalent to calling {@link #addPackage(PackageStateInternal, boolean)} with
     * equal to {@code false}.
     * {@code isReplace} equal to {@code false}.
     * @see AppsFilter#addPackage(PackageSetting, boolean)
     * @see AppsFilter#addPackage(PackageStateInternal, boolean)
     */
     */
    public void addPackage(PackageSetting newPkgSetting) {
    public void addPackage(PackageStateInternal newPkgSetting) {
        addPackage(newPkgSetting, false /* isReplace */);
        addPackage(newPkgSetting, false /* isReplace */);
    }
    }


@@ -1172,7 +1178,7 @@ public class AppsFilter implements Watchable, Snappable {
     * @param setting the setting of the package being removed.
     * @param setting the setting of the package being removed.
     * @param isReplace if the package is being replaced.
     * @param isReplace if the package is being replaced.
     */
     */
    public void removePackage(PackageSetting setting, boolean isReplace) {
    public void removePackage(PackageStateInternal setting, boolean isReplace) {
        mStateProvider.runWithState((settings, users) -> {
        mStateProvider.runWithState((settings, users) -> {
            final int userCount = users.length;
            final int userCount = users.length;
            for (int u = 0; u < userCount; u++) {
            for (int u = 0; u < userCount; u++) {
@@ -1244,7 +1250,8 @@ public class AppsFilter implements Watchable, Snappable {
                removeAppIdFromVisibilityCache(setting.getAppId());
                removeAppIdFromVisibilityCache(setting.getAppId());
                if (mShouldFilterCache != null && setting.getSharedUser() != null) {
                if (mShouldFilterCache != null && setting.getSharedUser() != null) {
                    for (int i = setting.getSharedUser().packages.size() - 1; i >= 0; i--) {
                    for (int i = setting.getSharedUser().packages.size() - 1; i >= 0; i--) {
                        PackageSetting siblingSetting = setting.getSharedUser().packages.valueAt(i);
                        PackageStateInternal siblingSetting =
                                setting.getSharedUser().packages.valueAt(i);
                        if (siblingSetting == setting) {
                        if (siblingSetting == setting) {
                            continue;
                            continue;
                        }
                        }
@@ -1258,7 +1265,7 @@ public class AppsFilter implements Watchable, Snappable {
                    if (additionalChangedPackages != null) {
                    if (additionalChangedPackages != null) {
                        for (int index = 0; index < additionalChangedPackages.size(); index++) {
                        for (int index = 0; index < additionalChangedPackages.size(); index++) {
                            String changedPackage = additionalChangedPackages.valueAt(index);
                            String changedPackage = additionalChangedPackages.valueAt(index);
                            PackageSetting changedPkgSetting = settings.get(changedPackage);
                            PackageStateInternal changedPkgSetting = settings.get(changedPackage);
                            if (changedPkgSetting == null) {
                            if (changedPkgSetting == null) {
                                // It's possible for the overlay mapper to know that an actor
                                // It's possible for the overlay mapper to know that an actor
                                // package changed via an explicit reference, even if the actor
                                // package changed via an explicit reference, even if the actor
@@ -1287,8 +1294,8 @@ public class AppsFilter implements Watchable, Snappable {
     * @param targetPkgSetting the package being accessed
     * @param targetPkgSetting the package being accessed
     * @param userId           the user in which this access is being attempted
     * @param userId           the user in which this access is being attempted
     */
     */
    public boolean shouldFilterApplication(int callingUid, @Nullable SettingBase callingSetting,
    public boolean shouldFilterApplication(int callingUid, @Nullable Object callingSetting,
            PackageSetting targetPkgSetting, int userId) {
            PackageStateInternal targetPkgSetting, int userId) {
        if (DEBUG_TRACING) {
        if (DEBUG_TRACING) {
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplication");
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplication");
        }
        }
@@ -1333,8 +1340,8 @@ public class AppsFilter implements Watchable, Snappable {
        }
        }
    }
    }


    private boolean shouldFilterApplicationInternal(int callingUid, SettingBase callingSetting,
    private boolean shouldFilterApplicationInternal(int callingUid, Object callingSetting,
            PackageSetting targetPkgSetting, int targetUserId) {
            PackageStateInternal targetPkgSetting, int targetUserId) {
        if (DEBUG_TRACING) {
        if (DEBUG_TRACING) {
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplicationInternal");
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplicationInternal");
        }
        }
@@ -1350,19 +1357,19 @@ public class AppsFilter implements Watchable, Snappable {
                Slog.wtf(TAG, "No setting found for non system uid " + callingUid);
                Slog.wtf(TAG, "No setting found for non system uid " + callingUid);
                return true;
                return true;
            }
            }
            final PackageSetting callingPkgSetting;
            final PackageStateInternal callingPkgSetting;
            final ArraySet<PackageSetting> callingSharedPkgSettings;
            final ArraySet<? extends PackageStateInternal> callingSharedPkgSettings;
            if (DEBUG_TRACING) {
            if (DEBUG_TRACING) {
                Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "callingSetting instanceof");
                Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "callingSetting instanceof");
            }
            }
            if (callingSetting instanceof PackageSetting) {
            if (callingSetting instanceof PackageStateInternal) {
                if (((PackageSetting) callingSetting).getSharedUser() == null) {
                if (((PackageStateInternal) callingSetting).getSharedUser() == null) {
                    callingPkgSetting = (PackageSetting) callingSetting;
                    callingPkgSetting = (PackageStateInternal) callingSetting;
                    callingSharedPkgSettings = null;
                    callingSharedPkgSettings = null;
                } else {
                } else {
                    callingPkgSetting = null;
                    callingPkgSetting = null;
                    callingSharedPkgSettings =
                    callingSharedPkgSettings =
                            ((PackageSetting) callingSetting).getSharedUser().packages;
                            ((PackageStateInternal) callingSetting).getSharedUser().packages;
                }
                }
            } else {
            } else {
                callingPkgSetting = null;
                callingPkgSetting = null;
@@ -1544,7 +1551,7 @@ public class AppsFilter implements Watchable, Snappable {
                if (callingSharedPkgSettings != null) {
                if (callingSharedPkgSettings != null) {
                    int size = callingSharedPkgSettings.size();
                    int size = callingSharedPkgSettings.size();
                    for (int index = 0; index < size; index++) {
                    for (int index = 0; index < size; index++) {
                        PackageSetting pkgSetting = callingSharedPkgSettings.valueAt(index);
                        PackageStateInternal pkgSetting = callingSharedPkgSettings.valueAt(index);
                        if (mOverlayReferenceMapper.isValidActor(targetName,
                        if (mOverlayReferenceMapper.isValidActor(targetName,
                                pkgSetting.getPackageName())) {
                                pkgSetting.getPackageName())) {
                            if (DEBUG_LOGGING) {
                            if (DEBUG_LOGGING) {
@@ -1642,7 +1649,7 @@ public class AppsFilter implements Watchable, Snappable {
        }
        }
    }
    }


    private static void log(SettingBase callingSetting, PackageSetting targetPkgSetting,
    private static void log(Object callingSetting, PackageStateInternal targetPkgSetting,
            String description) {
            String description) {
        Slog.i(TAG,
        Slog.i(TAG,
                "interaction: " + (callingSetting == null ? "system" : callingSetting) + " -> "
                "interaction: " + (callingSetting == null ? "system" : callingSetting) + " -> "
+22 −23

File changed.

Preview size limit exceeded, changes collapsed.

Loading