blob: 8668bd49c8f50304d88ad9f18588460d8e19af30 [file] [log] [blame]
Alan Viverette3da604b2020-06-10 18:34:39 +00001/*
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 move an activity to stopped state.
28 * @hide
29 */
30public class StopActivityItem extends ActivityLifecycleItem {
31
32 private static final String TAG = "StopActivityItem";
33
34 private int mConfigChanges;
35
36 @Override
37 public void execute(ClientTransactionHandler client, IBinder token,
38 PendingTransactionActions pendingActions) {
39 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityStop");
40 client.handleStopActivity(token, mConfigChanges, pendingActions,
41 true /* finalStateRequest */, "STOP_ACTIVITY_ITEM");
42 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
43 }
44
45 @Override
46 public void postExecute(ClientTransactionHandler client, IBinder token,
47 PendingTransactionActions pendingActions) {
48 client.reportStop(pendingActions);
49 }
50
51 @Override
52 public int getTargetState() {
53 return ON_STOP;
54 }
55
56
57 // ObjectPoolItem implementation
58
59 private StopActivityItem() {}
60
61 /**
62 * Obtain an instance initialized with provided params.
63 * @param configChanges Configuration pieces that changed.
64 */
65 public static StopActivityItem obtain(int configChanges) {
66 StopActivityItem instance = ObjectPool.obtain(StopActivityItem.class);
67 if (instance == null) {
68 instance = new StopActivityItem();
69 }
70 instance.mConfigChanges = configChanges;
71
72 return instance;
73 }
74
75 @Override
76 public void recycle() {
77 super.recycle();
78 mConfigChanges = 0;
79 ObjectPool.recycle(this);
80 }
81
82
83 // Parcelable implementation
84
85 /** Write to Parcel. */
86 @Override
87 public void writeToParcel(Parcel dest, int flags) {
88 dest.writeInt(mConfigChanges);
89 }
90
91 /** Read from Parcel. */
92 private StopActivityItem(Parcel in) {
93 mConfigChanges = in.readInt();
94 }
95
96 public static final @android.annotation.NonNull Creator<StopActivityItem> CREATOR =
97 new Creator<StopActivityItem>() {
98 public StopActivityItem createFromParcel(Parcel in) {
99 return new StopActivityItem(in);
100 }
101
102 public StopActivityItem[] newArray(int size) {
103 return new StopActivityItem[size];
104 }
105 };
106
107 @Override
108 public boolean equals(Object o) {
109 if (this == o) {
110 return true;
111 }
112 if (o == null || getClass() != o.getClass()) {
113 return false;
114 }
115 final StopActivityItem other = (StopActivityItem) o;
116 return mConfigChanges == other.mConfigChanges;
117 }
118
119 @Override
120 public int hashCode() {
121 int result = 17;
122 result = 31 * result + mConfigChanges;
123 return result;
124 }
125
126 @Override
127 public String toString() {
128 return "StopActivityItem{configChanges=" + mConfigChanges + "}";
129 }
130}