Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 88e05cb8 authored by Andrii Kulian's avatar Andrii Kulian
Browse files

Add transaction executor

This adds TransactionExecutor class, that takes care of executing
a multi-stage ActivityManager client transaction in correct order.

First it executes all callbacks, while also making sure to transition
to the right pre- and post-execution state if requested.
In the end it cycles to the final requested lifecycle state.

This also switches activity launch process to use lifecycler - it
initializes activity launch and sets final desired state in the same
transaction.

Bug: 64797980
Test: android.app.servertransaction.TransactionExecutorTests
Change-Id: I306f9396fab263682f580cc8c924a3cedb40ef89
parent 1f272d89
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -7070,7 +7070,13 @@ public class Activity extends ContextThemeWrapper
        mActivityTransitionState.enterReady(this);
    }

    final void performRestart() {
    /**
     * Restart the activity.
     * @param start Indicates whether the activity should also be started after restart.
     *              The option to not start immediately is needed in case a transaction with
     *              multiple lifecycle transitions is in progress.
     */
    final void performRestart(boolean start) {
        mCanEnterPictureInPicture = true;
        mFragments.noteStateNotSaved();

@@ -7108,12 +7114,14 @@ public class Activity extends ContextThemeWrapper
                    "Activity " + mComponent.toShortString() +
                    " did not call through to super.onRestart()");
            }
            if (start) {
                performStart();
            }
        }
    }

    final void performResume() {
        performRestart();
        performRestart(true /* start */);

        mFragments.execPendingActions();

+244 −251

File changed.

Preview size limit exceeded, changes collapsed.

+28 −18
Original line number Diff line number Diff line
@@ -16,15 +16,12 @@
package android.app;

import android.app.servertransaction.ClientTransaction;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.app.servertransaction.PendingTransactionActions;
import android.content.pm.ApplicationInfo;
import android.content.res.CompatibilityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.IBinder;
import android.os.PersistableBundle;

import com.android.internal.app.IVoiceInteractor;
import com.android.internal.content.ReferrerIntent;

import java.util.List;
@@ -40,7 +37,7 @@ public abstract class ClientTransactionHandler {

    /** Prepare and schedule transaction for execution. */
    void scheduleTransaction(ClientTransaction transaction) {
        transaction.prepare(this);
        transaction.preExecute(this);
        sendMessage(ActivityThread.H.EXECUTE_TRANSACTION, transaction);
    }

@@ -50,9 +47,6 @@ public abstract class ClientTransactionHandler {
    // Prepare phase related logic and handlers. Methods that inform about about pending changes or
    // do other internal bookkeeping.

    /** Get current lifecycle request number to maintain correct ordering. */
    public abstract int getLifecycleSeq();

    /** Set pending config in case it will be updated by other transaction item. */
    public abstract void updatePendingConfiguration(Configuration config);

@@ -69,15 +63,21 @@ public abstract class ClientTransactionHandler {

    /** Pause the activity. */
    public abstract void handlePauseActivity(IBinder token, boolean finished, boolean userLeaving,
            int configChanges, boolean dontReport, int seq);
            int configChanges, boolean dontReport, PendingTransactionActions pendingActions);

    /** Resume the activity. */
    public abstract void handleResumeActivity(IBinder token, boolean clearHide, boolean isForward,
            boolean reallyResume, int seq, String reason);
            String reason);

    /** Stop the activity. */
    public abstract void handleStopActivity(IBinder token, boolean show, int configChanges,
            int seq);
            PendingTransactionActions pendingActions);

    /** Report that activity was stopped to server. */
    public abstract void reportStop(PendingTransactionActions pendingActions);

    /** Restart the activity after it was stopped. */
    public abstract void performRestartActivity(IBinder token, boolean start);

    /** Deliver activity (override) configuration change. */
    public abstract void handleActivityConfigurationChanged(IBinder activityToken,
@@ -102,13 +102,23 @@ public abstract class ClientTransactionHandler {
    public abstract void handleWindowVisibility(IBinder token, boolean show);

    /** Perform activity launch. */
    public abstract void handleLaunchActivity(IBinder token, Intent intent, int ident,
            ActivityInfo info, Configuration overrideConfig, CompatibilityInfo compatInfo,
            String referrer, IVoiceInteractor voiceInteractor, Bundle state,
            PersistableBundle persistentState, List<ResultInfo> pendingResults,
            List<ReferrerIntent> pendingNewIntents, boolean notResumed, boolean isForward,
            ProfilerInfo profilerInfo);
    public abstract Activity handleLaunchActivity(ActivityThread.ActivityClientRecord r,
            PendingTransactionActions pendingActions);

    /** Perform activity start. */
    public abstract void handleStartActivity(ActivityThread.ActivityClientRecord r,
            PendingTransactionActions pendingActions);

    /** Get package info. */
    public abstract LoadedApk getPackageInfoNoCheck(ApplicationInfo ai,
            CompatibilityInfo compatInfo);

    /** Deliver app configuration change notification. */
    public abstract void handleConfigurationChanged(Configuration config);

    /**
     * Get {@link android.app.ActivityThread.ActivityClientRecord} instance that corresponds to the
     * provided token.
     */
    public abstract ActivityThread.ActivityClientRecord getActivityClient(IBinder token);
}
+8 −5
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.Binder;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;

import com.android.internal.content.ReferrerIntent;

import java.util.ArrayList;
@@ -161,12 +162,12 @@ public class LocalActivityManager {
            case CREATED:
                if (desiredState == STARTED) {
                    if (localLOGV) Log.v(TAG, r.id + ": restarting");
                    mActivityThread.performRestartActivity(r);
                    mActivityThread.performRestartActivity(r, true /* start */);
                    r.curState = STARTED;
                }
                if (desiredState == RESUMED) {
                    if (localLOGV) Log.v(TAG, r.id + ": restarting and resuming");
                    mActivityThread.performRestartActivity(r);
                    mActivityThread.performRestartActivity(r, true /* start */);
                    mActivityThread.performResumeActivity(r, true, "moveToState-CREATED");
                    r.curState = RESUMED;
                }
@@ -207,7 +208,7 @@ public class LocalActivityManager {
    private void performPause(LocalActivityRecord r, boolean finishing) {
        final boolean needState = r.instanceState == null;
        final Bundle instanceState = mActivityThread.performPauseActivity(
                r, finishing, needState, "performPause");
                r, finishing, needState, "performPause", null /* pendingActions */);
        if (needState) {
            r.instanceState = instanceState;
        }
@@ -361,7 +362,8 @@ public class LocalActivityManager {
            performPause(r, finish);
        }
        if (localLOGV) Log.v(TAG, r.id + ": destroying");
        mActivityThread.performDestroyActivity(r, finish);
        mActivityThread.performDestroyActivity(r, finish, 0 /* configChanges */,
                false /* getNonConfigInstance */);
        r.activity = null;
        r.window = null;
        if (finish) {
@@ -625,7 +627,8 @@ public class LocalActivityManager {
        for (int i=0; i<N; i++) {
            LocalActivityRecord r = mActivityArray.get(i);
            if (localLOGV) Log.v(TAG, r.id + ": destroying");
            mActivityThread.performDestroyActivity(r, finishing);
            mActivityThread.performDestroyActivity(r, finishing, 0 /* configChanges */,
                    false /* getNonConfigInstance */);
        }
        mActivities.clear();
        mActivityArray.clear();
+8 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.app.servertransaction;
import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
import static android.view.Display.INVALID_DISPLAY;

import android.app.ClientTransactionHandler;
import android.content.res.Configuration;
import android.os.IBinder;
import android.os.Parcel;
@@ -37,7 +38,8 @@ public class ActivityConfigurationChangeItem extends ClientTransactionItem {
    }

    @Override
    public void execute(android.app.ClientTransactionHandler client, IBinder token) {
    public void execute(ClientTransactionHandler client, IBinder token,
            PendingTransactionActions pendingActions) {
        // TODO(lifecycler): detect if PIP or multi-window mode changed and report it here.
        Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityConfigChanged");
        client.handleActivityConfigurationChanged(token, mConfiguration, INVALID_DISPLAY);
@@ -85,4 +87,9 @@ public class ActivityConfigurationChangeItem extends ClientTransactionItem {
    public int hashCode() {
        return mConfiguration.hashCode();
    }

    @Override
    public String toString() {
        return "ActivityConfigurationChange{config=" + mConfiguration + "}";
    }
}
Loading