blob: 5abf39e781f34af407d70e9fb6f2769c40a16e83 [file] [log] [blame]
Selim Cinek2c890ee2019-05-20 19:16:43 -07001/*
2 * Copyright (C) 2019 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.systemui.statusbar.phone
18
19import android.content.Context
Lucas Dupin1b883b42019-05-28 17:43:59 -070020import android.hardware.face.FaceManager
Selim Cinek2c890ee2019-05-20 19:16:43 -070021import android.provider.Settings
22import com.android.internal.annotations.VisibleForTesting
23import com.android.keyguard.KeyguardUpdateMonitor
Selim Cinek2c890ee2019-05-20 19:16:43 -070024import com.android.systemui.tuner.TunerService
25
26import javax.inject.Inject
27import javax.inject.Singleton
28
29@Singleton
30class KeyguardBypassController {
31
32 @Inject
33 constructor(context: Context,
34 tunerService: TunerService) {
Lucas Dupin1b883b42019-05-28 17:43:59 -070035 val faceManager = context.getSystemService(FaceManager::class.java)
36 if (faceManager?.isHardwareDetected != true) {
37 return
38 }
39
40 val dismissByDefault = if (context.resources.getBoolean(
41 com.android.internal.R.bool.config_faceAuthDismissesKeyguard)) 1 else 0
Selim Cinek2c890ee2019-05-20 19:16:43 -070042 tunerService.addTunable(
43 object : TunerService.Tunable {
44 override fun onTuningChanged(key: String?, newValue: String?) {
45 bypassEnabled = Settings.Secure.getIntForUser(
46 context.contentResolver,
47 Settings.Secure.FACE_UNLOCK_DISMISSES_KEYGUARD,
48 dismissByDefault,
49 KeyguardUpdateMonitor.getCurrentUser()) != 0
50 }
51 }, Settings.Secure.FACE_UNLOCK_DISMISSES_KEYGUARD)
52 }
53
54 @VisibleForTesting
55 constructor(bypassEnabled: Boolean) {
56 this.bypassEnabled = bypassEnabled;
57 }
58
59 /**
60 * If face unlock dismisses the lock screen or keeps user on keyguard for the current user.
61 */
62 var bypassEnabled: Boolean = false
63 private set
64}