Aurimas Liutikas | ac5fe7c | 2018-03-06 14:40:53 -0800 | [diff] [blame] | 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 | |
| 17 | package androidx.core.os; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.os.Build; |
| 21 | import android.os.UserManager; |
| 22 | |
Jake Wharton | 8c11db7 | 2018-08-02 22:19:37 -0400 | [diff] [blame] | 23 | import androidx.annotation.NonNull; |
| 24 | |
Aurimas Liutikas | ac5fe7c | 2018-03-06 14:40:53 -0800 | [diff] [blame] | 25 | /** |
| 26 | * Helper for accessing features in {@link android.os.UserManager} in a backwards compatible |
| 27 | * fashion. |
| 28 | */ |
| 29 | public 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 Wharton | 8c11db7 | 2018-08-02 22:19:37 -0400 | [diff] [blame] | 40 | public static boolean isUserUnlocked(@NonNull Context context) { |
Aurimas Liutikas | ac5fe7c | 2018-03-06 14:40:53 -0800 | [diff] [blame] | 41 | if (Build.VERSION.SDK_INT >= 24) { |
| 42 | return context.getSystemService(UserManager.class).isUserUnlocked(); |
| 43 | } else { |
| 44 | return true; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | } |