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.DisplayAdjustments.FixedRotationAdjustments; 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 // Execute phase related logic and handlers. Methods here execute actual lifecycle transactions 86 // and deliver callbacks. 87 88 /** Get activity and its corresponding transaction item which are going to destroy. */ getActivitiesToBeDestroyed()89 public abstract Map<IBinder, ClientTransactionItem> getActivitiesToBeDestroyed(); 90 91 /** Destroy the activity. */ handleDestroyActivity(@onNull ActivityClientRecord r, boolean finishing, int configChanges, boolean getNonConfigInstance, String reason)92 public abstract void handleDestroyActivity(@NonNull ActivityClientRecord r, boolean finishing, 93 int configChanges, boolean getNonConfigInstance, String reason); 94 95 /** Pause the activity. */ handlePauseActivity(@onNull ActivityClientRecord r, boolean finished, boolean userLeaving, int configChanges, PendingTransactionActions pendingActions, String reason)96 public abstract void handlePauseActivity(@NonNull ActivityClientRecord r, boolean finished, 97 boolean userLeaving, int configChanges, PendingTransactionActions pendingActions, 98 String reason); 99 100 /** 101 * Resume the activity. 102 * @param r Target activity record. 103 * @param finalStateRequest Flag indicating if this call is handling final lifecycle state 104 * request for a transaction. 105 * @param isForward Flag indicating if next transition is forward. 106 * @param reason Reason for performing this operation. 107 */ handleResumeActivity(@onNull ActivityClientRecord r, boolean finalStateRequest, boolean isForward, String reason)108 public abstract void handleResumeActivity(@NonNull ActivityClientRecord r, 109 boolean finalStateRequest, boolean isForward, String reason); 110 111 /** 112 * Notify the activity about top resumed state change. 113 * @param r Target activity record. 114 * @param isTopResumedActivity Current state of the activity, {@code true} if it's the 115 * topmost resumed activity in the system, {@code false} otherwise. 116 * @param reason Reason for performing this operation. 117 */ handleTopResumedActivityChanged(@onNull ActivityClientRecord r, boolean isTopResumedActivity, String reason)118 public abstract void handleTopResumedActivityChanged(@NonNull ActivityClientRecord r, 119 boolean isTopResumedActivity, String reason); 120 121 /** 122 * Stop the activity. 123 * @param r Target activity record. 124 * @param configChanges Activity configuration changes. 125 * @param pendingActions Pending actions to be used on this or later stages of activity 126 * transaction. 127 * @param finalStateRequest Flag indicating if this call is handling final lifecycle state 128 * request for a transaction. 129 * @param reason Reason for performing this operation. 130 */ handleStopActivity(@onNull ActivityClientRecord r, int configChanges, PendingTransactionActions pendingActions, boolean finalStateRequest, String reason)131 public abstract void handleStopActivity(@NonNull ActivityClientRecord r, int configChanges, 132 PendingTransactionActions pendingActions, boolean finalStateRequest, String reason); 133 134 /** Report that activity was stopped to server. */ reportStop(PendingTransactionActions pendingActions)135 public abstract void reportStop(PendingTransactionActions pendingActions); 136 137 /** Restart the activity after it was stopped. */ performRestartActivity(@onNull ActivityClientRecord r, boolean start)138 public abstract void performRestartActivity(@NonNull ActivityClientRecord r, boolean start); 139 140 /** Set pending activity configuration in case it will be updated by other transaction item. */ updatePendingActivityConfiguration(@onNull ActivityClientRecord r, Configuration overrideConfig)141 public abstract void updatePendingActivityConfiguration(@NonNull ActivityClientRecord r, 142 Configuration overrideConfig); 143 144 /** Deliver activity (override) configuration change. */ handleActivityConfigurationChanged(@onNull ActivityClientRecord r, Configuration overrideConfig, int displayId)145 public abstract void handleActivityConfigurationChanged(@NonNull ActivityClientRecord r, 146 Configuration overrideConfig, int displayId); 147 148 /** Deliver result from another activity. */ handleSendResult( @onNull ActivityClientRecord r, List<ResultInfo> results, String reason)149 public abstract void handleSendResult( 150 @NonNull ActivityClientRecord r, List<ResultInfo> results, String reason); 151 152 /** Deliver new intent. */ handleNewIntent( @onNull ActivityClientRecord r, List<ReferrerIntent> intents)153 public abstract void handleNewIntent( 154 @NonNull ActivityClientRecord r, List<ReferrerIntent> intents); 155 156 /** Request that an activity enter picture-in-picture. */ handlePictureInPictureRequested(@onNull ActivityClientRecord r)157 public abstract void handlePictureInPictureRequested(@NonNull ActivityClientRecord r); 158 159 /** Signal to an activity (that is currently in PiP) of PiP state changes. */ handlePictureInPictureStateChanged(@onNull ActivityClientRecord r, PictureInPictureUiState pipState)160 public abstract void handlePictureInPictureStateChanged(@NonNull ActivityClientRecord r, 161 PictureInPictureUiState pipState); 162 163 /** Whether the activity want to handle splash screen exit animation */ isHandleSplashScreenExit(@onNull IBinder token)164 public abstract boolean isHandleSplashScreenExit(@NonNull IBinder token); 165 166 /** Attach a splash screen window view to the top of the activity */ handleAttachSplashScreenView(@onNull ActivityClientRecord r, @NonNull SplashScreenViewParcelable parcelable)167 public abstract void handleAttachSplashScreenView(@NonNull ActivityClientRecord r, 168 @NonNull SplashScreenViewParcelable parcelable); 169 170 /** Hand over the splash screen window view to the activity */ handOverSplashScreenView(@onNull ActivityClientRecord r)171 public abstract void handOverSplashScreenView(@NonNull ActivityClientRecord r); 172 173 /** Perform activity launch. */ handleLaunchActivity(@onNull ActivityClientRecord r, PendingTransactionActions pendingActions, Intent customIntent)174 public abstract Activity handleLaunchActivity(@NonNull ActivityClientRecord r, 175 PendingTransactionActions pendingActions, Intent customIntent); 176 177 /** Perform activity start. */ handleStartActivity(@onNull ActivityClientRecord r, PendingTransactionActions pendingActions, ActivityOptions activityOptions)178 public abstract void handleStartActivity(@NonNull ActivityClientRecord r, 179 PendingTransactionActions pendingActions, ActivityOptions activityOptions); 180 181 /** Get package info. */ getPackageInfoNoCheck(ApplicationInfo ai, CompatibilityInfo compatInfo)182 public abstract LoadedApk getPackageInfoNoCheck(ApplicationInfo ai, 183 CompatibilityInfo compatInfo); 184 185 /** Deliver app configuration change notification. */ handleConfigurationChanged(Configuration config)186 public abstract void handleConfigurationChanged(Configuration config); 187 188 /** Apply addition adjustments to override display information. */ handleFixedRotationAdjustments(IBinder token, FixedRotationAdjustments fixedRotationAdjustments)189 public abstract void handleFixedRotationAdjustments(IBinder token, 190 FixedRotationAdjustments fixedRotationAdjustments); 191 192 /** 193 * Add {@link ActivityClientRecord} that is preparing to be launched. 194 * @param token Activity token. 195 * @param activity An initialized instance of {@link ActivityClientRecord} to use during launch. 196 */ addLaunchingActivity(IBinder token, ActivityClientRecord activity)197 public abstract void addLaunchingActivity(IBinder token, ActivityClientRecord activity); 198 199 /** 200 * Get {@link ActivityClientRecord} that is preparing to be launched. 201 * @param token Activity token. 202 * @return An initialized instance of {@link ActivityClientRecord} to use during launch. 203 */ getLaunchingActivity(IBinder token)204 public abstract ActivityClientRecord getLaunchingActivity(IBinder token); 205 206 /** 207 * Remove {@link ActivityClientRecord} from the launching activity list. 208 * @param token Activity token. 209 */ removeLaunchingActivity(IBinder token)210 public abstract void removeLaunchingActivity(IBinder token); 211 212 /** 213 * Get {@link android.app.ActivityThread.ActivityClientRecord} instance that corresponds to the 214 * provided token. 215 */ getActivityClient(IBinder token)216 public abstract ActivityClientRecord getActivityClient(IBinder token); 217 218 /** 219 * Prepare activity relaunch to update internal bookkeeping. This is used to track multiple 220 * relaunch and config update requests. 221 * @param token Activity token. 222 * @param pendingResults Activity results to be delivered. 223 * @param pendingNewIntents New intent messages to be delivered. 224 * @param configChanges Mask of configuration changes that have occurred. 225 * @param config New configuration applied to the activity. 226 * @param preserveWindow Whether the activity should try to reuse the window it created, 227 * including the decor view after the relaunch. 228 * @return An initialized instance of {@link ActivityThread.ActivityClientRecord} to use during 229 * relaunch, or {@code null} if relaunch cancelled. 230 */ prepareRelaunchActivity(IBinder token, List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, int configChanges, MergedConfiguration config, boolean preserveWindow)231 public abstract ActivityClientRecord prepareRelaunchActivity(IBinder token, 232 List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, 233 int configChanges, MergedConfiguration config, boolean preserveWindow); 234 235 /** 236 * Perform activity relaunch. 237 * @param r Activity client record prepared for relaunch. 238 * @param pendingActions Pending actions to be used on later stages of activity transaction. 239 * */ handleRelaunchActivity(@onNull ActivityClientRecord r, PendingTransactionActions pendingActions)240 public abstract void handleRelaunchActivity(@NonNull ActivityClientRecord r, 241 PendingTransactionActions pendingActions); 242 243 /** 244 * Report that relaunch request was handled. 245 * @param r Target activity record. 246 * @param pendingActions Pending actions initialized on earlier stages of activity transaction. 247 * Used to check if we should report relaunch to WM. 248 * */ reportRelaunch(@onNull ActivityClientRecord r, PendingTransactionActions pendingActions)249 public abstract void reportRelaunch(@NonNull ActivityClientRecord r, 250 PendingTransactionActions pendingActions); 251 } 252