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

Commit fb257ff5 authored by Jack He's avatar Jack He
Browse files

Metrics: Log pairing state change to statsd

* Log bond state transition and failure reasons
* Log pin request and replies
* Loig SSP confirmation request and replies

Bug: 112969790
Test: make, test drive with statsd
Change-Id: I2b201645ca071ac368c7914b1e52e6d8e1bc400b
parent fc700cbd
Loading
Loading
Loading
Loading
+16 −0
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProtoEnums;
import android.bluetooth.IBluetooth;
import android.bluetooth.IBluetooth;
import android.bluetooth.IBluetoothCallback;
import android.bluetooth.IBluetoothCallback;
import android.bluetooth.IBluetoothMetadataListener;
import android.bluetooth.IBluetoothMetadataListener;
@@ -2203,6 +2204,11 @@ public class AdapterService extends Service {
            return false;
            return false;
        }
        }


        StatsLog.write(StatsLog.BLUETOOTH_BOND_STATE_CHANGED,
                obfuscateAddress(device), 0, device.getType(),
                BluetoothDevice.BOND_BONDING,
                BluetoothProtoEnums.BOND_SUB_STATE_LOCAL_PIN_REPLIED,
                accept ? 0 : BluetoothDevice.UNBOND_REASON_AUTH_REJECTED);
        byte[] addr = Utils.getBytesFromAddress(device.getAddress());
        byte[] addr = Utils.getBytesFromAddress(device.getAddress());
        return pinReplyNative(addr, accept, len, pinCode);
        return pinReplyNative(addr, accept, len, pinCode);
    }
    }
@@ -2214,6 +2220,11 @@ public class AdapterService extends Service {
            return false;
            return false;
        }
        }


        StatsLog.write(StatsLog.BLUETOOTH_BOND_STATE_CHANGED,
                obfuscateAddress(device), 0, device.getType(),
                BluetoothDevice.BOND_BONDING,
                BluetoothProtoEnums.BOND_SUB_STATE_LOCAL_SSP_REPLIED,
                accept ? 0 : BluetoothDevice.UNBOND_REASON_AUTH_REJECTED);
        byte[] addr = Utils.getBytesFromAddress(device.getAddress());
        byte[] addr = Utils.getBytesFromAddress(device.getAddress());
        return sspReplyNative(addr, AbstractionLayer.BT_SSP_VARIANT_PASSKEY_ENTRY, accept,
        return sspReplyNative(addr, AbstractionLayer.BT_SSP_VARIANT_PASSKEY_ENTRY, accept,
                Utils.byteArrayToInt(passkey));
                Utils.byteArrayToInt(passkey));
@@ -2227,6 +2238,11 @@ public class AdapterService extends Service {
            return false;
            return false;
        }
        }


        StatsLog.write(StatsLog.BLUETOOTH_BOND_STATE_CHANGED,
                obfuscateAddress(device), 0, device.getType(),
                BluetoothDevice.BOND_BONDING,
                BluetoothProtoEnums.BOND_SUB_STATE_LOCAL_SSP_REPLIED,
                accept ? 0 : BluetoothDevice.UNBOND_REASON_AUTH_REJECTED);
        byte[] addr = Utils.getBytesFromAddress(device.getAddress());
        byte[] addr = Utils.getBytesFromAddress(device.getAddress());
        return sspReplyNative(addr, AbstractionLayer.BT_SSP_VARIANT_PASSKEY_CONFIRMATION, accept,
        return sspReplyNative(addr, AbstractionLayer.BT_SSP_VARIANT_PASSKEY_CONFIRMATION, accept,
                0);
                0);
+35 −3
Original line number Original line Diff line number Diff line
@@ -20,11 +20,13 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProtoEnums;
import android.bluetooth.OobData;
import android.bluetooth.OobData;
import android.content.Intent;
import android.content.Intent;
import android.os.Message;
import android.os.Message;
import android.os.UserHandle;
import android.os.UserHandle;
import android.util.Log;
import android.util.Log;
import android.util.StatsLog;


import com.android.bluetooth.Utils;
import com.android.bluetooth.Utils;
import com.android.bluetooth.a2dp.A2dpService;
import com.android.bluetooth.a2dp.A2dpService;
@@ -40,6 +42,7 @@ import com.android.internal.util.StateMachine;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.Set;


/**
/**
@@ -204,6 +207,11 @@ final class BondStateMachine extends StateMachine {
                case BONDING_STATE_CHANGE:
                case BONDING_STATE_CHANGE:
                    int newState = msg.arg1;
                    int newState = msg.arg1;
                    int reason = getUnbondReasonFromHALCode(msg.arg2);
                    int reason = getUnbondReasonFromHALCode(msg.arg2);
                    // Bond is explicitly removed if we are in pending command state
                    if (newState == BluetoothDevice.BOND_NONE
                            && reason == BluetoothDevice.BOND_SUCCESS) {
                        reason = BluetoothDevice.UNBOND_REASON_REMOVED;
                    }
                    sendIntent(dev, newState, reason);
                    sendIntent(dev, newState, reason);
                    if (newState != BluetoothDevice.BOND_BONDING) {
                    if (newState != BluetoothDevice.BOND_BONDING) {
                        /* this is either none/bonded, remove and transition */
                        /* this is either none/bonded, remove and transition */
@@ -315,8 +323,18 @@ final class BondStateMachine extends StateMachine {
            } else {
            } else {
                result = mAdapterService.createBondNative(addr, transport);
                result = mAdapterService.createBondNative(addr, transport);
            }
            }

            StatsLog.write(StatsLog.BLUETOOTH_BOND_STATE_CHANGED,
                    mAdapterService.obfuscateAddress(dev), transport, dev.getType(),
                    BluetoothDevice.BOND_BONDING,
                    oobData == null ? BluetoothProtoEnums.BOND_SUB_STATE_UNKNOWN
                            : BluetoothProtoEnums.BOND_SUB_STATE_LOCAL_OOB_DATA_PROVIDED,
                    BluetoothProtoEnums.UNBOND_REASON_UNKNOWN);
            if (!result) {
            if (!result) {
                StatsLog.write(StatsLog.BLUETOOTH_BOND_STATE_CHANGED,
                        mAdapterService.obfuscateAddress(dev), transport, dev.getType(),
                        BluetoothDevice.BOND_NONE, BluetoothProtoEnums.BOND_SUB_STATE_UNKNOWN,
                        BluetoothDevice.UNBOND_REASON_REPEATED_ATTEMPTS);
                // Using UNBOND_REASON_REMOVED for legacy reason
                sendIntent(dev, BluetoothDevice.BOND_NONE, BluetoothDevice.UNBOND_REASON_REMOVED);
                sendIntent(dev, BluetoothDevice.BOND_NONE, BluetoothDevice.UNBOND_REASON_REMOVED);
                return false;
                return false;
            } else if (transition) {
            } else if (transition) {
@@ -368,7 +386,9 @@ final class BondStateMachine extends StateMachine {
        if (oldState == newState) {
        if (oldState == newState) {
            return;
            return;
        }
        }

        StatsLog.write(StatsLog.BLUETOOTH_BOND_STATE_CHANGED,
                mAdapterService.obfuscateAddress(device), 0, device.getType(),
                newState, BluetoothProtoEnums.BOND_SUB_STATE_UNKNOWN, reason);
        mAdapterProperties.onBondStateChanged(device, newState);
        mAdapterProperties.onBondStateChanged(device, newState);


        if ((devProp.getDeviceType() == BluetoothDevice.DEVICE_TYPE_CLASSIC
        if ((devProp.getDeviceType() == BluetoothDevice.DEVICE_TYPE_CLASSIC
@@ -464,9 +484,14 @@ final class BondStateMachine extends StateMachine {
        if (device == null) {
        if (device == null) {
            warnLog("Device is not known for:" + Utils.getAddressStringFromByte(address));
            warnLog("Device is not known for:" + Utils.getAddressStringFromByte(address));
            mRemoteDevices.addDeviceProperties(address);
            mRemoteDevices.addDeviceProperties(address);
            device = mRemoteDevices.getDevice(address);
            device = Objects.requireNonNull(mRemoteDevices.getDevice(address));
        }
        }


        StatsLog.write(StatsLog.BLUETOOTH_BOND_STATE_CHANGED,
                mAdapterService.obfuscateAddress(device), 0, device.getType(),
                BluetoothDevice.BOND_BONDING,
                BluetoothProtoEnums.BOND_SUB_STATE_LOCAL_SSP_REQUESTED, 0);

        Message msg = obtainMessage(SSP_REQUEST);
        Message msg = obtainMessage(SSP_REQUEST);
        msg.obj = device;
        msg.obj = device;
        if (displayPasskey) {
        if (displayPasskey) {
@@ -482,7 +507,14 @@ final class BondStateMachine extends StateMachine {
        BluetoothDevice bdDevice = mRemoteDevices.getDevice(address);
        BluetoothDevice bdDevice = mRemoteDevices.getDevice(address);
        if (bdDevice == null) {
        if (bdDevice == null) {
            mRemoteDevices.addDeviceProperties(address);
            mRemoteDevices.addDeviceProperties(address);
            bdDevice = Objects.requireNonNull(mRemoteDevices.getDevice(address));
        }
        }

        StatsLog.write(StatsLog.BLUETOOTH_BOND_STATE_CHANGED,
                mAdapterService.obfuscateAddress(bdDevice), 0, bdDevice.getType(),
                BluetoothDevice.BOND_BONDING,
                BluetoothProtoEnums.BOND_SUB_STATE_LOCAL_PIN_REQUESTED, 0);

        infoLog("pinRequestCallback: " + address + " name:" + name + " cod:" + cod);
        infoLog("pinRequestCallback: " + address + " name:" + name + " cod:" + cod);


        Message msg = obtainMessage(PIN_REQUEST);
        Message msg = obtainMessage(PIN_REQUEST);