use of nodomain.freeyourgadget.gadgetbridge.impl.GBDevice in project Gadgetbridge by Freeyourgadget.
the class DeviceHelper method getAvailableDevices.
/**
* Returns the list of all available devices that are supported by Gadgetbridge.
* Note that no state is known about the returned devices. Even if one of those
* devices is connected, it will report the default not-connected state.
*
* Clients interested in the "live" devices being managed should use the class
* DeviceManager.
* @param context
* @return
*/
public Set<GBDevice> getAvailableDevices(Context context) {
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
Set<GBDevice> availableDevices = new LinkedHashSet<GBDevice>();
if (btAdapter == null) {
GB.toast(context, context.getString(R.string.bluetooth_is_not_supported_), Toast.LENGTH_SHORT, GB.WARN);
} else if (!btAdapter.isEnabled()) {
GB.toast(context, context.getString(R.string.bluetooth_is_disabled_), Toast.LENGTH_SHORT, GB.WARN);
}
List<GBDevice> dbDevices = getDatabaseDevices();
// these come first, as they have the most information already
availableDevices.addAll(dbDevices);
if (btAdapter != null) {
List<GBDevice> bondedDevices = getBondedDevices(btAdapter);
availableDevices.addAll(bondedDevices);
}
Prefs prefs = GBApplication.getPrefs();
String miAddr = prefs.getString(MiBandConst.PREF_MIBAND_ADDRESS, "");
if (miAddr.length() > 0) {
GBDevice miDevice = new GBDevice(miAddr, "MI", DeviceType.MIBAND);
availableDevices.add(miDevice);
}
String pebbleEmuAddr = prefs.getString("pebble_emu_addr", "");
String pebbleEmuPort = prefs.getString("pebble_emu_port", "");
if (pebbleEmuAddr.length() >= 7 && pebbleEmuPort.length() > 0) {
GBDevice pebbleEmuDevice = new GBDevice(pebbleEmuAddr + ":" + pebbleEmuPort, "Pebble qemu", DeviceType.PEBBLE);
availableDevices.add(pebbleEmuDevice);
}
return availableDevices;
}
use of nodomain.freeyourgadget.gadgetbridge.impl.GBDevice in project Gadgetbridge by Freeyourgadget.
the class EntitiesTest method testDeviceAttributes.
@Test
public void testDeviceAttributes() throws Exception {
GBDevice dummyGBDevice = createDummyGDevice("00:00:00:00:02");
dummyGBDevice.setFirmwareVersion("1.0");
Device deviceOld = DBHelper.getDevice(dummyGBDevice, daoSession);
assertNotNull(deviceOld);
List<DeviceAttributes> attrListOld = deviceOld.getDeviceAttributesList();
assertEquals(1, attrListOld.size());
assertEquals("1.0", attrListOld.get(0).getFirmwareVersion1());
assertEquals("1.0", DBHelper.getDeviceAttributes(deviceOld).getFirmwareVersion1());
// some time passes, firmware update occurs
Thread.sleep(2 * 1000);
dummyGBDevice.setFirmwareVersion("2.0");
Device deviceNew = DBHelper.getDevice(dummyGBDevice, daoSession);
assertNotNull(deviceNew);
List<DeviceAttributes> attrListNew = deviceNew.getDeviceAttributesList();
assertEquals(2, attrListNew.size());
assertEquals("2.0", attrListNew.get(0).getFirmwareVersion1());
assertEquals("1.0", attrListNew.get(1).getFirmwareVersion1());
assertEquals("2.0", DBHelper.getDeviceAttributes(deviceNew).getFirmwareVersion1());
}
use of nodomain.freeyourgadget.gadgetbridge.impl.GBDevice in project Gadgetbridge by Freeyourgadget.
the class TestBase method createDummyGDevice.
protected GBDevice createDummyGDevice(String macAddress) {
GBDevice dummyGBDevice = new GBDevice(macAddress, "Testie", DeviceType.TEST);
dummyGBDevice.setFirmwareVersion("1.2.3");
dummyGBDevice.setModel("4.0");
return dummyGBDevice;
}
use of nodomain.freeyourgadget.gadgetbridge.impl.GBDevice in project Gadgetbridge by Freeyourgadget.
the class MiBandPairingActivity method performApplicationLevelPair.
private void performApplicationLevelPair() {
// just to make sure...
GBApplication.deviceService().disconnect();
GBDevice device = DeviceHelper.getInstance().toSupportedDevice(deviceCandidate);
if (device != null) {
GBApplication.deviceService().connect(device, true);
} else {
GB.toast(this, "Unable to connect, can't recognize the device type: " + deviceCandidate, Toast.LENGTH_LONG, GB.ERROR);
}
}
use of nodomain.freeyourgadget.gadgetbridge.impl.GBDevice in project Gadgetbridge by Freeyourgadget.
the class PebblePairingActivity method getMatchingParentDeviceFromDB.
private GBDevice getMatchingParentDeviceFromDB(BluetoothDevice btDevice) {
String expectedSuffix = btDevice.getName();
expectedSuffix = expectedSuffix.replace("Pebble-LE ", "");
expectedSuffix = expectedSuffix.replace("Pebble Time LE ", "");
expectedSuffix = expectedSuffix.substring(0, 2) + ":" + expectedSuffix.substring(2);
LOG.info("will try to find a Pebble with BT address suffix " + expectedSuffix);
GBDevice gbDevice = null;
try (DBHandler dbHandler = GBApplication.acquireDB()) {
DaoSession session = dbHandler.getDaoSession();
DeviceDao deviceDao = session.getDeviceDao();
Query<Device> query = deviceDao.queryBuilder().where(DeviceDao.Properties.Type.eq(1), DeviceDao.Properties.Identifier.like("%" + expectedSuffix)).build();
List<Device> devices = query.list();
if (devices.size() == 0) {
GB.toast("Please pair your non-LE Pebble before pairing the LE one", Toast.LENGTH_SHORT, GB.INFO);
returnToPairingActivity();
return null;
} else if (devices.size() > 1) {
GB.toast("Can not match this Pebble LE to a unique device", Toast.LENGTH_SHORT, GB.INFO);
returnToPairingActivity();
return null;
}
DeviceHelper deviceHelper = DeviceHelper.getInstance();
gbDevice = deviceHelper.toGBDevice(devices.get(0));
gbDevice.setVolatileAddress(btDevice.getAddress());
} catch (Exception e) {
GB.toast("Error retrieving devices from database", Toast.LENGTH_SHORT, GB.ERROR);
returnToPairingActivity();
return null;
}
return gbDevice;
}
Aggregations