Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.app.servertransaction; |
| 18 | |
| 19 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
| 20 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 21 | import android.app.ActivityManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 22 | import android.app.ActivityTaskManager; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 23 | import android.app.ClientTransactionHandler; |
| 24 | import android.os.IBinder; |
| 25 | import android.os.Parcel; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 26 | import android.os.RemoteException; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 27 | import android.os.Trace; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Request to move an activity to paused state. |
| 31 | * @hide |
| 32 | */ |
| 33 | public class PauseActivityItem extends ActivityLifecycleItem { |
| 34 | |
| 35 | private static final String TAG = "PauseActivityItem"; |
| 36 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 37 | private boolean mFinished; |
| 38 | private boolean mUserLeaving; |
| 39 | private int mConfigChanges; |
| 40 | private boolean mDontReport; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 41 | |
| 42 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 43 | public void execute(ClientTransactionHandler client, IBinder token, |
| 44 | PendingTransactionActions pendingActions) { |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 45 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); |
Andrii Kulian | a6176e3 | 2018-02-27 11:51:18 -0800 | [diff] [blame] | 46 | client.handlePauseActivity(token, mFinished, mUserLeaving, mConfigChanges, pendingActions, |
| 47 | "PAUSE_ACTIVITY_ITEM"); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 48 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public int getTargetState() { |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 53 | return ON_PAUSE; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 56 | @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 Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 64 | ActivityTaskManager.getService().activityPaused(token); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 65 | } catch (RemoteException ex) { |
| 66 | throw ex.rethrowFromSystemServer(); |
| 67 | } |
| 68 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 69 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 70 | |
| 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 Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 106 | super.recycle(); |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 107 | mFinished = false; |
| 108 | mUserLeaving = false; |
| 109 | mConfigChanges = 0; |
| 110 | mDontReport = false; |
| 111 | ObjectPool.recycle(this); |
| 112 | } |
| 113 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 114 | // 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 | |
| 133 | public static final Creator<PauseActivityItem> CREATOR = |
| 134 | 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 Kulian | 6b9d3a1 | 2017-11-16 14:36:36 -0800 | [diff] [blame] | 143 | |
| 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 Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 166 | |
| 167 | @Override |
| 168 | public String toString() { |
| 169 | return "PauseActivityItem{finished=" + mFinished + ",userLeaving=" + mUserLeaving |
| 170 | + ",configChanges=" + mConfigChanges + ",dontReport=" + mDontReport + "}"; |
| 171 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 172 | } |