-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFakeRemoteConfigSdk.kt
More file actions
49 lines (39 loc) · 1.92 KB
/
Copy pathFakeRemoteConfigSdk.kt
File metadata and controls
49 lines (39 loc) · 1.92 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
41
42
43
44
45
46
47
48
49
package com.aquib.androidperflab.sdk
import android.content.Context
import android.util.Log
object FakeRemoteConfigSdk {
private val config = HashMap<String, String>()
// Simulates: reading the last-fetched remote config blob from SharedPreferences,
// validating an HMAC checksum, deserialising key-value pairs, and resolving
// parameter overrides — synchronously blocking the main thread.
fun init(context: Context) {
val prefs = context.getSharedPreferences("fake_remote_config", Context.MODE_PRIVATE)
// Simulate: reading + validating a previously cached config blob
val cachedBlob = prefs.getString("config_blob", null)
val storedChecksum = prefs.getString("config_checksum", "")
if (cachedBlob != null) {
// Simulate: checksum validation (string hashing)
val computedChecksum = cachedBlob.fold(0L) { acc, c -> acc * 31 + c.code }.toString(16)
val valid = computedChecksum == storedChecksum
Log.d("FakeRemoteConfigSdk", "cache checksum valid=$valid")
}
// Simulate: building a new in-memory config with 150 keys
val newBlob = buildString {
repeat(150) { i ->
val key = "config_key_$i"
val value = "value_${i}_${System.nanoTime() % 1000}"
config[key] = value
append("$key=$value;")
}
}
val checksum = newBlob.fold(0L) { acc, c -> acc * 31 + c.code }.toString(16)
prefs.edit()
.putString("config_blob", newBlob)
.putString("config_checksum", checksum)
.commit()
// Simulate: blocking fetch of fresh config values from the remote endpoint
Thread.sleep(200L)
Log.d("FakeRemoteConfigSdk", "init complete — ${config.size} keys loaded, checksum=$checksum")
}
fun getString(key: String, default: String = ""): String = config[key] ?: default
}