Bluetooth Connection drops automatically with Android Application
Asked Answered
L

3

3

I am creating an application which Connects with the BLE Device with android application programmatically. Here's my code for the Connect / Disconnect

When user clicks on the Connect button

new Thread(new Runnable() {
            @Override
            public void run() {
                mConnecting = true;
                mConnectException = null;
                mConnectWait.close(); // Reset the condition.
                if (mConnectedGatt != null) {
                    // Reconnect to the BLE DEX adapter.
                    Logger.d(LOG_TAG, "going to connect");
                    mConnectedGatt.connect();
                    BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(deviceAddress);
                    device.connectGatt(mContext, false, mGattCallback);
                } else {
                    // Start scanning BLE devices.
                    Logger.d(LOG_TAG, "going to scan LE Devices");
                    scanLeDevice(true);
                }
                mConnectWait.block(); // Wait for connect to complete
                try {
                    if (mConnected) {
                        connectCallback.onConnectSuccess();

                    } else { // Error occurred in the connecting process
                        if (null == mConnectException) {
                            mConnectException = new BleDexException(
                                    "Failed to connect to the BLE DEX adapter",
                                    BleDexException.ERROR_BLE_CONNECT_FAILED);
                        }
                        connectCallback.onConnectFailed(mConnectException);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

                mConnecting = false;
            }
        }).start();

Scanning Code:

if (!mBleScanning) {
            // Stops scanning after a pre-defined scan period.
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mBleScanning = false;
                    if ((null != mBleScanner) && (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON)) {
                        mBleScanner.stopScan(mScanCallback);
                        if (mConnecting) {
                            Logger.e(LOG_TAG, "Timed out in scanning BLE devices");
                            mConnectException = new BleDexException(
                                    "Timed out in scanning BLE devices",
                                    BleDexException.ERROR_BLE_CONNECT_FAILED);
                            mConnectWait.open();
                        }
                    }
                }
            }, mBleScanPeriod);

            mBleScanning = true;
            //ScanFilter scanFilter = new ScanFilter.Builder().setServiceUuid(new ParcelUuid(DEX_SERVICE_SPP)).build();
            ScanFilter scanFilter = new ScanFilter.Builder().setDeviceName("DEXAdapter").build();
            java.util.ArrayList<ScanFilter> scanFilterList = new java.util.ArrayList<ScanFilter>();
            scanFilterList.add(scanFilter);
            ScanSettings scanSettings = new ScanSettings.Builder()
                    .setScanMode(ScanSettings.SCAN_MODE_BALANCED)
                    .build();
            if((null != mBleScanner) && (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON))
                mBleScanner.startScan(scanFilterList, scanSettings, mScanCallback);
        }
    } else {
        Logger.d(LOG_TAG, "stop scanning. what 's the scan flag is: " + mBleScanning);
        if (mBleScanning) {
            mBleScanning = false;
            if ((null != mBleScanner) && (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON))
                mBleScanner.stopScan(mScanCallback);
        }
    }

This is the broadcast receiver for pairing intent

public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action)) {
            if (mBtPin == null || mBtMacAddress == null) {
                return;
            }
            // Programmatically set the Bluetooth PIN.
            device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            pairingRequestType = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT,
                    BluetoothDevice.ERROR);
            Logger.d(LOG_TAG, "Received pairing request intent, Device mac address is: " + mBtMacAddress +
                    ". Device pairingrequest type is: " + pairingRequestType);
            if (device.getAddress().equals(mBtMacAddress)) {
                try {
                    int btpin = Integer.parseInt(mBtPin);
                    Logger.d(LOG_TAG, "Set pin to BT = " + btpin);
                    byte[] pinbytes;
                    pinbytes = ("" + btpin).getBytes("UTF-8");
                    device.setPin(pinbytes);
                    abortBroadcast();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
            int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
            switch (state) {
                case BluetoothDevice.BOND_NONE:
                    Logger.d(LOG_TAG, "Remote device is not bonded. Device: ");
                case BluetoothDevice.BOND_BONDING:
                    Logger.d(LOG_TAG, "Remote device is in bonding process");
                    break;
                case BluetoothDevice.BOND_BONDED:
                    Logger.d(LOG_TAG, "Remote device is paired");
                    BluetoothDevice bluetoothDevice = mBluetoothAdapter.getRemoteDevice(deviceAddress);
                    mConnectedGatt = bluetoothDevice.connectGatt(mContext, false, mGattCallback);
                    if (mConnectedGatt == null) {
                        Logger.e(LOG_TAG, "Failed to connect to GATT server");
                        if (mConnecting) {
                            mConnectException = new BleDexException(
                                    "Failed to connect to GATT server",
                                    BleDexException.ERROR_BLE_CONNECT_FAILED);
                            mConnectWait.open();
                        }
                    }
                    //scanLeDevice(false);
                    break;
            }
        }
    }
};

What happens is, as soon as I press the connect button it checks if the device is connected or not? If not it'll start he Bluetooth LE scan. I've added the ScanFilter for scanning the device so that it scans the limited device.

As soon as application receives the scan callback it pairs the device using createbond() method. And once that's done and pairing is complete it'll try to connect the blutooth gatt.

All this works successfully on the first attempt. But after some time the application disconnects the bluetooth device automatically.

This is the logs of automatic disconnection

07-05 15:15:26.101  6698  6698 D BleDexToolkitSample: Invoice send transaction initiated and is in progress.
07-05 15:15:26.103  6698  6765 D BleDexToolkitSample: SetConfigTransmissionControlNumber Success
07-05 15:15:26.103  6698  6765 D BleDexToolkitSample: SetConfigTestIndicator Success
07-05 15:15:26.103  6698  6765 D BleDexToolkitSample: SetRetailer Success
07-05 15:15:26.104  6698  6765 D BleDexToolkitSample: SetSupplier Success
07-05 15:15:26.112  6698  6765 D BleDexToolkitSample: BeginTransactionSet Success
07-05 15:15:26.115  6698  6765 D BleDexToolkitSample: WriteSTSegment Success
07-05 15:15:26.116  6698  6765 D BleDexToolkitSample: WriteG82Segment Success
07-05 15:15:26.116  6698  6765 D BleDexToolkitSample: WriteLoopStart Success
07-05 15:15:26.117  6698  6765 D BleDexToolkitSample: WriteG83Segment Success
07-05 15:15:26.117  6698  6765 D BleDexToolkitSample: WriteG83Segment Success
07-05 15:15:26.118  6698  6765 D BleDexToolkitSample: WriteG22Segment Success
07-05 15:15:26.118  6698  6765 D BleDexToolkitSample: WriteLoopEnd Success
07-05 15:15:26.118  6698  6765 D BleDexToolkitSample: WriteG84Segment Success
07-05 15:15:26.118  6698  6765 D BleDexToolkitSample: WriteG86Segment Success
07-05 15:15:26.118  6698  6765 D BleDexToolkitSample: WriteG85Segment Success
07-05 15:15:26.119  6698  6765 D BleDexToolkitSample: WriteSESegment Success
07-05 15:15:26.119  6698  6765 D BleDexToolkitSample: EndTransactionSet Success
07-05 15:15:26.136  6698  6723 D BleDexDevice: Initiated sending data: 05 
07-05 15:15:27.168  6698  6723 D BleDexDevice: Initiated sending data: 05 
07-05 15:15:28.174  1934  2382 W bt_btif : bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0008
07-05 15:15:28.175  1934  2382 W bt_btif : bta_gattc_conn_cback() - cif=4 connected=0 conn_id=4 reason=0x0008
07-05 15:15:28.175  1934  2382 W bt_btif : bta_gattc_conn_cback() - cif=6 connected=0 conn_id=6 reason=0x0008
07-05 15:15:28.176  1934  2049 D BtGatt.GattService: onConnected() connId=5, address=00:10:20:8E:26:97, connected=false
07-05 15:15:28.176  1934  2382 W bt_btif : bta_gattc_conn_cback() - cif=8 connected=0 conn_id=8 reason=0x0008
07-05 15:15:28.176  1934  2049 D BluetoothGattServer: onServerConnectionState() - status=0 serverIf=5 device=00:10:20:8E:26:97
07-05 15:15:28.180  1934  2049 D BtGatt.GattService: onDisconnected() - clientIf=8, connId=8, address=00:10:20:8E:26:97
07-05 15:15:28.181  6698  6711 D BluetoothGatt: onClientConnectionState() - status=8 clientIf=8 device=00:10:20:8E:26:97
07-05 15:15:28.181  6698  6711 E BleDexDevice: onConnectionStateChange failure status=8 newState=0
07-05 15:15:28.183  1934  2049 E BluetoothRemoteDevices: state12newState1
07-05 15:15:28.183  1934  2049 D BluetoothRemoteDevices: aclStateChangeCallback: State:DisConnected to Device:00:10:20:8E:26:97
07-05 15:15:28.189  6698  6698 D BleDexToolkitSample: BLE DEX Adapter disconnected.
07-05 15:15:28.193  1934  1934 D AvrcpBipRsp: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
07-05 15:15:28.193  1934  1934 D BluetoothMapService: onReceive
07-05 15:15:28.193  1934  1934 D BluetoothMapService: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
07-05 15:15:28.194  1934  1934 E BluetoothMapService: Unexpected error!
07-05 15:15:28.194  1934  1934 D BluetoothPbapReceiver: PbapReceiver onReceive action = android.bluetooth.device.action.ACL_DISCONNECTED
07-05 15:15:28.195  1934  1934 D BluetoothPbapReceiver: Calling start service with action = null
07-05 15:15:28.199  1934  1934 I BluetoothPbapReceiver: Exit - onReceive for intent:android.bluetooth.device.action.ACL_DISCONNECTED
07-05 15:15:28.199  1934  1934 D BluetoothPbapService: Enter - onStartCommand for service PBAP
07-05 15:15:28.200  1934  1934 D BluetoothPbapService: action: android.bluetooth.device.action.ACL_DISCONNECTED
07-05 15:15:28.200  1934  1934 D BluetoothPbapService: Exit - onStartCommand for service PBAP
07-05 15:15:28.203  1934  1952 E BtGatt.GattService: writeCharacteristic() - No connection for 00:10:20:8E:26:97...
07-05 15:15:28.203  6698  6723 D BleDexDevice: Initiated sending data: 05 
07-05 15:15:28.219  1934  4912 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@b82a9b1
07-05 15:15:28.219  4939  4939 I BTLEASH : BTReceive action : android.bluetooth.device.action.ACL_DISCONNECTED :: Device : DEXAdapter
07-05 15:15:28.233  1934  1934 V BluetoothFtpService: PARSE INTENT action: android.bluetooth.device.action.ACL_DISCONNECTED
07-05 15:15:28.239  1934  1934 D BluetoothDunService: parseIntent: action: android.bluetooth.device.action.ACL_DISCONNECTED

Now I changed the behavior of the application a little bit, rather than pairing and connecting the device, I directly connect the device without pairing. With this changes what I saw is the bluetooth connection is disconnected automatically after 30 seconds of connection. Below are the logs:

=Bluetooth Connected successfully logs =
07-10 13:27:00.554  5001  5001 D BleDexToolkitSample: Connecting to BLE DEX Adapter.
07-10 13:27:00.556  5001  5338 D BleDexDevice: device found, device address is: 00:10:20:8E:26:97
07-10 13:27:00.557  5001  5338 D BluetoothGatt: connect() - device: 00:10:20:8E:26:97, auto: false
07-10 13:27:00.558  5001  5338 D BluetoothGatt: registerApp()
07-10 13:27:00.558  5001  5338 D BluetoothGatt: registerApp() - UUID=9ed830a0-85b0-4192-9b4d-c9960f5bca84
07-10 13:27:00.560  1957  2829 D BtGatt.GattService: registerClient() - UUID=9ed830a0-85b0-4192-9b4d-c9960f5bca84
07-10 13:27:00.562  1957  2068 D BtGatt.GattService: onClientRegistered() - UUID=9ed830a0-85b0-4192-9b4d-c9960f5bca84, clientIf=9
07-10 13:27:00.562  5001  5015 D BluetoothGatt: onClientRegistered() - status=0 clientIf=9
07-10 13:27:00.563  1957  5052 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:00.564  1957  5052 I A2dpService: audio isMusicActive is false
07-10 13:27:00.565  1957  5052 D BtGatt.GattService: clientConnect() - address=00:10:20:8E:26:97, isDirect=true
07-10 13:27:00.565  1957  2068 D bt_btif_config: btif_get_address_type: Device [00:10:20:8e:26:97] address type 0
07-10 13:27:00.566  1957  2068 D bt_btif_config: btif_get_device_type: Device [00:10:20:8e:26:97] type 2
07-10 13:27:00.567  1957  2319 W bt_l2cap: l2cble_init_direct_conn
07-10 13:27:00.573  2198  2304 I WCNSS_FILTER: ibs_bt_device_wakeup: Writing IBS_WAKE_IND
07-10 13:27:01.577  2198  2325 I WCNSS_FILTER: ibs_wcnss_bt_device_sleep: TX Awake, Sending SLEEP_IND
07-10 13:27:01.926  1957  2319 W bt_btm  : btm_acl_created hci_handle=4 link_role=0  transport=2
07-10 13:27:01.927  2198  2304 I WCNSS_FILTER: ibs_bt_device_wakeup: Writing IBS_WAKE_IND
07-10 13:27:01.946  1957  2068 D BtGatt.GattService: onConnected() connId=5, address=00:10:20:8E:26:97, connected=true
07-10 13:27:01.946  1957  2068 D BluetoothGattServer: onServerConnectionState() - status=0 serverIf=5 device=00:10:20:8E:26:97
07-10 13:27:01.946  1957  2319 W bt_smp  : smp_br_connect_callback is called on unexpected transport 2
07-10 13:27:01.948  1957  2068 D bt_btif_config: btif_get_device_type: Device [00:10:20:8e:26:97] type 2
07-10 13:27:01.948  1957  2319 E bt_btif : bta_dm_acl_change new acl connetion:count = 1
07-10 13:27:01.949  1957  2319 W bt_btif : bta_dm_acl_change info: 0x0
07-10 13:27:01.949  1957  2319 W bt_l2cap: L2CA_SetDesireRole() new:x1, disallow_switch:0
07-10 13:27:01.949  1957  2068 D BluetoothRemoteDevices: Property type: 4
07-10 13:27:01.950  1957  2319 E bt_btif : bta_gattc_cache_load: can't open GATT cache file /data/misc/bluetooth/gatt_cache_0010208e2697 for reading, error: No such file or directory
07-10 13:27:01.952  1957  2068 D BluetoothRemoteDevices: Remote class is:7936
07-10 13:27:01.953  1957  2068 D BluetoothRemoteDevices: Property type: 5
07-10 13:27:01.953  1957  2068 D bt_btif_config: btif_get_device_type: Device [00:10:20:8e:26:97] type 2
07-10 13:27:01.953  1957  2068 I bt_btif_dm: get_cod remote_cod = 0x00001f00
07-10 13:27:01.953  1957  2068 I BluetoothBondStateMachine: bondStateChangeCallback: Status: 0 Address: 00:10:20:8E:26:97 newState: 1
07-10 13:27:01.954  1957  2068 I BluetoothBondStateMachine: sspRequestCallback: [B@f9753ea name: [B@ffc36db cod: 7936 pairingVariant 2 passkey: 0
07-10 13:27:01.955  1957  2068 D bt_btif_dm: remote version info [00:10:20:8e:26:97]: 0, 0, 0
07-10 13:27:01.957  1957  2068 E BluetoothRemoteDevices: state12newState0
07-10 13:27:01.957  1957  2068 D BluetoothRemoteDevices: aclStateChangeCallback: State:Connected to Device:00:10:20:8E:26:97
07-10 13:27:01.957  1957  2069 I BluetoothBondStateMachine: Bond State Change Intent:00:10:20:8E:26:97 OldState: 10 NewState: 11
07-10 13:27:01.957  1957  2069 I BluetoothBondStateMachine: Entering PendingCommandState State
07-10 13:27:01.958  2128  2128 W BluetoothEventManager: CachedBluetoothDevice for device 00:10:20:8E:26:97 not found, calling readPairedDevices().
07-10 13:27:01.961  2128  2128 E BluetoothEventManager: Got bonding state changed for 00:10:20:8E:26:97, but we have no record of that device.
07-10 13:27:01.974  1957  2068 D BtGatt.GattService: onConnected() - clientIf=9, connId=9, address=00:10:20:8E:26:97
07-10 13:27:01.975  5001  5015 D BluetoothGatt: onClientConnectionState() - status=0 clientIf=9 device=00:10:20:8E:26:97
07-10 13:27:01.975  5001  5015 D BluetoothGatt: discoverServices() - device: 00:10:20:8E:26:97
07-10 13:27:01.977  1957  2173 D BtGatt.GattService: discoverServices() - address=00:10:20:8E:26:97, connId=9
07-10 13:27:01.978  1957  1957 V BluetoothFtpService: Ftp Service onStartCommand
07-10 13:27:01.978  1957  1957 V BluetoothFtpService: PARSE INTENT action: android.bluetooth.device.action.BOND_STATE_CHANGED
07-10 13:27:01.984  5001  5001 D BleDexDevice: Received pairing request intent, Device mac address is: 00:10:20:8E:26:97. Device pairingrequest type is: 3
07-10 13:27:01.984  5001  5001 D BleDexDevice: Set pin to BT = 369371
07-10 13:27:01.986  1957  1957 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:01.987  1957  1957 D BluetoothFtpService: device: DEXAdapter
07-10 13:27:01.987  1957  2319 W bt_smp  : SMP_PasskeyReply() - Wrong State: 1
07-10 13:27:01.990  1957  2319 E bt_btm  : BTM_SetBlePhy failed, peer does not support request
07-10 13:27:01.993  1957  1957 D BluetoothDunService: parseIntent: action: android.bluetooth.device.action.BOND_STATE_CHANGED
07-10 13:27:02.000  1957  1957 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:02.002  1957  1957 D BluetoothDunService: device: DEXAdapter
07-10 13:27:02.456  1957  2319 W bt_btm  : btm_read_remote_version_complete: BDA: 00-10-20-8e-26-97
07-10 13:27:02.456  1957  2319 W bt_btm  : btm_read_remote_version_complete lmp_version 7 manufacturer 13 lmp_subversion 528
07-10 13:27:02.837  1957  2319 W bt_bta_gattc: bta_gattc_explore_srvc no more services found
07-10 13:27:02.840  1957  2068 D BtGatt.GattService: onSearchCompleted() - connId=9, status=0
07-10 13:27:02.843  1957  2068 D bt_bta_gattc: bta_gattc_get_gatt_db
07-10 13:27:02.845  1957  2068 D BtGatt.GattService: onGetGattDb() - address=00:10:20:8E:26:97
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got service with UUID=00001800-0000-1000-8000-00805f9b34fb
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got characteristic with UUID=00002a00-0000-1000-8000-00805f9b34fb
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got characteristic with UUID=00002a01-0000-1000-8000-00805f9b34fb
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got characteristic with UUID=00002a04-0000-1000-8000-00805f9b34fb
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got service with UUID=00001801-0000-1000-8000-00805f9b34fb
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got service with UUID=f000c0e0-0451-4000-b000-000000000000
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got characteristic with UUID=f000c0e1-0451-4000-b000-000000000000
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002902-0000-1000-8000-00805f9b34fb
07-10 13:27:02.846  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002901-0000-1000-8000-00805f9b34fb
07-10 13:27:02.847  1957  2068 D BtGatt.GattService: got characteristic with UUID=f000c0e2-0451-4000-b000-000000000000
07-10 13:27:02.847  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002901-0000-1000-8000-00805f9b34fb
07-10 13:27:02.847  1957  2068 D BtGatt.GattService: got service with UUID=f000ffd0-0451-4000-b000-000000000000
07-10 13:27:02.847  1957  2068 D BtGatt.GattService: got characteristic with UUID=f000ffd1-0451-4000-b000-000000000000
07-10 13:27:02.847  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002901-0000-1000-8000-00805f9b34fb
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got characteristic with UUID=f000ffd2-0451-4000-b000-000000000000
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002901-0000-1000-8000-00805f9b34fb
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got characteristic with UUID=f000ffd3-0451-4000-b000-000000000000
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002902-0000-1000-8000-00805f9b34fb
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002901-0000-1000-8000-00805f9b34fb
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got service with UUID=0000180f-0000-1000-8000-00805f9b34fb
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got characteristic with UUID=00002a19-0000-1000-8000-00805f9b34fb
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002902-0000-1000-8000-00805f9b34fb
07-10 13:27:02.848  1957  2068 D BtGatt.GattService: got descriptor with UUID=00002904-0000-1000-8000-00805f9b34fb
07-10 13:27:02.854  5001  5015 D BluetoothGatt: onSearchComplete() = Device=00:10:20:8E:26:97 Status=0
07-10 13:27:02.855  5001  5015 D BluetoothGatt: setCharacteristicNotification() - uuid: f000c0e1-0451-4000-b000-000000000000 enable: true
07-10 13:27:02.856  1957  1972 D BtGatt.GattService: registerForNotification() - address=00:10:20:8E:26:97 enable: true
07-10 13:27:02.857  1957  2068 D BtGatt.GattService: onRegisterForNotifications() - address=null, status=0, registered=1, handle=11
07-10 13:27:02.863  5001  5338 D BleDexToolkitSample: BLE DEX Adapter connection Success
07-10 13:27:02.870  5001  5001 D BleDexToolkitSample: BLE DEX Adapter connection Success.
07-10 13:27:03.863  2198  2325 I WCNSS_FILTER: ibs_wcnss_bt_device_sleep: TX Awake, Sending SLEEP_IND
07-10 13:27:07.947  2198  2304 I WCNSS_FILTER: ibs_bt_device_wakeup: Writing IBS_WAKE_IND
07-10 13:27:08.950  2198  2325 I WCNSS_FILTER: ibs_wcnss_bt_device_sleep: TX Awake, Sending SLEEP_IND

=android device disconneted the ble =

07-10 13:27:31.953  1957  2068 D bt_btif_config: btif_get_device_type: Device [00:10:20:8e:26:97] type 2
07-10 13:27:31.953  1957  2068 I bt_btif_dm: get_cod remote_cod = 0x00001f00
07-10 13:27:31.953  2172  5348 E bt_logger: Deleting old log file /data/media/0/bt_vnd_log20190710131438.txt
07-10 13:27:31.954  1957  2068 I BluetoothBondStateMachine: bondStateChangeCallback: Status: 1 Address: 00:10:20:8E:26:97 newState: 0
07-10 13:27:31.955  2172  5348 E bt_logger: Writing logs to file
07-10 13:27:31.955  1957  2069 D BluetoothAdapterProperties: Failed to remove device: 00:10:20:8E:26:97
07-10 13:27:31.962  2128  2128 W BluetoothEventManager: CachedBluetoothDevice for device 00:10:20:8E:26:97 not found, calling readPairedDevices().
07-10 13:27:31.964  1957  2069 I BluetoothBondStateMachine: Bond State Change Intent:00:10:20:8E:26:97 OldState: 11 NewState: 10
07-10 13:27:31.968  1957  2069 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:31.970  1957  2069 D A2dpService: Enter setPriority
07-10 13:27:31.972  1957  2069 D A2dpService: Saved priority 00:10:20:8E:26:97 = -1
07-10 13:27:31.972  1957  2069 D A2dpService: Exit setPriority
07-10 13:27:31.972  2128  2128 E BluetoothEventManager: Got bonding state changed for 00:10:20:8E:26:97, but we have no record of that device.
07-10 13:27:31.975  1957  2069 I BluetoothBondStateMachine: StableState(): Entering Off State
07-10 13:27:31.990  1957  1957 V BluetoothFtpService: Ftp Service onStartCommand
07-10 13:27:31.990  1957  1957 V BluetoothFtpService: PARSE INTENT action: android.bluetooth.device.action.BOND_STATE_CHANGED
07-10 13:27:31.994  1957  1957 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:31.994  1957  1957 D BluetoothFtpService: device: DEXAdapter
07-10 13:27:31.996  1957  1957 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:31.996  1957  1957 D BluetoothFtpService: BOND_STATE_CHANGED REFRESH trustDevices DEXAdapter
07-10 13:27:32.002  1957  1957 D BluetoothDunService: parseIntent: action: android.bluetooth.device.action.BOND_STATE_CHANGED
07-10 13:27:32.003  1957  1957 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:32.004  1957  1957 D BluetoothDunService: device: DEXAdapter
07-10 13:27:32.005  1957  1957 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:32.005  1957  1957 D BluetoothDunService: BOND_STATE_CHANGED REFRESH trustDevices DEXAdapter
07-10 13:27:32.020  1937  2199 W BluetoothEventManager: showUnbondMessage: Not displaying any message for reason: 9
07-10 13:27:32.021  2681  3699 I LicenseObserver: installLicenses - /storage/emulated/0/bt_vnd_log20190710132731.txt
07-10 13:27:34.953  1957  2066 D bt_osi_alarm: reschedule_root_alarm alarm expiration too close for posix timers, switching to guns
07-10 13:27:34.959  2198  2304 I WCNSS_FILTER: ibs_bt_device_wakeup: Writing IBS_WAKE_IND
07-10 13:27:34.994  1957  2319 W bt_btif : bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0016
07-10 13:27:34.994  1957  2319 W bt_btif : bta_gattc_conn_cback() - cif=4 connected=0 conn_id=4 reason=0x0016
07-10 13:27:34.995  1957  2319 W bt_btif : bta_gattc_conn_cback() - cif=6 connected=0 conn_id=6 reason=0x0016
07-10 13:27:34.995  1957  2319 W bt_btif : bta_gattc_conn_cback() - cif=7 connected=0 conn_id=7 reason=0x0016
07-10 13:27:34.995  1957  2319 W bt_btif : bta_gattc_conn_cback() - cif=8 connected=0 conn_id=8 reason=0x0016
07-10 13:27:34.995  1957  2068 D BtGatt.GattService: onConnected() connId=5, address=00:10:20:8E:26:97, connected=false
07-10 13:27:34.995  1957  2319 W bt_btif : bta_gattc_conn_cback() - cif=9 connected=0 conn_id=9 reason=0x0016
07-10 13:27:34.995  1957  2068 D BluetoothGattServer: onServerConnectionState() - status=0 serverIf=5 device=00:10:20:8E:26:97
07-10 13:27:34.996  1957  2319 I bt_btm_sec: btm_sec_disconnected clearing pending flag handle:4 reason:22
07-10 13:27:34.998  1957  2068 D BtGatt.GattService: onDisconnected() - clientIf=9, connId=9, address=00:10:20:8E:26:97
07-10 13:27:34.999  5001  5014 D BluetoothGatt: onClientConnectionState() - status=22 clientIf=9 device=00:10:20:8E:26:97
07-10 13:27:34.999  5001  5014 D BleDexDevice: onConnectionStateChange failure status=22 newState=0
07-10 13:27:34.999  2172  2172 E bt_logger: Logger Process: Invalid packet with no length field
07-10 13:27:34.999  2172  2172 E bt_logger: Error saving packet, buff = ound p_reg tcb_idx=0 gatt_if=9  conn_id=0x9�\
07-10 13:27:34.999  2172  2172 E bt_logger: Error saving packet, buff = 
07-10 13:27:35.000  1957  2319 W bt_l2cap: L2CA_SetDesireRole() new:x1, disallow_switch:0
07-10 13:27:35.001  1957  2319 E bt_btif : bta_gattc_mark_bg_conn unable to find the bg connection mask for: 00:10:20:8e:26:97
07-10 13:27:35.002  1957  2068 E BluetoothRemoteDevices: state12newState1
07-10 13:27:35.002  1957  2068 D BluetoothRemoteDevices: aclStateChangeCallback: State:DisConnected to Device:00:10:20:8E:26:97
07-10 13:27:35.004  5001  5001 D BleDexToolkitSample: BLE DEX Adapter disconnected.
07-10 13:27:35.006  1957  1957 D AvrcpBipRsp: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
07-10 13:27:35.006  1957  1957 D BluetoothMapService: onReceive
07-10 13:27:35.006  1957  1957 D BluetoothMapService: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
07-10 13:27:35.006  1957  1957 E BluetoothMapService: Unexpected error!
07-10 13:27:35.008  1957  1957 D BluetoothPbapReceiver: PbapReceiver onReceive action = android.bluetooth.device.action.ACL_DISCONNECTED
07-10 13:27:35.009  1957  1957 D BluetoothPbapReceiver: Calling start service with action = null
07-10 13:27:35.012  1957  1957 I BluetoothPbapReceiver: Exit - onReceive for intent:android.bluetooth.device.action.ACL_DISCONNECTED
07-10 13:27:35.013  1957  1957 D BluetoothPbapService: Enter - onStartCommand for service PBAP
07-10 13:27:35.013  1957  1957 D BluetoothPbapService: action: android.bluetooth.device.action.ACL_DISCONNECTED
07-10 13:27:35.013  1957  1957 D BluetoothPbapService: Exit - onStartCommand for service PBAP
07-10 13:27:35.026  1957  2829 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:35.027  5034  5034 I BTLEASH : BTReceive action : android.bluetooth.device.action.ACL_DISCONNECTED :: Device : DEXAdapter
07-10 13:27:35.030  1957  1970 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@d4dde01
07-10 13:27:35.045  1957  1957 V BluetoothFtpService: Ftp Service onStartCommand
07-10 13:27:35.046  1957  1957 V BluetoothFtpService: PARSE INTENT action: android.bluetooth.device.action.ACL_DISCONNECTED
07-10 13:27:35.053  1957  1957 D BluetoothDunService: parseIntent: action: android.bluetooth.device.action.ACL_DISCONNECTED
07-10 13:27:36.005  2198  2325 I WCNSS_FILTER: ibs_wcnss_bt_device_sleep: TX Awake, Sending SLEEP_IND
^C

Thanks in Advance.

Lachrymose answered 11/9, 2019 at 15:5 Comment(3)
What is the make of the phone you are using?Slipcase
Need some clarification BLE connection connect and disconnect to use DEX/UCS- MMJBioenergetics
I have same problem, but hardware part is not my. I resolved this problem by cache clearing on client sideDesignedly
L
3

Disconnect with reason 8 means Connection Timeout, and that's a hardware issue (not a software issue). The only reason it otherwise fails (at least what I can think of right now) with Connection Timeout is when the two devices try to use two different bonding keys. Then both set up the encryption with different keys, and then it fails due to this.

You could use an air sniffer to possibly find out why or when it's disconnecting.

Luna answered 11/9, 2019 at 16:53 Comment(1)
After a discussion with my hardware team they agreed that there was some issue with the hardware device which causes the bluetooth to disconnect. Some time I do get below log messages also bt_btif : bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0016 Which indicates that it's a BT_HCI_ERR_LOCALHOST_TERM_CONNLachrymose
L
0

If Android disconnects after 30 seconds, it means the remote device does not respond to a request such as GATT request or SMP (pairing) request. Please make sure the remote device correctly answers to all requests. If you don't know which request isn't responded to, please use the HCI log or an air sniffer to see which packet there is no response for.

Luna answered 17/9, 2019 at 15:23 Comment(2)
I think I have a theory why it's disconnecting. As I already know the mac address of the ble device so, I was directly connecting to the without scanning and pairing. So what I believe is as I don't need to do the scanning as I know the mac address but I did the pairing by calling the createBond() method before I connect the device using BluetoothGatt. So now my device is not disconnecting anymore. Could you please give your comments on this changes I did, @Emil?Lachrymose
If you scan or not is not related. If you do the bonding different then that might make your bonding sequence different and could be the reason it earlier failed. But you should check the packet log to really figure out why. Otherwise we can just speculate.Luna
D
0

Skip the scanning, when already knowing the MAC addresses, but keep the pairing in place - unless it's not the other side's firmware terminating the connection unexpectedly. A firmware with random connection drops may at least help testing that.

Derrik answered 22/9, 2019 at 5:2 Comment(1)
Yes, thats' what I did and it's working and no more disconnectsLachrymose

© 2022 - 2024 — McMap. All rights reserved.