Debian Codegraph @

core/java/android/content/rollback/PackageRollbackInfo.java

raw symbols SCIP
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.PackageManager;
22 import android.content.pm.VersionedPackage;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25
26 import java.util.ArrayList;
27 import java.util.List;
28
29 /**
30 * Information about a rollback available for a particular package.
31 *
32 * @hide
33 */
34 @SystemApi
35 public final class PackageRollbackInfo implements Parcelable {
36
37 private final VersionedPackage mVersionRolledBackFrom;
38 private final VersionedPackage mVersionRolledBackTo;
39
40 /**
41 * Encapsulates information required to restore a snapshot of an app's userdata.
42 *
43 * @hide
44 */
45 public static class RestoreInfo {
46 public final int userId;
47 public final int appId;
48 public final String seInfo;
49
50 public RestoreInfo(int userId, int appId, String seInfo) {
51 this.userId = userId;
52 this.appId = appId;
53 this.seInfo = seInfo;
54 }
55 }
56
57 /*
58 * The list of users for which we need to backup userdata for this package. Backups of
59 * credential encrypted data are listed as pending if the user hasn't unlocked their device
60 * with credentials yet.
61 */
62 // NOTE: Not a part of the Parcelable representation of this object.
63 private final List<Integer> mPendingBackups;
64
65 /**
66 * The list of users for which we need to restore userdata for this package. This field is
67 * non-null only after a rollback for this package has been committed.
68 */
69 // NOTE: Not a part of the Parcelable representation of this object.
70 private final ArrayList<RestoreInfo> mPendingRestores;
71
72 /**
73 * Whether this instance represents the PackageRollbackInfo for an APEX module.
74 */
75 private final boolean mIsApex;
76
77 /**
78 * Whether this instance represents the PackageRollbackInfo for an APK in APEX.
79 */
80 private final boolean mIsApkInApex;
81
82 /*
83 * The list of users for which snapshots have been saved.
84 */
85 // NOTE: Not a part of the Parcelable representation of this object.
86 private final List<Integer> mSnapshottedUsers;
87
88 /**
89 * The userdata policy to execute when a rollback for this package is committed.
90 */
91 private final int mRollbackDataPolicy;
92
93 /**
94 * Returns the name of the package to roll back from.
95 */
96 @NonNull
97 public String getPackageName() {
98 return mVersionRolledBackFrom.getPackageName();
99 }
100
101 /**
102 * Returns the version of the package rolled back from.
103 */
104 @NonNull
105 public VersionedPackage getVersionRolledBackFrom() {
106 return mVersionRolledBackFrom;
107 }
108
109 /**
110 * Returns the version of the package rolled back to.
111 */
112 @NonNull
113 public VersionedPackage getVersionRolledBackTo() {
114 return mVersionRolledBackTo;
115 }
116
117 /** @hide */
118 public void addPendingBackup(int userId) {
119 mPendingBackups.add(userId);
120 }
121
122 /** @hide */
123 public List<Integer> getPendingBackups() {
124 return mPendingBackups;
125 }
126
127 /** @hide */
128 public ArrayList<RestoreInfo> getPendingRestores() {
129 return mPendingRestores;
130 }
131
132 /** @hide */
133 public RestoreInfo getRestoreInfo(int userId) {
134 for (RestoreInfo ri : mPendingRestores) {
135 if (ri.userId == userId) {
136 return ri;
137 }
138 }
139
140 return null;
141 }
142
143 /** @hide */
144 public void removeRestoreInfo(RestoreInfo ri) {
145 mPendingRestores.remove(ri);
146 }
147
148 /** @hide */
149 public boolean isApex() {
150 return mIsApex;
151 }
152
153 /** @hide */
154 public @PackageManager.RollbackDataPolicy int getRollbackDataPolicy() {
155 return mRollbackDataPolicy;
156 }
157 /** @hide */
158 public boolean isApkInApex() {
159 return mIsApkInApex;
160 }
161
162 /** @hide */
163 public List<Integer> getSnapshottedUsers() {
164 return mSnapshottedUsers;
165 }
166
167 /** @hide */
168 public void removePendingBackup(int userId) {
169 mPendingBackups.remove((Integer) userId);
170 }
171
172 /** @hide */
173 public void removePendingRestoreInfo(int userId) {
174 removeRestoreInfo(getRestoreInfo(userId));
175 }
176
177 /** @hide */
178 public PackageRollbackInfo(VersionedPackage packageRolledBackFrom,
179 VersionedPackage packageRolledBackTo,
180 @NonNull List<Integer> pendingBackups, @NonNull ArrayList<RestoreInfo> pendingRestores,
181 boolean isApex, boolean isApkInApex, @NonNull List<Integer> snapshottedUsers) {
182 this(packageRolledBackFrom, packageRolledBackTo, pendingBackups, pendingRestores, isApex,
183 isApkInApex, snapshottedUsers, PackageManager.ROLLBACK_DATA_POLICY_RESTORE);
184 }
185
186 /** @hide */
187 public PackageRollbackInfo(VersionedPackage packageRolledBackFrom,
188 VersionedPackage packageRolledBackTo,
189 @NonNull List<Integer> pendingBackups, @NonNull ArrayList<RestoreInfo> pendingRestores,
190 boolean isApex, boolean isApkInApex, @NonNull List<Integer> snapshottedUsers,
191 @PackageManager.RollbackDataPolicy int rollbackDataPolicy) {
192 this.mVersionRolledBackFrom = packageRolledBackFrom;
193 this.mVersionRolledBackTo = packageRolledBackTo;
194 this.mPendingBackups = pendingBackups;
195 this.mPendingRestores = pendingRestores;
196 this.mIsApex = isApex;
197 this.mRollbackDataPolicy = rollbackDataPolicy;
198 this.mIsApkInApex = isApkInApex;
199 this.mSnapshottedUsers = snapshottedUsers;
200 }
201
202 private PackageRollbackInfo(Parcel in) {
203 this.mVersionRolledBackFrom = VersionedPackage.CREATOR.createFromParcel(in);
204 this.mVersionRolledBackTo = VersionedPackage.CREATOR.createFromParcel(in);
205 this.mIsApex = in.readBoolean();
206 this.mIsApkInApex = in.readBoolean();
207 this.mPendingRestores = null;
208 this.mPendingBackups = null;
209 this.mSnapshottedUsers = null;
210 this.mRollbackDataPolicy = PackageManager.ROLLBACK_DATA_POLICY_RESTORE;
211 }
212
213 @Override
214 public int describeContents() {
215 return 0;
216 }
217
218 @Override
219 public void writeToParcel(Parcel out, int flags) {
220 mVersionRolledBackFrom.writeToParcel(out, flags);
221 mVersionRolledBackTo.writeToParcel(out, flags);
222 out.writeBoolean(mIsApex);
223 out.writeBoolean(mIsApkInApex);
224 }
225
226 public static final @NonNull Parcelable.Creator<PackageRollbackInfo> CREATOR =
227 new Parcelable.Creator<PackageRollbackInfo>() {
228 public PackageRollbackInfo createFromParcel(Parcel in) {
229 return new PackageRollbackInfo(in);
230 }
231
232 public PackageRollbackInfo[] newArray(int size) {
233 return new PackageRollbackInfo[size];
234 }
235 };
236 }