aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorPo Lu2024-02-10 15:02:39 +0800
committerPo Lu2024-02-10 15:06:01 +0800
commite7d1b12878ed83ad8c6995d8443f3367750ff0c9 (patch)
tree9fe5c44c885358699f42eff0524c768306f77b20 /java
parent6568a9a0099e7745bfd142a0fd16b4d7215c0250 (diff)
downloademacs-e7d1b12878ed83ad8c6995d8443f3367750ff0c9.tar.gz
emacs-e7d1b12878ed83ad8c6995d8443f3367750ff0c9.zip
Make miscellaneous improvements to the Android port
* java/org/gnu/emacs/EmacsActivity.java (onCreate): Deal with omitted calls to onWindowFocusChanged after activity recreation. * java/org/gnu/emacs/EmacsService.java (clearWindow, clearArea): Delete redundant wrapper functions. (getUsefulContentResolver, getContentResolverContext): Delete functions. (openContentUri, checkContentUri): Stop searching for an activity content resolver, as that's actually not necessary. * src/android.c (android_init_emacs_service) (android_init_emacs_window, android_clear_window) (android_clear_area): Adjust to match.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsActivity.java4
-rw-r--r--java/org/gnu/emacs/EmacsService.java67
2 files changed, 5 insertions, 66 deletions
diff --git a/java/org/gnu/emacs/EmacsActivity.java b/java/org/gnu/emacs/EmacsActivity.java
index b821694b18a..66a1e41d84c 100644
--- a/java/org/gnu/emacs/EmacsActivity.java
+++ b/java/org/gnu/emacs/EmacsActivity.java
@@ -247,6 +247,10 @@ public class EmacsActivity extends Activity
247 } 247 }
248 248
249 super.onCreate (savedInstanceState); 249 super.onCreate (savedInstanceState);
250
251 /* Call `onWindowFocusChanged' to read the focus state, which fails
252 to be called after an activity is recreated. */
253 onWindowFocusChanged (false);
250 } 254 }
251 255
252 @Override 256 @Override
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java
index b65b10b9528..d17ba597d8e 100644
--- a/java/org/gnu/emacs/EmacsService.java
+++ b/java/org/gnu/emacs/EmacsService.java
@@ -449,21 +449,6 @@ public final class EmacsService extends Service
449 EmacsDrawPoint.perform (drawable, gc, x, y); 449 EmacsDrawPoint.perform (drawable, gc, x, y);
450 } 450 }
451 451
452 public void
453 clearWindow (EmacsWindow window)
454 {
455 checkEmacsThread ();
456 window.clearWindow ();
457 }
458
459 public void
460 clearArea (EmacsWindow window, int x, int y, int width,
461 int height)
462 {
463 checkEmacsThread ();
464 window.clearArea (x, y, width, height);
465 }
466
467 @SuppressWarnings ("deprecation") 452 @SuppressWarnings ("deprecation")
468 public void 453 public void
469 ringBell (int duration) 454 ringBell (int duration)
@@ -926,48 +911,6 @@ public final class EmacsService extends Service
926 911
927 /* Content provider functions. */ 912 /* Content provider functions. */
928 913
929 /* Return a ContentResolver capable of accessing as many files as
930 possible, namely the content resolver of the last selected
931 activity if available: only they posses the rights to access drag
932 and drop files. */
933
934 public ContentResolver
935 getUsefulContentResolver ()
936 {
937 EmacsActivity activity;
938
939 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
940 /* Since the system predates drag and drop, return this resolver
941 to avoid any unforeseen difficulties. */
942 return resolver;
943
944 activity = EmacsActivity.lastFocusedActivity;
945 if (activity == null)
946 return resolver;
947
948 return activity.getContentResolver ();
949 }
950
951 /* Return a context whose ContentResolver is granted access to most
952 files, as in `getUsefulContentResolver'. */
953
954 public Context
955 getContentResolverContext ()
956 {
957 EmacsActivity activity;
958
959 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
960 /* Since the system predates drag and drop, return this resolver
961 to avoid any unforeseen difficulties. */
962 return this;
963
964 activity = EmacsActivity.lastFocusedActivity;
965 if (activity == null)
966 return this;
967
968 return activity;
969 }
970
971 /* Open a content URI described by the bytes BYTES, a non-terminated 914 /* Open a content URI described by the bytes BYTES, a non-terminated
972 string; make it writable if WRITABLE, and readable if READABLE. 915 string; make it writable if WRITABLE, and readable if READABLE.
973 Truncate the file if TRUNCATE. 916 Truncate the file if TRUNCATE.
@@ -981,9 +924,6 @@ public final class EmacsService extends Service
981 String name, mode; 924 String name, mode;
982 ParcelFileDescriptor fd; 925 ParcelFileDescriptor fd;
983 int i; 926 int i;
984 ContentResolver resolver;
985
986 resolver = getUsefulContentResolver ();
987 927
988 /* Figure out the file access mode. */ 928 /* Figure out the file access mode. */
989 929
@@ -1045,12 +985,8 @@ public final class EmacsService extends Service
1045 ParcelFileDescriptor fd; 985 ParcelFileDescriptor fd;
1046 Uri uri; 986 Uri uri;
1047 int rc, flags; 987 int rc, flags;
1048 Context context;
1049 ContentResolver resolver;
1050 ParcelFileDescriptor descriptor; 988 ParcelFileDescriptor descriptor;
1051 989
1052 context = getContentResolverContext ();
1053
1054 uri = Uri.parse (name); 990 uri = Uri.parse (name);
1055 flags = 0; 991 flags = 0;
1056 992
@@ -1060,7 +996,7 @@ public final class EmacsService extends Service
1060 if (writable) 996 if (writable)
1061 flags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION; 997 flags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
1062 998
1063 rc = context.checkCallingUriPermission (uri, flags); 999 rc = checkCallingUriPermission (uri, flags);
1064 1000
1065 if (rc == PackageManager.PERMISSION_GRANTED) 1001 if (rc == PackageManager.PERMISSION_GRANTED)
1066 return true; 1002 return true;
@@ -1074,7 +1010,6 @@ public final class EmacsService extends Service
1074 1010
1075 try 1011 try
1076 { 1012 {
1077 resolver = context.getContentResolver ();
1078 descriptor = resolver.openFileDescriptor (uri, "r"); 1013 descriptor = resolver.openFileDescriptor (uri, "r");
1079 return true; 1014 return true;
1080 } 1015 }