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

Commit 529f3d2f authored by Nikita Ioffe's avatar Nikita Ioffe Committed by Bill Lin
Browse files

Populate error message if apexd verification fails

Test: atest CtsStagedInstallHostTestCases
Test: adb install --wait system/apex/shim/com.android.apex.cts.shim.v2_wrong_sha.apex
Bug: 136548037
Bug: 122952270

Change-Id: I5ceb6a6c37d1222358de9c6f3261da64f8010658
Merged-In: I5ea596ea6417825845c16bbb6e26e9c13845139b
(cherry picked from commit 4e7d24a7)
parent ca8f1c06
Loading
Loading
Loading
Loading
+17 −13
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
import android.os.RemoteException;
@@ -147,14 +148,10 @@ abstract class ApexManager {
     * @param childSessionIds if {@code sessionId} is a multi-package session, this should contain
     *                        an array of identifiers of all the child sessions. Otherwise it should
     *                        be an empty array.
     * @param apexInfoList this is an output parameter, which needs to be initialized by tha caller
     *                     and will be filled with a list of {@link ApexInfo} objects, each of which
     *                     contains metadata about one of the packages being submitted as part of
     *                     the session.
     * @return whether the submission of the session was successful.
     * @throws PackageManagerException if call to apexd fails
     */
    abstract boolean submitStagedSession(
            int sessionId, @NonNull int[] childSessionIds, @NonNull ApexInfoList apexInfoList);
    abstract ApexInfoList submitStagedSession(int sessionId, @NonNull int[] childSessionIds)
            throws PackageManagerException;

    /**
     * Mark a staged session previously submitted using {@code submitStagedSession} as ready to be
@@ -388,13 +385,19 @@ abstract class ApexManager {
        }

        @Override
        boolean submitStagedSession(
                int sessionId, @NonNull int[] childSessionIds, @NonNull ApexInfoList apexInfoList) {
        ApexInfoList submitStagedSession(int sessionId, @NonNull int[] childSessionIds)
                throws PackageManagerException {
            try {
                return mApexService.submitStagedSession(sessionId, childSessionIds, apexInfoList);
                final ApexInfoList apexInfoList = new ApexInfoList();
                mApexService.submitStagedSession(sessionId, childSessionIds, apexInfoList);
                return apexInfoList;
            } catch (RemoteException re) {
                Slog.e(TAG, "Unable to contact apexservice", re);
                throw new RuntimeException(re);
            } catch (Exception e) {
                throw new PackageManagerException(
                        PackageInstaller.SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
                        "apexd verification failed : " + e.getMessage());
            }
        }

@@ -566,9 +569,10 @@ abstract class ApexManager {
        }

        @Override
        boolean submitStagedSession(int sessionId, int[] childSessionIds,
                ApexInfoList apexInfoList) {
            throw new UnsupportedOperationException();
        ApexInfoList submitStagedSession(int sessionId, int[] childSessionIds)
                throws PackageManagerException {
            throw new PackageManagerException(PackageManager.INSTALL_FAILED_INTERNAL_ERROR,
                    "Device doesn't support updating APEX");
        }

        @Override
+4 −7
Original line number Diff line number Diff line
@@ -155,13 +155,10 @@ public class StagingManager {
                }
            }
        }
        final ApexInfoList apexInfoList = new ApexInfoList();
        boolean submittedToApexd = mApexManager.submitStagedSession(session.sessionId,
                childSessionsIds.toArray(), apexInfoList);
        if (!submittedToApexd) {
            throw new PackageManagerException(SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
                    "APEX staging failed, check logcat messages from apexd for more details.");
        }
        // submitStagedSession will throw a PackageManagerException if apexd verification fails,
        // which will be propagated to populate stagedSessionErrorMessage of this session.
        final ApexInfoList apexInfoList = mApexManager.submitStagedSession(session.sessionId,
                childSessionsIds.toArray());
        final List<PackageInfo> result = new ArrayList<>();
        for (ApexInfo newPackage : apexInfoList.apexInfos) {
            final PackageInfo pkg;