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

Commit 9409f7fc authored by Shawn Willden's avatar Shawn Willden
Browse files

Add getPackageInfo to IPackageManagerNative

The new native OMAPI service (replacing the existing Java APK-based
implementation of OMAPI, mostly because OMAPI is needed during early
boot and the Java OMAPI cannot start early) needs to retrieve package
information from PackageManager.  It doesn't need to get the package
info during early boot, only later when Android apps begin using it.

This is not flag-protected because AIDL does not support flagging and
the implementation must be included with the AIDL method definition.

Bug: 380331467
Test: atest CtsPackageManagerTests
Flag: EXEMPT HAL interface change
Change-Id: If754dcd3ac5725eedc9469bd1793a8dab1ef7963
parent 4cabd1d8
Loading
Loading
Loading
Loading
+53 −0
Original line number Diff line number Diff line
@@ -24,6 +24,11 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManagerNative;
import android.content.pm.IStagedApexObserver;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInfoNative;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.content.pm.SignatureNative;
import android.content.pm.SigningInfoNative;
import android.content.pm.StagedApexInfo;
import android.os.Binder;
import android.os.RemoteException;
@@ -67,6 +72,54 @@ final class PackageManagerNative extends IPackageManagerNative.Stub {
        }
    }

    @Override
    public PackageInfoNative getPackageInfoWithSigningInfo(String packageName, int userId) {
        PackageInfo pInfo = mPm.snapshotComputer().getPackageInfo(packageName,
                PackageManager.GET_SIGNING_CERTIFICATES, userId);
        if (pInfo == null)  {
            return null;
        }

        PackageInfoNative result = new PackageInfoNative();
        result.packageName = packageName;
        if (pInfo.signingInfo == null) {
            return result;
        }
        result.signingInfo = new SigningInfoNative();

        Signature[] signatures = pInfo.signingInfo.hasMultipleSigners()
                ? pInfo.signingInfo.getApkContentsSigners()
                : pInfo.signingInfo.getSigningCertificateHistory();
        if (signatures == null) {
            return result;
        }

        SignatureNative[] apkContentSigners = new SignatureNative[signatures.length];
        for (int i = 0; i < signatures.length; i++) {
            SignatureNative sig = new SignatureNative();
            sig.signature = signatures[i].toByteArray();
            apkContentSigners[i] = sig;
        }
        result.signingInfo.apkContentSigners = apkContentSigners;

        return result;
    }

    @Override
    public PackageInfoNative[] getPackageInfoWithSigningInfoForUid(int uid) throws RemoteException {
        String[] packageNames = mPm.snapshotComputer().getPackagesForUid(uid);
        if (packageNames == null) {
            return null;
        }

        int userId = UserHandle.getUserId(uid);
        PackageInfoNative[] result = new PackageInfoNative[packageNames.length];
        for (int i = 0; i < packageNames.length; i++) {
            result[i] = getPackageInfoWithSigningInfo(packageNames[i], userId);
        }
        return result;
    }

    @Override
    public int getPackageUid(String packageName, long flags, int userId) throws RemoteException {
        return mPm.snapshotComputer().getPackageUid(packageName, flags, userId);