1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 14:30:50 -08:00

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.
This commit is contained in:
Po Lu 2023-08-14 13:15:08 +08:00
parent 3895f88233
commit 9fb00904f9
3 changed files with 51 additions and 89 deletions

View file

@ -960,44 +960,30 @@ public final class EmacsService extends Service
}
}
/* Return whether Emacs is directly permitted to access the
content:// URI NAME. This is not a suitable test for files which
Emacs can access by virtue of their containing document
trees. */
public boolean
checkContentUri (byte[] string, boolean readable, boolean writable)
checkContentUri (String name, boolean readable, boolean writable)
{
String mode, name;
String mode;
ParcelFileDescriptor fd;
Uri uri;
int rc, flags;
/* Decode this into a URI. */
uri = Uri.parse (name);
flags = 0;
try
{
/* The usual file name encoding question rears its ugly head
again. */
name = new String (string, "UTF-8");
}
catch (UnsupportedEncodingException exception)
{
name = null;
throw new RuntimeException (exception);
}
mode = "r";
if (readable)
flags |= Intent.FLAG_GRANT_READ_URI_PERMISSION;
if (writable)
mode += "w";
flags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
try
{
fd = resolver.openFileDescriptor (Uri.parse (name), mode);
fd.close ();
return true;
}
catch (Exception exception)
{
/* Fall through. */
}
return false;
rc = checkCallingUriPermission (uri, flags);
return rc == PackageManager.PERMISSION_GRANTED;
}
/* Build a content file name for URI.