Code Monkey home page Code Monkey logo

ble-hid-peripheral-for-android's People

Contributors

kshoji avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ble-hid-peripheral-for-android's Issues

Pairing issues

Hi,

I built the app and trying to get it working between two Android devices.
Sadly the pairing doesn't work. When I'm in the BLE HID app (keyboard section) and want to pair it with another device, I confirm the Bluetooth security code on both devices and after few seconds, I'm again ask to confirm a different security code. With a different device, I get the message, that pairing is in progress but never finish.

The device with BLE HID app supports advertising as peripheral. Tested with following functions which are all returning true (according to https://stackoverflow.com/a/28768599):

bluetoothAdapter.isMultipleAdvertisementSupported();
bluetoothAdapter.isOffloadedFilteringSupported();
bluetoothAdapter.isOffloadedScanBatchingSupported();

The tested host devices (brand new Galaxy S8, laptop and another cheap tablet) are also supporting BLE.
Normal pairing between the devices is working. Any clue here?

Regards
Tjado

key entered are not getting displayed

I am able to connect my android device as input device via bluetooth also my connected device interpret it as keyboard but when i send key from my device it is not getting displayed.

Does the app still work?

Hello,

I was curious to know where the app still works today, especially on iOS.
I looked into it and I couldn't get the phone to recognize the absolute mouse.

Any thoughts?

App not working

I am using this app on Samsung Note 9 and connecting it to another android device. Even after both the devices are connected through bluetooth, the keyboard is not working.

Bluetooth Device auto disconnection

After successful pairing, when I start the BLE service ,the pairing auto disconnected. I tried it on multiple devices (Samsung, mi, oppo, motorola).

I am trying to connect phone(o.s- oreo and pie) to windows (windows 10) PC. Please help

nConnectionStateChange status: 0, newState: 0

Race condition in HidPeripheral.addService

According to Android doc BluetoothGattServer.addService:

The BluetoothGattServerCallback.onServiceAdded(int, BluetoothGattService) callback will indicate whether this service has been added successfully. Do not add another service before this callback.

The current codes in HidPeripheral.java break this promise and add several services in a row
without proper precautions. This results in race condition and failure adding services. The errors from logcat:

2019-01-16 15:21:18.859 26268-26268/me.dbw9580.apps.BridgeTooth D/BluetoothGattServer: registerCallback()
2019-01-16 15:21:18.859 26268-26268/me.dbw9580.apps.BridgeTooth D/BluetoothGattServer: registerCallback() - UUID=9f9ae403-ef94-4cfb-9925-4410ba150dff
2019-01-16 15:21:18.861 26268-26281/me.dbw9580.apps.BridgeTooth D/BluetoothGattServer: onServerRegistered() - status=0 serverIf=5
2019-01-16 15:21:18.861 26268-26268/me.dbw9580.apps.BridgeTooth D/BluetoothGattServer: addService() - service: 00001812-0000-1000-8000-00805f9b34fb
2019-01-16 15:21:18.869 26268-26268/me.dbw9580.apps.BridgeTooth D/HidPeripheral: Service: 00001812-0000-1000-8000-00805f9b34fb added.
2019-01-16 15:21:18.869 26268-26268/me.dbw9580.apps.BridgeTooth D/BluetoothGattServer: addService() - service: 0000180a-0000-1000-8000-00805f9b34fb
2019-01-16 15:21:18.871 26268-26281/me.dbw9580.apps.BridgeTooth D/BluetoothGattServer: onServiceAdded() - handle=40 uuid=00001812-0000-1000-8000-00805f9b34fb status=0
2019-01-16 15:21:18.871 26268-26268/me.dbw9580.apps.BridgeTooth D/HidPeripheral: Service: 0000180a-0000-1000-8000-00805f9b34fb added.
2019-01-16 15:21:18.871 26268-26268/me.dbw9580.apps.BridgeTooth D/BluetoothGattServer: addService() - service: 0000180f-0000-1000-8000-00805f9b34fb
2019-01-16 15:21:18.872 26268-26281/me.dbw9580.apps.BridgeTooth W/Binder: Caught a RuntimeException from the binder stub implementation.
    java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
        at java.util.ArrayList.get(ArrayList.java:437)
        at android.bluetooth.BluetoothGattServer$1.onServiceAdded(BluetoothGattServer.java:121)
        at android.bluetooth.IBluetoothGattServerCallback$Stub.onTransact(IBluetoothGattServerCallback.java:85)
        at android.os.Binder.execTransact(Binder.java:674)
2019-01-16 15:21:18.872 26268-26268/me.dbw9580.apps.BridgeTooth D/HidPeripheral: Service: 0000180f-0000-1000-8000-00805f9b34fb added.
2019-01-16 15:21:18.874 26268-26281/me.dbw9580.apps.BridgeTooth D/BluetoothGattServer: onServiceAdded() - handle=56 uuid=0000180a-0000-1000-8000-00805f9b34fb status=0
2019-01-16 15:21:18.874 26268-26268/me.dbw9580.apps.BridgeTooth D/BluetoothKeyboardService: onStartCommand: Intent { cmp=me.dbw9580.apps.BridgeTooth/.BluetoothKeyboardService }
2019-01-16 15:21:18.874 26268-29450/me.dbw9580.apps.BridgeTooth D/BluetoothKeyboardService: received intent: null
2019-01-16 15:21:18.875 26268-26281/me.dbw9580.apps.BridgeTooth W/Binder: Caught a RuntimeException from the binder stub implementation.
    java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
        at java.util.ArrayList.get(ArrayList.java:437)
        at android.bluetooth.BluetoothGattServer$1.onServiceAdded(BluetoothGattServer.java:121)
        at android.bluetooth.IBluetoothGattServerCallback$Stub.onTransact(IBluetoothGattServerCallback.java:85)
        at android.os.Binder.execTransact(Binder.java:674)
2019-01-16 15:21:18.877 26268-26268/me.dbw9580.apps.BridgeTooth W/Notification: Use of stream types is deprecated for operations other than volume control
2019-01-16 15:21:18.877 26268-26268/me.dbw9580.apps.BridgeTooth W/Notification: See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case
2019-01-16 15:21:18.881 26268-26281/me.dbw9580.apps.BridgeTooth D/BluetoothGattServer: onServiceAdded() - handle=63 uuid=0000180f-0000-1000-8000-00805f9b34fb status=0
2019-01-16 15:21:18.889 26268-26268/me.dbw9580.apps.BridgeTooth D/HidPeripheral: advertiseData: AdvertiseData [mServiceUuids=[0000180a-0000-1000-8000-00805f9b34fb, 00001812-0000-1000-8000-00805f9b34fb, 0000180f-0000-1000-8000-00805f9b34fb], mManufacturerSpecificData={}, mServiceData={}, mIncludeTxPowerLevel=false, mIncludeDeviceName=true], scanResult: AdvertiseData [mServiceUuids=[0000180a-0000-1000-8000-00805f9b34fb, 00001812-0000-1000-8000-00805f9b34fb, 0000180f-0000-1000-8000-00805f9b34fb], mManufacturerSpecificData={}, mServiceData={}, mIncludeTxPowerLevel=false, mIncludeDeviceName=false]
2019-01-16 15:21:18.891 26268-26268/me.dbw9580.apps.BridgeTooth D/BluetoothAdapter: isLeEnabled(): ON

I have created a pull request #10 that tries to solve this by using a local flag. I have tried mutex locks, but they only work when the shared object is accessed from two different threads. In our situation, it seems that the callback is executed on the same thread as the other codes, so they do not work. I am not aware of any better solution, though.

I have tested the fix in my own application on Android 8.0 on a Sony XZ1 Compact device, and it seems to be working fine.

Need BLUETOOTH PRIVILEGED permission

D/HidPeripheral: Need BLUETOOTH PRIVILEGED permission: Neither user 10152 nor current process has android.permission.BLUETOOTH_PRIVILEGED.
    java.lang.SecurityException: Need BLUETOOTH PRIVILEGED permission: Neither user 10152 nor current process has android.permission.BLUETOOTH_PRIVILEGED.
        at android.os.Parcel.readException(Parcel.java:1683)
        at android.os.Parcel.readException(Parcel.java:1636)
        at android.bluetooth.IBluetooth$Stub$Proxy.setPairingConfirmation(IBluetooth.java:1616)
        at android.bluetooth.BluetoothDevice.setPairingConfirmation(BluetoothDevice.java:1273)
        at jp.kshoji.blehid.HidPeripheral$5.onConnectionStateChange(HidPeripheral.java:609)
        at android.bluetooth.BluetoothGattServer$1.onServerConnectionState(BluetoothGattServer.java:105)
        at android.bluetooth.IBluetoothGattServerCallback$Stub.onTransact(IBluetoothGattServerCallback.java:82)
        at android.os.Binder.execTransact(Binder.java:570)

Android docs says 'Not for use by third-party applications.'
BLUETOOTH PRIVILEGED

How do I make it work?

Root required?

Trying to run this on unrooted Nexus 6, but doesn't seem to work. I see this error in logcat after pairing:

D/HidPeripheral: Need BLUETOOTH PRIVILEGED permission: Neither user 10102 nor current process has android.permission.BLUETOOTH_PRIVILEGED.
                                                                      java.lang.SecurityException: Need BLUETOOTH PRIVILEGED permission: Neither user 10102 nor current process has android.permission.BLUETOOTH_PRIVILEGED.
                                                                          at android.os.Parcel.readException(Parcel.java:1942)
                                                                          at android.os.Parcel.readException(Parcel.java:1888)
                                                                          at android.bluetooth.IBluetooth$Stub$Proxy.setPairingConfirmation(IBluetooth.java:1677)
                                                                          at android.bluetooth.BluetoothDevice.setPairingConfirmation(BluetoothDevice.java:1235)
                                                                          at jp.kshoji.blehid.HidPeripheral$4.onConnectionStateChange(HidPeripheral.java:581)
                                                                          at android.bluetooth.BluetoothGattServer$1.onServerConnectionState(BluetoothGattServer.java:93)
                                                                          at android.bluetooth.IBluetoothGattServerCallback$Stub.onTransact(IBluetoothGattServerCallback.java:70)
                                                                          at android.os.Binder.execTransact(Binder.java:674)

According to docs, BLUETOOTH_PRIVILEGED is not allowed for 3rd party apps.

Windows 10 disconnects BLE device

Hi, I know this project has not been tested on windows. I was trying to test it with Windows 10, I observed that HID Host initiates a disconnection soon after reading the 'HID information'!

08-20 12:53:45.109 30727-30740/jp.kshoji.blehid.sample D/HidPeripheral: onConnectionStateChange status: 0, newState: 2
08-20 12:53:45.112 30727-30740/jp.kshoji.blehid.sample D/HidPeripheral: BluetoothProfile.STATE_CONNECTED bondState: BOND_BONDED
08-20 12:53:45.117 30727-30740/jp.kshoji.blehid.sample D/HidPeripheral: Device bonded successfully
08-20 12:53:45.118 30727-30727/jp.kshoji.blehid.sample D/BluetoothGattServer: connect() - device: <>, auto: true
08-20 12:53:45.473 30727-30739/jp.kshoji.blehid.sample D/BluetoothGattServer: onMtuChanged() - device=<>, mtu=517
08-20 12:53:52.268 30727-30727/jp.kshoji.blehid.sample W/IInputConnectionWrapper: reportFullscreenMode on inexistent InputConnection
08-20 12:53:52.268 30727-30727/jp.kshoji.blehid.sample W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
08-20 12:54:01.998 30727-30727/jp.kshoji.blehid.sample I/HidPeripheral: onCharacteristicReadRequest characteristic: CHARACTERISTIC_MANUFACTURER_NAME , offset: 0
08-20 12:54:02.026 30727-30727/jp.kshoji.blehid.sample I/HidPeripheral: onCharacteristicReadRequest characteristic: CHARACTERISTIC_BATTERY_LEVEL , offset: 0
08-20 12:54:02.056 30727-30727/jp.kshoji.blehid.sample I/HidPeripheral: onCharacteristicReadRequest characteristic: CHARACTERISTIC_MODEL_NUMBER , offset: 0
08-20 12:54:02.161 30727-31071/jp.kshoji.blehid.sample D/HidPeripheral: onDescriptorReadRequest requestId: 7, offset: 0, descriptor: 00002902-0000-1000-8000-00805f9b34fb
08-20 12:54:02.284 30727-30727/jp.kshoji.blehid.sample I/HidPeripheral: onCharacteristicReadRequest characteristic: CHARACTERISTIC_MODEL_NUMBER , offset: 0
08-20 12:54:02.314 30727-30727/jp.kshoji.blehid.sample I/HidPeripheral: onCharacteristicReadRequest characteristic: CHARACTERISTIC_MANUFACTURER_NAME , offset: 0
08-20 12:54:02.435 30727-30727/jp.kshoji.blehid.sample I/HidPeripheral: onCharacteristicReadRequest characteristic: CHARACTERISTIC_REPORT , offset: 0
08-20 12:54:02.507 30727-30740/jp.kshoji.blehid.sample D/HidPeripheral: onDescriptorReadRequest requestId: 11, offset: 0, descriptor: 00002908-0000-1000-8000-00805f9b34fb
08-20 12:54:02.507 30727-30727/jp.kshoji.blehid.sample D/HidPeripheral: onDescriptorReadRequest: Read report reference for input report
08-20 12:54:02.537 30727-30727/jp.kshoji.blehid.sample I/HidPeripheral: onCharacteristicReadRequest characteristic: CHARACTERISTIC_REPORT , offset: 0
08-20 12:54:02.598 30727-31071/jp.kshoji.blehid.sample D/HidPeripheral: onDescriptorReadRequest requestId: 13, offset: 0, descriptor: 00002908-0000-1000-8000-00805f9b34fb
08-20 12:54:02.599 30727-30727/jp.kshoji.blehid.sample D/HidPeripheral: onDescriptorReadRequest: Read report reference for input report
08-20 12:54:02.628 30727-30740/jp.kshoji.blehid.sample D/HidPeripheral: onDescriptorReadRequest requestId: 14, offset: 0, descriptor: 00002902-0000-1000-8000-00805f9b34fb
08-20 12:54:02.674 30727-30727/jp.kshoji.blehid.sample I/HidPeripheral: onCharacteristicReadRequest characteristic: CHARACTERISTIC_PROTOCOL_MODE , offset: 0
08-20 12:54:02.704 30727-30727/jp.kshoji.blehid.sample I/HidPeripheral: onCharacteristicReadRequest characteristic: CHARACTERISTIC_REPORT_MAP , offset: 0
08-20 12:54:02.738 30727-30727/jp.kshoji.blehid.sample I/HidPeripheral: onCharacteristicReadRequest characteristic: CHARACTERISTIC_HID_INFORMATION , offset: 0
08-20 12:54:04.550 30727-30739/jp.kshoji.blehid.sample D/BluetoothGattServer: onServerConnectionState() - status=0 serverIf=6 device=<>
08-20 12:54:04.550 30727-30739/jp.kshoji.blehid.sample D/HidPeripheral: onConnectionStateChange status: 0, newState: 0
08-20 12:54:04.550 30727-30739/jp.kshoji.blehid.sample D/HidPeripheral: Device has been disconnected

I am stuck with this issue and unable to proceed. Let me know if you have any insight here.

Single Connection

Hi,

This is not an proper issue but it could be added feature if you can use single connection to use all input method i was wondering is it possible to do it since we have to send Characteristic.

If it is possible please let me know how to do it or any reference would be helpful.

Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.