Loading services/core/java/com/android/server/app/GameManagerService.java +7 −12 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import static android.content.Intent.ACTION_PACKAGE_ADDED; import static android.content.Intent.ACTION_PACKAGE_REMOVED; import static android.content.Intent.EXTRA_REPLACING; import static android.server.app.Flags.gameDefaultFrameRate; import static android.server.app.Flags.disableGameModeWhenAppTop; import static com.android.internal.R.styleable.GameModeConfig_allowGameAngleDriver; import static com.android.internal.R.styleable.GameModeConfig_allowGameDownscaling; Loading Loading @@ -2327,17 +2326,14 @@ public final class GameManagerService extends IGameManagerService.Stub { p -> isPackageGame(p, userId)); synchronized (mUidObserverLock) { if (isNotGame) { if (disableGameModeWhenAppTop()) { if (!mGameForegroundUids.isEmpty() && mNonGameForegroundUids.isEmpty()) { Slog.v(TAG, "Game power mode OFF (first non-game in foreground)"); mPowerManagerInternal.setPowerMode(Mode.GAME, false); } mNonGameForegroundUids.add(uid); } return; } if (mGameForegroundUids.isEmpty() && (!disableGameModeWhenAppTop() || mNonGameForegroundUids.isEmpty())) { if (mGameForegroundUids.isEmpty() && mNonGameForegroundUids.isEmpty()) { Slog.v(TAG, "Game power mode ON (first game in foreground)"); mPowerManagerInternal.setPowerMode(Mode.GAME, true); } Loading @@ -2354,12 +2350,11 @@ public final class GameManagerService extends IGameManagerService.Stub { synchronized (mUidObserverLock) { if (mGameForegroundUids.contains(uid)) { mGameForegroundUids.remove(uid); if (mGameForegroundUids.isEmpty() && (!disableGameModeWhenAppTop() || mNonGameForegroundUids.isEmpty())) { if (mGameForegroundUids.isEmpty() && mNonGameForegroundUids.isEmpty()) { Slog.v(TAG, "Game power mode OFF (no games in foreground)"); mPowerManagerInternal.setPowerMode(Mode.GAME, false); } } else if (disableGameModeWhenAppTop() && mNonGameForegroundUids.contains(uid)) { } else if (mNonGameForegroundUids.contains(uid)) { mNonGameForegroundUids.remove(uid); if (mNonGameForegroundUids.isEmpty() && !mGameForegroundUids.isEmpty()) { Slog.v(TAG, "Game power mode ON (only games in foreground)"); Loading services/core/java/com/android/server/app/flags.aconfig +0 −7 Original line number Diff line number Diff line Loading @@ -8,10 +8,3 @@ flag { bug: "286084594" is_fixed_read_only: true } flag { name: "disable_game_mode_when_app_top" namespace: "game" description: "Disable game power mode when a non-game app is also top and visible" bug: "299295925" } services/tests/mockingservicestests/src/com/android/server/app/GameManagerServiceTests.java +1 −67 Original line number Diff line number Diff line Loading @@ -246,7 +246,6 @@ public class GameManagerServiceTests { LocalServices.addService(PowerManagerInternal.class, mMockPowerManager); mSetFlagsRule.enableFlags(Flags.FLAG_GAME_DEFAULT_FRAME_RATE); mSetFlagsRule.disableFlags(Flags.FLAG_DISABLE_GAME_MODE_WHEN_APP_TOP); } private void mockAppCategory(String packageName, int packageUid, Loading Loading @@ -2403,8 +2402,7 @@ public class GameManagerServiceTests { } @Test public void testGamePowerMode_gameAndNotGameApps_flagOn() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_DISABLE_GAME_MODE_WHEN_APP_TOP); public void testGamePowerMode_gameAndNotGameApps() throws Exception { GameManagerService gameManagerService = new GameManagerService(mMockContext, mTestLooper.getLooper()); int userId = ActivityManager.getCurrentUser(); Loading Loading @@ -2490,70 +2488,6 @@ public class GameManagerServiceTests { clearInvocations(mMockPowerManager); } @Test public void testGamePowerMode_gameAndNotGameApps_flagOff() throws Exception { mSetFlagsRule.disableFlags(Flags.FLAG_DISABLE_GAME_MODE_WHEN_APP_TOP); int userId = ActivityManager.getCurrentUser(); GameManagerService gameManagerService = new GameManagerService(mMockContext, mTestLooper.getLooper()); String nonGamePkg1 = "not.game1"; int nonGameUid1 = DEFAULT_PACKAGE_UID + 1; mockAppCategory(nonGamePkg1, nonGameUid1, ApplicationInfo.CATEGORY_IMAGE, userId); String gamePkg1 = "game1"; int gameUid1 = DEFAULT_PACKAGE_UID + 3; mockAppCategory(gamePkg1, gameUid1, ApplicationInfo.CATEGORY_GAME, userId); // non-game1 top and background with no-op gameManagerService.mUidObserver.onUidStateChanged( nonGameUid1, ActivityManager.PROCESS_STATE_TOP, 0, 0); gameManagerService.mUidObserver.onUidStateChanged( nonGameUid1, ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND, 0, 0); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, true); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, false); clearInvocations(mMockPowerManager); // game1 top to enable game mode gameManagerService.mUidObserver.onUidStateChanged( gameUid1, ActivityManager.PROCESS_STATE_TOP, 0, 0); verify(mMockPowerManager, times(1)).setPowerMode(Mode.GAME, true); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, false); clearInvocations(mMockPowerManager); // non-game1 in foreground to not interfere gameManagerService.mUidObserver.onUidStateChanged( nonGameUid1, ActivityManager.PROCESS_STATE_TOP, 0, 0); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, true); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, false); clearInvocations(mMockPowerManager); // non-game 1 in background to not interfere gameManagerService.mUidObserver.onUidStateChanged( nonGameUid1, ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND, 0, 0); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, true); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, false); clearInvocations(mMockPowerManager); // move non-game1 to foreground again gameManagerService.mUidObserver.onUidStateChanged( nonGameUid1, ActivityManager.PROCESS_STATE_TOP, 0, 0); // with non-game1 on top, game 1 in background to still disable game mode gameManagerService.mUidObserver.onUidStateChanged( gameUid1, ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND, 0, 0); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, true); verify(mMockPowerManager, times(1)).setPowerMode(Mode.GAME, false); clearInvocations(mMockPowerManager); // with non-game1 on top, game 1 in foreground to still enable game mode gameManagerService.mUidObserver.onUidStateChanged( gameUid1, ActivityManager.PROCESS_STATE_TOP, 0, 0); verify(mMockPowerManager, times(1)).setPowerMode(Mode.GAME, true); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, false); clearInvocations(mMockPowerManager); } @Test public void testGameDefaultFrameRate_FlagOn() throws Exception { mFakePermissionEnforcer.grant(Manifest.permission.MANAGE_GAME_MODE); Loading Loading
services/core/java/com/android/server/app/GameManagerService.java +7 −12 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import static android.content.Intent.ACTION_PACKAGE_ADDED; import static android.content.Intent.ACTION_PACKAGE_REMOVED; import static android.content.Intent.EXTRA_REPLACING; import static android.server.app.Flags.gameDefaultFrameRate; import static android.server.app.Flags.disableGameModeWhenAppTop; import static com.android.internal.R.styleable.GameModeConfig_allowGameAngleDriver; import static com.android.internal.R.styleable.GameModeConfig_allowGameDownscaling; Loading Loading @@ -2327,17 +2326,14 @@ public final class GameManagerService extends IGameManagerService.Stub { p -> isPackageGame(p, userId)); synchronized (mUidObserverLock) { if (isNotGame) { if (disableGameModeWhenAppTop()) { if (!mGameForegroundUids.isEmpty() && mNonGameForegroundUids.isEmpty()) { Slog.v(TAG, "Game power mode OFF (first non-game in foreground)"); mPowerManagerInternal.setPowerMode(Mode.GAME, false); } mNonGameForegroundUids.add(uid); } return; } if (mGameForegroundUids.isEmpty() && (!disableGameModeWhenAppTop() || mNonGameForegroundUids.isEmpty())) { if (mGameForegroundUids.isEmpty() && mNonGameForegroundUids.isEmpty()) { Slog.v(TAG, "Game power mode ON (first game in foreground)"); mPowerManagerInternal.setPowerMode(Mode.GAME, true); } Loading @@ -2354,12 +2350,11 @@ public final class GameManagerService extends IGameManagerService.Stub { synchronized (mUidObserverLock) { if (mGameForegroundUids.contains(uid)) { mGameForegroundUids.remove(uid); if (mGameForegroundUids.isEmpty() && (!disableGameModeWhenAppTop() || mNonGameForegroundUids.isEmpty())) { if (mGameForegroundUids.isEmpty() && mNonGameForegroundUids.isEmpty()) { Slog.v(TAG, "Game power mode OFF (no games in foreground)"); mPowerManagerInternal.setPowerMode(Mode.GAME, false); } } else if (disableGameModeWhenAppTop() && mNonGameForegroundUids.contains(uid)) { } else if (mNonGameForegroundUids.contains(uid)) { mNonGameForegroundUids.remove(uid); if (mNonGameForegroundUids.isEmpty() && !mGameForegroundUids.isEmpty()) { Slog.v(TAG, "Game power mode ON (only games in foreground)"); Loading
services/core/java/com/android/server/app/flags.aconfig +0 −7 Original line number Diff line number Diff line Loading @@ -8,10 +8,3 @@ flag { bug: "286084594" is_fixed_read_only: true } flag { name: "disable_game_mode_when_app_top" namespace: "game" description: "Disable game power mode when a non-game app is also top and visible" bug: "299295925" }
services/tests/mockingservicestests/src/com/android/server/app/GameManagerServiceTests.java +1 −67 Original line number Diff line number Diff line Loading @@ -246,7 +246,6 @@ public class GameManagerServiceTests { LocalServices.addService(PowerManagerInternal.class, mMockPowerManager); mSetFlagsRule.enableFlags(Flags.FLAG_GAME_DEFAULT_FRAME_RATE); mSetFlagsRule.disableFlags(Flags.FLAG_DISABLE_GAME_MODE_WHEN_APP_TOP); } private void mockAppCategory(String packageName, int packageUid, Loading Loading @@ -2403,8 +2402,7 @@ public class GameManagerServiceTests { } @Test public void testGamePowerMode_gameAndNotGameApps_flagOn() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_DISABLE_GAME_MODE_WHEN_APP_TOP); public void testGamePowerMode_gameAndNotGameApps() throws Exception { GameManagerService gameManagerService = new GameManagerService(mMockContext, mTestLooper.getLooper()); int userId = ActivityManager.getCurrentUser(); Loading Loading @@ -2490,70 +2488,6 @@ public class GameManagerServiceTests { clearInvocations(mMockPowerManager); } @Test public void testGamePowerMode_gameAndNotGameApps_flagOff() throws Exception { mSetFlagsRule.disableFlags(Flags.FLAG_DISABLE_GAME_MODE_WHEN_APP_TOP); int userId = ActivityManager.getCurrentUser(); GameManagerService gameManagerService = new GameManagerService(mMockContext, mTestLooper.getLooper()); String nonGamePkg1 = "not.game1"; int nonGameUid1 = DEFAULT_PACKAGE_UID + 1; mockAppCategory(nonGamePkg1, nonGameUid1, ApplicationInfo.CATEGORY_IMAGE, userId); String gamePkg1 = "game1"; int gameUid1 = DEFAULT_PACKAGE_UID + 3; mockAppCategory(gamePkg1, gameUid1, ApplicationInfo.CATEGORY_GAME, userId); // non-game1 top and background with no-op gameManagerService.mUidObserver.onUidStateChanged( nonGameUid1, ActivityManager.PROCESS_STATE_TOP, 0, 0); gameManagerService.mUidObserver.onUidStateChanged( nonGameUid1, ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND, 0, 0); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, true); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, false); clearInvocations(mMockPowerManager); // game1 top to enable game mode gameManagerService.mUidObserver.onUidStateChanged( gameUid1, ActivityManager.PROCESS_STATE_TOP, 0, 0); verify(mMockPowerManager, times(1)).setPowerMode(Mode.GAME, true); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, false); clearInvocations(mMockPowerManager); // non-game1 in foreground to not interfere gameManagerService.mUidObserver.onUidStateChanged( nonGameUid1, ActivityManager.PROCESS_STATE_TOP, 0, 0); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, true); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, false); clearInvocations(mMockPowerManager); // non-game 1 in background to not interfere gameManagerService.mUidObserver.onUidStateChanged( nonGameUid1, ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND, 0, 0); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, true); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, false); clearInvocations(mMockPowerManager); // move non-game1 to foreground again gameManagerService.mUidObserver.onUidStateChanged( nonGameUid1, ActivityManager.PROCESS_STATE_TOP, 0, 0); // with non-game1 on top, game 1 in background to still disable game mode gameManagerService.mUidObserver.onUidStateChanged( gameUid1, ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND, 0, 0); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, true); verify(mMockPowerManager, times(1)).setPowerMode(Mode.GAME, false); clearInvocations(mMockPowerManager); // with non-game1 on top, game 1 in foreground to still enable game mode gameManagerService.mUidObserver.onUidStateChanged( gameUid1, ActivityManager.PROCESS_STATE_TOP, 0, 0); verify(mMockPowerManager, times(1)).setPowerMode(Mode.GAME, true); verify(mMockPowerManager, never()).setPowerMode(Mode.GAME, false); clearInvocations(mMockPowerManager); } @Test public void testGameDefaultFrameRate_FlagOn() throws Exception { mFakePermissionEnforcer.grant(Manifest.permission.MANAGE_GAME_MODE); Loading