-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFakeFeatureFlagsSdk.kt
More file actions
40 lines (30 loc) · 1.57 KB
/
Copy pathFakeFeatureFlagsSdk.kt
File metadata and controls
40 lines (30 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.aquib.androidperflab.sdk
import android.content.Context
import android.util.Log
object FakeFeatureFlagsSdk {
private val flags = HashMap<String, Boolean>()
// Simulates: parsing a large bundled JSON payload of flag definitions, evaluating
// per-user targeting rules against locally stored user attributes, and persisting
// the resolved flag state — all synchronously on the main thread.
fun init(context: Context) {
// Simulate: deserialising bundled flag defaults (CPU-bound JSON parsing)
val rawPayload = buildString {
repeat(200) { i ->
append("""{"flag":"feature_$i","enabled":${i % 3 != 0},"rollout":${(i * 7) % 100}},""")
}
}
// Simulate: evaluating targeting rules for each flag
val prefs = context.getSharedPreferences("fake_feature_flags", Context.MODE_PRIVATE)
val userSegment = prefs.getInt("user_segment", (System.nanoTime() % 100).toInt())
prefs.edit().putInt("user_segment", userSegment).commit()
repeat(200) { i ->
val rollout = (i * 7) % 100
flags["feature_$i"] = (i % 3 != 0) && (userSegment < rollout)
}
val enabledCount = flags.values.count { it }
// Simulate: blocking network sync to fetch any server-side flag overrides
Thread.sleep(150L)
Log.d("FakeFeatureFlagsSdk", "init complete — ${flags.size} flags resolved, $enabledCount enabled for segment=$userSegment payload=${rawPayload.length} chars")
}
fun isEnabled(flag: String): Boolean = flags[flag] ?: false
}