From 5680a1edadc0801b209e5753710b613f5880ed3c Mon Sep 17 00:00:00 2001 From: Christian Beier Date: Thu, 15 Aug 2024 17:49:44 +0200 Subject: [PATCH] MainService,native: wire up http root dir re #6 --- app/src/main/cpp/droidvnc-ng.c | 13 ++++++++++++- .../net/christianbeier/droidvnc_ng/MainService.java | 8 +++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/main/cpp/droidvnc-ng.c b/app/src/main/cpp/droidvnc-ng.c index 73f332e0..7724920d 100644 --- a/app/src/main/cpp/droidvnc-ng.c +++ b/app/src/main/cpp/droidvnc-ng.c @@ -272,6 +272,7 @@ JNIEXPORT jboolean JNICALL Java_net_christianbeier_droidvnc_1ng_MainService_vncS free(theScreen->frameBuffer); theScreen->frameBuffer = NULL; free((char*)theScreen->desktopName); // always malloc'ed by us + free(theScreen->httpDir); // always malloc'ed by us theScreen->desktopName = NULL; if(theScreen->authPasswdData) { // if this is set, it was malloc'ed by us and has one password in there char **passwordList = theScreen->authPasswdData; @@ -287,7 +288,7 @@ JNIEXPORT jboolean JNICALL Java_net_christianbeier_droidvnc_1ng_MainService_vncS } -JNIEXPORT jboolean JNICALL Java_net_christianbeier_droidvnc_1ng_MainService_vncStartServer(JNIEnv *env, jobject thiz, jint width, jint height, jint port, jstring desktopname, jstring password) { +JNIEXPORT jboolean JNICALL Java_net_christianbeier_droidvnc_1ng_MainService_vncStartServer(JNIEnv *env, jobject thiz, jint width, jint height, jint port, jstring desktopname, jstring password, jstring httpRootDir) { int argc = 0; @@ -355,6 +356,16 @@ JNIEXPORT jboolean JNICALL Java_net_christianbeier_droidvnc_1ng_MainService_vncS (*env)->ReleaseStringUTFChars(env, password, cPassword); } + if(httpRootDir) { // string arg to GetStringUTFChars() must not be NULL + const char *cHttpRootDir = (*env)->GetStringUTFChars(env, httpRootDir, NULL); + if(!cHttpRootDir) { + __android_log_print(ANDROID_LOG_ERROR, TAG, "vncStartServer: failed getting http root dir from JNI"); + Java_net_christianbeier_droidvnc_1ng_MainService_vncStopServer(env, thiz); + return JNI_FALSE; + } + theScreen->httpDir = strdup(cHttpRootDir); + (*env)->ReleaseStringUTFChars(env, httpRootDir, cHttpRootDir); + } rfbInitServer(theScreen); diff --git a/app/src/main/java/net/christianbeier/droidvnc_ng/MainService.java b/app/src/main/java/net/christianbeier/droidvnc_ng/MainService.java index 83f1fe20..8af10220 100644 --- a/app/src/main/java/net/christianbeier/droidvnc_ng/MainService.java +++ b/app/src/main/java/net/christianbeier/droidvnc_ng/MainService.java @@ -166,7 +166,7 @@ public void onServiceUnregistered(NsdServiceInfo nsdServiceInfo) { } @SuppressWarnings("BooleanMethodIsAlwaysInverted") - private native boolean vncStartServer(int width, int height, int port, String desktopName, String password); + private native boolean vncStartServer(int width, int height, int port, String desktopName, String password, String httpRootDir); private native boolean vncStopServer(); private native boolean vncIsActive(); private native long vncConnectReverse(String host, int port); @@ -339,7 +339,8 @@ public int onStartCommand(Intent intent, int flags, int startId) displayMetrics.heightPixels, port, name, - PreferenceManager.getDefaultSharedPreferences(this).getString(PREFS_KEY_SERVER_LAST_PASSWORD, mDefaults.getPassword())); + PreferenceManager.getDefaultSharedPreferences(this).getString(PREFS_KEY_SERVER_LAST_PASSWORD, mDefaults.getPassword()), + getFilesDir().getAbsolutePath() + File.separator + "novnc"); Intent answer = new Intent(ACTION_START); answer.putExtra(EXTRA_REQUEST_ID, PreferenceManager.getDefaultSharedPreferences(this).getString(PREFS_KEY_SERVER_LAST_START_REQUEST_ID, null)); answer.putExtra(EXTRA_REQUEST_SUCCESS, status); @@ -379,7 +380,8 @@ public int onStartCommand(Intent intent, int flags, int startId) displayMetrics.heightPixels, port, name, - PreferenceManager.getDefaultSharedPreferences(this).getString(PREFS_KEY_SERVER_LAST_PASSWORD, mDefaults.getPassword())); + PreferenceManager.getDefaultSharedPreferences(this).getString(PREFS_KEY_SERVER_LAST_PASSWORD, mDefaults.getPassword()), + getFilesDir().getAbsolutePath() + File.separator + "novnc"); Intent answer = new Intent(ACTION_START); answer.putExtra(EXTRA_REQUEST_ID, PreferenceManager.getDefaultSharedPreferences(this).getString(PREFS_KEY_SERVER_LAST_START_REQUEST_ID, null));