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

The following examples show how to use com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice#disconnected() . These examples are extracted from open source projects. 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 Project: xDrip   File: ShareTest.java    License: 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
@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
@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 Project: xDrip   File: ShareTest.java    License: 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
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 6
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 7
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 8
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 9
@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
@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
@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
@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
@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
@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
@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
@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.");
    }
}