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

Commit 39a6a5bf authored by Nikita Ioffe's avatar Nikita Ioffe
Browse files

Abort apex session if APK part of a train failed

Since in this case apex session can only be in state ACTIVATED, aborting
it will result in a apexd rolling back /data/apex/active to the previous
state. Unlike native-watchdog scenario, apexd won't reboot device, so
it is StagingManagers responsibility to issue a reboot.

Bug: 123622800
Test: install-multi-package apk + apex, apex got rolled back after reboot
Change-Id: I16dfa5a99fc8251ee335df9edfcad36c88785257
parent 4fecb6af
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -204,7 +204,8 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
        mSessionsDir.mkdirs();

        mApexManager = am;
        mStagingManager = new StagingManager(pm, this, am);

        mStagingManager = new StagingManager(pm, this, am, context);
    }

    boolean okToSendBroadcasts()  {
+19 −1
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Slog;
@@ -68,15 +69,18 @@ public class StagingManager {
    private final PackageInstallerService mPi;
    private final PackageManagerService mPm;
    private final ApexManager mApexManager;
    private final PowerManager mPowerManager;
    private final Handler mBgHandler;

    @GuardedBy("mStagedSessions")
    private final SparseArray<PackageInstallerSession> mStagedSessions = new SparseArray<>();

    StagingManager(PackageManagerService pm, PackageInstallerService pi, ApexManager am) {
    StagingManager(PackageManagerService pm, PackageInstallerService pi, ApexManager am,
            Context context) {
        mPm = pm;
        mPi = pi;
        mApexManager = am;
        mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        mBgHandler = BackgroundThread.getHandler();
    }

@@ -286,6 +290,20 @@ public class StagingManager {
            session.setStagedSessionFailed(SessionInfo.STAGED_SESSION_ACTIVATION_FAILED,
                    "Staged installation of APKs failed. Check logcat messages for"
                        + "more information.");

            if (!hasApex) {
                return;
            }

            if (!mApexManager.abortActiveSession()) {
                Slog.e(TAG, "Failed to abort APEXd session");
            } else {
                Slog.e(TAG,
                        "Successfully aborted apexd session. Rebooting device in order to revert "
                                + "to the previous state of APEXd.");
                mPowerManager.reboot(null);
            }

            return;
        }