emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master e7d1b12878e: Make miscellaneous improvements to the Android port


From: Po Lu
Subject: master e7d1b12878e: Make miscellaneous improvements to the Android port
Date: Sat, 10 Feb 2024 02:06:28 -0500 (EST)

branch: master
commit e7d1b12878ed83ad8c6995d8443f3367750ff0c9
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    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.
---
 java/org/gnu/emacs/EmacsActivity.java |  4 +++
 java/org/gnu/emacs/EmacsService.java  | 67 +----------------------------------
 src/android.c                         | 23 ++++++------
 3 files changed, 16 insertions(+), 78 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
       }
 
     super.onCreate (savedInstanceState);
+
+    /* Call `onWindowFocusChanged' to read the focus state, which fails
+       to be called after an activity is recreated.  */
+    onWindowFocusChanged (false);
   }
 
   @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
     EmacsDrawPoint.perform (drawable, gc, x, y);
   }
 
-  public void
-  clearWindow (EmacsWindow window)
-  {
-    checkEmacsThread ();
-    window.clearWindow ();
-  }
-
-  public void
-  clearArea (EmacsWindow window, int x, int y, int width,
-            int height)
-  {
-    checkEmacsThread ();
-    window.clearArea (x, y, width, height);
-  }
-
   @SuppressWarnings ("deprecation")
   public void
   ringBell (int duration)
@@ -926,48 +911,6 @@ public final class EmacsService extends Service
 
   /* Content provider functions.  */
 
-  /* Return a ContentResolver capable of accessing as many files as
-     possible, namely the content resolver of the last selected
-     activity if available: only they posses the rights to access drag
-     and drop files.  */
-
-  public ContentResolver
-  getUsefulContentResolver ()
-  {
-    EmacsActivity activity;
-
-    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
-      /* Since the system predates drag and drop, return this resolver
-        to avoid any unforeseen difficulties.  */
-      return resolver;
-
-    activity = EmacsActivity.lastFocusedActivity;
-    if (activity == null)
-      return resolver;
-
-    return activity.getContentResolver ();
-  }
-
-  /* Return a context whose ContentResolver is granted access to most
-     files, as in `getUsefulContentResolver'.  */
-
-  public Context
-  getContentResolverContext ()
-  {
-    EmacsActivity activity;
-
-    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
-      /* Since the system predates drag and drop, return this resolver
-        to avoid any unforeseen difficulties.  */
-      return this;
-
-    activity = EmacsActivity.lastFocusedActivity;
-    if (activity == null)
-      return this;
-
-    return activity;
-  }
-
   /* Open a content URI described by the bytes BYTES, a non-terminated
      string; make it writable if WRITABLE, and readable if READABLE.
      Truncate the file if TRUNCATE.
@@ -981,9 +924,6 @@ public final class EmacsService extends Service
     String name, mode;
     ParcelFileDescriptor fd;
     int i;
-    ContentResolver resolver;
-
-    resolver = getUsefulContentResolver ();
 
     /* Figure out the file access mode.  */
 
@@ -1045,12 +985,8 @@ public final class EmacsService extends Service
     ParcelFileDescriptor fd;
     Uri uri;
     int rc, flags;
-    Context context;
-    ContentResolver resolver;
     ParcelFileDescriptor descriptor;
 
-    context = getContentResolverContext ();
-
     uri = Uri.parse (name);
     flags = 0;
 
@@ -1060,7 +996,7 @@ public final class EmacsService extends Service
     if (writable)
       flags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
 
-    rc = context.checkCallingUriPermission (uri, flags);
+    rc = checkCallingUriPermission (uri, flags);
 
     if (rc == PackageManager.PERMISSION_GRANTED)
       return true;
@@ -1074,7 +1010,6 @@ public final class EmacsService extends Service
 
     try
       {
-       resolver = context.getContentResolver ();
         descriptor = resolver.openFileDescriptor (uri, "r");
        return true;
       }
diff --git a/src/android.c b/src/android.c
index 46f4dcd5546..4d56df1da3f 100644
--- a/src/android.c
+++ b/src/android.c
@@ -113,6 +113,8 @@ struct android_emacs_window
   jmethodID define_cursor;
   jmethodID damage_rect;
   jmethodID recreate_activity;
+  jmethodID clear_window;
+  jmethodID clear_area;
 };
 
 struct android_emacs_cursor
@@ -1605,10 +1607,6 @@ android_init_emacs_service (void)
   FIND_METHOD (draw_point, "drawPoint",
               "(Lorg/gnu/emacs/EmacsDrawable;"
               "Lorg/gnu/emacs/EmacsGC;II)V");
-  FIND_METHOD (clear_window, "clearWindow",
-              "(Lorg/gnu/emacs/EmacsWindow;)V");
-  FIND_METHOD (clear_area, "clearArea",
-              "(Lorg/gnu/emacs/EmacsWindow;IIII)V");
   FIND_METHOD (ring_bell, "ringBell", "(I)V");
   FIND_METHOD (query_tree, "queryTree",
               "(Lorg/gnu/emacs/EmacsWindow;)[S");
@@ -1832,6 +1830,8 @@ android_init_emacs_window (void)
      android_damage_window.  */
   FIND_METHOD (damage_rect, "damageRect", "(IIII)V");
   FIND_METHOD (recreate_activity, "recreateActivity", "()V");
+  FIND_METHOD (clear_window, "clearWindow", "()V");
+  FIND_METHOD (clear_area, "clearArea", "(IIII)V");
 #undef FIND_METHOD
 }
 
@@ -3431,10 +3431,9 @@ android_clear_window (android_window handle)
   window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
 
   (*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
-                                                emacs_service,
-                                                service_class.class,
-                                                service_class.clear_window,
-                                                window);
+                                                window,
+                                                window_class.class,
+                                                window_class.clear_window);
   android_exception_check ();
 }
 
@@ -4745,10 +4744,10 @@ android_clear_area (android_window handle, int x, int y,
   window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
 
   (*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
-                                                emacs_service,
-                                                service_class.class,
-                                                service_class.clear_area,
-                                                window, (jint) x, (jint) y,
+                                                window,
+                                                window_class.class,
+                                                window_class.clear_area,
+                                                (jint) x, (jint) y,
                                                 (jint) width, (jint) height);
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]