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