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.annotation.NonNull; 23 import android.annotation.Nullable; 24 import android.app.ActivityThread.ActivityClientRecord; 25 import android.app.ClientTransactionHandler; 26 import android.compat.annotation.UnsupportedAppUsage; 27 import android.os.Build; 28 import android.os.IBinder; 29 import android.os.Parcel; 30 import android.os.Parcelable; 31 import android.os.Trace; 32 33 import com.android.internal.content.ReferrerIntent; 34 35 import java.util.ArrayList; 36 import java.util.List; 37 import java.util.Objects; 38 39 /** 40 * New intent message. 41 * 42 * @hide 43 */ 44 public class NewIntentItem extends ActivityTransactionItem { 45 46 // TODO(b/170729553): Mark this with @NonNull and final once @UnsupportedAppUsage removed. 47 // We cannot do it now to avoid app compatibility regression. 48 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 49 private List<ReferrerIntent> mIntents; 50 51 private final boolean mResume; 52 NewIntentItem(@onNull IBinder activityToken, @NonNull List<ReferrerIntent> intents, boolean resume)53 public NewIntentItem(@NonNull IBinder activityToken, 54 @NonNull List<ReferrerIntent> intents, boolean resume) { 55 super(activityToken); 56 mIntents = new ArrayList<>(intents); 57 mResume = resume; 58 } 59 60 @Override getPostExecutionState()61 public int getPostExecutionState() { 62 return mResume ? ON_RESUME : UNDEFINED; 63 } 64 65 @Override execute(@onNull ClientTransactionHandler client, @NonNull ActivityClientRecord r, @NonNull PendingTransactionActions pendingActions)66 public void execute(@NonNull ClientTransactionHandler client, @NonNull ActivityClientRecord r, 67 @NonNull PendingTransactionActions pendingActions) { 68 Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityNewIntent"); 69 client.handleNewIntent(r, mIntents); 70 Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); 71 } 72 73 // Parcelable implementation 74 75 /** Writes to Parcel. */ 76 @Override writeToParcel(@onNull Parcel dest, int flags)77 public void writeToParcel(@NonNull Parcel dest, int flags) { 78 super.writeToParcel(dest, flags); 79 dest.writeBoolean(mResume); 80 dest.writeTypedList(mIntents, flags); 81 } 82 83 /** Reads from Parcel. */ NewIntentItem(@onNull Parcel in)84 private NewIntentItem(@NonNull Parcel in) { 85 super(in); 86 mResume = in.readBoolean(); 87 // TODO(b/170729553): Wrap with requireNonNull once @UnsupportedAppUsage removed. 88 mIntents = in.createTypedArrayList(ReferrerIntent.CREATOR); 89 } 90 91 public static final @NonNull Parcelable.Creator<NewIntentItem> CREATOR = 92 new Parcelable.Creator<>() { 93 public NewIntentItem createFromParcel(@NonNull Parcel in) { 94 return new NewIntentItem(in); 95 } 96 97 public NewIntentItem[] newArray(int size) { 98 return new NewIntentItem[size]; 99 } 100 }; 101 102 @Override equals(@ullable Object o)103 public boolean equals(@Nullable Object o) { 104 if (this == o) { 105 return true; 106 } 107 if (!super.equals(o)) { 108 return false; 109 } 110 final NewIntentItem other = (NewIntentItem) o; 111 return mResume == other.mResume && Objects.equals(mIntents, other.mIntents); 112 } 113 114 @Override hashCode()115 public int hashCode() { 116 int result = 17; 117 result = 31 * result + super.hashCode(); 118 result = 31 * result + (mResume ? 1 : 0); 119 result = 31 * result + mIntents.hashCode(); 120 return result; 121 } 122 123 @Override toString()124 public String toString() { 125 return "NewIntentItem{" + super.toString() 126 + ",intents=" + mIntents 127 + ",resume=" + mResume + "}"; 128 } 129 } 130