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

Commit 02ebfd06 authored by Filip Gruszczynski's avatar Filip Gruszczynski Committed by Android (Google) Code Review
Browse files

Merge "Log window mode to tron."

parents e5f4a9c1 77d9448e
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1434,6 +1434,7 @@ public final class ActivityManagerService extends ActivityManagerNative
    static final int CONTENT_PROVIDER_PUBLISH_TIMEOUT_MSG = 59;
    static final int IDLE_UIDS_MSG = 60;
    static final int SYSTEM_USER_UNLOCK_MSG = 61;
    static final int LOG_STACK_STATE = 62;
    static final int FIRST_ACTIVITY_STACK_MSG = 100;
    static final int FIRST_BROADCAST_QUEUE_MSG = 200;
@@ -2143,6 +2144,11 @@ public final class ActivityManagerService extends ActivityManagerNative
            case IDLE_UIDS_MSG: {
                idleUids();
            } break;
            case LOG_STACK_STATE: {
                synchronized (ActivityManagerService.this) {
                    mStackSupervisor.logStackState();
                }
            } break;
            }
        }
    };
@@ -10902,6 +10908,7 @@ public final class ActivityManagerService extends ActivityManagerNative
    /** Notifies all listeners when the task stack has changed. */
    void notifyTaskStackChangedLocked() {
        mHandler.sendEmptyMessage(LOG_STACK_STATE);
        mHandler.removeMessages(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG);
        Message nmsg = mHandler.obtainMessage(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG);
        mHandler.sendMessageDelayed(nmsg, NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY);
+72 −0
Original line number Diff line number Diff line
package com.android.server.am;

import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
import static android.app.ActivityManager.StackId.HOME_STACK_ID;

import android.app.ActivityManager.StackId;
import android.content.Context;
import android.os.SystemClock;

import com.android.internal.logging.MetricsLogger;

/**
 * Handles logging into Tron.
 */
class ActivityMetricsLogger {
    // Window modes we are interested in logging. If we ever introduce a new type, we need to add
    // a value here and increase the {@link #TRON_WINDOW_STATE_VARZ_STRINGS} array.
    private static final int WINDOW_STATE_STANDARD = 0;
    private static final int WINDOW_STATE_SIDE_BY_SIDE = 1;
    private static final int WINDOW_STATE_FREEFORM = 2;
    private static final int WINDOW_STATE_INVALID = -1;

    // Preallocated strings we are sending to tron, so we don't have to allocate a new one every
    // time we log.
    private static final String[] TRON_WINDOW_STATE_VARZ_STRINGS = {
            "tron_varz_window_time_0", "tron_varz_window_time_1", "tron_varz_window_time_2"};

    private int mWindowState = WINDOW_STATE_STANDARD;
    private long mLastLogTimeSecs;
    private final ActivityStackSupervisor mSupervisor;
    private final Context mContext;

    ActivityMetricsLogger(ActivityStackSupervisor supervisor, Context context) {
        mLastLogTimeSecs = SystemClock.elapsedRealtime() / 1000;
        mSupervisor = supervisor;
        mContext = context;
    }

    void logWindowState() {
        final long now = SystemClock.elapsedRealtime() / 1000;
        if (mWindowState != WINDOW_STATE_INVALID) {
            // We log even if the window state hasn't changed, because the user might remain in
            // home/fullscreen move forever and we would like to track this kind of behavior
            // too.
            MetricsLogger.count(mContext, TRON_WINDOW_STATE_VARZ_STRINGS[mWindowState],
                    (int) (now - mLastLogTimeSecs));
        }
        mLastLogTimeSecs = now;

        mWindowState = WINDOW_STATE_INVALID;
        ActivityStack stack = mSupervisor.getStack(DOCKED_STACK_ID);
        if (stack != null && stack.isStackVisibleLocked()) {
            mWindowState = WINDOW_STATE_SIDE_BY_SIDE;
        }
        if (mWindowState == WINDOW_STATE_INVALID) {
            stack = mSupervisor.getFocusedStack();
            if (stack.mStackId == HOME_STACK_ID
                    || stack.mStackId == FULLSCREEN_WORKSPACE_STACK_ID) {
                mWindowState = WINDOW_STATE_STANDARD;
            } else if (stack.mStackId == DOCKED_STACK_ID) {
                throw new IllegalStateException("Docked stack shouldn't be the focused stack, "
                        + "because it reported not being visible.");
            } else if (stack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
                mWindowState = WINDOW_STATE_FREEFORM;
            } else if (StackId.isStaticStack(stack.mStackId)) {
                throw new IllegalStateException("Unknown stack=" + stack);
            }
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -1334,7 +1334,7 @@ final class ActivityStack {
    }

    /** Returns true if the stack is considered visible. */
    private boolean isStackVisibleLocked() {
    boolean isStackVisibleLocked() {
        if (!isAttached()) {
            return false;
        }
+8 −2
Original line number Diff line number Diff line
@@ -126,7 +126,6 @@ import com.android.internal.app.HeavyWeightSwitcherActivity;
import com.android.internal.app.IVoiceInteractor;
import com.android.internal.content.ReferrerIntent;
import com.android.internal.os.TransferPipe;
import com.android.internal.R;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.util.ArrayUtils;
import com.android.internal.widget.LockPatternUtils;
@@ -371,6 +370,8 @@ public final class ActivityStackSupervisor implements DisplayListener {
    // Whether tasks have moved and we need to rank the tasks before next OOM scoring
    private boolean mTaskLayersChanged = true;

    private final ActivityMetricsLogger mActivityMetricsLogger;

    /**
     * Description of a request to start a new activity, which has been held
     * due to app switches being disabled.
@@ -407,6 +408,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
        mService = service;
        mRecentTasks = recentTasks;
        mHandler = new ActivityStackSupervisorHandler(mService.mHandler.getLooper());
        mActivityMetricsLogger = new ActivityMetricsLogger(this, mService.mContext);
    }

    /**
@@ -4541,6 +4543,10 @@ public final class ActivityStackSupervisor implements DisplayListener {
        return mLockTaskModeState;
    }

    void logStackState() {
        mActivityMetricsLogger.logWindowState();
    }

    private final class ActivityStackSupervisorHandler extends Handler {

        public ActivityStackSupervisorHandler(Looper looper) {