feat(native): custom emoji font
This commit is contained in:
@@ -13,6 +13,7 @@ typedef struct {
|
||||
bool disable_bitmoji;
|
||||
bool disable_metrics;
|
||||
bool composer_hooks;
|
||||
char custom_emoji_font_path[256];
|
||||
} native_config_t;
|
||||
|
||||
namespace common {
|
||||
|
||||
14
native/jni/src/hooks/custom_emoji_font.h
Normal file
14
native/jni/src/hooks/custom_emoji_font.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
namespace CustomEmojiFont {
|
||||
HOOK_DEF(int, open_hook, const char *pathname, int flags, mode_t mode) {
|
||||
if (strstr(pathname, "/system/fonts/NotoColorEmoji.ttf") != 0 && common::native_config->custom_emoji_font_path[0] != 0) {
|
||||
pathname = common::native_config->custom_emoji_font_path;
|
||||
}
|
||||
return open_hook_original(pathname, flags, mode);
|
||||
}
|
||||
|
||||
void init() {
|
||||
DobbyHook((void *) DobbySymbolResolver("libc.so", "open"), (void *)open_hook, (void **)&open_hook_original);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "hooks/sqlite_mutex.h"
|
||||
#include "hooks/duplex_hook.h"
|
||||
#include "hooks/composer_hook.h"
|
||||
#include "hooks/custom_emoji_font.h"
|
||||
|
||||
bool JNICALL init(JNIEnv *env, jobject clazz) {
|
||||
LOGD("Initializing native");
|
||||
@@ -38,6 +39,9 @@ bool JNICALL init(JNIEnv *env, jobject clazz) {
|
||||
RUN(FstatHook::init());
|
||||
RUN(SqliteMutexHook::init());
|
||||
RUN(DuplexHook::init(env));
|
||||
if (common::native_config->custom_emoji_font_path[0] != 0) {
|
||||
RUN(CustomEmojiFont::init());
|
||||
}
|
||||
if (common::native_config->composer_hooks) {
|
||||
RUN(ComposerHook::init());
|
||||
}
|
||||
@@ -58,6 +62,14 @@ void JNICALL load_config(JNIEnv *env, jobject, jobject config_object) {
|
||||
native_config->disable_bitmoji = GET_CONFIG_BOOL("disableBitmoji");
|
||||
native_config->disable_metrics = GET_CONFIG_BOOL("disableMetrics");
|
||||
native_config->composer_hooks = GET_CONFIG_BOOL("composerHooks");
|
||||
|
||||
memset(native_config->custom_emoji_font_path, 0, sizeof(native_config->custom_emoji_font_path));
|
||||
auto custom_emoji_font_path = env->GetObjectField(config_object, env->GetFieldID(native_config_clazz, "customEmojiFontPath", "Ljava/lang/String;"));
|
||||
if (custom_emoji_font_path != nullptr) {
|
||||
auto custom_emoji_font_path_str = env->GetStringUTFChars((jstring) custom_emoji_font_path, nullptr);
|
||||
strncpy(native_config->custom_emoji_font_path, custom_emoji_font_path_str, sizeof(native_config->custom_emoji_font_path));
|
||||
env->ReleaseStringUTFChars((jstring) custom_emoji_font_path, custom_emoji_font_path_str);
|
||||
}
|
||||
}
|
||||
|
||||
void JNICALL lock_database(JNIEnv *env, jobject, jstring database_name, jobject runnable) {
|
||||
|
||||
@@ -4,4 +4,5 @@ data class NativeConfig(
|
||||
val disableBitmoji: Boolean = false,
|
||||
val disableMetrics: Boolean = false,
|
||||
val composerHooks: Boolean = false,
|
||||
val customEmojiFontPath: String? = null,
|
||||
)
|
||||
Reference in New Issue
Block a user