android: Deduplicate GetJString

This commit is contained in:
JosJuice 2022-08-03 15:11:13 +02:00
parent bf6e4a41d7
commit e65ca8b907
5 changed files with 37 additions and 22 deletions

View file

@ -1,4 +1,6 @@
add_library(citra-android SHARED add_library(citra-android SHARED
android_common/android_common.cpp
android_common/android_common.h
applets/mii_selector.cpp applets/mii_selector.cpp
applets/mii_selector.h applets/mii_selector.h
applets/swkbd.cpp applets/swkbd.cpp

View file

@ -0,0 +1,20 @@
// Copyright 2022 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "jni/android_common/android_common.h"
#include <string>
#include <jni.h>
std::string GetJString(JNIEnv *env, jstring jstr) {
if (!jstr) {
return {};
}
const char *s = env->GetStringUTFChars(jstr, nullptr);
std::string result = s;
env->ReleaseStringUTFChars(jstr, s);
return result;
}

View file

@ -0,0 +1,11 @@
// Copyright 2022 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <string>
#include <jni.h>
std::string GetJString(JNIEnv* env, jstring jstr);

View file

@ -3,22 +3,14 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <map> #include <map>
#include <jni.h> #include <jni.h>
#include "core/core.h" #include "core/core.h"
#include "jni/android_common/android_common.h"
#include "jni/applets/swkbd.h" #include "jni/applets/swkbd.h"
#include "jni/id_cache.h" #include "jni/id_cache.h"
static std::string GetJString(JNIEnv* env, jstring jstr) {
if (!jstr) {
return {};
}
const char* s = env->GetStringUTFChars(jstr, nullptr);
std::string result = s;
env->ReleaseStringUTFChars(jstr, s);
return result;
}
static jclass s_software_keyboard_class; static jclass s_software_keyboard_class;
static jclass s_keyboard_config_class; static jclass s_keyboard_config_class;
static jclass s_keyboard_data_class; static jclass s_keyboard_data_class;

View file

@ -27,6 +27,7 @@
#include "core/hle/service/nfc/nfc.h" #include "core/hle/service/nfc/nfc.h"
#include "core/savestate.h" #include "core/savestate.h"
#include "core/settings.h" #include "core/settings.h"
#include "jni/android_common/android_common.h"
#include "jni/applets/mii_selector.h" #include "jni/applets/mii_selector.h"
#include "jni/applets/swkbd.h" #include "jni/applets/swkbd.h"
#include "jni/camera/ndk_camera.h" #include "jni/camera/ndk_camera.h"
@ -58,17 +59,6 @@ std::condition_variable running_cv;
} // Anonymous namespace } // Anonymous namespace
static std::string GetJString(JNIEnv* env, jstring jstr) {
if (!jstr) {
return {};
}
const char* s = env->GetStringUTFChars(jstr, nullptr);
std::string result = s;
env->ReleaseStringUTFChars(jstr, s);
return result;
}
static bool DisplayAlertMessage(const char* caption, const char* text, bool yes_no) { static bool DisplayAlertMessage(const char* caption, const char* text, bool yes_no) {
JNIEnv* env = IDCache::GetEnvForThread(); JNIEnv* env = IDCache::GetEnvForThread();