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

Commit 0c1ed1a7 authored by Rishab Ghanti's avatar Rishab Ghanti Committed by Gerrit Code Review
Browse files

Merge "Add device_type_metadata to atom BluetoothRemoteDeviceInformation" into main

parents 88da0446 ec8f6220
Loading
Loading
Loading
Loading
+45 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ import static com.android.bluetooth.BtRestrictedStatsLog.RESTRICTED_BLUETOOTH_DE


import android.app.AlarmManager;
import android.app.AlarmManager;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProtoEnums;
import android.content.Context;
import android.content.Context;
import android.os.Build;
import android.os.Build;
import android.os.SystemClock;
import android.os.SystemClock;
@@ -334,9 +335,53 @@ public class MetricsLogger {
                BluetoothRemoteDeviceInformation.OUI_FIELD_NUMBER,
                BluetoothRemoteDeviceInformation.OUI_FIELD_NUMBER,
                getOui(device));
                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();
        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) {
    private int getOui(BluetoothDevice device) {
        return Integer.parseInt(device.getAddress().replace(":", "").substring(0, 6), 16);
        return Integer.parseInt(device.getAddress().replace(":", "").substring(0, 6), 16);
    }
    }
+13 −0
Original line number Original line Diff line number Diff line
@@ -312,4 +312,17 @@ message BluetoothRemoteDeviceInformation {


  // The first three bytes of MAC address
  // The first three bytes of MAC address
  optional int32 oui = 3;
  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;
}
}