Skip to content

Commit

Permalink
Fix Compilation with Android NDK r26
Browse files Browse the repository at this point in the history
  • Loading branch information
BieHDC authored and andydotxyz committed Oct 3, 2023
1 parent 3949c51 commit db62982
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions app/app_mobile_and.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ jobject getSystemService(uintptr_t jni_env, uintptr_t ctx, char *service) {
JNIEnv *env = (JNIEnv*)jni_env;
jstring serviceStr = (*env)->NewStringUTF(env, service);

jclass ctxClass = (*env)->GetObjectClass(env, ctx);
jclass ctxClass = (*env)->GetObjectClass(env, (jobject)ctx);
jmethodID getSystemService = find_method(env, ctxClass, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");

return (jobject)(*env)->CallObjectMethod(env, ctx, getSystemService, serviceStr);
return (jobject)(*env)->CallObjectMethod(env, (jobject)ctx, getSystemService, serviceStr);
}

int nextId = 1;
Expand Down Expand Up @@ -81,7 +81,7 @@ void openURL(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx, char *url) {

jclass contextClass = find_class(env, "android/content/Context");
jmethodID start = find_method(env, contextClass, "startActivity", "(Landroid/content/Intent;)V");
(*env)->CallVoidMethod(env, ctx, start, intent);
(*env)->CallVoidMethod(env, (jobject)ctx, start, intent);
}

void sendNotification(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx, char *title, char *body) {
Expand All @@ -94,7 +94,7 @@ void sendNotification(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx, char
jobject builder = (*env)->NewObject(env, cls, constructor, ctx);

jclass mgrCls = find_class(env, "android/app/NotificationManager");
jobject mgr = getSystemService(env, ctx, "notification");
jobject mgr = getSystemService((uintptr_t)env, ctx, "notification");

if (isOreoOrLater(env)) {
jstring channelId = (*env)->NewStringUTF(env, "fyne-notif");
Expand Down Expand Up @@ -128,4 +128,4 @@ void sendNotification(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx, char
jmethodID notify = find_method(env, mgrCls, "notify", "(ILandroid/app/Notification;)V");
(*env)->CallVoidMethod(env, mgr, notify, nextId, notif);
nextId++;
}
}
26 changes: 13 additions & 13 deletions internal/driver/mobile/android.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static jmethodID find_static_method(JNIEnv *env, jclass clazz, const char *name,
return m;
}

char* getString(uintptr_t jni_env, uintptr_t ctx, jstring str) {
const char* getString(uintptr_t jni_env, uintptr_t ctx, jstring str) {
JNIEnv *env = (JNIEnv*)jni_env;

const char *chars = (*env)->GetStringUTFChars(env, str, NULL);
Expand All @@ -65,11 +65,11 @@ jobject parseURI(uintptr_t jni_env, uintptr_t ctx, char* uriCstr) {

jobject getClipboard(uintptr_t jni_env, uintptr_t ctx) {
JNIEnv *env = (JNIEnv*)jni_env;
jclass ctxClass = (*env)->GetObjectClass(env, ctx);
jclass ctxClass = (*env)->GetObjectClass(env, (jobject)ctx);
jmethodID getSystemService = find_method(env, ctxClass, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");

jstring service = (*env)->NewStringUTF(env, "clipboard");
jobject ret = (jobject)(*env)->CallObjectMethod(env, ctx, getSystemService, service);
jobject ret = (*env)->CallObjectMethod(env, (jobject)ctx, getSystemService, service);
jthrowable err = (*env)->ExceptionOccurred(env);

if (err != NULL) {
Expand All @@ -80,7 +80,7 @@ jobject getClipboard(uintptr_t jni_env, uintptr_t ctx) {
return ret;
}

char *getClipboardContent(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx) {
const char *getClipboardContent(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx) {
JNIEnv *env = (JNIEnv*)jni_env;
jobject mgr = getClipboard(jni_env, ctx);
if (mgr == NULL) {
Expand Down Expand Up @@ -120,10 +120,10 @@ void setClipboardContent(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx, ch

jobject getContentResolver(uintptr_t jni_env, uintptr_t ctx) {
JNIEnv *env = (JNIEnv*)jni_env;
jclass ctxClass = (*env)->GetObjectClass(env, ctx);
jclass ctxClass = (*env)->GetObjectClass(env, (jobject)ctx);
jmethodID getContentResolver = find_method(env, ctxClass, "getContentResolver", "()Landroid/content/ContentResolver;");

return (jobject)(*env)->CallObjectMethod(env, ctx, getContentResolver);
return (jobject)(*env)->CallObjectMethod(env, (jobject)ctx, getContentResolver);
}

void* openStream(uintptr_t jni_env, uintptr_t ctx, char* uriCstr) {
Expand Down Expand Up @@ -165,7 +165,7 @@ void* saveStream(uintptr_t jni_env, uintptr_t ctx, char* uriCstr) {
return (*env)->NewGlobalRef(env, stream);
}

char* readStream(uintptr_t jni_env, uintptr_t ctx, void* stream, int len, int* total) {
jbyte* readStream(uintptr_t jni_env, uintptr_t ctx, void* stream, int len, int* total) {
JNIEnv *env = (JNIEnv*)jni_env;
jclass streamClass = (*env)->GetObjectClass(env, stream);
jmethodID read = find_method(env, streamClass, "read", "([BII)I");
Expand All @@ -178,12 +178,12 @@ char* readStream(uintptr_t jni_env, uintptr_t ctx, void* stream, int len, int* t
return NULL;
}

char* bytes = malloc(sizeof(char)*count);
jbyte* bytes = (jbyte*)malloc(sizeof(jbyte)*count);
(*env)->GetByteArrayRegion(env, data, 0, count, bytes);
return bytes;
}

void writeStream(uintptr_t jni_env, uintptr_t ctx, void* stream, char* buf, int len) {
void writeStream(uintptr_t jni_env, uintptr_t ctx, void* stream, jbyte* buf, int len) {
JNIEnv *env = (JNIEnv*)jni_env;
jclass streamClass = (*env)->GetObjectClass(env, stream);
jmethodID write = find_method(env, streamClass, "write", "([BII)V");
Expand Down Expand Up @@ -246,7 +246,7 @@ bool canListContentURI(uintptr_t jni_env, uintptr_t ctx, char* uriCstr) {
return false;
}

char *str = getString(jni_env, ctx, type);
const char *str = getString(jni_env, ctx, type);
return strcmp(str, "vnd.android.document/directory") == 0;
}

Expand Down Expand Up @@ -297,7 +297,7 @@ bool createListableURI(uintptr_t jni_env, uintptr_t ctx, char* uriCstr) {
return false;
}

char* contentURIGetFileName(uintptr_t jni_env, uintptr_t ctx, char* uriCstr) {
const char* contentURIGetFileName(uintptr_t jni_env, uintptr_t ctx, char* uriCstr) {
JNIEnv *env = (JNIEnv*)jni_env;
jobject resolver = getContentResolver(jni_env, ctx);
jobject uri = parseURI(jni_env, ctx, uriCstr);
Expand All @@ -322,7 +322,7 @@ char* contentURIGetFileName(uintptr_t jni_env, uintptr_t ctx, char* uriCstr) {

if (((jboolean)(*env)->CallBooleanMethod(env, cursor, first)) == JNI_TRUE) {
jstring name = (jstring)(*env)->CallObjectMethod(env, cursor, get, 0);
char *fname = getString(jni_env, ctx, name);
const char *fname = getString(jni_env, ctx, name);
return fname;
}

Expand Down Expand Up @@ -401,7 +401,7 @@ char* listContentURI(uintptr_t jni_env, uintptr_t ctx, char* uriCstr) {
jmethodID toString = (*env)->GetMethodID(env, uriClass, "toString", "()Ljava/lang/String;");
jstring s = (jstring)(*env)->CallObjectMethod(env, childUri, toString);

char *uid = getString(jni_env, ctx, s);
const char *uid = getString(jni_env, ctx, s);

// append
char *old = ret;
Expand Down

0 comments on commit db62982

Please sign in to comment.