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

Commit 427d6f2f authored by William Escande's avatar William Escande
Browse files

Follow error prone recommendation

```
In ObexServerSockets.java
51: warning: The field 'NUMBER_OF_SOCKET_TYPES' is never read.
    private static final int NUMBER_OF_SOCKET_TYPES = 2;
                             ^
68: warning: This update of a volatile variable is non-atomic
        mTag = "ObexServerSockets" + sInstanceCounter++;
                                                     ^
76: warning: The documented method doesn't actually throw this
     * @throws IOException if it occurs while creating the
       ^
89: warning: The documented method doesn't actually throw this
     * @throws IOException if it occurs while creating the
       ^
107: warning: The documented method doesn't actually throw this
     * @throws IOException if it occurs while creating the
       ^
140: warning: Method create() annotated [none] but too narrow;
invokes method requiring {allOf=[android.permission.BLUETOOTH_CONNECT]}
                l2capSocket = bt.listenUsingInsecureL2capOn(l2capPsm);
                                                                   ^
296: warning: A block tag has an empty description.
         * @throws IllegalArgumentException
           ^
295: warning: Parameter name `latch` is unknown.
         * @param latch shall never be null.
           ^
```

Bug: 236759221
Test: m RUN_ERROR_PRONE=true Bluetooth
Change-Id: I202c2f54e9aee1ba05b8035e8d17b5aa0854d987
parent e5975fec
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
*/
package com.android.bluetooth;

import android.annotation.RequiresPermission;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothServerSocket;
@@ -24,6 +25,7 @@ import com.android.bluetooth.obex.ResponseCodes;
import com.android.bluetooth.obex.ServerSession;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Wraps multiple BluetoothServerSocket objects to make it possible to accept connections on
@@ -48,7 +50,6 @@ public class ObexServerSockets {
    private final String mTag;
    private static final String STAG = "ObexServerSockets";
    private static final boolean D = true; // TODO: set to false!
    private static final int NUMBER_OF_SOCKET_TYPES = 2; // increment if LE will be supported

    private final IObexConnectionHandler mConHandler;
    /* The wrapped sockets */
@@ -58,14 +59,14 @@ public class ObexServerSockets {
    private SocketAcceptThread mRfcommThread;
    private SocketAcceptThread mL2capThread;

    private static volatile int sInstanceCounter;
    private static volatile AtomicInteger sInstanceCounter = new AtomicInteger(0);

    private ObexServerSockets(IObexConnectionHandler conHandler, BluetoothServerSocket rfcommSocket,
            BluetoothServerSocket l2capSocket) {
        mConHandler = conHandler;
        mRfcommSocket = rfcommSocket;
        mL2capSocket = l2capSocket;
        mTag = "ObexServerSockets" + sInstanceCounter++;
        mTag = "ObexServerSockets" + sInstanceCounter.getAndIncrement();
    }

    /**
@@ -73,8 +74,8 @@ public class ObexServerSockets {
     * @param validator a reference to the {@link IObexConnectionHandler} object to call
     *                  to validate an incoming connection.
     * @return a reference to a {@link ObexServerSockets} object instance.
     * @throws IOException if it occurs while creating the {@link BluetoothServerSocket}s.
     */
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public static ObexServerSockets create(IObexConnectionHandler validator) {
        return create(validator, BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP,
                BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP, true);
@@ -86,8 +87,8 @@ public class ObexServerSockets {
     * @param validator a reference to the {@link IObexConnectionHandler} object to call
     *                  to validate an incoming connection.
     * @return a reference to a {@link ObexServerSockets} object instance.
     * @throws IOException if it occurs while creating the {@link BluetoothServerSocket}s.
     */
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public static ObexServerSockets createInsecure(IObexConnectionHandler validator) {
        return create(validator, BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP,
                BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP, false);
@@ -104,11 +105,11 @@ public class ObexServerSockets {
     *                  to validate an incoming connection.
     * @param isSecure boolean flag to determine whther socket would be secured or inseucure.
     * @return a reference to a {@link ObexServerSockets} object instance.
     * @throws IOException if it occurs while creating the {@link BluetoothServerSocket}s.
     *
     * TODO: Make public when it becomes possible to determine that the listen-call
     *       failed due to channel-in-use.
     */
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    private static ObexServerSockets create(IObexConnectionHandler validator, int rfcommChannel,
            int l2capPsm, boolean isSecure) {
        if (D) {
@@ -292,8 +293,7 @@ public class ObexServerSockets {
        /**
         * Create a SocketAcceptThread
         * @param serverSocket shall never be null.
         * @param latch shall never be null.
         * @throws IllegalArgumentException
         * @throws IllegalArgumentException if {@code serverSocket} is null
         */
        SocketAcceptThread(BluetoothServerSocket serverSocket) {
            if (serverSocket == null) {