Example usage for android.bluetooth BluetoothGatt GATT_INSUFFICIENT_AUTHENTICATION

List of usage examples for android.bluetooth BluetoothGatt GATT_INSUFFICIENT_AUTHENTICATION

Introduction

In this page you can find the example usage for android.bluetooth BluetoothGatt GATT_INSUFFICIENT_AUTHENTICATION.

Prototype

int GATT_INSUFFICIENT_AUTHENTICATION

To view the source code for android.bluetooth BluetoothGatt GATT_INSUFFICIENT_AUTHENTICATION.

Click Source Link

Document

Insufficient authentication for a given operation

Usage

From source file:Main.java

public static String getGattStatus(int status) {
    switch (status) {
    case BluetoothGatt.GATT_SUCCESS:
        return "GATT_SUCCESS";

    case BluetoothGatt.GATT_READ_NOT_PERMITTED:
        return "GATT_READ_NOT_PERMITTED";

    case BluetoothGatt.GATT_WRITE_NOT_PERMITTED:
        return "GATT_WRITE_NOT_PERMITTED";

    case BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION:
        return "GATT_INSUFFICIENT_AUTHENTICATION";

    case BluetoothGatt.GATT_REQUEST_NOT_SUPPORTED:
        return "GATT_REQUEST_NOT_SUPPORTED";

    case BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION:
        return "GATT_INSUFFICIENT_ENCRYPTION";

    case BluetoothGatt.GATT_INVALID_OFFSET:
        return "GATT_INVALID_OFFSET";

    case BluetoothGatt.GATT_INVALID_ATTRIBUTE_LENGTH:
        return "GATT_INVALID_ATTRIBUTE_LENGTH";

    case BluetoothGatt.GATT_FAILURE:
        return "GATT_FAILURE";

    default://from w  ww  .  j a  v a  2  s  .c  om
        return "STATE_UNKNOWN: " + status;
    }
}

From source file:Main.java

public static String gattStatusString(int status) {
    switch (status) {
    case BluetoothGatt.GATT_CONNECTION_CONGESTED:
        return "Connection congested";
    case BluetoothGatt.GATT_FAILURE:
        return "Failure";
    case BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION:
        return "Insufficient authentication";
    case BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION:
        return "Insufficient encryption";
    case BluetoothGatt.GATT_INVALID_ATTRIBUTE_LENGTH:
        return "Invalid attribute length";
    case BluetoothGatt.GATT_INVALID_OFFSET:
        return "Invalid offset";
    case BluetoothGatt.GATT_READ_NOT_PERMITTED:
        return "Read not permitted";
    case BluetoothGatt.GATT_REQUEST_NOT_SUPPORTED:
        return "Request not supported";
    case BluetoothGatt.GATT_WRITE_NOT_PERMITTED:
        return "Write not permitted";
    default:/*  w w w.  jav a2s  .co m*/
        return "GATT error with unknown status code: " + status;
    }
}

From source file:Main.java

public static String gattStatusToString(int status) {
    String str = "";
    switch (status) {
    case BluetoothGatt.GATT_SUCCESS:
        str = "GATT_SUCCESS";
        break;/*from   w w w .ja  va 2s .c  o  m*/
    case BluetoothGatt.GATT_READ_NOT_PERMITTED:
        str = "GATT_READ_NOT_PERMITTED";
        break;
    case BluetoothGatt.GATT_WRITE_NOT_PERMITTED:
        str = "GATT_WRITE_NOT_PERMITTED";
        break;
    case BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION:
        str = "GATT_INSUFFICIENT_AUTHENTICATION";
        break;
    case BluetoothGatt.GATT_REQUEST_NOT_SUPPORTED:
        str = "GATT_REQUEST_NOT_SUPPORTED";
        break;
    case BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION:
        str = "GATT_INSUFFICIENT_ENCRYPTION";
        break;
    case BluetoothGatt.GATT_INVALID_OFFSET:
        str = "GATT_INVALID_OFFSET";
        break;
    case BluetoothGatt.GATT_INVALID_ATTRIBUTE_LENGTH:
        str = "GATT_INVALID_ATTRIBUTE_LENGTH";
        break;
    case BluetoothGatt.GATT_CONNECTION_CONGESTED:
        str = "GATT_CONNECTION_CONGESTED";
        break;
    case BluetoothGatt.GATT_FAILURE:
        str = "GATT_FAILURE";
        break;
    }

    return str;
}

From source file:com.wolkabout.hexiwear.service.BluetoothService.java

private void createGATT(final BluetoothDevice device) {
    bluetoothGatt = device.connectGatt(this, true, new BluetoothGattCallback() {
        @Override/*  w  w w  .j  a v a 2s .co m*/
        public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
            isConnected = BluetoothProfile.STATE_CONNECTED == newState;
            if (isConnected) {
                Log.i(TAG, "GATT connected.");
                startForeground(442, getNotification(device));
                gatt.discoverServices();
            } else {
                Log.i(TAG, "GATT disconnected.");
                NotificationService_.intent(BluetoothService.this).stop();
                notificationManager.notify(442, getNotification(device));
                gatt.connect();
            }

            final Intent connectionStateChanged = new Intent(CONNECTION_STATE_CHANGED);
            connectionStateChanged.putExtra(CONNECTION_STATE, isConnected);
            sendBroadcast(connectionStateChanged);
        }

        @Override
        public void onServicesDiscovered(BluetoothGatt gatt, int status) {
            Log.i(TAG, "Services discovered.");
            if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
                handleAuthenticationError(gatt);
                return;
            }

            discoverCharacteristics(gatt);
        }

        @Override
        public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
                int status) {
            Log.i(TAG, "Characteristic written: " + status);

            if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
                handleAuthenticationError(gatt);
                return;
            }

            final byte command = characteristic.getValue()[0];
            switch (command) {
            case WRITE_TIME:
                Log.i(TAG, "Time written.");
                final BluetoothGattCharacteristic batteryCharacteristic = readableCharacteristics
                        .get(Characteristic.BATTERY.getUuid());
                gatt.setCharacteristicNotification(batteryCharacteristic, true);
                for (BluetoothGattDescriptor descriptor : batteryCharacteristic.getDescriptors()) {
                    if (descriptor.getUuid().toString().startsWith("00002904")) {
                        descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
                        gatt.writeDescriptor(descriptor);
                    }
                }
                break;
            case WRITE_NOTIFICATION:
                Log.i(TAG, "Notification sent.");
                if (notificationsQueue.isEmpty()) {
                    Log.i(TAG, "Reading characteristics...");
                    readNextCharacteristics(gatt);
                } else {
                    Log.i(TAG, "writing next notification...");
                    alertIn.setValue(notificationsQueue.poll());
                    gatt.writeCharacteristic(alertIn);
                }
                break;
            default:
                Log.w(TAG, "No such ALERT IN command: " + command);
                break;
            }
        }

        @Override
        public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
            readCharacteristic(gatt, Characteristic.MANUFACTURER);
        }

        @Override
        public void onCharacteristicRead(BluetoothGatt gatt,
                final BluetoothGattCharacteristic gattCharacteristic, int status) {
            if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
                handleAuthenticationError(gatt);
                return;
            }

            final String characteristicUuid = gattCharacteristic.getUuid().toString();
            final Characteristic characteristic = Characteristic.byUuid(characteristicUuid);
            switch (characteristic) {
            case MANUFACTURER:
                manufacturerInfo.manufacturer = gattCharacteristic.getStringValue(0);
                readCharacteristic(gatt, Characteristic.FW_REVISION);
                break;
            case FW_REVISION:
                manufacturerInfo.firmwareRevision = gattCharacteristic.getStringValue(0);
                readCharacteristic(gatt, Characteristic.MODE);
                break;
            default:
                Log.v(TAG, "Characteristic read: " + characteristic.name());
                if (characteristic == Characteristic.MODE) {
                    final Mode newMode = Mode.bySymbol(gattCharacteristic.getValue()[0]);
                    if (mode != newMode) {
                        onModeChanged(newMode);
                    }
                } else {
                    onBluetoothDataReceived(characteristic, gattCharacteristic.getValue());
                }

                if (notificationsQueue.isEmpty()) {
                    readNextCharacteristics(gatt);
                } else {
                    alertIn.setValue(notificationsQueue.poll());
                    gatt.writeCharacteristic(alertIn);
                }

                break;
            }
        }

        @Override
        public void onCharacteristicChanged(BluetoothGatt gatt,
                BluetoothGattCharacteristic gattCharacteristic) {
            final String characteristicUuid = gattCharacteristic.getUuid().toString();
            final Characteristic characteristic = Characteristic.byUuid(characteristicUuid);
            Log.d(TAG, "Characteristic changed: " + characteristic);

            if (characteristic == Characteristic.BATTERY) {
                onBluetoothDataReceived(Characteristic.BATTERY, gattCharacteristic.getValue());
            }
        }
    });
}

From source file:org.deviceconnect.android.deviceplugin.health.fragment.HealthCareDeviceSettingsFragment.java

/**
 * Display the error dialog.//from w  w  w.  j ava2s  .c  om
 * @param name device name
 * @param status error reason.
 */
private void showErrorDialog(String name, final int status) {
    dismissErrorDialog();

    Resources res = getActivity().getResources();
    String title = res.getString(R.string.heart_rate_setting_dialog_error_title);
    if (name == null) {
        name = getString(R.string.heart_rate_setting_default_name);
    }
    String message;
    if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
        message = res.getString(R.string.heart_rate_setting_dialog_need_auth, name);
    } else {
        message = res.getString(R.string.heart_rate_setting_dialog_error_message, name);
    }
    mErrorDialogFragment = ErrorDialogFragment.newInstance(title, message);
    mErrorDialogFragment.show(getFragmentManager(), "error_dialog");
    mErrorDialogFragment.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            mErrorDialogFragment = null;
        }
    });
}