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