1 /* 2 * Copyright (C) 2021 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.controls 18 19 import android.service.controls.DeviceTypes.DeviceType 20 21 import com.android.internal.logging.InstanceIdSequence 22 import com.android.systemui.dagger.SysUISingleton 23 import com.android.systemui.shared.system.SysUiStatsLog 24 25 import javax.inject.Inject 26 27 /** 28 * Implementation for logging UI events related to controls 29 */ 30 @SysUISingleton 31 class ControlsMetricsLoggerImpl @Inject constructor() : ControlsMetricsLogger { 32 33 companion object { 34 private const val INSTANCE_ID_MAX = 1 shl 13 35 } 36 37 private val instanceIdSequence = InstanceIdSequence(INSTANCE_ID_MAX) 38 private var instanceId = 0 39 assignInstanceIdnull40 override fun assignInstanceId() { 41 instanceId = instanceIdSequence.newInstanceId().id 42 } 43 44 /** 45 * {@see ControlsMetricsLogger#log} 46 */ lognull47 override fun log( 48 eventId: Int, 49 @DeviceType deviceType: Int, 50 uid: Int, 51 isLocked: Boolean 52 ) { 53 SysUiStatsLog.write( 54 SysUiStatsLog.DEVICE_CONTROL_CHANGED, 55 eventId, 56 instanceId, 57 deviceType, 58 uid, 59 isLocked 60 ) 61 } 62 } 63