feat(native): custom emoji font

This commit is contained in:
rhunk
2024-05-28 19:03:24 +02:00
parent c635994e50
commit 8ad40e1190
4 changed files with 28 additions and 0 deletions

View File

@@ -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 {

View 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);
}
}

View File

@@ -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) {

View File

@@ -4,4 +4,5 @@ data class NativeConfig(
val disableBitmoji: Boolean = false,
val disableMetrics: Boolean = false,
val composerHooks: Boolean = false,
val customEmojiFontPath: String? = null,
)