Correct package installation behaviour in GameManagerService
Previously when package is changed, GameManagerService always updates
the configuration, however, this is only necessary when package is
installed and removed. Hence correct the behaviour here to avoid
unnecessary. In the meantime, when a package is removed, also remove the
game mode set on the package because carrying the game mode for
uninstalled package is also unnecessary.
Bug: b/199920928
Test: atest GameManagerServiceTests
Change-Id: Idfd5c78776c182b37ef4c969991b1a4d88e65390
diff --git a/services/core/java/com/android/server/app/GameManagerService.java b/services/core/java/com/android/server/app/GameManagerService.java
index 551773e..9ba9d78 100644
--- a/services/core/java/com/android/server/app/GameManagerService.java
+++ b/services/core/java/com/android/server/app/GameManagerService.java
@@ -17,8 +17,8 @@
package com.android.server.app;
import static android.content.Intent.ACTION_PACKAGE_ADDED;
-import static android.content.Intent.ACTION_PACKAGE_CHANGED;
import static android.content.Intent.ACTION_PACKAGE_REMOVED;
+import static android.content.Intent.EXTRA_REPLACING;
import static com.android.internal.R.styleable.GameModeConfig_allowGameAngleDriver;
import static com.android.internal.R.styleable.GameModeConfig_allowGameDownscaling;
@@ -1467,7 +1467,6 @@
private void registerPackageReceiver() {
final IntentFilter packageFilter = new IntentFilter();
packageFilter.addAction(ACTION_PACKAGE_ADDED);
- packageFilter.addAction(ACTION_PACKAGE_CHANGED);
packageFilter.addAction(ACTION_PACKAGE_REMOVED);
packageFilter.addDataScheme("package");
final BroadcastReceiver packageReceiver = new BroadcastReceiver() {
@@ -1492,16 +1491,29 @@
}
switch (intent.getAction()) {
case ACTION_PACKAGE_ADDED:
- case ACTION_PACKAGE_CHANGED:
updateConfigsForUser(userId, packageName);
break;
case ACTION_PACKAGE_REMOVED:
disableCompatScale(packageName);
- synchronized (mOverrideConfigLock) {
- mOverrideConfigs.remove(packageName);
- }
- synchronized (mDeviceConfigLock) {
- mConfigs.remove(packageName);
+ // If EXTRA_REPLACING is true, it means there will be an
+ // ACTION_PACKAGE_ADDED triggered after this because this
+ // is an updated package that gets installed. Hence, disable
+ // resolution downscaling effort but avoid removing the server
+ // or commandline overriding configurations because those will
+ // not change but the package game mode configurations may change
+ // which may opt in and/or opt out some game mode configurations.
+ if (!intent.getBooleanExtra(EXTRA_REPLACING, false)) {
+ synchronized (mOverrideConfigLock) {
+ mOverrideConfigs.remove(packageName);
+ }
+ synchronized (mDeviceConfigLock) {
+ mConfigs.remove(packageName);
+ }
+ synchronized (mLock) {
+ if (mSettings.containsKey(userId)) {
+ mSettings.get(userId).removeGame(packageName);
+ }
+ }
}
break;
default:
diff --git a/services/core/java/com/android/server/app/GameManagerSettings.java b/services/core/java/com/android/server/app/GameManagerSettings.java
index 2982545..1455a61 100644
--- a/services/core/java/com/android/server/app/GameManagerSettings.java
+++ b/services/core/java/com/android/server/app/GameManagerSettings.java
@@ -93,6 +93,14 @@
}
/**
+ * Remove the game mode of a given package.
+ * This operation must be synced with an external lock.
+ */
+ void removeGame(String packageName) {
+ mGameModes.remove(packageName);
+ }
+
+ /**
* Write all current game service settings into disk.
* This operation must be synced with an external lock.
*/