Merge "Make sure all game modes are looped." into sc-dev

This commit is contained in:
Peiyong Lin
2021-05-22 00:12:42 +00:00
committed by Android (Google) Code Review
2 changed files with 6 additions and 6 deletions

View File

@@ -387,12 +387,12 @@ public final class GameManagerService extends IGameManagerService.Stub {
* Get an array of a package's available game modes. * Get an array of a package's available game modes.
*/ */
public @GameMode int[] getAvailableGameModes() { public @GameMode int[] getAvailableGameModes() {
final int modesBitfield = getAvailableGameModesBitfield();
int modesBitfield = getAvailableGameModesBitfield(); int[] modes = new int[Integer.bitCount(modesBitfield)];
int sigBits = Integer.bitCount(modesBitfield);
int[] modes = new int[sigBits];
int i = 0; int i = 0;
for (int mode = 0; mode < sigBits; ++mode) { final int gameModeInHighestBit =
Integer.numberOfTrailingZeros(Integer.highestOneBit(modesBitfield));
for (int mode = 0; mode <= gameModeInHighestBit; ++mode) {
if (((modesBitfield >> mode) & 1) != 0) { if (((modesBitfield >> mode) & 1) != 0) {
modes[i++] = mode; modes[i++] = mode;
} }

View File

@@ -412,7 +412,7 @@ public class GameManagerServiceTests {
reportedModes.add(mode); reportedModes.add(mode);
} }
assertEquals(requiredModes.length, reportedModes.size()); assertEquals(requiredModes.length, reportedModes.size());
for (int requiredMode : reportedModes) { for (int requiredMode : requiredModes) {
assertTrue("Required game mode not supported: " + requiredMode, assertTrue("Required game mode not supported: " + requiredMode,
reportedModes.contains(requiredMode)); reportedModes.contains(requiredMode));
} }