blob: 4f28cd2d58d7fdec50237b89183ad2ea28e9d88f [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
Mathew Inwood98e9ad12018-08-30 13:11:50 +010019import android.annotation.UnsupportedAppUsage;
Andrii Kulian88e05cb2017-12-05 17:21:10 -080020import android.app.ClientTransactionHandler;
Andrii Kulian446e8242017-10-26 15:17:29 -070021import android.os.IBinder;
22import android.os.Parcel;
23import android.os.Parcelable;
24import android.os.Trace;
25
26import com.android.internal.content.ReferrerIntent;
27
28import java.util.List;
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080029import java.util.Objects;
Andrii Kulian446e8242017-10-26 15:17:29 -070030
31/**
32 * New intent message.
33 * @hide
34 */
35public class NewIntentItem extends ClientTransactionItem {
36
Mathew Inwood98e9ad12018-08-30 13:11:50 +010037 @UnsupportedAppUsage
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080038 private List<ReferrerIntent> mIntents;
39 private boolean mPause;
Andrii Kulian446e8242017-10-26 15:17:29 -070040
Andrii Kulian88e05cb2017-12-05 17:21:10 -080041 // TODO(lifecycler): Switch new intent handling to this scheme.
42 /*@Override
Andrii Kulian446e8242017-10-26 15:17:29 -070043 public int getPostExecutionState() {
Andrii Kulian88e05cb2017-12-05 17:21:10 -080044 return ON_RESUME;
45 }*/
Andrii Kulian446e8242017-10-26 15:17:29 -070046
47 @Override
Andrii Kulian88e05cb2017-12-05 17:21:10 -080048 public void execute(ClientTransactionHandler client, IBinder token,
49 PendingTransactionActions pendingActions) {
Andrii Kulian446e8242017-10-26 15:17:29 -070050 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 Kulian9c5ea9c2017-12-07 09:31:01 -080056 // 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 Kulian446e8242017-10-26 15:17:29 -070080 // 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 Kulian6b9d3a12017-11-16 14:36:36 -0800105
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 Kulian9c5ea9c2017-12-07 09:31:01 -0800115 return mPause == other.mPause && Objects.equals(mIntents, other.mIntents);
Andrii Kulian6b9d3a12017-11-16 14:36:36 -0800116 }
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 Kulian88e05cb2017-12-05 17:21:10 -0800125
126 @Override
127 public String toString() {
128 return "NewIntentItem{pause=" + mPause + ",intents=" + mIntents + "}";
129 }
Andrii Kulian446e8242017-10-26 15:17:29 -0700130}