Using AM to turn off display with or without locking device

Post your questions and help other users.

Moderator: Martin

Post Reply
vertigo
Posts: 147
Joined: 28 Oct 2018 00:28

Using AM to turn off display with or without locking device

Post by vertigo » 03 Oct 2019 22:22

As mentioned in this thread, I'm trying to make AM turn the display on for several seconds on track change when playing music in the car. That part is easy, but there are further complications, and I figured I should make a separate thread about it since it's unrelated to the main topic of that one. The problem is that typically the phone is locked when the display is off, so when the display comes on, it only shows the lock screen, so the player info is sideways. Therefore, I need to keep it from locking when in the car. The obvious way to do this is with trusted devices, using the car BT. However, this has two problems: BT and trusted devices both have proven to be unreliable, and trusted devices doesn't provide the option to only KEEP a device unlocked but not UNLOCK it. That is, I only want it to NOT lock when connected to the device, but I DON'T want it to actually be unlocked by the device, meaning if someone stole both or stole/found the phone and were anywhere near my car (with it on, of course) they would have total access. This is, quite frankly, a gross oversight by Google.

So I'm trying to approach it from the opposite angle: disable Google's auto-locking when the power button is pressed and increase the lock delay when the screen is off and have AM do it instead, using the display off as a trigger and conditions such as BT device present as conditions to determine whether or not to actually lock it. The added bonus here is that, in theory, I might actually be able to get it to use my computer as a trusted device to keep it unlocked at home finally (what I'd really like is to be able to get my computer to lock/unlock using my phone as a BT proximity key). This approach has its own problems, however. First is that Android won't let me set the fingerprint sensor to turn the display off only--it also locks it--and I use that all the time for that. So that would bypass AM and lock the screen regardless, defeating what I'm trying to do. If I disable that option, I can't use the sensor to turn the screen off at all, and AM doesn't have the ability to do that. It does have up/down/left/right gestures, so it seems it should be able to do a long-press gesture as well.

The other problem is that when AM locks the screen, it can't be unlocked with the fingerprint sensor. This thread addresses that, and this thread provides a solution via the Control UI: lockscreen () command but, unfortunately, I'm on 8.0/Oreo, and that requires 9.0/Pie.

Thoughts/suggestions? Am I just out of luck here?

By the way, a little off-topic, but something I discovered while playing with this, because I was also thinking it would be nice to set it to turn the display on/off when I wave my hand in front of the phone, is that the proximity sensor reading in AM always shows 100cm unless I get really close, then it shows 3cm then 1cm. This is on a Moto Z Play. Is that just a limitation of the sensor, in that it only registers things 3cm or less, and then only with two discrete distances? It would make sense, since waving over it for the Moto Display only works when really close, but I guess I just assumed that's how it was configured, but that the sensors should be able to detect further out than that.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Using AM to turn off display with or without locking device

Post by Desmanto » 04 Oct 2019 18:57

Just use bluetooth connected trigger and set lock pattern state to off. However this require root and I think you don't have root access (hence trying to find alternatives). You can try Set keyguard state to off too, but maybe doesn't work too.

Workaround for your music, you can use the bluetooth connected trigger and set the display timeout to any timeout longer than your usual music, 5 minutes should be enough, 10 minutes can be used too. Then when the music changes, use the trigger media session changed and use control UI to click any element. this will simulate the click and refresh the timeout back to 5 minutes (or 10), hence keep the display screen always on. Once the music stop changing, no click, screen will turn off in 5 minutes from the last songs change. When you exit car, use another trigger to revert back the timeout to your typical timeout.

There is no way to override the power button in common usage, and not a good idea to do it. It is better you use another shortcut to turn off the screen and lock after the delay you want. This again, require root to set the lock pattern state on/off. Fingerprint gesture trigger not even working at all at my RN5. So it is limited to hardware and kernel, or basically per device case.

On android before pie, the way to lock the screen while still can be unlocked using fingerprint, is stated in the link you pointed out, either input keyevent (need root) or set the timeout to very low value.

Proximity value varies depends on device. Mine show only value 0 and 5 cm. You need to wave really close to use the wave gesture.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

vertigo
Posts: 147
Joined: 28 Oct 2018 00:28

Re: Using AM to turn off display with or without locking device

Post by vertigo » 04 Oct 2019 20:04

Yeah, no root. :( Never did it on this phone, and I don't feel like wiping it to unlock the boot loader.

Adjusting the timeout isn't really the answer, since I often just leave the display on while driving, but sometimes want to turn it off to save battery or just not have it showing, and so I have to turn it off manually, which locks it. And even if I had root, disabling that while connected to the BT would have the same security issue as trusted devices, which is that it should only keep it unlocked, not disable the lock altogether.

About the only solution I can think of is to make a flow with a proximity trigger and a music playing and face-left condition, so when driving I could wave over it and have it set the screen timeout to the minimum (which unfortunately is still 15 seconds, same as the minimum in settings) so it would turn off on its own (because doing it manually would instantly lock it, per my setting, which I prefer to keep), and then raise the timeout to keep it unlocked until the next event that triggers the screen on. The problems with this are that it would require a wave, which doesn't always work, would get screwed up if I turn my phone off the normal way by habit, would take 15 seconds to actually turn the display off, and would cause the flow to be triggered whenever the proximity sensor detects something, which would be all the time.

I've racked my brain and just can't come up with a decent solution. Not that this is a terribly important need--it's just as much about trying to figure it out as needing to do it--but it would have been nice if I could have made it work. It's too bad Google locks things down so much and then doesn't present viable alternatives or more fine-tunable configurations. Yet another reason I'm not a fan.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Using AM to turn off display with or without locking device

Post by Desmanto » 06 Oct 2019 17:02

You hAve other choice is to use the volume up down as the trigger. Use trigger hardware key event and catch the volume button, do your flow. Of course still the same problem if you press the power button. You gotta change that habit.

Other method, you might try voice command with hotword method. There is hotword plugin : https://play.google.com/store/apps/deta ... PluginFree
Install this and set the voice as you want. And use that as the trigger for your flow. It works almost like "Ok Google", except you can customize your own voice/word.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

vertigo
Posts: 147
Joined: 28 Oct 2018 00:28

Re: Using AM to turn off display with or without locking device

Post by vertigo » 07 Oct 2019 00:26

Oh, great. Why'd you have to go and tell me about that? I have a feeling I'm going to be spending a lot of time playing around with it...so many ideas. :) I'm having visions of telling my phone to do all sorts of stuff, and maybe even use my old phone as a voice-activated remote. Hmm...

Post Reply