1 /*
2  * Copyright (C) 2022 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 package com.android.customization.module.logging
17 
18 import android.stats.style.StyleEnums.CLOCK_SIZE_UNSPECIFIED
19 import android.stats.style.StyleEnums.COLOR_SOURCE_UNSPECIFIED
20 import android.stats.style.StyleEnums.DATE_PREFERENCE_UNSPECIFIED
21 import android.stats.style.StyleEnums.EFFECT_PREFERENCE_UNSPECIFIED
22 import android.stats.style.StyleEnums.LAUNCHED_PREFERENCE_UNSPECIFIED
23 import android.stats.style.StyleEnums.LOCATION_PREFERENCE_UNSPECIFIED
24 import android.stats.style.StyleEnums.SET_WALLPAPER_ENTRY_POINT_UNSPECIFIED
25 import android.stats.style.StyleEnums.WALLPAPER_DESTINATION_UNSPECIFIED
26 import com.android.systemui.shared.system.SysUiStatsLog
27 import com.android.systemui.shared.system.SysUiStatsLog.STYLE_UI_CHANGED
28 import com.android.wallpaper.module.logging.UserEventLogger.SetWallpaperEntryPoint
29 
30 /** The builder for [SysUiStatsLog]. */
31 class SysUiStatsLogger(val action: Int) {
32 
33     private var colorPackageHash = 0
34     private var fontPackageHash = 0
35     private var shapePackageHash = 0
36     private var clockPackageHash = 0
37     private var launcherGrid = 0
38     private var wallpaperCategoryHash = 0
39     private var wallpaperIdHash = 0
40     private var colorPreference = 0
41     private var locationPreference = LOCATION_PREFERENCE_UNSPECIFIED
42     private var datePreference = DATE_PREFERENCE_UNSPECIFIED
43     private var launchedPreference = LAUNCHED_PREFERENCE_UNSPECIFIED
44     private var effectPreference = EFFECT_PREFERENCE_UNSPECIFIED
45     private var effectIdHash = 0
46     private var lockWallpaperCategoryHash = 0
47     private var lockWallpaperIdHash = 0
48     private var firstLaunchDateSinceSetup = 0
49     private var firstWallpaperApplyDateSinceSetup = 0
50     private var appLaunchCount = 0
51     private var colorVariant = 0
52     private var timeElapsedMillis = 0L
53     private var effectResultCode = -1
54     private var appSessionId = 0
55     private var setWallpaperEntryPoint = SET_WALLPAPER_ENTRY_POINT_UNSPECIFIED
56     private var wallpaperDestination = WALLPAPER_DESTINATION_UNSPECIFIED
57     private var colorSource = COLOR_SOURCE_UNSPECIFIED
58     private var seedColor = 0
59     private var clockSize = CLOCK_SIZE_UNSPECIFIED
60     private var toggleOn = false
61     private var shortcut = ""
62     private var shortcutSlotId = ""
63     private var lockEffectIdHash = 0
64 
<lambda>null65     fun setColorPackageHash(colorPackageHash: Int) = apply {
66         this.colorPackageHash = colorPackageHash
67     }
68 
<lambda>null69     fun setFontPackageHash(fontPackageHash: Int) = apply { this.fontPackageHash = fontPackageHash }
70 
<lambda>null71     fun setShapePackageHash(shapePackageHash: Int) = apply {
72         this.shapePackageHash = shapePackageHash
73     }
74 
<lambda>null75     fun setClockPackageHash(clockPackageHash: Int) = apply {
76         this.clockPackageHash = clockPackageHash
77     }
78 
<lambda>null79     fun setLauncherGrid(launcherGrid: Int) = apply { this.launcherGrid = launcherGrid }
80 
<lambda>null81     fun setWallpaperCategoryHash(wallpaperCategoryHash: Int) = apply {
82         this.wallpaperCategoryHash = wallpaperCategoryHash
83     }
84 
<lambda>null85     fun setWallpaperIdHash(wallpaperIdHash: Int) = apply { this.wallpaperIdHash = wallpaperIdHash }
86 
<lambda>null87     fun setColorPreference(colorPreference: Int) = apply { this.colorPreference = colorPreference }
88 
<lambda>null89     fun setLocationPreference(locationPreference: Int) = apply {
90         this.locationPreference = locationPreference
91     }
92 
<lambda>null93     fun setDatePreference(datePreference: Int) = apply { this.datePreference = datePreference }
94 
<lambda>null95     fun setLaunchedPreference(launchedPreference: Int) = apply {
96         this.launchedPreference = launchedPreference
97     }
98 
<lambda>null99     fun setEffectPreference(effectPreference: Int) = apply {
100         this.effectPreference = effectPreference
101     }
102 
<lambda>null103     fun setEffectIdHash(effectIdHash: Int) = apply { this.effectIdHash = effectIdHash }
104 
<lambda>null105     fun setLockWallpaperCategoryHash(lockWallpaperCategoryHash: Int) = apply {
106         this.lockWallpaperCategoryHash = lockWallpaperCategoryHash
107     }
108 
<lambda>null109     fun setLockWallpaperIdHash(lockWallpaperIdHash: Int) = apply {
110         this.lockWallpaperIdHash = lockWallpaperIdHash
111     }
112 
<lambda>null113     fun setFirstLaunchDateSinceSetup(firstLaunchDateSinceSetup: Int) = apply {
114         this.firstLaunchDateSinceSetup = firstLaunchDateSinceSetup
115     }
116 
<lambda>null117     fun setFirstWallpaperApplyDateSinceSetup(firstWallpaperApplyDateSinceSetup: Int) = apply {
118         this.firstWallpaperApplyDateSinceSetup = firstWallpaperApplyDateSinceSetup
119     }
120 
<lambda>null121     fun setAppLaunchCount(appLaunchCount: Int) = apply { this.appLaunchCount = appLaunchCount }
122 
<lambda>null123     fun setColorVariant(colorVariant: Int) = apply { this.colorVariant = colorVariant }
124 
<lambda>null125     fun setTimeElapsed(timeElapsedMillis: Long) = apply {
126         this.timeElapsedMillis = timeElapsedMillis
127     }
128 
<lambda>null129     fun setEffectResultCode(effectResultCode: Int) = apply {
130         this.effectResultCode = effectResultCode
131     }
132 
<lambda>null133     fun setAppSessionId(sessionId: Int) = apply { this.appSessionId = sessionId }
134 
<lambda>null135     fun setSetWallpaperEntryPoint(@SetWallpaperEntryPoint setWallpaperEntryPoint: Int) = apply {
136         this.setWallpaperEntryPoint = setWallpaperEntryPoint
137     }
138 
<lambda>null139     fun setWallpaperDestination(wallpaperDestination: Int) = apply {
140         this.wallpaperDestination = wallpaperDestination
141     }
142 
<lambda>null143     fun setColorSource(colorSource: Int) = apply { this.colorSource = colorSource }
144 
<lambda>null145     fun setSeedColor(seedColor: Int) = apply { this.seedColor = seedColor }
146 
<lambda>null147     fun setClockSize(clockSize: Int) = apply { this.clockSize = clockSize }
148 
<lambda>null149     fun setToggleOn(toggleOn: Boolean) = apply { this.toggleOn = toggleOn }
150 
setShortcutnull151     fun setShortcut(shortcut: String) = apply { this.shortcut = shortcut }
152 
<lambda>null153     fun setShortcutSlotId(shortcutSlotId: String) = apply { this.shortcutSlotId = shortcutSlotId }
154 
<lambda>null155     fun setLockEffectIdHash(lockEffectIdHash: Int) = apply {
156         this.lockEffectIdHash = lockEffectIdHash
157     }
158 
lognull159     fun log() {
160         SysUiStatsLog.write(
161             STYLE_UI_CHANGED,
162             action,
163             colorPackageHash,
164             fontPackageHash,
165             shapePackageHash,
166             clockPackageHash,
167             launcherGrid,
168             wallpaperCategoryHash,
169             wallpaperIdHash,
170             colorPreference,
171             locationPreference,
172             datePreference,
173             launchedPreference,
174             effectPreference,
175             effectIdHash,
176             lockWallpaperCategoryHash,
177             lockWallpaperIdHash,
178             firstLaunchDateSinceSetup,
179             firstWallpaperApplyDateSinceSetup,
180             appLaunchCount,
181             colorVariant,
182             timeElapsedMillis,
183             effectResultCode,
184             appSessionId,
185             setWallpaperEntryPoint,
186             wallpaperDestination,
187             colorSource,
188             seedColor,
189             clockSize,
190             toggleOn,
191             shortcut,
192             shortcutSlotId,
193             lockEffectIdHash,
194         )
195     }
196 }
197