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