• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.content.pm.VersionedPackage;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 import java.util.List;
26 
27 /**
28  * Information about a set of packages that can be, or already have been
29  * rolled back together.
30  *
31  * @hide
32  */
33 @SystemApi
34 public final class RollbackInfo implements Parcelable {
35 
36     /**
37      * A unique identifier for the rollback.
38      */
39     private final int mRollbackId;
40 
41     private final List<PackageRollbackInfo> mPackages;
42 
43     private final List<VersionedPackage> mCausePackages;
44 
45     private final boolean mIsStaged;
46     private int mCommittedSessionId;
47 
48     /** @hide */
RollbackInfo(int rollbackId, List<PackageRollbackInfo> packages, boolean isStaged, List<VersionedPackage> causePackages, int committedSessionId)49     public RollbackInfo(int rollbackId, List<PackageRollbackInfo> packages, boolean isStaged,
50             List<VersionedPackage> causePackages,  int committedSessionId) {
51         this.mRollbackId = rollbackId;
52         this.mPackages = packages;
53         this.mIsStaged = isStaged;
54         this.mCausePackages = causePackages;
55         this.mCommittedSessionId = committedSessionId;
56     }
57 
RollbackInfo(Parcel in)58     private RollbackInfo(Parcel in) {
59         mRollbackId = in.readInt();
60         mPackages = in.createTypedArrayList(PackageRollbackInfo.CREATOR);
61         mIsStaged = in.readBoolean();
62         mCausePackages = in.createTypedArrayList(VersionedPackage.CREATOR);
63         mCommittedSessionId = in.readInt();
64     }
65 
66     /**
67      * Returns a unique identifier for this rollback.
68      */
getRollbackId()69     public int getRollbackId() {
70         return mRollbackId;
71     }
72 
73     /**
74      * Returns the list of package that are rolled back.
75      */
76     @NonNull
getPackages()77     public List<PackageRollbackInfo> getPackages() {
78         return mPackages;
79     }
80 
81     /**
82      * Returns true if this rollback requires reboot to take effect after
83      * being committed.
84      */
isStaged()85     public boolean isStaged() {
86         return mIsStaged;
87     }
88 
89     /**
90      * Returns the session ID for the committed rollback for staged rollbacks.
91      * Only applicable for rollbacks that have been committed.
92      */
getCommittedSessionId()93     public int getCommittedSessionId() {
94         return mCommittedSessionId;
95     }
96 
97     /**
98      * Sets the session ID for the committed rollback for staged rollbacks.
99      * @hide
100      */
setCommittedSessionId(int sessionId)101     public void setCommittedSessionId(int sessionId) {
102         mCommittedSessionId = sessionId;
103     }
104 
105     /**
106      * Gets the list of package versions that motivated this rollback.
107      * As provided to {@link #commitRollback} when the rollback was committed.
108      * This is only applicable for rollbacks that have been committed.
109      */
110     @NonNull
getCausePackages()111     public List<VersionedPackage> getCausePackages() {
112         return mCausePackages;
113     }
114 
115     @Override
describeContents()116     public int describeContents() {
117         return 0;
118     }
119 
120     @Override
writeToParcel(Parcel out, int flags)121     public void writeToParcel(Parcel out, int flags) {
122         out.writeInt(mRollbackId);
123         out.writeTypedList(mPackages);
124         out.writeBoolean(mIsStaged);
125         out.writeTypedList(mCausePackages);
126         out.writeInt(mCommittedSessionId);
127     }
128 
129     public static final @android.annotation.NonNull Parcelable.Creator<RollbackInfo> CREATOR =
130             new Parcelable.Creator<RollbackInfo>() {
131         public RollbackInfo createFromParcel(Parcel in) {
132             return new RollbackInfo(in);
133         }
134 
135         public RollbackInfo[] newArray(int size) {
136             return new RollbackInfo[size];
137         }
138     };
139 }
140