Improvements on UserManagerService ShellCommand implementation (3/4).
These changes will make it easier to extend / mantain it: - Moves all methods to Shell. BYPASS_INCLUSIVE_LANGUAGE_REASON: existing API Test: adb shell cmd user Bug: 203885212 Change-Id: I0a51ac790b619ab26041183e87c1979bfd881543
This commit is contained in:
@@ -5424,10 +5424,11 @@ public class UserManagerService extends IUserManager.Stub {
|
||||
private static final String ARG_CRITICAL_ONLY = "--critical-only";
|
||||
private static final String ARG_MODE = "--mode";
|
||||
|
||||
// Temporary class used to minmize git diff
|
||||
private final class TmpShellCommand {
|
||||
private final class Shell extends ShellCommand {
|
||||
|
||||
public void onHelp(PrintWriter pw) {
|
||||
@Override
|
||||
public void onHelp() {
|
||||
final PrintWriter pw = getOutPrintWriter();
|
||||
pw.printf("User manager (user) commands:\n");
|
||||
|
||||
pw.printf("%s%s\n", PREFIX_HELP_COMMAND, CMD_HELP);
|
||||
@@ -5452,32 +5453,33 @@ public class UserManagerService extends IUserManager.Stub {
|
||||
PREFIX_HELP_DESCRIPTION, ARG_MODE, PREFIX_HELP_DESCRIPTION_EXTRA_LINES);
|
||||
}
|
||||
|
||||
private int onShellCommand(Shell shell, String cmd) {
|
||||
@Override
|
||||
public int onCommand(String cmd) {
|
||||
if (cmd == null) {
|
||||
return shell.handleDefaultCommands(cmd);
|
||||
return handleDefaultCommands(cmd);
|
||||
}
|
||||
|
||||
final PrintWriter pw = shell.getOutPrintWriter();
|
||||
try {
|
||||
switch(cmd) {
|
||||
case CMD_LIST:
|
||||
return runList(pw, shell);
|
||||
return runList();
|
||||
case CMD_REPORT_SYSTEM_USER_PACKAGE_ALLOWLIST_PROBLEMS:
|
||||
return runReportPackageWhitelistProblems(pw, shell);
|
||||
return runReportPackageAllowlistProblems();
|
||||
default:
|
||||
return shell.handleDefaultCommands(cmd);
|
||||
return handleDefaultCommands(cmd);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
pw.println("Remote exception: " + e);
|
||||
getOutPrintWriter().println("Remote exception: " + e);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int runList(PrintWriter pw, Shell shell) throws RemoteException {
|
||||
private int runList() throws RemoteException {
|
||||
final PrintWriter pw = getOutPrintWriter();
|
||||
boolean all = false;
|
||||
boolean verbose = false;
|
||||
String opt;
|
||||
while ((opt = shell.getNextOption()) != null) {
|
||||
while ((opt = getNextOption()) != null) {
|
||||
switch (opt) {
|
||||
case ARG_V:
|
||||
verbose = true;
|
||||
@@ -5556,12 +5558,13 @@ public class UserManagerService extends IUserManager.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
private int runReportPackageWhitelistProblems(PrintWriter pw, Shell shell) {
|
||||
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 = shell.getNextOption()) != null) {
|
||||
while ((opt = getNextOption()) != null) {
|
||||
switch (opt) {
|
||||
case ARG_V:
|
||||
case ARG_VERBOSE:
|
||||
@@ -5571,7 +5574,7 @@ public class UserManagerService extends IUserManager.Stub {
|
||||
criticalOnly = true;
|
||||
break;
|
||||
case ARG_MODE:
|
||||
mode = Integer.parseInt(shell.getNextArgRequired());
|
||||
mode = Integer.parseInt(getNextArgRequired());
|
||||
break;
|
||||
default:
|
||||
pw.println("Invalid option: " + opt);
|
||||
@@ -5579,17 +5582,17 @@ public class UserManagerService extends IUserManager.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
Slog.d(LOG_TAG, "runReportPackageWhitelistProblems(): verbose=" + verbose
|
||||
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);
|
||||
mSystemPackageInstaller.dumpPackageWhitelistProblems(ipw, mode, verbose,
|
||||
criticalOnly);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // TmpShellCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
@@ -6284,20 +6287,6 @@ public class UserManagerService extends IUserManager.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
private class Shell extends ShellCommand {
|
||||
private final TmpShellCommand mTmpShellCommand = new TmpShellCommand();
|
||||
|
||||
@Override
|
||||
public int onCommand(String cmd) {
|
||||
return mTmpShellCommand.onShellCommand(this, cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHelp() {
|
||||
mTmpShellCommand.onHelp(getOutPrintWriter());
|
||||
}
|
||||
}
|
||||
|
||||
private static void debug(String message) {
|
||||
Slog.d(LOG_TAG, message
|
||||
+ (DBG_WITH_STACKTRACE ? " called at\n" + Debug.getCallers(10, " ") : ""));
|
||||
|
||||
Reference in New Issue
Block a user