• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download

<lambda>null1 package com.android.systemui.biometrics.ui.binder
2 
3 import androidx.lifecycle.Lifecycle
4 import androidx.lifecycle.repeatOnLifecycle
5 import com.android.internal.widget.LockPatternUtils
6 import com.android.internal.widget.LockPatternView
7 import com.android.systemui.res.R
8 import com.android.systemui.biometrics.ui.CredentialPatternView
9 import com.android.systemui.biometrics.ui.CredentialView
10 import com.android.systemui.biometrics.ui.viewmodel.CredentialViewModel
11 import com.android.systemui.lifecycle.repeatWhenAttached
12 import kotlinx.coroutines.launch
13 
14 /** Sub-binder for the [CredentialPatternView]. */
15 object CredentialPatternViewBinder {
16 
17     /** Bind the view. */
18     fun bind(
19         view: CredentialPatternView,
20         host: CredentialView.Host,
21         viewModel: CredentialViewModel,
22     ) {
23         val lockPatternView: LockPatternView = view.requireViewById(R.id.lockPattern)
24 
25         view.repeatWhenAttached {
26             repeatOnLifecycle(Lifecycle.State.STARTED) {
27                 // observe credential validation attempts and submit/cancel buttons
28                 launch {
29                     viewModel.header.collect { header ->
30                         lockPatternView.setOnPatternListener(
31                             OnPatternDetectedListener { pattern ->
32                                 if (pattern.isPatternTooShort()) {
33                                     // Pattern size is less than the minimum
34                                     // do not count it as a failed attempt
35                                     viewModel.showPatternTooShortError()
36                                 } else {
37                                     lockPatternView.isEnabled = false
38                                     launch { viewModel.checkCredential(pattern, header) }
39                                 }
40                             }
41                         )
42                     }
43                 }
44 
45                 launch { viewModel.stealthMode.collect { lockPatternView.isInStealthMode = it } }
46 
47                 // dismiss on a valid credential check
48                 launch {
49                     viewModel.validatedAttestation.collect { attestation ->
50                         val matched = attestation != null
51                         lockPatternView.isEnabled = !matched
52                         if (matched) {
53                             host.onCredentialMatched(attestation!!)
54                         }
55                     }
56                 }
57             }
58         }
59     }
60 }
61 
62 private class OnPatternDetectedListener(
63     private val onDetected: (pattern: List<LockPatternView.Cell>) -> Unit
64 ) : LockPatternView.OnPatternListener {
onPatternCellAddednull65     override fun onPatternCellAdded(pattern: List<LockPatternView.Cell>) {}
onPatternClearednull66     override fun onPatternCleared() {}
onPatternStartnull67     override fun onPatternStart() {}
onPatternDetectednull68     override fun onPatternDetected(pattern: List<LockPatternView.Cell>) {
69         onDetected(pattern)
70     }
71 }
72 
Listnull73 private fun List<LockPatternView.Cell>.isPatternTooShort(): Boolean =
74     size < LockPatternUtils.MIN_PATTERN_REGISTER_FAIL
75