You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
main-executable: allow passing arbitrary options to ART
This commit is contained in:
@@ -74,33 +74,44 @@ char *construct_classpath(char *prefix, char **cp_array, size_t len)
|
|||||||
|
|
||||||
#define JDWP_ARG "-XjdwpOptions:transport=dt_socket,server=y,suspend=y,address="
|
#define JDWP_ARG "-XjdwpOptions:transport=dt_socket,server=y,suspend=y,address="
|
||||||
|
|
||||||
JNIEnv* create_vm(char *api_impl_jar, char *apk_classpath, char *microg_apk, char *framework_res_apk, char *api_impl_natives_dir, char *app_lib_dir) {
|
JNIEnv* create_vm(char *api_impl_jar, char *apk_classpath, char *microg_apk, char *framework_res_apk, char *api_impl_natives_dir, char *app_lib_dir, char **extra_jvm_options) {
|
||||||
JavaVM* jvm;
|
JavaVM* jvm;
|
||||||
JNIEnv* env;
|
JNIEnv* env;
|
||||||
JavaVMInitArgs args;
|
JavaVMInitArgs args = {
|
||||||
JavaVMOption options[6];
|
.version = JNI_VERSION_1_6,
|
||||||
args.version = JNI_VERSION_1_6;
|
.nOptions = 3,
|
||||||
args.nOptions = 4;
|
};
|
||||||
|
JavaVMOption *options;
|
||||||
|
|
||||||
|
int option_counter = args.nOptions;
|
||||||
|
|
||||||
char jdwp_option_string[sizeof(JDWP_ARG) + 5] = JDWP_ARG; // 5 chars for port number, NULL byte is counted by sizeof
|
char jdwp_option_string[sizeof(JDWP_ARG) + 5] = JDWP_ARG; // 5 chars for port number, NULL byte is counted by sizeof
|
||||||
|
|
||||||
const char* jdwp_port = getenv("JDWP_LISTEN");
|
const char* jdwp_port = getenv("JDWP_LISTEN");
|
||||||
|
|
||||||
if(jdwp_port)
|
if(jdwp_port)
|
||||||
args.nOptions += 2;
|
args.nOptions += 2;
|
||||||
|
if(extra_jvm_options)
|
||||||
|
args.nOptions += g_strv_length(extra_jvm_options);
|
||||||
|
options = malloc(sizeof(JavaVMOption) * args.nOptions);
|
||||||
|
|
||||||
|
|
||||||
if(getenv("RUN_FROM_BUILDDIR")) {
|
if(getenv("RUN_FROM_BUILDDIR")) {
|
||||||
options[0].optionString = construct_classpath("-Djava.library.path=", (char *[]){"./", app_lib_dir}, 2);
|
options[0].optionString = construct_classpath("-Djava.library.path=", (char *[]){"./", app_lib_dir}, 2);
|
||||||
} else {
|
} else {
|
||||||
printf(">>%s<<\n", api_impl_natives_dir);
|
|
||||||
options[0].optionString = construct_classpath("-Djava.library.path=", (char *[]){api_impl_natives_dir, app_lib_dir}, 2);
|
options[0].optionString = construct_classpath("-Djava.library.path=", (char *[]){api_impl_natives_dir, app_lib_dir}, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
options[1].optionString = construct_classpath("-Djava.class.path=", (char *[]){api_impl_jar, apk_classpath, microg_apk, framework_res_apk}, 4);
|
options[1].optionString = construct_classpath("-Djava.class.path=", (char *[]){api_impl_jar, apk_classpath, microg_apk, framework_res_apk}, 4);
|
||||||
options[2].optionString = "-verbose:jni";
|
options[2].optionString = "-Xcheck:jni";
|
||||||
options[3].optionString = "-Xcheck:jni";
|
|
||||||
if(jdwp_port) {
|
if(jdwp_port) {
|
||||||
strncat(jdwp_option_string, jdwp_port, 5); // 5 chars is enough for a port number, and won't overflow our array
|
strncat(jdwp_option_string, jdwp_port, 5); // 5 chars is enough for a port number, and won't overflow our array
|
||||||
options[4].optionString = "-XjdwpProvider:internal";
|
options[option_counter++].optionString = "-XjdwpProvider:internal";
|
||||||
options[5].optionString = jdwp_option_string;
|
options[option_counter++].optionString = jdwp_option_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(extra_jvm_options && *extra_jvm_options) {
|
||||||
|
options[option_counter++].optionString = *(extra_jvm_options++);
|
||||||
}
|
}
|
||||||
|
|
||||||
args.options = options;
|
args.options = options;
|
||||||
@@ -112,6 +123,8 @@ JNIEnv* create_vm(char *api_impl_jar, char *apk_classpath, char *microg_apk, cha
|
|||||||
} else {
|
} else {
|
||||||
printf("JVM launched successfully\n");
|
printf("JVM launched successfully\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(options);
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +184,15 @@ void dl_parse_library_path(const char *path, char *delim);
|
|||||||
#define MICROG_APK_PATH_LOCAL "./com.google.android.gms.apk"
|
#define MICROG_APK_PATH_LOCAL "./com.google.android.gms.apk"
|
||||||
#define FRAMEWORK_RES_PATH_LOCAL "./res/framework-res.apk"
|
#define FRAMEWORK_RES_PATH_LOCAL "./res/framework-res.apk"
|
||||||
|
|
||||||
struct jni_callback_data { char *apk_main_activity_class; uint32_t window_width; uint32_t window_height; gboolean install; char *prgname; };
|
struct jni_callback_data {
|
||||||
|
char *apk_main_activity_class;
|
||||||
|
uint32_t window_width;
|
||||||
|
uint32_t window_height;
|
||||||
|
gboolean install;
|
||||||
|
char *prgname;
|
||||||
|
char **extra_jvm_options;
|
||||||
|
};
|
||||||
|
|
||||||
static void open(GtkApplication *app, GFile** files, gint nfiles, const gchar* hint, struct jni_callback_data *d)
|
static void open(GtkApplication *app, GFile** files, gint nfiles, const gchar* hint, struct jni_callback_data *d)
|
||||||
{
|
{
|
||||||
//TODO: pass all files to classpath
|
//TODO: pass all files to classpath
|
||||||
@@ -336,7 +357,7 @@ static void open(GtkApplication *app, GFile** files, gint nfiles, const gchar* h
|
|||||||
// calling directly into the shim bionic linker to whitelist the app's lib dir as containing bionic-linked libraries
|
// calling directly into the shim bionic linker to whitelist the app's lib dir as containing bionic-linked libraries
|
||||||
dl_parse_library_path(app_lib_dir, ":");
|
dl_parse_library_path(app_lib_dir, ":");
|
||||||
|
|
||||||
JNIEnv* env = create_vm(api_impl_jar, apk_classpath, microg_apk, framework_res_apk, api_impl_natives_dir, app_lib_dir);
|
JNIEnv* env = create_vm(api_impl_jar, apk_classpath, microg_apk, framework_res_apk, api_impl_natives_dir, app_lib_dir, d->extra_jvm_options);
|
||||||
|
|
||||||
free(app_lib_dir);
|
free(app_lib_dir);
|
||||||
|
|
||||||
@@ -561,6 +582,14 @@ void init_cmd_parameters(GApplication *app, struct jni_callback_data *d)
|
|||||||
.arg_data = &d->install,
|
.arg_data = &d->install,
|
||||||
.description = "install .desktop file for the given apk",
|
.description = "install .desktop file for the given apk",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.long_name = "extra-jvm-option",
|
||||||
|
.short_name = 'X',
|
||||||
|
.flags = 0,
|
||||||
|
.arg = G_OPTION_ARG_STRING_ARRAY,
|
||||||
|
.arg_data = &d->extra_jvm_options,
|
||||||
|
.description = "install .desktop file for the given apk",
|
||||||
|
},
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -588,6 +617,7 @@ int main(int argc, char **argv)
|
|||||||
callback_data->window_height = 540;
|
callback_data->window_height = 540;
|
||||||
callback_data->install = FALSE;
|
callback_data->install = FALSE;
|
||||||
callback_data->prgname = argv[0];
|
callback_data->prgname = argv[0];
|
||||||
|
callback_data->extra_jvm_options = NULL;
|
||||||
|
|
||||||
app = gtk_application_new("com.example.demo_application", G_APPLICATION_NON_UNIQUE | G_APPLICATION_HANDLES_OPEN | G_APPLICATION_CAN_OVERRIDE_APP_ID);
|
app = gtk_application_new("com.example.demo_application", G_APPLICATION_NON_UNIQUE | G_APPLICATION_HANDLES_OPEN | G_APPLICATION_CAN_OVERRIDE_APP_ID);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user