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

Commit 27a52fa8 authored by Chris Wren's avatar Chris Wren
Browse files

port status bar logs to Tron V2

Bug: 33303260
Test: runtest --path frameworks/base/core/tests/coretests/src/com/android/internal/logging/legacy/ && runtest --path frameworks/base/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone
Change-Id: I7746b846247e930617f0b440217635e71ed58bb5
parent 3084ec2d
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -45,8 +45,6 @@ public class EventLogCollector {

    private EventLogCollector() {
        mTagParsers = new ArrayMap<>();
        addParser(new LockscreenGestureParser());
        addParser(new StatusBarStateParser());
        addParser(new PowerScreenStateParser());
        addParser(new SysuiMultiActionParser());

+0 −8
Original line number Diff line number Diff line
@@ -24,14 +24,6 @@ import java.util.Queue;

/** @hide */
public class LegacyConversionLogger implements TronLogger {
    public static final String VIEW_KEY = "view";
    public static final String TYPE_KEY = "type";
    public static final String EVENT_KEY = "data";

    public static final int TYPE_COUNTER = 1;
    public static final int TYPE_HISTOGRAM = 2;
    public static final int TYPE_EVENT = 3;

    private final Queue<LogMaker> mQueue;
    private HashMap<String, Boolean> mConfig;

+0 −80
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.logging.legacy;

import android.util.Log;

import android.metrics.LogMaker;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;

/**
 * Parse the Android lockscreen gesture logs.
 * @hide
 */
public class LockscreenGestureParser extends TagParser {
    private static final String TAG = "LockscreenGestureParser";
    private static final int EVENTLOG_TAG = 36021;

    // source of truth is com.android.systemui.EventLogConstants
    public static final int[] GESTURE_TYPE_MAP = {
            MetricsEvent.VIEW_UNKNOWN,  // there is no type 0
            MetricsEvent.ACTION_LS_UNLOCK,  // SYSUI_LOCKSCREEN_GESTURE_SWIPE_UP_UNLOCK = 1
            MetricsEvent.ACTION_LS_SHADE,  // SYSUI_LOCKSCREEN_GESTURE_SWIPE_DOWN_FULL_SHADE = 2
            MetricsEvent.ACTION_LS_HINT,  // SYSUI_LOCKSCREEN_GESTURE_TAP_UNLOCK_HINT = 3
            MetricsEvent.ACTION_LS_CAMERA,  // SYSUI_LOCKSCREEN_GESTURE_SWIPE_CAMERA = 4
            MetricsEvent.ACTION_LS_DIALER,  // SYSUI_LOCKSCREEN_GESTURE_SWIPE_DIALER = 5
            MetricsEvent.ACTION_LS_LOCK,  // SYSUI_LOCKSCREEN_GESTURE_TAP_LOCK = 6
            MetricsEvent.ACTION_LS_NOTE,  // SYSUI_LOCKSCREEN_GESTURE_TAP_NOTIFICATION_ACTIVATE = 7
            MetricsEvent.ACTION_LS_QS,  // SYSUI_LOCKSCREEN_GESTURE_SWIPE_DOWN_QS = 8
            MetricsEvent.ACTION_SHADE_QS_PULL,  // SYSUI_SHADE_GESTURE_SWIPE_DOWN_QS = 9
            MetricsEvent.ACTION_SHADE_QS_TAP  // SYSUI_TAP_TO_OPEN_QS = 10
    };

    @Override
    public int getTag() {
        return EVENTLOG_TAG;
    }

    @Override
    public void parseEvent(TronLogger logger, long eventTimeMs, Object[] operands) {
        final boolean debug = Util.debug();
        if (operands.length >= 1) {
            try {
                int type = ((Integer) operands[0]).intValue();
                // ignore gesture length in operands[1]
                // ignore gesture velocity in operands[2]

                int category = MetricsEvent.VIEW_UNKNOWN;
                if (type < GESTURE_TYPE_MAP.length) {
                    category = GESTURE_TYPE_MAP[type];
                }
                if (category != MetricsEvent.VIEW_UNKNOWN) {
                    LogMaker proto = logger.obtain();
                    proto.setCategory(category);
                    proto.setType(MetricsEvent.TYPE_ACTION);
                    proto.setTimestamp(eventTimeMs);
                    logger.addEvent(proto);
                }
            } catch (ClassCastException e) {
                if (debug) {
                    Log.e(TAG, "unexpected operand type: ", e);
                }
            }
        } else if (debug) {
            Log.w(TAG, "wrong number of operands: " + operands.length);
        }
    }
}
+0 −74
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.logging.legacy;

import android.util.Log;

import android.metrics.LogMaker;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;

/**
 * Parse the Android lockscreen gesture logs.
 * @hide
 */
public class StatusBarStateParser extends TagParser {
    private static final String TAG = "StatusBarStateParser";
    private static final int EVENTLOG_TAG = 36004;

    // source of truth is com.android.systemui.statusbar.StatusBarState
    public static final int SHADE = 0;
    public static final int KEYGUARD = 1;
    public static final int SHADE_LOCKED = 2;

    @Override
    public int getTag() {
        return EVENTLOG_TAG;
    }

    @Override
    public void parseEvent(TronLogger logger, long eventTimeMs, Object[] operands) {
        final boolean debug = Util.debug();
        if (operands.length >= 6) {
            try {
                // [state, isShowing, isOccluded, isBouncerShowing, isSecure, isCurrentlyInsecure]
                int state = ((Integer) operands[0]).intValue();
                boolean isBouncerShowing = (((Integer) operands[3]).intValue()) == 1;
                int isSecure = ((Integer) operands[4]).intValue();

                int view = MetricsEvent.LOCKSCREEN;
                int type = MetricsEvent.TYPE_OPEN;
                if (state == SHADE) {
                    type = MetricsEvent.TYPE_CLOSE;
                } else if (isBouncerShowing) {
                    view = MetricsEvent.BOUNCER;
                }

                LogMaker proto = logger.obtain();
                proto.setCategory(view);
                proto.setType(type);
                proto.setTimestamp(eventTimeMs);
                proto.setSubtype(isSecure);
                logger.addEvent(proto);
            } catch (ClassCastException e) {
                if (debug) {
                    Log.e(TAG, "unexpected operand type: ", e);
                }
            }
        } else if (debug) {
            Log.w(TAG, "wrong number of operands: " + operands.length);
        }
    }
}
+0 −100
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.logging.legacy;

import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.metrics.LogMaker;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;

public class LockscreenGestureParserTest extends ParserTest {

    public LockscreenGestureParserTest() {
        mParser = new LockscreenGestureParser();
    }

    public void testSwipeUpUnlock() throws Throwable {
        validate(MetricsEvent.ACTION_LS_UNLOCK, 1, 359, 6382);
    }

    public void testSwipeToShade() throws Throwable {
        validate(MetricsEvent.ACTION_LS_SHADE, 2, 324, 0);
    }

    public void testTapLockHint() throws Throwable {
        validate(MetricsEvent.ACTION_LS_HINT, 3, 0, 0);
    }

    public void testCamera() throws Throwable {
        validate(MetricsEvent.ACTION_LS_CAMERA, 4, 223, 1756);
    }

    public void testDialer() throws Throwable {
        validate(MetricsEvent.ACTION_LS_DIALER, 5, 163, 861);
    }

    public void testTapToLock() throws Throwable {
        validate(MetricsEvent.ACTION_LS_LOCK, 6, 0, 0);
    }

    public void testTapOnNotification() throws Throwable {
        validate(MetricsEvent.ACTION_LS_NOTE, 7, 0, 0);
    }

    public void testLockscreenQuickSettings() throws Throwable {
        validate(MetricsEvent.ACTION_LS_QS, 8, 284, 3824);
    }

    public void testShadePullQuickSettings() throws Throwable {
        validate(MetricsEvent.ACTION_SHADE_QS_PULL, 9, 175, 3444);
    }

    public void testShadeTapQuickSettings() throws Throwable {
        validate(MetricsEvent.ACTION_SHADE_QS_TAP, 10, 0, 0);
    }

    private void validate(int view, int type, int len, int vel) {
        int t = 1000;
        Object[] objects = new Object[3];
        objects[0] = type;
        objects[1] = len;
        objects[2] = vel;

        mParser.parseEvent(mLogger, t, objects);

        verify(mLogger, times(1)).addEvent(mProtoCaptor.capture());

        LogMaker proto = mProtoCaptor.getValue();
        assertEquals(t, proto.getTimestamp());
        assertEquals(view, proto.getCategory());
        assertEquals(MetricsEvent.TYPE_ACTION, proto.getType());
    }

    public void testIgnoreUnexpectedData() throws Throwable {
        int t = 1000;
        Object[] objects = new Object[4];
        objects[0] = 1;
        objects[1] = 0;
        objects[2] = 0;
        objects[3] = "foo";

        mParser.parseEvent(mLogger, t, objects);

        verify(mLogger, times(1)).addEvent((LogMaker) anyObject());
    }
}
Loading