Page MenuHomePhabricator

Introduce MMKV to Android app
ClosedPublic

Authored by marcin on Feb 12 2024, 9:09 AM.
Tags
None
Referenced Files
F3267211: D11046.id37726.diff
Sat, Nov 16, 2:41 AM
F3267146: D11046.id37011.diff
Sat, Nov 16, 2:39 AM
F3267109: D11046.id37064.diff
Sat, Nov 16, 2:37 AM
F3264588: D11046.diff
Sat, Nov 16, 12:38 AM
Unknown Object (File)
Wed, Nov 6, 4:43 PM
Unknown Object (File)
Tue, Oct 22, 3:36 AM
Unknown Object (File)
Sun, Oct 20, 3:36 PM
Unknown Object (File)
Sat, Oct 19, 10:35 PM
Subscribers

Details

Summary

This differential introduces MMKV to Android app. For now only string getter and setter is implemented but future diffs will introduce new methods. This
differential introduces simplest API we can test.

Test Plan
  1. Below the CommMMKV.initialize() line add line that sets value under a string key.
  2. In CommNotificationsHandler.java at the beginning add line that tries to get string from the same key and logs this key in case it is present.
  3. Send notification and check it the same string is logged.

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

Rebase to update commit message

native/android/app/src/main/java/app/comm/android/fbjni/CommMMKV.java
20 ↗(On Diff #37011)

Same as here.

27 ↗(On Diff #37011)

I have to admit that is a little bit of code duplication - we could export comm::crypto:Tools::generateRandomString to Java. It could add some additional boilerplate so I opted for faster option. Additionally Base 64 strings don't differ much from the output comm::crypto:Tools::generateRandomString - the differences are that instead of " " and "_" we use "+" and "=".

40 ↗(On Diff #37011)

I tried to recreate dispatch_once functionality here being inspired by what we do with CommSecureStore.

59 ↗(On Diff #37011)
native/android/app/src/main/java/app/comm/android/fbjni/CommMMKV.java
27–30 ↗(On Diff #37011)

On iOS, you generate random string of length 16, while here you base64-encode 16 bytes, which results in ~20-24 char long string.
You can simply use substr()

Fix bug: replace "initializeMMKV" with "initialize" when calling Java method from C++ CommMMKVJavaClass.

tomek added inline comments.
native/android/app/src/cpp/CommMMKV.cpp
36 ↗(On Diff #37064)

Does this method return std::optional<std::string>?

44–52 ↗(On Diff #37064)

It doesn't seem we're capturing anything

69 ↗(On Diff #37064)

Can we have the new line at the end?

native/android/app/src/main/java/app/comm/android/fbjni/CommMMKV.java
18–19 ↗(On Diff #37064)

It doesn't seem efficient to create a new instance of MMKV on every call of getMMKVInstance. Can we store it as a static variable?

82 ↗(On Diff #37064)

newline

27–30 ↗(On Diff #37011)

Doesn't that mean that the number of possible encryption keys is different on different platforms?

This revision is now accepted and ready to land.Feb 14 2024, 8:44 AM
  1. Refactor to match new iOS logic.
  2. Address Bartek and Tomek comments.
native/android/app/src/cpp/CommMMKV.cpp
36 ↗(On Diff #37064)

Call to result->toStdString() returns std::string but it is a C++ feature that we can return type A from a function which signature says that the return type is T if T has constructor from A.

native/android/app/src/main/java/app/comm/android/fbjni/CommMMKV.java
18–19 ↗(On Diff #37064)

It is not recreated - MMKV has a global dict mapping from ID to instance. See: https://github.com/Tencent/MMKV/blob/master/Core/MMKV_Android.cpp#L139

This revision was automatically updated to reflect the committed changes.