-1

I am using Android 6 (Cyanogenmod) and I would like to have the following simple behaviour:

Hardware button X: Sleep AND lock the phone.

Hardware button Y: Sleep phone WITHOUT locking.

In addition I do not want ANY automatic locking/unlocking going on.

That seems to be impossible. If so, that's clearly a design fault.

Please enlighten me with your Android expertise.

TY

3
  • First one is definitely doable using Xposed Additions.
    – Firelord
    Commented May 21, 2016 at 19:37
  • So you are basically saying it's only possible with mods?
    – John Smith
    Commented May 21, 2016 at 19:53
  • Might be even doable with Tasker and Secure Settings – but will most likely require the device to be rooted.
    – Izzy
    Commented May 21, 2016 at 20:30

1 Answer 1

1

I've tested the following solution successfully on Nexus 6 running CM13 (a snapshot build) with volume rockers as HW key X and Y.

If you don't want to use an Xposed module such as Xposed Additions, then I suggest you setup AutoInput (free trial) and Tasker (free trial; user guide). You must have the accessibility service of AutoInput enabled and root access enabled under Developer options and already granted to Tasker.

Instructions for Tasker

  1. Create an Event based profile from Plugin → AutoInput → Key → Configuration:

    • Keys: your key X
    • Key Action: Key Down
  2. Setup a task for it with following actions:

    1. Plugin → AutoInput → Modes:

      • Configuration:

        • Key Suppress: Enable
        • Keys: your key X
      • Timeout: None
    2. Code → Run Shell:

      • Command: settings put secure lock_screen_lock_after_timeout 0; input keyevent 26
      • tick Use Root
    3. Plugin → AutoInput → Modes:

      • Configuration:

        • Key Suppress: Disable
        • Keys: your key X
      • Timeout: None
  3. Create an another Event based profile from Plugin → AutoInput → Key → Configuration:

    • Keys: your key Y
    • Key Action: Key Down
  4. Setup a task for it with following actions:

    1. Plugin → AutoInput → Modes:

      • Configuration:

        • Key Suppress: Enable
        • Keys: your key Y
      • Timeout: None
    2. Code → Run Shell:

      • Command: settings put secure lock_screen_lock_after_timeout <ms>; input keyevent 26
      • tick Use Root

        Replace <ms> with milliseconds. This is the timeout available under Lock screen settings and I've not tested it beyond 1800000.
    3. Plugin → AutoInput → Modes:

      • Configuration:

        • Key Suppress: Disable
        • Keys: your key Y
      • Timeout: None

All of the said instructions would bring to fruition only when the lock screen is secured. Furthermore, during testing I had to temporarily give up the original functionality of my HW keys.

Note: disable the action for disabling key suppress if you find that the actions are not working properly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .