diff --git a/services/core/java/com/android/server/pm/ApexPackageInfo.java b/services/core/java/com/android/server/pm/ApexPackageInfo.java index f959a52f03749..1fd9f8e7ab971 100644 --- a/services/core/java/com/android/server/pm/ApexPackageInfo.java +++ b/services/core/java/com/android/server/pm/ApexPackageInfo.java @@ -22,10 +22,9 @@ import static com.android.server.pm.ApexManager.MATCH_FACTORY_PACKAGE; import android.annotation.NonNull; import android.annotation.Nullable; import android.apex.ApexInfo; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.util.ArrayMap; +import android.util.Pair; import android.util.PrintWriterPrinter; import com.android.internal.annotations.GuardedBy; @@ -33,8 +32,9 @@ import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.Preconditions; import com.android.server.pm.parsing.PackageParser2; import com.android.server.pm.parsing.pkg.AndroidPackage; +import com.android.server.pm.parsing.pkg.AndroidPackageUtils; import com.android.server.pm.parsing.pkg.ParsedPackage; -import com.android.server.pm.pkg.parsing.PackageInfoWithoutStateUtils; +import com.android.server.pm.pkg.PackageStateInternal; import com.android.server.pm.pkg.parsing.ParsingPackageUtils; import java.io.File; @@ -59,17 +59,7 @@ class ApexPackageInfo { private final Object mLock = new Object(); @GuardedBy("mLock") - private List mAllPackagesCache; - - /** - * Whether an APEX package is active or not. - * - * @param packageInfo the package to check - * @return {@code true} if this package is active, {@code false} otherwise. - */ - private static boolean isActive(PackageInfo packageInfo) { - return packageInfo.isActiveApex; - } + private List> mAllPackagesCache; /** * Called by package manager service to scan apex package files when device boots up. @@ -105,20 +95,23 @@ class ApexPackageInfo { * is not found. */ @Nullable - PackageInfo getPackageInfo(String packageName, @ApexManager.PackageInfoFlags int flags) { + Pair getPackageInfo(String packageName, + @ApexManager.PackageInfoFlags int flags) { synchronized (mLock) { Preconditions.checkState(mAllPackagesCache != null, "APEX packages have not been scanned"); boolean matchActive = (flags & MATCH_ACTIVE_PACKAGE) != 0; boolean matchFactory = (flags & MATCH_FACTORY_PACKAGE) != 0; for (int i = 0, size = mAllPackagesCache.size(); i < size; i++) { - final PackageInfo packageInfo = mAllPackagesCache.get(i); - if (!packageInfo.packageName.equals(packageName)) { + final Pair pair = mAllPackagesCache.get(i); + var apexInfo = pair.first; + var pkg = pair.second; + if (!pkg.getPackageName().equals(packageName)) { continue; } - if ((matchActive && isActive(packageInfo)) - || (matchFactory && isFactory(packageInfo))) { - return packageInfo; + if ((matchActive && apexInfo.isActive) + || (matchFactory && apexInfo.isFactory)) { + return pair; } } return null; @@ -128,18 +121,18 @@ class ApexPackageInfo { /** * Retrieves information about all active APEX packages. * - * @return a List of PackageInfo object, each one containing information about a different - * active package. + * @return list containing information about different active packages. */ - List getActivePackages() { + @NonNull + List> getActivePackages() { synchronized (mLock) { Preconditions.checkState(mAllPackagesCache != null, "APEX packages have not been scanned"); - final List activePackages = new ArrayList<>(); + final List> activePackages = new ArrayList<>(); for (int i = 0; i < mAllPackagesCache.size(); i++) { - final PackageInfo packageInfo = mAllPackagesCache.get(i); - if (isActive(packageInfo)) { - activePackages.add(packageInfo); + final var pair = mAllPackagesCache.get(i); + if (pair.first.isActive) { + activePackages.add(pair); } } return activePackages; @@ -147,20 +140,20 @@ class ApexPackageInfo { } /** - * Retrieves information about all active pre-installed APEX packages. + * Retrieves information about all pre-installed APEX packages. * - * @return a List of PackageInfo object, each one containing information about a different - * active pre-installed package. + * @return list containing information about different pre-installed packages. */ - List getFactoryPackages() { + @NonNull + List> getFactoryPackages() { synchronized (mLock) { Preconditions.checkState(mAllPackagesCache != null, "APEX packages have not been scanned"); - final List factoryPackages = new ArrayList<>(); + final List> factoryPackages = new ArrayList<>(); for (int i = 0; i < mAllPackagesCache.size(); i++) { - final PackageInfo packageInfo = mAllPackagesCache.get(i); - if (isFactory(packageInfo)) { - factoryPackages.add(packageInfo); + final var pair = mAllPackagesCache.get(i); + if (pair.first.isFactory) { + factoryPackages.add(pair); } } return factoryPackages; @@ -170,18 +163,18 @@ class ApexPackageInfo { /** * Retrieves information about all inactive APEX packages. * - * @return a List of PackageInfo object, each one containing information about a different - * inactive package. + * @return list containing information about different inactive packages. */ - List getInactivePackages() { + @NonNull + List> getInactivePackages() { synchronized (mLock) { Preconditions.checkState(mAllPackagesCache != null, "APEX packages have not been scanned"); - final List inactivePackages = new ArrayList<>(); + final List> inactivePackages = new ArrayList<>(); for (int i = 0; i < mAllPackagesCache.size(); i++) { - final PackageInfo packageInfo = mAllPackagesCache.get(i); - if (!isActive(packageInfo)) { - inactivePackages.add(packageInfo); + final var pair = mAllPackagesCache.get(i); + if (!pair.first.isActive) { + inactivePackages.add(pair); } } return inactivePackages; @@ -199,8 +192,8 @@ class ApexPackageInfo { Preconditions.checkState(mAllPackagesCache != null, "APEX packages have not been scanned"); for (int i = 0, size = mAllPackagesCache.size(); i < size; i++) { - final PackageInfo packageInfo = mAllPackagesCache.get(i); - if (packageInfo.packageName.equals(packageName)) { + final var pair = mAllPackagesCache.get(i); + if (pair.second.getPackageName().equals(packageName)) { return true; } } @@ -222,21 +215,18 @@ class ApexPackageInfo { } void notifyPackageInstalled(ApexInfo apexInfo, AndroidPackage pkg) { - final int flags = PackageManager.GET_META_DATA - | PackageManager.GET_SIGNING_CERTIFICATES - | PackageManager.GET_SIGNATURES; - final PackageInfo newApexPkg = PackageInfoWithoutStateUtils.generate( - pkg, apexInfo, flags); - final String packageName = newApexPkg.packageName; + final String packageName = pkg.getPackageName(); synchronized (mLock) { for (int i = 0, size = mAllPackagesCache.size(); i < size; i++) { - PackageInfo oldApexPkg = mAllPackagesCache.get(i); - if (oldApexPkg.isActiveApex && oldApexPkg.packageName.equals(packageName)) { - if (isFactory(oldApexPkg)) { - oldApexPkg.isActiveApex = false; - mAllPackagesCache.add(newApexPkg); + var pair = mAllPackagesCache.get(i); + var oldApexInfo = pair.first; + var oldApexPkg = pair.second; + if (oldApexInfo.isActive && oldApexPkg.getPackageName().equals(packageName)) { + if (oldApexInfo.isFactory) { + oldApexInfo.isActive = false; + mAllPackagesCache.add(Pair.create(apexInfo, pkg)); } else { - mAllPackagesCache.set(i, newApexPkg); + mAllPackagesCache.set(i, Pair.create(apexInfo, pkg)); } break; } @@ -244,16 +234,6 @@ class ApexPackageInfo { } } - /** - * Whether the APEX package is pre-installed or not. - * - * @param packageInfo the package to check - * @return {@code true} if this package is pre-installed, {@code false} otherwise. - */ - private static boolean isFactory(@NonNull PackageInfo packageInfo) { - return (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0; - } - /** * Dumps various state information to the provided {@link PrintWriter} object. * @@ -288,33 +268,25 @@ class ApexPackageInfo { HashSet factoryPackagesSet = new HashSet<>(); for (ApexManager.ScanResult result : scanResults) { ApexInfo ai = result.apexInfo; - - final PackageInfo packageInfo = PackageInfoWithoutStateUtils.generate( - result.pkg, ai, flags); - if (packageInfo == null) { - throw new IllegalStateException("Unable to generate package info: " - + ai.modulePath); - } - if (!packageInfo.packageName.equals(result.packageName)) { + String packageName = result.pkg.getPackageName(); + if (!packageName.equals(result.packageName)) { throw new IllegalStateException("Unmatched package name: " - + result.packageName + " != " + packageInfo.packageName + + result.packageName + " != " + packageName + ", path=" + ai.modulePath); } - mAllPackagesCache.add(packageInfo); + mAllPackagesCache.add(Pair.create(ai, result.pkg)); if (ai.isActive) { - if (!activePackagesSet.add(packageInfo.packageName)) { + if (!activePackagesSet.add(packageName)) { throw new IllegalStateException( - "Two active packages have the same name: " - + packageInfo.packageName); + "Two active packages have the same name: " + packageName); } } if (ai.isFactory) { // Don't throw when the duplicating APEX is VNDK APEX - if (!factoryPackagesSet.add(packageInfo.packageName) + if (!factoryPackagesSet.add(packageName) && !ai.moduleName.startsWith(VNDK_APEX_MODULE_NAME_PREFIX)) { throw new IllegalStateException( - "Two factory packages have the same name: " - + packageInfo.packageName); + "Two factory packages have the same name: " + packageName); } } } @@ -362,6 +334,37 @@ class ApexPackageInfo { return results; } + /** + * @see #dumpPackages(List, String, IndentingPrintWriter) + */ + static void dumpPackageStates(List packageStates, boolean isActive, + @Nullable String packageName, IndentingPrintWriter ipw) { + ipw.println(); + ipw.increaseIndent(); + for (int i = 0, size = packageStates.size(); i < size; i++) { + final var packageState = packageStates.get(i); + var pkg = packageState.getPkg(); + if (packageName != null && !packageName.equals(pkg.getPackageName())) { + continue; + } + ipw.println(pkg.getPackageName()); + ipw.increaseIndent(); + ipw.println("Version: " + pkg.getLongVersionCode()); + ipw.println("Path: " + pkg.getBaseApkPath()); + ipw.println("IsActive: " + isActive); + ipw.println("IsFactory: " + !packageState.isUpdatedSystemApp()); + ipw.println("ApplicationInfo: "); + ipw.increaseIndent(); + // TODO: Dump the package manually + AndroidPackageUtils.generateAppInfoWithoutState(pkg) + .dump(new PrintWriterPrinter(ipw), ""); + ipw.decreaseIndent(); + ipw.decreaseIndent(); + } + ipw.decreaseIndent(); + ipw.println(); + } + /** * Dump information about the packages contained in a particular cache * @param packagesCache the cache to print information about. @@ -369,24 +372,28 @@ class ApexPackageInfo { * only information about that specific package will be dumped. * @param ipw the {@link IndentingPrintWriter} object to send information to. */ - static void dumpPackages(List packagesCache, + static void dumpPackages(List> packagesCache, @Nullable String packageName, IndentingPrintWriter ipw) { ipw.println(); ipw.increaseIndent(); for (int i = 0, size = packagesCache.size(); i < size; i++) { - final PackageInfo pi = packagesCache.get(i); - if (packageName != null && !packageName.equals(pi.packageName)) { + final var pair = packagesCache.get(i); + var apexInfo = pair.first; + var pkg = pair.second; + if (packageName != null && !packageName.equals(pkg.getPackageName())) { continue; } - ipw.println(pi.packageName); + ipw.println(pkg.getPackageName()); ipw.increaseIndent(); - ipw.println("Version: " + pi.versionCode); - ipw.println("Path: " + pi.applicationInfo.sourceDir); - ipw.println("IsActive: " + isActive(pi)); - ipw.println("IsFactory: " + isFactory(pi)); + ipw.println("Version: " + pkg.getLongVersionCode()); + ipw.println("Path: " + pkg.getBaseApkPath()); + ipw.println("IsActive: " + apexInfo.isActive); + ipw.println("IsFactory: " + apexInfo.isFactory); ipw.println("ApplicationInfo: "); ipw.increaseIndent(); - pi.applicationInfo.dump(new PrintWriterPrinter(ipw), ""); + // TODO: Dump the package manually + AndroidPackageUtils.generateAppInfoWithoutState(pkg) + .dump(new PrintWriterPrinter(ipw), ""); ipw.decreaseIndent(); ipw.decreaseIndent(); } diff --git a/services/core/java/com/android/server/pm/ComputerEngine.java b/services/core/java/com/android/server/pm/ComputerEngine.java index 63c25ea520f72..8ec3d2bc74cae 100644 --- a/services/core/java/com/android/server/pm/ComputerEngine.java +++ b/services/core/java/com/android/server/pm/ComputerEngine.java @@ -65,6 +65,7 @@ import android.Manifest; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; +import android.apex.ApexInfo; import android.app.ActivityManager; import android.content.ComponentName; import android.content.Context; @@ -1018,11 +1019,12 @@ public class ComputerEngine implements Computer { if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) { apexFlags = ApexManager.MATCH_FACTORY_PACKAGE; } - final PackageInfo pi = mApexPackageInfo.getPackageInfo(packageName, apexFlags); - if (pi == null) { + final var pair = mApexPackageInfo.getPackageInfo(packageName, apexFlags); + if (pair == null) { return null; } - return pi.applicationInfo; + return PackageInfoUtils.generateApplicationInfo(pair.second, flags, + PackageUserStateInternal.DEFAULT, userId, null); } } if ("android".equals(packageName) || "system".equals(packageName)) { @@ -1718,8 +1720,12 @@ public class ComputerEngine implements Computer { // Instant app filtering for APEX modules is ignored if (!ApexPackageInfo.ENABLE_FEATURE_SCAN_APEX) { if (matchApex) { - return mApexPackageInfo.getPackageInfo(packageName, + final var pair = mApexPackageInfo.getPackageInfo(packageName, ApexManager.MATCH_FACTORY_PACKAGE); + if (pair == null) { + return null; + } + return PackageInfoUtils.generate(pair.second, pair.first, flags, null, userId); } } final PackageStateInternal ps = mSettings.getDisabledSystemPkg(packageName); @@ -1775,8 +1781,12 @@ public class ComputerEngine implements Computer { } if (!ApexPackageInfo.ENABLE_FEATURE_SCAN_APEX) { if (matchApex) { - return mApexPackageInfo.getPackageInfo(packageName, + final var pair = mApexPackageInfo.getPackageInfo(packageName, ApexManager.MATCH_ACTIVE_PACKAGE); + if (pair == null) { + return null; + } + return PackageInfoUtils.generate(pair.second, pair.first, flags, null, userId); } } return null; @@ -1883,10 +1893,17 @@ public class ComputerEngine implements Computer { } if (!ApexPackageInfo.ENABLE_FEATURE_SCAN_APEX) { if (listApex) { + List> pairs; if (listFactory) { - list.addAll(mApexPackageInfo.getFactoryPackages()); + pairs = mApexPackageInfo.getFactoryPackages(); } else { - list.addAll(mApexPackageInfo.getActivePackages()); + pairs = mApexPackageInfo.getActivePackages(); + } + + for (int index = 0; index < pairs.size(); index++) { + var pair = pairs.get(index); + list.add(PackageInfoUtils.generate(pair.second, pair.first, flags, null, + userId)); } } } @@ -3404,29 +3421,23 @@ public class ComputerEngine implements Computer { } // switch } - private void generateApexPackageInfo(List activePackages, - List inactivePackages, List factoryPackages) { + private void generateApexPackageInfo(@NonNull List activePackages, + @NonNull List inactivePackages, + @NonNull List factoryActivePackages, + @NonNull List factoryInactivePackages) { for (AndroidPackage p : mPackages.values()) { final String packageName = p.getPackageName(); PackageStateInternal ps = mSettings.getPackage(packageName); if (!p.isApex() || ps == null) { continue; } - PackageInfo pi = generatePackageInfo(ps, 0, 0); - if (pi == null) { - continue; - } - pi.isActiveApex = true; - activePackages.add(pi); + activePackages.add(ps); if (!ps.isUpdatedSystemApp()) { - factoryPackages.add(pi); + factoryActivePackages.add(ps); } else { PackageStateInternal psDisabled = mSettings.getDisabledSystemPkg(packageName); - pi = generatePackageInfo(psDisabled, 0, 0); - if (pi != null) { - factoryPackages.add(pi); - inactivePackages.add(pi); - } + factoryInactivePackages.add(psDisabled); + inactivePackages.add(psDisabled); } } } @@ -3434,16 +3445,19 @@ public class ComputerEngine implements Computer { private void dumpApex(PrintWriter pw, String packageName) { if (ApexPackageInfo.ENABLE_FEATURE_SCAN_APEX) { final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ", 120); - List activePackages = new ArrayList<>(); - List inactivePackages = new ArrayList<>(); - List factoryPackages = new ArrayList<>(); - generateApexPackageInfo(activePackages, inactivePackages, factoryPackages); + List activePackages = new ArrayList<>(); + List inactivePackages = new ArrayList<>(); + List factoryActivePackages = new ArrayList<>(); + List factoryInactivePackages = new ArrayList<>(); + generateApexPackageInfo(activePackages, inactivePackages, factoryActivePackages, + factoryInactivePackages); ipw.println("Active APEX packages:"); - ApexPackageInfo.dumpPackages(activePackages, packageName, ipw); + ApexPackageInfo.dumpPackageStates(activePackages, true, packageName, ipw); ipw.println("Inactive APEX packages:"); - ApexPackageInfo.dumpPackages(inactivePackages, packageName, ipw); + ApexPackageInfo.dumpPackageStates(inactivePackages, false, packageName, ipw); ipw.println("Factory APEX packages:"); - ApexPackageInfo.dumpPackages(factoryPackages, packageName, ipw); + ApexPackageInfo.dumpPackageStates(factoryActivePackages, true, packageName, ipw); + ApexPackageInfo.dumpPackageStates(factoryInactivePackages, false, packageName, ipw); } else { mApexPackageInfo.dump(pw, packageName); } diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 2bdf62bdd707f..32b3e6a4ab766 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -1611,7 +1611,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService mSharedLibraries = injector.getSharedLibrariesImpl(); mApexManager = testParams.apexManager; - mApexPackageInfo = new ApexPackageInfo(); + mApexPackageInfo = new ApexPackageInfo(this); mArtManagerService = testParams.artManagerService; mAvailableFeatures = testParams.availableFeatures; mBackgroundDexOptService = testParams.backgroundDexOptService; @@ -1811,7 +1811,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService mProtectedPackages = new ProtectedPackages(mContext); mApexManager = injector.getApexManager(); - mApexPackageInfo = new ApexPackageInfo(); + mApexPackageInfo = new ApexPackageInfo(this); mAppsFilter = mInjector.getAppsFilter(); mInstantAppRegistry = new InstantAppRegistry(mContext, mPermissionManager, diff --git a/services/core/java/com/android/server/pm/ScanPackageUtils.java b/services/core/java/com/android/server/pm/ScanPackageUtils.java index 0e57c917a72b7..86affdd754817 100644 --- a/services/core/java/com/android/server/pm/ScanPackageUtils.java +++ b/services/core/java/com/android/server/pm/ScanPackageUtils.java @@ -823,8 +823,8 @@ final class ScanPackageUtils { * ideally be static, but, it requires locks to read system state. */ public static void applyPolicy(ParsedPackage parsedPackage, - final @PackageManagerService.ScanFlags int scanFlags, AndroidPackage platformPkg, - boolean isUpdatedSystemApp) { + final @PackageManagerService.ScanFlags int scanFlags, + @Nullable AndroidPackage platformPkg, boolean isUpdatedSystemApp) { if ((scanFlags & SCAN_AS_SYSTEM) != 0) { parsedPackage.setSystem(true); // TODO(b/135203078): Can this be done in PackageParser? Or just inferred when the flag diff --git a/services/core/java/com/android/server/pm/parsing/PackageInfoUtils.java b/services/core/java/com/android/server/pm/parsing/PackageInfoUtils.java index 9c620c4ff3ab1..a44def8f772a1 100644 --- a/services/core/java/com/android/server/pm/parsing/PackageInfoUtils.java +++ b/services/core/java/com/android/server/pm/parsing/PackageInfoUtils.java @@ -93,12 +93,14 @@ public class PackageInfoUtils { /** * @param pkgSetting See {@link PackageInfoUtils} for description of pkgSetting usage. + * @deprecated Once ENABLE_FEATURE_SCAN_APEX is removed, this should also be removed. */ + @Deprecated @Nullable - public static PackageInfo generate(AndroidPackage pkg, ApexInfo apexInfo, int flags, - @Nullable PackageStateInternal pkgSetting) { + public static PackageInfo generate(AndroidPackage pkg, ApexInfo apexInfo, long flags, + @Nullable PackageStateInternal pkgSetting, @UserIdInt int userId) { return generateWithComponents(pkg, EmptyArray.INT, flags, 0, 0, Collections.emptySet(), - PackageUserStateInternal.DEFAULT, UserHandle.getCallingUserId(), apexInfo, pkgSetting); + PackageUserStateInternal.DEFAULT, userId, apexInfo, pkgSetting); } /** diff --git a/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java b/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java index b91f15a4d037b..748d32894d8a4 100644 --- a/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java +++ b/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java @@ -22,7 +22,6 @@ import android.annotation.Nullable; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; -import com.android.server.pm.pkg.SELinuxUtil; import android.content.pm.SigningDetails; import android.content.res.TypedArray; import android.os.Environment; @@ -35,6 +34,7 @@ import com.android.internal.util.CollectionUtils; import com.android.internal.util.DataClass; import com.android.internal.util.Parcelling.BuiltIn.ForInternedString; import com.android.server.pm.parsing.PackageInfoUtils; +import com.android.server.pm.pkg.SELinuxUtil; import com.android.server.pm.pkg.component.ComponentMutateUtils; import com.android.server.pm.pkg.component.ParsedActivity; import com.android.server.pm.pkg.component.ParsedProvider; @@ -255,7 +255,7 @@ public class PackageImpl extends ParsingPackageImpl implements ParsedPackage, An } @Override - public PackageImpl setSigningDetails(@Nullable SigningDetails value) { + public PackageImpl setSigningDetails(@NonNull SigningDetails value) { super.setSigningDetails(value); return this; } diff --git a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackage.java b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackage.java index 40f859c5e82e6..b7b37b2630f72 100644 --- a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackage.java +++ b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackage.java @@ -334,7 +334,7 @@ public interface ParsingPackage extends ParsingPackageRead { ParsingPackage setSharedUserLabel(int sharedUserLabel); - ParsingPackage setSigningDetails(SigningDetails signingDetails); + ParsingPackage setSigningDetails(@NonNull SigningDetails signingDetails); ParsingPackage setSplitClassLoaderName(int splitIndex, String classLoaderName); diff --git a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageImpl.java b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageImpl.java index 6a4513d45d8f1..803780fe2a9b8 100644 --- a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageImpl.java +++ b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageImpl.java @@ -317,8 +317,8 @@ public class ParsingPackageImpl implements ParsingPackage, ParsingPackageHidden, @Nullable @DataClass.ParcelWith(ForInternedString.class) protected String volumeUuid; - @Nullable - private SigningDetails signingDetails; + @NonNull + private SigningDetails signingDetails = SigningDetails.UNKNOWN; @NonNull @DataClass.ParcelWith(ForInternedString.class) @@ -1873,7 +1873,7 @@ public class ParsingPackageImpl implements ParsingPackage, ParsingPackageHidden, return volumeUuid; } - @Nullable + @NonNull @Override public SigningDetails getSigningDetails() { return signingDetails; @@ -2474,7 +2474,7 @@ public class ParsingPackageImpl implements ParsingPackage, ParsingPackageHidden, } @Override - public ParsingPackageImpl setSigningDetails(@Nullable SigningDetails value) { + public ParsingPackageImpl setSigningDetails(@NonNull SigningDetails value) { signingDetails = value; return this; } diff --git a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageRead.java b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageRead.java index 20b1ed8d0c3e7..22729993af64e 100644 --- a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageRead.java +++ b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageRead.java @@ -188,6 +188,7 @@ public interface ParsingPackageRead extends PkgWithoutStateAppInfo, PkgWithoutSt * The signature data of all APKs in this package, which must be exactly the same across the * base and splits. */ + @NonNull SigningDetails getSigningDetails(); /** diff --git a/services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java b/services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java index 20482afd53ac7..503ca69a627f4 100644 --- a/services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java @@ -36,8 +36,6 @@ import android.apex.ApexSessionInfo; import android.apex.ApexSessionParams; import android.apex.IApexService; import android.content.Context; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageInfo; import android.os.Environment; import android.os.RemoteException; import android.os.ServiceSpecificException; @@ -93,16 +91,16 @@ public class ApexManagerTest { ApexPackageInfo apexPackageInfo = new ApexPackageInfo(); apexPackageInfo.scanApexPackages( apexInfo, mPackageParser2, ParallelPackageParser.makeExecutorService()); - final PackageInfo activePkgPi = apexPackageInfo.getPackageInfo(TEST_APEX_PKG, + final var activePair = apexPackageInfo.getPackageInfo(TEST_APEX_PKG, ApexManager.MATCH_ACTIVE_PACKAGE); - assertThat(activePkgPi).isNotNull(); - assertThat(activePkgPi.packageName).contains(TEST_APEX_PKG); + assertThat(activePair).isNotNull(); + assertThat(activePair.second.getPackageName()).contains(TEST_APEX_PKG); - final PackageInfo factoryPkgPi = apexPackageInfo.getPackageInfo(TEST_APEX_PKG, + final var factoryPair = apexPackageInfo.getPackageInfo(TEST_APEX_PKG, ApexManager.MATCH_FACTORY_PACKAGE); - assertThat(factoryPkgPi).isNull(); + assertThat(factoryPair).isNull(); } @Test @@ -111,16 +109,16 @@ public class ApexManagerTest { ApexPackageInfo apexPackageInfo = new ApexPackageInfo(); apexPackageInfo.scanApexPackages( apexInfo, mPackageParser2, ParallelPackageParser.makeExecutorService()); - PackageInfo factoryPkgPi = apexPackageInfo.getPackageInfo(TEST_APEX_PKG, + var factoryPair = apexPackageInfo.getPackageInfo(TEST_APEX_PKG, ApexManager.MATCH_FACTORY_PACKAGE); - assertThat(factoryPkgPi).isNotNull(); - assertThat(factoryPkgPi.packageName).contains(TEST_APEX_PKG); + assertThat(factoryPair).isNotNull(); + assertThat(factoryPair.second.getPackageName()).contains(TEST_APEX_PKG); - final PackageInfo activePkgPi = apexPackageInfo.getPackageInfo(TEST_APEX_PKG, + final var activePair = apexPackageInfo.getPackageInfo(TEST_APEX_PKG, ApexManager.MATCH_ACTIVE_PACKAGE); - assertThat(activePkgPi).isNull(); + assertThat(activePair).isNull(); } @Test @@ -388,23 +386,16 @@ public class ApexManagerTest { newApexInfo = mApexManager.installPackage(installedApex); apexPackageInfo.notifyPackageInstalled(newApexInfo, mPackageParser2); - PackageInfo newInfo = apexPackageInfo.getPackageInfo("test.apex.rebootless", + var newInfo = apexPackageInfo.getPackageInfo("test.apex.rebootless", ApexManager.MATCH_ACTIVE_PACKAGE); - assertThat(newInfo.applicationInfo.sourceDir).isEqualTo(finalApex.getAbsolutePath()); - assertThat(newInfo.applicationInfo.longVersionCode).isEqualTo(2); - assertThat(newInfo.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) - .isEqualTo(ApplicationInfo.FLAG_UPDATED_SYSTEM_APP); - assertThat(newInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) - .isEqualTo(ApplicationInfo.FLAG_INSTALLED); + assertThat(newInfo.second.getBaseApkPath()).isEqualTo(finalApex.getAbsolutePath()); + assertThat(newInfo.second.getLongVersionCode()).isEqualTo(2); - PackageInfo factoryInfo = apexPackageInfo.getPackageInfo("test.apex.rebootless", + var factoryInfo = apexPackageInfo.getPackageInfo("test.apex.rebootless", ApexManager.MATCH_FACTORY_PACKAGE); - assertThat(factoryInfo.applicationInfo.sourceDir).isEqualTo(activeApexInfo.modulePath); - assertThat(factoryInfo.applicationInfo.longVersionCode).isEqualTo(1); - assertThat(factoryInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) - .isEqualTo(ApplicationInfo.FLAG_SYSTEM); - assertThat(factoryInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) - .isEqualTo(ApplicationInfo.FLAG_INSTALLED); + assertThat(factoryInfo.second.getBaseApkPath()).isEqualTo(activeApexInfo.modulePath); + assertThat(factoryInfo.second.getLongVersionCode()).isEqualTo(1); + assertThat(factoryInfo.second.isSystem()).isTrue(); } @Test @@ -429,23 +420,16 @@ public class ApexManagerTest { newApexInfo = mApexManager.installPackage(installedApex); apexPackageInfo.notifyPackageInstalled(newApexInfo, mPackageParser2); - PackageInfo newInfo = apexPackageInfo.getPackageInfo("test.apex.rebootless", + var newInfo = apexPackageInfo.getPackageInfo("test.apex.rebootless", ApexManager.MATCH_ACTIVE_PACKAGE); - assertThat(newInfo.applicationInfo.sourceDir).isEqualTo(finalApex.getAbsolutePath()); - assertThat(newInfo.applicationInfo.longVersionCode).isEqualTo(2); - assertThat(newInfo.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) - .isEqualTo(ApplicationInfo.FLAG_UPDATED_SYSTEM_APP); - assertThat(newInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) - .isEqualTo(ApplicationInfo.FLAG_INSTALLED); + assertThat(newInfo.second.getBaseApkPath()).isEqualTo(finalApex.getAbsolutePath()); + assertThat(newInfo.second.getLongVersionCode()).isEqualTo(2); - PackageInfo factoryInfo = apexPackageInfo.getPackageInfo("test.apex.rebootless", + var factoryInfo = apexPackageInfo.getPackageInfo("test.apex.rebootless", ApexManager.MATCH_FACTORY_PACKAGE); - assertThat(factoryInfo.applicationInfo.sourceDir).isEqualTo(factoryApexInfo.modulePath); - assertThat(factoryInfo.applicationInfo.longVersionCode).isEqualTo(1); - assertThat(factoryInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) - .isEqualTo(ApplicationInfo.FLAG_SYSTEM); - assertThat(factoryInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) - .isEqualTo(ApplicationInfo.FLAG_INSTALLED); + assertThat(factoryInfo.second.getBaseApkPath()).isEqualTo(factoryApexInfo.modulePath); + assertThat(factoryInfo.second.getLongVersionCode()).isEqualTo(1); + assertThat(factoryInfo.second.isSystem()).isTrue(); } @Test