Guard the mode configs map in GamePackageConfiguration with lock am: 1ddd0c1b95

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20228875

Change-Id: I2ffd72519e373fac60bd2cc4d51cfc02dc7f4eb3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Xiang Wang
2022-10-27 17:55:53 +00:00
committed by Automerger Merge Worker

View File

@@ -554,6 +554,8 @@ public final class GameManagerService extends IGameManagerService.Stub {
private static final String GAME_MODE_CONFIG_NODE_NAME = "game-mode-config"; private static final String GAME_MODE_CONFIG_NODE_NAME = "game-mode-config";
private final String mPackageName; private final String mPackageName;
private final Object mModeConfigLock = new Object();
@GuardedBy("mModeConfigLock")
private final ArrayMap<Integer, GameModeConfiguration> mModeConfigs; private final ArrayMap<Integer, GameModeConfiguration> mModeConfigs;
private boolean mPerfModeOptedIn = false; private boolean mPerfModeOptedIn = false;
private boolean mBatteryModeOptedIn = false; private boolean mBatteryModeOptedIn = false;
@@ -694,11 +696,11 @@ public final class GameManagerService extends IGameManagerService.Stub {
return mGameMode; return mGameMode;
} }
public String getScaling() { public synchronized String getScaling() {
return mScaling; return mScaling;
} }
public int getFps() { public synchronized int getFps() {
return GameManagerService.getFpsInt(mFps); return GameManagerService.getFpsInt(mFps);
} }
@@ -710,11 +712,11 @@ public final class GameManagerService extends IGameManagerService.Stub {
return mLoadingBoostDuration; return mLoadingBoostDuration;
} }
public void setScaling(String scaling) { public synchronized void setScaling(String scaling) {
mScaling = scaling; mScaling = scaling;
} }
public void setFpsStr(String fpsStr) { public synchronized void setFpsStr(String fpsStr) {
mFps = fpsStr; mFps = fpsStr;
} }
@@ -761,9 +763,11 @@ public final class GameManagerService extends IGameManagerService.Stub {
private int getAvailableGameModesBitfield() { private int getAvailableGameModesBitfield() {
int field = 0; int field = 0;
synchronized (mModeConfigLock) {
for (final int mode : mModeConfigs.keySet()) { for (final int mode : mModeConfigs.keySet()) {
field |= modeToBitmask(mode); field |= modeToBitmask(mode);
} }
}
if (mBatteryModeOptedIn) { if (mBatteryModeOptedIn) {
field |= modeToBitmask(GameManager.GAME_MODE_BATTERY); field |= modeToBitmask(GameManager.GAME_MODE_BATTERY);
} }
@@ -803,15 +807,19 @@ public final class GameManagerService extends IGameManagerService.Stub {
* @return The package's GameModeConfiguration for the provided mode or null if absent * @return The package's GameModeConfiguration for the provided mode or null if absent
*/ */
public GameModeConfiguration getGameModeConfiguration(@GameMode int gameMode) { public GameModeConfiguration getGameModeConfiguration(@GameMode int gameMode) {
synchronized (mModeConfigLock) {
return mModeConfigs.get(gameMode); return mModeConfigs.get(gameMode);
} }
}
/** /**
* Insert a new GameModeConfiguration * Insert a new GameModeConfiguration
*/ */
public void addModeConfig(GameModeConfiguration config) { public void addModeConfig(GameModeConfiguration config) {
if (config.isActive()) { if (config.isActive()) {
synchronized (mModeConfigLock) {
mModeConfigs.put(config.getGameMode(), config); mModeConfigs.put(config.getGameMode(), config);
}
} else { } else {
Slog.w(TAG, "Attempt to add inactive game mode config for " Slog.w(TAG, "Attempt to add inactive game mode config for "
+ mPackageName + ":" + config.toString()); + mPackageName + ":" + config.toString());
@@ -819,13 +827,17 @@ public final class GameManagerService extends IGameManagerService.Stub {
} }
public boolean isActive() { public boolean isActive() {
synchronized (mModeConfigLock) {
return mModeConfigs.size() > 0 || mBatteryModeOptedIn || mPerfModeOptedIn; return mModeConfigs.size() > 0 || mBatteryModeOptedIn || mPerfModeOptedIn;
} }
}
public String toString() { public String toString() {
synchronized (mModeConfigLock) {
return "[Name:" + mPackageName + " Modes: " + mModeConfigs.toString() + "]"; return "[Name:" + mPackageName + " Modes: " + mModeConfigs.toString() + "]";
} }
} }
}
/** /**
* SystemService lifecycle for GameService. * SystemService lifecycle for GameService.
@@ -894,15 +906,7 @@ public final class GameManagerService extends IGameManagerService.Stub {
} }
private @GameMode int[] getAvailableGameModesUnchecked(String packageName) { private @GameMode int[] getAvailableGameModesUnchecked(String packageName) {
GamePackageConfiguration config = null; final GamePackageConfiguration config = getConfig(packageName);
synchronized (mOverrideConfigLock) {
config = mOverrideConfigs.get(packageName);
}
if (config == null) {
synchronized (mDeviceConfigLock) {
config = mConfigs.get(packageName);
}
}
if (config == null) { if (config == null) {
return new int[]{}; return new int[]{};
} }
@@ -1055,12 +1059,13 @@ public final class GameManagerService extends IGameManagerService.Stub {
if (gameMode == GameManager.GAME_MODE_UNSUPPORTED) { if (gameMode == GameManager.GAME_MODE_UNSUPPORTED) {
return false; return false;
} }
final GamePackageConfiguration config;
synchronized (mDeviceConfigLock) { synchronized (mDeviceConfigLock) {
final GamePackageConfiguration config = mConfigs.get(packageName); config = mConfigs.get(packageName);
if (config == null) { if (config == null) {
return false; return false;
} }
}
GamePackageConfiguration.GameModeConfiguration gameModeConfiguration = GamePackageConfiguration.GameModeConfiguration gameModeConfiguration =
config.getGameModeConfiguration(gameMode); config.getGameModeConfiguration(gameMode);
if (gameModeConfiguration == null) { if (gameModeConfiguration == null) {
@@ -1068,7 +1073,6 @@ public final class GameManagerService extends IGameManagerService.Stub {
} }
return gameModeConfiguration.getUseAngle(); return gameModeConfiguration.getUseAngle();
} }
}
/** /**
* If loading boost is applicable for the package for the currently enabled game mode, return * If loading boost is applicable for the package for the currently enabled game mode, return
@@ -1082,9 +1086,10 @@ public final class GameManagerService extends IGameManagerService.Stub {
if (gameMode == GameManager.GAME_MODE_UNSUPPORTED) { if (gameMode == GameManager.GAME_MODE_UNSUPPORTED) {
return -1; return -1;
} }
final GamePackageConfiguration config;
synchronized (mDeviceConfigLock) { synchronized (mDeviceConfigLock) {
final GamePackageConfiguration config = mConfigs.get(packageName); config = mConfigs.get(packageName);
}
if (config == null) { if (config == null) {
return -1; return -1;
} }
@@ -1095,7 +1100,6 @@ public final class GameManagerService extends IGameManagerService.Stub {
} }
return gameModeConfiguration.getLoadingBoostDuration(); return gameModeConfiguration.getLoadingBoostDuration();
} }
}
/** /**
* If loading boost is enabled, invoke it. * If loading boost is enabled, invoke it.
@@ -1364,18 +1368,7 @@ public final class GameManagerService extends IGameManagerService.Stub {
resetFps(packageName, userId); resetFps(packageName, userId);
return; return;
} }
GamePackageConfiguration packageConfig = null; final GamePackageConfiguration packageConfig = getConfig(packageName);
synchronized (mOverrideConfigLock) {
packageConfig = mOverrideConfigs.get(packageName);
}
if (packageConfig == null) {
synchronized (mDeviceConfigLock) {
packageConfig = mConfigs.get(packageName);
}
}
if (packageConfig == null) { if (packageConfig == null) {
disableCompatScale(packageName); disableCompatScale(packageName);
Slog.v(TAG, "Package configuration not found for " + packageName); Slog.v(TAG, "Package configuration not found for " + packageName);
@@ -1404,14 +1397,15 @@ public final class GameManagerService extends IGameManagerService.Stub {
} }
} }
// Adding override game mode configuration of the given package name // Adding override game mode configuration of the given package name
GamePackageConfiguration overrideConfig;
synchronized (mOverrideConfigLock) { synchronized (mOverrideConfigLock) {
// look for the existing override GamePackageConfiguration // look for the existing override GamePackageConfiguration
GamePackageConfiguration overrideConfig = mOverrideConfigs.get(packageName); overrideConfig = mOverrideConfigs.get(packageName);
if (overrideConfig == null) { if (overrideConfig == null) {
overrideConfig = new GamePackageConfiguration(packageName, userId); overrideConfig = new GamePackageConfiguration(packageName, userId);
mOverrideConfigs.put(packageName, overrideConfig); mOverrideConfigs.put(packageName, overrideConfig);
} }
}
// modify GameModeConfiguration intervention settings // modify GameModeConfiguration intervention settings
GamePackageConfiguration.GameModeConfiguration overrideModeConfig = GamePackageConfiguration.GameModeConfiguration overrideModeConfig =
overrideConfig.getGameModeConfiguration(gameMode); overrideConfig.getGameModeConfiguration(gameMode);
@@ -1431,7 +1425,6 @@ public final class GameManagerService extends IGameManagerService.Stub {
Slog.i(TAG, "Package Name: " + packageName Slog.i(TAG, "Package Name: " + packageName
+ " FPS: " + String.valueOf(overrideModeConfig.getFps()) + " FPS: " + String.valueOf(overrideModeConfig.getFps())
+ " Scaling: " + overrideModeConfig.getScaling()); + " Scaling: " + overrideModeConfig.getScaling());
}
setGameMode(packageName, gameMode, userId); setGameMode(packageName, gameMode, userId);
} }
@@ -1497,15 +1490,7 @@ public final class GameManagerService extends IGameManagerService.Stub {
// If not, set the game mode to standard // If not, set the game mode to standard
int gameMode = getGameMode(packageName, userId); int gameMode = getGameMode(packageName, userId);
GamePackageConfiguration config = null; final GamePackageConfiguration config = getConfig(packageName);
synchronized (mOverrideConfigLock) {
config = mOverrideConfigs.get(packageName);
}
if (config == null) {
synchronized (mDeviceConfigLock) {
config = mConfigs.get(packageName);
}
}
final int newGameMode = getNewGameMode(gameMode, config); final int newGameMode = getNewGameMode(gameMode, config);
if (gameMode != newGameMode) { if (gameMode != newGameMode) {
setGameMode(packageName, GameManager.GAME_MODE_STANDARD, userId); setGameMode(packageName, GameManager.GAME_MODE_STANDARD, userId);
@@ -1544,18 +1529,8 @@ public final class GameManagerService extends IGameManagerService.Stub {
* Returns the string listing all the interventions currently set to a game. * Returns the string listing all the interventions currently set to a game.
*/ */
public String getInterventionList(String packageName) { public String getInterventionList(String packageName) {
GamePackageConfiguration packageConfig = null; final GamePackageConfiguration packageConfig = getConfig(packageName);
synchronized (mOverrideConfigLock) { final StringBuilder listStrSb = new StringBuilder();
packageConfig = mOverrideConfigs.get(packageName);
}
if (packageConfig == null) {
synchronized (mDeviceConfigLock) {
packageConfig = mConfigs.get(packageName);
}
}
StringBuilder listStrSb = new StringBuilder();
if (packageConfig == null) { if (packageConfig == null) {
listStrSb.append("\n No intervention found for package ") listStrSb.append("\n No intervention found for package ")
.append(packageName); .append(packageName);