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

Commit 64806e51 authored by Songchun Fan's avatar Songchun Fan Committed by Android (Google) Code Review
Browse files

Merge "[pm] use snapshot instead of deep-copy of PackageUserState"

parents ef75d4bd 0a7550ba
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -7558,7 +7558,7 @@ public class PackageManagerService extends IPackageManager.Stub
            if (packageState == null) {
                return new ArraySet<>();
            }
            return packageState.getUserStateOrDefault(userId).getEnabledComponentsNoCopy();
            return packageState.getUserStateOrDefault(userId).getEnabledComponents();
        }

        @Override
@@ -7567,7 +7567,7 @@ public class PackageManagerService extends IPackageManager.Stub
            if (packageState == null) {
                return new ArraySet<>();
            }
            return packageState.getUserStateOrDefault(userId).getDisabledComponentsNoCopy();
            return packageState.getUserStateOrDefault(userId).getDisabledComponents();
        }

        @Override
+27 −16
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import com.android.server.pm.pkg.PackageUserStateImpl;
import com.android.server.pm.pkg.PackageUserStateInternal;
import com.android.server.pm.pkg.SuspendParams;
import com.android.server.utils.SnapshotCache;
import com.android.server.utils.WatchedArraySet;

import libcore.util.EmptyArray;

@@ -249,7 +250,7 @@ public class PackageSetting extends SettingBase implements PackageStateInternal

    PackageSetting(@NonNull PackageSetting original, boolean sealedSnapshot)  {
        super(original);
        copyPackageSetting(original);
        copyPackageSetting(original, sealedSnapshot);
        if (sealedSnapshot) {
            mSnapshot = new SnapshotCache.Sealed();
        } else {
@@ -515,7 +516,7 @@ public class PackageSetting extends SettingBase implements PackageStateInternal

    /** Updates all fields in the current setting from another. */
    public void updateFrom(PackageSetting other) {
        copyPackageSetting(other);
        copyPackageSetting(other, false /* sealedSnapshot */);

        Set<String> mimeGroupNames = other.mimeGroups != null ? other.mimeGroups.keySet() : null;
        updateMimeGroups(mimeGroupNames);
@@ -608,7 +609,7 @@ public class PackageSetting extends SettingBase implements PackageStateInternal
        return this;
    }

    public void copyPackageSetting(PackageSetting other) {
    public void copyPackageSetting(PackageSetting other, boolean sealedSnapshot) {
        super.copySettingBase(other);
        mSharedUserAppId = other.mSharedUserAppId;
        mLoadingProgress = other.mLoadingProgress;
@@ -650,8 +651,12 @@ public class PackageSetting extends SettingBase implements PackageStateInternal
                other.usesStaticLibrariesVersions.length) : null;
        mUserStates.clear();
        for (int i = 0; i < other.mUserStates.size(); i++) {
            if (sealedSnapshot) {
                mUserStates.put(other.mUserStates.keyAt(i),
                    new PackageUserStateImpl(this, other.mUserStates.valueAt(i)));
                        other.mUserStates.valueAt(i).snapshot());
            } else {
                mUserStates.put(other.mUserStates.keyAt(i), other.mUserStates.valueAt(i));
            }
        }

        if (mOldCodePaths != null) {
@@ -871,42 +876,48 @@ public class PackageSetting extends SettingBase implements PackageStateInternal
        setUserState(userId, otherState.getCeDataInode(), otherState.getEnabledState(),
                otherState.isInstalled(), otherState.isStopped(), otherState.isNotLaunched(),
                otherState.isHidden(), otherState.getDistractionFlags(),
                otherState.getSuspendParams(), otherState.isInstantApp(),
                otherState.getSuspendParams() == null
                        ? null : otherState.getSuspendParams().untrackedStorage(),
                otherState.isInstantApp(),
                otherState.isVirtualPreload(), otherState.getLastDisableAppCaller(),
                new ArraySet<>(otherState.getEnabledComponentsNoCopy()),
                new ArraySet<>(otherState.getDisabledComponentsNoCopy()),
                otherState.getEnabledComponentsNoCopy() == null
                        ? null : otherState.getEnabledComponentsNoCopy().untrackedStorage(),
                otherState.getDisabledComponentsNoCopy() == null
                        ? null : otherState.getDisabledComponentsNoCopy().untrackedStorage(),
                otherState.getInstallReason(), otherState.getUninstallReason(),
                otherState.getHarmfulAppWarning(), otherState.getSplashScreenTheme(),
                otherState.getFirstInstallTime());
    }

    ArraySet<String> getEnabledComponents(int userId) {
    WatchedArraySet<String> getEnabledComponents(int userId) {
        return readUserState(userId).getEnabledComponentsNoCopy();
    }

    ArraySet<String> getDisabledComponents(int userId) {
    WatchedArraySet<String> getDisabledComponents(int userId) {
        return readUserState(userId).getDisabledComponentsNoCopy();
    }

    void setEnabledComponents(ArraySet<String> components, int userId) {
    /** Test only */
    void setEnabledComponents(WatchedArraySet<String> components, int userId) {
        modifyUserState(userId).setEnabledComponents(components);
        onChanged();
    }

    void setDisabledComponents(ArraySet<String> components, int userId) {
    /** Test only */
    void setDisabledComponents(WatchedArraySet<String> components, int userId) {
        modifyUserState(userId).setDisabledComponents(components);
        onChanged();
    }

    void setEnabledComponentsCopy(ArraySet<String> components, int userId) {
    void setEnabledComponentsCopy(WatchedArraySet<String> components, int userId) {
        modifyUserState(userId).setEnabledComponents(components != null
                ? new ArraySet<String>(components) : null);
                ? components.untrackedStorage() : null);
        onChanged();
    }

    void setDisabledComponentsCopy(ArraySet<String> components, int userId) {
    void setDisabledComponentsCopy(WatchedArraySet<String> components, int userId) {
        modifyUserState(userId).setDisabledComponents(components != null
                ? new ArraySet<String>(components) : null);
                ? components.untrackedStorage() : null);
        onChanged();
    }

+16 −12
Original line number Diff line number Diff line
@@ -2142,20 +2142,24 @@ public final class Settings implements Watchable, Snappable {
                        serializer.endTag(null, TAG_SUSPEND_PARAMS);
                    }
                }
                if (!ArrayUtils.isEmpty(ustate.getEnabledComponentsNoCopy())) {
                final ArraySet<String> enabledComponents = ustate.getEnabledComponents();
                if (enabledComponents != null && enabledComponents.size() > 0) {
                    serializer.startTag(null, TAG_ENABLED_COMPONENTS);
                    for (final String name : ustate.getEnabledComponentsNoCopy()) {
                    for (int i = 0; i < enabledComponents.size(); i++) {
                        serializer.startTag(null, TAG_ITEM);
                        serializer.attribute(null, ATTR_NAME, name);
                        serializer.attribute(null, ATTR_NAME,
                                enabledComponents.valueAt(i));
                        serializer.endTag(null, TAG_ITEM);
                    }
                    serializer.endTag(null, TAG_ENABLED_COMPONENTS);
                }
                if (!ArrayUtils.isEmpty(ustate.getDisabledComponentsNoCopy())) {
                final ArraySet<String> disabledComponents = ustate.getDisabledComponents();
                if (disabledComponents != null && disabledComponents.size() > 0) {
                    serializer.startTag(null, TAG_DISABLED_COMPONENTS);
                    for (final String name : ustate.getDisabledComponentsNoCopy()) {
                    for (int i = 0; i < disabledComponents.size(); i++) {
                        serializer.startTag(null, TAG_ITEM);
                        serializer.attribute(null, ATTR_NAME, name);
                        serializer.attribute(null, ATTR_NAME,
                                disabledComponents.valueAt(i));
                        serializer.endTag(null, TAG_ITEM);
                    }
                    serializer.endTag(null, TAG_DISABLED_COMPONENTS);
@@ -4987,18 +4991,18 @@ public final class Settings implements Watchable, Snappable {
            }

            if (permissionNames == null) {
                Set<String> cmp = userState.getDisabledComponents();
                WatchedArraySet<String> cmp = userState.getDisabledComponentsNoCopy();
                if (cmp != null && cmp.size() > 0) {
                    pw.print(prefix); pw.println("    disabledComponents:");
                    for (String s : cmp) {
                        pw.print(prefix); pw.print("      "); pw.println(s);
                    for (int i = 0; i < cmp.size(); i++) {
                        pw.print(prefix); pw.print("      "); pw.println(cmp.valueAt(i));
                    }
                }
                cmp = userState.getEnabledComponents();
                cmp = userState.getEnabledComponentsNoCopy();
                if (cmp != null && cmp.size() > 0) {
                    pw.print(prefix); pw.println("    enabledComponents:");
                    for (String s : cmp) {
                        pw.print(prefix); pw.print("      "); pw.println(s);
                    for (int i = 0; i < cmp.size(); i++) {
                        pw.print(prefix); pw.print("      "); pw.println(cmp.valueAt(i));
                    }
                }
            }
+6 −3
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import com.android.server.pm.pkg.PackageStateInternal;
import com.android.server.pm.pkg.PackageUserStateInternal;
import com.android.server.pm.pkg.SuspendParams;
import com.android.server.pm.pkg.mutate.PackageUserStateWrite;
import com.android.server.utils.WatchedArrayMap;

import java.util.ArrayList;
import java.util.Arrays;
@@ -145,7 +146,7 @@ public final class SuspendPackageHelper {
                    continue;
                }

                final ArrayMap<String, SuspendParams> suspendParamsMap =
                final WatchedArrayMap<String, SuspendParams> suspendParamsMap =
                        packageState.getUserStateOrDefault(userId).getSuspendParams();
                final SuspendParams suspendParams = suspendParamsMap == null
                        ? null : suspendParamsMap.get(packageName);
@@ -297,7 +298,8 @@ public final class SuspendPackageHelper {
                    continue;
                }

                ArrayMap<String, SuspendParams> suspendParamsMap = packageUserState.getSuspendParams();
                WatchedArrayMap<String, SuspendParams> suspendParamsMap =
                        packageUserState.getSuspendParams();
                int countRemoved = 0;
                for (int index = 0; index < suspendParamsMap.size(); index++) {
                    String suspendingPackage = suspendParamsMap.keyAt(index);
@@ -440,7 +442,8 @@ public final class SuspendPackageHelper {
            return null;
        }

        final ArrayMap<String, SuspendParams> suspendParamsMap = userState.getSuspendParams();
        final WatchedArrayMap<String, SuspendParams> suspendParamsMap =
                userState.getSuspendParams();
        if (suspendParamsMap == null) {
            return null;
        }
+6 −4
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.pm.PackageManagerInternal;
import android.content.pm.SharedLibraryInfo;
import android.content.pm.SigningInfo;
import android.content.pm.overlay.OverlayPaths;
import android.util.ArraySet;
import android.util.SparseArray;

import com.android.internal.util.DataClass;
@@ -329,11 +330,11 @@ public class PackageStateImpl implements PackageState {

        private final long mCeDataInode;
        @NonNull
        private final Set<String> mDisabledComponents;
        private final ArraySet<String> mDisabledComponents;
        @PackageManager.DistractionRestriction
        private final int mDistractionFlags;
        @NonNull
        private final Set<String> mEnabledComponents;
        private final ArraySet<String> mEnabledComponents;
        private final int mEnabledState;
        @Nullable
        private final String mHarmfulAppWarning;
@@ -460,7 +461,8 @@ public class PackageStateImpl implements PackageState {
        }

        @DataClass.Generated.Member
        public @NonNull Set<String> getDisabledComponents() {
        public @NonNull
        ArraySet<String> getDisabledComponents() {
            return mDisabledComponents;
        }

@@ -470,7 +472,7 @@ public class PackageStateImpl implements PackageState {
        }

        @DataClass.Generated.Member
        public @NonNull Set<String> getEnabledComponents() {
        public @NonNull ArraySet<String> getEnabledComponents() {
            return mEnabledComponents;
        }

Loading