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 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 20 | import android.app.ClientTransactionHandler; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 21 | import android.os.IBinder; |
| 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
| 24 | import android.os.Trace; |
| 25 | |
| 26 | import com.android.internal.content.ReferrerIntent; |
| 27 | |
| 28 | import java.util.List; |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 29 | import java.util.Objects; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * New intent message. |
| 33 | * @hide |
| 34 | */ |
| 35 | public class NewIntentItem extends ClientTransactionItem { |
| 36 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 37 | @UnsupportedAppUsage |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 38 | private List<ReferrerIntent> mIntents; |
| 39 | private boolean mPause; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 40 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 41 | // TODO(lifecycler): Switch new intent handling to this scheme. |
| 42 | /*@Override |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 43 | public int getPostExecutionState() { |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 44 | return ON_RESUME; |
| 45 | }*/ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 46 | |
| 47 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 48 | public void execute(ClientTransactionHandler client, IBinder token, |
| 49 | PendingTransactionActions pendingActions) { |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 50 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityNewIntent"); |
| 51 | client.handleNewIntent(token, mIntents, mPause); |
| 52 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 53 | } |
| 54 | |
| 55 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 56 | // ObjectPoolItem implementation |
| 57 | |
| 58 | private NewIntentItem() {} |
| 59 | |
| 60 | /** Obtain an instance initialized with provided params. */ |
| 61 | public static NewIntentItem obtain(List<ReferrerIntent> intents, boolean pause) { |
| 62 | NewIntentItem instance = ObjectPool.obtain(NewIntentItem.class); |
| 63 | if (instance == null) { |
| 64 | instance = new NewIntentItem(); |
| 65 | } |
| 66 | instance.mIntents = intents; |
| 67 | instance.mPause = pause; |
| 68 | |
| 69 | return instance; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public void recycle() { |
| 74 | mIntents = null; |
| 75 | mPause = false; |
| 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(mPause); |
| 86 | dest.writeTypedList(mIntents, flags); |
| 87 | } |
| 88 | |
| 89 | /** Read from Parcel. */ |
| 90 | private NewIntentItem(Parcel in) { |
| 91 | mPause = in.readBoolean(); |
| 92 | mIntents = in.createTypedArrayList(ReferrerIntent.CREATOR); |
| 93 | } |
| 94 | |
| 95 | public static final Parcelable.Creator<NewIntentItem> CREATOR = |
| 96 | new Parcelable.Creator<NewIntentItem>() { |
| 97 | public NewIntentItem createFromParcel(Parcel in) { |
| 98 | return new NewIntentItem(in); |
| 99 | } |
| 100 | |
| 101 | public NewIntentItem[] newArray(int size) { |
| 102 | return new NewIntentItem[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 NewIntentItem other = (NewIntentItem) o; |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 115 | return mPause == other.mPause && Objects.equals(mIntents, other.mIntents); |
Andrii Kulian | 6b9d3a1 | 2017-11-16 14:36:36 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public int hashCode() { |
| 120 | int result = 17; |
| 121 | result = 31 * result + (mPause ? 1 : 0); |
| 122 | result = 31 * result + mIntents.hashCode(); |
| 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 "NewIntentItem{pause=" + mPause + ",intents=" + mIntents + "}"; |
| 129 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 130 | } |