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 | |
| 21 | import android.app.ClientTransactionHandler; |
| 22 | import android.os.IBinder; |
| 23 | import android.os.Parcel; |
| 24 | import android.os.Trace; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Request to move an activity to stopped state. |
| 28 | * @hide |
| 29 | */ |
| 30 | public class StopActivityItem extends ActivityLifecycleItem { |
| 31 | |
| 32 | private static final String TAG = "StopActivityItem"; |
| 33 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 34 | private boolean mShowWindow; |
| 35 | private int mConfigChanges; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 36 | |
| 37 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 38 | public void execute(ClientTransactionHandler client, IBinder token, |
| 39 | PendingTransactionActions pendingActions) { |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 40 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityStop"); |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 41 | client.handleStopActivity(token, mShowWindow, mConfigChanges, pendingActions, |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 42 | true /* finalStateRequest */, "STOP_ACTIVITY_ITEM"); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 43 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 44 | } |
| 45 | |
| 46 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 47 | public void postExecute(ClientTransactionHandler client, IBinder token, |
| 48 | PendingTransactionActions pendingActions) { |
| 49 | client.reportStop(pendingActions); |
| 50 | } |
| 51 | |
| 52 | @Override |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 53 | public int getTargetState() { |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 54 | return ON_STOP; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 58 | // 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 Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 76 | super.recycle(); |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 77 | mShowWindow = false; |
| 78 | mConfigChanges = 0; |
| 79 | ObjectPool.recycle(this); |
| 80 | } |
| 81 | |
| 82 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 83 | // 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 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 98 | public static final @android.annotation.NonNull Creator<StopActivityItem> CREATOR = |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 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 Kulian | 6b9d3a1 | 2017-11-16 14:36:36 -0800 | [diff] [blame] | 108 | |
| 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 Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 128 | |
| 129 | @Override |
| 130 | public String toString() { |
| 131 | return "StopActivityItem{showWindow=" + mShowWindow + ",configChanges=" + mConfigChanges |
| 132 | + "}"; |
| 133 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 134 | } |