diff options
| author | Po Lu | 2023-11-18 14:15:55 +0800 |
|---|---|---|
| committer | Po Lu | 2023-11-18 14:15:55 +0800 |
| commit | 669e754f5bdc9f9130a68eec6966babe9a85ecae (patch) | |
| tree | 718d7fe3517a79ae69ed3380cd86e0f8c4716621 /src | |
| parent | 05213345c04d4572afec46b99a58d206a111c846 (diff) | |
| download | emacs-669e754f5bdc9f9130a68eec6966babe9a85ecae.tar.gz emacs-669e754f5bdc9f9130a68eec6966babe9a85ecae.zip | |
Offer to grant storage permissions if absent
* java/org/gnu/emacs/EmacsService.java (externalStorageAvailable)
(requestStorageAccess23, requestStorageAccess30)
(requestStorageAccess): New functions.
* lisp/startup.el (fancy-startup-tail, normal-splash-screen):
Call android-win functions for inserting the new storage
permission notice.
* lisp/term/android-win.el
(android-display-storage-permission-popup)
(android-after-splash-screen): New functions.
* src/android.c (android_init_emacs_service): Link to new Java
functions.
(android_external_storage_available_p)
(android_request_storage_access): New functions.
* src/android.h: Update prototypes.
* src/androidfns.c (Fandroid_external_storage_available_p)
(Fandroid_request_storage_access): New functions.
(syms_of_androidfns): Register new subrs.
Diffstat (limited to 'src')
| -rw-r--r-- | src/android.c | 55 | ||||
| -rw-r--r-- | src/android.h | 4 | ||||
| -rw-r--r-- | src/androidfns.c | 38 |
3 files changed, 97 insertions, 0 deletions
diff --git a/src/android.c b/src/android.c index e116426ca05..7ca5eab817c 100644 --- a/src/android.c +++ b/src/android.c | |||
| @@ -1628,6 +1628,10 @@ android_init_emacs_service (void) | |||
| 1628 | "Ljava/lang/String;)Ljava/lang/String;"); | 1628 | "Ljava/lang/String;)Ljava/lang/String;"); |
| 1629 | FIND_METHOD (valid_authority, "validAuthority", | 1629 | FIND_METHOD (valid_authority, "validAuthority", |
| 1630 | "(Ljava/lang/String;)Z"); | 1630 | "(Ljava/lang/String;)Z"); |
| 1631 | FIND_METHOD (external_storage_available, | ||
| 1632 | "externalStorageAvailable", "()Z"); | ||
| 1633 | FIND_METHOD (request_storage_access, | ||
| 1634 | "requestStorageAccess", "()V"); | ||
| 1631 | #undef FIND_METHOD | 1635 | #undef FIND_METHOD |
| 1632 | } | 1636 | } |
| 1633 | 1637 | ||
| @@ -6558,6 +6562,57 @@ android_request_directory_access (void) | |||
| 6558 | return rc; | 6562 | return rc; |
| 6559 | } | 6563 | } |
| 6560 | 6564 | ||
| 6565 | /* Return whether Emacs is entitled to access external storage. | ||
| 6566 | |||
| 6567 | On Android 5.1 and earlier, such permissions as are declared within | ||
| 6568 | an application's manifest are granted during installation and are | ||
| 6569 | irrevocable. | ||
| 6570 | |||
| 6571 | On Android 6.0 through Android 10.0, the right to read external | ||
| 6572 | storage is a regular permission granted from the Permissions | ||
| 6573 | panel. | ||
| 6574 | |||
| 6575 | On Android 11.0 and later, that right must be granted through an | ||
| 6576 | independent ``Special App Access'' settings panel. */ | ||
| 6577 | |||
| 6578 | bool | ||
| 6579 | android_external_storage_available_p (void) | ||
| 6580 | { | ||
| 6581 | jboolean rc; | ||
| 6582 | jmethodID method; | ||
| 6583 | |||
| 6584 | if (android_api_level <= 22) /* LOLLIPOP_MR1 */ | ||
| 6585 | return true; | ||
| 6586 | |||
| 6587 | method = service_class.external_storage_available; | ||
| 6588 | rc = (*android_java_env)->CallNonvirtualBooleanMethod (android_java_env, | ||
| 6589 | emacs_service, | ||
| 6590 | service_class.class, | ||
| 6591 | method); | ||
| 6592 | android_exception_check (); | ||
| 6593 | |||
| 6594 | return rc; | ||
| 6595 | } | ||
| 6596 | |||
| 6597 | /* Display a dialog from which the aforementioned rights can be | ||
| 6598 | granted. */ | ||
| 6599 | |||
| 6600 | void | ||
| 6601 | android_request_storage_access (void) | ||
| 6602 | { | ||
| 6603 | jmethodID method; | ||
| 6604 | |||
| 6605 | if (android_api_level <= 22) /* LOLLIPOP_MR1 */ | ||
| 6606 | return; | ||
| 6607 | |||
| 6608 | method = service_class.request_storage_access; | ||
| 6609 | (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, | ||
| 6610 | emacs_service, | ||
| 6611 | service_class.class, | ||
| 6612 | method); | ||
| 6613 | android_exception_check (); | ||
| 6614 | } | ||
| 6615 | |||
| 6561 | 6616 | ||
| 6562 | 6617 | ||
| 6563 | /* The thread from which a query against a thread is currently being | 6618 | /* The thread from which a query against a thread is currently being |
diff --git a/src/android.h b/src/android.h index 28d9d25930e..12f9472836f 100644 --- a/src/android.h +++ b/src/android.h | |||
| @@ -123,6 +123,8 @@ extern void android_wait_event (void); | |||
| 123 | extern void android_toggle_on_screen_keyboard (android_window, bool); | 123 | extern void android_toggle_on_screen_keyboard (android_window, bool); |
| 124 | extern _Noreturn void android_restart_emacs (void); | 124 | extern _Noreturn void android_restart_emacs (void); |
| 125 | extern int android_request_directory_access (void); | 125 | extern int android_request_directory_access (void); |
| 126 | extern bool android_external_storage_available_p (void); | ||
| 127 | extern void android_request_storage_access (void); | ||
| 126 | extern int android_get_current_api_level (void) | 128 | extern int android_get_current_api_level (void) |
| 127 | __attribute__ ((pure)); | 129 | __attribute__ ((pure)); |
| 128 | 130 | ||
| @@ -289,6 +291,8 @@ struct android_emacs_service | |||
| 289 | jmethodID rename_document; | 291 | jmethodID rename_document; |
| 290 | jmethodID move_document; | 292 | jmethodID move_document; |
| 291 | jmethodID valid_authority; | 293 | jmethodID valid_authority; |
| 294 | jmethodID external_storage_available; | ||
| 295 | jmethodID request_storage_access; | ||
| 292 | }; | 296 | }; |
| 293 | 297 | ||
| 294 | extern JNIEnv *android_java_env; | 298 | extern JNIEnv *android_java_env; |
diff --git a/src/androidfns.c b/src/androidfns.c index 772a4f51e78..785587d9282 100644 --- a/src/androidfns.c +++ b/src/androidfns.c | |||
| @@ -3096,6 +3096,42 @@ within the directory `/content/storage'. */) | |||
| 3096 | 3096 | ||
| 3097 | 3097 | ||
| 3098 | 3098 | ||
| 3099 | /* Functions concerning storage permissions. */ | ||
| 3100 | |||
| 3101 | DEFUN ("android-external-storage-available-p", | ||
| 3102 | Fandroid_external_storage_available_p, | ||
| 3103 | Sandroid_external_storage_available_p, 0, 0, 0, | ||
| 3104 | doc: /* Return whether Emacs is entitled to access external storage. | ||
| 3105 | Return nil if the requisite permissions for external storage access | ||
| 3106 | have not been granted to Emacs, t otherwise. Such permissions can be | ||
| 3107 | requested by means of the `android-request-storage-access' | ||
| 3108 | command. | ||
| 3109 | |||
| 3110 | External storage on Android encompasses the `/sdcard' and | ||
| 3111 | `/storage/emulated' directories, access to which is denied to programs | ||
| 3112 | absent these permissions. */) | ||
| 3113 | (void) | ||
| 3114 | { | ||
| 3115 | return android_external_storage_available_p () ? Qt : Qnil; | ||
| 3116 | } | ||
| 3117 | |||
| 3118 | DEFUN ("android-request-storage-access", Fandroid_request_storage_access, | ||
| 3119 | Sandroid_request_storage_access, 0, 0, "", | ||
| 3120 | doc: /* Request rights to access external storage. | ||
| 3121 | |||
| 3122 | Return nil whether access is accorded or not, immediately subsequent | ||
| 3123 | to displaying the permissions request dialog. | ||
| 3124 | |||
| 3125 | `android-external-storage-available-p' (which see) ascertains if Emacs | ||
| 3126 | has received such rights. */) | ||
| 3127 | (void) | ||
| 3128 | { | ||
| 3129 | android_request_storage_access (); | ||
| 3130 | return Qnil; | ||
| 3131 | } | ||
| 3132 | |||
| 3133 | |||
| 3134 | |||
| 3099 | /* Miscellaneous input method related stuff. */ | 3135 | /* Miscellaneous input method related stuff. */ |
| 3100 | 3136 | ||
| 3101 | /* Report X, Y, by the phys cursor width and height as the cursor | 3137 | /* Report X, Y, by the phys cursor width and height as the cursor |
| @@ -3302,6 +3338,8 @@ bell being rung. */); | |||
| 3302 | #ifndef ANDROID_STUBIFY | 3338 | #ifndef ANDROID_STUBIFY |
| 3303 | defsubr (&Sandroid_query_battery); | 3339 | defsubr (&Sandroid_query_battery); |
| 3304 | defsubr (&Sandroid_request_directory_access); | 3340 | defsubr (&Sandroid_request_directory_access); |
| 3341 | defsubr (&Sandroid_external_storage_available_p); | ||
| 3342 | defsubr (&Sandroid_request_storage_access); | ||
| 3305 | 3343 | ||
| 3306 | tip_timer = Qnil; | 3344 | tip_timer = Qnil; |
| 3307 | staticpro (&tip_timer); | 3345 | staticpro (&tip_timer); |