Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 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.app.servertransaction.ClientTransaction; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 19 | import android.app.servertransaction.PendingTransactionActions; |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame^] | 20 | import android.app.servertransaction.TransactionExecutor; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 21 | import android.content.pm.ApplicationInfo; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 22 | import android.content.res.CompatibilityInfo; |
| 23 | import android.content.res.Configuration; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 24 | import android.os.IBinder; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 25 | import android.util.MergedConfiguration; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 26 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 27 | import com.android.internal.content.ReferrerIntent; |
| 28 | |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 29 | import java.io.PrintWriter; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 30 | import java.util.List; |
| 31 | |
| 32 | /** |
| 33 | * Defines operations that a {@link android.app.servertransaction.ClientTransaction} or its items |
| 34 | * can perform on client. |
| 35 | * @hide |
| 36 | */ |
| 37 | public abstract class ClientTransactionHandler { |
| 38 | |
| 39 | // Schedule phase related logic and handlers. |
| 40 | |
| 41 | /** Prepare and schedule transaction for execution. */ |
| 42 | void scheduleTransaction(ClientTransaction transaction) { |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 43 | transaction.preExecute(this); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 44 | sendMessage(ActivityThread.H.EXECUTE_TRANSACTION, transaction); |
| 45 | } |
| 46 | |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame^] | 47 | /** |
| 48 | * Execute transaction immediately without scheduling it. This is used for local requests, so |
| 49 | * it will also recycle the transaction. |
| 50 | */ |
| 51 | void executeTransaction(ClientTransaction transaction) { |
| 52 | transaction.preExecute(this); |
| 53 | getTransactionExecutor().execute(transaction); |
| 54 | transaction.recycle(); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Get the {@link TransactionExecutor} that will be performing lifecycle transitions and |
| 59 | * callbacks for activities. |
| 60 | */ |
| 61 | abstract TransactionExecutor getTransactionExecutor(); |
| 62 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 63 | abstract void sendMessage(int what, Object obj); |
| 64 | |
| 65 | |
| 66 | // Prepare phase related logic and handlers. Methods that inform about about pending changes or |
| 67 | // do other internal bookkeeping. |
| 68 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 69 | /** Set pending config in case it will be updated by other transaction item. */ |
| 70 | public abstract void updatePendingConfiguration(Configuration config); |
| 71 | |
| 72 | /** Set current process state. */ |
| 73 | public abstract void updateProcessState(int processState, boolean fromIpc); |
| 74 | |
| 75 | |
| 76 | // Execute phase related logic and handlers. Methods here execute actual lifecycle transactions |
| 77 | // and deliver callbacks. |
| 78 | |
| 79 | /** Destroy the activity. */ |
| 80 | public abstract void handleDestroyActivity(IBinder token, boolean finishing, int configChanges, |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 81 | boolean getNonConfigInstance, String reason); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 82 | |
| 83 | /** Pause the activity. */ |
| 84 | public abstract void handlePauseActivity(IBinder token, boolean finished, boolean userLeaving, |
Andrii Kulian | a6176e3 | 2018-02-27 11:51:18 -0800 | [diff] [blame] | 85 | int configChanges, PendingTransactionActions pendingActions, String reason); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 86 | |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 87 | /** |
| 88 | * Resume the activity. |
| 89 | * @param token Target activity token. |
| 90 | * @param finalStateRequest Flag indicating if this call is handling final lifecycle state |
| 91 | * request for a transaction. |
| 92 | * @param isForward Flag indicating if next transition is forward. |
| 93 | * @param reason Reason for performing this operation. |
| 94 | */ |
| 95 | public abstract void handleResumeActivity(IBinder token, boolean finalStateRequest, |
| 96 | boolean isForward, String reason); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 97 | |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 98 | /** |
| 99 | * Stop the activity. |
| 100 | * @param token Target activity token. |
| 101 | * @param show Flag indicating whether activity is still shown. |
| 102 | * @param configChanges Activity configuration changes. |
| 103 | * @param pendingActions Pending actions to be used on this or later stages of activity |
| 104 | * transaction. |
| 105 | * @param finalStateRequest Flag indicating if this call is handling final lifecycle state |
| 106 | * request for a transaction. |
| 107 | * @param reason Reason for performing this operation. |
| 108 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 109 | public abstract void handleStopActivity(IBinder token, boolean show, int configChanges, |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 110 | PendingTransactionActions pendingActions, boolean finalStateRequest, String reason); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 111 | |
| 112 | /** Report that activity was stopped to server. */ |
| 113 | public abstract void reportStop(PendingTransactionActions pendingActions); |
| 114 | |
| 115 | /** Restart the activity after it was stopped. */ |
| 116 | public abstract void performRestartActivity(IBinder token, boolean start); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 117 | |
| 118 | /** Deliver activity (override) configuration change. */ |
| 119 | public abstract void handleActivityConfigurationChanged(IBinder activityToken, |
| 120 | Configuration overrideConfig, int displayId); |
| 121 | |
| 122 | /** Deliver result from another activity. */ |
| 123 | public abstract void handleSendResult(IBinder token, List<ResultInfo> results); |
| 124 | |
| 125 | /** Deliver multi-window mode change notification. */ |
| 126 | public abstract void handleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode, |
| 127 | Configuration overrideConfig); |
| 128 | |
| 129 | /** Deliver new intent. */ |
| 130 | public abstract void handleNewIntent(IBinder token, List<ReferrerIntent> intents, |
| 131 | boolean andPause); |
| 132 | |
| 133 | /** Deliver picture-in-picture mode change notification. */ |
| 134 | public abstract void handlePictureInPictureModeChanged(IBinder token, boolean isInPipMode, |
| 135 | Configuration overrideConfig); |
| 136 | |
| 137 | /** Update window visibility. */ |
| 138 | public abstract void handleWindowVisibility(IBinder token, boolean show); |
| 139 | |
| 140 | /** Perform activity launch. */ |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 141 | public abstract Activity handleLaunchActivity(ActivityThread.ActivityClientRecord r, |
| 142 | PendingTransactionActions pendingActions); |
| 143 | |
| 144 | /** Perform activity start. */ |
| 145 | public abstract void handleStartActivity(ActivityThread.ActivityClientRecord r, |
| 146 | PendingTransactionActions pendingActions); |
| 147 | |
| 148 | /** Get package info. */ |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 149 | public abstract LoadedApk getPackageInfoNoCheck(ApplicationInfo ai, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 150 | CompatibilityInfo compatInfo); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 151 | |
| 152 | /** Deliver app configuration change notification. */ |
| 153 | public abstract void handleConfigurationChanged(Configuration config); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 154 | |
| 155 | /** |
| 156 | * Get {@link android.app.ActivityThread.ActivityClientRecord} instance that corresponds to the |
| 157 | * provided token. |
| 158 | */ |
| 159 | public abstract ActivityThread.ActivityClientRecord getActivityClient(IBinder token); |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 160 | |
| 161 | /** |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 162 | * Prepare activity relaunch to update internal bookkeeping. This is used to track multiple |
| 163 | * relaunch and config update requests. |
| 164 | * @param token Activity token. |
| 165 | * @param pendingResults Activity results to be delivered. |
| 166 | * @param pendingNewIntents New intent messages to be delivered. |
| 167 | * @param configChanges Mask of configuration changes that have occurred. |
| 168 | * @param config New configuration applied to the activity. |
| 169 | * @param preserveWindow Whether the activity should try to reuse the window it created, |
| 170 | * including the decor view after the relaunch. |
| 171 | * @return An initialized instance of {@link ActivityThread.ActivityClientRecord} to use during |
| 172 | * relaunch, or {@code null} if relaunch cancelled. |
| 173 | */ |
| 174 | public abstract ActivityThread.ActivityClientRecord prepareRelaunchActivity(IBinder token, |
| 175 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
| 176 | int configChanges, MergedConfiguration config, boolean preserveWindow); |
| 177 | |
| 178 | /** |
| 179 | * Perform activity relaunch. |
| 180 | * @param r Activity client record prepared for relaunch. |
| 181 | * @param pendingActions Pending actions to be used on later stages of activity transaction. |
| 182 | * */ |
| 183 | public abstract void handleRelaunchActivity(ActivityThread.ActivityClientRecord r, |
| 184 | PendingTransactionActions pendingActions); |
| 185 | |
| 186 | /** |
| 187 | * Report that relaunch request was handled. |
| 188 | * @param token Target activity token. |
| 189 | * @param pendingActions Pending actions initialized on earlier stages of activity transaction. |
| 190 | * Used to check if we should report relaunch to WM. |
| 191 | * */ |
| 192 | public abstract void reportRelaunch(IBinder token, PendingTransactionActions pendingActions); |
| 193 | |
| 194 | /** |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 195 | * Debugging output. |
| 196 | * @param pw {@link PrintWriter} to write logs to. |
| 197 | * @param prefix Prefix to prepend to output. |
| 198 | */ |
| 199 | public abstract void dump(PrintWriter pw, String prefix); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 200 | } |