1/*
2 * Copyright (C) 2015 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 android.support.v4.os;
18
19import android.content.Context;
20
21/**
22 * Helper for accessing features in {@link android.os.UserManager}
23 * introduced after API level 4 in a backwards compatible fashion.
24 */
25public class UserManagerCompat {
26    private UserManagerCompat() {
27    }
28
29    /**
30     * Return whether the calling user is running in a "locked" state. A user is
31     * unlocked only after they've entered their credentials (such as a lock
32     * pattern or PIN), and credential-encrypted private app data storage is
33     * available.
34     *
35     * @removed
36     * @deprecated Removed. Do not use.
37     */
38    @Deprecated
39    public static boolean isUserRunningAndLocked(Context context) {
40        return !isUserUnlocked(context);
41    }
42
43    /**
44     * Return whether the calling user is running in an "unlocked" state. A user
45     * is unlocked only after they've entered their credentials (such as a lock
46     * pattern or PIN), and credential-encrypted private app data storage is
47     * available.
48     *
49     * @removed
50     * @deprecated Removed. Do not use.
51     */
52    @Deprecated
53    public static boolean isUserRunningAndUnlocked(Context context) {
54        return isUserUnlocked(context);
55    }
56
57    /**
58     * Return whether the calling user is running in an "unlocked" state. A user
59     * is unlocked only after they've entered their credentials (such as a lock
60     * pattern or PIN), and credential-encrypted private app data storage is
61     * available.
62     */
63    public static boolean isUserUnlocked(Context context) {
64        if (BuildCompat.isAtLeastN()) {
65            return UserManagerCompatApi24.isUserUnlocked(context);
66        } else {
67            return true;
68        }
69    }
70}
71