Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 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 | |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Richard Uhler | c739c8c | 2018-12-12 11:03:34 +0000 | [diff] [blame] | 20 | import android.annotation.SystemApi; |
Richard Uhler | a7e9b2d | 2019-01-22 17:20:58 +0000 | [diff] [blame] | 21 | import android.content.pm.VersionedPackage; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 24 | import android.util.IntArray; |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 25 | import android.util.SparseLongArray; |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 26 | |
| 27 | import java.util.ArrayList; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 28 | |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 29 | /** |
| 30 | * Information about a rollback available for a particular package. |
| 31 | * |
Richard Uhler | c739c8c | 2018-12-12 11:03:34 +0000 | [diff] [blame] | 32 | * @hide |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 33 | */ |
Richard Uhler | c739c8c | 2018-12-12 11:03:34 +0000 | [diff] [blame] | 34 | @SystemApi |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 35 | public final class PackageRollbackInfo implements Parcelable { |
Richard Uhler | a7e9b2d | 2019-01-22 17:20:58 +0000 | [diff] [blame] | 36 | |
| 37 | private final VersionedPackage mVersionRolledBackFrom; |
| 38 | private final VersionedPackage mVersionRolledBackTo; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 39 | |
| 40 | /** |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 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 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 Kamath | fcd4a04 | 2019-02-01 14:16:37 +0000 | [diff] [blame] | 73 | * Whether this instance represents the PackageRollbackInfo for an APEX module. |
| 74 | */ |
| 75 | private final boolean mIsApex; |
| 76 | |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 77 | /* |
| 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 Kamath | fcd4a04 | 2019-02-01 14:16:37 +0000 | [diff] [blame] | 89 | /** |
Richard Uhler | a7e9b2d | 2019-01-22 17:20:58 +0000 | [diff] [blame] | 90 | * Returns the name of the package to roll back from. |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 91 | */ |
Richard Uhler | a7e9b2d | 2019-01-22 17:20:58 +0000 | [diff] [blame] | 92 | public String getPackageName() { |
| 93 | return mVersionRolledBackFrom.getPackageName(); |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 94 | } |
| 95 | |
Richard Uhler | a7e9b2d | 2019-01-22 17:20:58 +0000 | [diff] [blame] | 96 | /** |
| 97 | * Returns the version of the package rolled back from. |
| 98 | */ |
| 99 | public VersionedPackage getVersionRolledBackFrom() { |
| 100 | return mVersionRolledBackFrom; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Returns the version of the package rolled back to. |
| 105 | */ |
| 106 | public VersionedPackage getVersionRolledBackTo() { |
| 107 | return mVersionRolledBackTo; |
| 108 | } |
| 109 | |
| 110 | /** @hide */ |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 111 | public void addPendingBackup(int userId) { |
| 112 | mPendingBackups.add(userId); |
| 113 | } |
| 114 | |
| 115 | /** @hide */ |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 116 | public IntArray getPendingBackups() { |
| 117 | return mPendingBackups; |
| 118 | } |
| 119 | |
| 120 | /** @hide */ |
| 121 | public ArrayList<RestoreInfo> getPendingRestores() { |
| 122 | return mPendingRestores; |
| 123 | } |
| 124 | |
| 125 | /** @hide */ |
| 126 | public RestoreInfo getRestoreInfo(int userId) { |
| 127 | for (RestoreInfo ri : mPendingRestores) { |
| 128 | if (ri.userId == userId) { |
| 129 | return ri; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | return null; |
| 134 | } |
| 135 | |
| 136 | /** @hide */ |
| 137 | public void removeRestoreInfo(RestoreInfo ri) { |
| 138 | mPendingRestores.remove(ri); |
| 139 | } |
| 140 | |
| 141 | /** @hide */ |
Narayan Kamath | fcd4a04 | 2019-02-01 14:16:37 +0000 | [diff] [blame] | 142 | public boolean isApex() { |
| 143 | return mIsApex; |
| 144 | } |
| 145 | |
| 146 | /** @hide */ |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 147 | public IntArray getInstalledUsers() { |
| 148 | return mInstalledUsers; |
| 149 | } |
| 150 | |
| 151 | /** @hide */ |
| 152 | public SparseLongArray getCeSnapshotInodes() { |
| 153 | return mCeSnapshotInodes; |
| 154 | } |
| 155 | |
| 156 | /** @hide */ |
| 157 | public void putCeSnapshotInode(int userId, long ceSnapshotInode) { |
| 158 | mCeSnapshotInodes.put(userId, ceSnapshotInode); |
| 159 | } |
| 160 | |
| 161 | /** @hide */ |
Nikita Ioffe | 5dcd1797 | 2019-02-04 11:08:13 +0000 | [diff] [blame] | 162 | public void removePendingBackup(int userId) { |
| 163 | int idx = mPendingBackups.indexOf(userId); |
| 164 | if (idx != -1) { |
| 165 | mPendingBackups.remove(idx); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /** @hide */ |
| 170 | public void removePendingRestoreInfo(int userId) { |
| 171 | removeRestoreInfo(getRestoreInfo(userId)); |
| 172 | } |
| 173 | |
| 174 | /** @hide */ |
Richard Uhler | a7e9b2d | 2019-01-22 17:20:58 +0000 | [diff] [blame] | 175 | public PackageRollbackInfo(VersionedPackage packageRolledBackFrom, |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 176 | VersionedPackage packageRolledBackTo, |
Narayan Kamath | fcd4a04 | 2019-02-01 14:16:37 +0000 | [diff] [blame] | 177 | @NonNull IntArray pendingBackups, @NonNull ArrayList<RestoreInfo> pendingRestores, |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 178 | boolean isApex, @NonNull IntArray installedUsers, |
| 179 | @NonNull SparseLongArray ceSnapshotInodes) { |
Richard Uhler | a7e9b2d | 2019-01-22 17:20:58 +0000 | [diff] [blame] | 180 | this.mVersionRolledBackFrom = packageRolledBackFrom; |
| 181 | this.mVersionRolledBackTo = packageRolledBackTo; |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 182 | this.mPendingBackups = pendingBackups; |
| 183 | this.mPendingRestores = pendingRestores; |
Narayan Kamath | fcd4a04 | 2019-02-01 14:16:37 +0000 | [diff] [blame] | 184 | this.mIsApex = isApex; |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 185 | this.mInstalledUsers = installedUsers; |
| 186 | this.mCeSnapshotInodes = ceSnapshotInodes; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | private PackageRollbackInfo(Parcel in) { |
Richard Uhler | a7e9b2d | 2019-01-22 17:20:58 +0000 | [diff] [blame] | 190 | this.mVersionRolledBackFrom = VersionedPackage.CREATOR.createFromParcel(in); |
| 191 | this.mVersionRolledBackTo = VersionedPackage.CREATOR.createFromParcel(in); |
Narayan Kamath | fcd4a04 | 2019-02-01 14:16:37 +0000 | [diff] [blame] | 192 | this.mIsApex = in.readBoolean(); |
Narayan Kamath | c034fe9 | 2019-01-23 10:48:17 +0000 | [diff] [blame] | 193 | this.mPendingRestores = null; |
| 194 | this.mPendingBackups = null; |
Nikita Ioffe | 952aa7b | 2019-01-28 19:49:56 +0000 | [diff] [blame] | 195 | this.mInstalledUsers = null; |
| 196 | this.mCeSnapshotInodes = null; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public int describeContents() { |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public void writeToParcel(Parcel out, int flags) { |
Richard Uhler | a7e9b2d | 2019-01-22 17:20:58 +0000 | [diff] [blame] | 206 | mVersionRolledBackFrom.writeToParcel(out, flags); |
| 207 | mVersionRolledBackTo.writeToParcel(out, flags); |
Narayan Kamath | fcd4a04 | 2019-02-01 14:16:37 +0000 | [diff] [blame] | 208 | out.writeBoolean(mIsApex); |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | public static final Parcelable.Creator<PackageRollbackInfo> CREATOR = |
| 212 | new Parcelable.Creator<PackageRollbackInfo>() { |
| 213 | public PackageRollbackInfo createFromParcel(Parcel in) { |
| 214 | return new PackageRollbackInfo(in); |
| 215 | } |
| 216 | |
| 217 | public PackageRollbackInfo[] newArray(int size) { |
| 218 | return new PackageRollbackInfo[size]; |
| 219 | } |
| 220 | }; |
| 221 | } |