Search in sources :

Example 6 with Transmitter

use of com.eveningoutpost.dexdrip.G5Model.Transmitter in project xDrip by NightscoutFoundation.

the class G5CollectionService method forgetDevice.

private synchronized void forgetDevice() {
    Log.d(TAG, "forgetDevice() start");
    // should be cached?
    final Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
    mBluetoothAdapter = mBluetoothManager.getAdapter();
    final Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {
            if (device.getName() != null) {
                final String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
                final String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
                // Log.e(TAG, "removeBond: "+transmitterIdLastTwo+" vs "+deviceNameLastTwo);
                if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
                    try {
                        Log.e(TAG, "removingBond: " + transmitterIdLastTwo + " vs " + deviceNameLastTwo);
                        Method m = device.getClass().getMethod("removeBond", (Class[]) null);
                        m.invoke(device, (Object[]) null);
                        getTransmitterDetails();
                    } catch (Exception e) {
                        Log.e(TAG, e.getMessage(), e);
                    }
                }
            }
        }
    }
    Log.d(TAG, "forgetDevice() finished");
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) Transmitter(com.eveningoutpost.dexdrip.G5Model.Transmitter) Method(java.lang.reflect.Method) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) BadPaddingException(javax.crypto.BadPaddingException)

Example 7 with Transmitter

use of com.eveningoutpost.dexdrip.G5Model.Transmitter in project xDrip-plus by jamorham.

the class SystemStatus method forgetDeviceListener.

private void forgetDeviceListener() {
    forget_device.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (mBluetoothManager != null && ActiveBluetoothDevice.first() != null) {
                final BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
                if (bluetoothAdapter != null) {
                    for (BluetoothDevice bluetoothDevice : bluetoothAdapter.getBondedDevices()) {
                        if (bluetoothDevice.getAddress().compareTo(ActiveBluetoothDevice.first().address) == 0) {
                            try {
                                Method m = bluetoothDevice.getClass().getMethod("removeBond", (Class[]) null);
                                m.invoke(bluetoothDevice, (Object[]) null);
                                notes.append("\n- Bluetooth unbonded, if using share tell it to forget your device.");
                                notes.append("\n- Scan for devices again to set connection back up!");
                            } catch (Exception e) {
                                Log.e("SystemStatus", e.getMessage(), e);
                            }
                        }
                    }
                    ActiveBluetoothDevice.forget();
                    bluetoothAdapter.disable();
                    mHandler.postDelayed(new Runnable() {

                        public void run() {
                            bluetoothAdapter.enable();
                            set_current_values();
                            mHandler2.postDelayed(new Runnable() {

                                public void run() {
                                    CollectionServiceStarter.restartCollectionService(getApplicationContext());
                                    set_current_values();
                                }
                            }, 5000);
                        }
                    }, 1000);
                }
            }
            String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
            if (collection_method.compareTo("DexcomG5") == 0) {
                Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
                mBluetoothAdapter = mBluetoothManager.getAdapter();
                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)) {
                                try {
                                    Method m = device.getClass().getMethod("removeBond", (Class[]) null);
                                    m.invoke(device, (Object[]) null);
                                    notes.append("\nG5 Transmitter unbonded, switch device mode to prevent re-pairing to G5.");
                                } catch (Exception e) {
                                    Log.e("SystemStatus", e.getMessage(), e);
                                }
                            }
                        }
                    }
                }
            }
        }
    });
}
Also used : Set(java.util.Set) BluetoothDevice(android.bluetooth.BluetoothDevice) ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) Transmitter(com.eveningoutpost.dexdrip.G5Model.Transmitter) Method(java.lang.reflect.Method) View(android.view.View) TextView(android.widget.TextView) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 8 with Transmitter

use of com.eveningoutpost.dexdrip.G5Model.Transmitter in project xDrip-plus by jamorham.

the class Amazfitservice method getCurrentDevice.

// TODO what does this do? Use DexCollectionType and make as unified as possible
public String getCurrentDevice() {
    activeBluetoothDevice = ActiveBluetoothDevice.first();
    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    String currentdevice;
    if (activeBluetoothDevice != null) {
        currentdevice = activeBluetoothDevice.name;
    } else {
        currentdevice = "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)) {
                            currentdevice = defaultTransmitter.transmitterId;
                        }
                    }
                }
            }
        } else {
            currentdevice = "No Bluetooth";
        }
    }
    return currentdevice;
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) Transmitter(com.eveningoutpost.dexdrip.G5Model.Transmitter)

Example 9 with Transmitter

use of com.eveningoutpost.dexdrip.G5Model.Transmitter in project xDrip-plus by jamorham.

the class SystemStatusFragment method forgetDeviceListener.

private void forgetDeviceListener() {
    forget_device.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (mBluetoothManager != null && ActiveBluetoothDevice.first() != null) {
                final BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
                if (bluetoothAdapter != null) {
                    for (BluetoothDevice bluetoothDevice : bluetoothAdapter.getBondedDevices()) {
                        if (bluetoothDevice.getAddress().compareTo(ActiveBluetoothDevice.first().address) == 0) {
                            try {
                                Method m = bluetoothDevice.getClass().getMethod("removeBond", (Class[]) null);
                                m.invoke(bluetoothDevice, (Object[]) null);
                                notes.append("\n- Bluetooth unbonded, if using share tell it to forget your device.");
                                notes.append("\n- Scan for devices again to set connection back up!");
                            } catch (Exception e) {
                                Log.e("SystemStatus", e.getMessage(), e);
                            }
                        }
                    }
                    ActiveBluetoothDevice.forget();
                    bluetoothAdapter.disable();
                    mHandler.postDelayed(new Runnable() {

                        public void run() {
                            bluetoothAdapter.enable();
                            set_current_values();
                            mHandler2.postDelayed(new Runnable() {

                                public void run() {
                                    CollectionServiceStarter.restartCollectionService(safeGetContext());
                                    set_current_values();
                                }
                            }, 5000);
                        }
                    }, 1000);
                }
            }
            String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
            if (collection_method.compareTo("DexcomG5") == 0) {
                Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
                mBluetoothAdapter = mBluetoothManager.getAdapter();
                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)) {
                                try {
                                    Method m = device.getClass().getMethod("removeBond", (Class[]) null);
                                    m.invoke(device, (Object[]) null);
                                    notes.append("\nG5 Transmitter unbonded, switch device mode to prevent re-pairing to G5.");
                                } catch (Exception e) {
                                    Log.e("SystemStatus", e.getMessage(), e);
                                }
                            }
                        }
                    }
                }
            }
        }
    });
}
Also used : Set(java.util.Set) BluetoothDevice(android.bluetooth.BluetoothDevice) ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) Transmitter(com.eveningoutpost.dexdrip.G5Model.Transmitter) Method(java.lang.reflect.Method) View(android.view.View) TextView(android.widget.TextView) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 10 with Transmitter

use of com.eveningoutpost.dexdrip.G5Model.Transmitter in project xDrip-plus by jamorham.

the class G5CollectionService method forgetDevice.

private synchronized void forgetDevice() {
    Log.d(TAG, "forgetDevice() start");
    // should be cached?
    final Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
    mBluetoothAdapter = mBluetoothManager.getAdapter();
    final Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {
            if (device.getName() != null) {
                final String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
                final String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
                // Log.e(TAG, "removeBond: "+transmitterIdLastTwo+" vs "+deviceNameLastTwo);
                if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
                    try {
                        Log.e(TAG, "removingBond: " + transmitterIdLastTwo + " vs " + deviceNameLastTwo);
                        Method m = device.getClass().getMethod("removeBond", (Class[]) null);
                        m.invoke(device, (Object[]) null);
                        getTransmitterDetails();
                    } catch (Exception e) {
                        Log.e(TAG, e.getMessage(), e);
                    }
                }
            }
        }
    }
    Log.d(TAG, "forgetDevice() finished");
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) Transmitter(com.eveningoutpost.dexdrip.G5Model.Transmitter) Method(java.lang.reflect.Method) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) BadPaddingException(javax.crypto.BadPaddingException)

Aggregations

BluetoothDevice (android.bluetooth.BluetoothDevice)18 Transmitter (com.eveningoutpost.dexdrip.G5Model.Transmitter)18 ActiveBluetoothDevice (com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice)14 Method (java.lang.reflect.Method)6 BluetoothAdapter (android.bluetooth.BluetoothAdapter)4 View (android.view.View)4 TextView (android.widget.TextView)4 Set (java.util.Set)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 BadPaddingException (javax.crypto.BadPaddingException)2 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)2 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)2