DEV Community

Cover image for The new GameManager class in Android 12
Thomas Künneth
Thomas Künneth

Posted on

The new GameManager class in Android 12

Even though Android 12 is months away from its public release, we have already seen tons of interesting new features. With this post I continue my strolling through the developer preview apis. Today I present to you android.app.GameManager.

The docs currently describe the class like this:

The GameManager allows system apps to modify and query the
game mode of apps.

Sounds like fun, right?

As usual we obtain an instance with getSystemService().

val m = getSystemService(GameManager::class.java)
m?.run {
  println(when (gameMode) {
    GAME_MODE_BATTERY -> "GAME_MODE_BATTERY"
    GAME_MODE_PERFORMANCE -> "GAME_MODE_PERFORMANCE"
    GAME_MODE_STANDARD -> "GAME_MODE_STANDARD"
    GAME_MODE_UNSUPPORTED -> "GAME_MODE_UNSUPPORTED"
    else -> "???"
  })
}
Enter fullscreen mode Exit fullscreen mode

As of now, there is just one method of interest, getGameMode(). It is described this way:

Return the user selected game mode for this application.

An application can use android:isGame="true" or
android:appCategory="game" to indicate that the application is
a game. If an application is not a game, always return
GAME_MODE_UNSUPPORTED.

Developers should call this API every time the application
is resumed.

Now, let's look at the constants.

  • GAME_MODE_BATTERY:

Battery game mode will save battery and give longer
game play time.

  • GAME_MODE_PERFORMANCE:

Performance game mode maximizes the game's performance.

  • GAME_MODE_STANDARD:

Standard game mode means the platform will use the game's
default performance characteristics.

  • GAME_MODE_UNSUPPORTED:

Game mode is not supported for this application.

The description of the <application> tag explains the android:isGame attribute as follows:

Whether or not the application is a game. The system may
group together applications classifed as games or display
them separately from other applications.
The default is false.

And how about android:appCategory="game"?

While it is not marked as unknown in the IDE, the current docs not (yet) seem to include it. Which is... interesting... as app categories have been present since Android Oreo.

A little more on history. android.R.attr got a isGame constant with api level 21. Its docs say:

A boolean flag used to indicate if an application is a Game
or not.

This information can be used by the system to group together
applications that are classified as games, and display them
separately from the other applications.

May be a boolean value, such as "true" or "false".

With android.content.pm.ApplicationInfo you get information about a particular application. It corresponds to data from the AndroidManifest.xml's <application> tag. It has a FLAG_IS_GAME constant, too, which was added with api level 21 but deprecated with 26. Google asks developers to use CATEGORY_GAME, which also belongs to ApplicationInfo since api level 26. Still, given recent privacy changes, most apps probably should not query such data any more. Some, of course, need to.

How to change the values?

How, when or where the user or the system canchange or influence the values returned by getGameMode() still remains to be seen. My guess would have been that we will see some new controlls in system settings, but I have not found them yet. Have you? Please share your insights in the comments.

Top comments (0)