use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip-plus by jamorham.
the class SystemStatusFragment method setConnectionStatus.
private void setConnectionStatus() {
boolean connected = false;
if (mBluetoothManager != null && activeBluetoothDevice != null && (Build.VERSION.SDK_INT >= 18)) {
for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
if (bluetoothDevice.getAddress().compareTo(activeBluetoothDevice.address) == 0) {
connected = true;
}
}
}
if (connected) {
connection_status.setText(safeGetContext().getString(R.string.connected));
} else {
connection_status.setText(safeGetContext().getString(R.string.not_connected));
}
String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
if (collection_method.compareTo("DexcomG5") == 0) {
Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
if (Build.VERSION.SDK_INT >= 18)
mBluetoothAdapter = mBluetoothManager.getAdapter();
if (mBluetoothAdapter != null) {
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
if (device.getName() != null) {
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
final String fw = G5CollectionService.getFirmwareVersionString(defaultTransmitter.transmitterId);
connection_status.setText(device.getName() + " Authed" + ((fw != null) ? ("\n" + fw) : ""));
break;
}
}
}
}
} else {
connection_status.setText(safeGetContext().getString(R.string.no_bluetooth));
}
}
}
use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip-plus by jamorham.
the class SystemStatusFragment method setCurrentDevice.
public void setCurrentDevice() {
if (activeBluetoothDevice != null) {
current_device.setText(activeBluetoothDevice.name);
} else {
current_device.setText("None Set");
}
String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
if (collection_method.compareTo("DexcomG5") == 0) {
Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
if (Build.VERSION.SDK_INT >= 18) {
mBluetoothAdapter = mBluetoothManager.getAdapter();
}
if (mBluetoothAdapter != null) {
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if ((pairedDevices != null) && (pairedDevices.size() > 0)) {
for (BluetoothDevice device : pairedDevices) {
if (device.getName() != null) {
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
current_device.setText(defaultTransmitter.transmitterId);
}
}
}
}
} else {
current_device.setText("No Bluetooth");
}
}
}
use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip-plus by jamorham.
the class Blukon method unBondIfBlukonAtInit.
public static void unBondIfBlukonAtInit() {
try {
if (Blukon.expectingBlukonDevice() && Pref.getBooleanDefaultFalse("blukon_unbonding")) {
final ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
if (btDevice != null) {
UserError.Log.d(TAG, "Unbonding blukon at initialization");
JoH.unBond(btDevice.address);
}
}
} catch (Exception e) {
UserError.Log.e(TAG, "Got exception trying to unbond blukon at init");
}
}
use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip-plus by jamorham.
the class ListenerService method sendCollectorStatus.
private void sendCollectorStatus(Context context, String path) {
String msg;
// long last_timestamp = 0;
DataMap dataMap = new DataMap();
switch(DexCollectionType.getDexCollectionType()) {
case DexcomG5:
if (DexCollectionType.getCollectorServiceClass() == G5CollectionService.class) {
// msg, last_timestamp
dataMap = G5CollectionService.getWatchStatus();
} else {
// msg, last_timestamp
dataMap = Ob1G5CollectionService.getWatchStatus();
}
break;
case // TODO getLastState() in non-G5 Services
DexcomShare:
BluetoothManager mBluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
ActiveBluetoothDevice activeBluetoothDevice = ActiveBluetoothDevice.first();
boolean connected = false;
if (mBluetoothManager != null && activeBluetoothDevice != null) {
for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
if (bluetoothDevice.getAddress().compareTo(activeBluetoothDevice.address) == 0) {
connected = true;
}
}
}
if (connected) {
msg = "Connected on watch";
} else {
msg = "Not Connected";
}
dataMap.putString("lastState", msg);
break;
default:
dataMap = DexCollectionService.getWatchStatus();
break;
}
if (dataMap != null) {
dataMap.putString("action_path", path);
}
// sendReplyMsg (msg, last_timestamp, path, false);
sendData(WEARABLE_REPLYMSG_PATH, dataMap.toByteArray());
}
use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip-plus by jamorham.
the class WebLibre2ConnectCode method request.
// process the request and produce a response object
public WebResponse request(String query) {
final JSONObject reply = new JSONObject();
boolean readOnly = true;
final Map<String, String> cgi = getQueryParameters(query);
if (cgi.containsKey("ReadOnly")) {
try {
readOnly = Boolean.valueOf(cgi.get("ReadOnly"));
} catch (Exception e) {
UserError.Log.e(TAG, "Error parsing ReadOnly val, continuing as read only");
}
}
// populate json structures
try {
final ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
if (btDevice == null || btDevice.address == null) {
UserError.Log.e(TAG, "ActiveBluetoothDevice has no valid bt device");
// I wonder how this will work with the recieving side???
return new WebResponse(reply.toString());
}
final String deviceAddress = btDevice.address;
byte[] btUnlockBuffer = LibreOOPAlgorithm.btSendgetBluetoothEnablePayload(!readOnly);
if (btUnlockBuffer == null) {
UserError.Log.e(TAG, "btSendgetBluetoothEnablePayload returned null");
// I wonder how this will work with the recieving side???
return new WebResponse(reply.toString());
}
reply.put(Intents.BT_UNLOCK_BUFFER, Base64.encodeToString(btUnlockBuffer, Base64.NO_WRAP));
reply.put(Intents.DEVICE_MAC_ADDRESS, btDevice.address);
Log.d(TAG, "Output: " + reply.toString());
} catch (JSONException e) {
UserError.Log.wtf(TAG, "Got json exception: " + e);
}
return new WebResponse(reply.toString());
}
Aggregations