Skip to content

Commit e2c8a67

Browse files
runningcodeclaude
andcommitted
fix(snapshot): Use symbolic constants for night mode detection
Replace hardcoded hex literals (0x30, 0x20) with UI_MODE_NIGHT_MASK and UI_MODE_NIGHT_YES constants from PreviewConstants for consistency with the rest of the generated test code. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 67c9dc9 commit e2c8a67

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

plugin-build/src/main/kotlin/io/sentry/android/gradle/snapshot/GenerateSnapshotTestsTask.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package io.sentry.android.gradle.snapshot
33
import com.android.build.api.variant.ApplicationVariant
44
import com.android.build.gradle.BaseExtension
55
import io.sentry.android.gradle.SentryTasksProvider.capitalized
6+
import io.sentry.android.gradle.snapshot.metadata.UI_MODE_NIGHT_MASK
7+
import io.sentry.android.gradle.snapshot.metadata.UI_MODE_NIGHT_YES
68
import java.io.File
79
import org.gradle.api.DefaultTask
810
import org.gradle.api.Project
@@ -353,7 +355,7 @@ class $CLASS_NAME(
353355
if (info.name.isNotBlank()) metadata["previewName"] = info.name
354356
if (info.locale.isNotBlank()) metadata["locale"] = info.locale
355357
if (info.device.isNotBlank()) metadata["device"] = info.device
356-
metadata["nightMode"] = (info.uiMode and 0x30 == 0x20)
358+
metadata["nightMode"] = (info.uiMode and UI_MODE_NIGHT_MASK == UI_MODE_NIGHT_YES)
357359
if (info.fontScale != 1f) metadata["fontScale"] = info.fontScale
358360
if (info.apiLevel != -1) metadata["apiLevel"] = info.apiLevel
359361
if (info.widthDp > 0) metadata["widthDp"] = info.widthDp

plugin-build/src/main/kotlin/io/sentry/android/gradle/snapshot/metadata/PreviewConstants.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ private const val SQUARE = "id:wearos_square"
4747
// region UI mode constants
4848
// https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/content/res/Configuration.java
4949

50-
private const val UI_MODE_NIGHT_YES: Int = 32
50+
internal const val UI_MODE_NIGHT_MASK: Int = 0x30
51+
internal const val UI_MODE_NIGHT_YES: Int = 0x20
5152
private const val UI_MODE_TYPE_NORMAL: Int = 1
5253

5354
// endregion

0 commit comments

Comments
 (0)