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