Kontroller icon indicating copy to clipboard operation
Kontroller copied to clipboard

Crashes (NoSuchMethodException for hidden APIs) on Android 11

Open Volatile-Memory opened this issue 4 years ago • 5 comments

https://github.com/raghavk92/Kontroller/blob/5353b83bbc919d5822792f66f12bf6bff77f8f8c/app/src/main/java/com/github/roarappstudio/btkontroller/Unhide.kt#L6

NoSuchMethodException

Volatile-Memory avatar Sep 08 '20 19:09 Volatile-Memory

@rostopira any idea why this is happening? ......I don't have a android 11 device currently at my place.

raghavk92 avatar Nov 29 '20 11:11 raghavk92

I have a Pixel 2 with Android 11 and can confirm the bug. From analyzing source code the exception is thrown in BluetoothController.onServiceConnected. So I guess, it's from the overall architecture, that devices must be paired within the app. @raghavk92 Why did you architect it that way? Why can't I use a device paired formerly via default Android bluetooth mechanism? Using already paired devices might make this method call redundant.

Please excuse, if I'm wrong. That's just results from looking 5 minutes at the code. But I'm really interested in using the app and might also work on it.

AchimStuy avatar Jan 23 '21 22:01 AchimStuy

@AchimStuy you are right, devices must be paired within in App. @Computr0n : to solve this issue on Android 11, you should check your Bluetooth is discovering or not. If not, start discover it and you can use normally. Dont you setScanMode (it's deprecated and removed from Android 11)

 if(!btAdapter.isDiscovering){
                context.startActivity(Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE))            
}

cuongnv avatar Jan 27 '21 04:01 cuongnv

@AchimStuy I didnt work on this part of the code. Its a collaborative project between me and rostopira. I think this part of the code was written by rostopira . @rostopira Could you see if you can rectify this issue. I am a bit busy this month so won't be able to work on this . If I am able to next month and I get a bit free I can take a look at that part of the code.

@cuongnv Are you trying to say that the paring should not happen within app? It should happen in the settings app because the sets a mode function is deprecated in Android 11? Just wanted to confirm this.

@AchimStuy If you are interested in working on this app and have the google Pixel as you mentioned you are welcome to correct this issue but just check that your new changes didn't break functionality on android 9 and 10 devices. I don't have a Android 11 device yet so that is also an issue. I'll see if I can get hands-on an Android 11 device.

raghavk92 avatar Feb 02 '21 22:02 raghavk92

So I investigated a little bit on the issue:

Pairing must be done within the app, because we need the HID-Profile added to the Android device's Bluetooth class. This is done in BluetoothHidDevice.registerApp. But (citing from the docs) "the app will be automatically unregistered if it is not foreground." So we lose the HID profile as soon as the user switches to the settings app to pair his device.

The NoSuchMethodException could be fixed by calling BluetoothAdapter.startDiscovery. Then I get some IndexOutOfBoundsExceptions in BluetoothController, lines 153 and 164, because I have no paired devices yet.

How can I pair devices within the app?

AchimStuy avatar Feb 06 '21 13:02 AchimStuy