blob: 07dbb6bee9fdd6f83f9be3701c29e640028b081d [file] [log] [blame]
Andrii Kulian446e8242017-10-26 15:17:29 -07001/*
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 */
16package android.app;
17
18import android.app.servertransaction.ClientTransaction;
Riddle Hsud3062cb2018-06-30 02:06:42 +080019import android.app.servertransaction.ClientTransactionItem;
Andrii Kulian88e05cb2017-12-05 17:21:10 -080020import android.app.servertransaction.PendingTransactionActions;
Andrii Kulian914aa7d2018-03-19 21:51:53 -070021import android.app.servertransaction.TransactionExecutor;
Andrii Kulian770c4032018-05-02 18:40:59 -070022import android.content.Intent;
Andrii Kulian88e05cb2017-12-05 17:21:10 -080023import android.content.pm.ApplicationInfo;
Andrii Kulian446e8242017-10-26 15:17:29 -070024import android.content.res.CompatibilityInfo;
25import android.content.res.Configuration;
Andrii Kulian446e8242017-10-26 15:17:29 -070026import android.os.IBinder;
Andrii Kulianb372da62018-01-18 10:46:24 -080027import android.util.MergedConfiguration;
Andrii Kulian446e8242017-10-26 15:17:29 -070028
Andrii Kuliand9e2acb2018-03-29 16:07:11 -070029import com.android.internal.annotations.VisibleForTesting;
Andrii Kulian446e8242017-10-26 15:17:29 -070030import com.android.internal.content.ReferrerIntent;
31
32import java.util.List;
Riddle Hsud3062cb2018-06-30 02:06:42 +080033import java.util.Map;
Andrii Kulian446e8242017-10-26 15:17:29 -070034
35/**
36 * Defines operations that a {@link android.app.servertransaction.ClientTransaction} or its items
37 * can perform on client.
38 * @hide
39 */
40public abstract class ClientTransactionHandler {
41
42 // Schedule phase related logic and handlers.
43
44 /** Prepare and schedule transaction for execution. */
45 void scheduleTransaction(ClientTransaction transaction) {
Andrii Kulian88e05cb2017-12-05 17:21:10 -080046 transaction.preExecute(this);
Andrii Kulian446e8242017-10-26 15:17:29 -070047 sendMessage(ActivityThread.H.EXECUTE_TRANSACTION, transaction);
48 }
49
Andrii Kulian914aa7d2018-03-19 21:51:53 -070050 /**
51 * Execute transaction immediately without scheduling it. This is used for local requests, so
52 * it will also recycle the transaction.
53 */
Andrii Kuliand9e2acb2018-03-29 16:07:11 -070054 @VisibleForTesting
55 public void executeTransaction(ClientTransaction transaction) {
Andrii Kulian914aa7d2018-03-19 21:51:53 -070056 transaction.preExecute(this);
57 getTransactionExecutor().execute(transaction);
58 transaction.recycle();
59 }
60
61 /**
62 * Get the {@link TransactionExecutor} that will be performing lifecycle transitions and
63 * callbacks for activities.
64 */
65 abstract TransactionExecutor getTransactionExecutor();
66
Andrii Kulian446e8242017-10-26 15:17:29 -070067 abstract void sendMessage(int what, Object obj);
68
Andrii Kuliand56ed0c2018-06-14 12:22:18 -070069 /** Get activity instance for the token. */
70 public abstract Activity getActivity(IBinder token);
Andrii Kulian446e8242017-10-26 15:17:29 -070071
72 // Prepare phase related logic and handlers. Methods that inform about about pending changes or
73 // do other internal bookkeeping.
74
Andrii Kulian446e8242017-10-26 15:17:29 -070075 /** Set pending config in case it will be updated by other transaction item. */
76 public abstract void updatePendingConfiguration(Configuration config);
77
78 /** Set current process state. */
79 public abstract void updateProcessState(int processState, boolean fromIpc);
80
81
82 // Execute phase related logic and handlers. Methods here execute actual lifecycle transactions
83 // and deliver callbacks.
84
Riddle Hsud3062cb2018-06-30 02:06:42 +080085 /** Get activity and its corresponding transaction item which are going to destroy. */
86 public abstract Map<IBinder, ClientTransactionItem> getActivitiesToBeDestroyed();
87
Andrii Kulian446e8242017-10-26 15:17:29 -070088 /** Destroy the activity. */
89 public abstract void handleDestroyActivity(IBinder token, boolean finishing, int configChanges,
Bryce Leea33c13d2018-02-08 14:37:06 -080090 boolean getNonConfigInstance, String reason);
Andrii Kulian446e8242017-10-26 15:17:29 -070091
92 /** Pause the activity. */
93 public abstract void handlePauseActivity(IBinder token, boolean finished, boolean userLeaving,
Andrii Kuliana6176e32018-02-27 11:51:18 -080094 int configChanges, PendingTransactionActions pendingActions, String reason);
Andrii Kulian446e8242017-10-26 15:17:29 -070095
Andrii Kuliandfbf9712018-03-08 15:42:24 -080096 /**
97 * Resume the activity.
98 * @param token Target activity token.
99 * @param finalStateRequest Flag indicating if this call is handling final lifecycle state
100 * request for a transaction.
101 * @param isForward Flag indicating if next transition is forward.
102 * @param reason Reason for performing this operation.
103 */
104 public abstract void handleResumeActivity(IBinder token, boolean finalStateRequest,
105 boolean isForward, String reason);
Andrii Kulian446e8242017-10-26 15:17:29 -0700106
Andrii Kulian829829c2018-03-19 18:19:05 -0700107 /**
108 * Stop the activity.
109 * @param token Target activity token.
110 * @param show Flag indicating whether activity is still shown.
111 * @param configChanges Activity configuration changes.
112 * @param pendingActions Pending actions to be used on this or later stages of activity
113 * transaction.
114 * @param finalStateRequest Flag indicating if this call is handling final lifecycle state
115 * request for a transaction.
116 * @param reason Reason for performing this operation.
117 */
Andrii Kulian446e8242017-10-26 15:17:29 -0700118 public abstract void handleStopActivity(IBinder token, boolean show, int configChanges,
Andrii Kulian829829c2018-03-19 18:19:05 -0700119 PendingTransactionActions pendingActions, boolean finalStateRequest, String reason);
Andrii Kulian88e05cb2017-12-05 17:21:10 -0800120
121 /** Report that activity was stopped to server. */
122 public abstract void reportStop(PendingTransactionActions pendingActions);
123
124 /** Restart the activity after it was stopped. */
125 public abstract void performRestartActivity(IBinder token, boolean start);
Andrii Kulian446e8242017-10-26 15:17:29 -0700126
Garfield Tan0443b372019-01-04 15:00:13 -0800127 /** Set pending activity configuration in case it will be updated by other transaction item. */
128 public abstract void updatePendingActivityConfiguration(IBinder activityToken,
129 Configuration overrideConfig);
130
Andrii Kulian446e8242017-10-26 15:17:29 -0700131 /** Deliver activity (override) configuration change. */
132 public abstract void handleActivityConfigurationChanged(IBinder activityToken,
133 Configuration overrideConfig, int displayId);
134
135 /** Deliver result from another activity. */
Andrii Kuliane55b0092018-04-19 15:29:22 -0700136 public abstract void handleSendResult(IBinder token, List<ResultInfo> results, String reason);
Andrii Kulian446e8242017-10-26 15:17:29 -0700137
138 /** Deliver multi-window mode change notification. */
139 public abstract void handleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode,
140 Configuration overrideConfig);
141
142 /** Deliver new intent. */
143 public abstract void handleNewIntent(IBinder token, List<ReferrerIntent> intents,
144 boolean andPause);
145
146 /** Deliver picture-in-picture mode change notification. */
147 public abstract void handlePictureInPictureModeChanged(IBinder token, boolean isInPipMode,
148 Configuration overrideConfig);
149
150 /** Update window visibility. */
151 public abstract void handleWindowVisibility(IBinder token, boolean show);
152
153 /** Perform activity launch. */
Andrii Kulian88e05cb2017-12-05 17:21:10 -0800154 public abstract Activity handleLaunchActivity(ActivityThread.ActivityClientRecord r,
Andrii Kulian770c4032018-05-02 18:40:59 -0700155 PendingTransactionActions pendingActions, Intent customIntent);
Andrii Kulian88e05cb2017-12-05 17:21:10 -0800156
157 /** Perform activity start. */
158 public abstract void handleStartActivity(ActivityThread.ActivityClientRecord r,
159 PendingTransactionActions pendingActions);
160
161 /** Get package info. */
Todd Kennedy233a0b12018-01-29 20:30:24 +0000162 public abstract LoadedApk getPackageInfoNoCheck(ApplicationInfo ai,
Andrii Kulian88e05cb2017-12-05 17:21:10 -0800163 CompatibilityInfo compatInfo);
Andrii Kulian446e8242017-10-26 15:17:29 -0700164
165 /** Deliver app configuration change notification. */
166 public abstract void handleConfigurationChanged(Configuration config);
Andrii Kulian88e05cb2017-12-05 17:21:10 -0800167
168 /**
169 * Get {@link android.app.ActivityThread.ActivityClientRecord} instance that corresponds to the
170 * provided token.
171 */
172 public abstract ActivityThread.ActivityClientRecord getActivityClient(IBinder token);
Bryce Leed946f862018-01-16 15:59:47 -0800173
174 /**
Andrii Kulianb372da62018-01-18 10:46:24 -0800175 * Prepare activity relaunch to update internal bookkeeping. This is used to track multiple
176 * relaunch and config update requests.
177 * @param token Activity token.
178 * @param pendingResults Activity results to be delivered.
179 * @param pendingNewIntents New intent messages to be delivered.
180 * @param configChanges Mask of configuration changes that have occurred.
181 * @param config New configuration applied to the activity.
182 * @param preserveWindow Whether the activity should try to reuse the window it created,
183 * including the decor view after the relaunch.
184 * @return An initialized instance of {@link ActivityThread.ActivityClientRecord} to use during
185 * relaunch, or {@code null} if relaunch cancelled.
186 */
187 public abstract ActivityThread.ActivityClientRecord prepareRelaunchActivity(IBinder token,
188 List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents,
189 int configChanges, MergedConfiguration config, boolean preserveWindow);
190
191 /**
192 * Perform activity relaunch.
193 * @param r Activity client record prepared for relaunch.
194 * @param pendingActions Pending actions to be used on later stages of activity transaction.
195 * */
196 public abstract void handleRelaunchActivity(ActivityThread.ActivityClientRecord r,
197 PendingTransactionActions pendingActions);
198
199 /**
200 * Report that relaunch request was handled.
201 * @param token Target activity token.
202 * @param pendingActions Pending actions initialized on earlier stages of activity transaction.
203 * Used to check if we should report relaunch to WM.
204 * */
205 public abstract void reportRelaunch(IBinder token, PendingTransactionActions pendingActions);
Andrii Kulian446e8242017-10-26 15:17:29 -0700206}