// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// API and definitions exposed by the Telemetry Event Services. This API is
// normally consumed by the Telemetry Extension APIs implementation.
// Note: this is a subset of the cros_healthd event service interface which is
// located in
// //chromeos/ash/services/cros_healthd/public/mojom/cros_healthd_events.mojom.
// This interface serves as PII filtering and data post-processing service
// between the source (cros_healthd) and the clients
// (third-party telemetry extensions).
// WARNING: This mojom and its implementation is designed for use only by the
// telemetry extension. Certain input components such as touchpad event should
// not be connected by clients outside of the telemetry extension. Please
// consider alternatives such as wayland and pure JS solutions.
module crosapi.mojom;
import "chromeos/crosapi/mojom/probe_service.mojom";
import "chromeos/crosapi/mojom/telemetry_extension_exception.mojom";
import "chromeos/crosapi/mojom/telemetry_keyboard_event.mojom";
import "chromeos/crosapi/mojom/nullable_primitives.mojom";
// Audio jack event info. This is emitted when the
// audio jack is plugged in or out.
//
// NextMinVersion: 2, NextIndex: 2
[Stable]
struct TelemetryAudioJackEventInfo {
[Stable, Extensible]
enum State {
// This is required for backwards compatibility, should not be used.
[Default] kUnmappedEnumField = 0,
// Audio jack added.
kAdd = 1,
// Audio jack removed.
kRemove = 2,
};
State state@0;
[Stable, Extensible]
enum DeviceType {
// This is required for backwards compatibility, should not be used.
[Default] kUnmappedEnumField,
// The device is a headphone.
kHeadphone,
// The device is a microphone.
kMicrophone,
};
[MinVersion=1] DeviceType device_type@1;
};
// Lid event info. This is emitted when the lid is closed or opened.
//
// NextMinVersion: 1, NextIndex: 1
[Stable]
struct TelemetryLidEventInfo {
[Stable, Extensible]
enum State {
// This is required for backwards compatibility, should not be used.
[Default] kUnmappedEnumField = 0,
// Lid closed.
kClosed = 1,
// Lid opened.
kOpened = 2,
};
State state@0;
};
// USB event info. This is emitted when a USB device is connected or
// disconnected.
//
// NextMinVersion: 1, NextIndex: 6
[Stable]
struct TelemetryUsbEventInfo {
// Vendor name.
string vendor@0;
// Name, model name or product name.
string name@1;
// Vendor ID.
uint16 vid@2;
// Product ID.
uint16 pid@3;
// USB device categories.
// https://www.usb.org/defined-class-codes
array<string> categories@4;
[Stable, Extensible]
enum State {
// This is required for backwards compatibility, should not be used.
[Default] kUnmappedEnumField = 0,
// USB plugs in.
kAdd = 1,
// USB plugs out.
kRemove = 2,
};
State state@5;
};
// External display event info. This is emitted when an external display is
// plugged in or plugged out.
//
// NextMinVersion: 1, NextIndex: 1
[Stable, RenamedFrom="crosapi.mojom.TelemetryHdmiEventInfo"]
struct TelemetryExternalDisplayEventInfo {
[Stable, Extensible]
enum State {
// This is required for backwards compatibility, should not be used.
[Default] kUnmappedEnumField = 0,
// External display plugged in.
kAdd = 1,
// External display plugged out.
kRemove = 2,
};
State state@0;
// On external display event, also report information about the display.
[MinVersion=1] ProbeExternalDisplayInfo? display_info@1;
};
// SD card event info. This is emitted when a SD card is plugged in or plugged
// out.
//
// NextMinVersion: 1, NextIndex: 6
[Stable]
struct TelemetrySdCardEventInfo {
[Stable, Extensible]
enum State {
// This is required for backwards compatibility, should not be used.
[Default] kUnmappedEnumField = 0,
// SD card plugged in.
kAdd = 1,
// SD card plugged out.
kRemove = 2,
};
State state@0;
};
// Power event info. This is emitted when the device begins/stops consuming from
// an external power source or the system receives/completes a suspend request.
//
// NextMinVersion: 1, NextIndex: 1
[Stable]
struct TelemetryPowerEventInfo {
[Stable, Extensible]
enum State {
// This is required for backwards compatibility, should not be used.
[Default] kUnmappedEnumField = 0,
// The device began consuming from an external power source.
kAcInserted = 1,
// The device stopped consuming from an external power source.
kAcRemoved = 2,
// The system received a suspend request.
kOsSuspend = 3,
// The system completed a suspend request, i.e. resumed again.
kOsResume = 4,
};
State state@0;
};
// Stylus garage event info. This is emitted when the stylus is inserted into or
// removed from the garage.
//
// NextMinVersion: 1, NextIndex: 1
[Stable]
struct TelemetryStylusGarageEventInfo {
[Stable, Extensible]
enum State {
// This is required for backwards compatibility, should not be used.
[Default] kUnmappedEnumField = 0,
// Stylus inserted into the garage.
kInserted,
// Stylus removed from the garage.
kRemoved,
};
State state@0;
};
// An enumeration of input touch buttons. The enumeration refers to the
// physical button that is present in some touchpads under the surface. Clicks
// resulting from gestures such as two finger right-click are not included
// here. Separate physical buttons external to the touchpad are also not
// included.
//
// NextMinVersion: 1, NextIndex: 4
[Stable, Extensible]
enum TelemetryInputTouchButton {
// This is required for backwards compatibility, should not be used.
[Default] kUnmappedEnumField = 0,
// Left key.
kLeft = 1,
// Middle key.
kMiddle = 2,
// Right key.
kRight = 3,
};
// Emitted when some touchpad button is pressed or released.
//
// NextMinVersion: 1, NextIndex: 2
[Stable]
struct TelemetryTouchpadButtonEventInfo {
// The button that corresponds to this event.
TelemetryInputTouchButton button@0;
[Stable, Extensible]
// Whether the button is pressed or released.
enum State {
// This is required for backwards compatibility, should not be used.
[Default] kUnmappedEnumField = 0,
// Lid closed.
kPressed = 1,
// Lid opened.
kReleased = 2,
};
State state@1;
};
// Touch point info.
//
// NextMinVersion: 1, NextIndex: 6
[Stable]
struct TelemetryTouchPointInfo {
// An id to track an initiated contact throughout its life cycle.
uint32 tracking_id@0;
// The x position in the cartesian XY plane. The value ranges from 0 to
// |max_x| as defined in TelemetryTouchpadConnectedEventInfo.
uint32 x@1;
// The y position in the cartesian XY plane. The value ranges from 0 to
// |max_y| as defined in TelemetryTouchpadConnectedEventInfo.
uint32 y@2;
// The pressure applied to the touch contact. The value ranges from 0 to
// |max_pressure| as defined in TelemetryTouchpadConnectedEventInfo.
UInt32Value? pressure@3;
// The length of the longer dimension of the touch contact.
UInt32Value? touch_major@4;
// The length of the shorter dimension of the touch contact.
UInt32Value? touch_minor@5;
};
// Emitted when new touch points are updated.
//
// NextMinVersion: 1, NextIndex: 1
[Stable]
struct TelemetryTouchpadTouchEventInfo {
// The touch points reported by the touchpad.
array<TelemetryTouchPointInfo> touch_points@0;
};
// Emitted once the observer get connected to the touchpad events. This will be
// the first event from the touchpad.
//
// NextMinVersion: 1, NextIndex: 4
[Stable]
struct TelemetryTouchpadConnectedEventInfo {
// The maximum possible x position of touch points.
uint32 max_x@0;
// The maximum possible y position of touch points.
uint32 max_y@1;
// The maximum possible pressure of touch points, or 0 if pressure is not
// supported.
uint32 max_pressure@2;
// The supported buttons;
array<TelemetryInputTouchButton> buttons@3;
};
// Emitted when new touch points are updated.
//
// NextMinVersion: 1, NextIndex: 1
[Stable]
struct TelemetryTouchscreenTouchEventInfo {
// The touch points reported by the touchscreen.
array<TelemetryTouchPointInfo> touch_points@0;
};
// Emitted once the observer get connected to the touchscreen events. This will
// be the first event from the touchscreen.
//
// NextMinVersion: 1, NextIndex: 3
[Stable]
struct TelemetryTouchscreenConnectedEventInfo {
// The maximum possible x position of touch points.
uint32? max_x@0;
// The maximum possible y position of touch points.
uint32? max_y@1;
// The maximum possible pressure of touch points, or 0 if pressure is not
// supported.
uint32? max_pressure@2;
};
// Stylus touch point info.
//
// NextMinVersion: 1, NextIndex: 3
[Stable]
struct TelemetryStylusTouchPointInfo {
// The x position in the cartesian XY plane. The value ranges from 0 to
// |max_x| as defined in TelemetryStylusConnectedEventInfo.
uint32? x@0;
// The y position in the cartesian XY plane. The value ranges from 0 to
// |max_y| as defined in TelemetryStylusConnectedEventInfo.
uint32? y@1;
// The pressure applied to the touch contact. The value ranges from 0 to
// |max_pressure| as defined in TelemetryStylusConnectedEventInfo.
uint32? pressure@2;
};
// Emitted when new touch point is updated.
//
// NextMinVersion: 1, NextIndex: 1
[Stable]
struct TelemetryStylusTouchEventInfo {
// The info of the stylus touch point. A null touch point means the stylus
// leaves the contact.
TelemetryStylusTouchPointInfo? touch_point@0;
};
// Emitted once the observer get connected to the stylus events. This will be
// the first event from the stylus.
//
// NextMinVersion: 1, NextIndex: 3
[Stable]
struct TelemetryStylusConnectedEventInfo {
// The maximum possible x position of touch points.
uint32? max_x@0;
// The maximum possible y position of touch points.
uint32? max_y@1;
// The maximum possible pressure of touch points, or 0 if pressure is not
// supported.
uint32? max_pressure@2;
};
// Union of event info.
//
// NextMinVersion: 11, NextIndex: 16
[Stable, Extensible]
union TelemetryEventInfo {
// The default value for forward compatibility. All the unknown type will be
// mapped to this.
[Default] uint8 default_type@0;
// Audio jack event info.
TelemetryAudioJackEventInfo audio_jack_event_info@1;
// Lid event info.
[MinVersion=1] TelemetryLidEventInfo lid_event_info@2;
// Usb event info.
[MinVersion=2] TelemetryUsbEventInfo usb_event_info@3;
// SD card event info.
[MinVersion=3] TelemetrySdCardEventInfo sd_card_event_info@4;
// Power event info.
[MinVersion=4] TelemetryPowerEventInfo power_event_info@5;
// Keyboard diagnostic event info.
[MinVersion=5] TelemetryKeyboardDiagnosticEventInfo
keyboard_diagnostic_event_info@6;
// Stylus garage event info.
[MinVersion=6] TelemetryStylusGarageEventInfo stylus_garage_event_info@7;
// Touchpad Button event info.
[MinVersion=7] TelemetryTouchpadButtonEventInfo touchpad_button_event_info@8;
// Touchpad Touch event info.
[MinVersion=7] TelemetryTouchpadTouchEventInfo touchpad_touch_event_info@9;
// Touchpad Connected event info.
[MinVersion=7] TelemetryTouchpadConnectedEventInfo
touchpad_connected_event_info@10;
// External display event info.
[MinVersion=8] TelemetryExternalDisplayEventInfo
external_display_event_info@11;
// Stylus Touch event info.
[MinVersion=9] TelemetryStylusTouchEventInfo stylus_touch_event_info@12;
// Stylus connected event info.
[MinVersion=9] TelemetryStylusConnectedEventInfo
stylus_connected_event_info@13;
// Touchscreen Touch event info.
[MinVersion=10] TelemetryTouchscreenTouchEventInfo
touchscreen_touch_event_info@14;
// Touchscreen Connected event info.
[MinVersion=10] TelemetryTouchscreenConnectedEventInfo
touchscreen_connected_event_info@15;
};
// An enumeration of event categories.
//
// NextMinVersion: 11, NextIndex: 16
[Stable, Extensible]
enum TelemetryEventCategoryEnum {
// This is required for backwards compatibility, should not be used.
[Default] kUnmappedEnumField = 0,
kAudioJack = 1,
[MinVersion=1] kLid = 2,
[MinVersion=2] kUsb = 3,
[MinVersion=3] kSdCard = 4,
[MinVersion=4] kPower = 5,
[MinVersion=5] kKeyboardDiagnostic = 6,
[MinVersion=6] kStylusGarage = 7,
[MinVersion=7] kTouchpadButton = 8,
[MinVersion=7] kTouchpadTouch = 9,
[MinVersion=7] kTouchpadConnected = 10,
[MinVersion=8] kExternalDisplay = 11,
[MinVersion=9] kStylusTouch = 12,
[MinVersion=9] kStylusConnected = 13,
[MinVersion=10] kTouchscreenTouch = 14,
[MinVersion=10] kTouchscreenConnected = 15,
};
// Implemented by clients who desire events.
//
// NextMinVersion: 1, NextIndex: 1
[Stable]
interface TelemetryEventObserver {
// Fired when an event happens.
OnEvent@0(TelemetryEventInfo info);
};
// Event interface exposed to Lacros.
//
// NextMinVersion: 1, NextIndex: 3
[Stable, Uuid="9771fd1b-79b9-4698-b20f-3168d2af3f77"]
interface TelemetryEventService {
// Adds an observer to be notified on events. The caller can remove the
// observer created by this call by closing their end of the message pipe.
//
// The request:
// * |category| - Event category.
// * |observer| - Event observer to be added to crosapi.
AddEventObserver@1(
TelemetryEventCategoryEnum category,
pending_remote<TelemetryEventObserver> observer);
// Checks whether an event is supported. It does the same support status check
// as in `AddEventObserver()` and returns immediately after the check.
//
// The request:
// * |category| - Event category to check.
//
// The response:
// * |status| - See the documentation of `TelemetryExtensionSupportStatus`.
IsEventSupported@2(TelemetryEventCategoryEnum category)
=> (TelemetryExtensionSupportStatus status);
};