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; |
| 25 | |
| 26 | /** |
| 27 | * Request to destroy an activity. |
| 28 | * @hide |
| 29 | */ |
| 30 | public class DestroyActivityItem extends ActivityLifecycleItem { |
| 31 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 32 | private boolean mFinished; |
| 33 | private int mConfigChanges; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 34 | |
| 35 | @Override |
Riddle Hsu | d3062cb | 2018-06-30 02:06:42 +0800 | [diff] [blame] | 36 | public void preExecute(ClientTransactionHandler client, IBinder token) { |
| 37 | client.getActivitiesToBeDestroyed().put(token, this); |
| 38 | } |
| 39 | |
| 40 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 41 | public void execute(ClientTransactionHandler client, IBinder token, |
| 42 | PendingTransactionActions pendingActions) { |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 43 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityDestroy"); |
| 44 | client.handleDestroyActivity(token, mFinished, mConfigChanges, |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 45 | false /* getNonConfigInstance */, "DestroyActivityItem"); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 46 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public int getTargetState() { |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 51 | return ON_DESTROY; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 55 | // ObjectPoolItem implementation |
| 56 | |
| 57 | private DestroyActivityItem() {} |
| 58 | |
| 59 | /** Obtain an instance initialized with provided params. */ |
| 60 | public static DestroyActivityItem obtain(boolean finished, int configChanges) { |
| 61 | DestroyActivityItem instance = ObjectPool.obtain(DestroyActivityItem.class); |
| 62 | if (instance == null) { |
| 63 | instance = new DestroyActivityItem(); |
| 64 | } |
| 65 | instance.mFinished = finished; |
| 66 | instance.mConfigChanges = configChanges; |
| 67 | |
| 68 | return instance; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public void recycle() { |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 73 | super.recycle(); |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 74 | mFinished = false; |
| 75 | mConfigChanges = 0; |
| 76 | ObjectPool.recycle(this); |
| 77 | } |
| 78 | |
| 79 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 80 | // Parcelable implementation |
| 81 | |
| 82 | /** Write to Parcel. */ |
| 83 | @Override |
| 84 | public void writeToParcel(Parcel dest, int flags) { |
| 85 | dest.writeBoolean(mFinished); |
| 86 | dest.writeInt(mConfigChanges); |
| 87 | } |
| 88 | |
| 89 | /** Read from Parcel. */ |
| 90 | private DestroyActivityItem(Parcel in) { |
| 91 | mFinished = in.readBoolean(); |
| 92 | mConfigChanges = in.readInt(); |
| 93 | } |
| 94 | |
| 95 | public static final Creator<DestroyActivityItem> CREATOR = |
| 96 | new Creator<DestroyActivityItem>() { |
| 97 | public DestroyActivityItem createFromParcel(Parcel in) { |
| 98 | return new DestroyActivityItem(in); |
| 99 | } |
| 100 | |
| 101 | public DestroyActivityItem[] newArray(int size) { |
| 102 | return new DestroyActivityItem[size]; |
| 103 | } |
| 104 | }; |
Andrii Kulian | 6b9d3a1 | 2017-11-16 14:36:36 -0800 | [diff] [blame] | 105 | |
| 106 | @Override |
| 107 | public boolean equals(Object o) { |
| 108 | if (this == o) { |
| 109 | return true; |
| 110 | } |
| 111 | if (o == null || getClass() != o.getClass()) { |
| 112 | return false; |
| 113 | } |
| 114 | final DestroyActivityItem other = (DestroyActivityItem) o; |
| 115 | return mFinished == other.mFinished && mConfigChanges == other.mConfigChanges; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public int hashCode() { |
| 120 | int result = 17; |
| 121 | result = 31 * result + (mFinished ? 1 : 0); |
| 122 | result = 31 * result + mConfigChanges; |
| 123 | return result; |
| 124 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 125 | |
| 126 | @Override |
| 127 | public String toString() { |
| 128 | return "DestroyActivityItem{finished=" + mFinished + ",mConfigChanges=" |
| 129 | + mConfigChanges + "}"; |
| 130 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 131 | } |