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.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; 20 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.app.ActivityClient; 24 import android.app.ActivityThread.ActivityClientRecord; 25 import android.app.ClientTransactionHandler; 26 import android.os.IBinder; 27 import android.os.Parcel; 28 import android.os.Trace; 29 30 /** 31 * Request to move an activity to paused state. 32 * 33 * @hide 34 */ 35 public class PauseActivityItem extends ActivityLifecycleItem { 36 37 private final boolean mFinished; 38 private final boolean mUserLeaving; 39 private final boolean mDontReport; 40 private final boolean mAutoEnteringPip; 41 PauseActivityItem(@onNull IBinder activityToken)42 public PauseActivityItem(@NonNull IBinder activityToken) { 43 this(activityToken, false /* finished */, false /* userLeaving */, 44 true /* dontReport */, false /* autoEnteringPip*/); 45 } 46 PauseActivityItem(@onNull IBinder activityToken, boolean finished, boolean userLeaving, boolean dontReport, boolean autoEnteringPip)47 public PauseActivityItem(@NonNull IBinder activityToken, boolean finished, 48 boolean userLeaving, boolean dontReport, boolean autoEnteringPip) { 49 super(activityToken); 50 mFinished = finished; 51 mUserLeaving = userLeaving; 52 mDontReport = dontReport; 53 mAutoEnteringPip = autoEnteringPip; 54 } 55 56 @Override execute(@onNull ClientTransactionHandler client, @NonNull ActivityClientRecord r, @NonNull PendingTransactionActions pendingActions)57 public void execute(@NonNull ClientTransactionHandler client, @NonNull ActivityClientRecord r, 58 @NonNull PendingTransactionActions pendingActions) { 59 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); 60 client.handlePauseActivity(r, mFinished, mUserLeaving, mAutoEnteringPip, 61 pendingActions, "PAUSE_ACTIVITY_ITEM"); 62 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); 63 } 64 65 @Override getTargetState()66 public int getTargetState() { 67 return ON_PAUSE; 68 } 69 70 @Override postExecute(@onNull ClientTransactionHandler client, @NonNull PendingTransactionActions pendingActions)71 public void postExecute(@NonNull ClientTransactionHandler client, 72 @NonNull PendingTransactionActions pendingActions) { 73 if (mDontReport) { 74 return; 75 } 76 // TODO(lifecycler): Use interface callback instead of actual implementation. 77 ActivityClient.getInstance().activityPaused(getActivityToken()); 78 } 79 80 // Parcelable implementation 81 82 /** Writes to Parcel. */ 83 @Override writeToParcel(@onNull Parcel dest, int flags)84 public void writeToParcel(@NonNull Parcel dest, int flags) { 85 super.writeToParcel(dest, flags); 86 dest.writeBoolean(mFinished); 87 dest.writeBoolean(mUserLeaving); 88 dest.writeBoolean(mDontReport); 89 dest.writeBoolean(mAutoEnteringPip); 90 } 91 92 /** Reads from Parcel. */ PauseActivityItem(@onNull Parcel in)93 private PauseActivityItem(@NonNull Parcel in) { 94 super(in); 95 mFinished = in.readBoolean(); 96 mUserLeaving = in.readBoolean(); 97 mDontReport = in.readBoolean(); 98 mAutoEnteringPip = in.readBoolean(); 99 } 100 101 public static final @NonNull Creator<PauseActivityItem> CREATOR = new Creator<>() { 102 public PauseActivityItem createFromParcel(@NonNull Parcel in) { 103 return new PauseActivityItem(in); 104 } 105 106 public PauseActivityItem[] newArray(int size) { 107 return new PauseActivityItem[size]; 108 } 109 }; 110 111 @Override equals(@ullable Object o)112 public boolean equals(@Nullable Object o) { 113 if (this == o) { 114 return true; 115 } 116 if (!super.equals(o)) { 117 return false; 118 } 119 final PauseActivityItem other = (PauseActivityItem) o; 120 return mFinished == other.mFinished && mUserLeaving == other.mUserLeaving 121 && mDontReport == other.mDontReport 122 && mAutoEnteringPip == other.mAutoEnteringPip; 123 } 124 125 @Override hashCode()126 public int hashCode() { 127 int result = 17; 128 result = 31 * result + super.hashCode(); 129 result = 31 * result + (mFinished ? 1 : 0); 130 result = 31 * result + (mUserLeaving ? 1 : 0); 131 result = 31 * result + (mDontReport ? 1 : 0); 132 result = 31 * result + (mAutoEnteringPip ? 1 : 0); 133 return result; 134 } 135 136 @Override toString()137 public String toString() { 138 return "PauseActivityItem{" + super.toString() 139 + ",finished=" + mFinished 140 + ",userLeaving=" + mUserLeaving 141 + ",dontReport=" + mDontReport 142 + ",autoEnteringPip=" + mAutoEnteringPip + "}"; 143 } 144 } 145