keymapperorg / KeyMapper

An Android app that change what the buttons do on your devices!
http://docs.keymapper.club
GNU General Public License v3.0
1.28k stars 166 forks source link

Add Shizuku support to monitor key events instead of accessibility service #469

Closed thetoolz closed 3 years ago

thetoolz commented 4 years ago

Shizuku Let your app use system APIs directly https://shizuku.rikka.app/ https://github.com/RikkaApps/Shizuku

Use system APIs elegantly Forget about root shell, you can use APIs with higher privileges "directly". Also, Shizuku is significantly faster than shell.

Support adb usage If your "root required app" only needs adb permission, you can easily expand the audience by using Shizuku.

use Shizuku to avoid using Accessibility Service.

Apps using Shizuku https://shizuku.rikka.app/apps.html

Developer guide https://github.com/RikkaApps/Shizuku/blob/master/README.md

useful for Fire tv since update 6.2.7.3 Accessibility Services Stopped working

Start Shizuku on Fire TV / Android TV adb debugging enable in settings on tv (Only available on tv)

usb debugging pop up will show up to allow Running of adb command

will only work on fire tv /android tv

adb shell sh /data/user_de/0/moe.shizuku.privileged.api/start.sh

Option to run adb shell command tasker & tasker adb shell plugin

sds100 commented 4 years ago

So Fire TV doesn't support accessibility services at all? Key Mapper can turn on the accessibility service itself if it is given WRITE_SECURE_SETTINGS permission.

thetoolz commented 4 years ago

@sds100 yes no accessibility

sds100 commented 4 years ago

oh, okay.

sds100 commented 4 years ago

Do you know if shizuku can detect keyevents?

thetoolz commented 4 years ago

@sds100 I'm guessing yes as long as android api on Device supports key events

sds100 commented 4 years ago

If the user reboots a non-rooted device do they have to setup Shizuku again through adb?

sds100 commented 4 years ago

oh, okay. I don't understand, if Tasker can perform the command to start Shizuku why can't Shizuku? I still don't quite understand how Shizuku works.

thetoolz commented 4 years ago

@sds100 The developer has not added fire tv support most android devices don't have adb debugging only android TV's

Is not optimized for tv & not originally made for tv

sds100 commented 4 years ago

what do you mean by adb debugging? You can use ADB over USB on all devices so I'm guessing you're referring to something else. I'm trying to figure out how this all works permission-wise because you said that you can start Shizuku with Tasker after rebooting. I'm going to have a play with Shizuku now.

sds100 commented 4 years ago

Ohh, okay

sds100 commented 4 years ago

So you can use ADB wireless out of the box on Android TV as described in this article? https://www.androidpolice.com/2020/09/05/how-to-sideload-any-application-on-android-tv/ If that is so then I'm guessing those apps just connect to the TV over the network? If so, that is pretty cool and opens a world of opportunities. This all makes sense now. Thank you for clarifying. šŸ˜„

sds100 commented 4 years ago

Ooops, i edited you comment, sorry. Yeah, so Android TV older than Android 11 doesn't support ADB wireless? I was under the impression that it did from what you were saying.

sds100 commented 4 years ago

What im asking is, on older Android TV versions how did you use ADB? Android TV's dont have a USB port that you can plug into a PC and then use ADB.

thetoolz commented 4 years ago

@sds100 read this article about adb debugging

How to enable ADB debugging on an Amazon Fire TV or Fire TV Stick https://www.aftvnews.com/how-to-enable-adb-debugging-on-an-amazon-fire-tv-or-fire-tv-stick/#:~:text=From%20the%20Fire%20TV%20or%20Fire%20TV%20Stick%E2%80%99s,%E2%80%9CADB%20debugging%E2%80%9D%20to%20turn%20the%20option%20to%20%E2%80%9CON%E2%80%9D.

sds100 commented 4 years ago

Oh, thank you so much! Everything makes much more sense now. Sorry, I didn't realise it was a completely separate Fire TV specific feature.

zacharee commented 3 years ago

I made a fork of the develop branch with basic Shizuku support. It still needs the Accessibility service, but keys that would normally require the IME service now go through Shizuku. Right now, you have to grant the Shizuku permission from the intro slider.

https://github.com/zacharee/KeyMapper/tree/develop

keymapper-2.3.0-alpha-debug.apk.zip (Remove the extra .zip extension).

sds100 commented 3 years ago

@zacharee wow, thank you! the code looks fine but there are some things that I'd like you to change. could you create a pull request please?

zacharee commented 3 years ago

https://github.com/sds100/KeyMapper/pull/585

sds100 commented 3 years ago

@thetoolz i dont how to use shizuku to detect key events. I don't think it is possible because the Shell app on the device doesn't have permission to monitor input events. I wish it could... because that would open the doors to many amazing features.

zacharee commented 3 years ago

You can monitor KeyEvents at least without an AccessibilityService by hijacking the UiAutomation stuff. It needs Shizuku, but you can use UiAutomationConnection and your own client implementation. UiAutomation has an example implementation of the needed IAccessibilityServiceClient.

I don't know if it's possible to implement all this purely through reflection, though.

sds100 commented 3 years ago

can you capture input events even if the input events are being sent to other apps?

zacharee commented 3 years ago

It's basically creating a pseudo Accessibility Service, so it receives whatever those receive.

sds100 commented 3 years ago

do you know how to code it?

sds100 commented 3 years ago

This solution wouldn't work for the original poster because UI automation seems to use the accessibility service API. the Fire TV doesn't have the accessibility APIs apparently. It also doesn't seem to be able to monitor the raw input events from the user. Accessibility services are only told about information about the thing the user has interacted with and not the raw motion events. I would love to be wrong šŸ˜„

sds100 commented 3 years ago

There isn't a way to monitor input events without using an accessibility service because the android.Manifest.permission.MONITOR_INPUT permission can't be granted to apps. I'm working on Shizuku support in Key Mapper for other things like automatically granting WRITE_SECURE_SETTINGS permission and inputting key events. I will create a separate issue for this.