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

Commit c9f170ca authored by Harshit Mahajan's avatar Harshit Mahajan Committed by Android (Google) Code Review
Browse files

Merge "Use public API to determine apk-in-apex" into main

parents 7b945eda 377e629c
Loading
Loading
Loading
Loading
+36 −12
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.rollback;

import static android.content.pm.Flags.provideInfoOfApkInApex;

import android.annotation.AnyThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -23,6 +25,7 @@ import android.annotation.WorkerThread;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.VersionedPackage;
import android.content.rollback.PackageRollbackInfo;
@@ -486,21 +489,42 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve
     */
    @AnyThread
    private boolean isModule(String packageName) {
        // Check if the package is an APK inside an APEX. If it is, use the parent APEX package when
        // querying PackageManager.
        PackageManager pm = mContext.getPackageManager();

        if (Flags.refactorCrashrecovery() && provideInfoOfApkInApex()) {
            // Check if the package is listed among the system modules.
            boolean isApex = false;
            try {
                isApex = (pm.getModuleInfo(packageName, 0 /* flags */) != null);
            } catch (PackageManager.NameNotFoundException e) {
                //pass
            }

            // Check if the package is an APK inside an APEX.
            boolean isApkInApex = false;
            try {
                final PackageInfo pkg = pm.getPackageInfo(packageName, 0 /* flags */);
                isApkInApex = (pkg.getApexPackageName() != null);
            } catch (PackageManager.NameNotFoundException e) {
                // pass
            }
            return isApex || isApkInApex;
        } else {
            // Check if the package is an APK inside an APEX. If it is, use the parent APEX package
            // when querying PackageManager.
            String apexPackageName = mApexManager.getActiveApexPackageNameContainingPackage(
                    packageName);
            if (apexPackageName != null) {
                packageName = apexPackageName;
            }

        PackageManager pm = mContext.getPackageManager();
            try {
                return pm.getModuleInfo(packageName, 0) != null;
            } catch (PackageManager.NameNotFoundException ignore) {
                return false;
            }
        }
    }

    /**
     * Rolls back the session that owns {@code failedPackage}