diff options
| author | Po Lu | 2024-04-20 20:44:30 +0800 |
|---|---|---|
| committer | Po Lu | 2024-04-20 20:46:17 +0800 |
| commit | 571fd42d48a0d99b7b210bd218836bd2f6ce2ccf (patch) | |
| tree | b69f859170af2f803c8677b94d440979c1c37336 | |
| parent | 9ea415cde3c602f5f13e4425ca508700b8118ffb (diff) | |
| download | emacs-571fd42d48a0d99b7b210bd218836bd2f6ce2ccf.tar.gz emacs-571fd42d48a0d99b7b210bd218836bd2f6ce2ccf.zip | |
Eliminate minor wart in EmacsService.java
* java/org/gnu/emacs/EmacsService.java (openContentUri): Replace
arg BYTES with URI and change its type to String.
* src/android.c (android_init_emacs_service):
* src/androidvfs.c (android_authority_name)
(android_authority_open): Adjust commentary and code to match.
| -rw-r--r-- | java/org/gnu/emacs/EmacsService.java | 45 | ||||
| -rw-r--r-- | src/android.c | 2 | ||||
| -rw-r--r-- | src/androidvfs.c | 32 |
3 files changed, 21 insertions, 58 deletions
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index b1ec397bc41..2d4079c11b0 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java | |||
| @@ -962,11 +962,13 @@ public final class EmacsService extends Service | |||
| 962 | string; make it writable if WRITABLE, and readable if READABLE. | 962 | string; make it writable if WRITABLE, and readable if READABLE. |
| 963 | Truncate the file if TRUNCATE. | 963 | Truncate the file if TRUNCATE. |
| 964 | 964 | ||
| 965 | Value is the resulting file descriptor or -1 upon failure. */ | 965 | Value is the resulting file descriptor or an exception will be |
| 966 | raised. */ | ||
| 966 | 967 | ||
| 967 | public int | 968 | public int |
| 968 | openContentUri (byte[] bytes, boolean writable, boolean readable, | 969 | openContentUri (String uri, boolean writable, boolean readable, |
| 969 | boolean truncate) | 970 | boolean truncate) |
| 971 | throws FileNotFoundException, IOException | ||
| 970 | { | 972 | { |
| 971 | String name, mode; | 973 | String name, mode; |
| 972 | ParcelFileDescriptor fd; | 974 | ParcelFileDescriptor fd; |
| @@ -985,39 +987,16 @@ public final class EmacsService extends Service | |||
| 985 | if (truncate) | 987 | if (truncate) |
| 986 | mode += "t"; | 988 | mode += "t"; |
| 987 | 989 | ||
| 988 | /* Try to open an associated ParcelFileDescriptor. */ | 990 | /* Try to open a corresponding ParcelFileDescriptor. Though |
| 991 | `fd.detachFd' is exclusive to Honeycomb and up, this function is | ||
| 992 | never called on systems older than KitKat, which is Emacs's | ||
| 993 | minimum requirement for access to /content/by-authority. */ | ||
| 989 | 994 | ||
| 990 | try | 995 | fd = resolver.openFileDescriptor (Uri.parse (uri), mode); |
| 991 | { | 996 | i = fd.detachFd (); |
| 992 | /* The usual file name encoding question rears its ugly head | 997 | fd.close (); |
| 993 | again. */ | ||
| 994 | |||
| 995 | name = new String (bytes, "UTF-8"); | ||
| 996 | fd = resolver.openFileDescriptor (Uri.parse (name), mode); | ||
| 997 | |||
| 998 | /* Use detachFd on newer versions of Android or plain old | ||
| 999 | dup. */ | ||
| 1000 | |||
| 1001 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) | ||
| 1002 | { | ||
| 1003 | i = fd.detachFd (); | ||
| 1004 | fd.close (); | ||
| 1005 | |||
| 1006 | return i; | ||
| 1007 | } | ||
| 1008 | else | ||
| 1009 | { | ||
| 1010 | i = EmacsNative.dup (fd.getFd ()); | ||
| 1011 | fd.close (); | ||
| 1012 | 998 | ||
| 1013 | return i; | 999 | return i; |
| 1014 | } | ||
| 1015 | } | ||
| 1016 | catch (Exception exception) | ||
| 1017 | { | ||
| 1018 | exception.printStackTrace (); | ||
| 1019 | return -1; | ||
| 1020 | } | ||
| 1021 | } | 1000 | } |
| 1022 | 1001 | ||
| 1023 | /* Return whether Emacs is directly permitted to access the | 1002 | /* Return whether Emacs is directly permitted to access the |
diff --git a/src/android.c b/src/android.c index 507ffc458d8..7a7eadc946a 100644 --- a/src/android.c +++ b/src/android.c | |||
| @@ -1632,7 +1632,7 @@ android_init_emacs_service (void) | |||
| 1632 | FIND_METHOD (reset_ic, "resetIC", | 1632 | FIND_METHOD (reset_ic, "resetIC", |
| 1633 | "(Lorg/gnu/emacs/EmacsWindow;I)V"); | 1633 | "(Lorg/gnu/emacs/EmacsWindow;I)V"); |
| 1634 | FIND_METHOD (open_content_uri, "openContentUri", | 1634 | FIND_METHOD (open_content_uri, "openContentUri", |
| 1635 | "([BZZZ)I"); | 1635 | "(Ljava/lang/String;ZZZ)I"); |
| 1636 | FIND_METHOD (check_content_uri, "checkContentUri", | 1636 | FIND_METHOD (check_content_uri, "checkContentUri", |
| 1637 | "(Ljava/lang/String;ZZ)Z"); | 1637 | "(Ljava/lang/String;ZZ)Z"); |
| 1638 | FIND_METHOD (query_battery, "queryBattery", "()[J"); | 1638 | FIND_METHOD (query_battery, "queryBattery", "()[J"); |
diff --git a/src/androidvfs.c b/src/androidvfs.c index 88ea345a298..9e65dd2b140 100644 --- a/src/androidvfs.c +++ b/src/androidvfs.c | |||
| @@ -3130,8 +3130,10 @@ android_authority_name (struct android_vnode *vnode, char *name, | |||
| 3130 | return NULL; | 3130 | return NULL; |
| 3131 | } | 3131 | } |
| 3132 | 3132 | ||
| 3133 | /* NAME must be a valid JNI string, so that it can be encoded | 3133 | /* If the URI is not a valid JNI string, return immediately. This |
| 3134 | properly. */ | 3134 | should not be possible, since /content file names are encoded |
| 3135 | into JNI strings at the naming stage; the check is performed | ||
| 3136 | only out of an abundance of caution. */ | ||
| 3135 | 3137 | ||
| 3136 | if (android_verify_jni_string (name)) | 3138 | if (android_verify_jni_string (name)) |
| 3137 | goto no_entry; | 3139 | goto no_entry; |
| @@ -3169,7 +3171,6 @@ android_authority_open (struct android_vnode *vnode, int flags, | |||
| 3169 | AAsset **asset) | 3171 | AAsset **asset) |
| 3170 | { | 3172 | { |
| 3171 | struct android_authority_vnode *vp; | 3173 | struct android_authority_vnode *vp; |
| 3172 | size_t length; | ||
| 3173 | jobject string; | 3174 | jobject string; |
| 3174 | int fd; | 3175 | int fd; |
| 3175 | JNIEnv *env; | 3176 | JNIEnv *env; |
| @@ -3189,22 +3190,11 @@ android_authority_open (struct android_vnode *vnode, int flags, | |||
| 3189 | feasible. */ | 3190 | feasible. */ |
| 3190 | env = android_java_env; | 3191 | env = android_java_env; |
| 3191 | 3192 | ||
| 3192 | /* Allocate a buffer to hold the file name. */ | 3193 | /* Allocate a JNI string to hold VP->uri. */ |
| 3193 | length = strlen (vp->uri); | 3194 | string = (*env)->NewStringUTF (env, vp->uri); |
| 3194 | string = (*env)->NewByteArray (env, length); | 3195 | android_exception_check (); |
| 3195 | if (!string) | ||
| 3196 | { | ||
| 3197 | (*env)->ExceptionClear (env); | ||
| 3198 | errno = ENOMEM; | ||
| 3199 | return -1; | ||
| 3200 | } | ||
| 3201 | |||
| 3202 | /* Copy the URI into this byte array. */ | ||
| 3203 | (*env)->SetByteArrayRegion (env, string, 0, length, | ||
| 3204 | (jbyte *) vp->uri); | ||
| 3205 | 3196 | ||
| 3206 | /* Try to open the file descriptor. */ | 3197 | /* Try to open the file descriptor. */ |
| 3207 | |||
| 3208 | fd = (*env)->CallNonvirtualIntMethod (env, emacs_service, | 3198 | fd = (*env)->CallNonvirtualIntMethod (env, emacs_service, |
| 3209 | service_class.class, | 3199 | service_class.class, |
| 3210 | service_class.open_content_uri, | 3200 | service_class.open_content_uri, |
| @@ -3215,13 +3205,7 @@ android_authority_open (struct android_vnode *vnode, int flags, | |||
| 3215 | (jboolean) !(mode & O_WRONLY), | 3205 | (jboolean) !(mode & O_WRONLY), |
| 3216 | (jboolean) ((mode & O_TRUNC) | 3206 | (jboolean) ((mode & O_TRUNC) |
| 3217 | != 0)); | 3207 | != 0)); |
| 3218 | if ((*env)->ExceptionCheck (env)) | 3208 | android_exception_check_1 (string); |
| 3219 | { | ||
| 3220 | (*env)->ExceptionClear (env); | ||
| 3221 | errno = ENOMEM; | ||
| 3222 | ANDROID_DELETE_LOCAL_REF (string); | ||
| 3223 | return -1; | ||
| 3224 | } | ||
| 3225 | 3209 | ||
| 3226 | /* If fd is -1, just assume that the file does not exist, | 3210 | /* If fd is -1, just assume that the file does not exist, |
| 3227 | and return -1 with errno set to ENOENT. */ | 3211 | and return -1 with errno set to ENOENT. */ |