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.app.ClientTransactionHandler; 22 import android.os.IBinder; 23 import android.os.Parcel; 24 import android.os.Trace; 25 26 /** 27 * Request to destroy an activity. 28 * @hide 29 */ 30 public class DestroyActivityItem extends ActivityLifecycleItem { 31 32 private boolean mFinished; 33 private int mConfigChanges; 34 35 @Override preExecute(ClientTransactionHandler client, IBinder token)36 public void preExecute(ClientTransactionHandler client, IBinder token) { 37 client.getActivitiesToBeDestroyed().put(token, this); 38 } 39 40 @Override execute(ClientTransactionHandler client, IBinder token, PendingTransactionActions pendingActions)41 public void execute(ClientTransactionHandler client, IBinder token, 42 PendingTransactionActions pendingActions) { 43 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityDestroy"); 44 client.handleDestroyActivity(token, mFinished, mConfigChanges, 45 false /* getNonConfigInstance */, "DestroyActivityItem"); 46 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); 47 } 48 49 @Override getTargetState()50 public int getTargetState() { 51 return ON_DESTROY; 52 } 53 54 55 // ObjectPoolItem implementation 56 DestroyActivityItem()57 private DestroyActivityItem() {} 58 59 /** Obtain an instance initialized with provided params. */ obtain(boolean finished, int configChanges)60 public static DestroyActivityItem obtain(boolean finished, int configChanges) { 61 DestroyActivityItem instance = ObjectPool.obtain(DestroyActivityItem.class); 62 if (instance == null) { 63 instance = new DestroyActivityItem(); 64 } 65 instance.mFinished = finished; 66 instance.mConfigChanges = configChanges; 67 68 return instance; 69 } 70 71 @Override recycle()72 public void recycle() { 73 super.recycle(); 74 mFinished = false; 75 mConfigChanges = 0; 76 ObjectPool.recycle(this); 77 } 78 79 80 // Parcelable implementation 81 82 /** Write to Parcel. */ 83 @Override writeToParcel(Parcel dest, int flags)84 public void writeToParcel(Parcel dest, int flags) { 85 dest.writeBoolean(mFinished); 86 dest.writeInt(mConfigChanges); 87 } 88 89 /** Read from Parcel. */ DestroyActivityItem(Parcel in)90 private DestroyActivityItem(Parcel in) { 91 mFinished = in.readBoolean(); 92 mConfigChanges = in.readInt(); 93 } 94 95 public static final @android.annotation.NonNull Creator<DestroyActivityItem> CREATOR = 96 new Creator<DestroyActivityItem>() { 97 public DestroyActivityItem createFromParcel(Parcel in) { 98 return new DestroyActivityItem(in); 99 } 100 101 public DestroyActivityItem[] newArray(int size) { 102 return new DestroyActivityItem[size]; 103 } 104 }; 105 106 @Override equals(Object o)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 DestroyActivityItem other = (DestroyActivityItem) o; 115 return mFinished == other.mFinished && mConfigChanges == other.mConfigChanges; 116 } 117 118 @Override hashCode()119 public int hashCode() { 120 int result = 17; 121 result = 31 * result + (mFinished ? 1 : 0); 122 result = 31 * result + mConfigChanges; 123 return result; 124 } 125 126 @Override toString()127 public String toString() { 128 return "DestroyActivityItem{finished=" + mFinished + ",mConfigChanges=" 129 + mConfigChanges + "}"; 130 } 131 } 132