forked from cory/tildefriends
Steps toward following all the inconvenient, changing android rules:
* Set android:debuggable=false. * Call native code through JNI only. Having a native executable on disk and exec-ing it no longer seems possible. * Do all the Tilde Friends things in one process, without a proper sandbox, until I can wire up a restricted service worker process. * Jam Android App Bundle (.aab) building into the makefile. * Yuck.
This commit is contained in:
@ -1,15 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.unprompted.tildefriends"
|
||||
android:versionCode="21"
|
||||
android:versionCode="22"
|
||||
android:versionName="0.0.21-wip">
|
||||
<uses-sdk android:minSdkVersion="24" android:targetSdkVersion="34"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<application
|
||||
android:label="Tilde Friends"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:debuggable="true"
|
||||
android:extractNativeLibs="true">
|
||||
android:debuggable="false">
|
||||
<meta-data android:name="android.max_aspect" android:value="2.1"/>
|
||||
<activity
|
||||
android:name=".TildeFriendsActivity"
|
||||
|
5
src/android/BundleConfig.json
Normal file
5
src/android/BundleConfig.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"optimizations" : {
|
||||
"uncompress_native_libraries" : {}
|
||||
}
|
||||
}
|
@ -53,13 +53,23 @@ import java.util.concurrent.TimeUnit;
|
||||
public class TildeFriendsActivity extends Activity {
|
||||
TildeFriendsWebView web_view;
|
||||
String base_url;
|
||||
String port_file_path;
|
||||
Process process;
|
||||
Thread thread;
|
||||
Thread server_thread;
|
||||
|
||||
private ValueCallback<Uri[]> upload_message;
|
||||
private final static int FILECHOOSER_RESULT = 1;
|
||||
private float touch_down_y;
|
||||
|
||||
static {
|
||||
Log.w("tildefriends", "Calling system.loadLibrary().");
|
||||
System.loadLibrary("tildefriends");
|
||||
Log.w("tildefriends", "system.loadLibrary() completed.");
|
||||
}
|
||||
|
||||
static native int tf_server_main(String files_dir, String apk_path, String out_port_file_path);
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
|
||||
@ -76,7 +86,7 @@ public class TildeFriendsActivity extends Activity {
|
||||
Log.w("tildefriends", String.format("getPackageResourcePath() is %s", getPackageResourcePath().toString()));
|
||||
Log.w("tildefriends", String.format("nativeLibraryDir is %s", getApplicationInfo().nativeLibraryDir));
|
||||
|
||||
String port_file_path = getFilesDir().toString() + "/port.txt";
|
||||
port_file_path = getFilesDir().toString() + "/port.txt";
|
||||
new File(port_file_path).delete();
|
||||
base_url = "http://127.0.0.1:12345/";
|
||||
|
||||
@ -134,17 +144,15 @@ public class TildeFriendsActivity extends Activity {
|
||||
thread.start();
|
||||
|
||||
set_status("Starting server...");
|
||||
String exe = getApplicationInfo().nativeLibraryDir + "/tildefriends.so";
|
||||
ProcessBuilder builder = new ProcessBuilder(exe, "run", "-z", getPackageResourcePath().toString(), "-a", "out_http_port_file=" + port_file_path, "-p", "0");
|
||||
Log.w("tildefriends", "files = " + getFilesDir().toString());
|
||||
Log.w("tildefriends", "exe = " + exe);
|
||||
builder.directory(getFilesDir());
|
||||
builder.inheritIO();
|
||||
try {
|
||||
process = builder.start();
|
||||
} catch (java.io.IOException e) {
|
||||
Log.w("tildefriends", "IOException starting process: " + e.toString());
|
||||
}
|
||||
server_thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.w("tildefriends", "Calling tf_server_main.");
|
||||
int result = tf_server_main(getFilesDir().toString(), getPackageResourcePath().toString(), port_file_path);
|
||||
Log.w("tildefriends", "tf_server_main returned " + result + ".");
|
||||
}
|
||||
});
|
||||
server_thread.start();
|
||||
|
||||
web_view.getSettings().setJavaScriptEnabled(true);
|
||||
web_view.getSettings().setDatabaseEnabled(true);
|
||||
|
81
src/main.c
81
src/main.c
@ -34,6 +34,10 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include "jni.h"
|
||||
#endif
|
||||
|
||||
#if !defined(_countof)
|
||||
#define _countof(a) ((int)(sizeof((a)) / sizeof(*(a))))
|
||||
#endif
|
||||
@ -726,6 +730,83 @@ static void _startup(int argc, char* argv[])
|
||||
}
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
static jint _tf_server_main(JNIEnv* env, jobject this_object, jstring files_dir, jstring apk_path, jstring out_port_file_path)
|
||||
{
|
||||
tf_printf("This is tf_server_main main.\n");
|
||||
_startup(0, (char*[]) { NULL });
|
||||
tf_printf("That was startup.\n");
|
||||
|
||||
const char* files = (*env)->GetStringUTFChars(env, files_dir, NULL);
|
||||
const char* apk = (*env)->GetStringUTFChars(env, apk_path, NULL);
|
||||
const char* out_port_file = (*env)->GetStringUTFChars(env, out_port_file_path, NULL);
|
||||
|
||||
tf_printf("FILES = %s\n", files);
|
||||
tf_printf("APK = %s\n", apk);
|
||||
tf_printf("OUT_PORT = %s\n", out_port_file);
|
||||
|
||||
int result = uv_chdir(files);
|
||||
if (result)
|
||||
{
|
||||
tf_printf("uv_chdir: %s\n", uv_strerror(result));
|
||||
}
|
||||
|
||||
size_t port_file_arg_length = strlen(out_port_file) + strlen("out_http_port_file=") + 1;
|
||||
char* port_file_arg = alloca(port_file_arg_length);
|
||||
snprintf(port_file_arg, port_file_arg_length, "out_http_port_file=%s", out_port_file);
|
||||
|
||||
const char* args[] =
|
||||
{
|
||||
"-z",
|
||||
apk,
|
||||
"-a",
|
||||
port_file_arg,
|
||||
"-p",
|
||||
"0",
|
||||
"-o", /* HACK! FIXME! */
|
||||
};
|
||||
|
||||
result = _tf_command_run(apk, _countof(args), (char**)args);
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, files_dir, files);
|
||||
(*env)->ReleaseStringUTFChars(env, apk_path, apk);
|
||||
(*env)->ReleaseStringUTFChars(env, out_port_file_path, out_port_file);
|
||||
|
||||
tf_printf("tf_server_main finished with %d.", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
||||
{
|
||||
tf_printf("JNI_Onload called.\n");
|
||||
JNIEnv* env;
|
||||
if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK)
|
||||
{
|
||||
tf_printf("Failed to get JNI environment.\n");
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
tf_printf("Finding class.\n");
|
||||
jclass c = (*env)->FindClass(env, "com/unprompted/tildefriends/TildeFriendsActivity");
|
||||
if (!c)
|
||||
{
|
||||
tf_printf("Failed to find TildeFriendsActivity class.\n");
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
tf_printf("Registering method.\n");
|
||||
static const JNINativeMethod methods[] = {
|
||||
{ "tf_server_main", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", _tf_server_main },
|
||||
};
|
||||
int result = (*env)->RegisterNatives(env, c, methods, (int)_countof(methods));
|
||||
if (result != JNI_OK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
tf_printf("Done.\n");
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
_startup(argc, argv);
|
||||
|
Reference in New Issue
Block a user