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

Commit ec8f6220 authored by Rishab's avatar Rishab Committed by Rishab Ghanti
Browse files

Add device_type_metadata to atom BluetoothRemoteDeviceInformation

Test: m com.android.btservices and ran statsd_testdrive to verify atom
was logged
Bug: 351950036
Flag: EXEMPT, Metrics Logging

Change-Id: If3ac3d1853505b03bdca690a4ade9707727456c3
parent 9524d040
Loading
Loading
Loading
Loading
+45 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import static com.android.bluetooth.BtRestrictedStatsLog.RESTRICTED_BLUETOOTH_DE

import android.app.AlarmManager;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProtoEnums;
import android.content.Context;
import android.os.Build;
import android.os.SystemClock;
@@ -334,9 +335,53 @@ public class MetricsLogger {
                BluetoothRemoteDeviceInformation.OUI_FIELD_NUMBER,
                getOui(device));

        // write deviceTypeMetaData
        writeFieldIfNotNull(
                proto,
                ProtoOutputStream.FIELD_TYPE_INT32,
                ProtoOutputStream.FIELD_COUNT_SINGLE,
                BluetoothRemoteDeviceInformation.DEVICE_TYPE_METADATA_FIELD_NUMBER,
                getDeviceTypeMetaData(device));

        return proto.getBytes();
    }

    private int getDeviceTypeMetaData(BluetoothDevice device) {
        byte[] deviceTypeMetaDataBytes =
                mAdapterService.getMetadata(device, BluetoothDevice.METADATA_DEVICE_TYPE);

        if (deviceTypeMetaDataBytes == null) {
            return BluetoothProtoEnums.NOT_AVAILABLE;
        }
        String deviceTypeMetaData = new String(deviceTypeMetaDataBytes, StandardCharsets.UTF_8);

        switch (deviceTypeMetaData) {
            case "Watch":
                return BluetoothProtoEnums.WATCH;

            case "Untethered Headset":
                return BluetoothProtoEnums.UNTETHERED_HEADSET;

            case "Stylus":
                return BluetoothProtoEnums.STYLUS;

            case "Speaker":
                return BluetoothProtoEnums.SPEAKER;

            case "Headset":
                return BluetoothProtoEnums.HEADSET;

            case "Carkit":
                return BluetoothProtoEnums.CARKIT;

            case "Default":
                return BluetoothProtoEnums.DEFAULT;

            default:
                return BluetoothProtoEnums.NOT_AVAILABLE;
        }
    }

    private int getOui(BluetoothDevice device) {
        return Integer.parseInt(device.getAddress().replace(":", "").substring(0, 6), 16);
    }
+13 −0
Original line number Diff line number Diff line
@@ -312,4 +312,17 @@ message BluetoothRemoteDeviceInformation {

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

  enum RemoteDeviceTypeMetadata {
    WATCH = 0;
    UNTETHERED_HEADSET = 1;
    STYLUS = 2;
    SPEAKER = 3;
    HEADSET = 4;
    CARKIT = 5;
    DEFAULT = 6;
    NOT_AVAILABLE = 7;
  }
  // Device type metadata
  optional RemoteDeviceTypeMetadata device_type_metadata = 4;
}