1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.commands.locksettings;
18
19import android.os.ResultReceiver;
20import android.os.ServiceManager;
21import android.os.ShellCallback;
22
23import com.android.internal.os.BaseCommand;
24import com.android.internal.widget.ILockSettings;
25
26import java.io.FileDescriptor;
27import java.io.PrintStream;
28
29public final class LockSettingsCmd extends BaseCommand {
30
31    private static final String USAGE =
32            "usage: locksettings set-pattern [--old OLD_CREDENTIAL] NEW_PATTERN\n" +
33            "       locksettings set-pin [--old OLD_CREDENTIAL] NEW_PIN\n" +
34            "       locksettings set-password [--old OLD_CREDENTIAL] NEW_PASSWORD\n" +
35            "       locksettings clear [--old OLD_CREDENTIAL]\n" +
36            "       locksettings verify [--old OLD_CREDENTIAL]\n" +
37            "       locksettings set-disabled DISABLED\n" +
38            "       locksettings get-disabled\n" +
39            "\n" +
40            "flags: \n" +
41            "       --user USER_ID: specify the user, default value is current user\n" +
42            "\n" +
43            "locksettings set-pattern: sets a pattern\n" +
44            "    A pattern is specified by a non-separated list of numbers that index the cell\n" +
45            "    on the pattern in a 1-based manner in left to right and top to bottom order,\n" +
46            "    i.e. the top-left cell is indexed with 1, whereas the bottom-right cell\n" +
47            "    is indexed with 9. Example: 1234\n" +
48            "\n" +
49            "locksettings set-pin: sets a PIN\n" +
50            "\n" +
51            "locksettings set-password: sets a password\n" +
52            "\n" +
53            "locksettings clear: clears the unlock credential\n" +
54            "\n" +
55            "locksettings verify: verifies the credential and unlocks the user\n" +
56            "\n" +
57            "locksettings set-disabled: sets whether the lock screen should be disabled\n" +
58            "\n" +
59            "locksettings get-disabled: retrieves whether the lock screen is disabled\n";
60
61    public static void main(String[] args) {
62        (new LockSettingsCmd()).run(args);
63    }
64
65    @Override
66    public void onShowUsage(PrintStream out) {
67        out.println(USAGE);
68    }
69
70    @Override
71    public void onRun() throws Exception {
72        ILockSettings lockSettings = ILockSettings.Stub.asInterface(
73                ServiceManager.getService("lock_settings"));
74        lockSettings.asBinder().shellCommand(FileDescriptor.in, FileDescriptor.out,
75                FileDescriptor.err, getRawArgs(), new ShellCallback(), new ResultReceiver(null) {});
76    }
77}
78