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.settings;
18
19import android.content.Context;
20import android.content.Intent;
21
22/**
23 * Helper for handling managed passwords in security settings UI.
24 * It provides resources that should be shown in settings UI when lock password quality is set to
25 * {@link android.app.admin.DevicePolicyManager#PASSWORD_QUALITY_MANAGED} and hooks for implementing
26 * an option for setting the password quality to
27 * {@link android.app.admin.DevicePolicyManager#PASSWORD_QUALITY_MANAGED}.
28 */
29public class ManagedLockPasswordProvider {
30    /** Factory method to make it easier to inject extended ManagedLockPasswordProviders. */
31    static ManagedLockPasswordProvider get(Context context, int userId) {
32        return new ManagedLockPasswordProvider();
33    }
34
35    protected ManagedLockPasswordProvider() {}
36
37    /**
38     * Whether choosing/setting a managed lock password is supported for the user.
39     * Please update {@link #getPickerOptionTitle(boolean)} if overridden to return true.
40     */
41    boolean isSettingManagedPasswordSupported() { return false; }
42
43    /**
44     * Whether the user should be able to choose managed lock password.
45     */
46    boolean isManagedPasswordChoosable() { return false; }
47
48    /**
49     * Returns title for managed password preference in security (lock) setting picker.
50     * Should be overridden if {@link #isManagedPasswordSupported()} returns true.
51     * @param forFingerprint Whether fingerprint unlock is enabled.
52     */
53    String getPickerOptionTitle(boolean forFingerprint) { return ""; }
54
55    /**
56     * Gets resource id of the lock screen preference that should be displayed in security settings
57     * if the current password quality is set to
58     * {@link android.app.admin.DevicePolicyManager#PASSWORD_QUALITY_MANAGED}.
59     * @param forProfile Whether the settings are shown for a user profile rather than a user.
60     */
61    int getResIdForLockUnlockScreen(boolean forProfile) {
62        return forProfile ? R.xml.security_settings_password_profile
63                : R.xml.security_settings_password;
64    }
65
66    /**
67     * Gets resource id of the subscreen that should be shown after clicking gear icon for lock
68     * screen preference in security settings if the current password quality is set to
69     * {@link android.app.admin.DevicePolicyManager#PASSWORD_QUALITY_MANAGED}.
70     */
71    int getResIdForLockUnlockSubScreen() {
72        return R.xml.security_settings_password_sub;
73    }
74
75    /**
76     * Creates intent that should be launched when user chooses managed password in the lock
77     * settings picker.
78     * @param requirePasswordToDecrypt Whether a password is needed to decrypt the user.
79     * @param password Current lock password.
80     * @return Intent that should update lock password to a managed password.
81     */
82    Intent createIntent(boolean requirePasswordToDecrypt, String password) {
83        return null;
84    }
85}
86