Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dynamically register jni methods and use @FastNative & @CriticalNative #1792

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions test-app/app/src/main/java/com/tns/AndroidJsV8Inspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;

import dalvik.annotation.optimization.CriticalNative;
import dalvik.annotation.optimization.FastNative;
import fi.iki.elonen.NanoHTTPD;
import fi.iki.elonen.NanoWSD;

Expand All @@ -27,14 +29,19 @@ class AndroidJsV8Inspector {
private static String ApplicationDir;
private String packageName;

@CriticalNative
protected native final void init();

@FastNative
protected native final void connect(Object connection);

@CriticalNative
private native void scheduleBreak();

@CriticalNative
protected static native void disconnect();

@FastNative
protected native final void dispatchMessage(String message);

private Handler mainHandler;
Expand Down
28 changes: 21 additions & 7 deletions test-app/runtime/src/main/cpp/com_tns_AndroidJsV8Inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,42 @@
#include <sstream>
#include "JsV8InspectorClient.h"
#include "ArgConverter.h"
#include "com_tns_AndroidJsV8Inspector.h"

using namespace tns;
using namespace std;

JNIEXPORT extern "C" void Java_com_tns_AndroidJsV8Inspector_init(JNIEnv* env, jobject object) {
JsV8InspectorClient::GetInstance()->init();
}

JNIEXPORT extern "C" void Java_com_tns_AndroidJsV8Inspector_connect(JNIEnv* env, jobject instance, jobject connection) {
JNIEXPORT JNICALL void connect(JNIEnv *env, jobject instance, jobject connection) {
JsV8InspectorClient::GetInstance()->disconnect();
JsV8InspectorClient::GetInstance()->connect(connection);
}

JNIEXPORT extern "C" void Java_com_tns_AndroidJsV8Inspector_scheduleBreak(JNIEnv* env, jobject instance) {
JNIEXPORT JNICALL void scheduleBreak(JNIEnv *env, jobject instance) {
JsV8InspectorClient::GetInstance()->scheduleBreak();
}

JNIEXPORT extern "C" void Java_com_tns_AndroidJsV8Inspector_disconnect(JNIEnv* env, jobject instance) {
JNIEXPORT JNICALL void scheduleBreakCritical() {
JsV8InspectorClient::GetInstance()->scheduleBreak();
}

JNIEXPORT JNICALL void disconnect(JNIEnv *env, jobject instance) {
JsV8InspectorClient::GetInstance()->disconnect();
}

JNIEXPORT JNICALL void disconnectCritical() {
JsV8InspectorClient::GetInstance()->disconnect();
}

JNIEXPORT extern "C" void Java_com_tns_AndroidJsV8Inspector_dispatchMessage(JNIEnv* env, jobject instance, jstring jMessage) {
JNIEXPORT JNICALL void dispatchMessage(JNIEnv *env, jobject instance, jstring jMessage) {
std::string message = ArgConverter::jstringToString(jMessage);
JsV8InspectorClient::GetInstance()->dispatchMessage(message);
}

JNIEXPORT JNICALL void init(JNIEnv *env, jobject object) {
JsV8InspectorClient::GetInstance()->init();
}

JNIEXPORT JNICALL void initCritical() {
JsV8InspectorClient::GetInstance()->init();
}
35 changes: 35 additions & 0 deletions test-app/runtime/src/main/cpp/com_tns_AndroidJsV8Inspector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Created by Osei Fortune on 07/11/2023.
//
#include "jni.h"
#include "JEnv.h"
#include "NativeScriptException.h"
#include <sstream>
#include "JsV8InspectorClient.h"
#include "ArgConverter.h"


using namespace tns;
using namespace std;

#ifndef COM_TNS_ANDROIDJSV8INSPECTOR_H
#define COM_TNS_ANDROIDJSV8INSPECTOR_H

void init(JNIEnv *env, jobject object);

void initCritical();

void connect(JNIEnv *env, jobject instance, jobject connection);

void scheduleBreak(JNIEnv *env, jobject instance);

void scheduleBreakCritical();

void disconnect(JNIEnv *env, jobject instance);

void disconnectCritical();

void dispatchMessage(JNIEnv *env, jobject instance, jstring jMessage);


#endif //COM_TNS_ANDROIDJSV8INSPECTOR_H
2 changes: 1 addition & 1 deletion test-app/runtime/src/main/cpp/com_tns_AssetExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using namespace tns;
using namespace std;

extern "C" JNIEXPORT void Java_com_tns_AssetExtractor_extractAssets(JNIEnv* env, jobject obj, jstring apk, jstring inputDir, jstring outputDir, jboolean _forceOverwrite) {
JNIEXPORT JNICALL void extractAssets(JNIEnv* env, jobject obj, jstring apk, jstring inputDir, jstring outputDir, jboolean _forceOverwrite) {
try {
AssetExtractor::ExtractAssets(env, obj, apk, inputDir, outputDir, _forceOverwrite);
} catch (NativeScriptException& e) {
Expand Down
19 changes: 19 additions & 0 deletions test-app/runtime/src/main/cpp/com_tns_AssetExtractor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Created by Osei Fortune on 07/11/2023.
//

#include "jni.h"
#include "AssetExtractor.h"
#include "NativeScriptException.h"

#include <sstream>

#ifndef COM_TNS_ASSETEXTRACTOR_H
#define COM_TNS_ASSETEXTRACTOR_H

using namespace std;
using namespace tns;

void extractAssets(JNIEnv* env, jobject obj, jstring apk, jstring inputDir, jstring outputDir, jboolean _forceOverwrite);

#endif //COM_TNS_ASSETEXTRACTOR_H
Loading
Loading