Java Code Examples for com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice#connected()

The following examples show how to use com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice#connected() . 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 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 2
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 3
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 4
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 5
Source File: DexCollectionService.java    From xDrip 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 6
Source File: DexCollectionService.java    From xDrip 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 7
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 8
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 9
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 10
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 11
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 12
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 13
Source File: DexShareCollectionService.java    From xDrip with GNU General Public License v3.0 4 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) {
        statusErrors++;
        Log.e(TAG, "Got the status 133 bug, bad news! count:"+statusErrors+" - Might require devices to forget each other: instance uptime: "+JoH.qs((JoH.ts()-instance)/1000,0));
        if (statusErrors>4)
        {
            Log.wtf(TAG,"Forcing bluetooth reset to try to combat errors");
            statusErrors=0;
            JoH.niceRestartBluetooth(getApplicationContext());
            setRetryTimer();
            close();
            stopSelf();
            return;
        }
    }
    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 14
Source File: DexShareCollectionService.java    From xDrip with GNU General Public License v3.0 4 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) {
        statusErrors++;
        Log.e(TAG, "Got the status 133 bug, bad news! count:"+statusErrors+" - Might require devices to forget each other: instance uptime: "+JoH.qs((JoH.ts()-instance)/1000,0));
        if (statusErrors>4)
        {
            Log.wtf(TAG,"Forcing bluetooth reset to try to combat errors");
            statusErrors=0;
            JoH.niceRestartBluetooth(getApplicationContext());
            setRetryTimer();
            close();
            stopSelf();
            return;
        }
    }
    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 15
Source File: DexShareCollectionService.java    From xDrip-plus with GNU General Public License v3.0 4 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) {
        statusErrors++;
        Log.e(TAG, "Got the status 133 bug, bad news! count:"+statusErrors+" - Might require devices to forget each other: instance uptime: "+JoH.qs((JoH.ts()-instance)/1000,0));
        if (statusErrors>4)
        {
            Log.wtf(TAG,"Forcing bluetooth reset to try to combat errors");
            statusErrors=0;
            JoH.niceRestartBluetooth(getApplicationContext());
            setRetryTimer();
            close();
            stopSelf();
            return;
        }
    }
    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 16
Source File: DexShareCollectionService.java    From xDrip-plus with GNU General Public License v3.0 4 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) {
        statusErrors++;
        Log.e(TAG, "Got the status 133 bug, bad news! count:"+statusErrors+" - Might require devices to forget each other: instance uptime: "+JoH.qs((JoH.ts()-instance)/1000,0));
        if (statusErrors>4)
        {
            Log.wtf(TAG,"Forcing bluetooth reset to try to combat errors");
            statusErrors=0;
            JoH.niceRestartBluetooth(getApplicationContext());
            setRetryTimer();
            close();
            stopSelf();
            return;
        }
    }
    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.");
    }
}