blob: 9459ad366f767375b042f64c466c94f5b7f28e74 [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
Richard Uhlerc739c8c2018-12-12 11:03:34 +000019import android.annotation.SystemApi;
Richard Uhlerbf5b5c42019-01-28 15:26:37 +000020import android.content.pm.VersionedPackage;
Richard Uhlerb29f1452018-09-12 16:38:15 +010021import android.os.Parcel;
22import android.os.Parcelable;
23
Richard Uhler0a79b322019-01-23 13:51:07 +000024import java.util.List;
25
Richard Uhlerb29f1452018-09-12 16:38:15 +010026/**
27 * Information about a set of packages that can be, or already have been
28 * rolled back together.
29 *
Richard Uhlerc739c8c2018-12-12 11:03:34 +000030 * @hide
Richard Uhlerb29f1452018-09-12 16:38:15 +010031 */
Richard Uhlerc739c8c2018-12-12 11:03:34 +000032@SystemApi
Richard Uhlerb29f1452018-09-12 16:38:15 +010033public final class RollbackInfo implements Parcelable {
34
35 /**
Richard Uhlerb9d54472019-01-22 12:50:08 +000036 * A unique identifier for the rollback.
37 */
38 private final int mRollbackId;
39
Richard Uhler0a79b322019-01-23 13:51:07 +000040 private final List<PackageRollbackInfo> mPackages;
Richard Uhlerb29f1452018-09-12 16:38:15 +010041
Richard Uhlerbf5b5c42019-01-28 15:26:37 +000042 private final List<VersionedPackage> mCausePackages;
43
Richard Uhlerccf035d2019-02-04 14:04:52 +000044 private final boolean mIsStaged;
Richard Uhlercca637a2019-02-27 11:50:48 +000045 private int mCommittedSessionId;
Richard Uhlerccf035d2019-02-04 14:04:52 +000046
47 /** @hide */
48 public RollbackInfo(int rollbackId, List<PackageRollbackInfo> packages, boolean isStaged,
49 List<VersionedPackage> causePackages, int committedSessionId) {
Richard Uhlerb9d54472019-01-22 12:50:08 +000050 this.mRollbackId = rollbackId;
Richard Uhler0a79b322019-01-23 13:51:07 +000051 this.mPackages = packages;
Richard Uhlerccf035d2019-02-04 14:04:52 +000052 this.mIsStaged = isStaged;
Richard Uhlerbf5b5c42019-01-28 15:26:37 +000053 this.mCausePackages = causePackages;
Richard Uhlerccf035d2019-02-04 14:04:52 +000054 this.mCommittedSessionId = committedSessionId;
Richard Uhlerb29f1452018-09-12 16:38:15 +010055 }
56
57 private RollbackInfo(Parcel in) {
Richard Uhlerb9d54472019-01-22 12:50:08 +000058 mRollbackId = in.readInt();
Richard Uhler0a79b322019-01-23 13:51:07 +000059 mPackages = in.createTypedArrayList(PackageRollbackInfo.CREATOR);
Richard Uhlerccf035d2019-02-04 14:04:52 +000060 mIsStaged = in.readBoolean();
Richard Uhlerbf5b5c42019-01-28 15:26:37 +000061 mCausePackages = in.createTypedArrayList(VersionedPackage.CREATOR);
Richard Uhlerccf035d2019-02-04 14:04:52 +000062 mCommittedSessionId = in.readInt();
Richard Uhlerb9d54472019-01-22 12:50:08 +000063 }
64
65 /**
66 * Returns a unique identifier for this rollback.
67 */
68 public int getRollbackId() {
69 return mRollbackId;
Richard Uhlerb29f1452018-09-12 16:38:15 +010070 }
71
Richard Uhler0a79b322019-01-23 13:51:07 +000072 /**
73 * Returns the list of package that are rolled back.
74 */
75 public List<PackageRollbackInfo> getPackages() {
76 return mPackages;
77 }
78
Richard Uhlere4e38d62019-01-24 16:12:07 +000079 /**
80 * Returns true if this rollback requires reboot to take effect after
81 * being committed.
82 */
83 public boolean isStaged() {
Richard Uhlerccf035d2019-02-04 14:04:52 +000084 return mIsStaged;
Richard Uhlere4e38d62019-01-24 16:12:07 +000085 }
86
87 /**
88 * Returns the session ID for the committed rollback for staged rollbacks.
89 * Only applicable for rollbacks that have been committed.
90 */
Richard Uhlerd750b852019-01-29 16:04:26 +000091 public int getCommittedSessionId() {
Richard Uhlerccf035d2019-02-04 14:04:52 +000092 return mCommittedSessionId;
Richard Uhlere4e38d62019-01-24 16:12:07 +000093 }
94
Richard Uhlerbf5b5c42019-01-28 15:26:37 +000095 /**
Richard Uhlercca637a2019-02-27 11:50:48 +000096 * Sets the session ID for the committed rollback for staged rollbacks.
97 * @hide
98 */
99 public void setCommittedSessionId(int sessionId) {
100 mCommittedSessionId = sessionId;
101 }
102
103 /**
Richard Uhlerbf5b5c42019-01-28 15:26:37 +0000104 * 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 Uhlerb29f1452018-09-12 16:38:15 +0100112 @Override
113 public int describeContents() {
114 return 0;
115 }
116
117 @Override
118 public void writeToParcel(Parcel out, int flags) {
Richard Uhlerb9d54472019-01-22 12:50:08 +0000119 out.writeInt(mRollbackId);
Richard Uhler0a79b322019-01-23 13:51:07 +0000120 out.writeTypedList(mPackages);
Richard Uhlerccf035d2019-02-04 14:04:52 +0000121 out.writeBoolean(mIsStaged);
Richard Uhlerbf5b5c42019-01-28 15:26:37 +0000122 out.writeTypedList(mCausePackages);
Richard Uhlerccf035d2019-02-04 14:04:52 +0000123 out.writeInt(mCommittedSessionId);
Richard Uhlerb29f1452018-09-12 16:38:15 +0100124 }
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}