blob: f65c843ee76f72b6f6c5969d6c2521453a239cf5 [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
Andrii Kulian88e05cb2017-12-05 17:21:10 -080021import android.app.ActivityManager;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -070022import android.app.ActivityTaskManager;
Andrii Kulian446e8242017-10-26 15:17:29 -070023import android.app.ClientTransactionHandler;
24import android.os.IBinder;
25import android.os.Parcel;
Andrii Kulian88e05cb2017-12-05 17:21:10 -080026import android.os.RemoteException;
Andrii Kulian446e8242017-10-26 15:17:29 -070027import android.os.Trace;
Andrii Kulian446e8242017-10-26 15:17:29 -070028
29/**
30 * Request to move an activity to paused state.
31 * @hide
32 */
33public class PauseActivityItem extends ActivityLifecycleItem {
34
35 private static final String TAG = "PauseActivityItem";
36
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080037 private boolean mFinished;
38 private boolean mUserLeaving;
39 private int mConfigChanges;
40 private boolean mDontReport;
Andrii Kulian446e8242017-10-26 15:17:29 -070041
42 @Override
Andrii Kulian88e05cb2017-12-05 17:21:10 -080043 public void execute(ClientTransactionHandler client, IBinder token,
44 PendingTransactionActions pendingActions) {
Andrii Kulian446e8242017-10-26 15:17:29 -070045 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityPause");
Andrii Kuliana6176e32018-02-27 11:51:18 -080046 client.handlePauseActivity(token, mFinished, mUserLeaving, mConfigChanges, pendingActions,
47 "PAUSE_ACTIVITY_ITEM");
Andrii Kulian446e8242017-10-26 15:17:29 -070048 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
49 }
50
51 @Override
52 public int getTargetState() {
Andrii Kulian88e05cb2017-12-05 17:21:10 -080053 return ON_PAUSE;
Andrii Kulian446e8242017-10-26 15:17:29 -070054 }
55
Andrii Kulian88e05cb2017-12-05 17:21:10 -080056 @Override
57 public void postExecute(ClientTransactionHandler client, IBinder token,
58 PendingTransactionActions pendingActions) {
59 if (mDontReport) {
60 return;
61 }
62 try {
63 // TODO(lifecycler): Use interface callback instead of AMS.
Wale Ogunwale04d9cb52018-04-30 13:55:07 -070064 ActivityTaskManager.getService().activityPaused(token);
Andrii Kulian88e05cb2017-12-05 17:21:10 -080065 } catch (RemoteException ex) {
66 throw ex.rethrowFromSystemServer();
67 }
68 }
Andrii Kulian446e8242017-10-26 15:17:29 -070069
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080070
71 // ObjectPoolItem implementation
72
73 private PauseActivityItem() {}
74
75 /** Obtain an instance initialized with provided params. */
76 public static PauseActivityItem obtain(boolean finished, boolean userLeaving, int configChanges,
77 boolean dontReport) {
78 PauseActivityItem instance = ObjectPool.obtain(PauseActivityItem.class);
79 if (instance == null) {
80 instance = new PauseActivityItem();
81 }
82 instance.mFinished = finished;
83 instance.mUserLeaving = userLeaving;
84 instance.mConfigChanges = configChanges;
85 instance.mDontReport = dontReport;
86
87 return instance;
88 }
89
90 /** Obtain an instance initialized with default params. */
91 public static PauseActivityItem obtain() {
92 PauseActivityItem instance = ObjectPool.obtain(PauseActivityItem.class);
93 if (instance == null) {
94 instance = new PauseActivityItem();
95 }
96 instance.mFinished = false;
97 instance.mUserLeaving = false;
98 instance.mConfigChanges = 0;
99 instance.mDontReport = true;
100
101 return instance;
102 }
103
104 @Override
105 public void recycle() {
Bryce Leef52974c2018-02-14 15:12:01 -0800106 super.recycle();
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -0800107 mFinished = false;
108 mUserLeaving = false;
109 mConfigChanges = 0;
110 mDontReport = false;
111 ObjectPool.recycle(this);
112 }
113
Andrii Kulian446e8242017-10-26 15:17:29 -0700114 // Parcelable implementation
115
116 /** Write to Parcel. */
117 @Override
118 public void writeToParcel(Parcel dest, int flags) {
119 dest.writeBoolean(mFinished);
120 dest.writeBoolean(mUserLeaving);
121 dest.writeInt(mConfigChanges);
122 dest.writeBoolean(mDontReport);
123 }
124
125 /** Read from Parcel. */
126 private PauseActivityItem(Parcel in) {
127 mFinished = in.readBoolean();
128 mUserLeaving = in.readBoolean();
129 mConfigChanges = in.readInt();
130 mDontReport = in.readBoolean();
131 }
132
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700133 public static final @android.annotation.NonNull Creator<PauseActivityItem> CREATOR =
Andrii Kulian446e8242017-10-26 15:17:29 -0700134 new Creator<PauseActivityItem>() {
135 public PauseActivityItem createFromParcel(Parcel in) {
136 return new PauseActivityItem(in);
137 }
138
139 public PauseActivityItem[] newArray(int size) {
140 return new PauseActivityItem[size];
141 }
142 };
Andrii Kulian6b9d3a12017-11-16 14:36:36 -0800143
144 @Override
145 public boolean equals(Object o) {
146 if (this == o) {
147 return true;
148 }
149 if (o == null || getClass() != o.getClass()) {
150 return false;
151 }
152 final PauseActivityItem other = (PauseActivityItem) o;
153 return mFinished == other.mFinished && mUserLeaving == other.mUserLeaving
154 && mConfigChanges == other.mConfigChanges && mDontReport == other.mDontReport;
155 }
156
157 @Override
158 public int hashCode() {
159 int result = 17;
160 result = 31 * result + (mFinished ? 1 : 0);
161 result = 31 * result + (mUserLeaving ? 1 : 0);
162 result = 31 * result + mConfigChanges;
163 result = 31 * result + (mDontReport ? 1 : 0);
164 return result;
165 }
Andrii Kulian88e05cb2017-12-05 17:21:10 -0800166
167 @Override
168 public String toString() {
169 return "PauseActivityItem{finished=" + mFinished + ",userLeaving=" + mUserLeaving
170 + ",configChanges=" + mConfigChanges + ",dontReport=" + mDontReport + "}";
171 }
Andrii Kulian446e8242017-10-26 15:17:29 -0700172}