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