blob: 0c0fbbcc6f539586ea3395085d802948724c980f [file] [log] [blame]
Aurimas Liutikasac5fe7c2018-03-06 14:40:53 -08001/*
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 androidx.core.os;
18
19import android.content.Context;
20import android.os.Build;
21import android.os.UserManager;
22
Jake Wharton8c11db72018-08-02 22:19:37 -040023import androidx.annotation.NonNull;
24
Aurimas Liutikasac5fe7c2018-03-06 14:40:53 -080025/**
26 * Helper for accessing features in {@link android.os.UserManager} in a backwards compatible
27 * fashion.
28 */
29public class UserManagerCompat {
30
31 private UserManagerCompat() {
32 }
33
34 /**
35 * Return whether the calling user is running in an "unlocked" state. A user
36 * is unlocked only after they've entered their credentials (such as a lock
37 * pattern or PIN), and credential-encrypted private app data storage is
38 * available.
39 */
Jake Wharton8c11db72018-08-02 22:19:37 -040040 public static boolean isUserUnlocked(@NonNull Context context) {
Aurimas Liutikasac5fe7c2018-03-06 14:40:53 -080041 if (Build.VERSION.SDK_INT >= 24) {
42 return context.getSystemService(UserManager.class).isUserUnlocked();
43 } else {
44 return true;
45 }
46 }
47
48}