| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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.ActivityThread.ActivityClientRecord; |
| 24 |
import android.app.ClientTransactionHandler; |
| 25 |
import android.os.IBinder; |
| 26 |
import android.os.Parcel; |
| 27 |
import android.os.Trace; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public class DestroyActivityItem extends ActivityLifecycleItem { |
| 34 |
|
| 35 |
private boolean mFinished; |
| 36 |
private int mConfigChanges; |
| 37 |
|
| 38 |
@Override |
| 39 |
public void preExecute(ClientTransactionHandler client, IBinder token) { |
| 40 |
client.getActivitiesToBeDestroyed().put(token, this); |
| 41 |
} |
| 42 |
|
| 43 |
@Override |
| 44 |
public void execute(ClientTransactionHandler client, ActivityClientRecord r, |
| 45 |
PendingTransactionActions pendingActions) { |
| 46 |
Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityDestroy"); |
| 47 |
client.handleDestroyActivity(r, mFinished, mConfigChanges, |
| 48 |
false , "DestroyActivityItem"); |
| 49 |
Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 50 |
} |
| 51 |
|
| 52 |
@Override |
| 53 |
public int getTargetState() { |
| 54 |
return ON_DESTROY; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
private DestroyActivityItem() {} |
| 61 |
|
| 62 |
|
| 63 |
public static DestroyActivityItem obtain(boolean finished, int configChanges) { |
| 64 |
DestroyActivityItem instance = ObjectPool.obtain(DestroyActivityItem.class); |
| 65 |
if (instance == null) { |
| 66 |
instance = new DestroyActivityItem(); |
| 67 |
} |
| 68 |
instance.mFinished = finished; |
| 69 |
instance.mConfigChanges = configChanges; |
| 70 |
|
| 71 |
return instance; |
| 72 |
} |
| 73 |
|
| 74 |
@Override |
| 75 |
public void recycle() { |
| 76 |
super.recycle(); |
| 77 |
mFinished = false; |
| 78 |
mConfigChanges = 0; |
| 79 |
ObjectPool.recycle(this); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
@Override |
| 87 |
public void writeToParcel(Parcel dest, int flags) { |
| 88 |
dest.writeBoolean(mFinished); |
| 89 |
dest.writeInt(mConfigChanges); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
private DestroyActivityItem(Parcel in) { |
| 94 |
mFinished = in.readBoolean(); |
| 95 |
mConfigChanges = in.readInt(); |
| 96 |
} |
| 97 |
|
| 98 |
public static final @NonNull Creator<DestroyActivityItem> CREATOR = |
| 99 |
new Creator<DestroyActivityItem>() { |
| 100 |
public DestroyActivityItem createFromParcel(Parcel in) { |
| 101 |
return new DestroyActivityItem(in); |
| 102 |
} |
| 103 |
|
| 104 |
public DestroyActivityItem[] newArray(int size) { |
| 105 |
return new DestroyActivityItem[size]; |
| 106 |
} |
| 107 |
}; |
| 108 |
|
| 109 |
@Override |
| 110 |
public boolean equals(@Nullable Object o) { |
| 111 |
if (this == o) { |
| 112 |
return true; |
| 113 |
} |
| 114 |
if (o == null || getClass() != o.getClass()) { |
| 115 |
return false; |
| 116 |
} |
| 117 |
final DestroyActivityItem other = (DestroyActivityItem) o; |
| 118 |
return mFinished == other.mFinished && mConfigChanges == other.mConfigChanges; |
| 119 |
} |
| 120 |
|
| 121 |
@Override |
| 122 |
public int hashCode() { |
| 123 |
int result = 17; |
| 124 |
result = 31 * result + (mFinished ? 1 : 0); |
| 125 |
result = 31 * result + mConfigChanges; |
| 126 |
return result; |
| 127 |
} |
| 128 |
|
| 129 |
@Override |
| 130 |
public String toString() { |
| 131 |
return "DestroyActivityItem{finished=" + mFinished + ",mConfigChanges=" |
| 132 |
+ mConfigChanges + "}"; |
| 133 |
} |
| 134 |
} |