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

Commit 1d42c9ee authored by Mohammad Samiul Islam's avatar Mohammad Samiul Islam
Browse files

Remove unused code in StagingManager

Now that we don't create extra session during pre-reboot verification,
we don't need these codes.

Also, fixed up some warning that my IDE was showing.

Bug: 159336213
Test: builds
Change-Id: I54575422a3101fc514b26550393d12572c42948b
parent 5188d09a
Loading
Loading
Loading
Loading
+16 −83
Original line number Original line Diff line number Diff line
@@ -88,7 +88,6 @@ import java.util.List;
import java.util.Set;
import java.util.Set;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.Supplier;


@@ -189,7 +188,6 @@ public class StagingManager {
     * Validates the signature used to sign the container of the new apex package
     * Validates the signature used to sign the container of the new apex package
     *
     *
     * @param newApexPkg The new apex package that is being installed
     * @param newApexPkg The new apex package that is being installed
     * @throws PackageManagerException
     */
     */
    private void validateApexSignature(PackageInfo newApexPkg)
    private void validateApexSignature(PackageInfo newApexPkg)
            throws PackageManagerException {
            throws PackageManagerException {
@@ -725,12 +723,9 @@ public class StagingManager {
        return ret;
        return ret;
    }
    }


    @NonNull
    private PackageInstallerSession createAndWriteApkSession(
    private PackageInstallerSession createAndWriteApkSession(
            @NonNull PackageInstallerSession originalSession, boolean preReboot)
            PackageInstallerSession originalSession) throws PackageManagerException {
            throws PackageManagerException {
        final int errorCode = SessionInfo.STAGED_SESSION_ACTIVATION_FAILED;
        final int errorCode = preReboot ? SessionInfo.STAGED_SESSION_VERIFICATION_FAILED
                : SessionInfo.STAGED_SESSION_ACTIVATION_FAILED;
        if (originalSession.stageDir == null) {
        if (originalSession.stageDir == null) {
            Slog.wtf(TAG, "Attempting to install a staged APK session with no staging dir");
            Slog.wtf(TAG, "Attempting to install a staged APK session with no staging dir");
            throw new PackageManagerException(errorCode,
            throw new PackageManagerException(errorCode,
@@ -746,12 +741,7 @@ public class StagingManager {
        PackageInstaller.SessionParams params = originalSession.params.copy();
        PackageInstaller.SessionParams params = originalSession.params.copy();
        params.isStaged = false;
        params.isStaged = false;
        params.installFlags |= PackageManager.INSTALL_STAGED;
        params.installFlags |= PackageManager.INSTALL_STAGED;
        if (preReboot) {
            params.installFlags &= ~PackageManager.INSTALL_ENABLE_ROLLBACK;
            params.installFlags |= PackageManager.INSTALL_DRY_RUN;
        } else {
        params.installFlags |= PackageManager.INSTALL_DISABLE_VERIFICATION;
        params.installFlags |= PackageManager.INSTALL_DISABLE_VERIFICATION;
        }
        try {
        try {
            int apkSessionId = mPi.createSession(
            int apkSessionId = mPi.createSession(
                    params, originalSession.getInstallerPackageName(),
                    params, originalSession.getInstallerPackageName(),
@@ -783,12 +773,10 @@ public class StagingManager {
     * apks in the given session. Only parent session is returned for multi-package session.
     * apks in the given session. Only parent session is returned for multi-package session.
     */
     */
    @Nullable
    @Nullable
    private PackageInstallerSession extractApksInSession(PackageInstallerSession session,
    private PackageInstallerSession extractApksInSession(PackageInstallerSession session)
            boolean preReboot) throws PackageManagerException {
            throws PackageManagerException {
        final int errorCode = preReboot ? SessionInfo.STAGED_SESSION_VERIFICATION_FAILED
                : SessionInfo.STAGED_SESSION_ACTIVATION_FAILED;
        if (!session.isMultiPackage() && !isApexSession(session)) {
        if (!session.isMultiPackage() && !isApexSession(session)) {
            return createAndWriteApkSession(session, preReboot);
            return createAndWriteApkSession(session);
        } else if (session.isMultiPackage()) {
        } else if (session.isMultiPackage()) {
            // For multi-package staged sessions containing APKs, we identify which child sessions
            // For multi-package staged sessions containing APKs, we identify which child sessions
            // contain an APK, and with those then create a new multi-package group of sessions,
            // contain an APK, and with those then create a new multi-package group of sessions,
@@ -810,10 +798,6 @@ public class StagingManager {
            }
            }
            final PackageInstaller.SessionParams params = session.params.copy();
            final PackageInstaller.SessionParams params = session.params.copy();
            params.isStaged = false;
            params.isStaged = false;
            if (preReboot) {
                params.installFlags &= ~PackageManager.INSTALL_ENABLE_ROLLBACK;
                params.installFlags |= PackageManager.INSTALL_DRY_RUN;
            }
            final int apkParentSessionId = mPi.createSession(
            final int apkParentSessionId = mPi.createSession(
                    params, session.getInstallerPackageName(), session.getInstallerAttributionTag(),
                    params, session.getInstallerPackageName(), session.getInstallerAttributionTag(),
                    session.userId);
                    session.userId);
@@ -823,18 +807,18 @@ public class StagingManager {
            } catch (IOException e) {
            } catch (IOException e) {
                Slog.e(TAG, "Unable to prepare multi-package session for staged session "
                Slog.e(TAG, "Unable to prepare multi-package session for staged session "
                        + session.sessionId);
                        + session.sessionId);
                throw new PackageManagerException(errorCode,
                throw new PackageManagerException(SessionInfo.STAGED_SESSION_ACTIVATION_FAILED,
                        "Unable to prepare multi-package session for staged session");
                        "Unable to prepare multi-package session for staged session");
            }
            }


            for (int i = 0, size = childSessions.size(); i < size; i++) {
            for (int i = 0, size = childSessions.size(); i < size; i++) {
                final PackageInstallerSession apkChildSession = createAndWriteApkSession(
                final PackageInstallerSession apkChildSession = createAndWriteApkSession(
                        childSessions.get(i), preReboot);
                        childSessions.get(i));
                try {
                try {
                    apkParentSession.addChildSessionId(apkChildSession.sessionId);
                    apkParentSession.addChildSessionId(apkChildSession.sessionId);
                } catch (IllegalStateException e) {
                } catch (IllegalStateException e) {
                    Slog.e(TAG, "Failed to add a child session for installing the APK files", e);
                    Slog.e(TAG, "Failed to add a child session for installing the APK files", e);
                    throw new PackageManagerException(errorCode,
                    throw new PackageManagerException(SessionInfo.STAGED_SESSION_ACTIVATION_FAILED,
                            "Failed to add a child session " + apkChildSession.sessionId);
                            "Failed to add a child session " + apkChildSession.sessionId);
                }
                }
            }
            }
@@ -877,11 +861,9 @@ public class StagingManager {
        }
        }
    }
    }


    private void installApksInSession(@NonNull PackageInstallerSession session)
    private void installApksInSession(PackageInstallerSession session)
            throws PackageManagerException {
            throws PackageManagerException {

        final PackageInstallerSession apksToInstall = extractApksInSession(session);
        final PackageInstallerSession apksToInstall = extractApksInSession(
                session, /* preReboot */ false);
        if (apksToInstall == null) {
        if (apksToInstall == null) {
            return;
            return;
        }
        }
@@ -1047,7 +1029,7 @@ public class StagingManager {
    /**
    /**
     * <p>Abort committed staged session
     * <p>Abort committed staged session
     *
     *
     * <p>This method must be called while holding {@link PackageInstallerSession.mLock}.
     * <p>This method must be called while holding {@link PackageInstallerSession#mLock}.
     *
     *
     * <p>The method returns {@code false} to indicate it is not safe to clean up the session from
     * <p>The method returns {@code false} to indicate it is not safe to clean up the session from
     * system yet. When it is safe, the method returns {@code true}.
     * system yet. When it is safe, the method returns {@code true}.
@@ -1218,7 +1200,7 @@ public class StagingManager {
        }
        }
    }
    }


    void markStagedSessionsAsSuccessful() {
    private void markStagedSessionsAsSuccessful() {
        synchronized (mSuccessfulStagedSessionIds) {
        synchronized (mSuccessfulStagedSessionIds) {
            for (int i = 0; i < mSuccessfulStagedSessionIds.size(); i++) {
            for (int i = 0; i < mSuccessfulStagedSessionIds.size(); i++) {
                mApexManager.markStagedSessionSuccessful(mSuccessfulStagedSessionIds.get(i));
                mApexManager.markStagedSessionSuccessful(mSuccessfulStagedSessionIds.get(i));
@@ -1242,30 +1224,10 @@ public class StagingManager {
        mFailureReasonFile.delete();
        mFailureReasonFile.delete();
    }
    }


    private static class LocalIntentReceiverAsync {
        final Consumer<Intent> mConsumer;

        LocalIntentReceiverAsync(Consumer<Intent> consumer) {
            mConsumer = consumer;
        }

        private IIntentSender.Stub mLocalSender = new IIntentSender.Stub() {
            @Override
            public void send(int code, Intent intent, String resolvedType, IBinder whitelistToken,
                    IIntentReceiver finishedReceiver, String requiredPermission, Bundle options) {
                mConsumer.accept(intent);
            }
        };

        public IntentSender getIntentSender() {
            return new IntentSender((IIntentSender) mLocalSender);
        }
    }

    private static class LocalIntentReceiverSync {
    private static class LocalIntentReceiverSync {
        private final LinkedBlockingQueue<Intent> mResult = new LinkedBlockingQueue<>();
        private final LinkedBlockingQueue<Intent> mResult = new LinkedBlockingQueue<>();


        private IIntentSender.Stub mLocalSender = new IIntentSender.Stub() {
        private final IIntentSender.Stub mLocalSender = new IIntentSender.Stub() {
            @Override
            @Override
            public void send(int code, Intent intent, String resolvedType, IBinder whitelistToken,
            public void send(int code, Intent intent, String resolvedType, IBinder whitelistToken,
                    IIntentReceiver finishedReceiver, String requiredPermission,
                    IIntentReceiver finishedReceiver, String requiredPermission,
@@ -1300,14 +1262,14 @@ public class StagingManager {
    }
    }


    // TODO(b/136257624): Temporary API to let PMS communicate with StagingManager. When all
    // TODO(b/136257624): Temporary API to let PMS communicate with StagingManager. When all
    //  verification logic is extraced out of StagingManager into PMS, we can remove
    //  verification logic is extracted out of StagingManager into PMS, we can remove
    //  this.
    //  this.
    void notifyVerificationComplete(int sessionId) {
    void notifyVerificationComplete(int sessionId) {
        mPreRebootVerificationHandler.onPreRebootVerificationComplete(sessionId);
        mPreRebootVerificationHandler.onPreRebootVerificationComplete(sessionId);
    }
    }


    // TODO(b/136257624): Temporary API to let PMS communicate with StagingManager. When all
    // TODO(b/136257624): Temporary API to let PMS communicate with StagingManager. When all
    //  verification logic is extraced out of StagingManager into PMS, we can remove
    //  verification logic is extracted out of StagingManager into PMS, we can remove
    //  this.
    //  this.
    void notifyPreRebootVerification_Apk_Complete(int sessionId) {
    void notifyPreRebootVerification_Apk_Complete(int sessionId) {
        mPreRebootVerificationHandler.notifyPreRebootVerification_Apk_Complete(sessionId);
        mPreRebootVerificationHandler.notifyPreRebootVerification_Apk_Complete(sessionId);
@@ -1526,35 +1488,6 @@ public class StagingManager {
            session.verifyStagedSession();
            session.verifyStagedSession();
        }
        }


        private void verifyApksInSession(PackageInstallerSession session)
                throws PackageManagerException {

            final PackageInstallerSession apksToVerify = extractApksInSession(
                    session,  /* preReboot */ true);
            if (apksToVerify == null) {
                return;
            }

            final LocalIntentReceiverAsync receiver = new LocalIntentReceiverAsync(
                    (Intent result) -> {
                        final int status = result.getIntExtra(PackageInstaller.EXTRA_STATUS,
                                PackageInstaller.STATUS_FAILURE);
                        if (status != PackageInstaller.STATUS_SUCCESS) {
                            final String errorMessage = result.getStringExtra(
                                    PackageInstaller.EXTRA_STATUS_MESSAGE);
                            Slog.e(TAG, "Failure to verify APK staged session "
                                    + session.sessionId + " [" + errorMessage + "]");
                            onPreRebootVerificationFailure(session,
                                    SessionInfo.STAGED_SESSION_ACTIVATION_FAILED, errorMessage);
                            return;
                        }
                        mPreRebootVerificationHandler.notifyPreRebootVerification_Apk_Complete(
                                session.sessionId);
                    });

            apksToVerify.commit(receiver.getIntentSender(), false);
        }

        /**
        /**
         * Pre-reboot verification state for wrapping up:
         * Pre-reboot verification state for wrapping up:
         * <p><ul>
         * <p><ul>