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