Make sure all game modes are looped.

Previously when switched to use bitfield, we use bit count of 1 to check
all game modes. This patch makes sure all game modes are properly
checked.

Bug: b/188729014
Test: atest GameManagerServiceTests
Change-Id: Ia7a9cb925ba9b26f7ff7136ec60758e28a467573
This commit is contained in:
Peiyong Lin
2021-05-20 09:18:37 +00:00
parent 5eef411480
commit b4ade2ad53
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.
*/
public @GameMode int[] getAvailableGameModes() {
int modesBitfield = getAvailableGameModesBitfield();
int sigBits = Integer.bitCount(modesBitfield);
int[] modes = new int[sigBits];
final int modesBitfield = getAvailableGameModesBitfield();
int[] modes = new int[Integer.bitCount(modesBitfield)];
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) {
modes[i++] = mode;
}

View File

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