• 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.ActivityClient;
24 import android.app.ActivityManager;
25 import android.app.ActivityManager.ProcessState;
26 import android.app.ActivityThread.ActivityClientRecord;
27 import android.app.ClientTransactionHandler;
28 import android.os.IBinder;
29 import android.os.Parcel;
30 import android.os.Trace;
31 
32 /**
33  * Request to move an activity to resumed state.
34  *
35  * @hide
36  */
37 public class ResumeActivityItem extends ActivityLifecycleItem {
38 
39     @ProcessState
40     private final int mProcState;
41 
42     private final boolean mIsForward;
43 
44     // Whether we should send compat fake focus when the activity is resumed. This is needed
45     // because some game engines wait to get focus before drawing the content of the app.
46     private final boolean mShouldSendCompatFakeFocus;
47 
ResumeActivityItem(@onNull IBinder activityToken, boolean isForward, boolean shouldSendCompatFakeFocus)48     public ResumeActivityItem(@NonNull IBinder activityToken, boolean isForward,
49             boolean shouldSendCompatFakeFocus) {
50         this(activityToken, ActivityManager.PROCESS_STATE_UNKNOWN, isForward,
51                 shouldSendCompatFakeFocus);
52     }
53 
ResumeActivityItem(@onNull IBinder activityToken, @ProcessState int procState, boolean isForward, boolean shouldSendCompatFakeFocus)54     public ResumeActivityItem(@NonNull IBinder activityToken, @ProcessState int procState,
55             boolean isForward, boolean shouldSendCompatFakeFocus) {
56         super(activityToken);
57         mProcState = procState;
58         mIsForward = isForward;
59         mShouldSendCompatFakeFocus = shouldSendCompatFakeFocus;
60     }
61 
62     @Override
preExecute(@onNull ClientTransactionHandler client)63     public void preExecute(@NonNull ClientTransactionHandler client) {
64         if (mProcState != ActivityManager.PROCESS_STATE_UNKNOWN) {
65             client.updateProcessState(mProcState, false);
66         }
67     }
68 
69     @Override
execute(@onNull ClientTransactionHandler client, @NonNull ActivityClientRecord r, @NonNull PendingTransactionActions pendingActions)70     public void execute(@NonNull ClientTransactionHandler client, @NonNull ActivityClientRecord r,
71             @NonNull PendingTransactionActions pendingActions) {
72         Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityResume");
73         client.handleResumeActivity(r, true /* finalStateRequest */, mIsForward,
74                 mShouldSendCompatFakeFocus, "RESUME_ACTIVITY");
75         Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
76     }
77 
78     @Override
postExecute(@onNull ClientTransactionHandler client, @NonNull PendingTransactionActions pendingActions)79     public void postExecute(@NonNull ClientTransactionHandler client,
80             @NonNull PendingTransactionActions pendingActions) {
81         // TODO(lifecycler): Use interface callback instead of actual implementation.
82         ActivityClient.getInstance().activityResumed(getActivityToken(),
83                 client.isHandleSplashScreenExit(getActivityToken()));
84     }
85 
86     @Override
getTargetState()87     public int getTargetState() {
88         return ON_RESUME;
89     }
90 
91     // Parcelable implementation
92 
93     /** Writes to Parcel. */
94     @Override
writeToParcel(@onNull Parcel dest, int flags)95     public void writeToParcel(@NonNull Parcel dest, int flags) {
96         super.writeToParcel(dest, flags);
97         dest.writeInt(mProcState);
98         dest.writeBoolean(mIsForward);
99         dest.writeBoolean(mShouldSendCompatFakeFocus);
100     }
101 
102     /** Reads from Parcel. */
ResumeActivityItem(@onNull Parcel in)103     private ResumeActivityItem(@NonNull Parcel in) {
104         super(in);
105         mProcState = in.readInt();
106         mIsForward = in.readBoolean();
107         mShouldSendCompatFakeFocus = in.readBoolean();
108     }
109 
110     public static final @NonNull Creator<ResumeActivityItem> CREATOR = new Creator<>() {
111         public ResumeActivityItem createFromParcel(Parcel in) {
112             return new ResumeActivityItem(in);
113         }
114 
115         public ResumeActivityItem[] newArray(int size) {
116             return new ResumeActivityItem[size];
117         }
118     };
119 
120     @Override
equals(@ullable Object o)121     public boolean equals(@Nullable Object o) {
122         if (this == o) {
123             return true;
124         }
125         if (!super.equals(o)) {
126             return false;
127         }
128         final ResumeActivityItem other = (ResumeActivityItem) o;
129         return mProcState == other.mProcState
130                 && mIsForward == other.mIsForward
131                 && mShouldSendCompatFakeFocus == other.mShouldSendCompatFakeFocus;
132     }
133 
134     @Override
hashCode()135     public int hashCode() {
136         int result = 17;
137         result = 31 * result + super.hashCode();
138         result = 31 * result + mProcState;
139         result = 31 * result + (mIsForward ? 1 : 0);
140         result = 31 * result + (mShouldSendCompatFakeFocus ? 1 : 0);
141         return result;
142     }
143 
144     @Override
toString()145     public String toString() {
146         return "ResumeActivityItem{" + super.toString()
147                 + ",procState=" + mProcState
148                 + ",isForward=" + mIsForward
149                 + ",shouldSendCompatFakeFocus=" + mShouldSendCompatFakeFocus + "}";
150     }
151 }
152