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

Commit 4e209562 authored by Pomai Ahlo's avatar Pomai Ahlo Committed by Gerrit Code Review
Browse files

Merge changes I3c086bdd,Ica70f968,Iad667d59 into main

* changes:
  Add RFCOMM Metrics Implementation
  Save Socket Creation info as nanoseconds
  Separate Existing Metrics
parents 0e7d4542 b3db9592
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -175,7 +175,9 @@ interface IBluetooth
    IBluetoothSocketManager getSocketManager();
    IBluetoothSocketManager getSocketManager();


    @JavaPassthrough(annotation="@android.annotation.RequiresNoPermission")
    @JavaPassthrough(annotation="@android.annotation.RequiresNoPermission")
    oneway void logL2capcocClientConnection(in BluetoothDevice device, int port, boolean isSecured, int result, long socketCreationTimeMillis, long socketCreationLatencyMillis, long socketConnectionTimeMillis, in SynchronousResultReceiver receiver);
    oneway void logL2capcocClientConnection(in BluetoothDevice device, int port, boolean isSecured, int result, long socketCreationTimeNanos, long socketCreationLatencyNanos, long socketConnectionTimeNanos, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresNoPermission")
    oneway void logRfcommConnectionAttempt(in BluetoothDevice device, boolean isSecured, int resultCode, long socketCreationTimeNanos, boolean isSerialPort, in SynchronousResultReceiver receiver);


    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    oneway void factoryReset(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    oneway void factoryReset(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
+72 −13
Original line number Original line Diff line number Diff line
@@ -76,6 +76,7 @@ import android.bluetooth.IBluetoothSocketManager;
import android.bluetooth.IncomingRfcommSocketInfo;
import android.bluetooth.IncomingRfcommSocketInfo;
import android.bluetooth.OobData;
import android.bluetooth.OobData;
import android.bluetooth.UidTraffic;
import android.bluetooth.UidTraffic;
import android.bluetooth.rfcomm.BluetoothRfcommProtoEnums;
import android.companion.CompanionDeviceManager;
import android.companion.CompanionDeviceManager;
import android.content.AttributionSource;
import android.content.AttributionSource;
import android.content.Context;
import android.content.Context;
@@ -869,22 +870,23 @@ public class AdapterService extends Service {
     * @param port port of socket
     * @param port port of socket
     * @param isSecured if secured API is called
     * @param isSecured if secured API is called
     * @param result transaction result of the connection
     * @param result transaction result of the connection
     * @param socketCreationLatencyMillis latency of the connection
     * @param socketCreationLatencyNanos latency of the connection
     */
     */
    public void logL2capcocClientConnection(
    public void logL2capcocClientConnection(
            BluetoothDevice device,
            BluetoothDevice device,
            int port,
            int port,
            boolean isSecured,
            boolean isSecured,
            int result,
            int result,
            long socketCreationTimeMillis,
            long socketCreationTimeNanos,
            long socketCreationLatencyMillis,
            long socketCreationLatencyNanos,
            long socketConnectionTimeMillis,
            long socketConnectionTimeNanos,
            int appUid) {
            int appUid) {


        int metricId = getMetricId(device);
        int metricId = getMetricId(device);
        long currentTime = System.currentTimeMillis();
        long currentTime = System.nanoTime();
        long endToEndLatencyMillis = currentTime - socketCreationTimeMillis;
        long endToEndLatencyMillis = (currentTime - socketCreationTimeNanos) / 1000000;
        long socketConnectionLatencyMillis = currentTime - socketConnectionTimeMillis;
        long socketCreationLatencyMillis = socketCreationLatencyNanos / 1000000;
        long socketConnectionLatencyMillis = (currentTime - socketConnectionTimeNanos) / 1000000;
        Log.i(
        Log.i(
                TAG,
                TAG,
                "Statslog L2capcoc client connection."
                "Statslog L2capcoc client connection."
@@ -908,6 +910,37 @@ public class AdapterService extends Service {
                socketConnectionLatencyMillis);
                socketConnectionLatencyMillis);
    }
    }


    /**
     * Log RFCOMM Connection Metrics
     *
     * @param device Bluetooth device
     * @param isSecured if secured API is called
     * @param resultCode transaction result of the connection
     * @param isSerialPort true if service class UUID is 0x1101
     */
    public void logRfcommConnectionAttempt(
            BluetoothDevice device,
            boolean isSecured,
            int resultCode,
            long socketCreationTimeNanos,
            boolean isSerialPort,
            int appUid) {

        int metricId = getMetricId(device);
        long currentTime = System.nanoTime();
        long endToEndLatencyNanos = currentTime - socketCreationTimeNanos;
        BluetoothStatsLog.write(
                BluetoothStatsLog.BLUETOOTH_RFCOMM_CONNECTION_ATTEMPTED,
                metricId,
                endToEndLatencyNanos,
                isSecured
                        ? BluetoothRfcommProtoEnums.SOCKET_SECURITY_SECURE
                        : BluetoothRfcommProtoEnums.SOCKET_SECURITY_INSECURE,
                resultCode,
                isSerialPort,
                appUid);
    }

    @RequiresPermission(
    @RequiresPermission(
            allOf = {
            allOf = {
                android.Manifest.permission.BLUETOOTH_CONNECT,
                android.Manifest.permission.BLUETOOTH_CONNECT,
@@ -3933,9 +3966,9 @@ public class AdapterService extends Service {
                int port,
                int port,
                boolean isSecured,
                boolean isSecured,
                int result,
                int result,
                long socketCreationTimeMillis,
                long socketCreationTimeNanos,
                long socketCreationLatencyMillis,
                long socketCreationLatencyNanos,
                long socketConnectionTimeMillis,
                long socketConnectionTimeNanos,
                SynchronousResultReceiver receiver) {
                SynchronousResultReceiver receiver) {
            AdapterService service = getService();
            AdapterService service = getService();
            if (service == null) {
            if (service == null) {
@@ -3947,9 +3980,35 @@ public class AdapterService extends Service {
                        port,
                        port,
                        isSecured,
                        isSecured,
                        result,
                        result,
                        socketCreationTimeMillis,
                        socketCreationTimeNanos,
                        socketCreationLatencyMillis,
                        socketCreationLatencyNanos,
                        socketConnectionTimeMillis,
                        socketConnectionTimeNanos,
                        Binder.getCallingUid());
                receiver.send(null);
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }

        @Override
        public void logRfcommConnectionAttempt(
                BluetoothDevice device,
                boolean isSecured,
                int resultCode,
                long socketCreationTimeNanos,
                boolean isSerialPort,
                SynchronousResultReceiver receiver) {
            AdapterService service = getService();
            if (service == null) {
                return;
            }
            try {
                service.logRfcommConnectionAttempt(
                        device,
                        isSecured,
                        resultCode,
                        socketCreationTimeNanos,
                        isSerialPort,
                        Binder.getCallingUid());
                        Binder.getCallingUid());
                receiver.send(null);
                receiver.send(null);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
+14 −40
Original line number Original line Diff line number Diff line
@@ -16,20 +16,16 @@


package android.bluetooth;
package android.bluetooth;


import static android.bluetooth.BluetoothUtils.getSyncTimeout;


import android.annotation.SuppressLint;
import android.annotation.SuppressLint;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Handler;
import android.os.Handler;
import android.os.ParcelUuid;
import android.os.ParcelUuid;
import android.os.RemoteException;
import android.util.Log;
import android.util.Log;


import com.android.modules.utils.SynchronousResultReceiver;


import java.io.Closeable;
import java.io.Closeable;
import java.io.IOException;
import java.io.IOException;
import java.util.concurrent.TimeoutException;


/**
/**
 * A listening Bluetooth socket.
 * A listening Bluetooth socket.
@@ -192,54 +188,32 @@ public final class BluetoothServerSocket implements Closeable {
        BluetoothSocket acceptedSocket = null;
        BluetoothSocket acceptedSocket = null;
        try {
        try {
            acceptedSocket = mSocket.accept(timeout);
            acceptedSocket = mSocket.accept(timeout);
            logL2capcocServerConnection(
            SocketMetrics.logSocketAccept(
                    acceptedSocket,
                    acceptedSocket,
                    mSocket,
                    mType,
                    mChannel,
                    timeout,
                    timeout,
                    BluetoothSocket.RESULT_L2CAP_CONN_SUCCESS,
                    SocketMetrics.RESULT_L2CAP_CONN_SUCCESS,
                    mSocketCreationTimeMillis,
                    mSocketCreationLatencyMillis,
                    socketConnectionTime);
                    socketConnectionTime);
            return acceptedSocket;
            return acceptedSocket;
        } catch (IOException e) {
        } catch (IOException e) {
            logL2capcocServerConnection(
            SocketMetrics.logSocketAccept(
                    acceptedSocket,
                    acceptedSocket,
                    mSocket,
                    mType,
                    mChannel,
                    timeout,
                    timeout,
                    BluetoothSocket.RESULT_L2CAP_CONN_SERVER_FAILURE,
                    SocketMetrics.RESULT_L2CAP_CONN_SERVER_FAILURE,
                    mSocketCreationTimeMillis,
                    mSocketCreationLatencyMillis,
                    socketConnectionTime);
                    socketConnectionTime);
            throw e;
            throw e;
        }
        }
    }
    }


    private void logL2capcocServerConnection(
            BluetoothSocket acceptedSocket,
            int timeout,
            int result,
            long socketConnectionTimeMillis) {
        if (mType != BluetoothSocket.TYPE_L2CAP_LE) {
            return;
        }
        IBluetooth bluetoothProxy = BluetoothAdapter.getDefaultAdapter().getBluetoothService();
        if (bluetoothProxy == null) {
            Log.w(TAG, "bluetoothProxy is null while trying to log l2cap soc server connection");
            return;
        }
        try {
            final SynchronousResultReceiver recv = SynchronousResultReceiver.get();
            bluetoothProxy.logL2capcocServerConnection(
                    acceptedSocket == null ? null : acceptedSocket.getRemoteDevice(),
                    getPsm(),
                    mSocket.isAuth(),
                    result,
                    mSocketCreationTimeMillis, // pass creation time to calculate end to end latency
                    mSocketCreationLatencyMillis, // socket creation latency
                    socketConnectionTimeMillis, // send connection start time for connection latency
                    timeout,
                    recv);
            recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);

        } catch (RemoteException | TimeoutException e) {
            Log.w(TAG, "logL2capcocServerConnection failed due to remote exception");
        }
    }

    /**
    /**
     * Immediately close this socket, and release all associated resources.
     * Immediately close this socket, and release all associated resources.
     *
     *
+40 −83
Original line number Original line Diff line number Diff line
@@ -16,8 +16,6 @@


package android.bluetooth;
package android.bluetooth;


import static android.bluetooth.BluetoothUtils.getSyncTimeout;

import android.annotation.RequiresNoPermission;
import android.annotation.RequiresNoPermission;
import android.annotation.RequiresPermission;
import android.annotation.RequiresPermission;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
@@ -29,8 +27,6 @@ import android.os.ParcelUuid;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.Log;
import android.util.Log;


import com.android.modules.utils.SynchronousResultReceiver;

import java.io.Closeable;
import java.io.Closeable;
import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.IOException;
@@ -41,7 +37,6 @@ import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Locale;
import java.util.Locale;
import java.util.UUID;
import java.util.UUID;
import java.util.concurrent.TimeoutException;


/**
/**
 * A connected or connecting Bluetooth socket.
 * A connected or connecting Bluetooth socket.
@@ -129,16 +124,6 @@ public final class BluetoothSocket implements Closeable {
    /*package*/ static final int SEC_FLAG_AUTH_MITM = 1 << 3;
    /*package*/ static final int SEC_FLAG_AUTH_MITM = 1 << 3;
    /*package*/ static final int SEC_FLAG_AUTH_16_DIGIT = 1 << 4;
    /*package*/ static final int SEC_FLAG_AUTH_16_DIGIT = 1 << 4;


    // Defined in BluetoothProtoEnums.L2capCocConnectionResult of proto logging
    /*package*/ static final int RESULT_L2CAP_CONN_SUCCESS = 1;
    private static final int RESULT_L2CAP_CONN_BLUETOOTH_SOCKET_CONNECTION_FAILED = 1000;
    private static final int RESULT_L2CAP_CONN_BLUETOOTH_SOCKET_CONNECTION_CLOSED = 1001;
    private static final int RESULT_L2CAP_CONN_BLUETOOTH_UNABLE_TO_SEND_RPC = 1002;
    private static final int RESULT_L2CAP_CONN_BLUETOOTH_NULL_BLUETOOTH_DEVICE = 1003;
    private static final int RESULT_L2CAP_CONN_BLUETOOTH_GET_SOCKET_MANAGER_FAILED = 1004;
    private static final int RESULT_L2CAP_CONN_BLUETOOTH_NULL_FILE_DESCRIPTOR = 1005;
    /*package*/ static final int RESULT_L2CAP_CONN_SERVER_FAILURE = 2000;

    private final int mType; /* one of TYPE_RFCOMM etc */
    private final int mType; /* one of TYPE_RFCOMM etc */
    private BluetoothDevice mDevice; /* remote device */
    private BluetoothDevice mDevice; /* remote device */
    private String mAddress; /* remote address */
    private String mAddress; /* remote address */
@@ -172,8 +157,8 @@ public final class BluetoothSocket implements Closeable {
    private int mMaxTxPacketSize = 0; // The l2cap maximum packet size supported by the peer.
    private int mMaxTxPacketSize = 0; // The l2cap maximum packet size supported by the peer.
    private int mMaxRxPacketSize = 0; // The l2cap maximum packet size that can be received.
    private int mMaxRxPacketSize = 0; // The l2cap maximum packet size that can be received.


    private long mSocketCreationTimeMillis = 0;
    private long mSocketCreationTimeNanos = 0;
    private long mSocketCreationLatencyMillis = 0;
    private long mSocketCreationLatencyNanos = 0;


    private enum SocketState {
    private enum SocketState {
        INIT,
        INIT,
@@ -234,7 +219,7 @@ public final class BluetoothSocket implements Closeable {
            boolean min16DigitPin)
            boolean min16DigitPin)
            throws IOException {
            throws IOException {
        if (VDBG) Log.d(TAG, "Creating new BluetoothSocket of type: " + type);
        if (VDBG) Log.d(TAG, "Creating new BluetoothSocket of type: " + type);
        mSocketCreationTimeMillis = System.currentTimeMillis();
        mSocketCreationTimeNanos = System.nanoTime();
        if (type == BluetoothSocket.TYPE_RFCOMM
        if (type == BluetoothSocket.TYPE_RFCOMM
                && uuid == null
                && uuid == null
                && port != BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) {
                && port != BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) {
@@ -266,7 +251,7 @@ public final class BluetoothSocket implements Closeable {
        }
        }
        mInputStream = new BluetoothInputStream(this);
        mInputStream = new BluetoothInputStream(this);
        mOutputStream = new BluetoothOutputStream(this);
        mOutputStream = new BluetoothOutputStream(this);
        mSocketCreationLatencyMillis = System.currentTimeMillis() - mSocketCreationTimeMillis;
        mSocketCreationLatencyNanos = System.nanoTime() - mSocketCreationTimeNanos;
    }
    }


    /**
    /**
@@ -312,8 +297,8 @@ public final class BluetoothSocket implements Closeable {
        mExcludeSdp = s.mExcludeSdp;
        mExcludeSdp = s.mExcludeSdp;
        mAuthMitm = s.mAuthMitm;
        mAuthMitm = s.mAuthMitm;
        mMin16DigitPin = s.mMin16DigitPin;
        mMin16DigitPin = s.mMin16DigitPin;
        mSocketCreationTimeMillis = s.mSocketCreationTimeMillis;
        mSocketCreationTimeNanos = s.mSocketCreationTimeNanos;
        mSocketCreationLatencyMillis = s.mSocketCreationLatencyMillis;
        mSocketCreationLatencyNanos = s.mSocketCreationLatencyNanos;
    }
    }


    private BluetoothSocket acceptSocket(String remoteAddr) throws IOException {
    private BluetoothSocket acceptSocket(String remoteAddr) throws IOException {
@@ -445,50 +430,30 @@ public final class BluetoothSocket implements Closeable {
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public void connect() throws IOException {
    public void connect() throws IOException {
        IBluetooth bluetoothProxy = BluetoothAdapter.getDefaultAdapter().getBluetoothService();
        IBluetooth bluetoothProxy = BluetoothAdapter.getDefaultAdapter().getBluetoothService();
        long socketConnectionTimeMillis = System.currentTimeMillis();
        long socketConnectionTimeNanos = System.nanoTime();
        if (bluetoothProxy == null) {
        if (bluetoothProxy == null) {
            throw new BluetoothSocketException(BluetoothSocketException.BLUETOOTH_OFF_FAILURE);
            throw new BluetoothSocketException(BluetoothSocketException.BLUETOOTH_OFF_FAILURE);
        }
        }
        try {
            if (mDevice == null) {
            if (mDevice == null) {
            logL2capcocClientConnection(
                    bluetoothProxy,
                    RESULT_L2CAP_CONN_BLUETOOTH_NULL_BLUETOOTH_DEVICE,
                    socketConnectionTimeMillis);
                throw new BluetoothSocketException(BluetoothSocketException.NULL_DEVICE);
                throw new BluetoothSocketException(BluetoothSocketException.NULL_DEVICE);
            }
            }
        try {
            if (mSocketState == SocketState.CLOSED) {
            if (mSocketState == SocketState.CLOSED) {
                logL2capcocClientConnection(
                        bluetoothProxy,
                        RESULT_L2CAP_CONN_BLUETOOTH_SOCKET_CONNECTION_CLOSED,
                        socketConnectionTimeMillis);
                throw new BluetoothSocketException(BluetoothSocketException.SOCKET_CLOSED);
                throw new BluetoothSocketException(BluetoothSocketException.SOCKET_CLOSED);
            }
            }


            IBluetoothSocketManager socketManager = bluetoothProxy.getSocketManager();
            IBluetoothSocketManager socketManager = bluetoothProxy.getSocketManager();
            if (socketManager == null) {
            if (socketManager == null) {
                logL2capcocClientConnection(
                        bluetoothProxy,
                        RESULT_L2CAP_CONN_BLUETOOTH_GET_SOCKET_MANAGER_FAILED,
                        socketConnectionTimeMillis);
                throw new BluetoothSocketException(BluetoothSocketException.SOCKET_MANAGER_FAILURE);
                throw new BluetoothSocketException(BluetoothSocketException.SOCKET_MANAGER_FAILURE);
            }
            }
            mPfd = socketManager.connectSocket(mDevice, mType, mUuid, mPort, getSecurityFlags());
            mPfd = socketManager.connectSocket(mDevice, mType, mUuid, mPort, getSecurityFlags());
            synchronized (this) {
            synchronized (this) {
                if (DBG) Log.d(TAG, "connect(), SocketState: " + mSocketState + ", mPfd: " + mPfd);
                if (DBG) Log.d(TAG, "connect(), SocketState: " + mSocketState + ", mPfd: " + mPfd);
                if (mSocketState == SocketState.CLOSED) {
                if (mSocketState == SocketState.CLOSED) {
                    logL2capcocClientConnection(
                            bluetoothProxy,
                            RESULT_L2CAP_CONN_BLUETOOTH_SOCKET_CONNECTION_CLOSED,
                            socketConnectionTimeMillis);
                    throw new BluetoothSocketException(
                    throw new BluetoothSocketException(
                            BluetoothSocketException.SOCKET_CLOSED);
                            BluetoothSocketException.SOCKET_CLOSED);
                }
                }
                if (mPfd == null) {
                if (mPfd == null) {
                    logL2capcocClientConnection(
                            bluetoothProxy,
                            RESULT_L2CAP_CONN_BLUETOOTH_NULL_FILE_DESCRIPTOR,
                            socketConnectionTimeMillis);
                    throw new BluetoothSocketException(
                    throw new BluetoothSocketException(
                        BluetoothSocketException.UNIX_FILE_SOCKET_CREATION_FAILURE);
                        BluetoothSocketException.UNIX_FILE_SOCKET_CREATION_FAILURE);
                }
                }
@@ -500,14 +465,9 @@ public final class BluetoothSocket implements Closeable {
            int channel = readInt(mSocketIS);
            int channel = readInt(mSocketIS);
            if (channel == 0) {
            if (channel == 0) {
                int errCode = (int) mSocketIS.read();
                int errCode = (int) mSocketIS.read();
                logL2capcocClientConnection(bluetoothProxy, errCode, socketConnectionTimeMillis);
                throw new BluetoothSocketException(errCode);
                throw new BluetoothSocketException(errCode);
            }
            }
            if (channel < 0) {
            if (channel < 0) {
                logL2capcocClientConnection(
                        bluetoothProxy,
                        RESULT_L2CAP_CONN_BLUETOOTH_SOCKET_CONNECTION_FAILED,
                        socketConnectionTimeMillis);
                throw new BluetoothSocketException(
                throw new BluetoothSocketException(
                        BluetoothSocketException.SOCKET_CONNECTION_FAILURE);
                        BluetoothSocketException.SOCKET_CONNECTION_FAILURE);
            }
            }
@@ -515,26 +475,45 @@ public final class BluetoothSocket implements Closeable {
            waitSocketSignal(mSocketIS);
            waitSocketSignal(mSocketIS);
            synchronized (this) {
            synchronized (this) {
                if (mSocketState == SocketState.CLOSED) {
                if (mSocketState == SocketState.CLOSED) {
                    logL2capcocClientConnection(
                            bluetoothProxy,
                            RESULT_L2CAP_CONN_BLUETOOTH_SOCKET_CONNECTION_CLOSED,
                            socketConnectionTimeMillis);
                    throw new BluetoothSocketException(BluetoothSocketException.SOCKET_CLOSED);
                    throw new BluetoothSocketException(BluetoothSocketException.SOCKET_CLOSED);
                }
                }
                mSocketState = SocketState.CONNECTED;
                mSocketState = SocketState.CONNECTED;
                if (DBG) Log.d(TAG, "connect(), socket connected");
                if (DBG) Log.d(TAG, "connect(), socket connected");
            }
            }
            logL2capcocClientConnection(
        } catch (BluetoothSocketException e) {
                    bluetoothProxy, RESULT_L2CAP_CONN_SUCCESS, socketConnectionTimeMillis);
            SocketMetrics.logSocketConnect(
                    e.getErrorCode(),
                    socketConnectionTimeNanos,
                    mType,
                    mDevice,
                    mPort,
                    mAuth,
                    mSocketCreationTimeNanos,
                    mSocketCreationLatencyNanos);
            throw e;
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            logL2capcocClientConnection(
            SocketMetrics.logSocketConnect(
                    bluetoothProxy,
                    BluetoothSocketException.RPC_FAILURE,
                    RESULT_L2CAP_CONN_BLUETOOTH_UNABLE_TO_SEND_RPC,
                    socketConnectionTimeNanos,
                    socketConnectionTimeMillis);
                    mType,
                    mDevice,
                    mPort,
                    mAuth,
                    mSocketCreationTimeNanos,
                    mSocketCreationLatencyNanos);
            throw new BluetoothSocketException(
            throw new BluetoothSocketException(
                    BluetoothSocketException.RPC_FAILURE, "unable to send RPC: " + e.getMessage());
                    BluetoothSocketException.RPC_FAILURE, "unable to send RPC: " + e.getMessage());
        }
        }
        SocketMetrics.logSocketConnect(
                SocketMetrics.SOCKET_NO_ERROR,
                socketConnectionTimeNanos,
                mType,
                mDevice,
                mPort,
                mAuth,
                mSocketCreationTimeNanos,
                mSocketCreationLatencyNanos);
    }
    }


    /**
    /**
@@ -759,28 +738,6 @@ public final class BluetoothSocket implements Closeable {
        }
        }
    }
    }


    private void logL2capcocClientConnection(
            IBluetooth bluetoothProxy, int errCode, long socketConnectionTimeMillis) {
        if (mType != TYPE_L2CAP_LE) {
            return;
        }
        try {
            final SynchronousResultReceiver recv = SynchronousResultReceiver.get();
            bluetoothProxy.logL2capcocClientConnection(
                    mDevice,
                    mPort,
                    mAuth,
                    errCode,
                    mSocketCreationTimeMillis, // to calculate end to end latency
                    mSocketCreationLatencyMillis, // latency of the constructor
                    socketConnectionTimeMillis, // to calculate the latency of connect()
                    recv);
            recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
        } catch (RemoteException | TimeoutException e) {
            Log.w(TAG, "logL2capcocClientConnection failed due to remote exception");
        }
    }

    /*package */ void removeChannel() {}
    /*package */ void removeChannel() {}


    /*package */ int getPort() {
    /*package */ int getPort() {
@@ -788,7 +745,7 @@ public final class BluetoothSocket implements Closeable {
    }
    }


    /*package */ long getSocketCreationTime() {
    /*package */ long getSocketCreationTime() {
        return mSocketCreationTimeMillis;
        return mSocketCreationTimeNanos;
    }
    }


    /**
    /**
+183 −0

File added.

Preview size limit exceeded, changes collapsed.