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

Commit bc19c025 authored by Pomai Ahlo's avatar Pomai Ahlo
Browse files

Save Socket Creation info as nanoseconds

New metrics are going to save latency information in nanoseconds.
To accomodate for this, change socketCreationTime and
socketCreationLatency to nanoseconds.  This does not change the units
for existing metrics.

Bug: 306760576
Flag: EXEMPT mechanical refactor
Test: m Bluetooth
Change-Id: Ica70f968847e8f41c51344851882baabb7d03945
parent e28d3cb0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ interface IBluetooth
    IBluetoothSocketManager getSocketManager();

    @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.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    oneway void factoryReset(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
+14 −13
Original line number Diff line number Diff line
@@ -869,22 +869,23 @@ public class AdapterService extends Service {
     * @param port port of socket
     * @param isSecured if secured API is called
     * @param result transaction result of the connection
     * @param socketCreationLatencyMillis latency of the connection
     * @param socketCreationLatencyNanos latency of the connection
     */
    public void logL2capcocClientConnection(
            BluetoothDevice device,
            int port,
            boolean isSecured,
            int result,
            long socketCreationTimeMillis,
            long socketCreationLatencyMillis,
            long socketConnectionTimeMillis,
            long socketCreationTimeNanos,
            long socketCreationLatencyNanos,
            long socketConnectionTimeNanos,
            int appUid) {

        int metricId = getMetricId(device);
        long currentTime = System.currentTimeMillis();
        long endToEndLatencyMillis = currentTime - socketCreationTimeMillis;
        long socketConnectionLatencyMillis = currentTime - socketConnectionTimeMillis;
        long currentTime = System.nanoTime();
        long endToEndLatencyMillis = (currentTime - socketCreationTimeNanos) / 1000000;
        long socketCreationLatencyMillis = socketCreationLatencyNanos / 1000000;
        long socketConnectionLatencyMillis = (currentTime - socketConnectionTimeNanos) / 1000000;
        Log.i(
                TAG,
                "Statslog L2capcoc client connection."
@@ -3933,9 +3934,9 @@ public class AdapterService extends Service {
                int port,
                boolean isSecured,
                int result,
                long socketCreationTimeMillis,
                long socketCreationLatencyMillis,
                long socketConnectionTimeMillis,
                long socketCreationTimeNanos,
                long socketCreationLatencyNanos,
                long socketConnectionTimeNanos,
                SynchronousResultReceiver receiver) {
            AdapterService service = getService();
            if (service == null) {
@@ -3947,9 +3948,9 @@ public class AdapterService extends Service {
                        port,
                        isSecured,
                        result,
                        socketCreationTimeMillis,
                        socketCreationLatencyMillis,
                        socketConnectionTimeMillis,
                        socketCreationTimeNanos,
                        socketCreationLatencyNanos,
                        socketConnectionTimeNanos,
                        Binder.getCallingUid());
                receiver.send(null);
            } catch (RuntimeException e) {
+19 −19
Original line number Diff line number Diff line
@@ -157,8 +157,8 @@ public final class BluetoothSocket implements Closeable {
    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 long mSocketCreationTimeMillis = 0;
    private long mSocketCreationLatencyMillis = 0;
    private long mSocketCreationTimeNanos = 0;
    private long mSocketCreationLatencyNanos = 0;

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

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

    private BluetoothSocket acceptSocket(String remoteAddr) throws IOException {
@@ -430,7 +430,7 @@ public final class BluetoothSocket implements Closeable {
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public void connect() throws IOException {
        IBluetooth bluetoothProxy = BluetoothAdapter.getDefaultAdapter().getBluetoothService();
        long socketConnectionTimeMillis = System.currentTimeMillis();
        long socketConnectionTimeNanos = System.nanoTime();
        if (bluetoothProxy == null) {
            throw new BluetoothSocketException(BluetoothSocketException.BLUETOOTH_OFF_FAILURE);
        }
@@ -483,37 +483,37 @@ public final class BluetoothSocket implements Closeable {
        } catch (BluetoothSocketException e) {
            SocketMetrics.logSocketConnect(
                    e.getErrorCode(),
                    socketConnectionTimeMillis,
                    socketConnectionTimeNanos,
                    mType,
                    mDevice,
                    mPort,
                    mAuth,
                    mSocketCreationTimeMillis,
                    mSocketCreationLatencyMillis);
                    mSocketCreationTimeNanos,
                    mSocketCreationLatencyNanos);
            throw e;
        } catch (RemoteException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            SocketMetrics.logSocketConnect(
                    BluetoothSocketException.RPC_FAILURE,
                    socketConnectionTimeMillis,
                    socketConnectionTimeNanos,
                    mType,
                    mDevice,
                    mPort,
                    mAuth,
                    mSocketCreationTimeMillis,
                    mSocketCreationLatencyMillis);
            throw new BluetoothSocketException(BluetoothSocketException.RPC_FAILURE,
                    "unable to send RPC: " + e.getMessage());
                    mSocketCreationTimeNanos,
                    mSocketCreationLatencyNanos);
            throw new BluetoothSocketException(
                    BluetoothSocketException.RPC_FAILURE, "unable to send RPC: " + e.getMessage());
        }
        SocketMetrics.logSocketConnect(
                SocketMetrics.SOCKET_NO_ERROR,
                socketConnectionTimeMillis,
                socketConnectionTimeNanos,
                mType,
                mDevice,
                mPort,
                mAuth,
                mSocketCreationTimeMillis,
                mSocketCreationLatencyMillis);
                mSocketCreationTimeNanos,
                mSocketCreationLatencyNanos);
    }

    /**
@@ -745,7 +745,7 @@ public final class BluetoothSocket implements Closeable {
    }

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

    /**
+6 −6
Original line number Diff line number Diff line
@@ -44,13 +44,13 @@ class SocketMetrics {

    static void logSocketConnect(
            int socketExceptionCode,
            long socketConnectionTimeMillis,
            long socketConnectionTimeNanos,
            int connType,
            BluetoothDevice device,
            int port,
            boolean auth,
            long socketCreationTimeMillis,
            long socketCreationLatencyMillis) {
            long socketCreationTimeNanos,
            long socketCreationLatencyNanos) {
        if (connType != BluetoothSocket.TYPE_L2CAP_LE) {
            return;
        }
@@ -67,9 +67,9 @@ class SocketMetrics {
                    port,
                    auth,
                    errCode,
                    socketCreationTimeMillis, // to calculate end to end latency
                    socketCreationLatencyMillis, // latency of the constructor
                    socketConnectionTimeMillis, // to calculate the latency of connect()
                    socketCreationTimeNanos, // to calculate end to end latency
                    socketCreationLatencyNanos, // latency of the constructor
                    socketConnectionTimeNanos, // to calculate the latency of connect()
                    recv);
            recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
        } catch (RemoteException | TimeoutException e) {