• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.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  * Request to destroy an activity.
31  *
32  * @hide
33  */
34 public class DestroyActivityItem extends ActivityLifecycleItem {
35 
36     private final boolean mFinished;
37 
DestroyActivityItem(@onNull IBinder activityToken, boolean finished)38     public DestroyActivityItem(@NonNull IBinder activityToken, boolean finished) {
39         super(activityToken);
40         mFinished = finished;
41     }
42 
43     @Override
preExecute(@onNull ClientTransactionHandler client)44     public void preExecute(@NonNull ClientTransactionHandler client) {
45         client.getActivitiesToBeDestroyed().put(getActivityToken(), this);
46     }
47 
48     @Override
execute(@onNull ClientTransactionHandler client, @NonNull ActivityClientRecord r, @NonNull PendingTransactionActions pendingActions)49     public void execute(@NonNull ClientTransactionHandler client, @NonNull ActivityClientRecord r,
50             @NonNull PendingTransactionActions pendingActions) {
51         Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityDestroy");
52         client.handleDestroyActivity(r, mFinished,
53                 false /* getNonConfigInstance */, "DestroyActivityItem");
54         Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
55     }
56 
57     @Override
postExecute(@onNull ClientTransactionHandler client, @NonNull PendingTransactionActions pendingActions)58     public void postExecute(@NonNull ClientTransactionHandler client,
59             @NonNull PendingTransactionActions pendingActions) {
60         // Cleanup after execution.
61         client.getActivitiesToBeDestroyed().remove(getActivityToken());
62     }
63 
64     @Override
getTargetState()65     public int getTargetState() {
66         return ON_DESTROY;
67     }
68 
69     // Parcelable implementation
70 
71     /** Writes to Parcel. */
72     @Override
writeToParcel(@onNull Parcel dest, int flags)73     public void writeToParcel(@NonNull Parcel dest, int flags) {
74         super.writeToParcel(dest, flags);
75         dest.writeBoolean(mFinished);
76     }
77 
78     /** Reads from Parcel. */
DestroyActivityItem(@onNull Parcel in)79     private DestroyActivityItem(@NonNull Parcel in) {
80         super(in);
81         mFinished = in.readBoolean();
82     }
83 
84     public static final @NonNull Creator<DestroyActivityItem> CREATOR = new Creator<>() {
85         public DestroyActivityItem createFromParcel(@NonNull Parcel in) {
86             return new DestroyActivityItem(in);
87         }
88 
89         public DestroyActivityItem[] newArray(int size) {
90             return new DestroyActivityItem[size];
91         }
92     };
93 
94     @Override
equals(@ullable Object o)95     public boolean equals(@Nullable Object o) {
96         if (this == o) {
97             return true;
98         }
99         if (!super.equals(o)) {
100             return false;
101         }
102         final DestroyActivityItem other = (DestroyActivityItem) o;
103         return mFinished == other.mFinished;
104     }
105 
106     @Override
hashCode()107     public int hashCode() {
108         int result = 17;
109         result = 31 * result + super.hashCode();
110         result = 31 * result + (mFinished ? 1 : 0);
111         return result;
112     }
113 
114     @Override
toString()115     public String toString() {
116         return "DestroyActivityItem{" + super.toString()
117                 + ",finished=" + mFinished + "}";
118     }
119 }
120