aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorPo Lu2023-08-14 13:15:08 +0800
committerPo Lu2023-08-14 13:15:08 +0800
commit9fb00904f959a7e94cf992acb3a96e78a05e719c (patch)
tree9b5d11af74a58b42066f3795da87389de1b4a011 /java
parent3895f882337ade7744cf7964d9bab5d79d4aa059 (diff)
downloademacs-9fb00904f959a7e94cf992acb3a96e78a05e719c.tar.gz
emacs-9fb00904f959a7e94cf992acb3a96e78a05e719c.zip
Improve efficiency of checking for access to authority documents
* java/org/gnu/emacs/EmacsService.java (checkContentUri): Take a string instead of a byte array. Then, use checkCallingUriPermission, in lieu of opening the file. * src/android.c (android_check_content_access): Delete unused function. (android_init_emacs_service): Adjust for changes to checkContentUri's signature. * src/androidvfs.c (android_get_content_name): Return the file name in a new buffer. (android_check_content_access): Adjust correspondingly. (android_authority_name): Verify NAME is a valid JNI string.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsService.java46
1 files changed, 16 insertions, 30 deletions
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java
index cee823abc83..19ce67c59b7 100644
--- a/java/org/gnu/emacs/EmacsService.java
+++ b/java/org/gnu/emacs/EmacsService.java
@@ -960,44 +960,30 @@ public final class EmacsService extends Service
960 } 960 }
961 } 961 }
962 962
963 /* Return whether Emacs is directly permitted to access the
964 content:// URI NAME. This is not a suitable test for files which
965 Emacs can access by virtue of their containing document
966 trees. */
967
963 public boolean 968 public boolean
964 checkContentUri (byte[] string, boolean readable, boolean writable) 969 checkContentUri (String name, boolean readable, boolean writable)
965 { 970 {
966 String mode, name; 971 String mode;
967 ParcelFileDescriptor fd; 972 ParcelFileDescriptor fd;
973 Uri uri;
974 int rc, flags;
968 975
969 /* Decode this into a URI. */ 976 uri = Uri.parse (name);
970 977 flags = 0;
971 try
972 {
973 /* The usual file name encoding question rears its ugly head
974 again. */
975 name = new String (string, "UTF-8");
976 }
977 catch (UnsupportedEncodingException exception)
978 {
979 name = null;
980 throw new RuntimeException (exception);
981 }
982 978
983 mode = "r"; 979 if (readable)
980 flags |= Intent.FLAG_GRANT_READ_URI_PERMISSION;
984 981
985 if (writable) 982 if (writable)
986 mode += "w"; 983 flags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
987
988 try
989 {
990 fd = resolver.openFileDescriptor (Uri.parse (name), mode);
991 fd.close ();
992 984
993 return true; 985 rc = checkCallingUriPermission (uri, flags);
994 } 986 return rc == PackageManager.PERMISSION_GRANTED;
995 catch (Exception exception)
996 {
997 /* Fall through. */
998 }
999
1000 return false;
1001 } 987 }
1002 988
1003 /* Build a content file name for URI. 989 /* Build a content file name for URI.