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

Commit c4f6f211 authored by Palash Ahuja's avatar Palash Ahuja
Browse files

BluetoothMetrics: Log Profile Connection Event

Test: m com.android.btservices and statsd_testdrive
Bug: 345564021
Flag: EXEMPT, metrics related changes
Change-Id: Ibd821173bea8d658e596110d3c1789acfb2efe0d
parent cd655d26
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -776,6 +776,7 @@ class AdapterProperties {
                                        BluetoothAdapter.EXTRA_PREVIOUS_CONNECTION_STATE,
                                        prevAdapterState)
                                .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
                logProfileConnectionStateChange(device, newState, prevState);
                Log.d(TAG, "updateOnProfileConnectionChanged: " + logInfo);
                mService.sendBroadcastAsUser(
                        intent,
@@ -786,6 +787,34 @@ class AdapterProperties {
        }
    }

    private void logProfileConnectionStateChange(BluetoothDevice device, int state, int prevState) {

        switch (state) {
            case BluetoothAdapter.STATE_CONNECTED:
                MetricsLogger.getInstance()
                        .logBluetoothEvent(
                                device,
                                BluetoothStatsLog
                                        .BLUETOOTH_CROSS_LAYER_EVENT_REPORTED__EVENT_TYPE__PROFILE_CONNECTION,
                                BluetoothStatsLog
                                        .BLUETOOTH_CROSS_LAYER_EVENT_REPORTED__STATE__SUCCESS,
                                0);
                break;
            case BluetoothAdapter.STATE_DISCONNECTED:
                if (prevState == BluetoothAdapter.STATE_CONNECTING) {
                    MetricsLogger.getInstance()
                            .logBluetoothEvent(
                                    device,
                                    BluetoothStatsLog
                                            .BLUETOOTH_CROSS_LAYER_EVENT_REPORTED__EVENT_TYPE__PROFILE_CONNECTION,
                                    BluetoothStatsLog
                                            .BLUETOOTH_CROSS_LAYER_EVENT_REPORTED__STATE__FAIL,
                                    0);
                }
                break;
        }
    }

    private boolean validateProfileConnectionState(int state) {
        return (state == BluetoothProfile.STATE_DISCONNECTED
                || state == BluetoothProfile.STATE_CONNECTING