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