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/android.c | |
| 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/android.c')
| -rw-r--r-- | src/android.c | 55 |
1 files changed, 55 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 |