Implemented help for lock_settings Shell command.
Fixes: 111346876
Test: adb shell cmd lock_settings
Change-Id: I947e8f50b06b79e12495a404177608bb24d04481
diff --git a/services/core/java/com/android/server/locksettings/LockSettingsShellCommand.java b/services/core/java/com/android/server/locksettings/LockSettingsShellCommand.java
index 4d2cf32..085d17d 100644
--- a/services/core/java/com/android/server/locksettings/LockSettingsShellCommand.java
+++ b/services/core/java/com/android/server/locksettings/LockSettingsShellCommand.java
@@ -21,13 +21,13 @@
import static com.android.internal.widget.LockPatternUtils.stringToPattern;
import android.app.ActivityManager;
-import android.content.Context;
-import android.os.RemoteException;
import android.os.ShellCommand;
import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockPatternUtils.RequestThrottledException;
+import java.io.PrintWriter;
+
class LockSettingsShellCommand extends ShellCommand {
private static final String COMMAND_SET_PATTERN = "set-pattern";
@@ -38,20 +38,22 @@
private static final String COMMAND_SET_DISABLED = "set-disabled";
private static final String COMMAND_VERIFY = "verify";
private static final String COMMAND_GET_DISABLED = "get-disabled";
+ private static final String COMMAND_HELP = "help";
private int mCurrentUserId;
private final LockPatternUtils mLockPatternUtils;
- private final Context mContext;
private String mOld = "";
private String mNew = "";
- LockSettingsShellCommand(Context context, LockPatternUtils lockPatternUtils) {
- mContext = context;
+ LockSettingsShellCommand(LockPatternUtils lockPatternUtils) {
mLockPatternUtils = lockPatternUtils;
}
@Override
public int onCommand(String cmd) {
+ if (cmd == null) {
+ return handleDefaultCommands(cmd);
+ }
try {
mCurrentUserId = ActivityManager.getService().getCurrentUser().id;
@@ -84,6 +86,9 @@
case COMMAND_GET_DISABLED:
runGetDisabled();
break;
+ case COMMAND_HELP:
+ onHelp();
+ break;
default:
getErrPrintWriter().println("Unknown command: " + cmd);
break;
@@ -103,6 +108,43 @@
@Override
public void onHelp() {
+ try (final PrintWriter pw = getOutPrintWriter();) {
+ pw.println("lockSettings service commands:");
+ pw.println("");
+ pw.println("NOTE: when lock screen is set, all commands require the --old <CREDENTIAL>"
+ + " argument.");
+ pw.println("");
+ pw.println(" help");
+ pw.println(" Prints this help text.");
+ pw.println("");
+ pw.println(" get-disabled [--old <CREDENTIAL>] [--user USER_ID]");
+ pw.println(" Checks whether lock screen is disabled.");
+ pw.println("");
+ pw.println(" set-disabled [--old <CREDENTIAL>] [--user USER_ID] <true|false>");
+ pw.println(" When true, disables lock screen.");
+ pw.println("");
+ pw.println(" set-pattern [--old <CREDENTIAL>] [--user USER_ID] <PATTERN>");
+ pw.println(" Sets the lock screen as pattern, using the given PATTERN to unlock.");
+ pw.println("");
+ pw.println(" set-pin [--old <CREDENTIAL>] [--user USER_ID] <PIN>");
+ pw.println(" Sets the lock screen as PIN, using the given PIN to unlock.");
+ pw.println("");
+ pw.println(" set-pin [--old <CREDENTIAL>] [--user USER_ID] <PASSWORD>");
+ pw.println(" Sets the lock screen as password, using the given PASSOWRD to unlock.");
+ pw.println("");
+ pw.println(" sp [--old <CREDENTIAL>] [--user USER_ID]");
+ pw.println(" Gets whether synthetic password is enabled.");
+ pw.println("");
+ pw.println(" sp [--old <CREDENTIAL>] [--user USER_ID] <1|0>");
+ pw.println(" Enables / disables synthetic password.");
+ pw.println("");
+ pw.println(" clear [--old <CREDENTIAL>] [--user USER_ID]");
+ pw.println(" Clears the lock credentials.");
+ pw.println("");
+ pw.println(" verify [--old <CREDENTIAL>] [--user USER_ID]");
+ pw.println(" Verifies the lock credentials.");
+ pw.println("");
+ }
}
private void parseArgs() {
@@ -134,27 +176,27 @@
mLockPatternUtils.isSyntheticPasswordEnabled()));
}
- private void runSetPattern() throws RemoteException {
+ private void runSetPattern() {
mLockPatternUtils.saveLockPattern(stringToPattern(mNew), mOld, mCurrentUserId);
getOutPrintWriter().println("Pattern set to '" + mNew + "'");
}
- private void runSetPassword() throws RemoteException {
+ private void runSetPassword() {
mLockPatternUtils.saveLockPassword(mNew, mOld, PASSWORD_QUALITY_ALPHABETIC, mCurrentUserId);
getOutPrintWriter().println("Password set to '" + mNew + "'");
}
- private void runSetPin() throws RemoteException {
+ private void runSetPin() {
mLockPatternUtils.saveLockPassword(mNew, mOld, PASSWORD_QUALITY_NUMERIC, mCurrentUserId);
getOutPrintWriter().println("Pin set to '" + mNew + "'");
}
- private void runClear() throws RemoteException {
+ private void runClear() {
mLockPatternUtils.clearLock(mOld, mCurrentUserId);
getOutPrintWriter().println("Lock credential cleared");
}
- private void runSetDisabled() throws RemoteException {
+ private void runSetDisabled() {
final boolean disabled = Boolean.parseBoolean(mNew);
mLockPatternUtils.setLockScreenDisabled(disabled, mCurrentUserId);
getOutPrintWriter().println("Lock screen disabled set to " + disabled);
@@ -165,7 +207,7 @@
getOutPrintWriter().println(isLockScreenDisabled);
}
- private boolean checkCredential() throws RemoteException {
+ private boolean checkCredential() {
final boolean havePassword = mLockPatternUtils.isLockPasswordEnabled(mCurrentUserId);
final boolean havePattern = mLockPatternUtils.isLockPatternEnabled(mCurrentUserId);
if (havePassword || havePattern) {