/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

syntax = "proto2";

package android.os.statsd.bluetooth;

import "frameworks/proto_logging/stats/atom_field_options.proto";
import "frameworks/proto_logging/stats/atoms.proto";
import "frameworks/proto_logging/stats/attribution_node.proto";
import "frameworks/proto_logging/stats/enums/bluetooth/enums.proto";
import "frameworks/proto_logging/stats/enums/bluetooth/hci/enums.proto";
import "frameworks/proto_logging/stats/enums/bluetooth/le/enums.proto";
import "frameworks/proto_logging/stats/enums/bluetooth/rfcomm/enums.proto";

option java_package = "com.android.os.bluetooth";
option java_multiple_files = true;

extend Atom {
  optional BluetoothHashedDeviceNameReported
      bluetooth_hashed_device_name_reported = 613 [(module) = "bluetooth"];
  optional BluetoothL2capCocClientConnection
      bluetooth_l2cap_coc_client_connection = 614 [(module) = "bluetooth"];
  optional BluetoothL2capCocServerConnection
      bluetooth_l2cap_coc_server_connection = 615 [(module) = "bluetooth"];
  optional BluetoothLeSessionConnected bluetooth_le_session_connected = 656
      [(module) = "bluetooth"];
  optional RestrictedBluetoothDeviceNameReported
      restricted_bluetooth_device_name_reported = 666 [
        (module) = "bt_restricted",
        (restriction_category) = RESTRICTION_DIAGNOSTIC
      ];
  optional BluetoothProfileConnectionAttempted
      bluetooth_profile_connection_attempted = 696 [(module) = "bluetooth"];
  optional BluetoothContentProfileErrorReported
      bluetooth_content_profile_error_reported = 781 [(module) = "bluetooth"];
  optional BluetoothRfcommConnectionAttempted
      bluetooth_rfcomm_connection_attempted = 782 [(module) = "bluetooth"];
  optional RemoteDeviceInformationWithMetricId
      remote_device_information_with_metric_id = 862 [(module) = "bluetooth"];
  optional LeAppScanStateChanged le_app_scan_state_changed = 870
      [(module) = "bluetooth"];
  optional LeRadioScanStopped le_radio_scan_stopped = 871
      [(module) = "bluetooth"];
  optional LeScanResultReceived le_scan_result_received = 872
      [(module) = "bluetooth"];
  optional LeScanAbused le_scan_abused = 873 [(module) = "bluetooth"];
  optional LeAdvStateChanged le_adv_state_changed = 874
      [(module) = "bluetooth"];
  optional LeAdvErrorReported le_adv_error_reported = 875
      [(module) = "bluetooth"];
  optional A2dpSessionReported a2dp_session_reported = 904
      [(module) = "bluetooth"];
  optional BluetoothCrossLayerEventReported
      bluetooth_cross_layer_event_reported = 916 [(module) = "bluetooth"];
  optional BroadcastAudioSessionReported broadcast_audio_session_reported = 927
      [(module) = "bluetooth"];
  optional BroadcastAudioSyncReported broadcast_audio_sync_reported = 928
      [(module) = "bluetooth"];
  optional BluetoothRfcommConnectionReportedAtClose
      bluetooth_rfcomm_connection_reported_at_close = 982
      [(module) = "bluetooth"];
  optional BluetoothLeConnection bluetooth_le_connection = 988
      [(module) = "bluetooth"];
  optional HearingDeviceActiveEventReported
      hearing_device_active_event_reported = 1021 [(module) = "bluetooth"];
  optional ChannelSoundingTypesSupported channel_sounding_types_supported = 1070
      [(module) = "bluetooth"];
  optional ChannelSoundingRequesterSessionReported
      channel_sounding_requester_session_reported = 1084
      [(module) = "bluetooth"];
  optional BluetoothPbapClientContactDownloadReported
      bluetooth_pbap_client_contact_download_reported = 1104
      [(module) = "bluetooth"];
  optional BluetoothOppLauncherCreated bluetooth_opp_launcher_created = 1146
      [(module) = "bluetooth"];
  optional BluetoothOppShareStatusCompleteReported
      bluetooth_opp_share_status_complete_reported = 1147
      [(module) = "bluetooth"];
  optional BluetoothEnergyMonitorReported bluetooth_energy_monitor_reported =
      1169 [(module) = "bluetooth"];
  optional BluetoothRfStatsReported bluetooth_rf_stats_reported = 1170
      [(module) = "bluetooth"];
}

/**
 * Logs hashed Bluetooth device names
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message BluetoothHashedDeviceNameReported {
  // An identifier that can be used to match events for this device.
  // The incremental identifier is locally generated and guaranteed not derived
  // from any globally unique hardware id.
  // For paired devices, it stays consistent between Bluetooth toggling for the
  // same remote device.
  // For unpaired devices, it stays consistent within the same Bluetooth adapter
  // session for the same remote device.
  // Default: 0 if the device's metric id is unknown.
  optional int32 metric_id = 1;

  // SHA256 hashed Bluetooth device name.
  optional string device_name_hash = 2;
}

/**
 * Logs when L2CAP CoC on a Bluetooth device connects and disconnects.
 */
message BluetoothL2capCocClientConnection {
  // An identifier that can be used to match events for this device.
  // The incremental identifier is locally generated and guaranteed not derived
  // from any globally unique hardware id.
  // For paired devices, it stays consistent between Bluetooth toggling for the
  // same remote device.
  // For unpaired devices, it stays consistent within the same Bluetooth adapter
  // session for the same remote device.
  // Default: 0 if the device's metric id is unknown.
  optional int32 metric_id = 1;

  // Port used for the connection session
  optional int32 port = 2;

  // Flag to show if the connection is secured or not
  optional bool is_secured = 3;

  // Result of L2CAP CoC connection
  optional android.bluetooth.L2capCocConnectionResult result = 4;

  // Latency between connection start and end
  optional int64 connection_latency_millis = 5;

  // Uid of the app who calls l2cap coc connection API
  optional int32 uid = 6 [(is_uid) = true];

  // Latency of BluetoothSocket constructor
  optional int64 socket_creation_latency_millis = 7;

  // Latency of BluetoothSocket.connect
  optional int64 socket_connection_latency_millis = 8;
}

/**
 * Logs when L2CAP CoC on a Bluetooth device connects and disconnects.
 */
message BluetoothL2capCocServerConnection {
  // An identifier that can be used to match events for this device.
  // The incremental identifier is locally generated and guaranteed not derived
  // from any globally unique hardware id.
  // For paired devices, it stays consistent between Bluetooth toggling for the
  // same remote device.
  // For unpaired devices, it stays consistent within the same Bluetooth adapter
  // session for the same remote device.
  // Default: 0 if the device's metric id is unknown.
  optional int32 metric_id = 1;

  // Port used for the connection session
  optional int32 port = 2;

  // Flag to show if the connection is secured or not
  optional bool is_secured = 3;

  // Result of L2CAP CoC connection
  optional android.bluetooth.L2capCocConnectionResult result = 4;

  // Latency between connection start and end
  optional int64 latency_since_listening_millis = 5;

  // Timeout for connection acceptance. -1 if not timeout.
  optional int64 timeout_millis = 6;

  // Uid of the app who calls l2cap coc connection API
  optional int32 uid = 7 [(is_uid) = true];

  // Latency of BluetoothServerSocket constructor
  optional int64 socket_creation_latency_millis = 8;

  // Latency of BluetoothServerSocket.accept
  optional int64 socket_acceptance_latency_millis = 9;
}

/**
 * Logs when Bluetooth LE Connection Session is made
 *
 * Logged from: system/bt
 */
message BluetoothLeSessionConnected {
  // Contains the state of the LE Connection Session
  // Default: LE_ACL_ABSENT
  optional android.bluetooth.le.LeAclConnectionState acl_state = 1;
  // Origin type of the connection whether it was from the ORIGIN_JAVA
  // or the ORIGIN_NATIVE layer
  // Default: ORIGIN_NATIVE
  optional android.bluetooth.le.LeConnectionOriginType connection_origin = 2;
  // Contains the connection type whether it was CONNECTION_TYPE_GATT
  // ,CONNECTION_TYPE_LE_ACL
  // Default: CONNECTION_TYPE_LE_ACL
  optional android.bluetooth.le.LeConnectionType connection_type = 3;
  // Connection State which contain the last state associated with the
  // event
  // Default: STATE_UNSPECIFIED
  optional android.bluetooth.le.LeConnectionState state = 4;
  // Contains the latency of the transaction from the beginning till
  // the end:
  // Default: 0
  optional int64 latency_nanos = 5;
  // Contains the metric id associated with the remote device
  // Default: 0
  optional int32 metric_id = 6;
  // Contains the UID which is associated with the app
  // Default: 0
  optional int32 app_uid = 7 [(is_uid) = true];
  // Contains the latency of the ACL Connection, which if made will be
  // greater than 0
  // Default: 0
  optional int64 acl_latency_nanos = 8;
  // Contains the status of the ACL Transactions, which if made will be
  // something other than STATUS_UNKNOWN Default: STATUS_UNKNOWN
  optional android.bluetooth.hci.StatusEnum acl_connection_state = 9;
  // Identifies whether the LE-ACL Connection failed due to cancellation
  // Default: false
  optional bool is_cancelled = 10;
}

/**
 * Logs the user created Bluetooth device's name.
 * It is pushed at Bluetooth pairing and connection.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message RestrictedBluetoothDeviceNameReported {
  // Name of the Bluetooth device. It is created by the user.
  optional string device_name = 1
      [(field_restriction_option).peripheral_device_info = true];
}

/**
 * Logs profile connection known completions.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message BluetoothProfileConnectionAttempted {
  // The profile that is connected. Eg. GATT, A2DP, HEADSET.
  // From android.bluetooth.BluetoothAdapter.java
  // Default: 0 when not used
  optional int32 bt_profile = 1;

  // Result of Profile connection
  optional android.bluetooth.ProfileConnectionResult result = 2;

  // Previous connection state
  optional android.bluetooth.ConnectionStateEnum previous_state = 3;

  // Terminating connection state
  optional android.bluetooth.ConnectionStateEnum current_state = 4;

  // Reason for the connection result
  optional android.bluetooth.ProfileConnectionReason reason = 5;

  // Remote Device Information
  optional BluetoothRemoteDeviceInformation remote_device_information = 6
      [(log_mode) = MODE_BYTES];
}

/**
 * Logs LE connection success or failure.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message BluetoothLeConnection {
  // Result of LE connection
  optional android.bluetooth.LeConnectionResult result = 1;

  // Remote Device Information
  optional BluetoothRemoteDeviceInformation remote_device_information = 2
      [(log_mode) = MODE_BYTES];
}

/**
 * Logs content profiles' caught exceptions or logs (ERROR, WARN)
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message BluetoothContentProfileErrorReported {
  enum ErrorType {
    UNKNOWN = 0;
    EXCEPTION = 1;
    LOG_ERROR = 2;
    LOG_WARN = 3;
  }

  // The content profile where the error happened. (E.g. PBAP, MAP, OPP)
  // From android.bluetooth.BluetoothProfile.java
  // Default: 0 when not used
  optional int32 bt_profile = 1;

  // The file name where the error is reported from
  optional android.bluetooth.ContentProfileFileName file_name = 2;

  // The type of error (exception, Log.e, Log.w)
  optional ErrorType type = 3;

  // Integer tag associated with the error
  optional int32 tag = 4;
}

message BluetoothRemoteDeviceInformation {
  // SHA256 hashed Bluetooth device name.
  optional string allowlisted_device_name_hash = 1;

  // Class of Device
  optional int32 class_of_device = 2;

  // The first three bytes of MAC address
  optional int32 oui = 3;

  // Device type metadata
  optional android.bluetooth.RemoteDeviceTypeMetadata device_type_metadata = 4;
}

/**
 * Logs RFCOMM connection attempts
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message BluetoothRfcommConnectionAttempted {
  // Locally generated id for event matching
  optional int32 metric_id = 1;

  // Latency of the connection
  optional int64 latency_nanos = 2;

  // Whether or not the connection is secured
  optional android.bluetooth.rfcomm.SocketConnectionSecurity security = 3;

  // Result of Rfcomm connection
  optional android.bluetooth.rfcomm.RfcommConnectionResult status = 4;

  // is_serial_port is true if the service class UUID is 0x1101
  optional bool is_serial_port = 5;

  // Uid of the app that calls RFCOMM connection API
  optional int32 uid = 6
      [(is_uid) = true];  // [(datapol.semantic_type) = ST_SOFTWARE_ID]

  // Remote Device Information
  optional BluetoothRemoteDeviceInformation remote_device_information = 7
      [(log_mode) = MODE_BYTES];
}

/**
 * Logs remote device information with metric ID
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message RemoteDeviceInformationWithMetricId {
  // Locally generated id for event matching
  optional int32 metric_id = 1;

  // Remote Device Information
  optional BluetoothRemoteDeviceInformation remote_device_information = 2
      [(log_mode) = MODE_BYTES];
}

/**
 * Logs LE app scan information when the scan starts and stops.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message LeAppScanStateChanged {
  repeated AttributionNode attribution_node = 1;
  // True for scan start, false for scan stop.
  optional bool enabled = 2;
  // Does the scan have a filter.
  optional bool is_filtered = 3;
  // Whether the scan has callback function or pending intent.
  optional bool is_callback_scan = 4;
  optional android.bluetooth.le.LeScanCallbackType scan_callback_type = 5;
  optional android.bluetooth.le.LeScanType le_scan_type = 6;
  // For app scan modes, it is logged before being modified based on screen
  // state.
  optional android.bluetooth.le.LeScanMode le_scan_mode = 7;
  // Time of delay for reporting the scan result in milliseconds.
  optional int64 report_delay_ms = 8;
  // Duration from scan start to stop in milliseconds. Use 0 for scan start.
  optional int64 app_scan_duration_ms = 9;
  // Number of scans on going when the scan started or stopped.
  optional int32 num_ongoing_scan = 10;
  // Screen state when the scan started or stopped. True for STATE_ON, false
  // for any other state as defined in android.view.Display.
  optional bool is_screen_on = 11;
  // Whether the app is dead when the scan started or stopped.
  optional bool is_app_dead = 12;
  // App importance compared to foreground service when the scan started or
  // stopped.
  optional android.bluetooth.le.AppImportance app_importance = 13;
  // The Attribution tag to identify the last caller in the attribution chain,
  // which could be missing in attribution_node due to incomplete attribution in
  // the Worksource. Missing tag leads to incomplete attribution data.
  optional string attribution_tag = 14;
}

/**
 * Logs the LE scan information when the radio scan is stopped or screen state
 * changes which reconfigures the scan parameters.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message LeRadioScanStopped {
  // Attribution of the app with most aggressive scanning parameters, which
  // will be used by the LE radio for the scanning.
  repeated AttributionNode attribution_node = 1;
  optional android.bluetooth.le.LeScanType le_scan_type_most_aggressive_app = 2;
  optional android.bluetooth.le.LeScanMode le_scan_mode_most_aggressive_app = 3;
  // Radio scan interval in milliseconds.
  optional int64 le_scan_radio_settings_interval_ms = 4;
  // Radio Scan window in milliseconds.
  optional int64 le_scan_radio_settings_window_ms = 5;
  // True for STATE_ON, false for any other state as defined in
  // android.view.Display.
  optional bool is_screen_on = 6;
  // Delta time of radio scan start and stop in milliseconds.
  optional int64 scan_duration_ms = 7;
  // Importance of app with most aggressive scanning parameters compared to
  // foreground service when the radio scan started.
  optional android.bluetooth.le.AppImportance app_importance = 8;
  // The Attribution tag to identify the last caller in the attribution chain,
  // which could be missing in attribution_node due to incomplete attribution in
  // the Worksource. Missing tag leads to incomplete attribution data.
  optional string attribution_tag = 9;
}

/**
 * Logs the LE scan results information when regular and batched scan results
 * are received.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message LeScanResultReceived {
  repeated AttributionNode attribution_node = 1;
  // Number of ble scan results returned. 1 for regular scan, and use numRecords
  // for batched scan
  optional int32 num_results = 2;
  optional android.bluetooth.le.LeScanType le_scan_type = 3;
  // True for STATE_ON, false for any other state as defined in
  // android.view.Display.
  optional bool is_screen_on = 4;
  // The Attribution tag to identify the last caller in the attribution chain,
  // which could be missing in attribution_node due to incomplete attribution in
  // the Worksource. Missing tag leads to incomplete attribution data.
  optional string attribution_tag = 5;
}

/**
 * Logs LE scan abuse count and details for scan request errors.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message LeScanAbused {
  repeated AttributionNode attribution_node = 1;
  optional android.bluetooth.le.LeScanType le_scan_type = 2;
  // LE scan abuse reason.
  optional android.bluetooth.le.LeScanAbuseReason le_scan_abuse_reason = 3;
  // Logs the system configuration as details of the abuse reason.
  // getScanTimeoutMillis() in AdapterService.java for REASON_SCAN_TIMEOUT.
  // getNumOfOffloadedScanFilterSupported() in in AdapterService.java for
  // REASON_HW_FILTER_NOT_AVAILABLE.
  // getTotalNumOfTrackableAdvertisements() in AdapterService.java for
  // REASON_TRACKING_HW_FILTER_NOT_AVAILABLE.
  optional int64 le_scan_abuse_reason_details = 4;
  // The Attribution tag to identify the last caller in the attribution chain,
  // which could be missing in attribution_node due to incomplete attribution in
  // the Worksource. Missing tag leads to incomplete attribution data.
  optional string attribution_tag = 5;
}

/**
 * Logs LE advertisement information when LE adv starts and stops.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message LeAdvStateChanged {
  repeated AttributionNode attribution_node = 1;
  // LE advertisement state, true for adv start, false for adv stop.
  optional bool enabled = 2;
  // LE adv interval configuration.
  optional android.bluetooth.le.LeAdvInterval adv_interval = 3;
  // LE adv tx power configuration.
  optional android.bluetooth.le.LeAdvTxPower adv_tx_power = 4;
  // Whether the adv is connectable.
  optional bool is_connectable = 5;
  // Whether the adv is periodic.
  optional bool is_periodic = 6;
  // Whether the adv has scan response.
  optional bool has_scan_response = 7;
  // Whether the adv is extended adv.
  optional bool is_extended_adv = 8;
  // Number of total active advertisements when the current advertisement
  // starts or stops.
  optional int32 num_adv_instances_in_use = 9;
  // Adv duration when adv stops (adv stop timestamp - adv start timestamp),
  // in milliseconds. Use 0 for adv start.
  optional int64 adv_duration_ms = 10;
  // App importance compared to foreground service when the advertisement
  // started or stopped.
  optional android.bluetooth.le.AppImportance app_importance = 11;
  // The Attribution tag to identify the last caller in the attribution chain,
  // which could be missing in attribution_node due to incomplete attribution in
  // the Worksource. Missing tag leads to incomplete attribution data.
  optional string attribution_tag = 12;
}

/**
 * Logs errors when LE advertising set starts.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message LeAdvErrorReported {
  repeated AttributionNode attribution_node = 1;
  // Operation code for the adv error.
  optional android.bluetooth.le.LeAdvOpCode le_adv_op_code = 2;
  // The status code of internal state.
  optional android.bluetooth.le.LeAdvStatusCode status_code = 3;
  // The Attribution tag to identify the last caller in the attribution chain,
  // which could be missing in attribution_node due to incomplete attribution in
  // the Worksource. Missing tag leads to incomplete attribution data.
  optional string attribution_tag = 4;
}

/**
 * Logs A2DP session information when the session ends.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message A2dpSessionReported {
  // Full duration of the session in milliseconds.
  optional int64 duration_ms = 1;
  // Minimum duration of the media timer in milliseconds.
  optional int32 min_timer_duration_ms = 2;
  // Maximum duration of the media timer in milliseconds.
  optional int32 max_timer_duration_ms = 3;
  // Average duration of the media timer in milliseconds.
  optional int32 average_timer_duration_ms = 4;
  // Total number of times the media timer was scheduled.
  optional int32 total_scheduling_count = 5;
  // Counts the maximum number of audio frames dropped simultaneously due
  // to TX buffer overruns during the session.
  optional int32 max_buffer_overrun = 6;
  // Counts the total number of audio frames that were dropped due to TX buffer
  // overruns during the session.
  optional int32 total_buffer_overrun = 7;
  // Counts the average number of bytes of underflow when reading fromt the
  // PCM audio stream.
  optional float average_buffer_underrun = 8;
  // Total number of bytes of underflow when reading from the PCM audio stream.
  optional int32 total_buffer_underrun = 9;
  // Unique identifier of the codec used for the session. The codec identifier
  // is 40 bits,
  // - Bits 0-7: Audio Codec ID, as defined by [ID 6.5.1]
  //    0x00: SBC
  //    0x02: AAC
  //    0xFF: Vendor
  // - Bits 8-23: Company ID, set to 0, if octet 0 is not 0xFF.
  // - Bits 24-39: Vendor-defined codec ID, set to 0, if octet 0 is not 0xFF.
  optional int64 codec_id = 10;
  // Indicates whether the session is offloaded or not.
  optional bool offload = 11;
  // Identifier for the remote device.
  optional int32 metric_id = 12;
}

/**
 * Logs a Bluetooth Event
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message BluetoothCrossLayerEventReported {
  // Type of Bluetooth Event
  optional android.bluetooth.EventType event_type = 1;

  // Addition Details about the event, specific to the event type
  optional android.bluetooth.State state = 2;

  // Identifier for the app that initiates the CUJ (if applicable)
  optional int32 uid = 3 [(is_uid) = true];

  // Identifier for the remote device/metric id
  optional int32 metric_id = 4;

  // Remote Device Information
  optional BluetoothRemoteDeviceInformation remote_device_information = 5
      [(log_mode) = MODE_BYTES];
}

/**
 * Logs LE Audio Broadcast Audio Session
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message BroadcastAudioSessionReported {
  // Identifier randomly generated for every broadcast session
  // Default: -1 if the broadcast id is unknown
  optional int32 broadcast_id = 1;

  // Number of audio groups in this broadcast session
  optional int32 audio_group_size = 2;

  // Broadcast audio quality configuration for all subgroups
  repeated android.bluetooth.BroadcastAudioQualityType audio_quality = 3;

  // Number of devices in this broadcast session
  optional int32 group_size = 4;

  // Broadcast session duration
  optional int64 duration_ms = 5;

  // Broadcast session in configured state latency
  optional int64 latency_broadcast_configured_ms = 6;

  // Broadcast session in streaming state latency
  optional int64 latency_broadcast_streaming_ms = 7;

  // Status of broadcast session setup
  optional android.bluetooth.BroadcastSessionSetupStatus session_setup_status =
      8;
}

/**
 * Logs LE Audio Broadcast Audio Sync
 *
 * Logged from:
 *     packages/modules/Bluetooth
 */
message BroadcastAudioSyncReported {
  // Identifier randomly generated for every broadcast session
  // Default: -1 if the broadcast id is unknown
  optional int32 broadcast_id = 1;

  // Local broadcast or external broadcast
  optional bool is_local_broadcast = 2;

  // Broadcast session duration
  optional int64 duration_ms = 3;

  // Latency from adding source to PA synced
  optional int64 latency_pa_sync_ms = 4;

  // Latency from adding source to BIS synced
  optional int64 latency_bis_sync_ms = 5;

  // Status of broadcast sync
  optional android.bluetooth.BroadcastSyncStatus sync_status = 6;

  // Remote Device Information
  optional BluetoothRemoteDeviceInformation remote_device_information = 7
      [(log_mode) = MODE_BYTES];
}

/**
 * Logs RFCOMM connection attempts from the native layer after the connection
 * closes
 *
 * Logged from:
 *     packages/modules/Bluetooth
 *
 * Estimated Logging Rate:
 *     Peak: 5 times in 30 seconds | Avg: 4 per device per day
 *
 */
message BluetoothRfcommConnectionReportedAtClose {
  // Reason for error or closure
  optional android.bluetooth.rfcomm.PortResult close_reason = 1;
  // security level of the connection
  optional android.bluetooth.rfcomm.SocketConnectionSecurity security = 2;
  // last event processed by port state machine
  optional android.bluetooth.rfcomm.RfcommPortEvent last_event = 3;
  // state prior to "CLOSED"
  optional android.bluetooth.rfcomm.RfcommPortState previous_state = 4;
  // duration that the socket was opened, 0 if connection failed
  optional int32 open_duration_ms = 5;
  // uid of the app that called connect
  optional int32 uid = 6 [(is_uid) = true];
  // locally generated id for event matching
  optional int32 metric_id = 7;
  // sdp status, UNKNOWN if irrelevant
  optional android.bluetooth.BtaStatus sdp_status = 8;
  // true if device initiated connection as server, false otherwise
  optional bool is_server = 9;
  // true if device initiated SDP service discovery
  optional bool sdp_initiated = 10;
  // time in milliseconds between start and end of SDP, 0 if no SDP
  optional int32 sdp_duration_ms = 11;
}

/**
 * Logs hearing devices active event when profiles connected.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 *
 * Estimated Logging Rate:
 *     Peak: 3 times in 1 day | Avg: 1 per device per day
 */
message HearingDeviceActiveEventReported {
  enum DeviceType {
    UNKNOWN_TYPE = 0;
    CLASSIC = 1;
    // Deprecated, use ASHA_ONLY or ASHA_DUAL instead.
    ASHA = 2 [deprecated = true];
    // Deprecated, use LE_AUDIO_ONLY or LE_AUDIO_DUAL instead.
    LE_AUDIO = 3 [deprecated = true];
    ASHA_ONLY = 4;
    LE_AUDIO_ONLY = 5;
    ASHA_DUAL = 6;
    LE_AUDIO_DUAL = 7;
  }
  enum TimePeriod {
    UNKNOWN_TIME_PERIOD = 0;
    DAY = 1;
    WEEK = 2;
    MONTH = 3;
  }
  // The type of the hearing device
  optional DeviceType device_type = 1;
  // The time period of the active event
  optional TimePeriod time_period = 2;
  // Remote Device Information
  optional BluetoothRemoteDeviceInformation remote_device_information = 3
      [(log_mode) = MODE_BYTES];
}

/**
 * Logs the Channel Sounding types Supported by the device.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 *
 * Estimated Logging Rate:
 *     Peak: 1 time in 1 day | Avg: 1 per device per day
 */
message ChannelSoundingTypesSupported {
  // The channel sounding types
  repeated android.bluetooth.ChannelSoundingType cs_types = 1;
}

/**
 * Logs the Channel Sounding measurement session as requester
 *
 * Logged from:
 *     packages/modules/Bluetooth
 *
 * Estimated Logging Rate:
 *     Peak: 100 times in 1 day | Avg: 1 per device per day
 */
message ChannelSoundingRequesterSessionReported {
  // Locally generated id for event matching
  optional int32 metric_id = 1;

  // Uids of the apps which request the measurement
  repeated int32 app_uids = 2 [(is_uid) = true];

  // Channel Sounding security levels requested by different apps
  repeated android.bluetooth.ChannelSoundingSecurityLevel security_levels = 3;

  // Intervals requested by different apps
  repeated int32 measurement_interval_ms = 4;

  // The reason about why the session is stopped
  optional android.bluetooth.ChannelSoundingStopReason stop_reason = 5;

  // The channel sounding setup latency
  optional int32 setup_latency_ms = 6;

  // The duration of measurement session from start to stop
  optional int32 duration_seconds = 7;

  // If the back to back was detected, the device is used as both requester and
  // responder
  optional bool back_to_back = 8;

  // The channel sounding type used for this session
  optional android.bluetooth.ChannelSoundingType cs_type = 9;

  // The minimum number of subevent_len from the procedure_enable_complete
  // command
  optional int32 min_subevent_len = 10;

  // The count of min_subevent_len, use to estimate the duration of
  // min_subevent_len
  optional int32 min_subevent_len_count = 11;
}

/**
 * Logs BluetoothPbapClient contact downloads.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 *
 * Estimated Logging Rate:
 *     Peak: 100 times in 1 day | Avg: 10 per device per day
 *     Once per Bluetooth connection.
 */
message BluetoothPbapClientContactDownloadReported {
  // Connecting device information (phone model)
  optional int32 metrics_id = 1;
  // BluetoothPbapClient download status
  optional android.bluetooth.BluetoothPbapClientContactDownloadStatus
      download_status = 2;
  // Phonebooks downloaded
  optional PhonebookDownloads phonebook_downloads = 3 [(log_mode) = MODE_BYTES];
}

message PhonebookDownloads {
  // Phonebooks downloaded
  repeated PhonebookDownload phonebook_download = 1;
}

/**
 * BluetoothPbapClient Phonebook download information.
 */
message PhonebookDownload {
  // Phonebook type
  optional android.bluetooth.BluetoothPbapClientPhonebookType phonebook_type =
      1;
  // Phonebook download status
  optional android.bluetooth.BluetoothPbapClientPhonebookDownloadStatus status =
      2;
  // Actual number of contacts downloaded
  optional uint64 actual_contacts = 3;
  // Expected number of contacts downloaded
  optional uint64 expected_contacts = 4;
  // Total time spent downloading contacts
  optional uint64 total_duration_millis = 5;
  // Fraction of time spent storing contacts
  optional uint64 storage_duration_millis = 6;
  // Number of contacts images
  optional uint64 contacts_with_images = 7;
}

/**
 * Logs BluetoothOpp LauncherCreated when a OPP share launcher is triggered.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 *
 * Estimated Logging Rate:
 *     Peak: 3 times in 1 day | Avg: 1 per device per day
 *     Once per OPP share. OPP stands for Object Push Profile in Bluetooth.
 *     An OPP share is a file transfer between two devices using Bluetooth.
 */
message BluetoothOppLauncherCreated {
  // The uid of the app initiating the share.
  optional int32 uid = 1 [(is_uid) = true];

  // The number of files included in this share request.
  optional int32 file_count = 2;

  // The summed file size bucket of all files included in this share request.
  optional android.bluetooth.BluetoothOppFileSize file_size = 3;
}

/**
 * Logs BluetoothOpp ShareStatusComplete when a OPP share session is completed.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 *
 * Estimated Logging Rate:
 *     Peak: 3 times in 1 day | Avg: 1 per device per day
 *     Once per OPP file share.
 *     OPP stands for Object Push Profile in Bluetooth.
 *     An OPP share is a file transfer between two devices using Bluetooth.
 */
message BluetoothOppShareStatusCompleteReported {
  // The final result of the transfer.
  optional android.bluetooth.BluetoothOppSessionStatus session_status = 1;

  // The direction of the transfer (Sending/Receiving).
  optional android.bluetooth.BluetoothOppTransferDirection direction = 2;

  // Total duration from the file start to completion.
  optional android.bluetooth.BluetoothOppTransferDuration transfer_duration = 3;

  // The file size classification.
  optional android.bluetooth.BluetoothOppFileSize file_size = 4;

  // The transfer speed classification.
  optional android.bluetooth.BluetoothOppTransferSpeed transfer_speed = 5;

  // The categorized MIME type of the file.
  optional android.bluetooth.BluetoothOppMimeTypeCategory mime_type_category =
      6;

  // Remote Device Information
  optional BluetoothRemoteDeviceInformation remote_device_information = 7
      [(log_mode) = MODE_BYTES];
}

/**
 * Logs BluetoothEnergyMonitorReported when the energy monitor BQR is received.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 *
 * Estimated Logging Rate:
 *     Peak: 100 time in 1 day | Avg: 50 per device per day
 *     Once per energy monitor BQR.
 */
message BluetoothEnergyMonitorReported {
  // BQR version
  // Original type: uint16_t
  // Default: 0x0000
  // BqrVersion5_0: 0x103
  // BqrVersion6_0: 0x104
  // BqrVersion7_0: 0x105
  optional int32 bqr_version = 1;
  // Quality report ID
  // Original type: uint8_t
  // Default: BQR_ID_UNKNOWN
  optional android.bluetooth.hci.BqrIdEnum quality_report_id = 2;
  // Average current consumption of all activities consumed by the controller
  // (mA) Original type: uint16_t
  optional int32 avg_current_consume = 3;
  // Total time in the idle (low power states, sleep) state. (ms)
  // Original type: uint32_t
  optional int64 idle_total_time = 4;
  // Indicates how many times the controller enters the idle state.
  // Original type: uint32_t
  optional int64 idle_state_enter_count = 5;
  // Total time in the active (inquiring, paging, ACL/SCO/eSCO/BIS/CIS traffic,
  // processing any task) state. (ms) Original type: uint32_t
  optional int64 active_total_time = 6;
  // Indicates how many times the controller enters the active states.
  // Original type: uint32_t
  optional int64 active_state_enter_count = 7;
  // Total time in the BR/EDR specific Tx(Transmitting for ACL/SCO/eSCO
  // traffic)state (ms) Original type: uint32_t
  optional int64 bredr_tx_total_time = 8;
  // Indicates how many times the controller enters the BR/EDR specific Tx
  // state. Original type: uint32_t
  optional int64 bredr_tx_state_enter_count = 9;
  // Average Tx power level of all the BR/EDR link(s) (dBm)
  // Original type: uint8_t
  optional int32 bredr_tx_avg_power_lv = 10;
  // Total time in the BR/EDR specific Rx (Receiving from ACL/SCO/eSCO traffic)
  // state. (ms) Original type: uint32_t
  optional int64 bredr_rx_total_time = 11;
  // Indicates how many times the controller enters the BR/EDR specific Rx
  // state. (ms) Original type: uint32_t
  optional int64 bredr_rx_state_enter_count = 12;
  // Total time in the LE specific Tx (Transmitting for either ACL/BIS/CIS or LE
  // advertising traffic) state (ms) Original type: uint32_t
  optional int64 le_tx_total_time = 13;
  // Indicates how many times the controller enters theLE specific Tx state.
  // Original type: uint32_t
  optional int64 le_tx_state_enter_count = 14;
  // Average Tx power level of all the LE link(s) (dBm)
  // Original type: uint8_t
  optional int32 le_tx_avg_power_lv = 15;
  // Total time in the LE specific Rx (Receiving from either ACL/BIS/CIS or LE
  // scanning traffic) state. (ms) Original type: uint32_t
  optional int64 le_rx_total_time = 16;
  // Indicates how many times the controller enters the LE specific Rx state
  // Original type: uint32_t
  optional int64 le_rx_state_enter_count = 17;
  // The total time duration to collect power related information (ms)
  // Original type: uint32_t
  optional int64 tm_period = 18;
  // The time duration of RX active in one chain
  // Original type: uint32_t
  optional int64 rx_active_one_chain_time = 19;
  // The time duration of RX active in two chain
  // Original type: uint32_t
  optional int64 rx_active_two_chain_time = 20;
  // The time duration of internal TX active in one chain
  // Original type: uint32_t
  optional int64 tx_ipa_active_one_chain_time = 21;
  // The time duration of internal TX active in two chain
  // Original type: uint32_t
  optional int64 tx_ipa_active_two_chain_time = 22;
  // The time duration of external TX active in one chain
  // Original type: uint32_t
  optional int64 tx_epa_active_one_chain_time = 23;
  // The time duration of external TX active in two chain
  // Original type: uint32_t
  optional int64 tx_epa_active_two_chain_time = 24;
}

/**
 * Logs BluetoothRfStatsReported when the RF stats BQR is received.
 *
 * Logged from:
 *     packages/modules/Bluetooth
 *
 * Estimated Logging Rate:
 *     Peak: 60 time in 1 day | Avg: 24 per device per day
 *     Once per RF stats BQR.
 */
message BluetoothRfStatsReported {
  // BQR version
  // Original type: uint16_t
  // Default: 0x0000
  // BqrVersion5_0: 0x103
  // BqrVersion6_0: 0x104
  // BqrVersion7_0: 0x105
  optional int32 bqr_version = 1;
  // Quality report ID
  // Original type: uint8_t
  // Default: BQR_ID_UNKNOWN
  optional android.bluetooth.hci.BqrIdEnum quality_report_id = 2;
  // time period (ms)
  // Original type: uint32_t
  optional int64 tm_period = 3;
  // Packet counter of iPA BF
  // Original type: uint32_t
  optional int64 tx_pw_ipa_bf = 4;
  // Packet counter of ePA BF
  // Original type: uint32_t
  optional int64 tx_pw_epa_bf = 5;
  // Packet counter of iPA Div
  // Original type: uint32_t
  optional int64 tx_pw_ipa_div = 6;
  // Packet counter of ePA Div
  // Original type: uint32_t
  optional int64 tx_pw_epa_div = 7;
  // Packet counter of RSSI chain > -50 dBm
  // Original type: uint32_t
  optional int64 rssi_ch_50 = 8;
  // Packet counter of RSSI chain between  -50 dBm ~ >-55 dBm
  // Original type: uint32_t
  optional int64 rssi_ch_50_55 = 9;
  // Packet counter of RSSI chain between  -55 dBm ~ >-60 dBm
  // Original type: uint32_t
  optional int64 rssi_ch_55_60 = 10;
  // Packet counter of RSSI chain between  -60 dBm ~ >-65 dBm
  // Original type: uint32_t
  optional int64 rssi_ch_60_65 = 11;
  // Packet counter of RSSI chain between  -65 dBm ~ >-70 dBm
  // Original type: uint32_t
  optional int64 rssi_ch_65_70 = 12;
  // Packet counter of RSSI chain between  -70 dBm ~ >-75 dBm
  // Original type: uint32_t
  optional int64 rssi_ch_70_75 = 13;
  // Packet counter of RSSI chain between  -75 dBm ~ >-80 dBm
  // Original type: uint32_t
  optional int64 rssi_ch_75_80 = 14;
  // Packet counter of RSSI chain between  -80 dBm ~ >-85 dBm
  // Original type: uint32_t
  optional int64 rssi_ch_80_85 = 15;
  // Packet counter of RSSI chain between  -85 dBm ~ >-90 dBm
  // Original type: uint32_t
  optional int64 rssi_ch_85_90 = 16;
  // Packet counter of RSSI chain  < -90 dBm
  // Original type: uint32_t
  optional int64 rssi_ch_90 = 17;
  // Packet counter of RSSI delta < 2 dBm
  // Original type: uint32_t
  optional int64 rssi_delta_2_down = 18;
  // Packet counter of  RSSI delta between 2 dBm ~ 5 dBm
  // Original type: uint32_t
  optional int64 rssi_delta_2_5 = 19;
  // Packet counter of  RSSI delta between 5 dBm ~ 8 dB
  // Original type: uint32_t
  optional int64 rssi_delta_5_8 = 20;
  // Packet counter of  RSSI delta between 8 dBm ~ 11 dBm
  // Original type: uint32_t
  optional int64 rssi_delta_8_11 = 21;
  // Packet counter of RSSI delta > 11 dBm
  // Original type: uint32_t
  optional int64 rssi_delta_11_up = 22;
}
