1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.content.rollback; 18 19 import android.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.annotation.TestApi; 22 import android.content.pm.VersionedPackage; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 26 import java.util.List; 27 28 /** 29 * Information about a set of packages that can be, or already have been 30 * rolled back together. 31 * 32 * @hide 33 */ 34 @SystemApi @TestApi 35 public final class RollbackInfo implements Parcelable { 36 37 /** 38 * A unique identifier for the rollback. 39 */ 40 private final int mRollbackId; 41 42 private final List<PackageRollbackInfo> mPackages; 43 44 private final List<VersionedPackage> mCausePackages; 45 46 private final boolean mIsStaged; 47 private int mCommittedSessionId; 48 49 /** @hide */ RollbackInfo(int rollbackId, List<PackageRollbackInfo> packages, boolean isStaged, List<VersionedPackage> causePackages, int committedSessionId)50 public RollbackInfo(int rollbackId, List<PackageRollbackInfo> packages, boolean isStaged, 51 List<VersionedPackage> causePackages, int committedSessionId) { 52 this.mRollbackId = rollbackId; 53 this.mPackages = packages; 54 this.mIsStaged = isStaged; 55 this.mCausePackages = causePackages; 56 this.mCommittedSessionId = committedSessionId; 57 } 58 RollbackInfo(Parcel in)59 private RollbackInfo(Parcel in) { 60 mRollbackId = in.readInt(); 61 mPackages = in.createTypedArrayList(PackageRollbackInfo.CREATOR); 62 mIsStaged = in.readBoolean(); 63 mCausePackages = in.createTypedArrayList(VersionedPackage.CREATOR); 64 mCommittedSessionId = in.readInt(); 65 } 66 67 /** 68 * Returns a unique identifier for this rollback. 69 */ getRollbackId()70 public int getRollbackId() { 71 return mRollbackId; 72 } 73 74 /** 75 * Returns the list of package that are rolled back. 76 */ 77 @NonNull getPackages()78 public List<PackageRollbackInfo> getPackages() { 79 return mPackages; 80 } 81 82 /** 83 * Returns true if this rollback requires reboot to take effect after 84 * being committed. 85 */ isStaged()86 public boolean isStaged() { 87 return mIsStaged; 88 } 89 90 /** 91 * Returns the session ID for the committed rollback for staged rollbacks. 92 * Only applicable for rollbacks that have been committed. 93 */ getCommittedSessionId()94 public int getCommittedSessionId() { 95 return mCommittedSessionId; 96 } 97 98 /** 99 * Sets the session ID for the committed rollback for staged rollbacks. 100 * @hide 101 */ setCommittedSessionId(int sessionId)102 public void setCommittedSessionId(int sessionId) { 103 mCommittedSessionId = sessionId; 104 } 105 106 /** 107 * Gets the list of package versions that motivated this rollback. 108 * As provided to {@link #commitRollback} when the rollback was committed. 109 * This is only applicable for rollbacks that have been committed. 110 */ 111 @NonNull getCausePackages()112 public List<VersionedPackage> getCausePackages() { 113 return mCausePackages; 114 } 115 116 @Override describeContents()117 public int describeContents() { 118 return 0; 119 } 120 121 @Override writeToParcel(Parcel out, int flags)122 public void writeToParcel(Parcel out, int flags) { 123 out.writeInt(mRollbackId); 124 out.writeTypedList(mPackages); 125 out.writeBoolean(mIsStaged); 126 out.writeTypedList(mCausePackages); 127 out.writeInt(mCommittedSessionId); 128 } 129 130 public static final @android.annotation.NonNull Parcelable.Creator<RollbackInfo> CREATOR = 131 new Parcelable.Creator<RollbackInfo>() { 132 public RollbackInfo createFromParcel(Parcel in) { 133 return new RollbackInfo(in); 134 } 135 136 public RollbackInfo[] newArray(int size) { 137 return new RollbackInfo[size]; 138 } 139 }; 140 } 141