1 /* 2 * Copyright (C) 2025 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.settings.metrics 18 19 import android.content.Context 20 import com.android.settings.overlay.FeatureFactory 21 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider 22 import com.android.settingslib.metadata.PreferenceMetadata 23 import com.android.settingslib.metadata.PreferenceScreenMetadata 24 import com.android.settingslib.metadata.PreferenceUiActionMetricsLogger 25 26 /** [PreferenceUiActionMetricsLogger] of Settings app. */ 27 class SettingsMetricsLogger 28 @JvmOverloads 29 constructor( 30 private val context: Context, 31 private val metricsFeatureProvider: MetricsFeatureProvider = 32 FeatureFactory.featureFactory.metricsFeatureProvider, 33 ) : PreferenceUiActionMetricsLogger { 34 logPreferenceValueChangenull35 override fun logPreferenceValueChange( 36 screen: PreferenceScreenMetadata, 37 preference: PreferenceMetadata, 38 value: Any?, 39 ) { 40 if (preference !is PreferenceActionMetricsProvider) return 41 when (value) { 42 is Boolean -> 43 metricsFeatureProvider.action(context, preference.preferenceActionMetrics, value) 44 else -> {} 45 } 46 } 47 } 48