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

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

Merge "[pm] remove SharedUserSetting from PackageSetting"

parents 6b656f58 c7c5ed70
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.pkg.AndroidPackageApi;
import com.android.server.pm.pkg.PackageState;
import com.android.server.pm.pkg.PackageStateInternal;
import com.android.server.pm.pkg.SharedUserApi;
import com.android.server.pm.pkg.component.ParsedMainComponent;
import com.android.server.pm.pkg.mutate.PackageStateMutator;

@@ -1261,6 +1262,21 @@ public abstract class PackageManagerInternal implements PackageSettingsSnapshotP
    public abstract void reconcileAppsData(int userId, @StorageManager.StorageFlags int flags,
            boolean migrateAppsData);

    /**
     * Returns an array of PackageStateInternal that are all part of a shared user setting which is
     * denoted by the app ID. Returns an empty set if the shared user setting doesn't exist or does
     * not contain any package.
     */
    @NonNull
    public abstract ArraySet<PackageStateInternal> getSharedUserPackages(int sharedUserAppId);

    /**
     * Returns the SharedUserApi denoted by the app ID of the shared user setting. Returns null if
     * the corresponding shared user setting doesn't exist.
     */
    @Nullable
    public abstract SharedUserApi getSharedUserApi(int sharedUserAppId);

    /**
     * Initiates a package state mutation request, returning the current state as known by
     * PackageManager. This allows the later commit request to compare the initial values and
+24 −19
Original line number Diff line number Diff line
@@ -33,11 +33,6 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.SigningDetails;
import android.content.pm.UserInfo;
import com.android.server.pm.pkg.component.ParsedComponent;
import com.android.server.pm.pkg.component.ParsedInstrumentation;
import com.android.server.pm.pkg.component.ParsedIntentInfo;
import com.android.server.pm.pkg.component.ParsedMainComponent;
import com.android.server.pm.pkg.component.ParsedProvider;
import android.os.Binder;
import android.os.Process;
import android.os.Trace;
@@ -62,6 +57,11 @@ import com.android.server.om.OverlayReferenceMapper;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
import com.android.server.pm.pkg.PackageStateInternal;
import com.android.server.pm.pkg.component.ParsedComponent;
import com.android.server.pm.pkg.component.ParsedInstrumentation;
import com.android.server.pm.pkg.component.ParsedIntentInfo;
import com.android.server.pm.pkg.component.ParsedMainComponent;
import com.android.server.pm.pkg.component.ParsedProvider;
import com.android.server.utils.Snappable;
import com.android.server.utils.SnapshotCache;
import com.android.server.utils.Snapshots;
@@ -158,6 +158,7 @@ public class AppsFilter implements Watchable, Snappable {
    private final FeatureConfig mFeatureConfig;
    private final OverlayReferenceMapper mOverlayReferenceMapper;
    private final StateProvider mStateProvider;
    private final PackageManagerInternal mPmInternal;

    private SigningDetails mSystemSigningDetails;
    private Set<String> mProtectedBroadcasts = new ArraySet<>();
@@ -250,13 +251,15 @@ public class AppsFilter implements Watchable, Snappable {
            String[] forceQueryableList,
            boolean systemAppsQueryable,
            @Nullable OverlayReferenceMapper.Provider overlayProvider,
            Executor backgroundExecutor) {
            Executor backgroundExecutor,
            PackageManagerInternal pmInternal) {
        mFeatureConfig = featureConfig;
        mForceQueryableByDevicePackageNames = forceQueryableList;
        mSystemAppsQueryable = systemAppsQueryable;
        mOverlayReferenceMapper = new OverlayReferenceMapper(true /*deferRebuild*/,
                overlayProvider);
        mStateProvider = stateProvider;
        mPmInternal = pmInternal;
        mBackgroundExecutor = backgroundExecutor;
        mSnapshot = makeCache();
    }
@@ -289,6 +292,7 @@ public class AppsFilter implements Watchable, Snappable {
        }

        mBackgroundExecutor = null;
        mPmInternal = null;
        mSnapshot = new SnapshotCache.Sealed<>();
    }

@@ -508,7 +512,7 @@ public class AppsFilter implements Watchable, Snappable {
        };
        AppsFilter appsFilter = new AppsFilter(stateProvider, featureConfig,
                forcedQueryablePackageNames, forceSystemAppsQueryable, null,
                injector.getBackgroundExecutor());
                injector.getBackgroundExecutor(), pms);
        featureConfig.setAppsFilter(appsFilter);
        return appsFilter;
    }
@@ -1236,9 +1240,9 @@ public class AppsFilter implements Watchable, Snappable {
            // shared user members to re-establish visibility between them and other packages.
            // NOTE: this must come after all removals from data structures but before we update the
            //       cache
            if (setting.getSharedUser() != null) {
                final ArraySet<? extends PackageStateInternal> sharedUserPackages =
                        setting.getSharedUser().getPackageStates();
            if (setting.hasSharedUser()) {
                final ArraySet<PackageStateInternal> sharedUserPackages =
                        mPmInternal.getSharedUserPackages(setting.getSharedUserAppId());
                for (int i = sharedUserPackages.size() - 1; i >= 0; i--) {
                    if (sharedUserPackages.valueAt(i) == setting) {
                        continue;
@@ -1250,9 +1254,9 @@ public class AppsFilter implements Watchable, Snappable {

            synchronized (mCacheLock) {
                removeAppIdFromVisibilityCache(setting.getAppId());
                if (mShouldFilterCache != null && setting.getSharedUser() != null) {
                    final ArraySet<? extends PackageStateInternal> sharedUserPackages =
                            setting.getSharedUser().getPackageStates();
                if (mShouldFilterCache != null && setting.hasSharedUser()) {
                    final ArraySet<PackageStateInternal> sharedUserPackages =
                            mPmInternal.getSharedUserPackages(setting.getSharedUserAppId());
                    for (int i = sharedUserPackages.size() - 1; i >= 0; i--) {
                        PackageStateInternal siblingSetting =
                                sharedUserPackages.valueAt(i);
@@ -1367,13 +1371,14 @@ public class AppsFilter implements Watchable, Snappable {
                Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "callingSetting instanceof");
            }
            if (callingSetting instanceof PackageStateInternal) {
                if (((PackageStateInternal) callingSetting).getSharedUser() == null) {
                    callingPkgSetting = (PackageStateInternal) callingSetting;
                    callingSharedPkgSettings = null;
                } else {
                final PackageStateInternal packageState = (PackageStateInternal) callingSetting;
                if (packageState.hasSharedUser()) {
                    callingPkgSetting = null;
                    callingSharedPkgSettings = ((PackageStateInternal) callingSetting)
                            .getSharedUser().getPackageStates();
                    callingSharedPkgSettings = mPmInternal.getSharedUserPackages(
                            packageState.getSharedUserAppId());
                } else {
                    callingPkgSetting = packageState;
                    callingSharedPkgSettings = null;
                }
            } else {
                callingPkgSetting = null;
+8 −0
Original line number Diff line number Diff line
@@ -640,4 +640,12 @@ public interface Computer {
    @Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
    @Nullable
    Pair<PackageStateInternal, SharedUserApi> getPackageOrSharedUser(int appId);

    @Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
    @Nullable
    SharedUserApi getSharedUser(int sharedUserAppIde);

    @Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
    @NonNull
    ArraySet<PackageStateInternal> getSharedUserPackages(int sharedUserAppId);
}
+46 −8
Original line number Diff line number Diff line
@@ -264,7 +264,7 @@ public class ComputerEngine implements Computer {
        }

        @Nullable
        public SharedUserSetting getSharedUser(String name) {
        public SharedUserSetting getSharedUserFromId(String name) {
            try {
                return mSettings.getSharedUserLPw(name, 0, 0, false /*create*/);
            } catch (PackageManagerException ignored) {
@@ -298,6 +298,31 @@ public class ComputerEngine implements Computer {
        public Collection<SharedUserSetting> getAllSharedUsers() {
            return mSettings.getAllSharedUsersLPw();
        }

        @Nullable
        public SharedUserApi getSharedUserFromPackageName(String packageName) {
            return mSettings.getSharedUserSettingLPr(packageName);
        }

        @Nullable
        public SharedUserApi getSharedUserFromAppId(int sharedUserAppId) {
            return (SharedUserSetting) mSettings.getSettingLPr(sharedUserAppId);
        }

        @NonNull
        public ArraySet<PackageStateInternal> getSharedUserPackages(int sharedUserAppId) {
            final ArraySet<PackageStateInternal> res = new ArraySet<>();
            final SharedUserSetting sharedUserSetting =
                    (SharedUserSetting) mSettings.getSettingLPr(sharedUserAppId);
            if (sharedUserSetting != null) {
                final ArraySet<? extends PackageStateInternal> sharedUserPackages =
                        sharedUserSetting.getPackageStates();
                for (PackageStateInternal ps : sharedUserPackages) {
                    res.add(ps);
                }
            }
            return res;
        }
    }

    private static final Comparator<ProviderInfo> sProviderInitOrderSorter = (p1, p2) -> {
@@ -1570,7 +1595,8 @@ public class ComputerEngine implements Computer {
            PackageInfo pi = new PackageInfo();
            pi.packageName = ps.getPackageName();
            pi.setLongVersionCode(ps.getVersionCode());
            pi.sharedUserId = (ps.getSharedUser() != null) ? ps.getSharedUser().getName() : null;
            SharedUserApi sharedUser = mSettings.getSharedUserFromPackageName(pi.packageName);
            pi.sharedUserId = (sharedUser != null) ? sharedUser.getName() : null;
            pi.firstInstallTime = state.getFirstInstallTime();
            pi.lastUpdateTime = ps.getLastUpdateTime();

@@ -4306,7 +4332,7 @@ public class ComputerEngine implements Computer {
            if (shouldFilterApplication(sus, callingUid, callingUserId)) {
                return null;
            }
            return sus.name + ":" + sus.userId;
            return sus.name + ":" + sus.mAppId;
        } else if (obj instanceof PackageSetting) {
            final PackageSetting ps = (PackageSetting) obj;
            if (shouldFilterApplication(ps, callingUid, callingUserId)) {
@@ -4366,10 +4392,10 @@ public class ComputerEngine implements Computer {
        if (getInstantAppPackageName(callingUid) != null) {
            return Process.INVALID_UID;
        }
        final SharedUserSetting suid = mSettings.getSharedUser(sharedUserName);
        final SharedUserSetting suid = mSettings.getSharedUserFromId(sharedUserName);
        if (suid != null && !shouldFilterApplication(suid, callingUid,
                UserHandle.getUserId(callingUid))) {
            return suid.userId;
            return suid.mAppId;
        }
        return Process.INVALID_UID;
    }
@@ -5430,7 +5456,7 @@ public class ComputerEngine implements Computer {
    public SparseArray<String> getAppsWithSharedUserIds() {
        final SparseArray<String> sharedUserIds = new SparseArray<>();
        for (SharedUserSetting setting : mSettings.getAllSharedUsers()) {
            sharedUserIds.put(UserHandle.getAppId(setting.userId), setting.name);
            sharedUserIds.put(UserHandle.getAppId(setting.mAppId), setting.name);
        }
        return sharedUserIds;
    }
@@ -5440,12 +5466,12 @@ public class ComputerEngine implements Computer {
    public String[] getSharedUserPackagesForPackage(@NonNull String packageName,
            @UserIdInt int userId) {
        final PackageStateInternal packageSetting = mSettings.getPackage(packageName);
        if (packageSetting == null || packageSetting.getSharedUser() == null) {
        if (packageSetting == null || mSettings.getSharedUserFromPackageName(packageName) == null) {
            return EmptyArray.STRING;
        }

        ArraySet<? extends PackageStateInternal> packages =
                packageSetting.getSharedUser().getPackageStates();
                mSettings.getSharedUserFromPackageName(packageName).getPackageStates();
        final int numPackages = packages.size();
        String[] res = new String[numPackages];
        int i = 0;
@@ -5627,4 +5653,16 @@ public class ComputerEngine implements Computer {
    private int getSupplementalProcessUid() {
        return getPackage(mService.getSupplementalProcessPackageName()).getUid();
    }

    @Nullable
    @Override
    public SharedUserApi getSharedUser(int sharedUserAppId) {
        return mSettings.getSharedUserFromAppId(sharedUserAppId);
    }

    @NonNull
    @Override
    public ArraySet<PackageStateInternal> getSharedUserPackages(int sharedUserAppId) {
        return mSettings.getSharedUserPackages(sharedUserAppId);
    }
}
+16 −0
Original line number Diff line number Diff line
@@ -852,4 +852,20 @@ public final class ComputerLocked extends ComputerEngine {
            return super.getPackageOrSharedUser(appId);
        }
    }

    @Nullable
    @Override
    public SharedUserApi getSharedUser(int sharedUserAppId) {
        synchronized (mLock) {
            return super.getSharedUser(sharedUserAppId);
        }
    }

    @NonNull
    @Override
    public ArraySet<PackageStateInternal> getSharedUserPackages(int sharedUserAppId) {
        synchronized (mLock) {
            return super.getSharedUserPackages(sharedUserAppId);
        }
    }
}
Loading