use of android.bluetooth.BluetoothDevice in project Gadgetbridge by Freeyourgadget.
the class DeviceHelper method getBondedDevices.
private List<GBDevice> getBondedDevices(BluetoothAdapter btAdapter) {
Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
List<GBDevice> result = new ArrayList<>(pairedDevices.size());
DeviceHelper deviceHelper = DeviceHelper.getInstance();
for (BluetoothDevice pairedDevice : pairedDevices) {
if (pairedDevice.getName() != null && (pairedDevice.getName().startsWith("Pebble-LE ") || pairedDevice.getName().startsWith("Pebble Time LE "))) {
// ignore LE Pebble (this is part of the main device now (volatileAddress)
continue;
}
GBDevice device = deviceHelper.toSupportedDevice(pairedDevice);
if (device != null) {
result.add(device);
}
}
return result;
}
use of android.bluetooth.BluetoothDevice in project Gadgetbridge by Freeyourgadget.
the class BluetoothConnectReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (!action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)) {
return;
}
LOG.info("got connection attempt");
GBDevice gbDevice = service.getGBDevice();
if (gbDevice != null) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (device.getAddress().equals(gbDevice.getAddress()) && gbDevice.getState() == GBDevice.State.WAITING_FOR_RECONNECT) {
LOG.info("will connect to " + gbDevice.getName());
GBApplication.deviceService().connect();
} else {
LOG.info("won't connect to " + device.getAddress() + "(" + device.getName() + ")");
}
}
}
use of android.bluetooth.BluetoothDevice in project Gadgetbridge by Freeyourgadget.
the class MiBandPairingActivity method performBluetoothPair.
protected void performBluetoothPair(GBDeviceCandidate deviceCandidate) {
BluetoothDevice device = deviceCandidate.getDevice();
int bondState = device.getBondState();
if (bondState == BluetoothDevice.BOND_BONDED) {
GB.toast(getString(R.string.pairing_already_bonded, device.getName(), device.getAddress()), Toast.LENGTH_SHORT, GB.INFO);
performApplicationLevelPair();
return;
}
bondingMacAddress = device.getAddress();
if (bondState == BluetoothDevice.BOND_BONDING) {
GB.toast(this, getString(R.string.pairing_in_progress, device.getName(), bondingMacAddress), Toast.LENGTH_LONG, GB.INFO);
return;
}
GB.toast(this, getString(R.string.pairing_creating_bond_with, device.getName(), bondingMacAddress), Toast.LENGTH_LONG, GB.INFO);
if (!device.createBond()) {
GB.toast(this, getString(R.string.pairing_unable_to_pair_with, device.getName(), bondingMacAddress), Toast.LENGTH_LONG, GB.ERROR);
}
}
use of android.bluetooth.BluetoothDevice in project Gadgetbridge by Freeyourgadget.
the class BtLEQueue method connect.
/**
* Connects to the given remote device. Note that this does not perform any device
* specific initialization. This should be done in the specific {@link DeviceSupport}
* class.
*
* @return <code>true</code> whether the connection attempt was successfully triggered and <code>false</code> if that failed or if there is already a connection
*/
public boolean connect() {
if (isConnected()) {
LOG.warn("Ingoring connect() because already connected.");
return false;
}
synchronized (mGattMonitor) {
if (mBluetoothGatt != null) {
// Tribal knowledge says you're better off not reusing existing BluetoothGatt connections,
// so create a new one.
LOG.info("connect() requested -- disconnecting previous connection: " + mGbDevice.getName());
disconnect();
}
}
LOG.info("Attempting to connect to " + mGbDevice.getName());
mBluetoothAdapter.cancelDiscovery();
BluetoothDevice remoteDevice = mBluetoothAdapter.getRemoteDevice(mGbDevice.getAddress());
synchronized (mGattMonitor) {
// connectGatt with true doesn't really work ;( too often connection problems
mBluetoothGatt = remoteDevice.connectGatt(mContext, false, internalGattCallback);
}
boolean result = mBluetoothGatt != null;
if (result) {
setDeviceConnectionState(State.CONNECTING);
}
return result;
}
use of android.bluetooth.BluetoothDevice in project android_frameworks_base by DirtyUnicorns.
the class ScanResultTest method testScanResultParceling.
/**
* Test read and write parcel of ScanResult
*/
@SmallTest
public void testScanResultParceling() {
BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("01:02:03:04:05:06");
byte[] scanRecord = new byte[] { 1, 2, 3 };
int rssi = -10;
long timestampMicros = 10000L;
ScanResult result = new ScanResult(device, ScanRecord.parseFromBytes(scanRecord), rssi, timestampMicros);
Parcel parcel = Parcel.obtain();
result.writeToParcel(parcel, 0);
// Need to reset parcel data position to the beginning.
parcel.setDataPosition(0);
ScanResult resultFromParcel = ScanResult.CREATOR.createFromParcel(parcel);
assertEquals(result, resultFromParcel);
}
Aggregations