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 | |
Richard Uhler | c739c8c | 2018-12-12 11:03:34 +0000 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Richard Uhler | e4e38d6 | 2019-01-24 16:12:07 +0000 | [diff] [blame] | 20 | import android.content.pm.PackageInstaller; |
Richard Uhler | bf5b5c4 | 2019-01-28 15:26:37 +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; |
| 24 | |
Richard Uhler | 0a79b32 | 2019-01-23 13:51:07 +0000 | [diff] [blame] | 25 | import java.util.List; |
| 26 | |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 27 | /** |
| 28 | * Information about a set of packages that can be, or already have been |
| 29 | * rolled back together. |
| 30 | * |
Richard Uhler | c739c8c | 2018-12-12 11:03:34 +0000 | [diff] [blame] | 31 | * @hide |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 32 | */ |
Richard Uhler | c739c8c | 2018-12-12 11:03:34 +0000 | [diff] [blame] | 33 | @SystemApi |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 34 | public final class RollbackInfo implements Parcelable { |
| 35 | |
| 36 | /** |
Richard Uhler | b9d5447 | 2019-01-22 12:50:08 +0000 | [diff] [blame] | 37 | * A unique identifier for the rollback. |
| 38 | */ |
| 39 | private final int mRollbackId; |
| 40 | |
Richard Uhler | 0a79b32 | 2019-01-23 13:51:07 +0000 | [diff] [blame] | 41 | private final List<PackageRollbackInfo> mPackages; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 42 | |
Richard Uhler | bf5b5c4 | 2019-01-28 15:26:37 +0000 | [diff] [blame] | 43 | private final List<VersionedPackage> mCausePackages; |
| 44 | |
Richard Uhler | c739c8c | 2018-12-12 11:03:34 +0000 | [diff] [blame] | 45 | /** @hide */ |
Richard Uhler | bf5b5c4 | 2019-01-28 15:26:37 +0000 | [diff] [blame] | 46 | public RollbackInfo(int rollbackId, List<PackageRollbackInfo> packages, |
| 47 | List<VersionedPackage> causePackages) { |
Richard Uhler | b9d5447 | 2019-01-22 12:50:08 +0000 | [diff] [blame] | 48 | this.mRollbackId = rollbackId; |
Richard Uhler | 0a79b32 | 2019-01-23 13:51:07 +0000 | [diff] [blame] | 49 | this.mPackages = packages; |
Richard Uhler | bf5b5c4 | 2019-01-28 15:26:37 +0000 | [diff] [blame] | 50 | this.mCausePackages = causePackages; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | private RollbackInfo(Parcel in) { |
Richard Uhler | b9d5447 | 2019-01-22 12:50:08 +0000 | [diff] [blame] | 54 | mRollbackId = in.readInt(); |
Richard Uhler | 0a79b32 | 2019-01-23 13:51:07 +0000 | [diff] [blame] | 55 | mPackages = in.createTypedArrayList(PackageRollbackInfo.CREATOR); |
Richard Uhler | bf5b5c4 | 2019-01-28 15:26:37 +0000 | [diff] [blame] | 56 | mCausePackages = in.createTypedArrayList(VersionedPackage.CREATOR); |
Richard Uhler | b9d5447 | 2019-01-22 12:50:08 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns a unique identifier for this rollback. |
| 61 | */ |
| 62 | public int getRollbackId() { |
| 63 | return mRollbackId; |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Richard Uhler | 0a79b32 | 2019-01-23 13:51:07 +0000 | [diff] [blame] | 66 | /** |
| 67 | * Returns the list of package that are rolled back. |
| 68 | */ |
| 69 | public List<PackageRollbackInfo> getPackages() { |
| 70 | return mPackages; |
| 71 | } |
| 72 | |
Richard Uhler | e4e38d6 | 2019-01-24 16:12:07 +0000 | [diff] [blame] | 73 | /** |
| 74 | * Returns true if this rollback requires reboot to take effect after |
| 75 | * being committed. |
| 76 | */ |
| 77 | public boolean isStaged() { |
| 78 | // TODO: Support rollback of staged installs. |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Returns the session ID for the committed rollback for staged rollbacks. |
| 84 | * Only applicable for rollbacks that have been committed. |
| 85 | */ |
Richard Uhler | d750b85 | 2019-01-29 16:04:26 +0000 | [diff] [blame^] | 86 | public int getCommittedSessionId() { |
Richard Uhler | e4e38d6 | 2019-01-24 16:12:07 +0000 | [diff] [blame] | 87 | // TODO: Support rollback of staged installs. |
| 88 | return PackageInstaller.SessionInfo.INVALID_ID; |
| 89 | } |
| 90 | |
Richard Uhler | bf5b5c4 | 2019-01-28 15:26:37 +0000 | [diff] [blame] | 91 | /** |
| 92 | * Gets the list of package versions that motivated this rollback. |
| 93 | * As provided to {@link #commitRollback} when the rollback was committed. |
| 94 | * This is only applicable for rollbacks that have been committed. |
| 95 | */ |
| 96 | public List<VersionedPackage> getCausePackages() { |
| 97 | return mCausePackages; |
| 98 | } |
| 99 | |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 100 | @Override |
| 101 | public int describeContents() { |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public void writeToParcel(Parcel out, int flags) { |
Richard Uhler | b9d5447 | 2019-01-22 12:50:08 +0000 | [diff] [blame] | 107 | out.writeInt(mRollbackId); |
Richard Uhler | 0a79b32 | 2019-01-23 13:51:07 +0000 | [diff] [blame] | 108 | out.writeTypedList(mPackages); |
Richard Uhler | bf5b5c4 | 2019-01-28 15:26:37 +0000 | [diff] [blame] | 109 | out.writeTypedList(mCausePackages); |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | public static final Parcelable.Creator<RollbackInfo> CREATOR = |
| 113 | new Parcelable.Creator<RollbackInfo>() { |
| 114 | public RollbackInfo createFromParcel(Parcel in) { |
| 115 | return new RollbackInfo(in); |
| 116 | } |
| 117 | |
| 118 | public RollbackInfo[] newArray(int size) { |
| 119 | return new RollbackInfo[size]; |
| 120 | } |
| 121 | }; |
| 122 | } |