make sure the apk path is reliably set in the PackageInfo

This commit is contained in:
Mis012
2024-06-19 20:47:49 +02:00
parent 6832f5d16e
commit 92e2c06347
4 changed files with 22 additions and 9 deletions

View File

@@ -8,7 +8,13 @@
#include "../generated_headers/android_content_Context.h"
JNIEXPORT void JNICALL Java_android_content_Context_native_1updateConfig(JNIEnv *env, jclass class, jobject config)
extern char *apk_path;
JNIEXPORT jstring JNICALL Java_android_content_Context_native_1get_1apk_1path(JNIEnv *env, jclass this) {
return _JSTRING(apk_path);
}
JNIEXPORT void JNICALL Java_android_content_Context_native_1updateConfig(JNIEnv *env, jclass this, jobject config)
{
GtkSettings *settings = gtk_settings_get_default();
char *theme_name;

View File

@@ -9,6 +9,14 @@ extern "C" {
#endif
#undef android_content_Context_MODE_PRIVATE
#define android_content_Context_MODE_PRIVATE 0L
/*
* Class: android_content_Context
* Method: native_get_apk_path
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_android_content_Context_native_1get_1apk_1path
(JNIEnv *, jclass);
/*
* Class: android_content_Context
* Method: native_updateConfig

View File

@@ -81,8 +81,6 @@ public class Context extends Object {
public static PackageParser.Package pkg;
public static PackageManager package_manager;
static String apk_path = "/tmp/APK_PATH_SHOULD_HAVE_BEEN_FILLED_IN_BY_CODE_IN_main.c/";
public /*← FIXME?*/ static Application this_application;
File data_dir = null;
@@ -110,9 +108,11 @@ public class Context extends Object {
}
application_info.dataDir = Environment.getExternalStorageDirectory().getAbsolutePath();
application_info.nativeLibraryDir = (new File(Environment.getExternalStorageDirectory(), "lib")).getAbsolutePath();
application_info.sourceDir = native_get_apk_path();
package_manager = new PackageManager();
}
private static native String native_get_apk_path();
protected static native void native_updateConfig(Configuration config);
static Application createApplication(long native_window) throws Exception {
@@ -135,7 +135,6 @@ public class Context extends Object {
public Context() {
Slog.v(TAG, "new Context! this one is: " + this);
getApplicationInfo().sourceDir = getPackageCodePath();
}
public int checkPermission(String permission, int pid, int uid) {
@@ -224,7 +223,7 @@ public class Context extends Object {
}
public String getPackageCodePath() {
return apk_path;
return getApplicationInfo().sourceDir;
}
public int getColor(int resId) {

View File

@@ -33,6 +33,7 @@
#endif
GtkWidget *window;
char *apk_path;
// standard Gtk Application stuff, more or less
@@ -386,14 +387,13 @@ static void open(GtkApplication *app, GFile** files, gint nfiles, const gchar* h
jmethodID loadLibrary_with_classloader = _METHOD(java_runtime_class, "loadLibrary", "(Ljava/lang/String;Ljava/lang/ClassLoader;)V");
(*env)->CallVoidMethod(env, java_runtime, loadLibrary_with_classloader, _JSTRING("translation_layer_main"), class_loader);
// some apps need the apk path since they directly read their apk
apk_path = strdup(apk_classpath);
set_up_handle_cache(env);
/* -- misc -- */
// some apps need the apk path since they directly read their apk
jclass context_class = (*env)->FindClass(env, "android/content/Context");
_SET_STATIC_OBJ_FIELD(context_class, "apk_path", "Ljava/lang/String;", _JSTRING(apk_classpath));
window = gtk_application_window_new(app);
if(getenv("ATL_DISABLE_WINDOW_DECORATIONS"))