Why do different Android devices allow for different maximum number of simultaneous Bluetooth connections?

Viewed 43

I have an Android tablet that acts as a Bluetooth server and allows up to 6 clients to connect (I set this limit, knowing that the theoretical maximum is 7, as per the Bluetooth piconet specification). I tried with two different tablet models from the same manufacturer: Huawei Mediapad T3 and Huawei MediaPad T5. On the T3, I can get up to 6 connections that remain stable and allow communicating almost seamlessly with the clients. On the T5, however, the tablet will not accept more than 4 simultaneous connections. If I disconnect one device, one of the two remaining ones which keep requesting to connect gets accepted in its place. I do not get any error messages from the calls to the accept() method, or any other errors regarding Bluetooth in the Android Logcat.

Both tablets run under EMUI 8.0.0 (the Huawei brew of Android 8.0.0).

Here is the code I run for the thread that accepts the connections :

 private class AcceptThread extends Thread {

        private BluetoothServerSocket serverSocket;

        AcceptThread(String name, String uuidStr) {
            btAdapter.cancelDiscovery();
            try{
                serverSocket = btAdapter.listenUsingInsecureRfcommWithServiceRecord(name, UUID.fromString(uuidStr));
            } catch (IOException ex){
                onStatusListener.OnStatus("server.error.COULD_NOT_LISTEN");
                Log.e(TAG, "Could not open socket", ex);
            }
        }

        public void run() {
            onStatusListener.OnStatus("server.listening");
            while (connections.size() < maxConnections) {
                setState(STATE_LISTENING);
                try {
                    BluetoothSocket socket = serverSocket.accept();
                    if (socket != null) {
                        ConnectedThread conn = new ConnectedThread(socket);
                        setState(STATE_CONNECTING);
                        conn.start();
                        connections.add(conn);
                        conn.setOnDisconnectEvent(() -> {
                            onStatusListener.OnStatus("server.disconnected." + socket.getRemoteDevice().getAddress());
                            connections.remove(conn);
                        });
                        onStatusListener.OnStatus("server.connected." + socket.getRemoteDevice().getAddress());
                    }
                } catch (IOException ex) {
                    onStatusListener.OnStatus("server.error.COULD_NOT_ACCEPT");
                    Log.e(TAG, "Socket's accept() method failed", ex);
                    break;
                }
            }
            onStatusListener.OnStatus("server.not_listening");
            cancel();
        }

        void cancel(){
            try {
                setState(STATE_NONE);
                serverSocket.close();
            } catch (IOException e) {
                Log.e(TAG, "Could not close server socket", e);
            }
        }
    }

What can cause my code to work on the T3 tablet and not on the T5?

Is there anything I could do differently to get my 6 simultaneous connections working with both tablets?

1 Answers

When it comes to the maximum connections allowed by a device, the limitation is usually related to the hardware and not the software. In other words, it is the Bluetooth hardware on the T5 that is preventing you from creating further connections. This is evident by the fact that both tablets are running the same OS yet still exhibit this difference.

What I find strange is the fact that you are not getting any error response back when you attempt to exceed the number of possible connections. Unfortunately I don't think there is a way to increase the limit on the T3. I would contact Huawei if possible as they would be able to confirm this discrepancy.

Related