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.13k stars 156 forks source link

Assistant Button Detection (LG Devices) #497

Open ksaerdna opened 4 years ago

ksaerdna commented 4 years ago

Currently the respective hardware key of LG devices is not handled by KeyMapper. However, there is a paid app that can, so it is technically possible. Possibly the solution is the same as with Samsung's pendant.

sds100 commented 4 years ago

Hello, do you have any idea how the other app does it? I don't have any LG devices or any device with an Assistant button so I have no idea how to approach the problem. There usually isn't an answer or documentation online about the "hacky" solution.

ksaerdna commented 4 years ago

If I had had any idea how to technically solve it, I would have told you. :-) I also checked if the source code of the mentioned application is available, but unfortunately it is not. In its basic, free functionality the LG or Samsung button cannot be mapped, for this one needs some kind of in-app purchase.

BTW: All applications I wrote so far for Android are open source, so my intention for this "issue" was not primarily to save a litte amount of money...

sds100 commented 4 years ago

Yeah. Which app is this? With the Bixby button remapping apps the phone throws an error in the logcat whenever the Bixby button is pressed and the Bixby package is disabled. The user must grant the app permission to read logs through ADB for the feature to work. Can you see if the LG button shows an error in the logcat?

ksaerdna commented 4 years ago

I hesitated to place any advertisement, but the application is called Button Mapper. Basically it seems to do the same as yours, with the same Android permissions.

LG has three settings regarding the "Assistant Button":

The logcat shows with deactivated Assistant Button:

HotKeyController: launch Assist: 1 turned off

and with a longpress on lockscreen:

D HotKeyController: AI long action not support : Lockscreen and non-interactive status

and with longpress not on lockscreen, Google configured as Assistant-App:

D HotKeyController: launch Assist: 3 turned off D HotKeyController: currentAssistComponent : com.google.android.voiceinteraction.GsaVoiceInteractionService D HotKeyController: received HOTKEY_RELEASE_AFTER_LONG_PRESS: duration=2897 D HotKeyController: launch Assist: 4 turned off

and longpress without "Assistant-App" configured

D HotKeyController: launch Assist: 3 turned off D HotKeyController: currentAssistComponent :

sds100 commented 4 years ago

Is there a setup process in the app specific to remapping the Assistant button or does it detect it "out of the box"?

sds100 commented 4 years ago

Are there log messages for short presses?

ksaerdna commented 4 years ago

Is there a setup process in the app specific to remapping the Assistant button or does it detect it "out of the box"?

I cannot know because I did not follow the in-app purchase request, but as far as I read from users' reports it works "out of the box".

Are there log messages for short presses?

The first log message I mentioned (Assist 1) resulted from a short press. The message is the same, during or without lockscreen. Note that there is ridiculous flood of stupid messages, and finally I used "grep HotKeyController" for filtering.

sds100 commented 4 years ago

If the app detects the button press by filtering the logcat then it can't work out of the box because an app needs a permission that can only be granted through the shell. Can you find a youtube video or something that can show how it is set up? It isn't a huge deal because the logging information that you gave me is enough to detect when it is pressed.

Was the button "deactivated" for all of those logcat messages? When the button is "deactivated" does it not do anything on the device when you press it? This is important because Key Mapper will not be able to remap the button but can detect when it is supposedly pressed and then do something, assuming that nothing else is happening on the device to interfere with the action.

sds100 commented 4 years ago

This button won't have the same amount of flexibility as normal triggers because I can't detect when it is pressed down and then up. Do those logcat messages show up after you release the button? These logcat messages seem more trivial to interpret than the Bixby ones, which is a good thing.

ksaerdna commented 4 years ago

The command for the mentioned application seems to be:

adb shell pm grant flar2.homebutton android.permission.READ_LOGS

as I saw in the respective xda thread (https://forum.xda-developers.com/android/apps-games/app-button-mapper-customize-hardware-t3361340). There are more "pm grant" commands mentioned, like WRITE_SECURE_SETTINGS and others.

The button was deactivated for all my log tests, both press and longpress. The LG UI is inconsistent. One cannot activate or deactivate the button while the "Assistent App" is "None", but on on the other hand one can change it to "Google", then activate the button, and then set the App again to "None".

On LG: The HotKeyController messages appear in this context:

D InputReader: Key event: device=6 type=0x0001 value=0x00000000 when=121391700184000 D WindowManager: interceptKeyTq keycode=165 down=false injected=false mDisplayState=2 interactive=true keyguardActive=false flags=0x8 policyFlags=22000000 D TeleService: OtaspCallManager: isOtaSpActive is false only D PocketDetection: isInthePocketInternal: isInthePocket = false D LGPhoneWindowManager: hotKeyRelease count= : 0, duration=608 D LGPhoneWindowManager: hotKeyActions : mode=11, interactive=true, type=1 D HotKeyController: launch Assist: 1 turned off D LGPhoneWindowManager: hotKeyLongRelease : handled=false, count=0

So there are more processes involved in the key handling than only HotKeyController.

lucom commented 3 years ago

I also own an LG device and have the same problem: The Assistant button cannot be remapped with your tool. Would it be possible to register your Key Mapper app as an alternative "Assistant App" so that one could select it in the Android settings?

Alternatively: How could I help get this issue fixed?

sds100 commented 3 years ago

Yes, I think I can add that feature. That would the most trivial way to add support for Assistant buttons. It would be a very simple key map because the Assist app is just told to open and isn't given any information about how the button was pressed. Does the setting to change the assistant app for the LG button the same as the stock Android setting to globally change the assistant app? If so then you won't be able to seamlessly use any other assistant on your device.

For the hacky work around can you confirm that you get the same logcat output as the other person? You'll need to figure out how Key Mapper can determine that the assistant button was short pressed or long pressed by just parsing the logcat. The same messages need to be outputted consistently every time you short or long press the button.

Susko3 commented 3 years ago

Phone: LG VELVET

Relevant settings: image

Logcat, with the last two settings disabled:

Short press:

D HotKeyController: launch Assist: 1 turned off

Long press:

D HotKeyController: launch Assist: 3 turned off
D HotKeyController: currentAssistComponent : com.google.android.voiceinteraction.GsaVoiceInteractionService
D HotKeyController: received HOTKEY_RELEASE_AFTER_LONG_PRESS: duration=1293
D HotKeyController: launch Assist: 4 turned off

"Short" long press:

D HotKeyController: launch Assist: 3 turned off
D HotKeyController: currentAssistComponent : com.google.android.voiceinteraction.GsaVoiceInteractionService
D HotKeyController: received HOTKEY_RELEASE_AFTER_LONG_PRESS: duration=22
D HotKeyController: need2moreTime =478
D HotKeyController: launch Assist: 4 turned off

Long press (when screen is off, or when on the lock screen), one entry for press and another for release:

D HotKeyController: AI long action not support : Lockscreen and non-interactive status
D HotKeyController: AI long action not support : Lockscreen and non-interactive status

It's also possible to get this output if you hold the assistant button, and then turn the screen off:

D HotKeyController: launch Assist: 3 turned off
D HotKeyController: AI long action not support : Lockscreen and non-interactive status
sds100 commented 3 years ago

image Do these options still show if you select a 3rd party assist app? like Firefox or DuckDuckGo?

Thank you for the comprehensive logcat output!

Susko3 commented 3 years ago

If I select a 3rd party assistant app, or select none, then those options are greyed out.

If the assistant app is changed and the options were enabled, then pressing the assistant button will display a full screen prompt from the Google Assistant asking the user to switch to the Google Assistant to use the button.

If the options were disabled, then nothing will happen when pressing the assistant button. (Haven't tested, but I presume it still logs to logcat)

IvanBayan commented 2 years ago

I've faced with similar issue on android 11 nokia. Key mapper just didn't pick up google assistant button until I switched it off in gesture settings (Settings->System->Gestures disable google assistant button).

GL513 commented 2 years ago

https://forum.xda-developers.com/t/how-to-remap-the-lg-v50-assistant-key-no-root.4029035/

https://forum.xda-developers.com/t/new-project-remap-google-assistant-key.3934930/

These are links i had bookmarked from when i had the G7 thinQ, i dont have it anymore so i cant be of much use other than this.

ghost commented 1 year ago

Issue status?

I'm on a Nokia G10. I want to turn my assistant button into an instant mute button.

Trigger: unknown keycode 289 (Nokia's assistant button)

Actions: Mute volume Pause media Lock device

This kind of works BUT HERE'S THE PROBLEM: after getting locked, a split second later the screen wakes up because Google Assistant is still being triggered.

Disabling the button will completely prevent the trigger from being received.

I can't change the default assistant to None because I actually use it and find it convenient.

I think the only solution is if this app can be set as the assistant. And then, some kind of condition needs to be met. For example, if the keymapper assistant is activated by this keypress then execute these actions, else launch Google assistant.

So as an assistant app, keymapper would respond differently based on how it was triggered. The hardware button would execute user defined actions while other ways of being launched would just activate the default assistant.

No idea how complicated this is, I've never done Android development.

Side note: There's an app on the Play Store called Assist Mapper, it can be set as an assistant app. So I at least know that part of my idea is possible, but I have no clue if the detection of how an app was launched is possible.

r3a1d3a1 commented 1 year ago

Hey @IvanBayan So it works totally fine after disabling the related setting?

@raniesantos Assist Mapper isn't available anymore. But I see an alternative here: Assistant Button; though I haven't tried.