Loading src/com/android/customization/module/logging/AppSessionId.kt 0 → 100644 +43 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.customization.module.logging import com.android.internal.logging.InstanceId import com.android.internal.logging.InstanceIdSequence import javax.inject.Inject import javax.inject.Singleton @Singleton class AppSessionId @Inject constructor() { private var sessionId: InstanceId = newInstanceId() fun createNewId(): AppSessionId { sessionId = newInstanceId() return this } fun getId(): Int { return sessionId.hashCode() } private fun newInstanceId(): InstanceId = InstanceIdSequence(INSTANCE_ID_MAX).newInstanceId() companion object { // At most 20 bits: ~1m possibilities, ~0.5% probability of collision in 100 values private const val INSTANCE_ID_MAX = 1 shl 20 } } src/com/android/customization/module/logging/SysUiStatsLogger.kt +3 −3 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ class SysUiStatsLogger(val action: Int) { private var colorVariant = 0 private var timeElapsedMillis = 0L private var effectResultCode = -1 private var sessionId = 0 private var appSessionId = 0 private var setWallpaperEntryPoint = STYLE_UICHANGED__SET_WALLPAPER_ENTRY_POINT__SET_WALLPAPER_ENTRY_POINT_UNSPECIFIED private var wallpaperDestination = Loading Loading @@ -133,7 +133,7 @@ class SysUiStatsLogger(val action: Int) { this.effectResultCode = effectResultCode } fun setSessionId(sessionId: Int) = apply { this.sessionId = sessionId } fun setAppSessionId(sessionId: Int) = apply { this.appSessionId = sessionId } fun setSetWallpaperEntryPoint(@SetWallpaperEntryPoint setWallpaperEntryPoint: Int) = apply { this.setWallpaperEntryPoint = setWallpaperEntryPoint Loading Loading @@ -180,7 +180,7 @@ class SysUiStatsLogger(val action: Int) { colorVariant, timeElapsedMillis, effectResultCode, sessionId, appSessionId, setWallpaperEntryPoint, wallpaperDestination, colorSource, Loading src/com/android/customization/module/logging/ThemesUserEventLoggerImpl.kt +35 −8 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ class ThemesUserEventLoggerImpl @Inject constructor( private val preferences: WallpaperPreferences, private val appSessionId: AppSessionId, ) : ThemesUserEventLogger { override fun logSnapshot() { Loading @@ -54,6 +55,7 @@ constructor( override fun logAppLaunched(launchSource: Intent) { SysUiStatsLogger(StyleEnums.APP_LAUNCHED) .setAppSessionId(appSessionId.createNewId().getId()) .setLaunchedPreference(launchSource.getAppLaunchSource()) .log() } Loading @@ -70,6 +72,7 @@ constructor( val isHomeWallpaperSet = destination == DEST_HOME_SCREEN || destination == DEST_BOTH val isLockWallpaperSet = destination == DEST_LOCK_SCREEN || destination == DEST_BOTH SysUiStatsLogger(StyleEnums.WALLPAPER_APPLIED) .setAppSessionId(appSessionId.getId()) .setWallpaperCategoryHash(if (isHomeWallpaperSet) categoryHash else 0) .setWallpaperIdHash(if (isHomeWallpaperSet) wallpaperIdHash else 0) .setLockWallpaperCategoryHash(if (isLockWallpaperSet) categoryHash else 0) Loading @@ -87,6 +90,7 @@ constructor( resultCode: Int ) { SysUiStatsLogger(StyleEnums.WALLPAPER_EFFECT_APPLIED) .setAppSessionId(appSessionId.getId()) .setEffectPreference(status) .setEffectIdHash(getIdHashCode(effect)) .setTimeElapsed(timeElapsedMillis) Loading @@ -96,6 +100,7 @@ constructor( override fun logEffectProbe(effect: String, @EffectStatus status: Int) { SysUiStatsLogger(StyleEnums.WALLPAPER_EFFECT_PROBE) .setAppSessionId(appSessionId.getId()) .setEffectPreference(status) .setEffectIdHash(getIdHashCode(effect)) .log() Loading @@ -107,6 +112,7 @@ constructor( timeElapsedMillis: Long ) { SysUiStatsLogger(StyleEnums.WALLPAPER_EFFECT_FG_DOWNLOAD) .setAppSessionId(appSessionId.getId()) .setEffectPreference(status) .setEffectIdHash(getIdHashCode(effect)) .setTimeElapsed(timeElapsedMillis) Loading @@ -114,11 +120,11 @@ constructor( } override fun logResetApplied() { SysUiStatsLogger(StyleEnums.RESET_APPLIED).log() SysUiStatsLogger(StyleEnums.RESET_APPLIED).setAppSessionId(appSessionId.getId()).log() } override fun logWallpaperExploreButtonClicked() { SysUiStatsLogger(StyleEnums.WALLPAPER_EXPLORE).log() SysUiStatsLogger(StyleEnums.WALLPAPER_EXPLORE).setAppSessionId(appSessionId.getId()).log() } override fun logThemeColorApplied( Loading @@ -127,6 +133,7 @@ constructor( seedColor: Int, ) { SysUiStatsLogger(StyleEnums.THEME_COLOR_APPLIED) .setAppSessionId(appSessionId.getId()) .setColorSource(source) .setColorVariant(variant) .setSeedColor(seedColor) Loading @@ -134,40 +141,60 @@ constructor( } override fun logGridApplied(grid: GridOption) { SysUiStatsLogger(StyleEnums.GRID_APPLIED).setLauncherGrid(grid.getLauncherGridInt()).log() SysUiStatsLogger(StyleEnums.GRID_APPLIED) .setAppSessionId(appSessionId.getId()) .setLauncherGrid(grid.getLauncherGridInt()) .log() } override fun logClockApplied(clockId: String) { SysUiStatsLogger(StyleEnums.CLOCK_APPLIED).setClockPackageHash(getIdHashCode(clockId)).log() SysUiStatsLogger(StyleEnums.CLOCK_APPLIED) .setAppSessionId(appSessionId.getId()) .setClockPackageHash(getIdHashCode(clockId)) .log() } override fun logClockColorApplied(seedColor: Int) { SysUiStatsLogger(StyleEnums.CLOCK_COLOR_APPLIED).setSeedColor(seedColor).log() SysUiStatsLogger(StyleEnums.CLOCK_COLOR_APPLIED) .setAppSessionId(appSessionId.getId()) .setSeedColor(seedColor) .log() } override fun logClockSizeApplied(@ClockSize clockSize: Int) { SysUiStatsLogger(StyleEnums.CLOCK_SIZE_APPLIED).setClockSize(clockSize).log() SysUiStatsLogger(StyleEnums.CLOCK_SIZE_APPLIED) .setAppSessionId(appSessionId.getId()) .setClockSize(clockSize) .log() } override fun logThemedIconApplied(useThemeIcon: Boolean) { SysUiStatsLogger(StyleEnums.THEMED_ICON_APPLIED).setToggleOn(useThemeIcon).log() SysUiStatsLogger(StyleEnums.THEMED_ICON_APPLIED) .setAppSessionId(appSessionId.getId()) .setToggleOn(useThemeIcon) .log() } override fun logLockScreenNotificationApplied(showLockScreenNotifications: Boolean) { SysUiStatsLogger(StyleEnums.LOCK_SCREEN_NOTIFICATION_APPLIED) .setAppSessionId(appSessionId.getId()) .setToggleOn(showLockScreenNotifications) .log() } override fun logShortcutApplied(shortcut: String, shortcutSlotId: String) { SysUiStatsLogger(StyleEnums.SHORTCUT_APPLIED) .setAppSessionId(appSessionId.getId()) .setShortcut(shortcut) .setShortcutSlotId(shortcutSlotId) .log() } override fun logDarkThemeApplied(useDarkTheme: Boolean) { SysUiStatsLogger(StyleEnums.DARK_THEME_APPLIED).setToggleOn(useDarkTheme).log() SysUiStatsLogger(StyleEnums.DARK_THEME_APPLIED) .setAppSessionId(appSessionId.getId()) .setToggleOn(useDarkTheme) .log() } /** Loading Loading
src/com/android/customization/module/logging/AppSessionId.kt 0 → 100644 +43 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.customization.module.logging import com.android.internal.logging.InstanceId import com.android.internal.logging.InstanceIdSequence import javax.inject.Inject import javax.inject.Singleton @Singleton class AppSessionId @Inject constructor() { private var sessionId: InstanceId = newInstanceId() fun createNewId(): AppSessionId { sessionId = newInstanceId() return this } fun getId(): Int { return sessionId.hashCode() } private fun newInstanceId(): InstanceId = InstanceIdSequence(INSTANCE_ID_MAX).newInstanceId() companion object { // At most 20 bits: ~1m possibilities, ~0.5% probability of collision in 100 values private const val INSTANCE_ID_MAX = 1 shl 20 } }
src/com/android/customization/module/logging/SysUiStatsLogger.kt +3 −3 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ class SysUiStatsLogger(val action: Int) { private var colorVariant = 0 private var timeElapsedMillis = 0L private var effectResultCode = -1 private var sessionId = 0 private var appSessionId = 0 private var setWallpaperEntryPoint = STYLE_UICHANGED__SET_WALLPAPER_ENTRY_POINT__SET_WALLPAPER_ENTRY_POINT_UNSPECIFIED private var wallpaperDestination = Loading Loading @@ -133,7 +133,7 @@ class SysUiStatsLogger(val action: Int) { this.effectResultCode = effectResultCode } fun setSessionId(sessionId: Int) = apply { this.sessionId = sessionId } fun setAppSessionId(sessionId: Int) = apply { this.appSessionId = sessionId } fun setSetWallpaperEntryPoint(@SetWallpaperEntryPoint setWallpaperEntryPoint: Int) = apply { this.setWallpaperEntryPoint = setWallpaperEntryPoint Loading Loading @@ -180,7 +180,7 @@ class SysUiStatsLogger(val action: Int) { colorVariant, timeElapsedMillis, effectResultCode, sessionId, appSessionId, setWallpaperEntryPoint, wallpaperDestination, colorSource, Loading
src/com/android/customization/module/logging/ThemesUserEventLoggerImpl.kt +35 −8 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ class ThemesUserEventLoggerImpl @Inject constructor( private val preferences: WallpaperPreferences, private val appSessionId: AppSessionId, ) : ThemesUserEventLogger { override fun logSnapshot() { Loading @@ -54,6 +55,7 @@ constructor( override fun logAppLaunched(launchSource: Intent) { SysUiStatsLogger(StyleEnums.APP_LAUNCHED) .setAppSessionId(appSessionId.createNewId().getId()) .setLaunchedPreference(launchSource.getAppLaunchSource()) .log() } Loading @@ -70,6 +72,7 @@ constructor( val isHomeWallpaperSet = destination == DEST_HOME_SCREEN || destination == DEST_BOTH val isLockWallpaperSet = destination == DEST_LOCK_SCREEN || destination == DEST_BOTH SysUiStatsLogger(StyleEnums.WALLPAPER_APPLIED) .setAppSessionId(appSessionId.getId()) .setWallpaperCategoryHash(if (isHomeWallpaperSet) categoryHash else 0) .setWallpaperIdHash(if (isHomeWallpaperSet) wallpaperIdHash else 0) .setLockWallpaperCategoryHash(if (isLockWallpaperSet) categoryHash else 0) Loading @@ -87,6 +90,7 @@ constructor( resultCode: Int ) { SysUiStatsLogger(StyleEnums.WALLPAPER_EFFECT_APPLIED) .setAppSessionId(appSessionId.getId()) .setEffectPreference(status) .setEffectIdHash(getIdHashCode(effect)) .setTimeElapsed(timeElapsedMillis) Loading @@ -96,6 +100,7 @@ constructor( override fun logEffectProbe(effect: String, @EffectStatus status: Int) { SysUiStatsLogger(StyleEnums.WALLPAPER_EFFECT_PROBE) .setAppSessionId(appSessionId.getId()) .setEffectPreference(status) .setEffectIdHash(getIdHashCode(effect)) .log() Loading @@ -107,6 +112,7 @@ constructor( timeElapsedMillis: Long ) { SysUiStatsLogger(StyleEnums.WALLPAPER_EFFECT_FG_DOWNLOAD) .setAppSessionId(appSessionId.getId()) .setEffectPreference(status) .setEffectIdHash(getIdHashCode(effect)) .setTimeElapsed(timeElapsedMillis) Loading @@ -114,11 +120,11 @@ constructor( } override fun logResetApplied() { SysUiStatsLogger(StyleEnums.RESET_APPLIED).log() SysUiStatsLogger(StyleEnums.RESET_APPLIED).setAppSessionId(appSessionId.getId()).log() } override fun logWallpaperExploreButtonClicked() { SysUiStatsLogger(StyleEnums.WALLPAPER_EXPLORE).log() SysUiStatsLogger(StyleEnums.WALLPAPER_EXPLORE).setAppSessionId(appSessionId.getId()).log() } override fun logThemeColorApplied( Loading @@ -127,6 +133,7 @@ constructor( seedColor: Int, ) { SysUiStatsLogger(StyleEnums.THEME_COLOR_APPLIED) .setAppSessionId(appSessionId.getId()) .setColorSource(source) .setColorVariant(variant) .setSeedColor(seedColor) Loading @@ -134,40 +141,60 @@ constructor( } override fun logGridApplied(grid: GridOption) { SysUiStatsLogger(StyleEnums.GRID_APPLIED).setLauncherGrid(grid.getLauncherGridInt()).log() SysUiStatsLogger(StyleEnums.GRID_APPLIED) .setAppSessionId(appSessionId.getId()) .setLauncherGrid(grid.getLauncherGridInt()) .log() } override fun logClockApplied(clockId: String) { SysUiStatsLogger(StyleEnums.CLOCK_APPLIED).setClockPackageHash(getIdHashCode(clockId)).log() SysUiStatsLogger(StyleEnums.CLOCK_APPLIED) .setAppSessionId(appSessionId.getId()) .setClockPackageHash(getIdHashCode(clockId)) .log() } override fun logClockColorApplied(seedColor: Int) { SysUiStatsLogger(StyleEnums.CLOCK_COLOR_APPLIED).setSeedColor(seedColor).log() SysUiStatsLogger(StyleEnums.CLOCK_COLOR_APPLIED) .setAppSessionId(appSessionId.getId()) .setSeedColor(seedColor) .log() } override fun logClockSizeApplied(@ClockSize clockSize: Int) { SysUiStatsLogger(StyleEnums.CLOCK_SIZE_APPLIED).setClockSize(clockSize).log() SysUiStatsLogger(StyleEnums.CLOCK_SIZE_APPLIED) .setAppSessionId(appSessionId.getId()) .setClockSize(clockSize) .log() } override fun logThemedIconApplied(useThemeIcon: Boolean) { SysUiStatsLogger(StyleEnums.THEMED_ICON_APPLIED).setToggleOn(useThemeIcon).log() SysUiStatsLogger(StyleEnums.THEMED_ICON_APPLIED) .setAppSessionId(appSessionId.getId()) .setToggleOn(useThemeIcon) .log() } override fun logLockScreenNotificationApplied(showLockScreenNotifications: Boolean) { SysUiStatsLogger(StyleEnums.LOCK_SCREEN_NOTIFICATION_APPLIED) .setAppSessionId(appSessionId.getId()) .setToggleOn(showLockScreenNotifications) .log() } override fun logShortcutApplied(shortcut: String, shortcutSlotId: String) { SysUiStatsLogger(StyleEnums.SHORTCUT_APPLIED) .setAppSessionId(appSessionId.getId()) .setShortcut(shortcut) .setShortcutSlotId(shortcutSlotId) .log() } override fun logDarkThemeApplied(useDarkTheme: Boolean) { SysUiStatsLogger(StyleEnums.DARK_THEME_APPLIED).setToggleOn(useDarkTheme).log() SysUiStatsLogger(StyleEnums.DARK_THEME_APPLIED) .setAppSessionId(appSessionId.getId()) .setToggleOn(useDarkTheme) .log() } /** Loading