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