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

Commit d25680cb authored by Andrii Kulian's avatar Andrii Kulian
Browse files

Improve AM lifecycle event logs

Add missing lifecycle event logs and provide more detailed
reasons.

Test: Open and switch between apps, observe lifecycle event logs
Change-Id: I403c8d84afec9c950ea3a8fc88600cf554e015f4
parent f1862955
Loading
Loading
Loading
Loading
+28 −7
Original line number Original line Diff line number Diff line
@@ -751,6 +751,14 @@ public class Activity extends ContextThemeWrapper


    private static final String KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME = "com.android.systemui";
    private static final String KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME = "com.android.systemui";


    private static final int LOG_AM_ON_CREATE_CALLED = 30057;
    private static final int LOG_AM_ON_START_CALLED = 30059;
    private static final int LOG_AM_ON_RESUME_CALLED = 30022;
    private static final int LOG_AM_ON_PAUSE_CALLED = 30021;
    private static final int LOG_AM_ON_STOP_CALLED = 30049;
    private static final int LOG_AM_ON_RESTART_CALLED = 30058;
    private static final int LOG_AM_ON_DESTROY_CALLED = 30060;

    private static class ManagedDialog {
    private static class ManagedDialog {
        Dialog mDialog;
        Dialog mDialog;
        Bundle mArgs;
        Bundle mArgs;
@@ -7103,6 +7111,7 @@ public class Activity extends ContextThemeWrapper
        } else {
        } else {
            onCreate(icicle);
            onCreate(icicle);
        }
        }
        writeEventLog(LOG_AM_ON_CREATE_CALLED, "performCreate");
        mActivityTransitionState.readState(icicle);
        mActivityTransitionState.readState(icicle);


        mVisibleFromClient = !mWindow.getWindowStyle().getBoolean(
        mVisibleFromClient = !mWindow.getWindowStyle().getBoolean(
@@ -7116,12 +7125,14 @@ public class Activity extends ContextThemeWrapper
        onNewIntent(intent);
        onNewIntent(intent);
    }
    }


    final void performStart() {
    final void performStart(String reason) {
        mActivityTransitionState.setEnterActivityOptions(this, getActivityOptions());
        mActivityTransitionState.setEnterActivityOptions(this, getActivityOptions());
        mFragments.noteStateNotSaved();
        mFragments.noteStateNotSaved();
        mCalled = false;
        mCalled = false;
        mFragments.execPendingActions();
        mFragments.execPendingActions();
        mInstrumentation.callActivityOnStart(this);
        mInstrumentation.callActivityOnStart(this);
        writeEventLog(LOG_AM_ON_START_CALLED, reason);

        if (!mCalled) {
        if (!mCalled) {
            throw new SuperNotCalledException(
            throw new SuperNotCalledException(
                "Activity " + mComponent.toShortString() +
                "Activity " + mComponent.toShortString() +
@@ -7190,7 +7201,7 @@ public class Activity extends ContextThemeWrapper
     *              The option to not start immediately is needed in case a transaction with
     *              The option to not start immediately is needed in case a transaction with
     *              multiple lifecycle transitions is in progress.
     *              multiple lifecycle transitions is in progress.
     */
     */
    final void performRestart(boolean start) {
    final void performRestart(boolean start, String reason) {
        mCanEnterPictureInPicture = true;
        mCanEnterPictureInPicture = true;
        mFragments.noteStateNotSaved();
        mFragments.noteStateNotSaved();


@@ -7223,19 +7234,20 @@ public class Activity extends ContextThemeWrapper


            mCalled = false;
            mCalled = false;
            mInstrumentation.callActivityOnRestart(this);
            mInstrumentation.callActivityOnRestart(this);
            writeEventLog(LOG_AM_ON_RESTART_CALLED, reason);
            if (!mCalled) {
            if (!mCalled) {
                throw new SuperNotCalledException(
                throw new SuperNotCalledException(
                    "Activity " + mComponent.toShortString() +
                    "Activity " + mComponent.toShortString() +
                    " did not call through to super.onRestart()");
                    " did not call through to super.onRestart()");
            }
            }
            if (start) {
            if (start) {
                performStart();
                performStart(reason);
            }
            }
        }
        }
    }
    }


    final void performResume(boolean followedByPause) {
    final void performResume(boolean followedByPause, String reason) {
        performRestart(true /* start */);
        performRestart(true /* start */, reason);


        mFragments.execPendingActions();
        mFragments.execPendingActions();


@@ -7254,6 +7266,7 @@ public class Activity extends ContextThemeWrapper
        mCalled = false;
        mCalled = false;
        // mResumed is set by the instrumentation
        // mResumed is set by the instrumentation
        mInstrumentation.callActivityOnResume(this);
        mInstrumentation.callActivityOnResume(this);
        writeEventLog(LOG_AM_ON_RESUME_CALLED, reason);
        if (!mCalled) {
        if (!mCalled) {
            throw new SuperNotCalledException(
            throw new SuperNotCalledException(
                "Activity " + mComponent.toShortString() +
                "Activity " + mComponent.toShortString() +
@@ -7290,6 +7303,7 @@ public class Activity extends ContextThemeWrapper
        mFragments.dispatchPause();
        mFragments.dispatchPause();
        mCalled = false;
        mCalled = false;
        onPause();
        onPause();
        writeEventLog(LOG_AM_ON_PAUSE_CALLED, "performPause");
        mResumed = false;
        mResumed = false;
        if (!mCalled && getApplicationInfo().targetSdkVersion
        if (!mCalled && getApplicationInfo().targetSdkVersion
                >= android.os.Build.VERSION_CODES.GINGERBREAD) {
                >= android.os.Build.VERSION_CODES.GINGERBREAD) {
@@ -7297,7 +7311,6 @@ public class Activity extends ContextThemeWrapper
                    "Activity " + mComponent.toShortString() +
                    "Activity " + mComponent.toShortString() +
                    " did not call through to super.onPause()");
                    " did not call through to super.onPause()");
        }
        }
        mResumed = false;
    }
    }


    final void performUserLeaving() {
    final void performUserLeaving() {
@@ -7305,7 +7318,7 @@ public class Activity extends ContextThemeWrapper
        onUserLeaveHint();
        onUserLeaveHint();
    }
    }


    final void performStop(boolean preserveWindow) {
    final void performStop(boolean preserveWindow, String reason) {
        mDoReportFullyDrawn = false;
        mDoReportFullyDrawn = false;
        mFragments.doLoaderStop(mChangingConfigurations /*retain*/);
        mFragments.doLoaderStop(mChangingConfigurations /*retain*/);


@@ -7328,6 +7341,7 @@ public class Activity extends ContextThemeWrapper


            mCalled = false;
            mCalled = false;
            mInstrumentation.callActivityOnStop(this);
            mInstrumentation.callActivityOnStop(this);
            writeEventLog(LOG_AM_ON_STOP_CALLED, reason);
            if (!mCalled) {
            if (!mCalled) {
                throw new SuperNotCalledException(
                throw new SuperNotCalledException(
                    "Activity " + mComponent.toShortString() +
                    "Activity " + mComponent.toShortString() +
@@ -7355,6 +7369,7 @@ public class Activity extends ContextThemeWrapper
        mWindow.destroy();
        mWindow.destroy();
        mFragments.dispatchDestroy();
        mFragments.dispatchDestroy();
        onDestroy();
        onDestroy();
        writeEventLog(LOG_AM_ON_DESTROY_CALLED, "performDestroy");
        mFragments.doLoaderDestroy();
        mFragments.doLoaderDestroy();
        if (mVoiceInteractor != null) {
        if (mVoiceInteractor != null) {
            mVoiceInteractor.detachActivity();
            mVoiceInteractor.detachActivity();
@@ -7829,6 +7844,12 @@ public class Activity extends ContextThemeWrapper
        }
        }
    }
    }


    /** Log a lifecycle event for current user id and component class. */
    private void writeEventLog(int event, String reason) {
        EventLog.writeEvent(event, UserHandle.myUserId(), getComponentName().getClassName(),
                reason);
    }

    class HostCallbacks extends FragmentHostCallback<Activity> {
    class HostCallbacks extends FragmentHostCallback<Activity> {
        public HostCallbacks() {
        public HostCallbacks() {
            super(Activity.this /*activity*/);
            super(Activity.this /*activity*/);
+13 −22
Original line number Original line Diff line number Diff line
@@ -208,9 +208,6 @@ public final class ActivityThread extends ClientTransactionHandler {
    public static final boolean DEBUG_ORDER = false;
    public static final boolean DEBUG_ORDER = false;
    private static final long MIN_TIME_BETWEEN_GCS = 5*1000;
    private static final long MIN_TIME_BETWEEN_GCS = 5*1000;
    private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003;
    private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003;
    private static final int LOG_AM_ON_PAUSE_CALLED = 30021;
    private static final int LOG_AM_ON_RESUME_CALLED = 30022;
    private static final int LOG_AM_ON_STOP_CALLED = 30049;


    /** Type for IActivityManager.serviceDoneExecuting: anonymous operation */
    /** Type for IActivityManager.serviceDoneExecuting: anonymous operation */
    public static final int SERVICE_DONE_EXECUTING_ANON = 0;
    public static final int SERVICE_DONE_EXECUTING_ANON = 0;
@@ -2924,7 +2921,7 @@ public final class ActivityThread extends ClientTransactionHandler {
        }
        }


        // Start
        // Start
        activity.performStart();
        activity.performStart("handleStartActivity");
        r.setState(ON_START);
        r.setState(ON_START);


        if (pendingActions == null) {
        if (pendingActions == null) {
@@ -3113,7 +3110,7 @@ public final class ActivityThread extends ClientTransactionHandler {
        checkAndBlockForNetworkAccess();
        checkAndBlockForNetworkAccess();
        deliverNewIntents(r, intents);
        deliverNewIntents(r, intents);
        if (resumed) {
        if (resumed) {
            r.activity.performResume(false);
            r.activity.performResume(false, "performNewIntents");
            r.activity.mTemporaryPause = false;
            r.activity.mTemporaryPause = false;
        }
        }


@@ -3735,10 +3732,7 @@ public final class ActivityThread extends ClientTransactionHandler {
                    deliverResults(r, r.pendingResults);
                    deliverResults(r, r.pendingResults);
                    r.pendingResults = null;
                    r.pendingResults = null;
                }
                }
                r.activity.performResume(r.startsNotResumed);
                r.activity.performResume(r.startsNotResumed, reason);

                EventLog.writeEvent(LOG_AM_ON_RESUME_CALLED, UserHandle.myUserId(),
                        r.activity.getComponentName().getClassName(), reason);


                r.state = null;
                r.state = null;
                r.persistentState = null;
                r.persistentState = null;
@@ -3906,7 +3900,8 @@ public final class ActivityThread extends ClientTransactionHandler {


    @Override
    @Override
    public void handlePauseActivity(IBinder token, boolean finished, boolean userLeaving,
    public void handlePauseActivity(IBinder token, boolean finished, boolean userLeaving,
            int configChanges, boolean dontReport, PendingTransactionActions pendingActions) {
            int configChanges, boolean dontReport, PendingTransactionActions pendingActions,
            String reason) {
        ActivityClientRecord r = mActivities.get(token);
        ActivityClientRecord r = mActivities.get(token);
        if (r != null) {
        if (r != null) {
            if (userLeaving) {
            if (userLeaving) {
@@ -3914,7 +3909,7 @@ public final class ActivityThread extends ClientTransactionHandler {
            }
            }


            r.activity.mConfigChangeFlags |= configChanges;
            r.activity.mConfigChangeFlags |= configChanges;
            performPauseActivity(r, finished, "handlePauseActivity", pendingActions);
            performPauseActivity(r, finished, reason, pendingActions);


            // Make sure any pending writes are now committed.
            // Make sure any pending writes are now committed.
            if (r.isPreHoneycomb()) {
            if (r.isPreHoneycomb()) {
@@ -4007,8 +4002,6 @@ public final class ActivityThread extends ClientTransactionHandler {
        try {
        try {
            r.activity.mCalled = false;
            r.activity.mCalled = false;
            mInstrumentation.callActivityOnPause(r.activity);
            mInstrumentation.callActivityOnPause(r.activity);
            EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(),
                    r.activity.getComponentName().getClassName(), reason);
            if (!r.activity.mCalled) {
            if (!r.activity.mCalled) {
                throw new SuperNotCalledException("Activity " + safeToComponentShortString(r.intent)
                throw new SuperNotCalledException("Activity " + safeToComponentShortString(r.intent)
                        + " did not call through to super.onPause()");
                        + " did not call through to super.onPause()");
@@ -4119,7 +4112,7 @@ public final class ActivityThread extends ClientTransactionHandler {
        }
        }


        try {
        try {
            r.activity.performStop(false /*preserveWindow*/);
            r.activity.performStop(false /*preserveWindow*/, reason);
        } catch (SuperNotCalledException e) {
        } catch (SuperNotCalledException e) {
            throw e;
            throw e;
        } catch (Exception e) {
        } catch (Exception e) {
@@ -4131,8 +4124,6 @@ public final class ActivityThread extends ClientTransactionHandler {
            }
            }
        }
        }
        r.setState(ON_STOP);
        r.setState(ON_STOP);
        EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(),
                r.activity.getComponentName().getClassName(), reason);


        if (shouldSaveState && !isPreP) {
        if (shouldSaveState && !isPreP) {
            callActivityOnSaveInstanceState(r);
            callActivityOnSaveInstanceState(r);
@@ -4169,12 +4160,12 @@ public final class ActivityThread extends ClientTransactionHandler {


    @Override
    @Override
    public void handleStopActivity(IBinder token, boolean show, int configChanges,
    public void handleStopActivity(IBinder token, boolean show, int configChanges,
            PendingTransactionActions pendingActions) {
            PendingTransactionActions pendingActions, String reason) {
        final ActivityClientRecord r = mActivities.get(token);
        final ActivityClientRecord r = mActivities.get(token);
        r.activity.mConfigChangeFlags |= configChanges;
        r.activity.mConfigChangeFlags |= configChanges;


        final StopInfo stopInfo = new StopInfo();
        final StopInfo stopInfo = new StopInfo();
        performStopActivityInner(r, stopInfo, show, true, "handleStopActivity");
        performStopActivityInner(r, stopInfo, show, true, reason);


        if (localLOGV) Slog.v(
        if (localLOGV) Slog.v(
            TAG, "Finishing stop of " + r + ": show=" + show
            TAG, "Finishing stop of " + r + ": show=" + show
@@ -4209,7 +4200,7 @@ public final class ActivityThread extends ClientTransactionHandler {
    public void performRestartActivity(IBinder token, boolean start) {
    public void performRestartActivity(IBinder token, boolean start) {
        ActivityClientRecord r = mActivities.get(token);
        ActivityClientRecord r = mActivities.get(token);
        if (r.stopped) {
        if (r.stopped) {
            r.activity.performRestart(start);
            r.activity.performRestart(start, "performRestartActivity");
            if (start) {
            if (start) {
                r.setState(ON_START);
                r.setState(ON_START);
            }
            }
@@ -4232,7 +4223,7 @@ public final class ActivityThread extends ClientTransactionHandler {
            // we are back active so skip it.
            // we are back active so skip it.
            unscheduleGcIdler();
            unscheduleGcIdler();


            r.activity.performRestart(true /* start */);
            r.activity.performRestart(true /* start */, "handleWindowVisibility");
            r.setState(ON_START);
            r.setState(ON_START);
        }
        }
        if (r.activity.mDecor != null) {
        if (r.activity.mDecor != null) {
@@ -4272,7 +4263,7 @@ public final class ActivityThread extends ClientTransactionHandler {
            }
            }
        } else {
        } else {
            if (r.stopped && r.activity.mVisibleFromServer) {
            if (r.stopped && r.activity.mVisibleFromServer) {
                r.activity.performRestart(true /* start */);
                r.activity.performRestart(true /* start */, "handleSleeping");
                r.setState(ON_START);
                r.setState(ON_START);
            }
            }
        }
        }
@@ -4384,7 +4375,7 @@ public final class ActivityThread extends ClientTransactionHandler {
            checkAndBlockForNetworkAccess();
            checkAndBlockForNetworkAccess();
            deliverResults(r, results);
            deliverResults(r, results);
            if (resumed) {
            if (resumed) {
                r.activity.performResume(false);
                r.activity.performResume(false, "handleSendResult");
                r.activity.mTemporaryPause = false;
                r.activity.mTemporaryPause = false;
            }
            }
        }
        }
+3 −2
Original line number Original line Diff line number Diff line
@@ -65,7 +65,8 @@ public abstract class ClientTransactionHandler {


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


    /** Resume the activity. */
    /** Resume the activity. */
    public abstract void handleResumeActivity(IBinder token, boolean clearHide, boolean isForward,
    public abstract void handleResumeActivity(IBinder token, boolean clearHide, boolean isForward,
@@ -73,7 +74,7 @@ public abstract class ClientTransactionHandler {


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


    /** Report that activity was stopped to server. */
    /** Report that activity was stopped to server. */
    public abstract void reportStop(PendingTransactionActions pendingActions);
    public abstract void reportStop(PendingTransactionActions pendingActions);
+1 −1
Original line number Original line Diff line number Diff line
@@ -43,7 +43,7 @@ public class PauseActivityItem extends ActivityLifecycleItem {
            PendingTransactionActions pendingActions) {
            PendingTransactionActions pendingActions) {
        Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityPause");
        Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityPause");
        client.handlePauseActivity(token, mFinished, mUserLeaving, mConfigChanges, mDontReport,
        client.handlePauseActivity(token, mFinished, mUserLeaving, mConfigChanges, mDontReport,
                pendingActions);
                pendingActions, "PAUSE_ACTIVITY_ITEM");
        Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
        Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
    }
    }


+2 −1
Original line number Original line Diff line number Diff line
@@ -38,7 +38,8 @@ public class StopActivityItem extends ActivityLifecycleItem {
    public void execute(ClientTransactionHandler client, IBinder token,
    public void execute(ClientTransactionHandler client, IBinder token,
            PendingTransactionActions pendingActions) {
            PendingTransactionActions pendingActions) {
        Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityStop");
        Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityStop");
        client.handleStopActivity(token, mShowWindow, mConfigChanges, pendingActions);
        client.handleStopActivity(token, mShowWindow, mConfigChanges, pendingActions,
                "STOP_ACTIVITY_ITEM");
        Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
        Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
    }
    }


Loading