Skip to content
Commit bf590fe7 authored by Tyler Lacey's avatar Tyler Lacey
Browse files

Add GameSession game task focus lifecycle methods.

Introduce GameSession#onGameTaskFocusChanged method that is called to
inform GameSession implementations abouts when their game task goes into
our out of focus.

Also introduce a new LifecycleState to the abstract GameSession class
to ensure that transitions follow the following rules:

- All GameSessions start in the INITIALIZED state
- All GameSessions will then transition to the CREATED state [onCreate()
  is called]. If a GameSession transitions from INITIALIZED directly to
  DESTOYED, onCreate() and onDestroy() will both be called.
- A GameSession in the CREATED state may transition to either the
  TASK_FOCUSED state [onGameTaskFocusChanged(true) is called] or the
  DESTROYED state [onDestroy() is called]. If a game task starts in a
  non-focused state and never comes into focus, the GameSession will
  never transition to the TASK_FOCUSED or TASK_UNFOCUSED states.
- A GameSession in the TASK_FOCUSED state may only transition
  to the TASK_UNFOCUSED state [onGameTaskFocusChanged(false) is called].
  If a GameSession transitions from TASK_FOCUSED to DESTROYED, it will
  call onGameTaskFocusChanged(false) to complete that part of the
  lifecycle before transitioning to the DESTROYED state.
- A GameSession in the TASK_UNFOCUSED state may transition back to the
  TASK_FOCUSED state [onGameTaskFocusChanged(false) is called again] or
  the DESTROYED state [onDestroy() is called].

In this way, all GameSessions are guaranteed to have
onGameTaskFocusChanged(true) be called if they are ever in focus before
being destroyed (generally as soon as the GameSession is created) and to
have onGameTaskFocusChanged(false) be called before they are destroyed.
GameSessions are also guarnateed to have onCreate() be called before
onDestroy().

Test: Manual e2e testing
Bug: 214104366
Bug: 202414447
Bug: 202417255
CTS-Coverage-Bug: 206128693
Change-Id: Id4e1eec50eb891ffb6df74650c27ea3a27a8b9c3
parent b5956636
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment