Add InstallIdProvider (UUID v7 + SharedPreferences) and bump to 0.0.4 - #7
Merged
Conversation
UUID v7 generator (RFC 9562) plus persistent storage in a dedicated kontextso SharedPreferences file under the installId key. Survives launches, resets only on uninstall / app-data clear. Mirrors iOS InstallIdProvider (UserDefaults.standard, kontextso.installId key) and the kontextso:installId localStorage key used by @kontextso/sdk-js so web and native installs share the same shape on the wire. The validator is intentionally version-agnostic — checks 8-4-4-4-12 hex shape only, not v7-specific bits — so a future generator change doesn't invalidate IDs already on disk. Uses a strict regex rather than java.util.UUID.fromString, which accepts shorthand like "1-2-3-4-5". Bumps version 0.0.3 → 0.0.4. Consumer SDKs (sdk-kotlin) will pin to 0.0.4 and thread installId through their request DTOs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
SecureRandom is documented thread-safe and meant to be reused; instantiating one per uuidv7() call re-seeds from /dev/urandom every time, which is measurably slow on older Android devices. Lift to a private val so the seed-and-construct cost is paid once. Also fixes a misleading claim in the class docstring. The previous wording said this mirrors iOS's "kontextso:installId field name" — but iOS actually stores under "kontextso.installId" (flat UserDefaults key with dot), and sdk-js uses localStorage key "kontextso:installId" (with colon). Only the on-the-wire DTO field name (installId) is shared across all three; the local-storage layout is per-platform by design. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
deviceinfo/InstallIdProvider.kt: apublic objectexposinggetOrCreate(context): String, which returns a UUID v7 per-app-install identifier persisted in a dedicatedkontextsoSharedPreferencesfile under theinstallIdkey. Generated on first call, survives launches, resets only on uninstall / app-data clear.kit = "0.0.3"→"0.0.4"and adds a0.0.4CHANGELOG.mdentry.Mirrors
kontextkit-ios'sInstallIdProvider(which reads/writesUserDefaults.standard) and thekontextso:installIdlocalStorage key used by@kontextso/sdk-js, so web, iOS, and Android installs share the same shape on the wire.Why now
sdk-kotlinis wiringinstallIdinto its/init,/preload,/error, and/debugrequest payloads as part of the v4 release (seesdk-kotlinPR #103). Threading the field on the consumer side is blocked on this kit ship — sdk-kotlin will pin to0.0.4once it's on Maven Central.Design notes
0111in byte 6; variant10in byte 8; remaining bits fromSecureRandom. Time-ordered, so server-side sorts and B-tree indexes stay friendly.java.util.UUID.fromStringaccepts shorthand like"1-2-3-4-5", which would round-trip forever once stored.kontextsoSharedPreferencesfile, not the host app's default prefs. Keeps the install ID out of any file the IAB TCF library reads/writes throughPreferenceManager.getDefaultSharedPreferences, and gives the host app a single file name to clear if they ever need to reset the ID.Test plan
./gradlew spotlessCheck detekt test— BUILD SUCCESSFUL locallyInstallIdProviderTest.kt:before..aftersystem millisgetOrCreategenerates and persists on first callgetOrCreatereturns same value on subsequent calls"1-2-3-4-5"shorthand is rejected (would passUUID.fromString)isCanonicalUuidaccept/reject sanity🤖 Generated with Claude Code