• 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 package android.app;
17 
18 import android.annotation.NonNull;
19 import android.app.ActivityThread.ActivityClientRecord;
20 import android.app.servertransaction.ClientTransaction;
21 import android.app.servertransaction.ClientTransactionItem;
22 import android.app.servertransaction.PendingTransactionActions;
23 import android.app.servertransaction.TransactionExecutor;
24 import android.content.Intent;
25 import android.content.pm.ApplicationInfo;
26 import android.content.res.Configuration;
27 import android.os.IBinder;
28 import android.util.MergedConfiguration;
29 import android.view.SurfaceControl;
30 import android.window.SplashScreenView.SplashScreenViewParcelable;
31 
32 import com.android.internal.annotations.VisibleForTesting;
33 import com.android.internal.content.ReferrerIntent;
34 
35 import java.util.List;
36 import java.util.Map;
37 
38 /**
39  * Defines operations that a {@link android.app.servertransaction.ClientTransaction} or its items
40  * can perform on client.
41  * @hide
42  */
43 public abstract class ClientTransactionHandler {
44 
45     private boolean mIsExecutingLocalTransaction;
46 
47     // Schedule phase related logic and handlers.
48 
49     /** Prepare and schedule transaction for execution. */
scheduleTransaction(ClientTransaction transaction)50     void scheduleTransaction(ClientTransaction transaction) {
51         transaction.preExecute(this);
52         sendMessage(ActivityThread.H.EXECUTE_TRANSACTION, transaction);
53     }
54 
55     /**
56      * Execute transaction immediately without scheduling it. This is used for local requests, so
57      * it will also recycle the transaction.
58      */
59     @VisibleForTesting
executeTransaction(ClientTransaction transaction)60     public void executeTransaction(ClientTransaction transaction) {
61         mIsExecutingLocalTransaction = true;
62         try {
63             transaction.preExecute(this);
64             getTransactionExecutor().execute(transaction);
65         } finally {
66             mIsExecutingLocalTransaction = false;
67             transaction.recycle();
68         }
69     }
70 
71     /** Returns {@code true} if the current executing ClientTransaction is from local request. */
isExecutingLocalTransaction()72     public boolean isExecutingLocalTransaction() {
73         return mIsExecutingLocalTransaction;
74     }
75 
76     /**
77      * Get the {@link TransactionExecutor} that will be performing lifecycle transitions and
78      * callbacks for activities.
79      */
getTransactionExecutor()80     abstract TransactionExecutor getTransactionExecutor();
81 
sendMessage(int what, Object obj)82     abstract void sendMessage(int what, Object obj);
83 
84     /** Get activity instance for the token. */
getActivity(IBinder token)85     public abstract Activity getActivity(IBinder token);
86 
87     // Prepare phase related logic and handlers. Methods that inform about about pending changes or
88     // do other internal bookkeeping.
89 
90     /** Set pending config in case it will be updated by other transaction item. */
updatePendingConfiguration(Configuration config)91     public abstract void updatePendingConfiguration(Configuration config);
92 
93     /** Set current process state. */
updateProcessState(int processState, boolean fromIpc)94     public abstract void updateProcessState(int processState, boolean fromIpc);
95 
96     /** Count how many activities are launching. */
countLaunchingActivities(int num)97     public abstract void countLaunchingActivities(int num);
98 
99     // Execute phase related logic and handlers. Methods here execute actual lifecycle transactions
100     // and deliver callbacks.
101 
102     /** Get activity and its corresponding transaction item which are going to destroy. */
getActivitiesToBeDestroyed()103     public abstract Map<IBinder, ClientTransactionItem> getActivitiesToBeDestroyed();
104 
105     /** Destroy the activity. */
handleDestroyActivity(@onNull ActivityClientRecord r, boolean finishing, int configChanges, boolean getNonConfigInstance, String reason)106     public abstract void handleDestroyActivity(@NonNull ActivityClientRecord r, boolean finishing,
107             int configChanges, boolean getNonConfigInstance, String reason);
108 
109     /** Pause the activity. */
handlePauseActivity(@onNull ActivityClientRecord r, boolean finished, boolean userLeaving, int configChanges, boolean autoEnteringPip, PendingTransactionActions pendingActions, String reason)110     public abstract void handlePauseActivity(@NonNull ActivityClientRecord r, boolean finished,
111             boolean userLeaving, int configChanges, boolean autoEnteringPip,
112             PendingTransactionActions pendingActions, String reason);
113 
114     /**
115      * Resume the activity.
116      * @param r Target activity record.
117      * @param finalStateRequest Flag indicating if this call is handling final lifecycle state
118      *                          request for a transaction.
119      * @param isForward Flag indicating if next transition is forward.
120      * @param reason Reason for performing this operation.
121      */
handleResumeActivity(@onNull ActivityClientRecord r, boolean finalStateRequest, boolean isForward, boolean shouldSendCompatFakeFocus, String reason)122     public abstract void handleResumeActivity(@NonNull ActivityClientRecord r,
123             boolean finalStateRequest, boolean isForward, boolean shouldSendCompatFakeFocus,
124             String reason);
125 
126     /**
127      * Notify the activity about top resumed state change.
128      * @param r Target activity record.
129      * @param isTopResumedActivity Current state of the activity, {@code true} if it's the
130      *                             topmost resumed activity in the system, {@code false} otherwise.
131      * @param reason Reason for performing this operation.
132      */
handleTopResumedActivityChanged(@onNull ActivityClientRecord r, boolean isTopResumedActivity, String reason)133     public abstract void handleTopResumedActivityChanged(@NonNull ActivityClientRecord r,
134             boolean isTopResumedActivity, String reason);
135 
136     /**
137      * Stop the activity.
138      * @param r Target activity record.
139      * @param configChanges Activity configuration changes.
140      * @param pendingActions Pending actions to be used on this or later stages of activity
141      *                       transaction.
142      * @param finalStateRequest Flag indicating if this call is handling final lifecycle state
143      *                          request for a transaction.
144      * @param reason Reason for performing this operation.
145      */
handleStopActivity(@onNull ActivityClientRecord r, int configChanges, PendingTransactionActions pendingActions, boolean finalStateRequest, String reason)146     public abstract void handleStopActivity(@NonNull ActivityClientRecord r, int configChanges,
147             PendingTransactionActions pendingActions, boolean finalStateRequest, String reason);
148 
149     /** Report that activity was stopped to server. */
reportStop(PendingTransactionActions pendingActions)150     public abstract void reportStop(PendingTransactionActions pendingActions);
151 
152     /** Restart the activity after it was stopped. */
performRestartActivity(@onNull ActivityClientRecord r, boolean start)153     public abstract void performRestartActivity(@NonNull ActivityClientRecord r, boolean start);
154 
155      /** Report that activity was refreshed to server. */
reportRefresh(@onNull ActivityClientRecord r)156     public abstract void reportRefresh(@NonNull ActivityClientRecord r);
157 
158     /** Set pending activity configuration in case it will be updated by other transaction item. */
updatePendingActivityConfiguration(@onNull IBinder token, Configuration overrideConfig)159     public abstract void updatePendingActivityConfiguration(@NonNull IBinder token,
160             Configuration overrideConfig);
161 
162     /** Deliver activity (override) configuration change. */
handleActivityConfigurationChanged(@onNull ActivityClientRecord r, Configuration overrideConfig, int displayId)163     public abstract void handleActivityConfigurationChanged(@NonNull ActivityClientRecord r,
164             Configuration overrideConfig, int displayId);
165 
166     /** Deliver result from another activity. */
handleSendResult( @onNull ActivityClientRecord r, List<ResultInfo> results, String reason)167     public abstract void handleSendResult(
168             @NonNull ActivityClientRecord r, List<ResultInfo> results, String reason);
169 
170     /** Deliver new intent. */
handleNewIntent( @onNull ActivityClientRecord r, List<ReferrerIntent> intents)171     public abstract void handleNewIntent(
172             @NonNull ActivityClientRecord r, List<ReferrerIntent> intents);
173 
174     /** Request that an activity enter picture-in-picture. */
handlePictureInPictureRequested(@onNull ActivityClientRecord r)175     public abstract void handlePictureInPictureRequested(@NonNull ActivityClientRecord r);
176 
177     /** Signal to an activity (that is currently in PiP) of PiP state changes. */
handlePictureInPictureStateChanged(@onNull ActivityClientRecord r, PictureInPictureUiState pipState)178     public abstract void handlePictureInPictureStateChanged(@NonNull ActivityClientRecord r,
179             PictureInPictureUiState pipState);
180 
181     /** Whether the activity want to handle splash screen exit animation */
isHandleSplashScreenExit(@onNull IBinder token)182     public abstract boolean isHandleSplashScreenExit(@NonNull IBinder token);
183 
184     /** Attach a splash screen window view to the top of the activity */
handleAttachSplashScreenView(@onNull ActivityClientRecord r, @NonNull SplashScreenViewParcelable parcelable, @NonNull SurfaceControl startingWindowLeash)185     public abstract void handleAttachSplashScreenView(@NonNull ActivityClientRecord r,
186             @NonNull SplashScreenViewParcelable parcelable,
187             @NonNull SurfaceControl startingWindowLeash);
188 
189     /** Perform activity launch. */
handleLaunchActivity(@onNull ActivityClientRecord r, PendingTransactionActions pendingActions, int deviceId, Intent customIntent)190     public abstract Activity handleLaunchActivity(@NonNull ActivityClientRecord r,
191             PendingTransactionActions pendingActions, int deviceId, Intent customIntent);
192 
193     /** Perform activity start. */
handleStartActivity(@onNull ActivityClientRecord r, PendingTransactionActions pendingActions, ActivityOptions activityOptions)194     public abstract void handleStartActivity(@NonNull ActivityClientRecord r,
195             PendingTransactionActions pendingActions, ActivityOptions activityOptions);
196 
197     /** Get package info. */
getPackageInfoNoCheck(ApplicationInfo ai)198     public abstract LoadedApk getPackageInfoNoCheck(ApplicationInfo ai);
199 
200     /** Deliver app configuration change notification and device association. */
handleConfigurationChanged(Configuration config, int deviceId)201     public abstract void handleConfigurationChanged(Configuration config, int deviceId);
202 
203     /**
204      * Get {@link android.app.ActivityThread.ActivityClientRecord} instance that corresponds to the
205      * provided token.
206      */
getActivityClient(IBinder token)207     public abstract ActivityClientRecord getActivityClient(IBinder token);
208 
209     /**
210      * Prepare activity relaunch to update internal bookkeeping. This is used to track multiple
211      * relaunch and config update requests.
212      * @param token Activity token.
213      * @param pendingResults Activity results to be delivered.
214      * @param pendingNewIntents New intent messages to be delivered.
215      * @param configChanges Mask of configuration changes that have occurred.
216      * @param config New configuration applied to the activity.
217      * @param preserveWindow Whether the activity should try to reuse the window it created,
218      *                        including the decor view after the relaunch.
219      * @return An initialized instance of {@link ActivityThread.ActivityClientRecord} to use during
220      *         relaunch, or {@code null} if relaunch cancelled.
221      */
prepareRelaunchActivity(IBinder token, List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, int configChanges, MergedConfiguration config, boolean preserveWindow)222     public abstract ActivityClientRecord prepareRelaunchActivity(IBinder token,
223             List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents,
224             int configChanges, MergedConfiguration config, boolean preserveWindow);
225 
226     /**
227      * Perform activity relaunch.
228      * @param r Activity client record prepared for relaunch.
229      * @param pendingActions Pending actions to be used on later stages of activity transaction.
230      * */
handleRelaunchActivity(@onNull ActivityClientRecord r, PendingTransactionActions pendingActions)231     public abstract void handleRelaunchActivity(@NonNull ActivityClientRecord r,
232             PendingTransactionActions pendingActions);
233 
234     /**
235      * Report that relaunch request was handled.
236      * @param r Target activity record.
237      */
reportRelaunch(@onNull ActivityClientRecord r)238     public abstract void reportRelaunch(@NonNull ActivityClientRecord r);
239 }
240