问题
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?
回答1:
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);
}
...
回答2:
It's hard to say with absolute certainty, but looking at how it's used in the rest of the class, I would say it's a unique ID assigned by the layer underneath called IBluetoothGatt
.
来源:https://stackoverflow.com/questions/34158315/clientif-field-in-android-bluetoothgatt-class