com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice Java Examples

The following examples show how to use com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShareTest.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
public void attemptConnection() {
    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    if (device != null) {
        details.append("\nConnection state: " + " Device is not null");
        mConnectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);
    }

    Log.i(TAG, "Connection state: " + mConnectionState);
    details.append("\nConnection state: " + mConnectionState);
    if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) {
        ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class)
                .orderBy("_ID desc")
                .executeSingle();
        if (btDevice != null) {
            details.append("\nBT Device: " + btDevice.name);
            mDeviceName = btDevice.name;
            mDeviceAddress = btDevice.address;
            mBluetoothAdapter = mBluetoothManager.getAdapter();
            boolean newConnection = true;
            if(newConnection) {
                is_connected = connect(mDeviceAddress);
                details.append("\nConnecting...: ");
            }
        }
    }
}
 
Example #2
Source File: SystemStatus.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void set_current_values() {
    activeBluetoothDevice = ActiveBluetoothDevice.first();
    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    setVersionName();
    setCollectionMethod();
    setCurrentDevice();
    if (Home.get_follower()) {
        setConnectionStatusFollower();
    } else if (prefs.getString("dex_collection_method", "bogus").equals("WifiWixel")) {
        setConnectionStatusWifiWixel();
    } else {
        setConnectionStatus();
    }
    setSensorStatus();
    setTransmitterStatus();
    setNotes();
    futureDataCheck();
}
 
Example #3
Source File: SystemStatusFragment.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void set_current_values() {
    notes.setText("");
    activeBluetoothDevice = ActiveBluetoothDevice.first();
    if (Build.VERSION.SDK_INT >= 18) {
        mBluetoothManager = (BluetoothManager) safeGetContext().getSystemService(Context.BLUETOOTH_SERVICE);
    }
    setVersionName();
    //setCollectionMethod();
    setCurrentDevice();
    if (Home.get_follower()) {
        setConnectionStatusFollower();
    } else if (prefs.getString("dex_collection_method", "bogus").equals("WifiWixel")) {
        setConnectionStatusWifiWixel();
    } else {
        setConnectionStatus();
    }
    setSensorStatus();
    setTransmitterStatus();
    setNotes();
    futureDataCheck();

   /* if (notes.getText().length()==0) {
        notes.setText("Swipe for more status pages!");
    }*/
}
 
Example #4
Source File: SystemStatusFragment.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void set_current_values() {
    notes.setText("");
    activeBluetoothDevice = ActiveBluetoothDevice.first();
    if (Build.VERSION.SDK_INT >= 18) {
        mBluetoothManager = (BluetoothManager) safeGetContext().getSystemService(Context.BLUETOOTH_SERVICE);
    }
    setVersionName();
    //setCollectionMethod();
    setCurrentDevice();
    if (Home.get_follower()) {
        setConnectionStatusFollower();
    } else if (prefs.getString("dex_collection_method", "bogus").equals("WifiWixel")) {
        setConnectionStatusWifiWixel();
    } else {
        setConnectionStatus();
    }
    setSensorStatus();
    setTransmitterStatus();
    setNotes();
    futureDataCheck();

   /* if (notes.getText().length()==0) {
        notes.setText("Swipe for more status pages!");
    }*/
}
 
Example #5
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void sendActiveBtDeviceData() {//KS
    if (is_using_bt) {//only required for Collector running on watch
        forceGoogleApiConnect();
        ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
        if (btDevice != null) {
            if (wear_integration) {
                DataMap dataMap = new DataMap();
                Log.d(TAG, "sendActiveBtDeviceData name=" + btDevice.name + " address=" + btDevice.address + " connected=" + btDevice.connected);

                dataMap.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP

                dataMap.putString("name", btDevice.name);
                dataMap.putString("address", btDevice.address);
                dataMap.putBoolean("connected", btDevice.connected);

                new SendToDataLayerThread(WEARABLE_ACTIVEBTDEVICE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap);
            }
        }
    } else {
        Log.d(TAG, "Not sending activebluetoothdevice data as we are not using bt");
    }
}
 
Example #6
Source File: SystemStatus.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void set_current_values() {
    activeBluetoothDevice = ActiveBluetoothDevice.first();
    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    setVersionName();
    setCollectionMethod();
    setCurrentDevice();
    if (Home.get_follower()) {
        setConnectionStatusFollower();
    } else if (prefs.getString("dex_collection_method", "bogus").equals("WifiWixel")) {
        setConnectionStatusWifiWixel();
    } else {
        setConnectionStatus();
    }
    setSensorStatus();
    setTransmitterStatus();
    setNotes();
    futureDataCheck();
}
 
Example #7
Source File: ShareTest.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void attemptConnection() {
    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    if (device != null) {
        details.append("\nConnection state: " + " Device is not null");
        mConnectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);
    }

    Log.i(TAG, "Connection state: " + mConnectionState);
    details.append("\nConnection state: " + mConnectionState);
    if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) {
        ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class)
                .orderBy("_ID desc")
                .executeSingle();
        if (btDevice != null) {
            details.append("\nBT Device: " + btDevice.name);
            mDeviceName = btDevice.name;
            mDeviceAddress = btDevice.address;
            mBluetoothAdapter = mBluetoothManager.getAdapter();
            boolean newConnection = true;
            if(newConnection) {
                is_connected = connect(mDeviceAddress);
                details.append("\nConnecting...: ");
            }
        }
    }
}
 
Example #8
Source File: ShareTest.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        mBluetoothGatt = gatt;
        mConnectionState = STATE_CONNECTED;
        ActiveBluetoothDevice.connected();
        Log.i(TAG, "Connected to GATT server.");
        Log.i(TAG, "Connection state: Bonded - " + device.getBondState());

        if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
            currentGattTask = GATT_SETUP;
            mBluetoothGatt.discoverServices();

        } else {
            device.setPin("000000".getBytes());
            device.createBond();
        }
    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        mConnectionState = STATE_DISCONNECTED;
        ActiveBluetoothDevice.disconnected();
        Log.w(TAG, "Disconnected from GATT server.");
    }
}
 
Example #9
Source File: WatchUpdaterService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void sendActiveBtDeviceData() {//KS
    if (is_using_bt) {//only required for Collector running on watch
        forceGoogleApiConnect();
        ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
        if (btDevice != null) {
            if (wear_integration) {
                DataMap dataMap = new DataMap();
                Log.d(TAG, "sendActiveBtDeviceData name=" + btDevice.name + " address=" + btDevice.address + " connected=" + btDevice.connected);

                dataMap.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP

                dataMap.putString("name", btDevice.name);
                dataMap.putString("address", btDevice.address);
                dataMap.putBoolean("connected", btDevice.connected);

                new SendToDataLayerThread(WEARABLE_ACTIVEBTDEVICE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap);
            }
        }
    } else {
        Log.d(TAG, "Not sending activebluetoothdevice data as we are not using bt");
    }
}
 
Example #10
Source File: ShareTest.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        mBluetoothGatt = gatt;
        mConnectionState = STATE_CONNECTED;
        ActiveBluetoothDevice.connected();
        Log.i(TAG, "Connected to GATT server.");
        Log.i(TAG, "Connection state: Bonded - " + device.getBondState());

        if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
            currentGattTask = GATT_SETUP;
            mBluetoothGatt.discoverServices();

        } else {
            device.setPin("000000".getBytes());
            device.createBond();
        }
    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        mConnectionState = STATE_DISCONNECTED;
        ActiveBluetoothDevice.disconnected();
        Log.w(TAG, "Disconnected from GATT server.");
    }
}
 
Example #11
Source File: ShareTest.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public void attemptConnection() {
    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    if (device != null) {
        details.append("\nConnection state: " + " Device is not null");
        mConnectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);
    }

    Log.i(TAG, "Connection state: " + mConnectionState);
    details.append("\nConnection state: " + mConnectionState);
    if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) {
        ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class)
                .orderBy("_ID desc")
                .executeSingle();
        if (btDevice != null) {
            details.append("\nBT Device: " + btDevice.name);
            mDeviceName = btDevice.name;
            mDeviceAddress = btDevice.address;
            mBluetoothAdapter = mBluetoothManager.getAdapter();
            boolean newConnection = true;
            if(newConnection) {
                is_connected = connect(mDeviceAddress);
                details.append("\nConnecting...: ");
            }
        }
    }
}
 
Example #12
Source File: ShareTest.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        mBluetoothGatt = gatt;
        mConnectionState = STATE_CONNECTED;
        ActiveBluetoothDevice.connected();
        Log.i(TAG, "Connected to GATT server.");
        Log.i(TAG, "Connection state: Bonded - " + device.getBondState());

        if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
            currentGattTask = GATT_SETUP;
            mBluetoothGatt.discoverServices();

        } else {
            device.setPin("000000".getBytes());
            device.createBond();
        }
    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        mConnectionState = STATE_DISCONNECTED;
        ActiveBluetoothDevice.disconnected();
        Log.w(TAG, "Disconnected from GATT server.");
    }
}
 
Example #13
Source File: ShareTest.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        mBluetoothGatt = gatt;
        mConnectionState = STATE_CONNECTED;
        ActiveBluetoothDevice.connected();
        Log.w(TAG, "Connected to GATT server.");
        Log.w(TAG, "Connection state: Bonded - " + device.getBondState());

        if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
            currentGattTask = GATT_SETUP;
            mBluetoothGatt.discoverServices();

        } else {
            device.setPin("000000".getBytes());
            device.createBond();
        }
    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        mConnectionState = STATE_DISCONNECTED;
        ActiveBluetoothDevice.disconnected();
        Log.w(TAG, "Disconnected from GATT server.");
    }
}
 
Example #14
Source File: ShareTest.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void attemptConnection() {
    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    if (device != null) {
        details.append("\nConnection state: " + " Device is not null");
        mConnectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);
    }

    Log.w(TAG, "Connection state: " + mConnectionState);
    details.append("\nConnection state: " + mConnectionState);
    if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) {
        ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class)
                .orderBy("_ID desc")
                .executeSingle();
        if (btDevice != null) {
            details.append("\nBT Device: " + btDevice.name);
            mDeviceName = btDevice.name;
            mDeviceAddress = btDevice.address;
            mBluetoothAdapter = mBluetoothManager.getAdapter();
            boolean newConnection = true;
            if(newConnection) {
                is_connected = connect(mDeviceAddress);
                details.append("\nConnecting...: ");
            }
        }
    }
}
 
Example #15
Source File: DexCollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        mConnectionState = STATE_CONNECTED;
        ActiveBluetoothDevice.connected();
        Log.w(TAG, "Connected to GATT server.");
        mBluetoothGatt.discoverServices();
    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        mConnectionState = STATE_DISCONNECTED;
        ActiveBluetoothDevice.disconnected();
        Log.w(TAG, "Disconnected from GATT server.");
        setRetryTimer();
    }
}
 
Example #16
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void syncActiveBtDeviceData(DataMap dataMap, Context context) {//KS
    Log.d(TAG, "syncActiveBtDeviceData");
    if (dataMap != null) {
        String name = dataMap.getString("name", "");
        String address = dataMap.getString("address", "");
        Boolean connected = dataMap.getBoolean("connected", false);
        Log.d(TAG, "syncActiveBtDeviceData add ActiveBluetoothDevice for name=" + name + " address=" + address + " connected=" + connected);
        Sensor.InitDb(context);//ensure database has already been initialized
        if (name != null && !name.isEmpty() && address != null && !address.isEmpty()) {
            final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
            synchronized (ActiveBluetoothDevice.table_lock) {
                ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class)
                        .orderBy("_ID desc")
                        .executeSingle();

                prefs.edit().putString("last_connected_device_address", address).apply();
                if (btDevice == null) {
                    ActiveBluetoothDevice newBtDevice = new ActiveBluetoothDevice();
                    newBtDevice.name = name;
                    newBtDevice.address = address;
                    newBtDevice.connected = connected;
                    newBtDevice.save();
                } else {
                    btDevice.name = name;
                    btDevice.address = address;
                    btDevice.connected = connected;
                    btDevice.save();
                }
            }
        }
    }
}
 
Example #17
Source File: DexCollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public void attemptConnection() {
    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    if (mBluetoothManager != null) {
        mBluetoothAdapter = mBluetoothManager.getAdapter();
        if (mBluetoothAdapter != null) {
            if (device != null) {
                mConnectionState = STATE_DISCONNECTED;
                for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
                    if (bluetoothDevice.getAddress().compareTo(device.getAddress()) == 0) {
                        mConnectionState = STATE_CONNECTED;
                    }
                }
            }

            Log.w(TAG, "Connection state: " + mConnectionState);
            if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) {
                ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
                if (btDevice != null) {
                    mDeviceName = btDevice.name;
                    mDeviceAddress = btDevice.address;
                    if (mBluetoothAdapter.isEnabled() && mBluetoothAdapter.getRemoteDevice(mDeviceAddress) != null) {
                        connect(mDeviceAddress);
                        return;
                    }
                }
            } else if (mConnectionState == STATE_CONNECTED) { //WOOO, we are good to go, nothing to do here!
                Log.w(TAG, "Looks like we are already connected, going to read!");
                return;
            }
        }
    }
    setRetryTimer();
}
 
Example #18
Source File: DexShareCollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    Log.w(TAG, "Gatt state change status: " + status + " new state: " + newState);
    writeStatusConnectionFailures(status);
    if (status == 133) {
        Log.e(TAG, "Got the status 133 bug, GROSS!!");
    }
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        mBluetoothGatt = gatt;
        device = mBluetoothGatt.getDevice();
        mConnectionState = STATE_CONNECTED;
        ActiveBluetoothDevice.connected();
        Log.w(TAG, "Connected to GATT server.");

        Log.w(TAG, "discovering services");
        currentGattTask = GATT_SETUP;
        if (!mBluetoothGatt.discoverServices()) {
            Log.w(TAG, "discovering failed");
            if(shouldDisconnect) {
                stopSelf();
            } else {
                setRetryTimer();
            }
        }
    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        mConnectionState = STATE_DISCONNECTED;
        ActiveBluetoothDevice.disconnected();
        if(shouldDisconnect) {
            stopSelf();
        } else {
            setRetryTimer();
        }
        Log.w(TAG, "Disconnected from GATT server.");
    } else {
        Log.w(TAG, "Gatt callback... strange state.");
    }
}
 
Example #19
Source File: SystemStatus.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void set_current_values() {
    activeBluetoothDevice = ActiveBluetoothDevice.first();
    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    setCollectionMethod();
    setCurrentDevice();
    setConnectionStatus();
    setNotes();
}
 
Example #20
Source File: BluetoothScan.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Log.d(TAG, "Item Clicked");
    final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position);
    if (device == null) return;
    Toast.makeText(this, R.string.connecting_to_device, Toast.LENGTH_LONG).show();

    ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class)
            .orderBy("_ID desc")
            .executeSingle();
    if (btDevice == null) {
        ActiveBluetoothDevice newBtDevice = new ActiveBluetoothDevice();
        newBtDevice.name = device.getName();
        newBtDevice.address = device.getAddress();
        newBtDevice.save();
    } else {
        btDevice.name = device.getName();
        btDevice.address = device.getAddress();
        btDevice.save();
    }

    if (is_scanning) {
        bluetooth_adapter.stopLeScan(mLeScanCallback);
        is_scanning = false;
    }
    Intent intent = new Intent(this, Home.class);
    CollectionServiceStarter.newStart(getApplicationContext());
    startActivity(intent);
    finish();
}
 
Example #21
Source File: DexCollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    PowerManager powerManager = (PowerManager) mContext.getSystemService(POWER_SERVICE);
    PowerManager.WakeLock wakeLock2 = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
            "DexCollectionService");
    wakeLock2.acquire(45000);
    switch (newState) {
        case BluetoothProfile.STATE_CONNECTED:
            mConnectionState = STATE_CONNECTED;
            ActiveBluetoothDevice.connected();
            Log.i(TAG, "onConnectionStateChange: Connected to GATT server.");
            mBluetoothGatt.discoverServices();
            break;
        case BluetoothProfile.STATE_DISCONNECTED:
            mConnectionState = STATE_DISCONNECTED;
            ActiveBluetoothDevice.disconnected();
            if (mBluetoothGatt != null) {
                Log.i(TAG, "onConnectionStateChange: mBluetoothGatt is not null, closing.");
                mBluetoothGatt.close();
                mBluetoothGatt = null;
                mCharacteristic = null;
            }
            lastdata = null;
            Log.i(TAG, "onConnectionStateChange: Disconnected from GATT server.");
            setRetryTimer();
            break;
    }
}
 
Example #22
Source File: DexShareCollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    Log.i(TAG, "Gatt state change status: " + status + " new state: " + newState);
    if (status == 133) {
        Log.e(TAG, "Got the status 133 bug, bad news! Might require devices to forget each other");
    }
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        mBluetoothGatt = gatt;
        device = mBluetoothGatt.getDevice();
        mConnectionState = STATE_CONNECTED;
        ActiveBluetoothDevice.connected();
        Log.i(TAG, "Connected to GATT server.");

        Log.i(TAG, "discovering services");
        currentGattTask = GATT_SETUP;
        if (mBluetoothGatt == null || !mBluetoothGatt.discoverServices()) {
            Log.w(TAG, "discovering failed");
            if(shouldDisconnect) {
                stopSelf();
            } else {
                setRetryTimer();
            }
        }
    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        mConnectionState = STATE_DISCONNECTED;
        ActiveBluetoothDevice.disconnected();
        if(shouldDisconnect) {
            stopSelf();
        } else {
            setRetryTimer();
        }
        Log.d(TAG, "Disconnected from GATT server.");
    } else {
        Log.d(TAG, "Gatt callback... strange state.");
    }
}
 
Example #23
Source File: SystemStatus.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
private void set_current_values() {
    activeBluetoothDevice = ActiveBluetoothDevice.first();
    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    setVersionName();
    setCollectionMethod();
    setCurrentDevice();
    setConnectionStatus();
    setSensorStatus();
    setTransmitterStatus();
    setNotes();
    futureDataCheck();
}
 
Example #24
Source File: Home.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void updateCurrentBgInfoForBtShare(TextView notificationText) {
    if ((android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)) {
        notificationText.setText(R.string.unfortunately_andoird_version_no_blueooth_low_energy);
        return;
    }

    String receiverSn = Pref.getString("share_key", "SM00000000").toUpperCase();
    if (receiverSn.compareTo("SM00000000") == 0 || receiverSn.length() == 0) {
        notificationText.setText(R.string.please_set_dex_receiver_serial_number);
        return;
    }

    if (receiverSn.length() < 10) {
        notificationText.setText(R.string.double_check_dex_receiver_serial_number);
        return;
    }

    if (ActiveBluetoothDevice.first() == null) {
        notificationText.setText(R.string.now_pair_with_your_dexcom_share);
        return;
    }

    if (!Sensor.isActive()) {
        notificationText.setText(R.string.now_choose_start_sensor_in_settings);
        return;
    }

    displayCurrentInfo();
}
 
Example #25
Source File: Home.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void updateCurrentBgInfoForBtBasedWixel(DexCollectionType collector, TextView notificationText) {
    if ((android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)) {
        notificationText.setText(R.string.unfortunately_andoird_version_no_blueooth_low_energy);
        return;
    }

    if (ActiveBluetoothDevice.first() == null) {
        notificationText.setText(R.string.first_use_menu_to_scan);
        return;
    }
    updateCurrentBgInfoCommon(collector, notificationText);
}
 
Example #26
Source File: Blukon.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void unBondIfBlukonAtInit() {
    try {
        if (Blukon.expectingBlukonDevice() && Pref.getBooleanDefaultFalse("blukon_unbonding")) {
            final ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
            if (btDevice != null) {
                Log.d(TAG, "Unbonding blukon at initialization");
                JoH.unBond(btDevice.address);
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Got exception trying to unbond blukon at init");
    }
}
 
Example #27
Source File: Blukon.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static boolean expectingBlukonDevice() {
    try {
        final ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
        if (btDevice.name.startsWith("BLU")) return true;
    } catch (Exception e) {
        //
    }
    return false;
}
 
Example #28
Source File: DexCollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void handleDisconnectedStateChange() {
    if (JoH.ratelimit("handle-disconnected-state-change", 2)) {
        mConnectionState = STATE_DISCONNECTED;
        ActiveBluetoothDevice.disconnected();

        if (!getTrustAutoConnect()) {
            if (mBluetoothGatt != null) {
                UserError.Log.d(TAG, "Sending disconnection");
                try {
                    mBluetoothGatt.disconnect();
                } catch (Exception e) {
                    //
                }
            }
        }

        // TODO should we allow close when trusting auto-connect?
        if (prefs.getBoolean("close_gatt_on_ble_disconnect", true)) {
            if (mBluetoothGatt != null) {
                Log.i(TAG, "onConnectionStateChange: mBluetoothGatt is not null, closing.");
                if (JoH.ratelimit("refresh-gatt", 60)) {
                    Log.d(TAG, "Refresh result state close: " + JoH.refreshDeviceCache(TAG, mBluetoothGatt));
                }
                mBluetoothGatt.close();
                mBluetoothGatt = null;
                mCharacteristic = null;
                servicesDiscovered = DISCOVERED.NULL;
            } else {
                Log.d(TAG, "mBluetoothGatt is null so not closing");
            }
            lastdata = null;
        } else {
            UserError.Log.d(TAG, "Not closing gatt on bluetooth disconnect");
        }
        Log.i(TAG, "onConnectionStateChange: Disconnected from GATT server.");
        setRetryTimer();
    } else {
        UserError.Log.d(TAG, "Ignoring duplicate disconnected state change");
    }
}
 
Example #29
Source File: DexCollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void handleConnectedStateChange() {
    mConnectionState = STATE_CONNECTED;
    scanMeister.stop();
    if ((servicesDiscovered == DISCOVERED.NULL) || Pref.getBoolean("always_discover_services", true)) {
        Log.d(TAG, "Requesting to discover services: previous: " + servicesDiscovered);
        servicesDiscovered = DISCOVERED.PENDING;
    }
    ActiveBluetoothDevice.connected();

    if (JoH.ratelimit("attempt-connection", 30)) {
        checkConnection(); // refresh status info
    }
    if (servicesDiscovered != DISCOVERED.COMPLETE) {
        if (mBluetoothGatt != null) {
            if (JoH.ratelimit("dexcollect-discover-services", 1)) {
                Log.d(TAG, "Calling discoverServices");
                mBluetoothGatt.discoverServices();
            } else {
                Log.d(TAG, "Discover services duplicate blocked by rate limit");
            }

        } else {
            UserError.Log.d(TAG, "Wanted to discover services but gatt was null!");
        }
    } else {
        Log.d(TAG, "Services already discovered");
        checkImmediateSend();
    }

    if (mBluetoothGatt == null) {
        //gregorybel: no needs to continue if Gatt is null!
        UserError.Log.e(TAG, "gregorybel: force disconnect!");
        handleDisconnectedStateChange();
    }
}
 
Example #30
Source File: Blukon.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
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");
    }
}