跳转至

借助 event log 有效排查问题

system log

user版本log有限,看到关键的一行log。如下:

11-15 15:39:34.053  2839  3519 I GestureLauncherService: Power button double tap gesture detected, launching camera. Interval=202ms

通过这行log我们是就有确定 BSP 上报了两次 power 键的时间间隔是 202 ms。 GestureLauncherService检测到了,并且调了 handleCameraGesture() 函数,但 handleCameraGesture() 函数里的 log 在 user 版本不打印,所以不能完全确定 handleCameraGesture() 函数是调到 StatusBarManagerService.onCameraLaunchGestureDetected() 里。 也就是 现在要排查 handleCameraGesture() 返回的是 true 还是 false 。

public class GestureLauncherService extends SystemService {

    private static final boolean DBG = false;

    /**
     * Attempts to intercept power key down event by detecting certain gesture patterns
     *
     * @param interactive true if the event's policy contains {@code FLAG_INTERACTIVE}
     * @param outLaunched true if some action is taken as part of the key intercept (eg, app launch)
     * @return true if the key down event is intercepted
     */
    public boolean interceptPowerKeyDown(KeyEvent event, boolean interactive,
            MutableBoolean outLaunched) {
        ...

        if (launchCamera) {
            Slog.i(TAG, "Power button double tap gesture detected, launching camera. Interval="
                    + powerTapInterval + "ms");
            launchCamera = handleCameraGesture(false /* useWakelock */,
                    StatusBarManager.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP);
            if (launchCamera) {
                mMetricsLogger.action(MetricsEvent.ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE,
                        (int) powerTapInterval);
                mUiEventLogger.log(GestureLauncherEvent.GESTURE_CAMERA_DOUBLE_TAP_POWER);
            }
        }

        ...
    }

    /**
     * @return true if camera was launched, false otherwise.
     */
    @VisibleForTesting
    boolean handleCameraGesture(boolean useWakelock, int source) {
        Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "GestureLauncher:handleCameraGesture");
        try {
            boolean userSetupComplete = isUserSetupComplete();
            if (!userSetupComplete) {
                if (DBG) {
                    Slog.d(TAG, String.format(
                            "userSetupComplete = %s, ignoring camera gesture.",
                            userSetupComplete));
                }
                return false;
            }
            if (DBG) {
                Slog.d(TAG, String.format(
                        "userSetupComplete = %s, performing camera gesture.",
                        userSetupComplete));
            }

            if (useWakelock) {
                // Make sure we don't sleep too early
                mWakeLock.acquire(500L);
            }
            StatusBarManagerInternal service = LocalServices.getService(
                    StatusBarManagerInternal.class);
            service.onCameraLaunchGestureDetected(source);
            return true;
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
        }
    }

}

event log

仔细看代码可以发现,调用 handleCameraGesture() 函数后,根据其返回值判断,如果是 true 则执行:

launchCamera = handleCameraGesture(false /* useWakelock */,
        StatusBarManager.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP);
if (launchCamera) {
    // MetricsEvent.ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE = 255;
    mMetricsLogger.action(MetricsEvent.ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE,
            (int) powerTapInterval);
    mUiEventLogger.log(GestureLauncherEvent.GESTURE_CAMERA_DOUBLE_TAP_POWER);
}

这就好办了,我们只需要通过 event log 确定在同一时间内是否有 MetricsEvent.ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE 就好了。

那我们接着看 MetricsLogger.action() 都在干嘛。

frameworks/base/proto/src/metrics_constants/metrics_constants.proto

public class MetricsLogger {

    public void action(int category, int value) {
        // MetricsEvent.TYPE_ACTION = 4;
        saveLog(new LogMaker(category).setType(MetricsEvent.TYPE_ACTION).setSubtype(value));
    }
}


public class LogMaker {
    public LogMaker(int category) {
        setCategory(category);
    }

    public LogMaker setCategory(int category) {
        // MetricsEvent.RESERVED_FOR_LOGBUILDER_CATEGORY = 575;
        entries.put(MetricsEvent.RESERVED_FOR_LOGBUILDER_CATEGORY, category);
        return this;
    }

     public LogMaker setType(int type) {
        // MetricsEvent.RESERVED_FOR_LOGBUILDER_TYPE = 758;
        entries.put(MetricsEvent.RESERVED_FOR_LOGBUILDER_TYPE, type);
        return this;
    }

    public LogMaker setSubtype(int subtype) {
        // MetricsEvent.RESERVED_FOR_LOGBUILDER_SUBTYPE = 759;
        entries.put(MetricsEvent.RESERVED_FOR_LOGBUILDER_SUBTYPE, subtype);  
        return this;  
    }
}

所以,这里 mMetricsLogger.action(MetricsEvent.ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE, (int) powerTapInterval); 应该保存这样的log:

[MetricsEvent.RESERVED_FOR_LOGBUILDER_CATEGORY, MetricsEvent.ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE
MetricsEvent.RESERVED_FOR_LOGBUILDER_TYPE, MetricsEvent.TYPE_ACTION
MetricsEvent.RESERVED_FOR_LOGBUILDER_SUBTYPE, powerTapInterval]

也就是有6个数字,[category, category_value, type, type_value, subtype, subtype-value]

最终也就是:

[757,255,758,4,759,powerTapInterval]

如果通过查看 event log 可以看到:

11-15 15:39:34.053  2839  3519 I sysui_multi_action: [757,255,758,4,759,202]

nice!这里已经可以证明 handleCameraGesture() 函数返回 true ;也就是调到了 StatusBarManagerService.onCameraLaunchGestureDetected() 。

评论