Methods Summary |
---|
private void | checkForDeviceRemoval(LocalBluetoothDevice device)
if (device.getBondState() == BluetoothDevice.BOND_NOT_BONDED &&
!device.isVisible()) {
// If device isn't paired, remove it altogether
mDevices.remove(device);
dispatchDeviceDeleted(device);
}
|
private void | dispatchDeviceAdded(LocalBluetoothDevice device)
synchronized (mCallbacks) {
for (Callback callback : mCallbacks) {
callback.onDeviceAdded(device);
}
}
// TODO: divider between prev paired/connected and scanned
|
private void | dispatchDeviceDeleted(LocalBluetoothDevice device)
synchronized (mCallbacks) {
for (Callback callback : mCallbacks) {
callback.onDeviceDeleted(device);
}
}
|
public synchronized LocalBluetoothDevice | findDevice(java.lang.String address)
for (int i = mDevices.size() - 1; i >= 0; i--) {
LocalBluetoothDevice device = mDevices.get(i);
if (device.getAddress().equals(address)) {
return device;
}
}
return null;
|
public synchronized java.util.List | getDevicesCopy()
return new ArrayList<LocalBluetoothDevice>(mDevices);
|
public java.lang.String | getName(java.lang.String address)Attempts to get the name of a remote device, otherwise returns the address.
LocalBluetoothDevice device = findDevice(address);
return device != null ? device.getName() : address;
|
void | onBluetoothStateChanged(boolean enabled)
if (enabled) {
readPairedDevices();
}
|
public synchronized void | onBondingError(java.lang.String address, int reason)Called when there is a bonding error.
mLocalManager.showError(address, R.string.bluetooth_error_title,
(reason == BluetoothDevice.UNBOND_REASON_AUTH_FAILED) ?
R.string.bluetooth_pairing_pin_error_message :
R.string.bluetooth_pairing_error_message);
|
public synchronized void | onBondingStateChanged(java.lang.String address, int bondState)
LocalBluetoothDevice device = findDevice(address);
if (device == null) {
if (!readPairedDevices()) {
Log.e(TAG, "Got bonding state changed for " + address +
", but we have no record of that device.");
}
return;
}
device.refresh();
if (bondState == BluetoothDevice.BOND_BONDED) {
// Auto-connect after pairing
device.connect();
}
|
public synchronized void | onBtClassChanged(java.lang.String address)
LocalBluetoothDevice device = findDevice(address);
if (device != null) {
device.refreshBtClass();
}
|
public synchronized void | onConnectingError(java.lang.String address)
LocalBluetoothDevice device = findDevice(address);
if (device == null) return;
/*
* Go through the device's delegate so we don't spam the user with
* errors connecting to different profiles, and instead make sure the
* user sees a single error for his single 'connect' action.
*/
device.showConnectingError();
|
public synchronized void | onDeviceAppeared(java.lang.String address, short rssi)
boolean deviceAdded = false;
LocalBluetoothDevice device = findDevice(address);
if (device == null) {
device = new LocalBluetoothDevice(mLocalManager.getContext(), address);
mDevices.add(device);
deviceAdded = true;
}
device.setRssi(rssi);
device.setVisible(true);
if (deviceAdded) {
dispatchDeviceAdded(device);
}
|
public synchronized void | onDeviceDisappeared(java.lang.String address)
LocalBluetoothDevice device = findDevice(address);
if (device == null) return;
device.setVisible(false);
checkForDeviceRemoval(device);
|
public synchronized void | onDeviceNameUpdated(java.lang.String address)
LocalBluetoothDevice device = findDevice(address);
if (device != null) {
device.refreshName();
}
|
public synchronized void | onProfileStateChanged(java.lang.String address, boolean transientState)
LocalBluetoothDevice device = findDevice(address);
if (device == null) return;
if (!transientState) {
device.onProfileStateChanged();
}
device.refresh();
|
public synchronized void | onScanningStateChanged(boolean started)
if (!started) return;
// If starting a new scan, clear old visibility
for (int i = mDevices.size() - 1; i >= 0; i--) {
LocalBluetoothDevice device = mDevices.get(i);
device.setVisible(false);
checkForDeviceRemoval(device);
}
|
private synchronized boolean | readPairedDevices()
BluetoothDevice manager = mLocalManager.getBluetoothManager();
String[] bondedAddresses = manager.listBonds();
if (bondedAddresses == null) return false;
boolean deviceAdded = false;
for (String address : bondedAddresses) {
LocalBluetoothDevice device = findDevice(address);
if (device == null) {
device = new LocalBluetoothDevice(mLocalManager.getContext(), address);
mDevices.add(device);
dispatchDeviceAdded(device);
deviceAdded = true;
}
}
return deviceAdded;
|