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

Commit ccf035d6 authored by Richard Uhler's avatar Richard Uhler
Browse files

Add mIsStaged and mCommittedSessionId to RollbackInfo.

These will be needed for the rollback manager to support rollback of
staged sessions.

Bug: 112431924
Test: atest RollbackTest

Change-Id: I22c02ba2de023af6cf6908207bf69ab36ca9291c
parent 92f6c4c5
Loading
Loading
Loading
Loading
+20 −6
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.pm.VersionedPackage;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.Collections;
import java.util.List;

/**
@@ -42,18 +43,31 @@ public final class RollbackInfo implements Parcelable {

    private final List<VersionedPackage> mCausePackages;

    private final boolean mIsStaged;
    private final int mCommittedSessionId;

    /** @hide */
    public RollbackInfo(int rollbackId, List<PackageRollbackInfo> packages, boolean isStaged) {
        this(rollbackId, packages, isStaged, Collections.emptyList(),
                PackageInstaller.SessionInfo.INVALID_ID);
    }

    /** @hide */
    public RollbackInfo(int rollbackId, List<PackageRollbackInfo> packages,
            List<VersionedPackage> causePackages) {
    public RollbackInfo(int rollbackId, List<PackageRollbackInfo> packages, boolean isStaged,
            List<VersionedPackage> causePackages,  int committedSessionId) {
        this.mRollbackId = rollbackId;
        this.mPackages = packages;
        this.mIsStaged = isStaged;
        this.mCausePackages = causePackages;
        this.mCommittedSessionId = committedSessionId;
    }

    private RollbackInfo(Parcel in) {
        mRollbackId = in.readInt();
        mPackages = in.createTypedArrayList(PackageRollbackInfo.CREATOR);
        mIsStaged = in.readBoolean();
        mCausePackages = in.createTypedArrayList(VersionedPackage.CREATOR);
        mCommittedSessionId = in.readInt();
    }

    /**
@@ -75,8 +89,7 @@ public final class RollbackInfo implements Parcelable {
     * being committed.
     */
    public boolean isStaged() {
        // TODO: Support rollback of staged installs.
        return false;
        return mIsStaged;
    }

    /**
@@ -84,8 +97,7 @@ public final class RollbackInfo implements Parcelable {
     * Only applicable for rollbacks that have been committed.
     */
    public int getCommittedSessionId() {
        // TODO: Support rollback of staged installs.
        return PackageInstaller.SessionInfo.INVALID_ID;
        return mCommittedSessionId;
    }

    /**
@@ -106,7 +118,9 @@ public final class RollbackInfo implements Parcelable {
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(mRollbackId);
        out.writeTypedList(mPackages);
        out.writeBoolean(mIsStaged);
        out.writeTypedList(mCausePackages);
        out.writeInt(mCommittedSessionId);
    }

    public static final Parcelable.Creator<RollbackInfo> CREATOR =
+7 −4
Original line number Diff line number Diff line
@@ -54,7 +54,6 @@ import java.security.SecureRandom;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -210,8 +209,9 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
            List<RollbackInfo> rollbacks = new ArrayList<>();
            for (int i = 0; i < mAvailableRollbacks.size(); ++i) {
                RollbackData data = mAvailableRollbacks.get(i);
                rollbacks.add(new RollbackInfo(data.rollbackId, data.packages,
                            Collections.emptyList()));
                // TODO: Pass the correct value for isStaged instead of
                // assuming always false.
                rollbacks.add(new RollbackInfo(data.rollbackId, data.packages, false));
            }
            return new ParceledListSlice<>(rollbacks);
        }
@@ -364,8 +364,11 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
                                return;
                            }

                            // TODO: Set the correct values for isStaged and
                            // committedSessionId.
                            addRecentlyExecutedRollback(new RollbackInfo(
                                        data.rollbackId, data.packages, causePackages));
                                        data.rollbackId, data.packages, false, causePackages,
                                        PackageInstaller.SessionInfo.INVALID_ID));
                            sendSuccess(statusReceiver);

                            Intent broadcast = new Intent(Intent.ACTION_ROLLBACK_COMMITTED);
+6 −1
Original line number Diff line number Diff line
@@ -178,9 +178,12 @@ class RollbackStore {
                    int rollbackId = element.getInt("rollbackId");
                    List<PackageRollbackInfo> packages = packageRollbackInfosFromJson(
                            element.getJSONArray("packages"));
                    boolean isStaged = element.getBoolean("isStaged");
                    List<VersionedPackage> causePackages = versionedPackagesFromJson(
                            element.getJSONArray("causePackages"));
                    RollbackInfo rollback = new RollbackInfo(rollbackId, packages, causePackages);
                    int committedSessionId = element.getInt("committedSessionId");
                    RollbackInfo rollback = new RollbackInfo(rollbackId, packages, isStaged,
                            causePackages, committedSessionId);
                    recentlyExecutedRollbacks.add(rollback);
                }
            } catch (IOException | JSONException e) {
@@ -270,7 +273,9 @@ class RollbackStore {
                JSONObject element = new JSONObject();
                element.put("rollbackId", rollback.getRollbackId());
                element.put("packages", toJson(rollback.getPackages()));
                element.put("isStaged", rollback.isStaged());
                element.put("causePackages", versionedPackagesToJson(rollback.getCausePackages()));
                element.put("committedSessionId", rollback.getCommittedSessionId());
                array.put(element);
            }