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

Commit b3a18767 authored by Vaibhav Devmurari's avatar Vaibhav Devmurari Committed by Gerrit Code Review
Browse files

Merge "Log device bus for keyboard metrics" into main

parents ec12e1cd d3b7a177
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -369,15 +369,15 @@ public final class KeyboardMetricsCollector {
        if (inputDevice == null || inputDevice.isVirtual() || !inputDevice.isFullKeyboard()) {
            return;
        }
        int vendorId = inputDevice.getVendorId();
        int productId = inputDevice.getProductId();
        if (keyboardSystemEvent == null) {
            Slog.w(TAG, "Invalid keyboard event logging, keycode = " + Arrays.toString(keyCodes)
                    + ", modifier state = " + modifierState);
            return;
        }
        FrameworkStatsLog.write(FrameworkStatsLog.KEYBOARD_SYSTEMS_EVENT_REPORTED,
                vendorId, productId, keyboardSystemEvent.getIntValue(), keyCodes, modifierState);
                inputDevice.getVendorId(), inputDevice.getProductId(),
                keyboardSystemEvent.getIntValue(), keyCodes, modifierState,
                inputDevice.getDeviceBus());

        if (DEBUG) {
            Slog.d(TAG, "Logging Keyboard system event: " + keyboardSystemEvent.mName);
@@ -402,7 +402,7 @@ public final class KeyboardMetricsCollector {
        // Push the atom to Statsd
        FrameworkStatsLog.write(FrameworkStatsLog.KEYBOARD_CONFIGURED,
                event.isFirstConfiguration(), event.getVendorId(), event.getProductId(),
                proto.getBytes());
                proto.getBytes(), event.getDeviceBus());

        if (DEBUG) {
            Slog.d(TAG, "Logging Keyboard configuration event: " + event);
@@ -467,6 +467,10 @@ public final class KeyboardMetricsCollector {
            return mInputDevice.getProductId();
        }

        public int getDeviceBus() {
            return mInputDevice.getDeviceBus();
        }

        public boolean isFirstConfiguration() {
            return mIsFirstConfiguration;
        }
@@ -479,6 +483,7 @@ public final class KeyboardMetricsCollector {
        public String toString() {
            return "InputDevice = {VendorId = " + Integer.toHexString(getVendorId())
                    + ", ProductId = " + Integer.toHexString(getProductId())
                    + ", Device Bus = " + Integer.toHexString(getDeviceBus())
                    + "}, isFirstConfiguration = " + mIsFirstConfiguration
                    + ", LayoutConfigurations = " + mLayoutConfigurations;
        }
+12 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ private fun createKeyboard(
    deviceId: Int,
    vendorId: Int,
    productId: Int,
    deviceBus: Int,
    languageTag: String?,
    layoutType: String?
): InputDevice =
@@ -42,6 +43,7 @@ private fun createKeyboard(
        .setExternal(true)
        .setVendorId(vendorId)
        .setProductId(productId)
        .setDeviceBus(deviceBus)
        .setKeyboardLanguageTag(languageTag)
        .setKeyboardLayoutType(layoutType)
        .build()
@@ -67,6 +69,7 @@ class KeyboardMetricsCollectorTests {
        const val DEVICE_ID = 1
        const val DEFAULT_VENDOR_ID = 123
        const val DEFAULT_PRODUCT_ID = 456
        const val DEFAULT_DEVICE_BUS = 789
    }

    @Test
@@ -77,6 +80,7 @@ class KeyboardMetricsCollectorTests {
                    DEVICE_ID,
                    DEFAULT_VENDOR_ID,
                    DEFAULT_PRODUCT_ID,
                    DEFAULT_DEVICE_BUS,
                    null,
                    null
                )
@@ -92,6 +96,7 @@ class KeyboardMetricsCollectorTests {
                    DEVICE_ID,
                    DEFAULT_VENDOR_ID,
                    DEFAULT_PRODUCT_ID,
                    DEFAULT_DEVICE_BUS,
                    null,
                    null
                )
@@ -107,6 +112,7 @@ class KeyboardMetricsCollectorTests {
                DEVICE_ID,
                DEFAULT_VENDOR_ID,
                DEFAULT_PRODUCT_ID,
                DEFAULT_DEVICE_BUS,
                "de-CH",
                "qwertz"
            )
@@ -135,6 +141,11 @@ class KeyboardMetricsCollectorTests {
            DEFAULT_PRODUCT_ID,
            event.productId
        )
        assertEquals(
             "KeyboardConfigurationEvent should pick device bus from provided InputDevice",
             DEFAULT_DEVICE_BUS,
             event.deviceBus
        )
        assertTrue(event.isFirstConfiguration)

        assertEquals(
@@ -178,6 +189,7 @@ class KeyboardMetricsCollectorTests {
                DEVICE_ID,
                DEFAULT_VENDOR_ID,
                DEFAULT_PRODUCT_ID,
                DEFAULT_DEVICE_BUS,
                "und", // Undefined language tag
                "azerty"
            )
+4 −2
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ public class ShortcutLoggingTests extends ShortcutKeyTestBase {

    private static final int VENDOR_ID = 0x123;
    private static final int PRODUCT_ID = 0x456;
    private static final int DEVICE_BUS = 0x789;
    private static final int META_KEY = KeyEvent.KEYCODE_META_LEFT;
    private static final int META_ON = MODIFIER.get(KeyEvent.KEYCODE_META_LEFT);
    private static final int ALT_KEY = KeyEvent.KEYCODE_ALT_LEFT;
@@ -224,7 +225,7 @@ public class ShortcutLoggingTests extends ShortcutKeyTestBase {
    @Override
    public void setUp() {
        super.setUp();
        mPhoneWindowManager.overrideKeyEventSource(VENDOR_ID, PRODUCT_ID);
        mPhoneWindowManager.overrideKeyEventSource(VENDOR_ID, PRODUCT_ID, DEVICE_BUS);
        mPhoneWindowManager.overrideLaunchHome();
        mPhoneWindowManager.overrideSearchKeyBehavior(
                PhoneWindowManager.SEARCH_BEHAVIOR_TARGET_ACTIVITY);
@@ -240,6 +241,7 @@ public class ShortcutLoggingTests extends ShortcutKeyTestBase {
            int expectedKey, int expectedModifierState) {
        sendKeyCombination(testKeys, 0);
        mPhoneWindowManager.assertShortcutLogged(VENDOR_ID, PRODUCT_ID, expectedLogEvent,
                expectedKey, expectedModifierState, "Failed while executing " + testName);
                expectedKey, expectedModifierState, DEVICE_BUS,
                "Failed while executing " + testName);
    }
}
+11 −6
Original line number Diff line number Diff line
@@ -423,10 +423,15 @@ class TestPhoneWindowManager {
        doReturn(isShowing).when(mKeyguardServiceDelegate).isShowing();
    }

    void overrideKeyEventSource(int vendorId, int productId) {
        InputDevice device = new InputDevice.Builder().setId(1).setVendorId(vendorId).setProductId(
                productId).setSources(InputDevice.SOURCE_KEYBOARD).setKeyboardType(
                InputDevice.KEYBOARD_TYPE_ALPHABETIC).build();
    void overrideKeyEventSource(int vendorId, int productId, int deviceBus) {
        InputDevice device = new InputDevice.Builder()
                .setId(1)
                .setVendorId(vendorId)
                .setProductId(productId)
                .setDeviceBus(deviceBus)
                .setSources(InputDevice.SOURCE_KEYBOARD)
                .setKeyboardType(InputDevice.KEYBOARD_TYPE_ALPHABETIC)
                .build();
        doReturn(mInputManager).when(mContext).getSystemService(eq(InputManager.class));
        doReturn(device).when(mInputManager).getInputDevice(anyInt());
    }
@@ -604,10 +609,10 @@ class TestPhoneWindowManager {
    }

    void assertShortcutLogged(int vendorId, int productId, KeyboardLogEvent logEvent,
            int expectedKey, int expectedModifierState, String errorMsg) {
            int expectedKey, int expectedModifierState, int deviceBus, String errorMsg) {
        waitForIdle();
        verify(() -> FrameworkStatsLog.write(FrameworkStatsLog.KEYBOARD_SYSTEMS_EVENT_REPORTED,
                        vendorId, productId, logEvent.getIntValue(), new int[]{expectedKey},
                        expectedModifierState), description(errorMsg));
                        expectedModifierState, deviceBus), description(errorMsg));
    }
}