From c2b9e8fb04bb906b237393a833da4548d5825ea2 Mon Sep 17 00:00:00 2001 From: ACh Sulfate Date: Fri, 24 Nov 2023 23:28:57 +0800 Subject: [PATCH] chore: deps: update mmkv to 1.3.2 --- libs/mmkv/MMKV | 2 +- libs/mmkv/build.gradle.kts | 9 +- libs/mmkv/native-bridge.cpp | 202 +++++++++++++++++++++++------------- 3 files changed, 136 insertions(+), 77 deletions(-) diff --git a/libs/mmkv/MMKV b/libs/mmkv/MMKV index 09c165e93f..a8d3cdd2a4 160000 --- a/libs/mmkv/MMKV +++ b/libs/mmkv/MMKV @@ -1 +1 @@ -Subproject commit 09c165e93fd354cc11b927a947b6465905964850 +Subproject commit a8d3cdd2a43a8e5c5ab5043dfad111c96a4963bf diff --git a/libs/mmkv/build.gradle.kts b/libs/mmkv/build.gradle.kts index 7a0314e153..828a611531 100644 --- a/libs/mmkv/build.gradle.kts +++ b/libs/mmkv/build.gradle.kts @@ -16,7 +16,14 @@ android { val main by getting main.apply { manifest.srcFile("AndroidManifest.xml") - java.setSrcDirs(listOf("MMKV/Android/MMKV/mmkv/src/main/java")) + java { + setSrcDirs(listOf("MMKV/Android/MMKV/mmkv/src/main/java")) + // it seems that FastNative.class is already included in the SDK 34 + (this as com.android.build.gradle.api.AndroidSourceDirectorySet).apply { + // AGP kts DSK still not having a way to exclude files? + filter.exclude("**/FastNative.java") + } + } aidl.setSrcDirs(listOf("MMKV/Android/MMKV/mmkv/src/main/aidl")) res.setSrcDirs(listOf("MMKV/Android/MMKV/mmkv/src/main/res")) assets.setSrcDirs(listOf("MMKV/Android/MMKV/mmkv/src/main/assets")) diff --git a/libs/mmkv/native-bridge.cpp b/libs/mmkv/native-bridge.cpp index 6662bc241b..7e3e0bf711 100644 --- a/libs/mmkv/native-bridge.cpp +++ b/libs/mmkv/native-bridge.cpp @@ -294,7 +294,8 @@ static void onContentChangedByOuterProcess(const std::string &mmapID) { } } -MMKV_JNI jlong getMMKVWithID(JNIEnv *env, jobject, jstring mmapID, jint mode, jstring cryptKey, jstring rootPath) { +MMKV_JNI jlong getMMKVWithID(JNIEnv *env, jobject, jstring mmapID, jint mode, jstring cryptKey, jstring rootPath, + jlong expectedCapacity) { MMKV *kv = nullptr; if (!mmapID) { return (jlong) kv; @@ -307,9 +308,9 @@ MMKV_JNI jlong getMMKVWithID(JNIEnv *env, jobject, jstring mmapID, jint mode, js if (crypt.length() > 0) { if (rootPath) { string path = jstring2string(env, rootPath); - kv = MMKV::mmkvWithID(str, DEFAULT_MMAP_SIZE, (MMKVMode) mode, &crypt, &path); + kv = MMKV::mmkvWithID(str, DEFAULT_MMAP_SIZE, (MMKVMode) mode, &crypt, &path, expectedCapacity); } else { - kv = MMKV::mmkvWithID(str, DEFAULT_MMAP_SIZE, (MMKVMode) mode, &crypt, nullptr); + kv = MMKV::mmkvWithID(str, DEFAULT_MMAP_SIZE, (MMKVMode) mode, &crypt, nullptr, expectedCapacity); } done = true; } @@ -317,9 +318,9 @@ MMKV_JNI jlong getMMKVWithID(JNIEnv *env, jobject, jstring mmapID, jint mode, js if (!done) { if (rootPath) { string path = jstring2string(env, rootPath); - kv = MMKV::mmkvWithID(str, DEFAULT_MMAP_SIZE, (MMKVMode) mode, nullptr, &path); + kv = MMKV::mmkvWithID(str, DEFAULT_MMAP_SIZE, (MMKVMode) mode, nullptr, &path, expectedCapacity); } else { - kv = MMKV::mmkvWithID(str, DEFAULT_MMAP_SIZE, (MMKVMode) mode, nullptr, nullptr); + kv = MMKV::mmkvWithID(str, DEFAULT_MMAP_SIZE, (MMKVMode) mode, nullptr, nullptr, expectedCapacity); } } @@ -1013,81 +1014,132 @@ MMKV_JNI jboolean disableAutoExpire(JNIEnv *env, jobject instance) { return (jboolean) false; } +MMKV_JNI void enableCompareBeforeSet(JNIEnv *env, jobject instance) { + MMKV *kv = getMMKV(env, instance); + if (kv) { + kv->enableCompareBeforeSet(); + } +} + +MMKV_JNI void disableCompareBeforeSet(JNIEnv *env, jobject instance) { + MMKV *kv = getMMKV(env, instance); + if (kv) { + kv->disableCompareBeforeSet(); + } +} + +MMKV_JNI bool isCompareBeforeSetEnabled(JNIEnv *env, jobject instance) { + MMKV *kv = getMMKV(env, instance); + if (kv) { + return kv->isCompareBeforeSetEnabled(); + } + return false; +} + +MMKV_JNI bool isEncryptionEnabled(JNIEnv *env, jobject instance) { + MMKV *kv = getMMKV(env, instance); + if (kv) { + return kv->isEncryptionEnabled(); + } + return false; +} + +MMKV_JNI bool isExpirationEnabled(JNIEnv *env, jobject instance) { + MMKV *kv = getMMKV(env, instance); + if (kv) { + return kv->isExpirationEnabled(); + } + return false; +} + +MMKV_JNI void clearAllWithKeepingSpace(JNIEnv *env, jobject instance) { + MMKV *kv = getMMKV(env, instance); + if (kv) { + kv->clearAll(true); + } +} + } // namespace mmkv static JNINativeMethod g_methods[] = { - {"onExit", "()V", (void *) mmkv::onExit}, - {"cryptKey", "()Ljava/lang/String;", (void *) mmkv::cryptKey}, + {"onExit", "()V", (void *) mmkv::onExit}, + {"cryptKey", "()Ljava/lang/String;", (void *) mmkv::cryptKey}, # ifndef MMKV_DISABLE_CRYPT - {"reKey", "(Ljava/lang/String;)Z", (void *) mmkv::reKey}, - {"checkReSetCryptKey", "(Ljava/lang/String;)V", (void *) mmkv::checkReSetCryptKey}, + {"reKey", "(Ljava/lang/String;)Z", (void *) mmkv::reKey}, + {"checkReSetCryptKey", "(Ljava/lang/String;)V", (void *) mmkv::checkReSetCryptKey}, # endif - {"pageSize", "()I", (void *) mmkv::pageSize}, - {"mmapID", "()Ljava/lang/String;", (void *) mmkv::mmapID}, - {"version", "()Ljava/lang/String;", (void *) mmkv::version}, - {"lock", "()V", (void *) mmkv::lock}, - {"unlock", "()V", (void *) mmkv::unlock}, - {"tryLock", "()Z", (void *) mmkv::tryLock}, - {"allKeys", "(JZ)[Ljava/lang/String;", (void *) mmkv::allKeys}, - {"removeValuesForKeys", "([Ljava/lang/String;)V", (void *) mmkv::removeValuesForKeys}, - {"clearAll", "()V", (void *) mmkv::clearAll}, - {"trim", "()V", (void *) mmkv::trim}, - {"close", "()V", (void *) mmkv::close}, - {"clearMemoryCache", "()V", (void *) mmkv::clearMemoryCache}, - {"sync", "(Z)V", (void *) mmkv::sync}, - {"isFileValid", "(Ljava/lang/String;Ljava/lang/String;)Z", (void *) mmkv::isFileValid}, - {"ashmemFD", "()I", (void *) mmkv::ashmemFD}, - {"ashmemMetaFD", "()I", (void *) mmkv::ashmemMetaFD}, - //{"jniInitialize", "(Ljava/lang/String;Ljava/lang/String;I)V", (void *) mmkv::jniInitialize}, - {"jniInitialize", "(Ljava/lang/String;Ljava/lang/String;IZ)V", (void *) mmkv::jniInitialize_2}, - {"getMMKVWithID", "(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)J", (void *) mmkv::getMMKVWithID}, - {"getMMKVWithIDAndSize", "(Ljava/lang/String;IILjava/lang/String;)J", (void *) mmkv::getMMKVWithIDAndSize}, - {"getDefaultMMKV", "(ILjava/lang/String;)J", (void *) mmkv::getDefaultMMKV}, - {"getMMKVWithAshmemFD", "(Ljava/lang/String;IILjava/lang/String;)J", (void *) mmkv::getMMKVWithAshmemFD}, - {"encodeBool", "(JLjava/lang/String;Z)Z", (void *) mmkv::encodeBool}, - {"encodeBool_2", "(JLjava/lang/String;ZI)Z", (void *) mmkv::encodeBool_2}, - {"decodeBool", "(JLjava/lang/String;Z)Z", (void *) mmkv::decodeBool}, - {"encodeInt", "(JLjava/lang/String;I)Z", (void *) mmkv::encodeInt}, - {"encodeInt_2", "(JLjava/lang/String;II)Z", (void *) mmkv::encodeInt_2}, - {"decodeInt", "(JLjava/lang/String;I)I", (void *) mmkv::decodeInt}, - {"encodeLong", "(JLjava/lang/String;J)Z", (void *) mmkv::encodeLong}, - {"encodeLong_2", "(JLjava/lang/String;JI)Z", (void *) mmkv::encodeLong_2}, - {"decodeLong", "(JLjava/lang/String;J)J", (void *) mmkv::decodeLong}, - {"encodeFloat", "(JLjava/lang/String;F)Z", (void *) mmkv::encodeFloat}, - {"encodeFloat_2", "(JLjava/lang/String;FI)Z", (void *) mmkv::encodeFloat_2}, - {"decodeFloat", "(JLjava/lang/String;F)F", (void *) mmkv::decodeFloat}, - {"encodeDouble", "(JLjava/lang/String;D)Z", (void *) mmkv::encodeDouble}, - {"encodeDouble_2", "(JLjava/lang/String;DI)Z", (void *) mmkv::encodeDouble_2}, - {"decodeDouble", "(JLjava/lang/String;D)D", (void *) mmkv::decodeDouble}, - {"encodeString", "(JLjava/lang/String;Ljava/lang/String;)Z", (void *) mmkv::encodeString}, - {"encodeString_2", "(JLjava/lang/String;Ljava/lang/String;I)Z", (void *) mmkv::encodeString_2}, - {"decodeString", "(JLjava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void *) mmkv::decodeString}, - {"encodeSet", "(JLjava/lang/String;[Ljava/lang/String;)Z", (void *) mmkv::encodeSet}, - {"encodeSet_2", "(JLjava/lang/String;[Ljava/lang/String;I)Z", (void *) mmkv::encodeSet_2}, - {"decodeStringSet", "(JLjava/lang/String;)[Ljava/lang/String;", (void *) mmkv::decodeStringSet}, - {"encodeBytes", "(JLjava/lang/String;[B)Z", (void *) mmkv::encodeBytes}, - {"encodeBytes_2", "(JLjava/lang/String;[BI)Z", (void *) mmkv::encodeBytes_2}, - {"decodeBytes", "(JLjava/lang/String;)[B", (void *) mmkv::decodeBytes}, - {"containsKey", "(JLjava/lang/String;)Z", (void *) mmkv::containsKey}, - {"count", "(JZ)J", (void *) mmkv::count}, - {"totalSize", "(J)J", (void *) mmkv::totalSize}, - {"actualSize", "(J)J", (void *) mmkv::actualSize}, - {"removeValueForKey", "(JLjava/lang/String;)V", (void *) mmkv::removeValueForKey}, - {"valueSize", "(JLjava/lang/String;Z)I", (void *) mmkv::valueSize}, - {"setLogLevel", "(I)V", (void *) mmkv::setLogLevel}, - {"setCallbackHandler", "(ZZ)V", (void *) mmkv::setCallbackHandler}, - {"createNB", "(I)J", (void *) mmkv::createNB}, - {"destroyNB", "(JI)V", (void *) mmkv::destroyNB}, - {"writeValueToNB", "(JLjava/lang/String;JI)I", (void *) mmkv::writeValueToNB}, - {"setWantsContentChangeNotify", "(Z)V", (void *) mmkv::setWantsContentChangeNotify}, - {"checkContentChangedByOuterProcess", "()V", (void *) mmkv::checkContentChanged}, - {"checkProcessMode", "(J)Z", (void *) mmkv::checkProcessMode}, - {"backupOneToDirectory", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z", (void *) mmkv::backupOne}, - {"restoreOneMMKVFromDirectory", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z", (void *) mmkv::restoreOne}, - {"backupAllToDirectory", "(Ljava/lang/String;)J", (void *) mmkv::backupAll}, - {"restoreAllFromDirectory", "(Ljava/lang/String;)J", (void *) mmkv::restoreAll}, - {"enableAutoKeyExpire", "(I)Z", (void *) mmkv::enableAutoExpire}, - {"disableAutoKeyExpire", "()Z", (void *) mmkv::disableAutoExpire}, + {"pageSize", "()I", (void *) mmkv::pageSize}, + {"mmapID", "()Ljava/lang/String;", (void *) mmkv::mmapID}, + {"version", "()Ljava/lang/String;", (void *) mmkv::version}, + {"lock", "()V", (void *) mmkv::lock}, + {"unlock", "()V", (void *) mmkv::unlock}, + {"tryLock", "()Z", (void *) mmkv::tryLock}, + {"allKeys", "(JZ)[Ljava/lang/String;", (void *) mmkv::allKeys}, + {"removeValuesForKeys", "([Ljava/lang/String;)V", (void *) mmkv::removeValuesForKeys}, + {"clearAll", "()V", (void *) mmkv::clearAll}, + {"trim", "()V", (void *) mmkv::trim}, + {"close", "()V", (void *) mmkv::close}, + {"clearMemoryCache", "()V", (void *) mmkv::clearMemoryCache}, + {"sync", "(Z)V", (void *) mmkv::sync}, + {"isFileValid", "(Ljava/lang/String;Ljava/lang/String;)Z", (void *) mmkv::isFileValid}, + {"ashmemFD", "()I", (void *) mmkv::ashmemFD}, + {"ashmemMetaFD", "()I", (void *) mmkv::ashmemMetaFD}, + //{"jniInitialize", "(Ljava/lang/String;Ljava/lang/String;I)V", (void *) mmkv::jniInitialize}, + {"jniInitialize", "(Ljava/lang/String;Ljava/lang/String;IZ)V", (void *) mmkv::jniInitialize_2}, + {"getMMKVWithID", "(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;J)J", (void *) mmkv::getMMKVWithID}, + {"getMMKVWithIDAndSize", "(Ljava/lang/String;IILjava/lang/String;)J", (void *) mmkv::getMMKVWithIDAndSize}, + {"getDefaultMMKV", "(ILjava/lang/String;)J", (void *) mmkv::getDefaultMMKV}, + {"getMMKVWithAshmemFD", "(Ljava/lang/String;IILjava/lang/String;)J", (void *) mmkv::getMMKVWithAshmemFD}, + {"encodeBool", "(JLjava/lang/String;Z)Z", (void *) mmkv::encodeBool}, + {"encodeBool_2", "(JLjava/lang/String;ZI)Z", (void *) mmkv::encodeBool_2}, + {"decodeBool", "(JLjava/lang/String;Z)Z", (void *) mmkv::decodeBool}, + {"encodeInt", "(JLjava/lang/String;I)Z", (void *) mmkv::encodeInt}, + {"encodeInt_2", "(JLjava/lang/String;II)Z", (void *) mmkv::encodeInt_2}, + {"decodeInt", "(JLjava/lang/String;I)I", (void *) mmkv::decodeInt}, + {"encodeLong", "(JLjava/lang/String;J)Z", (void *) mmkv::encodeLong}, + {"encodeLong_2", "(JLjava/lang/String;JI)Z", (void *) mmkv::encodeLong_2}, + {"decodeLong", "(JLjava/lang/String;J)J", (void *) mmkv::decodeLong}, + {"encodeFloat", "(JLjava/lang/String;F)Z", (void *) mmkv::encodeFloat}, + {"encodeFloat_2", "(JLjava/lang/String;FI)Z", (void *) mmkv::encodeFloat_2}, + {"decodeFloat", "(JLjava/lang/String;F)F", (void *) mmkv::decodeFloat}, + {"encodeDouble", "(JLjava/lang/String;D)Z", (void *) mmkv::encodeDouble}, + {"encodeDouble_2", "(JLjava/lang/String;DI)Z", (void *) mmkv::encodeDouble_2}, + {"decodeDouble", "(JLjava/lang/String;D)D", (void *) mmkv::decodeDouble}, + {"encodeString", "(JLjava/lang/String;Ljava/lang/String;)Z", (void *) mmkv::encodeString}, + {"encodeString_2", "(JLjava/lang/String;Ljava/lang/String;I)Z", (void *) mmkv::encodeString_2}, + {"decodeString", "(JLjava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void *) mmkv::decodeString}, + {"encodeSet", "(JLjava/lang/String;[Ljava/lang/String;)Z", (void *) mmkv::encodeSet}, + {"encodeSet_2", "(JLjava/lang/String;[Ljava/lang/String;I)Z", (void *) mmkv::encodeSet_2}, + {"decodeStringSet", "(JLjava/lang/String;)[Ljava/lang/String;", (void *) mmkv::decodeStringSet}, + {"encodeBytes", "(JLjava/lang/String;[B)Z", (void *) mmkv::encodeBytes}, + {"encodeBytes_2", "(JLjava/lang/String;[BI)Z", (void *) mmkv::encodeBytes_2}, + {"decodeBytes", "(JLjava/lang/String;)[B", (void *) mmkv::decodeBytes}, + {"containsKey", "(JLjava/lang/String;)Z", (void *) mmkv::containsKey}, + {"count", "(JZ)J", (void *) mmkv::count}, + {"totalSize", "(J)J", (void *) mmkv::totalSize}, + {"actualSize", "(J)J", (void *) mmkv::actualSize}, + {"removeValueForKey", "(JLjava/lang/String;)V", (void *) mmkv::removeValueForKey}, + {"valueSize", "(JLjava/lang/String;Z)I", (void *) mmkv::valueSize}, + {"setLogLevel", "(I)V", (void *) mmkv::setLogLevel}, + {"setCallbackHandler", "(ZZ)V", (void *) mmkv::setCallbackHandler}, + {"createNB", "(I)J", (void *) mmkv::createNB}, + {"destroyNB", "(JI)V", (void *) mmkv::destroyNB}, + {"writeValueToNB", "(JLjava/lang/String;JI)I", (void *) mmkv::writeValueToNB}, + {"setWantsContentChangeNotify", "(Z)V", (void *) mmkv::setWantsContentChangeNotify}, + {"checkContentChangedByOuterProcess", "()V", (void *) mmkv::checkContentChanged}, + {"checkProcessMode", "(J)Z", (void *) mmkv::checkProcessMode}, + {"backupOneToDirectory", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z", (void *) mmkv::backupOne}, + {"restoreOneMMKVFromDirectory", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z", (void *) mmkv::restoreOne}, + {"backupAllToDirectory", "(Ljava/lang/String;)J", (void *) mmkv::backupAll}, + {"restoreAllFromDirectory", "(Ljava/lang/String;)J", (void *) mmkv::restoreAll}, + {"enableAutoKeyExpire", "(I)Z", (void *) mmkv::enableAutoExpire}, + {"disableAutoKeyExpire", "()Z", (void *) mmkv::disableAutoExpire}, + {"nativeEnableCompareBeforeSet", "()V", (void *) mmkv::enableCompareBeforeSet}, + {"disableCompareBeforeSet", "()V", (void *) mmkv::disableCompareBeforeSet}, + {"isCompareBeforeSetEnabled", "()Z", (void *) mmkv::isCompareBeforeSetEnabled}, + {"isEncryptionEnabled", "()Z", (void *) mmkv::isEncryptionEnabled}, + {"isExpirationEnabled", "()Z", (void *) mmkv::isExpirationEnabled}, + {"clearAllWithKeepingSpace", "()V", (void *) mmkv::clearAllWithKeepingSpace}, }; static int registerNativeMethods(JNIEnv *env, jclass cls) {