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