1 /* 2 * 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.bouncer.domain.interactor 18 19 import android.os.Build 20 import android.util.Log 21 import com.android.systemui.CoreStartable 22 import com.android.systemui.bouncer.data.repository.BouncerMessageRepository 23 import com.android.systemui.bouncer.shared.model.BouncerMessageModel 24 import com.android.systemui.dagger.SysUISingleton 25 import com.android.systemui.dagger.qualifiers.Application 26 import javax.inject.Inject 27 import kotlinx.coroutines.CoroutineScope 28 import kotlinx.coroutines.flow.Flow 29 import kotlinx.coroutines.launch 30 31 private val TAG = BouncerMessageAuditLogger::class.simpleName!! 32 33 /** Logger that echoes bouncer messages state to logcat in debuggable builds. */ 34 @SysUISingleton 35 class BouncerMessageAuditLogger 36 @Inject 37 constructor( 38 @Application private val scope: CoroutineScope, 39 private val repository: BouncerMessageRepository, 40 private val interactor: BouncerMessageInteractor, 41 ) : CoreStartable { 42 override fun start() { 43 if (Build.isDebuggable()) { 44 collectAndLog(repository.biometricAuthMessage, "biometricMessage: ") 45 collectAndLog(repository.primaryAuthMessage, "primaryAuthMessage: ") 46 collectAndLog(repository.customMessage, "customMessage: ") 47 collectAndLog(repository.faceAcquisitionMessage, "faceAcquisitionMessage: ") 48 collectAndLog( 49 repository.fingerprintAcquisitionMessage, 50 "fingerprintAcquisitionMessage: " 51 ) 52 collectAndLog(repository.authFlagsMessage, "authFlagsMessage: ") 53 collectAndLog(interactor.bouncerMessage, "interactor.bouncerMessage: ") 54 } 55 } 56 57 private fun collectAndLog(flow: Flow<BouncerMessageModel?>, context: String) { 58 scope.launch { flow.collect { Log.d(TAG, context + it) } } 59 } 60 } 61