Skip to content

Commit

Permalink
Migrate JNI functions in StarboardBridge
Browse files Browse the repository at this point in the history
b/389117681
  • Loading branch information
haozheng-cobalt committed Jan 10, 2025
1 parent 632168a commit 23ade15
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,8 @@ public Context getApplicationContext() {
return appContext;
}

// TODO: (cobalt b/372559388) remove or migrate JNI?
// Used in starboard/android/shared/system_platform_error.cc
@SuppressWarnings("unused")
@UsedByNative
@CalledByNative
void raisePlatformError(@PlatformError.ErrorType int errorType, long data) {
PlatformError error = new PlatformError(activityHolder, errorType, data);
error.raise();
Expand Down
8 changes: 8 additions & 0 deletions starboard/android/shared/starboard_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ StarboardBridge::GetSupportedHdrTypes(JNIEnv* env) {
SB_DCHECK(env);
return Java_StarboardBridge_getSupportedHdrTypes(env, j_starboard_bridge_);
}

void StarboardBridge::RaisePlatformError(JNIEnv* env,
jint errorType,
jlong data) {
SB_DCHECK(env);
Java_StarboardBridge_raisePlatformError(env, j_starboard_bridge_, errorType,
data);
}
} // namespace shared
} // namespace android
} // namespace starboard
2 changes: 2 additions & 0 deletions starboard/android/shared/starboard_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class StarboardBridge {
base::android::ScopedJavaLocalRef<jintArray> GetSupportedHdrTypes(
JNIEnv* env);

void RaisePlatformError(JNIEnv* env, jint errorType, jlong data);

private:
StarboardBridge() = default;
~StarboardBridge() = default;
Expand Down
11 changes: 5 additions & 6 deletions starboard/android/shared/system_platform_error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
#include <functional>

#include "starboard/android/shared/application_android.h"
#include "starboard/android/shared/jni_env_ext.h"
#include "starboard/android/shared/starboard_bridge.h"

using starboard::android::shared::ApplicationAndroid;
using starboard::android::shared::JniEnvExt;

namespace {

Expand All @@ -50,7 +49,7 @@ bool SbSystemRaisePlatformError(SbSystemPlatformErrorType type,
return false;
}

JniEnvExt* env = JniEnvExt::Get();
JNIEnv* env = base::android::AttachCurrentThread();

auto send_response_callback =
callback ? new SendResponseCallback(
Expand All @@ -60,9 +59,9 @@ bool SbSystemRaisePlatformError(SbSystemPlatformErrorType type,
})
: nullptr;

env->CallStarboardVoidMethodOrAbort(
"raisePlatformError", "(IJ)V", jni_error_type,
reinterpret_cast<jlong>(send_response_callback));
starboard::android::shared::StarboardBridge::GetInstance()
->RaisePlatformError(env, jni_error_type,
reinterpret_cast<jlong>(send_response_callback));
return true;
}

Expand Down

0 comments on commit 23ade15

Please sign in to comment.