Merge "Update shell command line to take optional user id." into sc-dev
This commit is contained in:
@@ -469,9 +469,10 @@ public final class GameManagerService extends IGameManagerService.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isValidPackageName(String packageName) {
|
private boolean isValidPackageName(String packageName, int userId) {
|
||||||
try {
|
try {
|
||||||
return mPackageManager.getPackageUid(packageName, 0) == Binder.getCallingUid();
|
return mPackageManager.getPackageUidAsUser(packageName, userId)
|
||||||
|
== Binder.getCallingUid();
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
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
|
// 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
|
// 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.
|
// 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);
|
return getGameModeFromSettings(packageName, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.server.app;
|
package com.android.server.app;
|
||||||
|
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.app.GameManager;
|
import android.app.GameManager;
|
||||||
import android.app.IGameManagerService;
|
import android.app.IGameManagerService;
|
||||||
import android.compat.Compatibility;
|
import android.compat.Compatibility;
|
||||||
@@ -127,9 +128,14 @@ public class GameManagerShellCommand extends ShellCommand {
|
|||||||
* <PACKAGE_NAME> <CONFIG_STRING>`
|
* <PACKAGE_NAME> <CONFIG_STRING>`
|
||||||
* see: {@link GameManagerServiceTests#mockDeviceConfigAll()}
|
* 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 gameMode = getNextArgRequired();
|
||||||
final String packageName = getNextArgRequired();
|
final String packageName = getNextArgRequired();
|
||||||
final String userIdStr = getNextArgRequired();
|
|
||||||
final IGameManagerService service = IGameManagerService.Stub.asInterface(
|
final IGameManagerService service = IGameManagerService.Stub.asInterface(
|
||||||
ServiceManager.getServiceOrThrow(Context.GAME_SERVICE));
|
ServiceManager.getServiceOrThrow(Context.GAME_SERVICE));
|
||||||
boolean batteryModeSupported = false;
|
boolean batteryModeSupported = false;
|
||||||
@@ -142,7 +148,8 @@ public class GameManagerShellCommand extends ShellCommand {
|
|||||||
batteryModeSupported = true;
|
batteryModeSupported = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int userId = Integer.parseInt(userIdStr);
|
int userId = userIdStr != null ? Integer.parseInt(userIdStr)
|
||||||
|
: ActivityManager.getCurrentUser();
|
||||||
switch (gameMode.toLowerCase()) {
|
switch (gameMode.toLowerCase()) {
|
||||||
case "1":
|
case "1":
|
||||||
case "standard":
|
case "standard":
|
||||||
@@ -199,7 +206,8 @@ public class GameManagerShellCommand extends ShellCommand {
|
|||||||
pw.println(" Print this help text.");
|
pw.println(" Print this help text.");
|
||||||
pw.println(" downscale [0.5|0.6|0.7|0.8|0.9|disable] <PACKAGE_NAME>");
|
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(" 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(" 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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user