blob: 87db2062a63d196e24d25b764f928b0ae39b3c99 [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;
Andrii Kulian446e8242017-10-26 15:17:29 -070025
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
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080034 private boolean mShowWindow;
35 private int mConfigChanges;
Andrii Kulian446e8242017-10-26 15:17:29 -070036
37 @Override
Andrii Kulian88e05cb2017-12-05 17:21:10 -080038 public void execute(ClientTransactionHandler client, IBinder token,
39 PendingTransactionActions pendingActions) {
Andrii Kulian446e8242017-10-26 15:17:29 -070040 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityStop");
Andrii Kuliand25680c2018-02-21 15:16:58 -080041 client.handleStopActivity(token, mShowWindow, mConfigChanges, pendingActions,
Andrii Kulian829829c2018-03-19 18:19:05 -070042 true /* finalStateRequest */, "STOP_ACTIVITY_ITEM");
Andrii Kulian446e8242017-10-26 15:17:29 -070043 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
44 }
45
46 @Override
Andrii Kulian88e05cb2017-12-05 17:21:10 -080047 public void postExecute(ClientTransactionHandler client, IBinder token,
48 PendingTransactionActions pendingActions) {
49 client.reportStop(pendingActions);
50 }
51
52 @Override
Andrii Kulian446e8242017-10-26 15:17:29 -070053 public int getTargetState() {
Andrii Kulian88e05cb2017-12-05 17:21:10 -080054 return ON_STOP;
Andrii Kulian446e8242017-10-26 15:17:29 -070055 }
56
57
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080058 // ObjectPoolItem implementation
59
60 private StopActivityItem() {}
61
62 /** Obtain an instance initialized with provided params. */
63 public static StopActivityItem obtain(boolean showWindow, int configChanges) {
64 StopActivityItem instance = ObjectPool.obtain(StopActivityItem.class);
65 if (instance == null) {
66 instance = new StopActivityItem();
67 }
68 instance.mShowWindow = showWindow;
69 instance.mConfigChanges = configChanges;
70
71 return instance;
72 }
73
74 @Override
75 public void recycle() {
Bryce Leef52974c2018-02-14 15:12:01 -080076 super.recycle();
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080077 mShowWindow = false;
78 mConfigChanges = 0;
79 ObjectPool.recycle(this);
80 }
81
82
Andrii Kulian446e8242017-10-26 15:17:29 -070083 // Parcelable implementation
84
85 /** Write to Parcel. */
86 @Override
87 public void writeToParcel(Parcel dest, int flags) {
88 dest.writeBoolean(mShowWindow);
89 dest.writeInt(mConfigChanges);
90 }
91
92 /** Read from Parcel. */
93 private StopActivityItem(Parcel in) {
94 mShowWindow = in.readBoolean();
95 mConfigChanges = in.readInt();
96 }
97
98 public static final Creator<StopActivityItem> CREATOR =
99 new Creator<StopActivityItem>() {
100 public StopActivityItem createFromParcel(Parcel in) {
101 return new StopActivityItem(in);
102 }
103
104 public StopActivityItem[] newArray(int size) {
105 return new StopActivityItem[size];
106 }
107 };
Andrii Kulian6b9d3a12017-11-16 14:36:36 -0800108
109 @Override
110 public boolean equals(Object o) {
111 if (this == o) {
112 return true;
113 }
114 if (o == null || getClass() != o.getClass()) {
115 return false;
116 }
117 final StopActivityItem other = (StopActivityItem) o;
118 return mShowWindow == other.mShowWindow && mConfigChanges == other.mConfigChanges;
119 }
120
121 @Override
122 public int hashCode() {
123 int result = 17;
124 result = 31 * result + (mShowWindow ? 1 : 0);
125 result = 31 * result + mConfigChanges;
126 return result;
127 }
Andrii Kulian88e05cb2017-12-05 17:21:10 -0800128
129 @Override
130 public String toString() {
131 return "StopActivityItem{showWindow=" + mShowWindow + ",configChanges=" + mConfigChanges
132 + "}";
133 }
Andrii Kulian446e8242017-10-26 15:17:29 -0700134}