Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone |
| 18 | |
| 19 | import android.content.Context |
Lucas Dupin | 1b883b4 | 2019-05-28 17:43:59 -0700 | [diff] [blame^] | 20 | import android.hardware.face.FaceManager |
Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 21 | import android.provider.Settings |
| 22 | import com.android.internal.annotations.VisibleForTesting |
| 23 | import com.android.keyguard.KeyguardUpdateMonitor |
Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 24 | import com.android.systemui.tuner.TunerService |
| 25 | |
| 26 | import javax.inject.Inject |
| 27 | import javax.inject.Singleton |
| 28 | |
| 29 | @Singleton |
| 30 | class KeyguardBypassController { |
| 31 | |
| 32 | @Inject |
| 33 | constructor(context: Context, |
| 34 | tunerService: TunerService) { |
Lucas Dupin | 1b883b4 | 2019-05-28 17:43:59 -0700 | [diff] [blame^] | 35 | 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 Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 42 | 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 | } |