Skip to content

[Android] Add support for the new Game-Mode API #1995

@pavly-gerges

Description

@pavly-gerges

The Android team has launched a new API that's shipped with Android-12, the Game-Mode API reads the system game mode configuration to optimize the game accordingly using jMonkeyEngine APIs or submitting a call to the Android Stock Game interventions APIs, the first approach to this should be integrating a call to the Game-Mode API and adding a listener for that to be handled independently through users actions, for example, altering Lod, loading low-poly models or playing with frame-rates and disabling game filters.

A dummy example:

public interface GameMode {
      void onDisabled(GameManager gameManager);
      void onPerformanceEnabled(GameManager gameManager);
      void onBatterySaverEnabled(GameManager gameManager);
      void onStandardEnabled(GameManager gameManager);
}

...

// Later on JmeSurfaceView
GameMode gameMode;
...
// Only call this for Android 12 and higher devices
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ) {
  // Get GameManager from SystemService
  GameManager gameManager = Context.getSystemService(GameManager.class);

  // Returns the selected GameMode
  int gameMode = gameManager.getGameMode();
  if (gameMode == UNSUPPORTED) {
      gameMode.onDisabled(gameManager);
  } else if (gameMode == STANDARD) {
      gameMode.onStandardEnabled(gameManager);
  } else if (gameMode == BATTERY) {
      gameMode.onBatterySaverEnabled(gameManager);
  } else if (gameMode == PERFORMANCE) {
      gameMode.onPerformanceEnabled(gameManager);
  }
} else {
      gameMode.onDisabled(gameManager);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions