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

Commit 9a8727c1 authored by TYM Tsai's avatar TYM Tsai
Browse files

Ignore register existing app id for sdk library

addPackageLPw() should return a PackageSetting if the package is a sdk
library and the feature "Disallow sdk libraries to be apps" is enabled.

Bug: 328104784

Test: atest CtsSdkSandboxHostSideTests
Test: atest CtsPackageManagerTestCases
Test: atest FrameworksMockingServicesTests:com.android.server.pm
Change-Id: Ie42ecaa14488c03982c591585e5c07d3daf24ba8
parent 487d8fa9
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ import android.util.proto.ProtoOutputStream;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.BackgroundThread;
import com.android.internal.pm.parsing.pkg.AndroidPackageInternal;
import com.android.internal.pm.pkg.component.ParsedComponent;
import com.android.internal.pm.pkg.component.ParsedIntentInfo;
import com.android.internal.pm.pkg.component.ParsedPermission;
@@ -909,8 +910,10 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
            sharedUserSetting.mDisabledPackages.remove(p);
        }
        p.getPkgState().setUpdatedSystemApp(false);
        final AndroidPackageInternal pkg = p.getPkg();
        PackageSetting ret = addPackageLPw(name, p.getRealName(), p.getPath(), p.getAppId(),
                p.getFlags(), p.getPrivateFlags(), mDomainVerificationManager.generateNewId());
                p.getFlags(), p.getPrivateFlags(), mDomainVerificationManager.generateNewId(),
                pkg == null ? false : pkg.isSdkLibrary());
        if (ret != null) {
            ret.setLegacyNativeLibraryPath(p.getLegacyNativeLibraryPath());
            ret.setPrimaryCpuAbi(p.getPrimaryCpuAbiLegacy());
@@ -949,8 +952,8 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
        }
    }

    PackageSetting addPackageLPw(String name, String realName, File codePath, int uid, int pkgFlags,
                                 int pkgPrivateFlags, @NonNull UUID domainSetId) {
    PackageSetting addPackageLPw(String name, String realName, File codePath, int uid,
            int pkgFlags, int pkgPrivateFlags, @NonNull UUID domainSetId, boolean isSdkLibrary) {
        PackageSetting p = mPackages.get(name);
        if (p != null) {
            if (p.getAppId() == uid) {
@@ -962,7 +965,8 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
        }
        p = new PackageSetting(name, realName, codePath, pkgFlags, pkgPrivateFlags, domainSetId)
                .setAppId(uid);
        if (mAppIds.registerExistingAppId(uid, p, name)) {
        if ((uid == Process.INVALID_UID && isSdkLibrary && Flags.disallowSdkLibsToBeApps())
                || mAppIds.registerExistingAppId(uid, p, name)) {
            mPackages.put(name, p);
            return p;
        }
@@ -4157,7 +4161,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
            } else if (appId > 0 || (appId == Process.INVALID_UID && isSdkLibrary
                    && Flags.disallowSdkLibsToBeApps())) {
                packageSetting = addPackageLPw(name.intern(), realName, new File(codePathStr),
                        appId, pkgFlags, pkgPrivateFlags, domainSetId);
                        appId, pkgFlags, pkgPrivateFlags, domainSetId, isSdkLibrary);
                if (PackageManagerService.DEBUG_SETTINGS)
                    Log.i(PackageManagerService.TAG, "Reading package " + name + ": appId="
                            + appId + " pkg=" + packageSetting);
+1 −1
Original line number Diff line number Diff line
@@ -166,7 +166,7 @@ class MockSystem(withSession: (StaticMockitoSessionBuilder) -> Unit = {}) {
            null
        }
        whenever(mocks.settings.addPackageLPw(nullable(), nullable(), nullable(), nullable(),
                nullable(), nullable(), nullable())) {
                nullable(), nullable(), nullable(), nullable())) {
            val name: String = getArgument(0)
            val pendingAdd = mPendingPackageAdds.firstOrNull { it.first == name }
                    ?: return@whenever null