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.app.servertransaction.ActivityLifecycleItem.ON_RESUME; 20 import static android.app.servertransaction.ActivityLifecycleItem.UNDEFINED; 21 22 import android.app.ClientTransactionHandler; 23 import android.compat.annotation.UnsupportedAppUsage; 24 import android.os.IBinder; 25 import android.os.Parcel; 26 import android.os.Parcelable; 27 import android.os.Trace; 28 29 import com.android.internal.content.ReferrerIntent; 30 31 import java.util.List; 32 import java.util.Objects; 33 34 /** 35 * New intent message. 36 * @hide 37 */ 38 public class NewIntentItem extends ClientTransactionItem { 39 40 @UnsupportedAppUsage 41 private List<ReferrerIntent> mIntents; 42 private boolean mResume; 43 44 @Override getPostExecutionState()45 public int getPostExecutionState() { 46 return mResume ? ON_RESUME : UNDEFINED; 47 } 48 49 @Override execute(ClientTransactionHandler client, IBinder token, PendingTransactionActions pendingActions)50 public void execute(ClientTransactionHandler client, IBinder token, 51 PendingTransactionActions pendingActions) { 52 Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityNewIntent"); 53 client.handleNewIntent(token, mIntents); 54 Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); 55 } 56 57 58 // ObjectPoolItem implementation 59 NewIntentItem()60 private NewIntentItem() {} 61 62 /** Obtain an instance initialized with provided params. */ obtain(List<ReferrerIntent> intents, boolean resume)63 public static NewIntentItem obtain(List<ReferrerIntent> intents, boolean resume) { 64 NewIntentItem instance = ObjectPool.obtain(NewIntentItem.class); 65 if (instance == null) { 66 instance = new NewIntentItem(); 67 } 68 instance.mIntents = intents; 69 instance.mResume = resume; 70 71 return instance; 72 } 73 74 @Override recycle()75 public void recycle() { 76 mIntents = null; 77 mResume = false; 78 ObjectPool.recycle(this); 79 } 80 81 82 // Parcelable implementation 83 84 /** Write to Parcel. */ 85 @Override writeToParcel(Parcel dest, int flags)86 public void writeToParcel(Parcel dest, int flags) { 87 dest.writeBoolean(mResume); 88 dest.writeTypedList(mIntents, flags); 89 } 90 91 /** Read from Parcel. */ NewIntentItem(Parcel in)92 private NewIntentItem(Parcel in) { 93 mResume = in.readBoolean(); 94 mIntents = in.createTypedArrayList(ReferrerIntent.CREATOR); 95 } 96 97 public static final @android.annotation.NonNull Parcelable.Creator<NewIntentItem> CREATOR = 98 new Parcelable.Creator<NewIntentItem>() { 99 public NewIntentItem createFromParcel(Parcel in) { 100 return new NewIntentItem(in); 101 } 102 103 public NewIntentItem[] newArray(int size) { 104 return new NewIntentItem[size]; 105 } 106 }; 107 108 @Override equals(Object o)109 public boolean equals(Object o) { 110 if (this == o) { 111 return true; 112 } 113 if (o == null || getClass() != o.getClass()) { 114 return false; 115 } 116 final NewIntentItem other = (NewIntentItem) o; 117 return mResume == other.mResume && Objects.equals(mIntents, other.mIntents); 118 } 119 120 @Override hashCode()121 public int hashCode() { 122 int result = 17; 123 result = 31 * result + (mResume ? 1 : 0); 124 result = 31 * result + mIntents.hashCode(); 125 return result; 126 } 127 128 @Override toString()129 public String toString() { 130 return "NewIntentItem{intents=" + mIntents + ",resume=" + mResume + "}"; 131 } 132 } 133