Skip to content

Commit 2ac89c2

Browse files
Fall back to device id for Logger userId (#2319)
- Add PREFERENCE_KEY_DEVICE_ID and include it in BLACKLISTED_KEYS so the id stays device-local and never replicates through PreferenceSync - Generate the id lazily via UUID.randomUUID on first need, persisted through the existing PreferenceManager string API - Substitute the persisted id (prefixed "device:") for userId in Logger.log when no signed-in user email is available, so unsigned telemetry can still be grouped per install 🤖 Auto-generated Co-authored-by: Owen McGirr <o.a.mcgirr@gmail.com>
1 parent 0d8e0b3 commit 2ac89c2

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

app/src/main/java/com/enaboapps/switchify/backend/preferences/PreferenceManager.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class PreferenceManager(context: Context) {
4949
const val PREFERENCE_KEY_MENU_SIZE_SCALE = "menu_size_scale"
5050
const val PREFERENCE_KEY_SETTINGS_TAB = "settings_tab"
5151
const val PREFERENCE_KEY_TELEMETRY_ENABLED = "telemetry_enabled"
52+
const val PREFERENCE_KEY_DEVICE_ID = "device_id"
5253
const val PREFERENCE_KEY_ONBOARDING_CURRENT_STEP = "onboarding_current_step"
5354
const val PREFERENCE_KEY_ONBOARDING_USER_TYPE = "onboarding_user_type"
5455
const val PREFERENCE_KEY_ONBOARDING_IS_NEW_USER = "onboarding_is_new_user"
@@ -94,6 +95,7 @@ class PreferenceManager(context: Context) {
9495
PREFERENCE_KEY_SETUP_COMPLETE,
9596
PREFERENCE_KEY_REVIEW_LAST_SHOWN,
9697
PREFERENCE_KEY_TELEMETRY_ENABLED,
98+
PREFERENCE_KEY_DEVICE_ID,
9799
PREFERENCE_KEY_GEMMA_TERMS_ACCEPTED
98100
)
99101
}

app/src/main/java/com/enaboapps/switchify/utils/Logger.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import kotlinx.coroutines.Dispatchers
1111
import kotlinx.coroutines.launch
1212
import java.net.HttpURLConnection
1313
import java.net.URL
14+
import java.util.UUID
1415

1516
object Logger {
1617
private const val TAG = "SwitchifyLogger"
@@ -97,6 +98,7 @@ object Logger {
9798
flowId = flowId,
9899
stepIndex = stepIndex,
99100
userId = AuthRepository.instance.getCurrentUser()?.email
101+
?: "device:${getOrCreateDeviceId(prefs)}"
100102
)
101103
val payload = LogPayload(logs = listOf(entry))
102104

@@ -126,4 +128,17 @@ object Logger {
126128
}
127129
}
128130
}
131+
132+
/**
133+
* Returns a stable per-install identifier used as the userId fallback when no user
134+
* is signed in. Generated once on first call and persisted; the key is blacklisted
135+
* from sync so it never follows the account across devices.
136+
*/
137+
private fun getOrCreateDeviceId(prefs: PreferenceManager): String {
138+
val existing = prefs.getStringValue(PreferenceManager.PREFERENCE_KEY_DEVICE_ID)
139+
if (existing.isNotEmpty()) return existing
140+
val generated = UUID.randomUUID().toString()
141+
prefs.setStringValue(PreferenceManager.PREFERENCE_KEY_DEVICE_ID, generated)
142+
return generated
143+
}
129144
}

0 commit comments

Comments
 (0)