1 /*
2  * Copyright (C) 2024 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.spa.core.instrumentation
18 
19 import android.app.settings.SettingsEnums
20 import android.os.Bundle
21 import android.util.Log
22 import com.android.settings.overlay.FeatureFactory.Companion.featureFactory
23 import com.android.settingslib.spa.framework.common.LOG_DATA_METRICS_CATEGORY
24 import com.android.settingslib.spa.framework.common.LogCategory
25 import com.android.settingslib.spa.framework.common.LogEvent
26 import com.android.settingslib.spa.framework.common.SpaLogger
27 
28 /**
29  * To receive the events from spa framework and logging the these events.
30  */
31 object SpaLogMetricsProvider : SpaLogger {
eventnull32     override fun event(id: String, event: LogEvent, category: LogCategory, extraData: Bundle) {
33         val metricsFeatureProvider = featureFactory.metricsFeatureProvider
34         val metricsCategoryOfPage = extraData.getInt(LOG_DATA_METRICS_CATEGORY)
35         Log.d("SpaLogMetricsProvider", "${event} page ${metricsCategoryOfPage}")
36 
37         if (metricsCategoryOfPage == SettingsEnums.PAGE_UNKNOWN) {
38             return
39         }
40 
41         when (event) {
42             LogEvent.PAGE_ENTER -> {
43                 metricsFeatureProvider.visible(
44                     null,
45                     SettingsEnums.PAGE_UNKNOWN,
46                     metricsCategoryOfPage,
47                     0
48                 )
49             }
50 
51             LogEvent.PAGE_LEAVE -> {
52                 metricsFeatureProvider.hidden(
53                     null,
54                     metricsCategoryOfPage,
55                     0
56                 )
57             }
58 
59             else -> return
60         }
61     }
62 }
63