• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2023 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.biometrics.ui.binder
18 
19 import android.util.Log
20 import androidx.core.view.isInvisible
21 import androidx.lifecycle.Lifecycle
22 import androidx.lifecycle.repeatOnLifecycle
23 import com.android.systemui.biometrics.domain.interactor.UdfpsOverlayInteractor
24 import com.android.systemui.biometrics.ui.view.UdfpsTouchOverlay
25 import com.android.systemui.biometrics.ui.viewmodel.UdfpsTouchOverlayViewModel
26 import com.android.systemui.lifecycle.repeatWhenAttached
27 import com.android.app.tracing.coroutines.launchTraced as launch
28 
29 object UdfpsTouchOverlayBinder {
30 
31     /**
32      * Updates visibility for the UdfpsTouchOverlay which controls whether the view will receive
33      * touches or not. For some devices, this is instead handled by UdfpsOverlayInteractor, so this
34      * viewBinder will send the information to the interactor.
35      */
36     @JvmStatic
37     fun bind(
38         view: UdfpsTouchOverlay,
39         viewModel: UdfpsTouchOverlayViewModel,
40         udfpsOverlayInteractor: UdfpsOverlayInteractor,
41     ) {
42         view.repeatWhenAttached {
43             repeatOnLifecycle(Lifecycle.State.CREATED) {
44                 launch {
45                         viewModel.shouldHandleTouches.collect { shouldHandleTouches ->
46                             Log.d(
47                                 "UdfpsTouchOverlayBinder",
48                                 "[$view]: update shouldHandleTouches=$shouldHandleTouches",
49                             )
50                             view.isInvisible = !shouldHandleTouches
51                             udfpsOverlayInteractor.setHandleTouches(shouldHandleTouches)
52                         }
53                     }
54                     .invokeOnCompletion {
55                         Log.d(
56                             "UdfpsTouchOverlayBinder",
57                             "[$view-detached]: update shouldHandleTouches=false",
58                         )
59                         udfpsOverlayInteractor.setHandleTouches(false)
60                     }
61             }
62         }
63     }
64 }
65