Merge "Improvements on UserManagerService ShellCommand implementation (4/4)." into tm-dev am: f82c20ad5d
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17124768 Change-Id: Iaa6b7f7cd05be93e753e0205012ae32e11c467a4 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -5413,191 +5413,191 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
(new Shell()).exec(this, in, out, err, args, callback, resultReceiver);
|
(new Shell()).exec(this, in, out, err, args, callback, resultReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String PREFIX_HELP_COMMAND = " ";
|
|
||||||
private static final String PREFIX_HELP_DESCRIPTION = " ";
|
|
||||||
private static final String PREFIX_HELP_DESCRIPTION_EXTRA_LINES = " ";
|
|
||||||
|
|
||||||
private static final String CMD_HELP = "help";
|
|
||||||
private static final String CMD_LIST = "list";
|
|
||||||
private static final String CMD_REPORT_SYSTEM_USER_PACKAGE_ALLOWLIST_PROBLEMS =
|
|
||||||
"report-system-user-package-whitelist-problems";
|
|
||||||
|
|
||||||
private static final String ARG_V = "-v";
|
|
||||||
private static final String ARG_VERBOSE = "--verbose";
|
|
||||||
private static final String ARG_ALL = "--all";
|
|
||||||
private static final String ARG_CRITICAL_ONLY = "--critical-only";
|
|
||||||
private static final String ARG_MODE = "--mode";
|
|
||||||
|
|
||||||
private final class Shell extends ShellCommand {
|
private final class Shell extends ShellCommand {
|
||||||
|
|
||||||
@Override
|
private static final String PREFIX_HELP_COMMAND = " ";
|
||||||
public void onHelp() {
|
private static final String PREFIX_HELP_DESCRIPTION = " ";
|
||||||
final PrintWriter pw = getOutPrintWriter();
|
private static final String PREFIX_HELP_DESCRIPTION_EXTRA_LINES = " ";
|
||||||
pw.printf("User manager (user) commands:\n");
|
|
||||||
|
|
||||||
pw.printf("%s%s\n", PREFIX_HELP_COMMAND, CMD_HELP);
|
private static final String CMD_HELP = "help";
|
||||||
pw.printf("%sPrints this help text.\n\n", PREFIX_HELP_DESCRIPTION);
|
private static final String CMD_LIST = "list";
|
||||||
|
private static final String CMD_REPORT_SYSTEM_USER_PACKAGE_ALLOWLIST_PROBLEMS =
|
||||||
|
"report-system-user-package-whitelist-problems";
|
||||||
|
|
||||||
pw.printf("%s%s [%s] [%s]\n", PREFIX_HELP_COMMAND, CMD_LIST, ARG_V, ARG_ALL);
|
private static final String ARG_V = "-v";
|
||||||
pw.printf("%sPrints all users on the system.\n\n", PREFIX_HELP_DESCRIPTION);
|
private static final String ARG_VERBOSE = "--verbose";
|
||||||
|
private static final String ARG_ALL = "--all";
|
||||||
|
private static final String ARG_CRITICAL_ONLY = "--critical-only";
|
||||||
|
private static final String ARG_MODE = "--mode";
|
||||||
|
|
||||||
pw.printf("%s%s [%s | %s] [%s] [%s MODE]\n", PREFIX_HELP_COMMAND,
|
@Override
|
||||||
CMD_REPORT_SYSTEM_USER_PACKAGE_ALLOWLIST_PROBLEMS,
|
public void onHelp() {
|
||||||
ARG_V, ARG_VERBOSE, ARG_CRITICAL_ONLY, ARG_MODE);
|
final PrintWriter pw = getOutPrintWriter();
|
||||||
|
pw.printf("User manager (user) commands:\n");
|
||||||
|
|
||||||
pw.printf("%sReports all issues on user-type package allowlist XML files. Options:\n",
|
pw.printf("%s%s\n", PREFIX_HELP_COMMAND, CMD_HELP);
|
||||||
PREFIX_HELP_DESCRIPTION);
|
pw.printf("%sPrints this help text.\n\n", PREFIX_HELP_DESCRIPTION);
|
||||||
pw.printf("%s%s | %s: shows extra info, like number of issues\n",
|
|
||||||
PREFIX_HELP_DESCRIPTION, ARG_V, ARG_VERBOSE);
|
|
||||||
pw.printf("%s%s: show only critical issues, excluding warnings\n",
|
|
||||||
PREFIX_HELP_DESCRIPTION, ARG_CRITICAL_ONLY);
|
|
||||||
pw.printf("%s%s MODE: shows what errors would be if device used mode MODE\n"
|
|
||||||
+ "%s(where MODE is the allowlist mode integer as defined by "
|
|
||||||
+ "config_userTypePackageWhitelistMode)\n\n",
|
|
||||||
PREFIX_HELP_DESCRIPTION, ARG_MODE, PREFIX_HELP_DESCRIPTION_EXTRA_LINES);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
pw.printf("%s%s [%s] [%s]\n", PREFIX_HELP_COMMAND, CMD_LIST, ARG_V, ARG_ALL);
|
||||||
public int onCommand(String cmd) {
|
pw.printf("%sPrints all users on the system.\n\n", PREFIX_HELP_DESCRIPTION);
|
||||||
if (cmd == null) {
|
|
||||||
return handleDefaultCommands(cmd);
|
pw.printf("%s%s [%s | %s] [%s] [%s MODE]\n", PREFIX_HELP_COMMAND,
|
||||||
|
CMD_REPORT_SYSTEM_USER_PACKAGE_ALLOWLIST_PROBLEMS,
|
||||||
|
ARG_V, ARG_VERBOSE, ARG_CRITICAL_ONLY, ARG_MODE);
|
||||||
|
|
||||||
|
pw.printf("%sReports all issues on user-type package allowlist XML files. Options:\n",
|
||||||
|
PREFIX_HELP_DESCRIPTION);
|
||||||
|
pw.printf("%s%s | %s: shows extra info, like number of issues\n",
|
||||||
|
PREFIX_HELP_DESCRIPTION, ARG_V, ARG_VERBOSE);
|
||||||
|
pw.printf("%s%s: show only critical issues, excluding warnings\n",
|
||||||
|
PREFIX_HELP_DESCRIPTION, ARG_CRITICAL_ONLY);
|
||||||
|
pw.printf("%s%s MODE: shows what errors would be if device used mode MODE\n"
|
||||||
|
+ "%s(where MODE is the allowlist mode integer as defined by "
|
||||||
|
+ "config_userTypePackageWhitelistMode)\n\n",
|
||||||
|
PREFIX_HELP_DESCRIPTION, ARG_MODE, PREFIX_HELP_DESCRIPTION_EXTRA_LINES);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
@Override
|
||||||
switch(cmd) {
|
public int onCommand(String cmd) {
|
||||||
case CMD_LIST:
|
if (cmd == null) {
|
||||||
return runList();
|
return handleDefaultCommands(cmd);
|
||||||
case CMD_REPORT_SYSTEM_USER_PACKAGE_ALLOWLIST_PROBLEMS:
|
|
||||||
return runReportPackageAllowlistProblems();
|
|
||||||
default:
|
|
||||||
return handleDefaultCommands(cmd);
|
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
|
||||||
getOutPrintWriter().println("Remote exception: " + e);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int runList() throws RemoteException {
|
try {
|
||||||
final PrintWriter pw = getOutPrintWriter();
|
switch(cmd) {
|
||||||
boolean all = false;
|
case CMD_LIST:
|
||||||
boolean verbose = false;
|
return runList();
|
||||||
String opt;
|
case CMD_REPORT_SYSTEM_USER_PACKAGE_ALLOWLIST_PROBLEMS:
|
||||||
while ((opt = getNextOption()) != null) {
|
return runReportPackageAllowlistProblems();
|
||||||
switch (opt) {
|
default:
|
||||||
case ARG_V:
|
return handleDefaultCommands(cmd);
|
||||||
verbose = true;
|
}
|
||||||
break;
|
} catch (RemoteException e) {
|
||||||
case ARG_ALL:
|
getOutPrintWriter().println("Remote exception: " + e);
|
||||||
all = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
pw.println("Invalid option: " + opt);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
final IActivityManager am = ActivityManager.getService();
|
|
||||||
final List<UserInfo> users = getUsers(/* excludePartial= */ !all,
|
private int runList() throws RemoteException {
|
||||||
/* excludingDying=*/ false, /* excludePreCreated= */ !all);
|
final PrintWriter pw = getOutPrintWriter();
|
||||||
if (users == null) {
|
boolean all = false;
|
||||||
pw.println("Error: couldn't get users");
|
boolean verbose = false;
|
||||||
return 1;
|
String opt;
|
||||||
} else {
|
while ((opt = getNextOption()) != null) {
|
||||||
final int size = users.size();
|
switch (opt) {
|
||||||
int currentUser = UserHandle.USER_NULL;
|
case ARG_V:
|
||||||
if (verbose) {
|
verbose = true;
|
||||||
pw.printf("%d users:\n\n", size);
|
break;
|
||||||
currentUser = am.getCurrentUser().id;
|
case ARG_ALL:
|
||||||
|
all = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
pw.println("Invalid option: " + opt);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final IActivityManager am = ActivityManager.getService();
|
||||||
|
final List<UserInfo> users = getUsers(/* excludePartial= */ !all,
|
||||||
|
/* excludeDying= */ false, /* excludePreCreated= */ !all);
|
||||||
|
if (users == null) {
|
||||||
|
pw.println("Error: couldn't get users");
|
||||||
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
// NOTE: the standard "list users" command is used by integration tests and
|
final int size = users.size();
|
||||||
// hence should not be changed. If you need to add more info, use the
|
int currentUser = UserHandle.USER_NULL;
|
||||||
// verbose option.
|
|
||||||
pw.println("Users:");
|
|
||||||
}
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
final UserInfo user = users.get(i);
|
|
||||||
final boolean running = am.isUserRunning(user.id, 0);
|
|
||||||
final boolean current = user.id == currentUser;
|
|
||||||
final boolean hasParent = user.profileGroupId != user.id
|
|
||||||
&& user.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID;
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
final DevicePolicyManagerInternal dpm = getDevicePolicyManagerInternal();
|
pw.printf("%d users:\n\n", size);
|
||||||
String deviceOwner = "";
|
currentUser = am.getCurrentUser().id;
|
||||||
String profileOwner = "";
|
|
||||||
if (dpm != null) {
|
|
||||||
final long ident = Binder.clearCallingIdentity();
|
|
||||||
// NOTE: dpm methods below CANNOT be called while holding the mUsersLock
|
|
||||||
try {
|
|
||||||
if (dpm.getDeviceOwnerUserId() == user.id) {
|
|
||||||
deviceOwner = " (device-owner)";
|
|
||||||
}
|
|
||||||
if (dpm.getProfileOwnerAsUser(user.id) != null) {
|
|
||||||
profileOwner = " (profile-owner)";
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
Binder.restoreCallingIdentity(ident);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pw.printf("%d: id=%d, name=%s, type=%s, flags=%s%s%s%s%s%s%s%s%s\n",
|
|
||||||
i,
|
|
||||||
user.id,
|
|
||||||
user.name,
|
|
||||||
user.userType.replace("android.os.usertype.", ""),
|
|
||||||
UserInfo.flagsToString(user.flags),
|
|
||||||
hasParent ? " (parentId=" + user.profileGroupId + ")" : "",
|
|
||||||
running ? " (running)" : "",
|
|
||||||
user.partial ? " (partial)" : "",
|
|
||||||
user.preCreated ? " (pre-created)" : "",
|
|
||||||
user.convertedFromPreCreated ? " (converted)" : "",
|
|
||||||
deviceOwner, profileOwner,
|
|
||||||
current ? " (current)" : "");
|
|
||||||
} else {
|
} else {
|
||||||
// NOTE: the standard "list users" command is used by integration tests and
|
// NOTE: the standard "list users" command is used by integration tests and
|
||||||
// hence should not be changed. If you need to add more info, use the
|
// hence should not be changed. If you need to add more info, use the
|
||||||
// verbose option.
|
// verbose option.
|
||||||
pw.printf("\t%s%s\n", user, running ? " running" : "");
|
pw.println("Users:");
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
final UserInfo user = users.get(i);
|
||||||
|
final boolean running = am.isUserRunning(user.id, 0);
|
||||||
|
final boolean current = user.id == currentUser;
|
||||||
|
final boolean hasParent = user.profileGroupId != user.id
|
||||||
|
&& user.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID;
|
||||||
|
if (verbose) {
|
||||||
|
final DevicePolicyManagerInternal dpm = getDevicePolicyManagerInternal();
|
||||||
|
String deviceOwner = "";
|
||||||
|
String profileOwner = "";
|
||||||
|
if (dpm != null) {
|
||||||
|
final long ident = Binder.clearCallingIdentity();
|
||||||
|
// NOTE: dpm methods below CANNOT be called while holding the mUsersLock
|
||||||
|
try {
|
||||||
|
if (dpm.getDeviceOwnerUserId() == user.id) {
|
||||||
|
deviceOwner = " (device-owner)";
|
||||||
|
}
|
||||||
|
if (dpm.getProfileOwnerAsUser(user.id) != null) {
|
||||||
|
profileOwner = " (profile-owner)";
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
Binder.restoreCallingIdentity(ident);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pw.printf("%d: id=%d, name=%s, type=%s, flags=%s%s%s%s%s%s%s%s%s\n",
|
||||||
|
i,
|
||||||
|
user.id,
|
||||||
|
user.name,
|
||||||
|
user.userType.replace("android.os.usertype.", ""),
|
||||||
|
UserInfo.flagsToString(user.flags),
|
||||||
|
hasParent ? " (parentId=" + user.profileGroupId + ")" : "",
|
||||||
|
running ? " (running)" : "",
|
||||||
|
user.partial ? " (partial)" : "",
|
||||||
|
user.preCreated ? " (pre-created)" : "",
|
||||||
|
user.convertedFromPreCreated ? " (converted)" : "",
|
||||||
|
deviceOwner, profileOwner,
|
||||||
|
current ? " (current)" : "");
|
||||||
|
} else {
|
||||||
|
// NOTE: the standard "list users" command is used by integration tests and
|
||||||
|
// hence should not be changed. If you need to add more info, use the
|
||||||
|
// verbose option.
|
||||||
|
pw.printf("\t%s%s\n", user, running ? " running" : "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int runReportPackageAllowlistProblems() {
|
||||||
|
final PrintWriter pw = getOutPrintWriter();
|
||||||
|
boolean verbose = false;
|
||||||
|
boolean criticalOnly = false;
|
||||||
|
int mode = UserSystemPackageInstaller.USER_TYPE_PACKAGE_WHITELIST_MODE_NONE;
|
||||||
|
String opt;
|
||||||
|
while ((opt = getNextOption()) != null) {
|
||||||
|
switch (opt) {
|
||||||
|
case ARG_V:
|
||||||
|
case ARG_VERBOSE:
|
||||||
|
verbose = true;
|
||||||
|
break;
|
||||||
|
case ARG_CRITICAL_ONLY:
|
||||||
|
criticalOnly = true;
|
||||||
|
break;
|
||||||
|
case ARG_MODE:
|
||||||
|
mode = Integer.parseInt(getNextArgRequired());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
pw.println("Invalid option: " + opt);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Slog.d(LOG_TAG, "runReportPackageAllowlistProblems(): verbose=" + verbose
|
||||||
|
+ ", criticalOnly=" + criticalOnly
|
||||||
|
+ ", mode=" + UserSystemPackageInstaller.modeToString(mode));
|
||||||
|
|
||||||
|
try (IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ")) {
|
||||||
|
mSystemPackageInstaller.dumpPackageWhitelistProblems(ipw, mode, verbose,
|
||||||
|
criticalOnly);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int runReportPackageAllowlistProblems() {
|
|
||||||
final PrintWriter pw = getOutPrintWriter();
|
|
||||||
boolean verbose = false;
|
|
||||||
boolean criticalOnly = false;
|
|
||||||
int mode = UserSystemPackageInstaller.USER_TYPE_PACKAGE_WHITELIST_MODE_NONE;
|
|
||||||
String opt;
|
|
||||||
while ((opt = getNextOption()) != null) {
|
|
||||||
switch (opt) {
|
|
||||||
case ARG_V:
|
|
||||||
case ARG_VERBOSE:
|
|
||||||
verbose = true;
|
|
||||||
break;
|
|
||||||
case ARG_CRITICAL_ONLY:
|
|
||||||
criticalOnly = true;
|
|
||||||
break;
|
|
||||||
case ARG_MODE:
|
|
||||||
mode = Integer.parseInt(getNextArgRequired());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
pw.println("Invalid option: " + opt);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Slog.d(LOG_TAG, "runReportPackageAllowlistProblems(): verbose=" + verbose
|
|
||||||
+ ", criticalOnly=" + criticalOnly
|
|
||||||
+ ", mode=" + UserSystemPackageInstaller.modeToString(mode));
|
|
||||||
|
|
||||||
try (IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ")) {
|
|
||||||
mSystemPackageInstaller.dumpPackageWhitelistProblems(ipw, mode, verbose,
|
|
||||||
criticalOnly);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||||
if (!DumpUtils.checkDumpPermission(mContext, LOG_TAG, pw)) return;
|
if (!DumpUtils.checkDumpPermission(mContext, LOG_TAG, pw)) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user