从 Android 14 开始,Android 动态性能框架 (ADPF) 中新增了一种名为 GAME 的电源模式,以便自定义手机在玩游戏期间的性能。GAME 会向 Power HAL 指明游戏应用位于前台。此指示可让 Power HAL 在玩游戏时采用电源管理策略,以便让用户获得稳定并提升性能的效果。
为了缩短游戏的加载时间,Android 13 在 ADPF 中引入了一个名为 GAME_LOADING 的新电源模式。GAME_LOADING 表示游戏应用是否处于加载状态,以便 Power HAL 可以提供加载速度提升。此指示可让 Power HAL 提供性能提升措施,从而缩短游戏加载时间。
本页介绍了游戏应用如何将游戏状态传递给 Power HAL,并说明了如何配置 Power HAL 以便在您的设备中充分利用它,以及如何测试您的 Power HAL 实现。
加载速度提升模式的工作原理是检测游戏应用何时处于加载状态,并通知 Power HAL。Android 13 在面向开发者的 API 中引入了一个名为 isLoading 的新游戏状态。此游戏状态使用电源管理器服务中新增的 GAME_LOADING 电源模式来向 Power HAL 发送有关顶级游戏状态的通知。Power HAL 收到游戏加载状态通知后,可以调整平台的性能设置和 CPU 时钟频率,从而缩短加载时间。
为了表明游戏正在加载,游戏应用会使用游戏信息中心在游戏管理器中设置 isLoading 状态。游戏管理器将此状态传递给游戏管理器服务,后者将 setPowerMode 与新增的 GAME_LOADING 电源模式结合使用,以调用电源管理器服务。GAME_LOADING 电源模式会向 Power HAL 发出指示,告知其游戏处于加载状态,以便 Power HAL 可以提供加载速度提升。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-07。"],[],[],null,["# Performance boost for games\n\nStarting with Android 14 a new power mode named [`GAME`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces//power/aidl/android/hardware/power/Mode.aidl)\nin the Android Dynamic Performance Framework (ADPF) enables customization of\nphone performance during game use. `GAME` indicates to the Power HAL that a\ngame app is in the foreground. This indication allows the Power HAL to\nadopt power management strategies when a game is being played, so that the user\nexperiences a stable and improved performance.\n\nTo provide an improvement on a game's loading time, Android\n13 introduces a new power mode named [`GAME_LOADING`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces//power/aidl/android/hardware/power/Mode.aidl)\nin ADPF. `GAME_LOADING` indicates if a game app is in the loading state so that\nthe Power HAL can provide a loading boost. This indication allows the Power HAL\nto provide performance boosting measures that can speed up the game loading\ntime.\n\nThis page describes how the game app passes\nthe game state to the Power HAL, explains how to configure Power HAL in order to\ntake advantage of it in your devices, as well as how to test your Power HAL\nimplementation.\n\nPower mode detection and notification\n-------------------------------------\n\nThis section describes how the Power Manager handles the [`GAME`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces//power/aidl/android/hardware/power/Mode.aidl) and [`GAME_LOADING`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces//power/aidl/android/hardware/power/Mode.aidl) modes.\n\n### GAME power mode\n\nThe new power mode `GAME` in Android 14 indicates to\nthe [Power Manager Service](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java)\nthat the user is playing a game. When the Power HAL is notified of the `GAME`\nmode, it can adjust power to enhance performance, lower temperature and extend\nbattery life, while the game is being played.\n\nThe following figure explains the flow of information to the Power HAL to\nindicate the `GAME` power mode:\n\n**Figure 1.** Information flow to indicate that a game is being played.\n\nThe `GAME` power mode is always set for apps with an `appCategory`\nof `GAME` in [`AndroidManifest.xml`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/core/res/AndroidManifest.xml).\n\n### GAME_LOADING power mode\n\nThe loading boost mode works by detecting when a game app is in a loading\nstate and notifying the Power HAL. Android 13\nintroduces a new game state called [`isLoading`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base//core/java/android/app/GameState.java) in the [developer-facing API](https://developer.android.com/reference/android/app/GameState).\nThis game state uses the new [`GAME_LOADING`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces//power/aidl/android/hardware/power/Mode.aidl)\npower mode in the Power Manager Service to notify the Power HAL about the top\nlevel game state. Once the Power HAL is notified of the game loading state, it\ncan adjust the platform's performance settings and CPU clock rate, which results\nin improved load times.\n\nTo indicate that a game is loading, the game app uses the Game Dashboard to set\nan [`isLoading`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base//core/java/android/app/GameState.java)\nstate in the Game Manager. The Game Manager passes this state to the Game\nManager Service, which uses [`setPowerMode`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base//core/java/android/os/IPowerManager.aidl)\nwith the new [`GAME_LOADING`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces//power/aidl/android/hardware/power/Mode.aidl)\npower mode to invoke the Power Manager Service. The `GAME_LOADING` power mode\nindicates to the [Power HAL](/docs/core/power/performance) that the game is in a\nloading state so that the Power HAL can provide a loading boost.\n\nThe following figure explains the flow of information from the app to the Power\nHAL to indicate the loading state:\n\n**Figure 2.** Information flow to indicate that a game is in a loading state.\n\nThe game dashboard allows users to turn the loading boost feature on or off with\nthe Performance Setting. The Performance Setting always defaults to off.\n\nCustomize Power HAL using GAME and GAME_LOADING\n-----------------------------------------------\n\nTo take advantage of the `GAME` and `GAME_LOADING` modes, OEMs must\ncustomize their implementation of the [Power HAL](https://android.googlesource.com/platform/hardware/interfaces/+/android16-release/power/aidl/default/Power.cpp).\nAs power management and performance boosting is hardware specific, no reference\nimplementations for the `GAME` or `GAME_LOADING` modes are made available until\na reference implementation for the Google Pixel device is released.\n\nTo enhance performance in a `GAME` and `GAME_LOADING` mode, OEMs can choose to\nimplement a combination of the following measures:\n\n- Stabilize frame rate\n- Increase CPU clock speed\n- Temporarily reduce temperature throttling\n- Assign a higher CPU priority to the foreground game app\n- Reduce CPU boost tuned for regular, non-game apps\n- Optimize the thermal-related power distribution strategy\n\nTest GAME mode implementation\n-----------------------------\n\nTo test the implementation of the `GAME` mode, use tests prefixed with\n`testGamePowerMode_` in `GameManagerServiceTests.java`.\n\nTest GAME_LOADING implementation\n--------------------------------\n\nTo test the implementation of the `GAME_LOADING` mode, use [`android.gamemanager.cts.GameManagerTest#testSetGameContext`](https://cs.android.com/android/platform/superproject/+/android-latest-release:cts//tests/tests/gamemanager/src/android/gamemanager/cts/GameManagerTest.java).\nThis test verifies if `GameManager::setGameContext()` with an `isLoading`\ncontext invokes the game loading mode on the Power HAL in performance mode.\n| **Note:** Because the implementation of these modes is hardware specific, OEMs must perform their own manual tests to see if game performance is enhanced and the game loading times are decreased while using this feature. Measuring an improvement in the performance boost can be difficult. Hence, it might be necessary to perform many tests using different boost configurations to determine if improvements are being made."]]