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.credentialmanager.logging 18 19 import androidx.compose.runtime.Composable 20 import androidx.compose.runtime.LaunchedEffect 21 import com.android.internal.logging.InstanceId 22 import com.android.internal.logging.InstanceIdSequence 23 import com.android.internal.logging.UiEventLogger 24 import com.android.internal.logging.UiEventLoggerImpl 25 26 class UIMetrics() { 27 private val INSTANCE_ID_MAX = 1 shl 20 28 private val mUiEventLogger: UiEventLogger = UiEventLoggerImpl() 29 val mInstanceIdSequence: InstanceIdSequence = InstanceIdSequence(INSTANCE_ID_MAX) 30 31 var mInstanceId: InstanceId = mInstanceIdSequence.newInstanceId() 32 resetInstanceIdnull33 fun resetInstanceId() { 34 this.mInstanceId = mInstanceIdSequence.newInstanceId() 35 } 36 37 @Composable lognull38 fun log(event: UiEventLogger.UiEventEnum) { 39 val instanceId: InstanceId = mInstanceId 40 LaunchedEffect(true) { 41 mUiEventLogger.log(event, instanceId) 42 } 43 } 44 45 @Composable lognull46 fun log(event: UiEventLogger.UiEventEnum, packageName: String?) { 47 val instanceId: InstanceId = mInstanceId 48 LaunchedEffect(true) { 49 mUiEventLogger.logWithInstanceId(event, /*uid=*/0, packageName, instanceId) 50 } 51 } 52 53 @Composable lognull54 fun log(event: UiEventLogger.UiEventEnum, instanceId: InstanceId, packageName: String?) { 55 LaunchedEffect(true) { 56 mUiEventLogger.logWithInstanceId(event, /*uid=*/0, packageName, instanceId) 57 } 58 } 59 logNormalnull60 fun logNormal(event: UiEventLogger.UiEventEnum, packageName: String?) { 61 mUiEventLogger.logWithInstanceId(event, /*uid=*/0, packageName, mInstanceId) 62 } 63 } 64