From 561545af711aa23058686d51261f9aea6f64694b Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Tue, 27 Feb 2024 16:24:50 +0000 Subject: [PATCH] [KBM]Send daily activation telemetry (#31593) * [KBM]Send daily activation telemetry * Update src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.cpp Co-authored-by: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com> --------- Co-authored-by: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com> --- .../KeyboardEventHandlers.cpp | 70 +++++++++++++++++++ .../KeyboardManagerEngineLibrary/trace.cpp | 60 ++++++++++++++++ .../KeyboardManagerEngineLibrary/trace.h | 18 +++++ 3 files changed, 148 insertions(+) diff --git a/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.cpp b/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.cpp index b70c0dd32b..d4a21ce104 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.cpp @@ -118,6 +118,28 @@ namespace KeyboardEventHandlers ResetIfModifierKeyForLowerLevelKeyHandlers(ii, itSk, it->first); } } + + // Send daily telemetry event for Keyboard Manager key activation. + if (remapToKey) + { + static int dayWeLastSentKeyToKeyTelemetryOn = -1; + auto currentDay = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + if (dayWeLastSentKeyToKeyTelemetryOn != currentDay) + { + Trace::DailyKeyToKeyRemapInvoked(); + dayWeLastSentKeyToKeyTelemetryOn = currentDay; + } + } + else + { + static int dayWeLastSentKeyToShortcutTelemetryOn = -1; + auto currentDay = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + if (dayWeLastSentKeyToShortcutTelemetryOn != currentDay) + { + Trace::DailyKeyToShortcutRemapInvoked(); + dayWeLastSentKeyToShortcutTelemetryOn = currentDay; + } + } } return 1; @@ -348,6 +370,54 @@ namespace KeyboardEventHandlers UINT res = ii.SendVirtualInput(static_cast(key_count), keyEventList, sizeof(INPUT)); delete[] keyEventList; + // Send daily telemetry event for Keyboard Manager key activation. + if (activatedApp.has_value()) + { + if (remapToKey) + { + static int dayWeLastSentAppSpecificShortcutToKeyTelemetryOn = -1; + auto currentDay = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + if (dayWeLastSentAppSpecificShortcutToKeyTelemetryOn != currentDay) + { + Trace::DailyAppSpecificShortcutToKeyRemapInvoked(); + dayWeLastSentAppSpecificShortcutToKeyTelemetryOn = currentDay; + } + } + else if (remapToShortcut) + { + static int dayWeLastSentAppSpecificShortcutToShortcutTelemetryOn = -1; + auto currentDay = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + if (dayWeLastSentAppSpecificShortcutToShortcutTelemetryOn != currentDay) + { + Trace::DailyAppSpecificShortcutToShortcutRemapInvoked(); + dayWeLastSentAppSpecificShortcutToShortcutTelemetryOn = currentDay; + } + } + } + else + { + if (remapToKey) + { + static int dayWeLastSentShortcutToKeyTelemetryOn = -1; + auto currentDay = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + if (dayWeLastSentShortcutToKeyTelemetryOn != currentDay) + { + Trace::DailyShortcutToKeyRemapInvoked(); + dayWeLastSentShortcutToKeyTelemetryOn = currentDay; + } + } + else if (remapToShortcut) + { + static int dayWeLastSentShortcutToShortcutTelemetryOn = -1; + auto currentDay = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + if (dayWeLastSentShortcutToShortcutTelemetryOn != currentDay) + { + Trace::DailyShortcutToShortcutRemapInvoked(); + dayWeLastSentShortcutToShortcutTelemetryOn = currentDay; + } + } + } + return 1; } } diff --git a/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/trace.cpp b/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/trace.cpp index 1cf0c60e1f..394840de32 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/trace.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/trace.cpp @@ -19,6 +19,66 @@ void Trace::UnregisterProvider() noexcept TraceLoggingUnregister(g_hProvider); } +// Log if a key to key remap has been invoked today. +void Trace::DailyKeyToKeyRemapInvoked() noexcept +{ + TraceLoggingWrite( + g_hProvider, + "KeyboardManager_DailyKeyToKeyRemapInvoked", + ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), + TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE)); +} + +// Log if a key to shortcut remap has been invoked today. +void Trace::DailyKeyToShortcutRemapInvoked() noexcept +{ + TraceLoggingWrite( + g_hProvider, + "KeyboardManager_DailyKeyToShortcutRemapInvoked", + ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), + TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE)); +} + +// Log if a shortcut to key remap has been invoked today. +void Trace::DailyShortcutToKeyRemapInvoked() noexcept +{ + TraceLoggingWrite( + g_hProvider, + "KeyboardManager_DailyShortcutToKeyRemapInvoked", + ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), + TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE)); +} + +// Log if a shortcut to shortcut remap has been invoked today. +void Trace::DailyShortcutToShortcutRemapInvoked() noexcept +{ + TraceLoggingWrite( + g_hProvider, + "KeyboardManager_DailyShortcutToShortcutRemapInvoked", + ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), + TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE)); +} + +// Log if an app specific shortcut to key remap has been invoked today. +void Trace::DailyAppSpecificShortcutToKeyRemapInvoked() noexcept +{ + TraceLoggingWrite( + g_hProvider, + "KeyboardManager_DailyAppSpecificShortcutToKeyRemapInvoked", + ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), + TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE)); +} + +// Log if an app specific shortcut to shortcut remap has been invoked today. +void Trace::DailyAppSpecificShortcutToShortcutRemapInvoked() noexcept +{ + TraceLoggingWrite( + g_hProvider, + "KeyboardManager_DailyAppSpecificShortcutToShortcutRemapInvoked", + ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), + TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE)); +} + // Log if a key remap has been invoked (not being used currently, due to being garrulous) void Trace::KeyRemapInvoked(bool isKeyToKey) noexcept { diff --git a/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/trace.h b/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/trace.h index 0281b59c81..9408a38e0e 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/trace.h +++ b/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/trace.h @@ -8,6 +8,24 @@ public: static void RegisterProvider() noexcept; static void UnregisterProvider() noexcept; + // Log if a key to key remap has been invoked today. + static void DailyKeyToKeyRemapInvoked() noexcept; + + // Log if a key to shortcut remap has been invoked today. + static void DailyKeyToShortcutRemapInvoked() noexcept; + + // Log if a shortcut to key remap has been invoked today. + static void DailyShortcutToKeyRemapInvoked() noexcept; + + // Log if a shortcut to shortcut remap has been invoked today. + static void DailyShortcutToShortcutRemapInvoked() noexcept; + + // Log if an app specific shortcut to key remap has been invoked today. + static void DailyAppSpecificShortcutToKeyRemapInvoked() noexcept; + + // Log if an app specific shortcut to shortcut remap has been invoked today. + static void DailyAppSpecificShortcutToShortcutRemapInvoked() noexcept; + // Log if a key remap has been invoked (not being used currently, due to being garrulous) static void KeyRemapInvoked(bool isKeyToKey) noexcept;