By Firelord

2015-06-12 23:56:29 8 Comments

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:
  • 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.


@Thomas Vos 2015-06-25 15:48:06

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(

    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.BUTTON_BRIGHTNESS, 0);
    } else {
        int oldBright = prefs.getInt("pre_navbar_button_backlight", -1);
        if (oldBright != -1) {
                    Settings.Secure.BUTTON_BRIGHTNESS, oldBright);

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);

@Firelord 2015-06-25 17:22:44

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. :)

@Thomas Vos 2015-06-25 19:14:43

@Firelord you had it in your answer, and I had it in my answer... Why didn't we see it :)

@Aniket Lamba 2015-06-14 12:19:49

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

@Matthew Read 2015-06-14 16:01:52

Can you link this app?

@Aniket Lamba 2015-06-15 18:56:00

Oh my bad.Install Gravitybox*

@Firelord 2015-06-19 05:58:45

How does Gravitybox helps especially when the developer mentioned that it's not meant for CM like ROMs?

@Aniket Lamba 2015-06-20 07:01:42

Gravitybox is working fine on my CM12.1 based ROM.

@Firelord 2015-06-20 10:41:07

GravityBox is an Xposed Module and the device still needs to be restarted at least once. Besides, how do I use it using shell?

@Aniket Lamba 2015-06-21 15:29:33

Can you soft reboot the phone and use the method by SuperThomasLab above?

@Firelord 2015-06-22 12:31:09

I cannot afford any kind of reboot.

@user109933 2015-06-25 17:02:55

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.

@user109933 2015-06-25 17:03:47

I'll be waiting for a big leap. :-D

@user109933 2015-06-25 17:14:34

I'm glad my answer is helping you, but please make sure to award the bounty before it expires (soon). And of course, partial credit goes to the users I mentioned.

@Thomas Vos 2015-06-25 19:17:13

Does this only work on CyanogenMod, or also on stock ROMs?

@user109933 2015-06-25 19:47:49

@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.

@Firelord 2015-08-30 12:56:42

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

Related Questions

Sponsored Content

1 Answered Questions

How to hide navigation bar on home screen of Samsung j6

  • 2018-06-06 14:16:17
  • Syed imran
  • 1930 View
  • 0 Score
  • 1 Answer
  • Tags:   navbar

1 Answered Questions

[SOLVED] Enable OTG with a shell command

1 Answered Questions

1 Answered Questions

[SOLVED] How do I screen pin an app in Android Lollipop using command-line?

2 Answered Questions

[SOLVED] Using command-line to boot into primary and secondary ROM of MultiROM

  • 2015-12-29 23:40:15
  • Firelord
  • 525 View
  • 0 Score
  • 2 Answer
  • Tags:   command-line

2 Answered Questions

Sponsored Content