目录

GameManager

Class Info

public class GameManager

An abstract class that provides a public static method for obtaining a GameManager instance.

Public Method Summary

Qualifier and Type

Method Name and Description

GameManager

getGameManager()

Returns an instance that inherits and implements the GameManager abstract class.

boolean

registerGame(String packageName, GameCallBack gameCallback)

Registers an app with a device.

void

updateGameAppInfo(String gameInfoJson)

Sends game information to a device.

String

getPhoneInfo()

Obtains device information proactively.

Public Methods

[h2]getGameManager

Method

public static GameManager getGameManager()

Returns an instance that inherits and implements the GameManager abstract class.

This API uses the singleton pattern. That is, it returns the same instance each time when it is called.

Returns

Type

Description

GameManager

Returns an instance that inherits and implements the GameManager abstract class.

This API uses the singleton pattern. That is, it returns the same instance each time when it is called.

[h2]registerGame

Method

public boolean registerGame(String packageName, GameCallBack gameCallback)

Registers an app with a device. After the registration is successful, the device can call the API provided by GameManager.

Parameters

Name

Description

String packageName

App package name.

GameCallBack gameCallback

Callback used to obtain device information such as the temperature from the device.

This parameter can be set to null, indicating that the app does not obtain the information reported by the device through callback.

Returns

Type

Description

boolean

A registration result. The options are as follows:

  • true: The registration is successful.
  • false: The registration fails.

[h2]updateGameAppInfo

Method

public void updateGameAppInfo(String gameInfoJson)

Sends game information to a device. After your app is registered with a device using the registerGame method, you can then use this method to send game information to the device. Otherwise, the device cannot receive game information.

Parameters

Name

Description

String gameInfoJson

Game information sent to the device.

Global game message:

A message containing global parameters of a game, which is sent during game initialization. These parameters remain unchanged during the entire game process.

Example in the JSON format:

{
"MessageType":0,
"PackageName":"xxx.xxx.xxxx.xxx",
"AppVersion":"1.0",
"ResourceVersion":"1.0",
"EngineType":2,
"EngineVersion":"1.0",
"GameType":2,
"VulkanSupport":true
}

[Field] MessageType (int)

[Description] Mandatory. The value 0 indicates a global game message.

[Field] PackageName (String)

[Description] Mandatory. It indicates the name of a game package. The value contains a maximum of 128 characters.

[Field] AppVersion (String)

[Description] Mandatory. It indicates the game app version number. The value contains a maximum of 64 characters.

[Field] ResourceVersion (String)

[Description] Optional. It indicates the game resource version number. The value contains a maximum of 64 characters.

[Field] EngineType (byte)

[Description] Optional. It indicates the game engine type.

  • 1: Unity
  • 2: Unreal Engine 4
  • 3: Messiah
  • 4: Cocos2d
  • 200: other game engine

[Field] EngineVersion (String)

[Description] Optional. It indicates the version number of the game engine. If EngineType is not set, this parameter can be left empty. The value contains a maximum of 64 characters.

[Field] GameType (byte)

[Description] Optional. It indicates the game type.

  • 1: MOBA (multi-player online battle arena)
  • 2: role playing games (RPG)
  • 3: first-person shooter (FPS)
  • 4: fight technology games (FTG)
  • 5: racing car (RAC)
  • 200: other game category

[Field] VulkanSupport (boolean)

[Description] Optional. It indicates whether Vulkan is supported.

Game setting message:

A message containing default game settings, which is sent during game initialization. Or, a message containing an updated setting, which is sent when a game setting changes (for example, when a user changes a parameter).

Example in the JSON format:

{
"MessageType":1,
"PictureQualityMaxLevel":3,
"PictureQualityCurLevel":3,
"FrameRateMaxValue":60,
"FrameRateCurValue":50,
"ResolutionMaxValue":"1920x1080",
"ResolutionCurValue":"1280x720",
"AntiAliasing":true,
"Shadow":true,
"MultiThread":true,
"Particle":true,
"HDMode":true,
"TempTrendThresholdLevel":4
}

[Field] MessageType (int)

[Description] Mandatory. The value 1 indicates a game setting message.

[Field] PictureQualityMaxLevel (byte)

[Description] Mandatory. It indicates the highest image quality level that is supported. For example, if HD is the highest image quality level, the value is 3.

The value ranges from 1 to 5. The greater the value, the higher the image quality.

[Field] PictureQualityCurLevel (byte)

[Description] Mandatory. It indicates the current image quality level. For example, if the current image quality level is HD, the value is 3.

[Field] FrameRateMaxValue (float)

[Description] Mandatory. It indicates the maximum frame rate that is supported. For example, if up to 60 FPS is supported, the value is 60.

[Field] FrameRateCurValue (float)

[Description] Mandatory. It indicates the frame rate that is set. For example, if the current frame rate is 50 FPS, the value is 50.

[Field] ResolutionMaxValue (String)

[Description] Mandatory. It indicates the highest resolution that is supported. For example, "1920 x 1080".

[Field] ResolutionCurValue (String)

[Description] Mandatory. It indicates the current resolution. For example, "1280 x 720".

[Field] AntiAliasing (boolean)

[Description] Mandatory. It indicates whether anti-aliasing is enabled.

[Field] Shadow (boolean)

[Description] Mandatory. It indicates whether the shadow function is enabled.

[Field] MultiThread (boolean)

[Description] Mandatory. It indicates whether multiple threads are enabled.

[Field] Particle (boolean)

[Description] Mandatory. It indicates whether the particle effect is enabled.

[Field] HDMode (boolean)

[Description] Mandatory. It indicates whether the HD mode is enabled.

[Field] TempTrendThresholdLevel(int)

[Description] Optional. It indicates target threshold levels of the temperature trend.

The suggestions for different levels are as follows:

  • 1: No action is required.
  • 2: You are advised to lower the specifications for services that are not perceivable to users, such as slowing down background updates or deferring execution.
  • 3: You are advised to suspend services that are not perceivable to users and lower the specifications for the game's non-core services, such as slowing down foreground updates.
  • 4: You are advised to lower the game's overall specifications, such as the resolution and graphics quality.
  • 5: You are advised to further lower the game specifications.
  • 6: You are advised to lower the game specifications to the minimum level.

Game matching message, which is sent at the beginning and end of a game.

Example in the JSON format:

{
"MessageType":2,
"Status":1
}

[Field] MessageType (int)

[Description] Mandatory. The value 2 indicates a game matching message.

[Field] Status (byte)

[Description] Mandatory. It indicates the start and end of a game.

  • 1: start
  • 0: end

Game scene message:

A message sent when a game scene begins, when the game scene is in progress, or when the game scene ends. The message contains parameters related to scene importance and optimization of performance and power consumption.

{
"MessageType":3,
"SceneID":1,
"Description":"driving",
"ImportantLevel":5,
"SceneFreq":3,
"SceneTime":1000,
"RecommendCpuLevel":5,
"RecommendGpuLevel":5,
"RecommendDdrLevel":5,
"RecommendFps":60,
"MaxFps":60,
"CurrentFps":56.6,
"KeyThread":"render|5006|render|5007|logic|6008|logic|6009|logic|6010|net|7009",
"DrawCallNum":5000,
"VertexNum":60000,
"TriangleNum":30000,
"ShaderNum":500,
"TextureNum":1000,
"MeshNum":100,
"PassNum":5,
"PeopleNum":6
}

[Field] MessageType (int)

[Description] Mandatory. The value 3 indicates a game scene message.

[Field] SceneID (int)

[Description] Mandatory. It indicates the game scene ID. Common game scene IDs are as follows:

  • 0: default scene (switchback scene or other scene). After the current scene ends, the switchback scene can be sent to indicate an end.
  • 1: game starting
  • 2: in-game update
  • 3: sign-in process
  • 4: main interface
  • 5: game loading (player loading)
  • 6: game loading (player loading finished; waiting for others loading)
  • 7: game in progress
  • 8: onlooker mode

A special game scene code is customized starting from 100.

[Field] Description (String)

[Description] Optional. It indicates the game scene description, for example, driving.

[Field] ImportantLevel (byte)

[Description] Mandatory. It indicates the importance of a scene. The value ranges from 1 to 5. The greater the value, the higher the importance.

[Field] SceneFreq (int)

[Description] Optional. It indicates the number of times a scene occurs in a game. The number is provided based on the game big data.

[Field] SceneTime (int)

[Description] Optional. It indicates the duration of a scene, in milliseconds. The number is provided based on the game big data.

[Field] RecommendCpuLevel (byte)

[Description] Optional. It indicates the recommended CPU usage level in the scene.

[Field] RecommendGpuLevel (byte)

[Description] Optional. It indicates the recommended GPU usage level in the scene.

[Field] RecommendDdrLevel (byte)

[Description] Optional. It indicates the recommended DDR usage level in the scene.

[Field] RecommendFps (float)

[Description] Optional. It indicates the recommended frame rate in the scene.

[Field] MaxFps (float)

[Description] Optional. It indicates the maximum frame rate in the scene.

[Field] CurrentFps(float)

[Description] Optional. It indicates the current frame rate in the scene.

[Field] KeyThread (String)

[Description] Optional. It indicates the key thread in the scene.

  • render: rendering thread
  • logic: logic thread
  • net: network thread

[Field] DrawCallNum (int)

[Description] Optional. It indicates the average number of Drawcalls per frame in the scene.

[Field] VertexNum (int)

[Description] Optional. It indicates the average number of model vertices per frame in the scene.

[Field] TriangleNum (int)

[Description] Optional. It indicates the average number of triangles per frame in the scene.

[Field] ShaderNum (int)

[Description] Optional. It indicates the average number of shaders per frame in the scene.

[Field] TextureNum (int)

[Description] Optional. It indicates the average number of textures per frame in the scene.

[Field] MeshNum (String)

[Description] Optional. It indicates the average number of meshes per frame in the scene.

[Field] PassNum (int)

[Description] Optional. It indicates the number of rendering channels per frame in the scene.

[Field] PeopleNum (int)

[Description] Optional. It indicates the number of users playing on the same screen in the scene.

Game touch area message:

A message indicating a valid touch area, which is sent to the system when the game scene begins.

If the valid touch area changes in the game scene, the change should also be sent to the phone system.

Example in the JSON format:

{
"MessageType":4,
"ValidRegin":"direct:3:(10,10,30,30)|op:2:(200,200,210,210)|set:1:(500,500,510,510)",
"HandleTime":10
}

[Field] MessageType (int)

[Description] Mandatory. The value 4 indicates a game touch area message.

[Field] ValidRegin (String)

[Description] Mandatory. It identifies the valid touch area in the game scene, including the attributes, usage frequency, and area attribute definition.

  • direct: direction
  • op: operation
  • set: setting

The frequency ranges from 1 to 3, which are defined as low, medium, and high levels.

Example of using the coordinates in the upper left and lower right corners to represent the rectangle:

direct:3:(10,10,30,30)|op:2:(200,200,210,210)|set:1:(500,500,510,510)

[Field] HandleTime (int)

[Description] Optional. It indicates the duration from the time when the game app receives the input event to the time when the app responds, in milliseconds.

Game network status message:

A message indicating the network status, which is sent to the device when the game scene begins.

The message should also be sent when network delay or load jump occurs.

Example in the JSON format:

{
"MessageType":5,
"NetLatency":"total:50|up:20|server:10|down:20",
"NetServerIP":"10.111.65.22",
"NetLoad":2
}

[Field] MessageType (int)

[Description] Mandatory. The value 5 indicates a game network status message.

[Field] NetLatency (String)

[Description] Mandatory. It indicates the network delay in the game scene, in milliseconds.

0-50-100-150-200... When the total delay changes, the delay is sent once. When sending the delay message, the upstream, downstream, and server processing time should be included, for example:

total:50|up:20|server:10|down:20.

[Field] NetServerIP (String)

[Description] Mandatory. It indicates the address of the game server in the scene.

[Field] NetLoad (byte)

[Description] Optional. It indicates the game network load level, ranging from 1 to 3.

  • 1: light load
  • 2: medium load
  • 3: heavy load

[h2]getPhoneInfo

Method

public String getPhoneInfo()

Proactively obtains device information, such as the temperature, CPU load, and GPU load.

The device information obtained using this method is in the same format as that obtained by using the onPhoneInfoUpdated method of the GameCallback API.

NOTE:
  • You need to use the registerGame method to complete the registration first before calling this method to obtain device information. Otherwise, no information will be obtained.
  • The device information returned is from the most recent callback of the onPhoneInfoUpdated method in the GameCallback API.

Returns

Type

Description

String

Device information, such as the temperature, CPU load, and GPU load. The value can be null or empty.

The returned content is the same as that returned by the onPhoneInfoUpdated method of the GameCallback API.