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

Commit 0f6f7a95 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "BluetoothMetrics: Upload GATT server and client connection state change...

Merge "BluetoothMetrics: Upload GATT server and client connection state change events" am: 6480052c

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2099501



Change-Id: I657abb612077e7a334779c872f79120ddbe1e971
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents f1a3f918 6480052c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -692,7 +692,7 @@ class AdapterProperties {
                        + prevState + " -> " + state);
        BluetoothStatsLog.write(BluetoothStatsLog.BLUETOOTH_CONNECTION_STATE_CHANGED, state,
                0 /* deprecated */, profile, mService.obfuscateAddress(device),
                mService.getMetricId(device));
                mService.getMetricId(device), 0);

        if (!isNormalStateTransition(prevState, state)) {
            Log.w(TAG,
+35 −3
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProtoEnums;
import android.bluetooth.BluetoothStatusCodes;
import android.bluetooth.IBluetoothGatt;
import android.bluetooth.IBluetoothGattCallback;
@@ -70,6 +71,7 @@ import android.text.format.DateUtils;
import android.util.Log;

import com.android.bluetooth.BluetoothMetricsProto;
import com.android.bluetooth.BluetoothStatsLog;
import com.android.bluetooth.R;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.AbstractionLayer;
@@ -2005,7 +2007,7 @@ public class GattService extends ProfileService {
            Log.d(TAG, "onConnected() - clientIf=" + clientIf + ", connId=" + connId + ", address="
                    + address);
        }

        int connectionState = BluetoothProtoEnums.CONNECTION_STATE_DISCONNECTED;
        if (status == 0) {
            mClientMap.addConnection(clientIf, connId, address);

@@ -2015,12 +2017,16 @@ public class GattService extends ProfileService {
                    + address);
                mPermits.putIfAbsent(address, new AtomicBoolean(true));
            }
            connectionState = BluetoothProtoEnums.CONNECTION_STATE_CONNECTED;

        }
        ClientMap.App app = mClientMap.getById(clientIf);
        if (app != null) {
            app.callback.onClientConnectionState(status, clientIf,
                    (status == BluetoothGatt.GATT_SUCCESS), address);
        }
        statsLogGattConnectionStateChange(
                BluetoothProfile.GATT, address, clientIf, connectionState);
    }

    void onDisconnected(int clientIf, int connId, int status, String address)
@@ -2047,6 +2053,9 @@ public class GattService extends ProfileService {
        if (app != null) {
            app.callback.onClientConnectionState(status, clientIf, false, address);
        }
        statsLogGattConnectionStateChange(
                BluetoothProfile.GATT, address, clientIf,
                BluetoothProtoEnums.CONNECTION_STATE_DISCONNECTED);
    }

    void onClientPhyUpdate(int connId, int txPhy, int rxPhy, int status) throws RemoteException {
@@ -3386,6 +3395,9 @@ public class GattService extends ProfileService {
            Log.d(TAG, "clientConnect() - address=" + address + ", isDirect=" + isDirect
                    + ", opportunistic=" + opportunistic + ", phy=" + phy);
        }
        statsLogGattConnectionStateChange(
                BluetoothProfile.GATT, address, clientIf,
                BluetoothProtoEnums.CONNECTION_STATE_CONNECTING);
        gattClientConnectNative(clientIf, address, isDirect, transport, opportunistic, phy);
    }

@@ -3400,7 +3412,9 @@ public class GattService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "clientDisconnect() - address=" + address + ", connId=" + connId);
        }

        statsLogGattConnectionStateChange(
                BluetoothProfile.GATT, address, clientIf,
                BluetoothProtoEnums.CONNECTION_STATE_DISCONNECTING);
        gattClientDisconnectNative(clientIf, address, connId != null ? connId : 0);
    }

@@ -3962,14 +3976,18 @@ public class GattService extends ProfileService {
        if (app == null) {
            return;
        }

        int connectionState;
        if (connected) {
            mServerMap.addConnection(serverIf, connId, address);
            connectionState = BluetoothProtoEnums.CONNECTION_STATE_CONNECTED;
        } else {
            mServerMap.removeConnection(serverIf, connId);
            connectionState = BluetoothProtoEnums.CONNECTION_STATE_DISCONNECTED;
        }

        app.callback.onServerConnectionState((byte) 0, serverIf, connected, address);
        statsLogGattConnectionStateChange(
                BluetoothProfile.GATT_SERVER, address, serverIf, connectionState);
    }

    void onServerReadCharacteristic(String address, int connId, int transId, int handle, int offset,
@@ -4643,6 +4661,20 @@ public class GattService extends ProfileService {
        }
    }

    private void statsLogGattConnectionStateChange(
            int profile, String address, int sessionIndex, int connectionState) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothStatsLog.write(
                BluetoothStatsLog.BLUETOOTH_CONNECTION_STATE_CHANGED, connectionState,
                0 /* deprecated */, profile, new byte[0],
                mAdapterService.getMetricId(device), sessionIndex);
        if (DBG) {
            Log.d(TAG, "Gatt Logging: metric_id=" + mAdapterService.getMetricId(device)
                    + ", session_index=" + sessionIndex
                    + ", connection state=" + connectionState);
        }
    }

    @Override
    public void dumpProto(BluetoothMetricsProto.BluetoothLog.Builder builder) {
        synchronized (mScanEvents) {