chromium/components/reporting/proto/synced/metric_data.proto

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

syntax = "proto2";

import "components/reporting/proto/synced/session_affiliated_user.proto";
import "components/services/app_service/public/protos/app_types.proto";

option optimize_for = LITE_RUNTIME;

package reporting;

// Diagnostics routine verdict.
enum RoutineVerdict {
  ROUTINE_VERDICT_UNSPECIFIED = 0;
  // Routine ran successfully and no connectivity problem found.
  NO_PROBLEM = 1;
  // Routine ran successfully and connectivity problem found.
  PROBLEM = 2;
  // Routine has not been run.
  NOT_RUN = 3;
}

// Https latency problems.
enum HttpsLatencyProblem {
  HTTPS_LATENCY_PROBLEM_UNSPECIFIED = 0;
  // One or more DNS resolutions resulted in a failure.
  FAILED_DNS_RESOLUTIONS = 1;
  // One or more HTTPS requests resulted in a failure.
  FAILED_HTTPS_REQUESTS = 2;
  // HTTPS request latency is high.
  HIGH_LATENCY = 3;
  // HTTPS request latency is very high.
  VERY_HIGH_LATENCY = 4;
}

// Data that describe the result of the https latency diagnostics routine.
// Default checking rate: 10 mins.
// Policy: ReportDeviceNetworkStatus
// Policy default: true
message HttpsLatencyRoutineData {
  // Https latency routine verdict.
  optional RoutineVerdict verdict = 1;
  // Https latency routine problem if a problem occurred.
  optional HttpsLatencyProblem problem = 2;
  // Https latency in milliseconds if routine succeeded or failed because of
  // `HIGH_LATENCY` or `VERY_HIGH_LATENCY`.
  optional int64 latency_ms = 3;
}

// Data describing observed network bandwidth
// Default checking rate: 60 mins.
// Checking rate policy: ReportDeviceNetworkTelemetryCollectionRateMs
// Policy: ReportDeviceNetworkStatus
// Policy default: true
message BandwidthData {
  // Download speed in kbps
  optional int64 download_speed_kbps = 1;
  // Upload speed in kbps
  optional int64 upload_speed_kbps = 2;
}

// Network connection state.
enum NetworkConnectionState {
  NETWORK_CONNECTION_STATE_UNSPECIFIED = 0;
  // The network is connected and internet connectivity is available.
  ONLINE = 1;
  // The network is connected and not in a detected portal state, but
  // internet connectivity may not be available.
  CONNECTED = 2;
  // The network is connected but a portal state was detected. Internet
  // connectivity may be limited.
  PORTAL = 3;
  // The network is in the process of connecting.
  CONNECTING = 4;
  // The network is not connected.
  NOT_CONNECTED = 5;
}

// Network connection type.
enum NetworkType {
  NETWORK_TYPE_UNSPECIFIED = 0;
  CELLULAR = 1;
  ETHERNET = 2;
  TETHER = 3;
  VPN = 4;
  WIFI = 5;
}

// A single network telemetry data collected at a specific point of time.
// Contained inside the `NetworksTelemetry` message.
// Default checking rate: 60 mins.
// Checking rate policy: ReportDeviceNetworkTelemetryCollectionRateMs,
// Policy: ReportDeviceNetworkStatus
// Policy default: true
message NetworkTelemetry {
  // Unique identifier of the network.
  optional string guid = 1;
  // Current connection state of the network.
  optional NetworkConnectionState connection_state = 2;
  // Signal strength of the network provided only for wireless networks. Values
  // are normalized between 0 to 100 inclusive.
  optional int32 signal_strength = 3;
  // For networks associated with a device, the path of the device.
  optional string device_path = 4;
  // The IP address this interface is bound to, if any.
  optional string ip_address = 5;
  // The gateway IP for this interface, if any.
  optional string gateway = 6;
  // Network connection type.
  optional NetworkType type = 7;

  reserved 8;

  // Transmission bit rate measured in Mbps.
  optional int64 tx_bit_rate_mbps = 9;
  // Receiving bit rate measured in Mbps.
  optional int64 rx_bit_rate_mbps = 10;
  // Transmission power measured in dBm.
  optional int32 tx_power_dbm = 11;
  // Is wifi encryption key on or not.
  optional bool encryption_on = 12;
  // Wifi link quality.
  optional int64 link_quality = 13;
  // Wifi power management enabled
  optional bool power_management_enabled = 14;
  // Signal strength for wireless networks in dBm.
  optional int32 signal_strength_dbm = 15;
}

// Message describing the NETWORK_CONNECTION_STATE_CHANGE event.
// Policy: ReportDeviceNetworkStatus
// Policy default: true
// Triggered by an event, not collected periodically or once per boot.
// Triggered when there is a network state change from one stage to another one.
message NetworkConnectionStateChangeEventData {
  // Unique identifier of the network.
  optional string guid = 1;
  // New connection state of the network.
  optional NetworkConnectionState connection_state = 2;
}

// Message describing the WIFI_SIGNAL_STRENGTH_LOW and
// WIFI_SIGNAL_STRENGTH_RECOVERED events.
// Policy: ReportDeviceNetworkStatus
// Policy default: true
// Triggered by an event, not collected periodically or once per boot.
// Triggered when the signal of the WiFi network drops below the
// dbm threshold of -70 or if the signal was low and it improves
// above the threshold we also report it.
message SignalStrengthEventData {
  // Unique identifier of the network.
  optional string guid = 1;
  // Signal strength value in dBm.
  optional int32 signal_strength_dbm = 2;
}

// Configured networks telemetry data. This is umbrella networks telemetry proto
// containing multiple network telemetry types, for the specific network
// telemetry take a look at the NetworkTelemetry message. Each of the internal
// messages have separate collection/reporting rates. Policy:
// ReportDeviceNetworkStatus Policy default: true
message NetworksTelemetry {
  // List of each network telemetry.
  repeated NetworkTelemetry network_telemetry = 1;
  // Https latency diagnostics routine result.
  optional HttpsLatencyRoutineData https_latency_data = 2;
  // Observed bandwidth data for active connection
  optional BandwidthData bandwidth_data = 3;
  // Network connection data describing the NETWORK_CONNECTION_STATE_CHANGE
  // event.
  optional NetworkConnectionStateChangeEventData
      network_connection_change_event_data = 4;
  // Signal strength data describing the WIFI_SIGNAL_STRENGTH_LOW and
  // WIFI_SIGNAL_STRENGTH_RECOVERED events.
  optional SignalStrengthEventData signal_strength_event_data = 5;
}

// Security level of the thunderbolt bus.
enum ThunderboltSecurityLevel {
  UNSPECIFIED_THUNDERBOLT_SECURITY_LEVEL = 0;
  // All devices are automatically connected by the firmware. No user approval
  // is needed.
  THUNDERBOLT_SECURITY_NONE_LEVEL = 1;
  // User is asked whether the device is allowed to be connected.
  THUNDERBOLT_SECURITY_USER_LEVEL = 2;
  // User is asked whether the device is allowed to be connected. In addition
  // the device is sent a challenge that should match the expected one based on
  // a random key written to the key sysfs attribute
  THUNDERBOLT_SECURITY_SECURE_LEVEL = 3;
  // The firmware automatically creates tunnels for thunderbolt.
  THUNDERBOLT_SECURITY_DP_ONLY_LEVEL = 4;
  // The firmware automatically creates tunnels for the USB controller and
  // Display Port in a dock. All PCIe links downstream of the dock are removed.
  THUNDERBOLT_SECURITY_USB_ONLY_LEVEL = 5;
  // PCIE tunneling is disabled.
  THUNDERBOLT_SECURITY_NO_PCIE_LEVEL = 6;
}

// Collected once per boot.
// Policy: ReportDeviceSecurityStatus
// Policy default: false
message ThunderboltInfo {
  optional ThunderboltSecurityLevel security_level = 1;
}

// Currently we are only reporting bus device info for thunderbolt, though we
// will certainly add more in the future.
// Collected once per boot.
// Policy: ReportDeviceSecurityStatus
// Policy default: false
message BusDeviceInfo {
  repeated ThunderboltInfo thunderbolt_info = 1;
}

enum MemoryEncryptionState {
  UNSPECIFIED_MEMORY_ENCRYPTION_STATE = 0;
  // The memory encryption state is unknown.
  MEMORY_ENCRYPTION_STATE_UNKNOWN = 1;
  // Memory encrpytion on the device is disabled.
  MEMORY_ENCRYPTION_STATE_DISABLED = 2;
  // Memory encryption on the device uses total memory encryption.
  MEMORY_ENCRYPTION_STATE_TME = 3;
  // Memory encryption on the device uses multi-key total memory encryption.
  MEMORY_ENCRYPTION_STATE_MKTME = 4;
}

enum MemoryEncryptionAlgorithm {
  UNSPECIFIED_MEMORY_ENCRYPTION_ALGORITHM = 0;
  // The memory encryption algorithm being used is unknown.
  MEMORY_ENCRYPTION_ALGORITHM_UNKNOWN = 1;
  // The memory encryption algorithm is using the AES_XTS encryption algorithm
  // with a 128 bit block cypher.
  MEMORY_ENCRYPTION_ALGORITHM_AES_XTS_128 = 2;
  // The memory encryption algorithm is using the AES_XTS encryption algorithm
  // with a 256 bit block cypher.
  MEMORY_ENCRYPTION_ALGORITHM_AES_XTS_256 = 3;
}

// Collected once per boot.
// Policy: ReportDeviceMemoryInfo
// Policy default: false
message TotalMemoryEncryptionInfo {
  // The state of memory encryption on the device.
  optional MemoryEncryptionState encryption_state = 1;
  // The maximum number of keys that can be used for encryption.
  optional int64 max_keys = 2;
  // The length of the encryption keys.
  optional int64 key_length = 3;
  // The encryption algorithm being used on the device.
  optional MemoryEncryptionAlgorithm encryption_algorithm = 4;
}

// Collected once per boot.
// Policy: ReportDeviceMemoryInfo
// Policy default: false
message MemoryInfo {
  // TME info for the device.
  optional TotalMemoryEncryptionInfo tme_info = 1;
}

enum NetworkDeviceType {
  NETWORK_DEVICE_TYPE_UNSPECIFIED = 0;
  CELLULAR_DEVICE = 1;
  ETHERNET_DEVICE = 2;
  WIFI_DEVICE = 5;
}

// Info details about network interface.
message NetworkInterface {
  // Network device type.
  optional NetworkDeviceType type = 1;

  // MAC address (if applicable) of the corresponding network device. This is
  // formatted as an ASCII string with 12 hex digits. Example: A0B1C2D3E4F5.
  optional string mac_address = 2;

  // MEID (if applicable) of the corresponding network device. Formatted as
  // ASCII string composed of 14 hex digits. Example: A10000009296F2.
  optional string meid = 3;

  // IMEI (if applicable) of the corresponding network device. 15-16 decimal
  // digits encoded as ASCII string. Example: 355402040158759.
  optional string imei = 4;

  // The device path associated with this network interface.
  optional string device_path = 5;

  // The integrated circuit card ID associated with the device's sim card.
  optional string iccid = 6;

  // The mobile directory number associated with the device's sim card.
  optional string mdn = 7;

  // List of EID (EUICC Identifier) of all cellular EUICCs
  // (Embedded Universal Integrated Circuit Cards) on the device.
  // 32 decimal digits encoded as ASCII string.
  repeated string eids = 8;
}

// Networks info data.
// Collected once per boot.
// Policy: ReportDeviceNetworkStatus
// Policy default: true
message NetworksInfo {
  repeated NetworkInterface network_interfaces = 1;
}

// Touch screens info data.
// Collected once per boot.
// Policy: ReportDeviceGraphicsStatus
// Policy default: false
message TouchScreenInfo {
  // The touchpad library name used by the input stack.
  optional string library_name = 1;
  // List of the touchscreen devices.
  repeated TouchScreenDevice touch_screen_devices = 2;
}

// Information about the internal touch screen of a device.
message TouchScreenDevice {
  // Name of the device (touchscreen).
  optional string display_name = 1;
  // Number of touch points this device supports.
  optional int32 touch_points = 2;
  // True if the specified touchscreen device is stylus capable.
  optional bool has_stylus = 3;
}

// Information about ePrivacy Screens
// Collected once per boot.
// Policy: ReportDeviceGraphicsStatus
// Policy default: false
message PrivacyScreenInfo {
  // If ePrivacy Screen is supported on the device.
  optional bool supported = 1;
}

// Information about the displays.
// Collected once per boot.
// Policy: ReportDeviceGraphicsStatus
// Policy default: false
message DisplayInfo {
  // Info on all the screens the device has.
  repeated DisplayDevice display_device = 1;
}

// Information on one display.
message DisplayDevice {
  // Name of display product.
  optional string display_name = 1;
  // Display width in millimeters.
  optional int32 display_width = 2;
  // Display height in millimeters.
  optional int32 display_height = 3;
  // Internal or external display.
  optional bool is_internal = 4;
  // Three letter manufacturer ID.
  optional string manufacturer = 5;
  // Manufacturer product code.
  optional int32 model_id = 6;
  // Year of manufacture.
  optional int32 manufacture_year = 7;
}

// Information about keylocker. This is supported on Intel CPUs.
message KeylockerInfo {
  // If keylocker is supported on the devices CPUs.
  optional bool supported = 1;
  // If keylocker is configured on the devices CPUs.
  optional bool configured = 2;
}

// Collected once per boot.
// Policy: ReportDeviceCpuInfo
// Policy default: false
message CpuInfo {
  // Information about keylocker for the devices CPUs.
  optional KeylockerInfo keylocker_info = 1;
}

// Data that is considered immutable, should only be reported on startup and
// policy enablment.
message InfoData {
  // CPU info for the device.
  optional CpuInfo cpu_info = 1;
  // Bus Device info for the device.
  optional BusDeviceInfo bus_device_info = 2;
  // Memory info for the device.
  optional MemoryInfo memory_info = 3;
  // Network interfaces info.
  optional NetworksInfo networks_info = 4;
  // Touch screen info.
  optional TouchScreenInfo touch_screen_info = 5;
  // Information about the ePrivacy Screen.
  optional PrivacyScreenInfo privacy_screen_info = 6;
  // Information about the displays.
  optional DisplayInfo display_info = 7;
}

// Audio telemetry data recorded intermittently
// Default checking rate: 15 mins.
// Checking rate policy: ReportDeviceAudioStatusCheckingRateMs
// Policy: ReportDeviceAudioStatus
// Policy default: true
message AudioTelemetry {
  // Is active output device mute or not.
  optional bool output_mute = 1;
  // Is active input device mute or not.
  optional bool input_mute = 2;
  // Active output device's volume in [0, 100].
  optional int32 output_volume = 3;
  // Active output device's name.
  optional string output_device_name = 4;
  // Active input device's gain in [0, 100].
  optional int32 input_gain = 5;
  // Active input device's name.
  optional string input_device_name = 6;
}

// Boot Performance telemetry data
// Collected once per boot
// Policy: ReportDeviceBootMode
// Policy default: true
message BootPerformanceTelemetry {
  // Total time when to boot up.
  optional int64 boot_up_seconds = 1;
  // The Timestamp when power came on.
  optional int64 boot_up_timestamp_seconds = 2;
  // Total time since shutdown start to power off.
  optional int64 shutdown_seconds = 3;
  // Timestamp when shutdown.
  optional int64 shutdown_timestamp_seconds = 4;
  // Shutdown reason.
  optional string shutdown_reason = 5;
}

// Data tracking user status information
// Default checking rate: 15 mins.
// Checking rate policy: DeviceActivityHeartbeatCollectionRateMs
// Policy: DeviceActivityHeartbeatEnabled
// Policy default: false
message UserStatusTelemetry {
  enum DeviceActivityState {
    DEVICE_ACTIVITY_STATE_UNKNOWN = 0;
    ACTIVE = 1;
    IDLE = 2;
    LOCKED = 3;
  }

  // Device state.
  optional DeviceActivityState device_activity_state = 1;
}

// Displays telemetry data
// Default checking rate: 3 hrs.
// Policy: ReportDeviceGraphicsStatus
// Policy default: false
message DisplaysTelemetry {
  // Status of all the displays.
  repeated DisplayStatus display_status = 1;
}

message DisplayStatus {
  // Name of display product.
  optional string display_name = 1;
  // Horizontal resolution.
  optional int32 resolution_horizontal = 2;
  // Vertical resolution.
  optional int32 resolution_vertical = 3;
  // Refresh rate.
  optional int64 refresh_rate = 4;
  // Internal or external display.
  optional bool is_internal = 5;
}

// Deliberately left empty as there is no payload for Heartbeat messages.
// It just implicitly indicates that the sender is still alive.
// Default checking rate: 2 mins.
// Policy: HeartbeatEnabled
// Policy default: false
message KioskHeartbeatTelemetry {
  // No payload
}

// A message describing a single attention span of a person for the Kiosk
// Vision telemetry report.
message KioskVisionView {
  // Start time of this view. In seconds since epoch.
  optional int64 start_time_sec = 1;
  // End time of this view. In seconds.
  optional int64 end_time_sec = 2;
}

// A message describing the attention of one person for the Kiosk Vision
// telemetry report.
message KioskVisionAudience {
  // The start date when this person was first detected.
  // In seconds since epoch.
  optional int64 presence_start_date_sec = 1;
  // The end date when this person was no longer detected.
  // In seconds since epoch.
  optional int64 presence_end_date_sec = 2;
  // The view information of this person.
  // Repeated, as a person can view multiple times.
  repeated KioskVisionView views = 3;
}

// A message to report Kiosk Vision's audience data.
message KioskVisionTelemetry {
  // Start date of this aggregate report. In seconds since epoch.
  optional int64 start_date_sec = 1;
  // End date of this aggregate report. In seconds since epoch.
  optional int64 end_date_sec = 2;
  // Number of persons that left in the time frame of this aggregate
  // report and looked at the sign.
  optional int32 view_count = 3;
  // Number of persons that left in the time frame of this aggregate
  // report and didn't look at the sign.
  optional int32 pass_count = 4;
  // Audience information. Only information from people that are no
  // longer detected is transmitted. This also means that the
  // audience information includes older data.
  repeated KioskVisionAudience audience = 5;
}

// A message to report the current state and potential errors of the
// KioskVision framework to the telemetry api.
message KioskVisionStatusReport {
  enum KioskVisionState {
    // Kiosk vision is functioning normally.
    KIOSK_VISION_STATE_ACTIVE = 0;
    // An unknown error has occurred.
    KIOSK_VISION_STATE_UNKNOWN_ERROR = 1;
    // The KioskVision framework could not detect a camera.
    KIOSK_VISION_STATE_CAMERA_NOT_FOUND = 2;
  }
  optional KioskVisionState state = 1;

  // Time stamp of this status report (seconds since epoch).
  optional int64 time_stamp_sec = 2;

  // Time stamp of the last status change (seconds since epoch).
  optional int64 state_change_time_stamp_sec = 3;
}

// Data that can change over time, collected and reported every specific period
// of time or when an event occur.
// IMPORTANT: Do not add additional non-message fields (bool, int, string,
// etc.) to `TelemetryData` -- they will be ignored by the server and not
// written to the telemetry database.
message TelemetryData {
  // Indicates whether the telemetry data was collected in response to an event.
  optional bool is_event_driven = 8;

  // At least one of the following telemetry should be present.

  // Networks telemetry data.
  optional NetworksTelemetry networks_telemetry = 1;
  // Audio telemetry data.
  optional AudioTelemetry audio_telemetry = 2;
  // Peripherals telemetry data
  optional PeripheralsTelemetry peripherals_telemetry = 3;
  // Boot Performance telemetry data.
  optional BootPerformanceTelemetry boot_performance_telemetry = 4;
  // User status telemetry data.
  optional UserStatusTelemetry user_status_telemetry = 5;
  // Displays telemetry data.
  optional DisplaysTelemetry displays_telemetry = 6;
  // App telemetry data.
  optional AppTelemetry app_telemetry = 7;
  // Fatal crash data.
  optional FatalCrashTelemetry fatal_crash_telemetry = 9;
  // Runtime counter data.
  optional RuntimeCountersTelemetry runtime_counters_telemetry = 10;
  // Website telemetry data.
  optional WebsiteTelemetry website_telemetry = 11;
  // Kiosk Heartbeats as telemetry data.
  optional KioskHeartbeatTelemetry heartbeat_telemetry = 12;
  // Kiosk Vision telemetry data.
  optional KioskVisionTelemetry kiosk_vision_telemetry = 13;
  // Kiosk Vision status data.
  optional KioskVisionStatusReport kiosk_vision_status = 14;
}

// Type of event metric being reported.
// This must be kept in sync with //tools/metrics/histograms/enums.xml's
// EnterpriseCloudReportingMetricEventType in the Chromium repo.
enum MetricEventType {
  EVENT_TYPE_UNSPECIFIED = 0;
  NETWORK_HTTPS_LATENCY_CHANGE = 1;
  AUDIO_SEVERE_UNDERRUN = 4;
  USB_ADDED = 5;
  USB_REMOVED = 6;
  APP_INSTALLED = 7;
  APP_UNINSTALLED = 8;
  APP_LAUNCHED = 9;
  WIFI_SIGNAL_STRENGTH_LOW = 13;
  WIFI_SIGNAL_STRENGTH_RECOVERED = 14;
  NETWORK_STATE_CHANGE = 15;
  VPN_CONNECTION_STATE_CHANGE = 16;
  FATAL_CRASH = 17;
  URL_OPENED = 18;
  URL_CLOSED = 19;
  KIOSK_HEARTBEAT = 20;

  reserved 2, 3, 10, 11, 12;
}

// App telemetry data.
// Policy: ReportAppInventory
// Policy default: false
message AppTelemetry {
  oneof app_metric_data {
    // App installation data.
    AppInstallData app_install_data = 3;
    // App uninstall data.
    AppUninstallData app_uninstall_data = 4;
    // App launch data.
    AppLaunchData app_launch_data = 5;
    // App usage data.
    AppUsageData app_usage_data = 6;
  }

  reserved 1, 2;
}

// App installation data.
// Policy: ReportAppInventory
// Policy default: false
// Triggered by an event, not collected periodically or once per boot.
// Triggered when an Chrome app, extension or progressive web app is launched.
// Depends on the policy.
message AppInstallData {
  // App installation source.
  optional apps.ApplicationInstallSource app_install_source = 1;
  // App installation reason.
  optional apps.ApplicationInstallReason app_install_reason = 2;
  // App installation time depending on the app lifecycle.
  optional apps.ApplicationInstallTime app_install_time = 3;
  // App id.
  optional string app_id = 4;
  // Type of app.
  optional apps.ApplicationType app_type = 5;
}

// App launch data.
// Policy: ReportAppInventory
// Policy default: false
// Triggered by an event, not collected periodically or once per boot.
// Triggered when an Chrome app, extension or progressive web app is launched.
// Depends on the policy.
message AppLaunchData {
  // App launch source.
  optional apps.ApplicationLaunchSource app_launch_source = 1;
  // App id.
  optional string app_id = 2;
  // Type of app.
  optional apps.ApplicationType app_type = 3;
}

// App usage data.
// Default checking rate: 15 mins.
// Policy: ReportAppInventory
// Policy default: false
// Minimum usage time threshold for app usage reporting: 1 millisecond.
message AppUsageData {
  message AppUsage {
    // App foreground running time (in milliseconds).
    optional int64 running_time_ms = 1;
    // App id.
    optional string app_id = 2;
    // Type of app.
    optional apps.ApplicationType app_type = 3;
    // Application instance id. This will be unique per window/instance.
    optional string app_instance_id = 4;
  }

  // Usage data that also includes other app metadata.
  repeated AppUsage app_usage = 2;

  reserved 1;
}

// App uninstall data.
// Policy: ReportAppInventory
// Policy default: false
// Triggered by an event, not collected periodically or once per boot.
// Triggered when an Chrome app, extension or progressive web app is
// uninstalled. Depends on the policy.
message AppUninstallData {
  // App uninstall source.
  optional apps.ApplicationUninstallSource app_uninstall_source = 1;
  // App id.
  optional string app_id = 2;
  // Type of app.
  optional apps.ApplicationType app_type = 3;
}

// Website telemetry data.
// Policy: ReportWebsiteActivityAllowlist
// Policy default: false
message WebsiteTelemetry {
  oneof website_metric_data {
    // Website opened data.
    WebsiteOpenedData website_opened_data = 1;
    // Website closed data.
    WebsiteClosedData website_closed_data = 2;
    // Website usage data.
    WebsiteUsageData website_usage_data = 3;
  }
}

// Website opened data.
// Policy: ReportWebsiteActivityAllowlist
// Policy default: false
// Triggered by an event, not collected periodically or once per boot.
// Triggered if the website is in the allowlist of the policy and when
// that website is opened.
message WebsiteOpenedData {
  // Website URL.
  optional string url = 1;
  // Render process host id.
  optional int32 render_process_host_id = 2;
  // Render frame routing id.
  optional int32 render_frame_routing_id = 3;
}

// Website closed data.
// Policy: ReportWebsiteActivityAllowlist
// Policy default: false
// Triggered by an event, not collected periodically or once per boot.
// Triggered if the website is in the allowlist of the policy and when
// that website is closed.
message WebsiteClosedData {
  // Website URL.
  optional string url = 1;
  // Render process host id.
  optional int32 render_process_host_id = 2;
  // Render frame routing id.
  optional int32 render_frame_routing_id = 3;
}

// Website usage data.
// Default checking rate: 15 mins.
// Policy: ReportWebsiteActivityAllowlist
// Policy default: false
// Minimum usage time threshold for app usage reporting: 1 millisecond.
message WebsiteUsageData {
  message WebsiteUsage {
    // Website URL.
    optional string url = 1;
    // Website foreground running time (in milliseconds).
    optional int64 running_time_ms = 2;
  }

  // Usage data that includes other website metadata.
  repeated WebsiteUsage website_usage = 3;
}

// Peripherals data.
// Triggered by an event, not collected periodically or once per boot.
// Policy: ReportDevicePeripherals
// Policy default: false
// Triggering mechanisms:
// 1. A USB device is added or removed from the device during an affiliated user
// session. We send the added/removed event, and then send a separate event
// containing a list of USBs currently connected to the device.
// 2. An affiliated user logs in. We send a list of USBs connected to the
// device.
message PeripheralsTelemetry {
  repeated UsbTelemetry usb_telemetry = 1;
}

// Usb data.
message UsbTelemetry {
  // Vendor name
  optional string vendor = 1;
  // Device name, model name, or product name
  optional string name = 2;
  // Vendor ID
  optional int32 vid = 3;
  // Product ID
  optional int32 pid = 4;
  // Categories the device belongs to
  // https://www.usb.org/defined-class-codes
  repeated string categories = 5;
  // Class ID
  // https://www.usb.org/defined-class-codes
  optional int32 class_id = 6;
  // Subclass ID
  // https://www.usb.org/defined-class-codes
  optional int32 subclass_id = 7;
  // Firmware version
  optional string firmware_version = 8;
}

// Fatal crash data.
// Policy: ReportDeviceCrashReportInfo
// Policy default: false
// Triggered by an event, not collected periodically or once per boot.
// Triggered by fatal crashes in the embedded controller, kernel, or Chrome.
// Crash severity is generally assigned in the associated crash collector in
// src/platform2/crash-reporter, however for Chrome crashes, our definition of a
// fatal crash is a crash that is "user disruptive". The following types of
// Chrome crashes are user disruptive:
// 1. Crashes or hangs in the browser process (except if they occur during
// shutdown)
// 2. Crashes in the renderer, utility, or extension process that are
// assigned a severity of ERROR.
//
// The code for determining if a Chrome crash is user
// disruptive is in crash-reporter/crash_sender_util.cc
message FatalCrashTelemetry {
  enum CrashType {
    // Unknown crashes.
    CRASH_TYPE_UNSPECIFIED = 0;
    // Kernel crashes.
    CRASH_TYPE_KERNEL = 1;
    // EC crashes.
    CRASH_TYPE_EMBEDDED_CONTROLLER = 2;
    // Chrome crashes.
    CRASH_TYPE_CHROME = 3;
  }
  // The session types follow user_manager::UserType. The server side will
  // translate to the types described below.
  enum SessionType {
    // Including when a crash occurs on the login screen.
    SESSION_TYPE_UNSPECIFIED = 0;
    // When presenting to the admin, the following will be SIGNED_IN_USER
    SESSION_TYPE_REGULAR = 1;
    SESSION_TYPE_CHILD = 2;

    // When presenting to the admin, the following will be KIOSK
    SESSION_TYPE_KIOSK_APP = 3;
    SESSION_TYPE_ARC_KIOSK_APP = 4;
    SESSION_TYPE_WEB_KIOSK_APP = 5;

    // When presenting to the admin, the following will be MANAGED_GUEST
    SESSION_TYPE_GUEST = 6;
    SESSION_TYPE_PUBLIC_ACCOUNT = 7;

    // When presenting to the admin, the following will be ACTIVE_DIRECTORY
    SESSION_TYPE_ACTIVE_DIRECTORY = 8;
  }
  // required
  optional CrashType type = 1;
  // required
  optional SessionType session_type = 2;
  // required
  optional int64 timestamp_us = 3;
  // Absent if not signed in or the user is not affiliated. Currently only
  // contains user email.
  optional SessionAffiliatedUser affiliated_user = 4;
  // Absent if the crash has not been uploaded by crash_sender yet.
  optional string crash_report_id = 5;
  // required
  optional string local_id = 6;
  // If crash report ID is available, has this event been reported without ID
  // once before?
  // The optionality of crash_report_id is not sufficient because we need to
  // distinguish the two cases: (a) A crash is reported for the first time with
  // a crash report ID and (b) a crash is reported for the first time without a
  // crash report ID and only has a crash report ID when it is reported for the
  // second time.
  optional bool been_reported_without_crash_report_id = 7;
  // Event based log upload ID that contains the logs related to the crash
  // event. This Id will be used in the server to connect the uploaded log file
  // to the specific crash event.
  optional string event_based_log_id = 8;
}

// Runtime counters retrieved from CPU. Currently the runtime counters telemetry
// is only supported by Intel vPro PSR on Gen 14+.
// Default checking rate: 1 day.
// Checking rate policy: DeviceReportRuntimeCountersCheckingRateMs
// Policy: DeviceReportRuntimeCounters
// Policy default: false
message RuntimeCountersTelemetry {
  // All fields below are currently required since Intel vPro is the only
  // supported source, but we reserve the possibility that absence of a field
  // implies that it is unavailable on the device in the future.

  // Hardly any of the following fields can be beyond the size of int32.
  // However, we use int64 because: (a) healthD retrieves uint32 integers from
  // the hardware, and therefore using int32 here risks overflow. (b) Server
  // side requires signed integers and therefore uint32 is not an option.

  // Total lifetime runtime. Currently always S0 runtime from Intel vPro PSR.
  optional int64 uptime_runtime_seconds = 1;
  // Number of times that the device has entered into the sleep state. Currently
  // obtained via the PSR, count from S0->S3. As of Oct 2023, this number is
  // expected to be always zero as ChromeOS devices do not use this state.
  optional int64 counter_enter_sleep = 2;
  // Number of times that the device has entered into the hibernation state.
  // Currently obtained via the PSR, count from S0->S4. As of Oct 2023, this
  // number is expected to be always zero, unless the ChromeOS device is
  // equipped with Intel KeyLocker.
  optional int64 counter_enter_hibernation = 3;
  // Number of times that the device has entered into the power-off state.
  // Currently obtained via the PSR, count from S0->S5.
  optional int64 counter_enter_poweroff = 4;
}

// Indicates one of the following conditions occurred on the device, data
// associated with the event will be reported as `TelemetryData`.
// IMPORTANT: DO NOT add any additional fields to `EventData`.
message EventData {
  optional MetricEventType type = 1;
}

// Main message to be reported, can contain `InfoData`, `TelemetryData`, or
// `EventData`. Data, associated with an event or collected in response to an
// event, is added as `TelemetryData` along with EventData.
message MetricData {
  // The time from epoch when the data was collected.
  optional int64 timestamp_ms = 1;

  oneof metric_type {
    // Info data collected.
    // All of this is collected once per boot unless specified otherwise.
    InfoData info_data = 2;
    // Telemetry data collected.
    // The collection of this data varies, check each message, some of the
    // messages are collected when an event is detected, if that is the case you
    // should also expect the `EventData` to be populated with the appropriate
    // enum.
    TelemetryData telemetry_data = 3;
  }

  // Event data collected. This is just an enum, if there is data related to
  // this event is should be present in `TelemetryData`.
  optional EventData event_data = 4;
}