5

Device: OnePlus One (OPO); running CM12, is rooted, and has Xposed Framework installed.


I need to enable On-screen navigation (it disables Hardware (HW) keys and shows soft keys at the screen; like this) in OPO. I'm able to do it via Settings but my objective requires a command-line solution through shell.

(Note that this is not a development/programming question, simply an Android question.)

  • Objective: To disable Back(HW) key when main activity of an app (random) is in foreground, but without a reboot.

  • I found On-screen nav. to be a good choice which doesn't require a reboot. I'll use an automation app to trigger the disabling action.

  • There are manual ways to disable HW keys (by editing .kl files) and enabling Soft keys (by editing build.prop), or using tools like Xposed modules to disable or swap HW keys. But they all require reboot (soft/hard) at least once which I cannot afford.

  • I experimented and found that when On-screen nav. is enabled, the value for dev_force_show_navbar changes to 1 from 0. Similarly. button_brightness changes to 0 from 255. Both names are under Settings.db (Table:secure)

  • Also, there is no special activity assigned for Settings → Buttons(it enables On-screen nav). I used dumpsys activity | grep mFocusedActivity to see activity related to Buttons. The result was:

    com.android.settings/.SubSettings
    
  • dumpsys activity activities or dumpsys activity recents also has nothing more to tell here.

  • I logged my actions using logcat when enabling On-screen nav. and here is the log file.

So, how do I enable On-screen nav. through command line, irrespective of whether it requires superuser access or not?

Edit: Is there any other way using which I can achieve the objective precisely?


Only thing that comes to my mind is to use input <keyevent> but that's counterproductive to me. The other way is to trigger an Xposed module like Xposed Additions but I'm unable to use it with shell.

10
  • I know you can enable it within the build.prop just add this at the end: qemu.hw.mainkeys=0
    – Thomas Vos
    Commented Jun 13, 2015 at 13:33
  • @SuperThomasLab Thanks for explicitly mentioning it, but as I already mentioned about it in the question, it needs reboot to take effect which I cannot afford.
    – Firelord
    Commented Jun 13, 2015 at 18:05
  • sorry didn't notice that, maybe you can decompile settings and take a look how they did it then.
    – Thomas Vos
    Commented Jun 13, 2015 at 18:06
  • @SuperThomasLab Here is the source. Can you help how can it be used in a shell?
    – Firelord
    Commented Jun 24, 2015 at 20:13
  • I took a look at the code, there is a way to disable the hardware buttons, and enable the navigation buttons, but it is coded and can't be used in the commanline. Where are you going to execute that shell command? You can maybe launch an activity of an app I/we can make that automatically does it in the background. (In java code) @Firelord
    – Thomas Vos
    Commented Jun 25, 2015 at 5:37

3 Answers 3

4
+100

I experimented and found that when On-screen nav. is enabled, the value for dev_force_show_navbar changes to 1 from 0... Both names are under Settings.db (Table:secure).

You actually mentioned the key to the answer but somehow (I suppose) didn't know how to use it. Many thanks to Andrew T. and DavisNT for this answer since it would lead to a solution for your problem.

I myself is a owner of OnePlus One running stock CM12 so you may now expect a working answer.

From the shell, be it adb, or a Terminal app, or Tasker's "Run Shell" action, enter the following command with root privileges:

settings put secure dev_force_show_navbar 1

You would now see that On-screen navigation bar is enabled just like in your pic posted here.

Don't worry about button_brightness since the changes in its value would be reflected automatically by the above command.

I tested that command in Tasker by manual execution of action "Code -> Run Shell -> command" with "Use Root", and its working good.

The changes are exactly same as doing it from "Settings -> Buttons" so nothing to worry, i.e. only Soft-keys are visible and Hard keys are disabled. Coolest part -- no reboot needed.

You can revert back by using 0 in place of 1 in the aforesaid command.

3
  • Does this only work on CyanogenMod, or also on stock ROMs?
    – Thomas Vos
    Commented Jun 25, 2015 at 19:17
  • @SuperThomasLab I so far tried on CM12 (Cyanogen OS 12, stock ROM for OnePlus One) only. It is dependent on settings.db. If the Stock ROM differs in features then the solution may not work.
    – user109933
    Commented Jun 25, 2015 at 19:47
  • I would like the readers to note that in some other custom ROMs the table system has that key value so the command would be settings put system dev_force_show_navbar 1
    – Firelord
    Commented Aug 30, 2015 at 12:56
0

There isn't a solution for your question. All the ways to do it will require a reboot except the Settings app for Cyanogenmod. I took a look at the source code of Cyanogenmod how they managed to get it working, and I found this:

This is the method that does enable/disable the navigationbar:

(Sorry if this is off-topic, wanted to add this in case others are interested)

private static void writeDisableNavkeysOption(Context context, boolean enabled) {
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    final int defaultBrightness = context.getResources().getInteger(
            com.android.internal.R.integer.config_buttonBrightnessSettingDefault);

    Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.DEV_FORCE_SHOW_NAVBAR, enabled ? 1 : 0);
    CmHardwareManager cmHardwareManager = (CmHardwareManager) context.getSystemService(Context.CMHW_SERVICE);
    cmHardwareManager.set(CmHardwareManager.FEATURE_KEY_DISABLE, enabled);

    /* Save/restore button timeouts to disable them in softkey mode */
    SharedPreferences.Editor editor = prefs.edit();

    if (enabled) {
        int currentBrightness = Settings.Secure.getInt(context.getContentResolver(),
                Settings.Secure.BUTTON_BRIGHTNESS, defaultBrightness);
        if (!prefs.contains("pre_navbar_button_backlight")) {
            editor.putInt("pre_navbar_button_backlight", currentBrightness);
        }
        Settings.Secure.putInt(context.getContentResolver(),
                Settings.Secure.BUTTON_BRIGHTNESS, 0);
    } else {
        int oldBright = prefs.getInt("pre_navbar_button_backlight", -1);
        if (oldBright != -1) {
            Settings.Secure.putInt(context.getContentResolver(),
                    Settings.Secure.BUTTON_BRIGHTNESS, oldBright);
            editor.remove("pre_navbar_button_backlight");
        }
    }
    editor.commit();
}

As you can see it uses android.hardware.CmHardwareManager and the stuff is hard coded into the ROM and it's not possible to make it yourself.

Edit: There is a solution for the question. Look at the accepted answer. I already had it in my answer:

Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.DEV_FORCE_SHOW_NAVBAR, enabled ? 1 : 0);
2
  • Hi SuperThomasLab, this answer seems to suffice what I intended to know. We both thought the goal might not be possible to achieve but it can be done. Have a look at it. :)
    – Firelord
    Commented Jun 25, 2015 at 17:22
  • 1
    @Firelord you had it in your answer, and I had it in my answer... Why didn't we see it :)
    – Thomas Vos
    Commented Jun 25, 2015 at 19:14
-2

What I can suggest is - Install Gravity Box and enable the Navigation Bar from there.

5
  • How does Gravitybox helps especially when the developer mentioned that it's not meant for CM like ROMs?
    – Firelord
    Commented Jun 19, 2015 at 5:58
  • Gravitybox is working fine on my CM12.1 based ROM. Commented Jun 20, 2015 at 7:01
  • GravityBox is an Xposed Module and the device still needs to be restarted at least once. Besides, how do I use it using shell?
    – Firelord
    Commented Jun 20, 2015 at 10:41
  • Can you soft reboot the phone and use the method by SuperThomasLab above? Commented Jun 21, 2015 at 15:29
  • I cannot afford any kind of reboot.
    – Firelord
    Commented Jun 22, 2015 at 12:31

You must log in to answer this question.

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