From bf72782c9f6d3bf8d002bb4cae8b9cf1f91abbd4 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Thu, 9 Mar 2023 00:32:42 +0000 Subject: [PATCH] Now we're running enough code to respond (incorrectly) to http requests. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4207 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- Makefile | 4 ++-- .../unprompted/tildefriends/MainActivity.java | 6 ++--- src/jnitest.c | 23 ++++++++++--------- src/main.c | 13 +++++++---- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index f463c765..4dacf844 100644 --- a/Makefile +++ b/Makefile @@ -423,8 +423,8 @@ out/TildeFriends.unsigned.apk: out/apk/classes.dex out/androiddebug/libtildefrie @cp out/androiddebug/libtildefriends.so out/apk/lib/arm64-v8a/ @cp deps/openssl/android/arm64-v8a/usr/local/lib/libssl.so out/apk/lib/arm64-v8a/ @cp deps/openssl/android/arm64-v8a/usr/local/lib/libcrypto.so out/apk/lib/arm64-v8a/ - $(ANDROID_BUILD_TOOLS)/aapt package -f -M src/android/AndroidManifest.xml -S src/android/res/ -I $(ANDROID_PLATFORM)/android.jar -F $@ out/apk/ - zip -u $@ -r $(PACKAGE_DIRS) + @$(ANDROID_BUILD_TOOLS)/aapt package -f -M src/android/AndroidManifest.xml -S src/android/res/ -I $(ANDROID_PLATFORM)/android.jar -F $@ out/apk/ + @zip -u $@ -q -r $(PACKAGE_DIRS) out/TildeFriends.apk: out/TildeFriends.unsigned.apk @echo [apksigner] $(notdir $@) diff --git a/src/android/com/unprompted/tildefriends/MainActivity.java b/src/android/com/unprompted/tildefriends/MainActivity.java index ef980251..5e725b51 100644 --- a/src/android/com/unprompted/tildefriends/MainActivity.java +++ b/src/android/com/unprompted/tildefriends/MainActivity.java @@ -14,12 +14,10 @@ public class MainActivity extends Activity { Log.w("tildefriends", String.format("getFilesDir() is %s", getFilesDir().toString())); Log.w("tildefriends", String.format("getPackageResourcePath() is %s", getPackageResourcePath().toString())); Log.w("tildefriends", String.format("getPackageCodePath() is %s", getPackageCodePath().toString())); - setFilesPath(getFilesDir().toString()); - text.setText(getMessage()); + setFilesPath(getFilesDir().toString(), getPackageResourcePath().toString()); } - public native String getMessage(); - public native void setFilesPath(String path); + public native void setFilesPath(String files_path, String apk_path); static { System.loadLibrary("tildefriends"); diff --git a/src/jnitest.c b/src/jnitest.c index 57913762..80d5b813 100644 --- a/src/jnitest.c +++ b/src/jnitest.c @@ -4,19 +4,20 @@ #include #include -void tf_android(); +void tf_android(const char* apk_path); -JNIEXPORT jstring JNICALL Java_com_unprompted_tildefriends_MainActivity_getMessage(JNIEnv* env, jobject obj) -{ - tf_android(); - return (*env)->NewStringUTF(env, "Hello!"); -} - -JNIEXPORT void JNICALL Java_com_unprompted_tildefriends_MainActivity_setFilesPath( JNIEnv* env, jobject obj, jstring path) +JNIEXPORT void JNICALL Java_com_unprompted_tildefriends_MainActivity_setFilesPath(JNIEnv* env, jobject obj, jstring files_path, jstring apk_path) { tf_printf("setFilesPath called.\n"); - const char* file_path = (*env)->GetStringUTFChars(obj, path, NULL); - int result = chdir(file_path); - tf_printf("chdir %s => %d\n", file_path, result); + const char* path_string = (*env)->GetStringUTFChars(env, files_path, NULL); + tf_printf("files_path = %s\n", path_string); + int result = chdir(path_string); + tf_printf("chdir %s => %d\n", path_string, result); + (*env)->ReleaseStringUTFChars(env, files_path, path_string); + + const char* apk_path_string = (*env)->GetStringUTFChars(env, apk_path, NULL); + tf_printf("apk = %s\n", apk_path_string); + tf_android(apk_path_string); + (*env)->ReleaseStringUTFChars(env, apk_path, apk_path_string); } #endif diff --git a/src/main.c b/src/main.c index b54c6377..b7ed7c9b 100644 --- a/src/main.c +++ b/src/main.c @@ -340,6 +340,7 @@ static int _tf_run_task(const tf_run_args_t* args, int index) int result = -1; tf_task_t* task = tf_task_create(); tf_task_set_trusted(task, true); + tf_printf("setting zip path to %s\n", args->zip); tf_task_set_zip_path(task, args->zip); tf_task_set_ssb_port(task, args->ssb_port ? args->ssb_port + index : 0); tf_task_set_http_port(task, args->http_port ? args->http_port + index : 0); @@ -740,14 +741,16 @@ done: static void _tf_android_thread(void* user_data) { - char* args[] = { "tildefriends", "run" }; + char* apk_path = user_data; + char* args[] = { "tildefriends", "run", "-z", apk_path }; main(_countof(args), args); + tf_free(apk_path); } -void tf_android() +void tf_android(const char* apk_path) { uv_thread_t thread_id = 0; - tf_printf("TEST: Starting a thread.\n"); - uv_thread_create(&thread_id, _tf_android_thread, NULL); - tf_printf("TEST: Post-thread start.\n"); + tf_printf("Starting a thread.\n"); + uv_thread_create(&thread_id, _tf_android_thread, tf_strdup(apk_path)); + tf_printf("Post-thread start.\n"); }