Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test pr for v2.0.0 #1403

Merged
merged 38 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a38a99e
upgrade flutter example proj
lingol Jul 8, 2024
530e9d0
drop 32bit arch & bump Android API level to 23 starting from v2.0.0
lingol Jul 8, 2024
b38368b
upgrade NDK to 26.3.11579264
lingol Jul 8, 2024
ce06673
OHOS: protect from non-positive size or malloc failure in createNativ…
lingol Jul 9, 2024
32ed8ce
add Mac Catalyst support #1345
lingol Jul 9, 2024
0c46ffb
Get current process name for AppStore review
Jul 11, 2024
3cacb30
Merge pull request #1352 from fine1021/dev_process_name
lingol Jul 11, 2024
bb24c99
expose flutter ffi symbols on OHOS
lingol Jul 12, 2024
d9abefd
add override point for path_provider
lingol Jul 12, 2024
990cd26
add mmkv_ohos plugin
lingol Jul 12, 2024
45b7e7e
Lower Dart to 2.17 to avoid OHOS conflict
lingol Jul 12, 2024
ec15865
add ohos support
lingol Jul 12, 2024
bd29ac9
unlock pthread_mutex before destroy it
lingol Jul 12, 2024
912f8a4
fix override bug on encrypted mmkv #1351
lingol Jul 16, 2024
dcdd4e6
use random size holder to make encryption resilient from brute force …
lingol Jul 17, 2024
52a46bd
support 16K for Android 15 #1353
lingol Jul 23, 2024
4c7d981
Merge branch '1.3.x_lts' into dev
lingol Jul 26, 2024
391d403
use rand() instead of random() #1367
lingol Jul 26, 2024
05afbde
fix compile error on MMKV_DISABLE_CRYPT #1368
lingol Jul 26, 2024
248a88f
fix docs error with initializeWithPath() #1381
lingol Aug 9, 2024
ebca973
fix(flutter): remove files from version control as recommended
Chiichen Aug 23, 2024
61629b3
Merge pull request #1388 from Chiichen/fix-flutter-git-ignore
lingol Aug 23, 2024
0142f0b
fix compile error on debug build #1392
lingol Aug 29, 2024
270c8a3
Fixed Checksum.h header path
nikitasigal Sep 2, 2024
3624d0e
Merge pull request #1393 from nikitasigal/fix-core-checksum-header-path
lingol Sep 3, 2024
47d3c08
add readonly support
lingol Sep 6, 2024
934b7fc
support obfuscation #1385 #1397
lingol Sep 9, 2024
3a7071f
support read-only on ohos
lingol Sep 9, 2024
3eb129a
add change log for ohos
lingol Sep 9, 2024
6688793
check getMMKVWithID result and throw exception #1399
lingol Sep 9, 2024
44fa393
add back initialize MMKV test code
lingol Sep 10, 2024
5a67d5d
ohos support log & error callback
lingol Sep 11, 2024
8b8188d
add log & error & content change callback for flutter & ArtTS
lingol Sep 12, 2024
da1ef97
v2.0.0-SNAPSHOT
lingol Sep 23, 2024
52973be
fix compile error on MMKV_DISABLE_CRYPT on ohos
lingol Jul 26, 2024
6d19527
try to fix ohos obsfucation bug
lingol Sep 25, 2024
dba878e
opt getdir
lingol Oct 21, 2024
83e2fa5
prepare for v2.0.0
lingol Oct 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Android/MMKV/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ task clean(type: Delete) {
}

ext {
minSdkVersion = 21
minSdkVersion = 23
compileSdkVersion = 34
targetSdkVersion = compileSdkVersion
supportLibVersion = "25.4.0"
Expand Down
2 changes: 1 addition & 1 deletion Android/MMKV/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ org.gradle.jvmargs=-Xmx1536m
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

VERSION_NAME_PREFIX=1.3.9
VERSION_NAME_PREFIX=2.0.0
#VERSION_NAME_SUFFIX=-SNAPSHOT
VERSION_NAME_SUFFIX=

Expand Down
13 changes: 9 additions & 4 deletions Android/MMKV/mmkv/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
externalNativeBuild {
cmake {
// uncomment this line to support 32-bit ABIs (armeabi-v7a & x86)
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
// abiFilters 'arm64-v8a', 'x86_64'
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
abiFilters 'arm64-v8a', 'x86_64'
}
}
ndkVersion = '26.3.11579264'
Expand All @@ -23,7 +23,8 @@ android {
minifyEnabled false
externalNativeBuild {
cmake {
cppFlags "-fvisibility=hidden", "-funwind-tables", "-fasynchronous-unwind-tables", "-O2"
cppFlags "-fvisibility=hidden", "-funwind-tables", "-fasynchronous-unwind-tables", "-O2",
"-Wl,-z,max-page-size=16384"
}
}
consumerProguardFiles 'proguard-rules.pro'
Expand All @@ -43,7 +44,11 @@ android {
lintOptions {
tasks.lint.enabled = false
}

packagingOptions {
jniLibs {
useLegacyPackaging true
}
}
flavorDimensions "stl_mode"
productFlavors {
DefaultCpp {
Expand Down
87 changes: 83 additions & 4 deletions Android/MMKV/mmkv/src/main/cpp/flutter-bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ extern string g_android_tmpDir;

# define MMKV_EXPORT extern "C" __attribute__((visibility("default"))) __attribute__((used))

MMKV_EXPORT void mmkvInitialize_v1(const char *rootDir, const char *cacheDir, int32_t sdkInt, int32_t logLevel) {
using LogCallback_t = void (*)(uint32_t level, const char *file, int32_t line, const char *funcname, const char *message);
LogCallback_t g_logCallback = nullptr;

static void myLogHandler(MMKVLogLevel level, const char *file, int line, const char *function, MMKVLog_t message) {
if (g_logCallback) {
g_logCallback(level, file, line, function, message.c_str());
}
}

MMKV_EXPORT void *mmkvInitialize_v2(const char *rootDir, const char *cacheDir, int32_t sdkInt, int32_t logLevel, LogCallback_t callback) {
if (!rootDir) {
return;
return nullptr;
}
if (cacheDir) {
g_android_tmpDir = string(cacheDir);
Expand All @@ -52,11 +61,21 @@ MMKV_EXPORT void mmkvInitialize_v1(const char *rootDir, const char *cacheDir, in
MMKVInfo("current API level = %d, libc++_shared=?", g_android_api);
#endif

MMKV::initializeMMKV(rootDir, (MMKVLogLevel) logLevel);
if (callback) {
g_logCallback = callback;
MMKV::initializeMMKV(rootDir, (MMKVLogLevel) logLevel, myLogHandler);
} else {
MMKV::initializeMMKV(rootDir, (MMKVLogLevel) logLevel);
}
return (void *) MMKV::getRootDir().c_str();
}

MMKV_EXPORT void mmkvInitialize_v1(const char *rootDir, const char *cacheDir, int32_t sdkInt, int32_t logLevel) {
mmkvInitialize_v2(rootDir, cacheDir, sdkInt, logLevel, nullptr);
}

MMKV_EXPORT void mmkvInitialize(const char *rootDir, int32_t logLevel) {
mmkvInitialize_v1(rootDir, nullptr, 0, logLevel);
mmkvInitialize_v2(rootDir, nullptr, 0, logLevel, nullptr);
}

MMKV_EXPORT void *getMMKVWithID(const char *mmapID, int32_t mode, const char *cryptKey, const char *rootPath, size_t expectedCapacity) {
Expand Down Expand Up @@ -566,4 +585,64 @@ MMKV_EXPORT bool removeStorage(const char *mmapID, const char *rootPath) {
return MMKV::removeStorage(mmapID, nullptr);
}

MMKV_EXPORT bool isMultiProcess(void *handle) {
MMKV *kv = static_cast<MMKV *>(handle);
if (kv) {
return kv->isMultiProcess();
}
return false;
}

MMKV_EXPORT bool isReadOnly(void *handle) {
MMKV *kv = static_cast<MMKV *>(handle);
if (kv) {
return kv->isReadOnly();
}
return false;
}

using ErrorCallback_t = int (*)(const char *mmapID, int32_t errorType);
static ErrorCallback_t g_errorCallback = nullptr;

static MMKVRecoverStrategic myErrorHandler(const std::string &mmapID, MMKVErrorType errorType) {
if (g_errorCallback) {
return (MMKVRecoverStrategic) g_errorCallback(mmapID.c_str(), errorType);
}
return OnErrorDiscard;
}

MMKV_EXPORT void registerErrorHandler(ErrorCallback_t callback) {
g_errorCallback = callback;
if (callback) {
MMKV::registerErrorHandler(myErrorHandler);
} else {
MMKV::unRegisterErrorHandler();
}
}

using ContenctChangeCallback_t = void (*)(const char *mmapID);
static ContenctChangeCallback_t g_contentChanceCallback = nullptr;

static void myContentChangeHandler(const std::string &mmapID) {
if (g_contentChanceCallback) {
g_contentChanceCallback(mmapID.c_str());
}
}

MMKV_EXPORT void registerContentChangeNotify(ContenctChangeCallback_t callback) {
g_contentChanceCallback = callback;
if (callback) {
MMKV::registerContentChangeHandler(myContentChangeHandler);
} else {
MMKV::unRegisterContentChangeHandler();
}
}

MMKV_EXPORT void checkContentChanged(void *handle) {
MMKV *kv = static_cast<MMKV *>(handle);
if (kv) {
kv->checkContentChanged();
}
}

#endif // MMKV_DISABLE_FLUTTER
18 changes: 18 additions & 0 deletions Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,22 @@ MMKV_JNI void clearAllWithKeepingSpace(JNIEnv *env, jobject instance) {
}
}

MMKV_JNI jboolean isMultiProcess(JNIEnv *env, jobject instance) {
MMKV *kv = getMMKV(env, instance);
if (kv) {
return (jboolean) kv->isMultiProcess();
}
return jboolean(false);
}

MMKV_JNI jboolean isReadOnly(JNIEnv *env, jobject instance) {
MMKV *kv = getMMKV(env, instance);
if (kv) {
return (jboolean) kv->isReadOnly();
}
return jboolean(false);
}

} // namespace mmkv

static JNINativeMethod g_methods[] = {
Expand Down Expand Up @@ -1146,6 +1162,8 @@ static JNINativeMethod g_methods[] = {
{"isEncryptionEnabled", "()Z", (void *) mmkv::isEncryptionEnabled},
{"isExpirationEnabled", "()Z", (void *) mmkv::isExpirationEnabled},
{"clearAllWithKeepingSpace", "()V", (void *) mmkv::clearAllWithKeepingSpace},
{"isMultiProcess", "()Z", (void *) mmkv::isMultiProcess},
{"isReadOnly", "()Z", (void *) mmkv::isReadOnly},
};

static int registerNativeMethods(JNIEnv *env, jclass cls) {
Expand Down
15 changes: 15 additions & 0 deletions Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ public static void setLogLevel(MMKVLogLevel level) {

static private final int BACKUP_MODE = 1 << 4;

/**
* Read-only mode.
*/
static public final int READ_ONLY_MODE = 1 << 5;

/**
* Create an MMKV instance with an unique ID (in single-process mode).
*
Expand Down Expand Up @@ -1646,6 +1651,16 @@ private static void onContentChangedByOuterProcess(String mmapID) {
*/
public native void checkContentChangedByOuterProcess();

/**
* Check if this instance is in multi-process mode.
*/
public native boolean isMultiProcess();

/**
* Check if this instance is in read-only mode.
*/
public native boolean isReadOnly();

// jni
private final long nativeHandle;

Expand Down
6 changes: 3 additions & 3 deletions Android/MMKV/mmkvdemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ repositories {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':mmkv')
// implementation 'com.tencent:mmkv:1.3.9'
// implementation 'com.tencent:mmkv-static:1.3.9' // this is identical to 'com.tencent:mmkv'
// implementation 'com.tencent:mmkv-shared:1.3.9'
// implementation 'com.tencent:mmkv:2.0.0'
// implementation 'com.tencent:mmkv-static:2.0.0' // this is identical to 'com.tencent:mmkv'
// implementation 'com.tencent:mmkv-shared:2.0.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public void onClick(View v) {
// testFastNativeSpeed();
testRemoveStorage();
overrideTest();
testReadOnly();
}

private void testCompareBeforeSet() {
Expand Down Expand Up @@ -212,7 +213,12 @@ private void testInterProcessLogic() {
private MMKV testMMKV(String mmapID, String cryptKey, boolean decodeOnly, String rootPath) {
//MMKV kv = MMKV.defaultMMKV();
MMKV kv = MMKV.mmkvWithID(mmapID, MMKV.SINGLE_PROCESS_MODE, cryptKey, rootPath);
testMMKV(kv, decodeOnly);
Log.i("MMKV", "isFileValid[" + kv.mmapID() + "]: " + MMKV.isFileValid(kv.mmapID(), rootPath));
return kv;
}

private void testMMKV(MMKV kv, boolean decodeOnly) {
if (!decodeOnly) {
kv.encode("bool", true);
}
Expand Down Expand Up @@ -291,9 +297,6 @@ private MMKV testMMKV(String mmapID, String cryptKey, boolean decodeOnly, String
//kv.clearAll();
kv.clearMemoryCache();
Log.i("MMKV", "allKeys: " + Arrays.toString(kv.allKeys()));
Log.i("MMKV", "isFileValid[" + kv.mmapID() + "]: " + MMKV.isFileValid(kv.mmapID(), rootPath));

return kv;
}

private void testImportSharedPreferences() {
Expand Down Expand Up @@ -915,4 +918,29 @@ private void encryptionTestKV(String key, String value) {
}
mmkv0.removeValueForKey(key);
}

private void testReadOnly() {
final String name = "testReadOnly";
final String key = "readonly+key";
{
MMKV kv = MMKV.mmkvWithID(name, MMKV.SINGLE_PROCESS_MODE, key);
testMMKV(kv, false);
kv.close();
}

String path = MMKV.getRootDir() + "/" + name;
File file = new File(path);
file.setReadOnly();
File crcFile = new File(path + ".crc");
crcFile.setReadOnly();

MMKV kv = MMKV.mmkvWithID(name, MMKV.SINGLE_PROCESS_MODE | MMKV.READ_ONLY_MODE, key);
testMMKV(kv, true);

// also check if it tolerate update operations without crash
testMMKV(kv, false);

file.setWritable(true);
crcFile.setWritable(true);
}
}
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
# MMKV Change Log
## v2.0.0 / 2024-10-21
**This release is a breaking change release, especially for Android.**
### Changes for All platforms
* Add **readonly mode** support.
* Fix a compile error when `MMKV_DISABLE_CRYPT` is defined and MMKV is built by source in DEBUG.

### Android
* Support 16K page size for Android 15.
* Drop the support of **32-bit ABI**.
* Bump the mini **SDK level to API 23**.

### iOS / macOS
* Add Mac Catalyst support

### Flutter
* Add add log/error/content-change callback.

### HarmonyOS NEXT
* Add add log/error/content-change callback.
* Support obfuscation. For the time being, you will have to manually copy the content of MMKV's [consumer-rules.txt](https://github.com/Tencent/MMKV/blob/master/OpenHarmony/MMKV/consumer-rules.txt) into your App's obfuscation-rules.txt.

### Win32
* Replace `random()` with `rand()` to fix a compile error.

## v1.3.9 / 2024-07-26
**This is a Long Term Support (LTS) release.**
### Changes for All platforms
Expand Down
2 changes: 2 additions & 0 deletions Core/Core.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx appletvsimulator appletvos xrsimulator xros";
TARGETED_DEVICE_FAMILY = "1,2,3";
SUPPORTS_MACCATALYST = YES;
};
name = Debug;
};
Expand All @@ -617,6 +618,7 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx appletvsimulator appletvos xrsimulator xros";
TARGETED_DEVICE_FAMILY = "1,2,3";
SUPPORTS_MACCATALYST = YES;
};
name = Release;
};
Expand Down
Loading