Fix failing GameManagerServiceTests

The following tests are currently failing:

- com.android.server.app.GameManagerServiceTests#testDeviceConfigInvalid
- com.android.server.app.GameManagerServiceTests#testSetGameModePermissionDenied
  - This is actually flaky, rather than consistently failing.

testDeviceConfigInvalid is failing because the current config string is
actually valid. This test is fixed by updating the string to actually
be invalid by making it empty.

testSetGameModePermissionDenied is failing because the test package
doesn't have any valid configs, so the call to getGameMode() returns
GAME_MODE_UNSUPPORTED rather than GAME_MODE_STANDARD. This is fixed by
calling mockDeviceConfigAll() at the start of the test.

Test: GameManagerServiceTests#testDeviceConfigInvalid
Test: GameManagerServiceTests#testSetGameModePermissionDenied
Bug: b/193794028
Change-Id: I4d4581c37c31f6234b825f6b557b1e7dd4ce1c77
(cherry picked from commit f13fe0ccea)
This commit is contained in:
Tim Van Patten
2021-07-15 11:04:10 -06:00
parent 4de992c9cb
commit bb5a62d8d7

View File

@@ -207,7 +207,7 @@ public class GameManagerServiceTests {
}
private void mockDeviceConfigInvalid() {
String configString = "mode=2,downscaleFactor=0.55";
String configString = "";
when(DeviceConfig.getProperty(anyString(), anyString()))
.thenReturn(configString);
}
@@ -373,11 +373,12 @@ public class GameManagerServiceTests {
*/
@Test
public void testSetGameModePermissionDenied() {
mockModifyGameModeGranted();
mockDeviceConfigAll();
GameManagerService gameManagerService = new GameManagerService(mMockContext);
gameManagerService.onUserStarting(USER_ID_1);
// Update the game mode so we can read back something valid.
mockModifyGameModeGranted();
gameManagerService.setGameMode(mPackageName, GameManager.GAME_MODE_STANDARD, USER_ID_1);
assertEquals(GameManager.GAME_MODE_STANDARD,
gameManagerService.getGameMode(mPackageName, USER_ID_1));