Add session ID to WPP logging
Test: Manually tested that session ID is logged. See bug.
Bug: 299659307
Change-Id: I051bfcc30bca89dcd34cd293dfaed8f62cd41298
diff --git a/src/com/android/customization/module/logging/AppSessionId.kt b/src/com/android/customization/module/logging/AppSessionId.kt
new file mode 100644
index 0000000..c831f22
--- /dev/null
+++ b/src/com/android/customization/module/logging/AppSessionId.kt
@@ -0,0 +1,43 @@
+/*
+ * 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
+ }
+}
diff --git a/src/com/android/customization/module/logging/SysUiStatsLogger.kt b/src/com/android/customization/module/logging/SysUiStatsLogger.kt
index 14f0be6..6c55df8 100644
--- a/src/com/android/customization/module/logging/SysUiStatsLogger.kt
+++ b/src/com/android/customization/module/logging/SysUiStatsLogger.kt
@@ -53,7 +53,7 @@
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 =
@@ -133,7 +133,7 @@
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
@@ -180,7 +180,7 @@
colorVariant,
timeElapsedMillis,
effectResultCode,
- sessionId,
+ appSessionId,
setWallpaperEntryPoint,
wallpaperDestination,
colorSource,
diff --git a/src/com/android/customization/module/logging/ThemesUserEventLoggerImpl.kt b/src/com/android/customization/module/logging/ThemesUserEventLoggerImpl.kt
index 8998dee..e4b8c8b 100644
--- a/src/com/android/customization/module/logging/ThemesUserEventLoggerImpl.kt
+++ b/src/com/android/customization/module/logging/ThemesUserEventLoggerImpl.kt
@@ -40,6 +40,7 @@
@Inject
constructor(
private val preferences: WallpaperPreferences,
+ private val appSessionId: AppSessionId,
) : ThemesUserEventLogger {
override fun logSnapshot() {
@@ -54,6 +55,7 @@
override fun logAppLaunched(launchSource: Intent) {
SysUiStatsLogger(StyleEnums.APP_LAUNCHED)
+ .setAppSessionId(appSessionId.createNewId().getId())
.setLaunchedPreference(launchSource.getAppLaunchSource())
.log()
}
@@ -70,6 +72,7 @@
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)
@@ -87,6 +90,7 @@
resultCode: Int
) {
SysUiStatsLogger(StyleEnums.WALLPAPER_EFFECT_APPLIED)
+ .setAppSessionId(appSessionId.getId())
.setEffectPreference(status)
.setEffectIdHash(getIdHashCode(effect))
.setTimeElapsed(timeElapsedMillis)
@@ -96,6 +100,7 @@
override fun logEffectProbe(effect: String, @EffectStatus status: Int) {
SysUiStatsLogger(StyleEnums.WALLPAPER_EFFECT_PROBE)
+ .setAppSessionId(appSessionId.getId())
.setEffectPreference(status)
.setEffectIdHash(getIdHashCode(effect))
.log()
@@ -107,6 +112,7 @@
timeElapsedMillis: Long
) {
SysUiStatsLogger(StyleEnums.WALLPAPER_EFFECT_FG_DOWNLOAD)
+ .setAppSessionId(appSessionId.getId())
.setEffectPreference(status)
.setEffectIdHash(getIdHashCode(effect))
.setTimeElapsed(timeElapsedMillis)
@@ -114,11 +120,11 @@
}
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(
@@ -127,6 +133,7 @@
seedColor: Int,
) {
SysUiStatsLogger(StyleEnums.THEME_COLOR_APPLIED)
+ .setAppSessionId(appSessionId.getId())
.setColorSource(source)
.setColorVariant(variant)
.setSeedColor(seedColor)
@@ -134,40 +141,60 @@
}
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()
}
/**