Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clientIf field in Android BluetoothGatt class

Android BluetoothGatt.class has mClientIf private field. Most of the log messages related to BLE events contain this value. For example:

onClientRegistered() - status=0 clientIf=17

What does the mClientIf field represent? What does the integer value of this field tell?

like image 805
ulusoyca Avatar asked Dec 08 '15 14:12

ulusoyca


1 Answers

mClientf is a scannerId from Bluetooth scanner,

If you dig through the source of BluetoothGatt and BluetoothLeScanner you can find the following:

mBluetoothGatt.unregisterClient(scannerId); method is implemented in

GattService.java unregisterClient(int clientIf)


BluetoothLeScanner.java

...
/**
 * Application interface registered - app is ready to go
 */
@Override
public void onScannerRegistered(int status, int scannerId) {
    Log.d(TAG, "onScannerRegistered() - status=" + status +
            " scannerId=" + scannerId + " mScannerId=" + mScannerId);
    synchronized (this) {
        if (status == BluetoothGatt.GATT_SUCCESS) {
            try {
                if (mScannerId == -1) {
                    // Registration succeeds after timeout, unregister client.
                    mBluetoothGatt.unregisterClient(scannerId);
                } else {
                    mScannerId = scannerId;
                    mBluetoothGatt.startScan(mScannerId, mSettings, mFilters,
                            mResultStorages,
                            ActivityThread.currentOpPackageName());
                }
            } catch (RemoteException e) {
                Log.e(TAG, "fail to start le scan: " + e);
                mScannerId = -1;
            }
        } else {
            // registration failed
            mScannerId = -1;
        }
        notifyAll();
    }
}
...

GattService.java

...
/**
 * Unregister the current application and callbacks.
 */
private IBluetoothGatt mService;
.
.   
public void unregisterClient(int clientIf) {
    GattService service = getService();
    if (service == null) return;
    service.unregisterClient(clientIf);
}
...
like image 155
Anup Avatar answered Oct 31 '22 08:10

Anup