From d4ea0e5ddd39134590d85ebf12d622e706fffdfe Mon Sep 17 00:00:00 2001 From: Po Lu Date: Fri, 10 May 2024 11:42:37 +0800 Subject: [PATCH] Remove redundant encoding of strings in androidvfs.c * java/org/gnu/emacs/EmacsService.java (getDocumentTrees): Accept PROVIDER as a String. * src/android.c (android_init_emacs_service): * src/androidvfs.c (android_saf_root_opendir): Adjust to match. (cherry picked from commit ea2b251ab2b2bc9a3d6f52a22408655be20de266) --- java/org/gnu/emacs/EmacsService.java | 17 +++++------------ src/android.c | 2 +- src/androidvfs.c | 20 ++++++++------------ 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index 1e5f72eed37..2dcaad16e50 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java @@ -1401,22 +1401,12 @@ public final class EmacsService extends Service otherwise. */ public String[] - getDocumentTrees (byte provider[]) + getDocumentTrees (String provider) { - String providerName; List treeList; List permissions; Uri uri; - try - { - providerName = new String (provider, "US-ASCII"); - } - catch (UnsupportedEncodingException exception) - { - return null; - } - permissions = resolver.getPersistedUriPermissions (); treeList = new ArrayList (); @@ -1425,7 +1415,7 @@ public final class EmacsService extends Service uri = permission.getUri (); if (DocumentsContract.isTreeUri (uri) - && uri.getAuthority ().equals (providerName) + && uri.getAuthority ().equals (provider) && permission.isReadPermission ()) /* Make sure the tree document ID is encoded. Refrain from encoding characters such as +:&?#, since they don't @@ -1435,6 +1425,9 @@ public final class EmacsService extends Service " +:&?#")); } + /* The empty string array that is ostensibly allocated to provide + the first argument provides just the type of the array to be + returned. */ return treeList.toArray (new String[0]); } diff --git a/src/android.c b/src/android.c index 0dd7702b301..d3b0bc21478 100644 --- a/src/android.c +++ b/src/android.c @@ -1659,7 +1659,7 @@ android_init_emacs_service (void) FIND_METHOD (request_directory_access, "requestDirectoryAccess", "()I"); FIND_METHOD (get_document_trees, "getDocumentTrees", - "([B)[Ljava/lang/String;"); + "(Ljava/lang/String;)[Ljava/lang/String;"); FIND_METHOD (document_id_from_name, "documentIdFromName", "(Ljava/lang/String;Ljava/lang/String;" "[Ljava/lang/String;)I"); diff --git a/src/androidvfs.c b/src/androidvfs.c index 284b1370549..004abd62518 100644 --- a/src/androidvfs.c +++ b/src/androidvfs.c @@ -4033,7 +4033,7 @@ android_saf_root_opendir (struct android_vnode *vnode) struct android_saf_root_vnode *vp; jobjectArray array; jmethodID method; - jbyteArray authority; + jstring authority; struct android_saf_root_vdir *dir; size_t length; @@ -4043,15 +4043,10 @@ android_saf_root_opendir (struct android_vnode *vnode) { /* Build a string containing the authority. */ length = strlen (vp->authority); - authority = (*android_java_env)->NewByteArray (android_java_env, - length); + authority = (*android_java_env)->NewStringUTF (android_java_env, + vp->authority); android_exception_check (); - /* Copy the authority name to that byte array. */ - (*android_java_env)->SetByteArrayRegion (android_java_env, - authority, 0, length, - (jbyte *) vp->authority); - /* Acquire a list of every tree provided by this authority. */ method = service_class.get_document_trees; @@ -6566,10 +6561,11 @@ static struct android_special_vnode special_vnodes[] = to CODING, and return a Lisp string with the data so produced. Calling this function creates an implicit assumption that - file-name-coding-system is compatible with utf-8-emacs, which is not - unacceptable as users with cause to modify file-name-coding-system - should be aware and prepared for consequences towards files stored on - different filesystems, including virtual ones. */ + `file-name-coding-system' is compatible with `utf-8-emacs', which is + not unacceptable as users with cause to modify + file-name-coding-system should be aware and prepared for adverse + consequences affecting files stored on different filesystems, + including virtual ones. */ static Lisp_Object android_vfs_convert_name (const char *name, Lisp_Object coding) -- 2.39.5