[Base] GetAndroidThreadJniEnv capitals, move JNI usage tips there

This commit is contained in:
Triang3l 2022-02-01 21:33:20 +03:00
parent 009f709ad4
commit c6fc8f706a
4 changed files with 14 additions and 13 deletions

View File

@ -145,7 +145,7 @@ void ShutdownAndroidAppFromMainThread() {
int32_t GetAndroidApiLevel() { return android_api_level_; }
JNIEnv* GetAndroidThreadJNIEnv() {
JNIEnv* GetAndroidThreadJniEnv() {
if (!android_java_vm_) {
return nullptr;
}

View File

@ -38,9 +38,18 @@ void ShutdownAndroidAppFromMainThread();
// configuration.
int32_t GetAndroidApiLevel();
// Useful notes about JNI usage on Android within Xenia:
// - All static libraries defining JNI native functions must be linked to shared
// libraries via LOCAL_WHOLE_STATIC_LIBRARIES.
// - If method or field IDs are cached, a global reference to the class needs to
// be held - it prevents the class from being unloaded by the class loaders
// (in a way that would make the IDs invalid when it's reloaded).
// - GetStringUTFChars (UTF-8) returns null-terminated strings, GetStringChars
// (UTF-16) does not.
// May return null if not in a Java VM process, or in case of a failure to
// attach on a non-main thread.
JNIEnv* GetAndroidThreadJNIEnv();
JNIEnv* GetAndroidThreadJniEnv();
// Returns the global reference if in an application context, or null otherwise.
// This is the application context, not the activity one, because multiple
// activities may be running in one process.

View File

@ -39,7 +39,7 @@ static bool android_system_initialized_ = false;
bool InitializeAndroidSystemForApplicationContext() {
assert_false(android_system_initialized_);
JNIEnv* jni_env = GetAndroidThreadJNIEnv();
JNIEnv* jni_env = GetAndroidThreadJniEnv();
if (!jni_env) {
return false;
}
@ -209,7 +209,7 @@ void ShutdownAndroidSystem() {
android_system_intent_init_action_uri_ = nullptr;
android_system_uri_parse_ = nullptr;
android_system_application_context_start_activity_ = nullptr;
JNIEnv* jni_env = GetAndroidThreadJNIEnv();
JNIEnv* jni_env = GetAndroidThreadJniEnv();
if (jni_env) {
if (android_system_intent_action_view_) {
jni_env->DeleteGlobalRef(android_system_intent_action_view_);
@ -234,7 +234,7 @@ void LaunchWebBrowser(const std::string_view url) {
if (!android_system_initialized_) {
return;
}
JNIEnv* jni_env = GetAndroidThreadJNIEnv();
JNIEnv* jni_env = GetAndroidThreadJniEnv();
if (!jni_env) {
return;
}

View File

@ -78,14 +78,6 @@ class AndroidWindowedAppContext final : public WindowedAppContext {
bool InitializeApp(std::unique_ptr<WindowedApp> (*app_creator)(
WindowedAppContext& app_context));
// Useful notes about JNI usage on Android within Xenia:
// - All static libraries defining JNI native functions must be linked to
// shared libraries via LOCAL_WHOLE_STATIC_LIBRARIES.
// - If method or field IDs are cached, a global reference to the class needs
// to be held - it prevents the class from being unloaded by the class
// loaders (in a way that would make the IDs invalid when it's reloaded).
// - GetStringUTFChars (UTF-8) returns null-terminated strings, GetStringChars
// (UTF-16) does not.
JNIEnv* ui_thread_jni_env_ = nullptr;
// The object reference must be held by the app according to