summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/app/GameManagerService.java10
-rw-r--r--services/core/java/com/android/server/app/GameManagerShellCommand.java136
2 files changed, 146 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/app/GameManagerService.java b/services/core/java/com/android/server/app/GameManagerService.java
index 0eae6617ba86..d35c0b8b8e77 100644
--- a/services/core/java/com/android/server/app/GameManagerService.java
+++ b/services/core/java/com/android/server/app/GameManagerService.java
@@ -31,6 +31,8 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
+import android.os.ResultReceiver;
+import android.os.ShellCallback;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Slog;
@@ -40,6 +42,8 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.server.ServiceThread;
import com.android.server.SystemService;
+import java.io.FileDescriptor;
+
/**
* Service to manage game related features.
*
@@ -72,6 +76,12 @@ public final class GameManagerService extends IGameManagerService.Stub {
mHandler = new SettingsHandler(looper);
}
+ @Override
+ public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
+ String[] args, ShellCallback callback, ResultReceiver result) {
+ new GameManagerShellCommand().exec(this, in, out, err, args, callback, result);
+ }
+
class SettingsHandler extends Handler {
SettingsHandler(Looper looper) {
diff --git a/services/core/java/com/android/server/app/GameManagerShellCommand.java b/services/core/java/com/android/server/app/GameManagerShellCommand.java
new file mode 100644
index 000000000000..e4c0002ab513
--- /dev/null
+++ b/services/core/java/com/android/server/app/GameManagerShellCommand.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.app;
+
+import android.compat.Compatibility;
+import android.content.Context;
+import android.os.ServiceManager;
+import android.os.ShellCommand;
+import android.util.ArraySet;
+
+import com.android.internal.compat.CompatibilityChangeConfig;
+import com.android.server.compat.PlatformCompat;
+import com.android.server.wm.CompatModePackages;
+
+import java.io.PrintWriter;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * ShellCommands for GameManagerService.
+ *
+ * Use with {@code adb shell cmd game ...}.
+ */
+public class GameManagerShellCommand extends ShellCommand {
+
+ public GameManagerShellCommand() {}
+
+ private static final ArraySet<Long> DOWNSCALE_CHANGE_IDS = new ArraySet<>(new Long[]{
+ CompatModePackages.DOWNSCALED,
+ CompatModePackages.DOWNSCALE_90,
+ CompatModePackages.DOWNSCALE_80,
+ CompatModePackages.DOWNSCALE_70,
+ CompatModePackages.DOWNSCALE_60,
+ CompatModePackages.DOWNSCALE_50});
+
+ @Override
+ public int onCommand(String cmd) {
+ if (cmd == null) {
+ return handleDefaultCommands(cmd);
+ }
+ final PrintWriter pw = getOutPrintWriter();
+ try {
+ switch (cmd) {
+ case "downscale":
+ final String ratio = getNextArgRequired();
+ final String packageName = getNextArgRequired();
+
+ final long changeId;
+ switch (ratio) {
+ case "0.5":
+ changeId = CompatModePackages.DOWNSCALE_50;
+ break;
+ case "0.6":
+ changeId = CompatModePackages.DOWNSCALE_60;
+ break;
+ case "0.7":
+ changeId = CompatModePackages.DOWNSCALE_70;
+ break;
+ case "0.8":
+ changeId = CompatModePackages.DOWNSCALE_80;
+ break;
+ case "0.9":
+ changeId = CompatModePackages.DOWNSCALE_90;
+ break;
+ case "disable":
+ changeId = 0;
+ break;
+ default:
+ changeId = -1;
+ pw.println("Invalid scaling ratio '" + ratio + "'");
+ break;
+ }
+ if (changeId == -1) {
+ break;
+ }
+
+ Set<Long> enabled = new ArraySet<>();
+ Set<Long> disabled;
+ if (changeId == 0) {
+ disabled = DOWNSCALE_CHANGE_IDS;
+ } else {
+ enabled.add(CompatModePackages.DOWNSCALED);
+ enabled.add(changeId);
+ disabled = DOWNSCALE_CHANGE_IDS.stream()
+ .filter(it -> it != CompatModePackages.DOWNSCALED && it != changeId)
+ .collect(Collectors.toSet());
+ }
+
+ final PlatformCompat platformCompat = (PlatformCompat)
+ ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE);
+ final CompatibilityChangeConfig overrides =
+ new CompatibilityChangeConfig(
+ new Compatibility.ChangeConfig(enabled, disabled));
+
+ platformCompat.setOverrides(overrides, packageName);
+ if (changeId == 0) {
+ pw.println("Disable downscaling for " + packageName + ".");
+ } else {
+ pw.println("Enable downscaling ratio for " + packageName + " to " + ratio);
+ }
+
+ break;
+ default:
+ return handleDefaultCommands(cmd);
+ }
+ } catch (Exception e) {
+ pw.println("Error: " + e);
+ }
+ return -1;
+ }
+
+
+ @Override
+ public void onHelp() {
+ PrintWriter pw = getOutPrintWriter();
+ pw.println("Game manager (game) commands:");
+ pw.println(" help");
+ pw.println(" Print this help text.");
+ pw.println(" downscale [0.5|0.6|0.7|0.8|0.9|disable] <PACKAGE_NAME>");
+ pw.println(" Force app to run at the specified scaling ratio.");
+ }
+}