Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 04528d73 authored by Peiyong Lin's avatar Peiyong Lin Committed by Automerger Merge Worker
Browse files

Merge "Update shell command line to take optional user id." into sc-dev am:...

Merge "Update shell command line to take optional user id." into sc-dev am: c030fb12 am: 69ffb961

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

Change-Id: I6ccf293dca69b3c9d0c67ed70fddc5db4f817bba
parents 976c9a89 69ffb961
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -469,9 +469,10 @@ public final class GameManagerService extends IGameManagerService.Stub {
        }
    }

    private boolean isValidPackageName(String packageName) {
    private boolean isValidPackageName(String packageName, int userId) {
        try {
            return mPackageManager.getPackageUid(packageName, 0) == Binder.getCallingUid();
            return mPackageManager.getPackageUidAsUser(packageName, userId)
                    == Binder.getCallingUid();
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return false;
@@ -547,7 +548,7 @@ public final class GameManagerService extends IGameManagerService.Stub {
        // The least privileged case is a normal app performing a query, so check that first and
        // return a value if the package name is valid. Next, check if the caller has the necessary
        // permission and return a value. Do this check last, since it can throw an exception.
        if (isValidPackageName(packageName)) {
        if (isValidPackageName(packageName, userId)) {
            return getGameModeFromSettings(packageName, userId);
        }

+11 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.app;

import android.app.ActivityManager;
import android.app.GameManager;
import android.app.IGameManagerService;
import android.compat.Compatibility;
@@ -127,9 +128,14 @@ public class GameManagerShellCommand extends ShellCommand {
                     *          <PACKAGE_NAME> <CONFIG_STRING>`
                     * see: {@link GameManagerServiceTests#mockDeviceConfigAll()}
                     */
                    final String option = getNextOption();
                    String userIdStr = null;
                    if (option != null && option.equals("--user")) {
                        userIdStr = getNextArgRequired();
                    }

                    final String gameMode = getNextArgRequired();
                    final String packageName = getNextArgRequired();
                    final String userIdStr = getNextArgRequired();
                    final IGameManagerService service = IGameManagerService.Stub.asInterface(
                            ServiceManager.getServiceOrThrow(Context.GAME_SERVICE));
                    boolean batteryModeSupported = false;
@@ -142,7 +148,8 @@ public class GameManagerShellCommand extends ShellCommand {
                            batteryModeSupported = true;
                        }
                    }
                    int userId = Integer.parseInt(userIdStr);
                    int userId = userIdStr != null ? Integer.parseInt(userIdStr)
                            : ActivityManager.getCurrentUser();
                    switch (gameMode.toLowerCase()) {
                        case "1":
                        case "standard":
@@ -199,7 +206,8 @@ public class GameManagerShellCommand extends ShellCommand {
        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.");
        pw.println("  mode [1|2|3|standard|performance|battery] <PACKAGE_NAME> <USER_ID>");
        pw.println("  mode [--user <USER_ID>] [1|2|3|standard|performance|battery] <PACKAGE_NAME>");
        pw.println("      Force app to run in the specified game mode, if supported.");
        pw.println("      --user <USER_ID>: apply for the given user, the current user is used when unspecified.");
    }
}