Android M: Tweaking System UI Tuner

Everything described in this post is based off the Android 'M' Developer Preview, Release 2. As new releases (and the source code) are made available, behaviors are subject to change and the contents of this post may change along with them.

By now, you've probably already seen (or at least heard about) the new System UI Tuner developer option in Android 'M'. Beginning with Preview 2, this power tool has two new tricks up its sleeve:

Allows control over which status bar icons are displayed

Includes a one-click "demo" mode to set the entire status bar to a pre-set default (static) state

The best part is, both of these features are externally accessible. We can fairly easily control them from both the device shell and using public APIs in an application.

Status Icon Control

With the UI found under System UI tuner -> Status bar, developers can easily turn off most of the primary status icons (except for notifications, battery level, and clock). Fortunately for us, these changes are persisted into Settings.Secure under the key icon_blacklist. This is what the value looks like with all the icons disabled:

Since this value lives in Settings.Secure, it cannot be written by third party application code (only read).

Demo Mode - More than Meets the Eye

On the surface, demo mode looks shows as a one-click solution to quickly set the status bar to a pre-defined "clean" state. It doesn't offer any configuration options for controlling the appearance of the status bar items…or does it?

While demo mode in and of itself cannot be configured, it turns out that the mechanism used to trigger these changes inside of SystemUI is unprotected broadcast intents. This means that, if we can figure out what intents SystemUI expects, we can configure our own "demo mode" from the shell or some application code.

SystemUI listens for broadcasts with the com.android.systemui.demo action string, and forwards them onto the various demo mode handlers. Demo mode is controlled with a series of "commands" that are passed along in the broadcasts as extras. Here is a list of the current top-level commands:

enter

exit

clock

battery

volume

status

network

notifications

bars

The enter and exit commands are used to turn demo mode on and off (the equivalent of the "Show demo mode" UI command, while the remaining commands configure the status bar if demo mode is enabled. From the shell, we could do the following:

Enabling External Control

Before any of the above commands will work, the "Enable demo mode" switch in System UI Tuner -> Demo mode must be toggled on. This process can be done by the user, or we can automate it from the shell:

$ adb shell put settings global sysui_demo_allowed 1

In the current preview, demo mode doesn't have to actually be enabled for external broadcasts to work. It just has to have been enabled at least once in the past. This may change in future releases.

This part cannot be done from application code because applications do not have the rights to write into the Settings.Global table.

Custom Demo Example

Tying a handful of these commands together, we can create an application method that builds the status bar just the way we want it for our demos: