blob: c0414fcdf5c5568a13100be843aa8385d2c6b079 [file] [log] [blame]
Richard Uhlerb29f1452018-09-12 16:38:15 +01001/*
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
17package android.content.rollback;
18
Narayan Kamathc034fe92019-01-23 10:48:17 +000019import android.annotation.NonNull;
Richard Uhlerc739c8c2018-12-12 11:03:34 +000020import android.annotation.SystemApi;
Richard Uhlera7e9b2d2019-01-22 17:20:58 +000021import android.content.pm.VersionedPackage;
Richard Uhlerb29f1452018-09-12 16:38:15 +010022import android.os.Parcel;
23import android.os.Parcelable;
Narayan Kamathc034fe92019-01-23 10:48:17 +000024import android.util.IntArray;
Nikita Ioffe952aa7b2019-01-28 19:49:56 +000025import android.util.SparseLongArray;
Narayan Kamathc034fe92019-01-23 10:48:17 +000026
27import java.util.ArrayList;
Richard Uhlerb29f1452018-09-12 16:38:15 +010028
Richard Uhlerb29f1452018-09-12 16:38:15 +010029/**
30 * Information about a rollback available for a particular package.
31 *
Richard Uhlerc739c8c2018-12-12 11:03:34 +000032 * @hide
Richard Uhlerb29f1452018-09-12 16:38:15 +010033 */
Richard Uhlerc739c8c2018-12-12 11:03:34 +000034@SystemApi
Richard Uhlerb29f1452018-09-12 16:38:15 +010035public final class PackageRollbackInfo implements Parcelable {
Richard Uhlera7e9b2d2019-01-22 17:20:58 +000036
37 private final VersionedPackage mVersionRolledBackFrom;
38 private final VersionedPackage mVersionRolledBackTo;
Richard Uhlerb29f1452018-09-12 16:38:15 +010039
40 /**
Narayan Kamathc034fe92019-01-23 10:48:17 +000041 * 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 IntArray 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 /**
Narayan Kamathfcd4a042019-02-01 14:16:37 +000073 * Whether this instance represents the PackageRollbackInfo for an APEX module.
74 */
75 private final boolean mIsApex;
76
Nikita Ioffe952aa7b2019-01-28 19:49:56 +000077 /*
78 * The list of users the package is installed for.
79 */
80 // NOTE: Not a part of the Parcelable representation of this object.
81 private final IntArray mInstalledUsers;
82
83 /**
84 * A mapping between user and an inode of theirs CE data snapshot.
85 */
86 // NOTE: Not a part of the Parcelable representation of this object.
87 private final SparseLongArray mCeSnapshotInodes;
88
Narayan Kamathfcd4a042019-02-01 14:16:37 +000089 /**
Richard Uhlera7e9b2d2019-01-22 17:20:58 +000090 * Returns the name of the package to roll back from.
Richard Uhlerb29f1452018-09-12 16:38:15 +010091 */
shafikfee3acf2019-03-08 15:44:26 +000092 @NonNull
Richard Uhlera7e9b2d2019-01-22 17:20:58 +000093 public String getPackageName() {
94 return mVersionRolledBackFrom.getPackageName();
Richard Uhlerb29f1452018-09-12 16:38:15 +010095 }
96
Richard Uhlera7e9b2d2019-01-22 17:20:58 +000097 /**
98 * Returns the version of the package rolled back from.
99 */
shafikfee3acf2019-03-08 15:44:26 +0000100 @NonNull
Richard Uhlera7e9b2d2019-01-22 17:20:58 +0000101 public VersionedPackage getVersionRolledBackFrom() {
102 return mVersionRolledBackFrom;
103 }
104
105 /**
106 * Returns the version of the package rolled back to.
107 */
shafikfee3acf2019-03-08 15:44:26 +0000108 @NonNull
Richard Uhlera7e9b2d2019-01-22 17:20:58 +0000109 public VersionedPackage getVersionRolledBackTo() {
110 return mVersionRolledBackTo;
111 }
112
113 /** @hide */
Nikita Ioffe5dcd17972019-02-04 11:08:13 +0000114 public void addPendingBackup(int userId) {
115 mPendingBackups.add(userId);
116 }
117
118 /** @hide */
Narayan Kamathc034fe92019-01-23 10:48:17 +0000119 public IntArray getPendingBackups() {
120 return mPendingBackups;
121 }
122
123 /** @hide */
124 public ArrayList<RestoreInfo> getPendingRestores() {
125 return mPendingRestores;
126 }
127
128 /** @hide */
129 public RestoreInfo getRestoreInfo(int userId) {
130 for (RestoreInfo ri : mPendingRestores) {
131 if (ri.userId == userId) {
132 return ri;
133 }
134 }
135
136 return null;
137 }
138
139 /** @hide */
140 public void removeRestoreInfo(RestoreInfo ri) {
141 mPendingRestores.remove(ri);
142 }
143
144 /** @hide */
Narayan Kamathfcd4a042019-02-01 14:16:37 +0000145 public boolean isApex() {
146 return mIsApex;
147 }
148
149 /** @hide */
Nikita Ioffe952aa7b2019-01-28 19:49:56 +0000150 public IntArray getInstalledUsers() {
151 return mInstalledUsers;
152 }
153
154 /** @hide */
155 public SparseLongArray getCeSnapshotInodes() {
156 return mCeSnapshotInodes;
157 }
158
159 /** @hide */
160 public void putCeSnapshotInode(int userId, long ceSnapshotInode) {
161 mCeSnapshotInodes.put(userId, ceSnapshotInode);
162 }
163
164 /** @hide */
Nikita Ioffe5dcd17972019-02-04 11:08:13 +0000165 public void removePendingBackup(int userId) {
166 int idx = mPendingBackups.indexOf(userId);
167 if (idx != -1) {
168 mPendingBackups.remove(idx);
169 }
170 }
171
172 /** @hide */
173 public void removePendingRestoreInfo(int userId) {
174 removeRestoreInfo(getRestoreInfo(userId));
175 }
176
177 /** @hide */
Richard Uhlera7e9b2d2019-01-22 17:20:58 +0000178 public PackageRollbackInfo(VersionedPackage packageRolledBackFrom,
Narayan Kamathc034fe92019-01-23 10:48:17 +0000179 VersionedPackage packageRolledBackTo,
Narayan Kamathfcd4a042019-02-01 14:16:37 +0000180 @NonNull IntArray pendingBackups, @NonNull ArrayList<RestoreInfo> pendingRestores,
Nikita Ioffe952aa7b2019-01-28 19:49:56 +0000181 boolean isApex, @NonNull IntArray installedUsers,
182 @NonNull SparseLongArray ceSnapshotInodes) {
Richard Uhlera7e9b2d2019-01-22 17:20:58 +0000183 this.mVersionRolledBackFrom = packageRolledBackFrom;
184 this.mVersionRolledBackTo = packageRolledBackTo;
Narayan Kamathc034fe92019-01-23 10:48:17 +0000185 this.mPendingBackups = pendingBackups;
186 this.mPendingRestores = pendingRestores;
Narayan Kamathfcd4a042019-02-01 14:16:37 +0000187 this.mIsApex = isApex;
Nikita Ioffe952aa7b2019-01-28 19:49:56 +0000188 this.mInstalledUsers = installedUsers;
189 this.mCeSnapshotInodes = ceSnapshotInodes;
Richard Uhlerb29f1452018-09-12 16:38:15 +0100190 }
191
192 private PackageRollbackInfo(Parcel in) {
Richard Uhlera7e9b2d2019-01-22 17:20:58 +0000193 this.mVersionRolledBackFrom = VersionedPackage.CREATOR.createFromParcel(in);
194 this.mVersionRolledBackTo = VersionedPackage.CREATOR.createFromParcel(in);
Narayan Kamathfcd4a042019-02-01 14:16:37 +0000195 this.mIsApex = in.readBoolean();
Narayan Kamathc034fe92019-01-23 10:48:17 +0000196 this.mPendingRestores = null;
197 this.mPendingBackups = null;
Nikita Ioffe952aa7b2019-01-28 19:49:56 +0000198 this.mInstalledUsers = null;
199 this.mCeSnapshotInodes = null;
Richard Uhlerb29f1452018-09-12 16:38:15 +0100200 }
201
202 @Override
203 public int describeContents() {
204 return 0;
205 }
206
207 @Override
208 public void writeToParcel(Parcel out, int flags) {
Richard Uhlera7e9b2d2019-01-22 17:20:58 +0000209 mVersionRolledBackFrom.writeToParcel(out, flags);
210 mVersionRolledBackTo.writeToParcel(out, flags);
Narayan Kamathfcd4a042019-02-01 14:16:37 +0000211 out.writeBoolean(mIsApex);
Richard Uhlerb29f1452018-09-12 16:38:15 +0100212 }
213
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700214 public static final @android.annotation.NonNull Parcelable.Creator<PackageRollbackInfo> CREATOR =
Richard Uhlerb29f1452018-09-12 16:38:15 +0100215 new Parcelable.Creator<PackageRollbackInfo>() {
216 public PackageRollbackInfo createFromParcel(Parcel in) {
217 return new PackageRollbackInfo(in);
218 }
219
220 public PackageRollbackInfo[] newArray(int size) {
221 return new PackageRollbackInfo[size];
222 }
223 };
224}