Skip to content

Commit 9c84d4c

Browse files
committed
fix(voip): prevent stale MMKV cache on Android first-install accept
MMKVKeyManager.initialize ran in MainApplication.onCreate before the JS engine started and opened the default MMKV file via the Tencent 1.2 JAR when it was still empty. Tencent caches instances per-ID in a singleton registry, so that empty-state view was held for the rest of the process. JS later wrote credentials through react-native-mmkv (MMKV Core 2.0), which has its own separate registry. When a VoIP push arrived, Ejson.getMMKV() got the cached empty Tencent instance and reported "No userId found in MMKV for server". Closing and reopening the app cleared the cache, which is why only the very first call after install failed. Drop the open/verify block — the encryption key is already cached from SecureKeystore, so no MMKV handle is needed here. The first Tencent instance is now created inside Ejson.getMMKV() after JS has written, so it scans the file fresh.
1 parent 1e2e6e8 commit 9c84d4c

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

android/app/src/main/java/chat/rocket/reactnative/storage/MMKVKeyManager.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ public static void initialize(Context context) {
6969
Log.i(TAG, "Existing encryption key found");
7070
}
7171

72-
// Cache the encryption key for other native code
72+
// Cache the encryption key for other native code.
73+
// Do NOT open MMKV here: Tencent MMKV 1.2 (this JAR) caches instances
74+
// per-ID in a singleton registry. Opening the file now — before JS has
75+
// written anything — would cache an empty-state instance. When
76+
// Ejson.java later reads via the same JAR, it gets that stale cached
77+
// instance and misses writes made through react-native-mmkv (MMKV 2.0),
78+
// which has its own separate registry. This manifests as the
79+
// "No userId found in MMKV for server" failure on first install,
80+
// resolved only by restarting the app (which clears the cache).
7381
encryptionKey = password;
74-
75-
// Verify MMKV can be opened with this key
76-
MMKV mmkv = MMKV.mmkvWithID(DEFAULT_INSTANCE_ID, MMKV.SINGLE_PROCESS_MODE, password);
77-
if (mmkv != null) {
78-
long keyCount = mmkv.count();
79-
Log.i(TAG, "MMKV initialized with encryption, " + keyCount + " keys found");
80-
} else {
81-
Log.w(TAG, "MMKV instance is null after initialization");
82-
}
82+
Log.i(TAG, "MMKV encryption key ready");
8383

8484
} catch (Exception e) {
8585
Log.e(TAG, "MMKV encryption initialization failed", e);

0 commit comments

Comments
 (0)