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

Commit 41e8bdc8 authored by Ethan Chen's avatar Ethan Chen
Browse files

PackageManager: Add configuration to specify vendor platform signatures

Devices with split system/vendor images may want to use the OEM's vendor
image. In that case, the OEM's platform signature is not actually the
same as the platform signature used to sign the Lineage system image.
Allow devices to specify an OEM platform signature which will also be
recognized as the system's platform signature.

Change-Id: Ida9bb25a32234af9d9507a214eae6a4672320d2b
parent 9f1085a4
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -1416,6 +1416,8 @@ public class PackageManagerService extends IPackageManager.Stub
    private final PackageUsage mPackageUsage = new PackageUsage();
    private final CompilerStats mCompilerStats = new CompilerStats();
    private final Signature[] mVendorPlatformSignatures;
    class PackageHandler extends Handler {
        private boolean mBound = false;
        final ArrayList<HandlerParams> mPendingInstalls =
@@ -2421,6 +2423,14 @@ public class PackageManagerService extends IPackageManager.Stub
        }
    }
    private static Signature[] createSignatures(String[] hexBytes) {
        Signature[] sigs = new Signature[hexBytes.length];
        for (int i = 0; i < sigs.length; i++) {
            sigs[i] = new Signature(hexBytes[i]);
        }
        return sigs;
    }
    public PackageManagerService(Context context, Installer installer,
            boolean factoryTest, boolean onlyCore) {
        LockGuard.installLock(mPackages, LockGuard.INDEX_PACKAGES);
@@ -2437,6 +2447,9 @@ public class PackageManagerService extends IPackageManager.Stub
        mPermissionReviewRequired = context.getResources().getBoolean(
                R.bool.config_permissionReviewRequired);
        mVendorPlatformSignatures = createSignatures(context.getResources().getStringArray(
                    org.lineageos.platform.internal.R.array.config_vendorPlatformSignatures));
        mFactoryTest = factoryTest;
        mOnlyCore = onlyCore;
        mMetrics = new DisplayMetrics();
@@ -9242,6 +9255,13 @@ public class PackageManagerService extends IPackageManager.Stub
        try {
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "collectCertificates");
            PackageParser.collectCertificates(pkg, policyFlags);
            if (compareSignatures(pkg.mSignatures,
                  mVendorPlatformSignatures) == PackageManager.SIGNATURE_MATCH) {
                // Overwrite package signature with our platform signature
                // if the signature is the vendor's platform signature
                pkg.mSignatures = mPlatformPackage.mSignatures;
                SELinuxMMAC.assignSeInfoValue(pkg);
            }
        } catch (PackageParserException e) {
            throw PackageManagerException.from(e);
        } finally {
@@ -13367,6 +13387,8 @@ public class PackageManagerService extends IPackageManager.Stub
                bp.packageSetting.signatures.mSignatures, pkg.mSignatures)
                        == PackageManager.SIGNATURE_MATCH)
                || (compareSignatures(mPlatformPackage.mSignatures, pkg.mSignatures)
                        == PackageManager.SIGNATURE_MATCH)
                || (compareSignatures(mVendorPlatformSignatures, pkg.mSignatures)
                        == PackageManager.SIGNATURE_MATCH);
        if (!allowed && privilegedPermission) {
            if (isSystemApp(pkg)) {