diff options
author | Po Lu <luangruo@yahoo.com> | 2024-04-05 15:04:09 +0800 |
---|---|---|
committer | Po Lu <luangruo@yahoo.com> | 2024-04-05 15:04:09 +0800 |
commit | aad63f935f8737598835612b53bc3b53c124661f (patch) | |
tree | a1a4c7d52a444b095facb01ae49ad0e15bbd2e38 /src/androidvfs.c | |
parent | 2637b642d482790bef7486d059f04b60920f1256 (diff) | |
download | emacs-aad63f935f8737598835612b53bc3b53c124661f.tar.gz |
Enable relinquishing access to Android content directories
* doc/emacs/android.texi (Android Document Providers): Document
new command.
* java/org/gnu/emacs/EmacsService.java (relinquishUriRights):
New function.
* src/Makefile.in (SOME_MACHINE_OBJECTS): Add androidvfs.c.
* src/android.c (android_init_emacs_service): Link to new
function.
* src/android.h (struct android_emacs_service)
<relinquish_uri_rights>: New field.
* src/androidfns.c:
* src/androidvfs.c (android_saf_tree_name)
(android_saf_tree_opendir): Minor adjustments to commentary.
(Fandroid_relinquish_directory_access): New function.
(syms_of_androidvfs): Define new subr.
Diffstat (limited to 'src/androidvfs.c')
-rw-r--r-- | src/androidvfs.c | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/src/androidvfs.c b/src/androidvfs.c index 2e23ed40cf5..88ea345a298 100644 --- a/src/androidvfs.c +++ b/src/androidvfs.c @@ -4997,7 +4997,7 @@ android_saf_tree_name (struct android_vnode *vnode, char *name, root.vnode.type = ANDROID_VNODE_SAF_ROOT; root.vnode.flags = 0; - /* Find the authority from the URI. */ + /* Derive the authority from the URI. */ fill = (char *) vp->tree_uri; @@ -5647,7 +5647,7 @@ android_saf_tree_opendir (struct android_vnode *vnode) dir->vdir.closedir = android_saf_tree_closedir; dir->vdir.dirfd = android_saf_tree_dirfd; - /* Find the authority from the URI. */ + /* Derive the authority from the URI. */ fill = (char *) vp->tree_uri; @@ -7816,8 +7816,58 @@ android_closedir (struct android_vdir *dirp) +DEFUN ("android-relinquish-directory-access", + Fandroid_relinquish_directory_access, + Sandroid_relinquish_directory_access, 1, 1, + "DDirectory: ", + doc: /* Relinquish access to the provided directory. +DIRECTORY must be an inferior directory to a subdirectory of +/content/storage. Once the command completes, the parent of DIRECTORY +below that subdirectory from will cease to appear there, but no files +will be removed. */) + (Lisp_Object file) +{ + struct android_vnode *vp; + struct android_saf_tree_vnode *saf_tree; + jstring string; + jmethodID method; + + if (android_get_current_api_level () < 21) + error ("Emacs can only access or relinquish application storage on" + " Android 5.0 and later"); + + if (!android_init_gui) + return Qnil; + + file = ENCODE_FILE (Fexpand_file_name (file, Qnil)); + vp = android_name_file (SSDATA (file)); + + if (vp->type != ANDROID_VNODE_SAF_TREE) + { + (*vp->ops->close) (vp); + signal_error ("Access to this directory cannot be relinquished", + file); + } + + saf_tree = (struct android_saf_tree_vnode *) vp; + string = android_build_jstring (saf_tree->tree_uri); + method = service_class.relinquish_uri_rights; + (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, + emacs_service, + service_class.class, + method, string); + (*vp->ops->close) (vp); + android_exception_check_1 (string); + ANDROID_DELETE_LOCAL_REF (string); + return Qnil; +} + + + void syms_of_androidvfs (void) { DEFSYM (Qandroid_jni, "android-jni"); + + defsubr (&Sandroid_relinquish_directory_access); } |