blob: 3ee761477efd3582173defccb40c070492f4e8fa [file] [log] [blame]
Andrii Kulian446e8242017-10-26 15:17:29 -07001/*
2 * Copyright 2017 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.app.servertransaction;
18
19import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
20
21import android.app.ClientTransactionHandler;
22import android.os.IBinder;
23import android.os.Parcel;
24import android.os.Trace;
25
26/**
27 * Request to destroy an activity.
28 * @hide
29 */
30public class DestroyActivityItem extends ActivityLifecycleItem {
31
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080032 private boolean mFinished;
33 private int mConfigChanges;
Andrii Kulian446e8242017-10-26 15:17:29 -070034
35 @Override
Riddle Hsud3062cb2018-06-30 02:06:42 +080036 public void preExecute(ClientTransactionHandler client, IBinder token) {
37 client.getActivitiesToBeDestroyed().put(token, this);
38 }
39
40 @Override
Andrii Kulian88e05cb2017-12-05 17:21:10 -080041 public void execute(ClientTransactionHandler client, IBinder token,
42 PendingTransactionActions pendingActions) {
Andrii Kulian446e8242017-10-26 15:17:29 -070043 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityDestroy");
44 client.handleDestroyActivity(token, mFinished, mConfigChanges,
Bryce Lee1d0d5142018-04-12 10:35:07 -070045 false /* getNonConfigInstance */, "DestroyActivityItem");
Andrii Kulian446e8242017-10-26 15:17:29 -070046 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
47 }
48
49 @Override
50 public int getTargetState() {
Andrii Kulian88e05cb2017-12-05 17:21:10 -080051 return ON_DESTROY;
Andrii Kulian446e8242017-10-26 15:17:29 -070052 }
53
54
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080055 // ObjectPoolItem implementation
56
57 private DestroyActivityItem() {}
58
59 /** Obtain an instance initialized with provided params. */
60 public static DestroyActivityItem obtain(boolean finished, int configChanges) {
61 DestroyActivityItem instance = ObjectPool.obtain(DestroyActivityItem.class);
62 if (instance == null) {
63 instance = new DestroyActivityItem();
64 }
65 instance.mFinished = finished;
66 instance.mConfigChanges = configChanges;
67
68 return instance;
69 }
70
71 @Override
72 public void recycle() {
Bryce Leef52974c2018-02-14 15:12:01 -080073 super.recycle();
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080074 mFinished = false;
75 mConfigChanges = 0;
76 ObjectPool.recycle(this);
77 }
78
79
Andrii Kulian446e8242017-10-26 15:17:29 -070080 // Parcelable implementation
81
82 /** Write to Parcel. */
83 @Override
84 public void writeToParcel(Parcel dest, int flags) {
85 dest.writeBoolean(mFinished);
86 dest.writeInt(mConfigChanges);
87 }
88
89 /** Read from Parcel. */
90 private DestroyActivityItem(Parcel in) {
91 mFinished = in.readBoolean();
92 mConfigChanges = in.readInt();
93 }
94
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070095 public static final @android.annotation.NonNull Creator<DestroyActivityItem> CREATOR =
Andrii Kulian446e8242017-10-26 15:17:29 -070096 new Creator<DestroyActivityItem>() {
97 public DestroyActivityItem createFromParcel(Parcel in) {
98 return new DestroyActivityItem(in);
99 }
100
101 public DestroyActivityItem[] newArray(int size) {
102 return new DestroyActivityItem[size];
103 }
104 };
Andrii Kulian6b9d3a12017-11-16 14:36:36 -0800105
106 @Override
107 public boolean equals(Object o) {
108 if (this == o) {
109 return true;
110 }
111 if (o == null || getClass() != o.getClass()) {
112 return false;
113 }
114 final DestroyActivityItem other = (DestroyActivityItem) o;
115 return mFinished == other.mFinished && mConfigChanges == other.mConfigChanges;
116 }
117
118 @Override
119 public int hashCode() {
120 int result = 17;
121 result = 31 * result + (mFinished ? 1 : 0);
122 result = 31 * result + mConfigChanges;
123 return result;
124 }
Andrii Kulian88e05cb2017-12-05 17:21:10 -0800125
126 @Override
127 public String toString() {
128 return "DestroyActivityItem{finished=" + mFinished + ",mConfigChanges="
129 + mConfigChanges + "}";
130 }
Andrii Kulian446e8242017-10-26 15:17:29 -0700131}