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.FlaggedApi; 20 import android.annotation.NonNull; 21 import android.annotation.SystemApi; 22 import android.annotation.TestApi; 23 import android.content.pm.Flags; 24 import android.content.pm.PackageManager; 25 import android.content.pm.VersionedPackage; 26 import android.os.Parcel; 27 import android.os.Parcelable; 28 29 import java.util.List; 30 31 /** 32 * Information about a set of packages that can be, or already have been rolled back together. 33 * 34 * @hide 35 */ 36 @SystemApi 37 public final class RollbackInfo implements Parcelable { 38 39 /** A unique identifier for the rollback. */ 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 private int mRollbackImpactLevel; 49 50 /** @hide */ RollbackInfo( int rollbackId, List<PackageRollbackInfo> packages, boolean isStaged, List<VersionedPackage> causePackages, int committedSessionId, @PackageManager.RollbackImpactLevel int rollbackImpactLevel)51 public RollbackInfo( 52 int rollbackId, 53 List<PackageRollbackInfo> packages, 54 boolean isStaged, 55 List<VersionedPackage> causePackages, 56 int committedSessionId, 57 @PackageManager.RollbackImpactLevel int rollbackImpactLevel) { 58 this.mRollbackId = rollbackId; 59 this.mPackages = packages; 60 this.mIsStaged = isStaged; 61 this.mCausePackages = causePackages; 62 this.mCommittedSessionId = committedSessionId; 63 this.mRollbackImpactLevel = rollbackImpactLevel; 64 } 65 66 /** @hide */ RollbackInfo( int rollbackId, List<PackageRollbackInfo> packages, boolean isStaged, List<VersionedPackage> causePackages, int committedSessionId)67 public RollbackInfo( 68 int rollbackId, 69 List<PackageRollbackInfo> packages, 70 boolean isStaged, 71 List<VersionedPackage> causePackages, 72 int committedSessionId) { 73 // If impact level is not set default to 0 74 this( 75 rollbackId, 76 packages, 77 isStaged, 78 causePackages, 79 committedSessionId, 80 PackageManager.ROLLBACK_USER_IMPACT_LOW); 81 } 82 RollbackInfo(Parcel in)83 private RollbackInfo(Parcel in) { 84 mRollbackId = in.readInt(); 85 mPackages = in.createTypedArrayList(PackageRollbackInfo.CREATOR); 86 mIsStaged = in.readBoolean(); 87 mCausePackages = in.createTypedArrayList(VersionedPackage.CREATOR); 88 mCommittedSessionId = in.readInt(); 89 mRollbackImpactLevel = in.readInt(); 90 } 91 92 /** Returns a unique identifier for this rollback. */ getRollbackId()93 public int getRollbackId() { 94 return mRollbackId; 95 } 96 97 /** Returns the list of package that are rolled back. */ 98 @NonNull getPackages()99 public List<PackageRollbackInfo> getPackages() { 100 return mPackages; 101 } 102 103 /** Returns true if this rollback requires reboot to take effect after being committed. */ isStaged()104 public boolean isStaged() { 105 return mIsStaged; 106 } 107 108 /** 109 * Returns the session ID for the committed rollback for staged rollbacks. Only applicable for 110 * rollbacks that have been committed. 111 */ getCommittedSessionId()112 public int getCommittedSessionId() { 113 return mCommittedSessionId; 114 } 115 116 /** 117 * Sets the session ID for the committed rollback for staged rollbacks. 118 * 119 * @hide 120 */ setCommittedSessionId(int sessionId)121 public void setCommittedSessionId(int sessionId) { 122 mCommittedSessionId = sessionId; 123 } 124 125 /** 126 * Gets the list of package versions that motivated this rollback. As provided to {@link 127 * #commitRollback} when the rollback was committed. This is only applicable for rollbacks that 128 * have been committed. 129 */ 130 @NonNull getCausePackages()131 public List<VersionedPackage> getCausePackages() { 132 return mCausePackages; 133 } 134 135 /** 136 * Get rollback impact level. Refer {@link 137 * android.content.pm.PackageInstaller.SessionParams#setRollbackImpactLevel(int)} for more info 138 * on impact level. 139 * 140 * @hide 141 */ 142 @TestApi 143 @FlaggedApi(Flags.FLAG_RECOVERABILITY_DETECTION) getRollbackImpactLevel()144 public @PackageManager.RollbackImpactLevel int getRollbackImpactLevel() { 145 return mRollbackImpactLevel; 146 } 147 148 /** 149 * Set rollback impact level. Refer {@link 150 * android.content.pm.PackageInstaller.SessionParams#setRollbackImpactLevel(int)} for more info 151 * on impact level. 152 * 153 * @hide 154 */ setRollbackImpactLevel( @ackageManager.RollbackImpactLevel int rollbackImpactLevel)155 public void setRollbackImpactLevel( 156 @PackageManager.RollbackImpactLevel int rollbackImpactLevel) { 157 mRollbackImpactLevel = rollbackImpactLevel; 158 } 159 160 @Override describeContents()161 public int describeContents() { 162 return 0; 163 } 164 165 @Override writeToParcel(Parcel out, int flags)166 public void writeToParcel(Parcel out, int flags) { 167 out.writeInt(mRollbackId); 168 out.writeTypedList(mPackages); 169 out.writeBoolean(mIsStaged); 170 out.writeTypedList(mCausePackages); 171 out.writeInt(mCommittedSessionId); 172 out.writeInt(mRollbackImpactLevel); 173 } 174 175 public static final @android.annotation.NonNull Parcelable.Creator<RollbackInfo> CREATOR = 176 new Parcelable.Creator<RollbackInfo>() { 177 public RollbackInfo createFromParcel(Parcel in) { 178 return new RollbackInfo(in); 179 } 180 181 public RollbackInfo[] newArray(int size) { 182 return new RollbackInfo[size]; 183 } 184 }; 185 } 186