- Android Labs: Bluetooth HID device implementation (your phone as a mouse + voice control)
- Why is this different?
- Introduction
- Work done so far
- Future scope
- How can i use the Bluetooth HID Device profile in Android Pie?
- 3 Answers 3
- Saved searches
- Use saved searches to filter your results more quickly
- License
- ralismark/bluehid
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
Android Labs: Bluetooth HID device implementation (your phone as a mouse + voice control)
Android Labs is an internal activity within the HSC Connected Devices CoE where our amazing engineers implement proof of concept solutions showcasing our depth in the Android and Linux software stacks.
In this edition of Android Labs we bring you an innovative implementation of Android HID device specification for Bluetooth that allows your Android phone to be used as a standard BT mouse. We also added keyboard control and voice control to boot.
Remember to take a look at our demo video below! HSC may release the changes as part of its Open Source initiative in the near future. Please keep a tab on our Open Source page.
Why is this different?
There are many applications (like RemoteDroid and others) that have allowed a phone to act as a mouse for a few years. These solutions are typically implemented over WiFi (you need both PC and phone to be connected over WiFi) and comprise of a ‘server’ process installed on the PC and a client on the smartphone. In other words, this is a client-server model that needs special software on the PC. By implementing the BT HID device profile, your phone actually shows up as a standard BT mouse and requires no additional functionality.
Introduction
The purpose of this activity is to enable an Android device to be used as a Bluetooth peripheral device, such as a mouse, keyboard, remote control, gamepad etc. The android device can then be used to control devices like phones, computers, TV, PS3 etc., over Bluetooth. To act as a Bluetooth HID device, the android Bluetooth stack needs to support HID device role of the Bluetooth HID profile. The current implementation of HID in blue droid supports HID host role only. This activity implements HID device role in bludroid.
Work done so far
HID device role has been implemented in bluedroid using classic bluetooth. The current usecase allows the android device to act as a mouse and keyboard combo device. To support other use cases like remote control and gamepad, the changes will be required in HID report descriptor. The support of HID device role is being controlled through a compile time flag as of now. Some minor changes have been done in android framework and bluetooth system app to send input reports(mouse positions, key presses etc.) from a third party application. This implementation has been tested on a Nexus5 device connecting with windows as well as linux machines and a few smart phones supporting HID host role. A test application has been developed which provides a touch panel to send mouse cursor positions and two buttons to send left click and right click. For keyboard layout, the soft keyboard has been used which is available to all the android applications. The HID keyboard implementation has also been used to implement voice control of PC from Android device. For this purpose, the speech recognition feature of Android has been used which uses Google engine’s voice search functionality. Offline speech recognition is also available however it is not that accurate when compared to online voice recognition. Some of the popular commands are available from voice control for Windows such as lock, unlock, reboot, shutdown, sleep etc. Apart from this, the individual key combinations can also be sent by speaking the actual keys such as “control alt delete” will send CTRL+ALT+DELETE key combination.
Future scope
HID device implementation should be modified in such as way that the HID profile role in bluedroid can be switched at run time based on a configuration. An application containing a master keyboard layout like keyboards for PC(containing CTRL, ALT, ESC and function keys) needs to be developed to provide full control. Mouse implementation can be extended as well to include scroll wheel using some touch gesture. The support for other HID devices can also be included such as gamepad, remote control, touchpad etc. Support for receiving output reports and feature reports needs to be implemented in the bluetooth stack for completeness of HID device role. The implementation can also be extended to support boot protocol mode of HID profile. Moreover, this work can also become the basis for implementing device role in HOGP (HID over GATT) profile over BLE.
(Note: This video has text annotation overlays which may not show up on a mobile device)
(Do you find this article interesting? You may want to check out our Embedded Android pages to read more about what we do in this space.)
How can i use the Bluetooth HID Device profile in Android Pie?
I am trying to write an app for Android P using the Bluetooth HID device profile service to be used as a Bluetooth keyboard. According to the documentation I am supposed to use the method BluetoothAdapter.getProfileProxy(Context, BluetoothProfile.ServiceListener, int) to get the BluetoothHidDevice proxy object. During debug on my Android Pie device (Nokia 7 plus) the service listener never get called ( onServiceConnected ), and i get the following error in Logcat:
Could not bind to Bluetooth HID Device Service with Intent
- Has anyone created a working HID_DEVICE on Android Pie?
- Can BluetoothHidDevice be used to create a hid-device on an Android Pie phone?
- Is there any working code that i can look at?
- Is there some feature ( getPackageManager().hasSystemFeature ) missing in my phone?
- What could be the reason for the error above?
Any hints would be greatly appreciated 🙂
This seems to be a third-party issue. Nokia did not enable the hid-profile in Android Pie. I also tried with a Mototorola G7 play, it was also disabled, i guess it’s time for a pixel.
I’ve tried messing around with this with Xposed on Oreo 8.1 (since it’s implemented but disabled and hidden), and I also encountered this issue. For me, it was because the service was disabled in the manifest ( android:enabled=»@bool/profile_supported_hidd» and the bool set to false). I fixed it with setComponentEnabledSetting
I’d really also like to know if using Android as HID device works in Android Pie.. I’d like to use my Pixel 2XL as a game controller programmatically
I will also put this here.. maybe someone can reach out to author directly to see if he can help provide an answer xda-developers.com/android-p-bluetooth-keyboard-mouse
@Kim I am also working on making an app for using android as bluetooth keyboard on android pie. If you’d like we can work on this together.I ll let you know if i get any headway on this issue.
As per the google issue tracker this may be a third party issue. I can confirm that on a OnePlus 6 / OxygenOS 9.0.4 the HID device service is still disabled just like the @ralismark’s description for Oreo. 🙁
3 Answers 3
Currently on pixel the HID device Profile is enabled . Nokia, moto(as mentioned above) and One Plus 5T and 6 as far as i know dont support this profile.
We have created an app which lets you use your phone as a bluetooth mouse and keyboard with this HID device profile. https://play.google.com/store/apps/details?id=com.github.roarappstudio.btkontroller
The code is open sourced at https://github.com/raghavk92/Kontroller. If anyone wants to help in making improvements or contribute to the code they are welcome.
You can also check if your phone supports Bluetooth HID device profile with the app — https://play.google.com/store/apps/details?id=com.rkaneapplabs.bluetooth_hid.bluetoothproxy and let your device manufacturer know if they dont support your device because its part of android pie and should be supported.
List of devices that have the Bluetooth HID device profile activated/Not Working(due to manufacturer implementation bugs) is here — https://github.com/raghavk92/Android_Bluetooth_HID_Device_Profile_CompatibilityList
The bugs are due to implementation on the manufacturer’s side not google as pixel devices support this Bluetooth HID device profile since android pie
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Bluetooth HID device for Android Oreo (proof of concept)
License
ralismark/bluehid
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Bluetooth HID game controller for Android Oreo. Requires Xposed, but no host-side software needed!
This is a proof of concept, so, even though it’s mostly usable at its current stage, it has many rough edges. This can also be taken as an example on how to use the BluetoothHidDevice API, as Oreo has this functionality already implemented, but with slight differences.
See my blog posts for a more detailed explanation, starting from part 1.
This project is set up for Android Oreo (specifically API level 27 — version 8.1), but you will need to to use the android.jar from anggrayudi/android-hidden-api as this app uses hidden API. You will also need Xposed (minimum version 83) on your phone to run this.
Android P has official support for this through BluetoothHidDevice. The hidden Oreo API that is used here is very similar, but with a few differences (most notably, BluetoothHidDevice was named BluetoothInputHost in O), so it’s possible to make this app support it with a few changes.
As described above, you need to replace your API 27 android.jar with one that exposes hidden API. After that, you can open this in Android Studio and build it as you normally would.
If you haven’t paired with the host device, you need to do so first.
To connect, open the app (enabling Bluetooth if prompted), press on (disconnected) and select the host device. The status should change to Connecting , then Connected (Note that Connecting may not be visible for long). After this, you should be able to use the app as a controller.
This project uses controlwear/virtual-joystick-android, which is available under the Apache 2.0 License. A copy can be obtained from LICENSE file in that repository, or from http://www.apache.org/licenses/LICENSE-2.0.
Copyright 2019 ralismark Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
About
Bluetooth HID device for Android Oreo (proof of concept)