emacs-diffs
[Top][All Lists]
Advanced

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

feature/android b776feb7f27: Update Android port


From: Po Lu
Subject: feature/android b776feb7f27: Update Android port
Date: Mon, 13 Mar 2023 01:25:18 -0400 (EDT)

branch: feature/android
commit b776feb7f2737fb6b3fca05ae3b786dc67a2a9ae
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Update Android port
    
    * doc/emacs/android.texi (Android Startup): Document changes to
    emacsclient wrapper.
    * java/org/gnu/emacs/EmacsOpenActivity.java (EmacsOpenActivity)
    (startEmacsClient): Open EmacsActivity if the service is not
    running.
    * java/org/gnu/emacs/EmacsService.java (onCreate):
    * java/org/gnu/emacs/EmacsThread.java (EmacsThread, run): Pass
    any file to open to Emacs.
    * lisp/term/android-win.el (handle-args-function): Implement.
---
 doc/emacs/android.texi                    |  5 +++++
 java/org/gnu/emacs/EmacsOpenActivity.java | 15 +++++++++++++++
 java/org/gnu/emacs/EmacsService.java      |  7 +++++--
 java/org/gnu/emacs/EmacsThread.java       | 29 +++++++++++++++++++++++++----
 lisp/term/android-win.el                  |  8 ++++----
 5 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/doc/emacs/android.texi b/doc/emacs/android.texi
index d50acda7710..15415f12570 100644
--- a/doc/emacs/android.texi
+++ b/doc/emacs/android.texi
@@ -133,6 +133,11 @@ file, it invokes @command{emacsclient} with the options
 and the name of the file being opened.  Then, upon success, the focus
 is transferred to any open Emacs frame.
 
+  However, if Emacs is not running at the time the wrapper is opened,
+it starts Emacs and gives it the file to open as an argument.  Note
+that if that Emacs in turn does not start the Emacs server, subsequent
+attempts to open the file with the wrapper will fail.
+
 @cindex /content directory, android
   Some files are given to Emacs as ``content identifiers'', which the
 system provides access to outside the normal filesystem APIs.  Emacs
diff --git a/java/org/gnu/emacs/EmacsOpenActivity.java 
b/java/org/gnu/emacs/EmacsOpenActivity.java
index e8fb24d53d8..f402e25c7fb 100644
--- a/java/org/gnu/emacs/EmacsOpenActivity.java
+++ b/java/org/gnu/emacs/EmacsOpenActivity.java
@@ -72,6 +72,7 @@ public final class EmacsOpenActivity extends Activity
   DialogInterface.OnCancelListener
 {
   private static final String TAG = "EmacsOpenActivity";
+  public static String fileToOpen;
 
   private class EmacsClientThread extends Thread
   {
@@ -317,6 +318,20 @@ public final class EmacsOpenActivity extends Activity
     Process process;
     EmacsClientThread thread;
     File file;
+    Intent intent;
+
+    /* If the Emacs service is not running, then start Emacs and make
+       it open this file.  */
+
+    if (EmacsService.SERVICE == null)
+      {
+       fileToOpen = fileName;
+       intent = new Intent (EmacsOpenActivity.this,
+                            EmacsActivity.class);
+       finish ();
+       startActivity (intent);
+       return;
+      }
 
     libDir = EmacsService.getLibraryDirectory (this);
     builder = new ProcessBuilder (libDir + "/libemacsclient.so",
diff --git a/java/org/gnu/emacs/EmacsService.java 
b/java/org/gnu/emacs/EmacsService.java
index 9c48c56ca26..33436892caa 100644
--- a/java/org/gnu/emacs/EmacsService.java
+++ b/java/org/gnu/emacs/EmacsService.java
@@ -215,7 +215,8 @@ public final class EmacsService extends Service
        classPath = getApkFile ();
 
        Log.d (TAG, "Initializing Emacs, where filesDir = " + filesDir
-              + ", libDir = " + libDir + ", and classPath = " + classPath);
+              + ", libDir = " + libDir + ", and classPath = " + classPath
+              + "; fileToOpen = " + EmacsOpenActivity.fileToOpen);
 
        /* Start the thread that runs Emacs.  */
        thread = new EmacsThread (this, new Runnable () {
@@ -228,7 +229,9 @@ public final class EmacsService extends Service
                                          (float) pixelDensityY,
                                          classPath, EmacsService.this);
            }
-         }, needDashQ);
+         }, needDashQ,
+         /* If any file needs to be opened, open it now.  */
+         EmacsOpenActivity.fileToOpen);
        thread.start ();
       }
     catch (IOException exception)
diff --git a/java/org/gnu/emacs/EmacsThread.java 
b/java/org/gnu/emacs/EmacsThread.java
index 30484710651..d175fe332b5 100644
--- a/java/org/gnu/emacs/EmacsThread.java
+++ b/java/org/gnu/emacs/EmacsThread.java
@@ -20,24 +20,32 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 package org.gnu.emacs;
 
 import java.lang.Thread;
+import java.util.Arrays;
 
 import android.os.Build;
+import android.util.Log;
 
 public class EmacsThread extends Thread
 {
+  private static final String TAG = "EmacsThread";
+
   /* Whether or not Emacs should be started -Q.  */
   private boolean startDashQ;
 
   /* Runnable run to initialize Emacs.  */
   private Runnable paramsClosure;
 
+  /* Whether or not to open a file after starting Emacs.  */
+  private String fileToOpen;
+
   public
   EmacsThread (EmacsService service, Runnable paramsClosure,
-              boolean startDashQ)
+              boolean startDashQ, String fileToOpen)
   {
     super ("Emacs main thread");
     this.startDashQ = startDashQ;
     this.paramsClosure = paramsClosure;
+    this.fileToOpen = fileToOpen;
   }
 
   @Override
@@ -46,14 +54,27 @@ public class EmacsThread extends Thread
   {
     String args[];
 
-    if (!startDashQ)
-      args = new String[] { "libandroid-emacs.so", };
+    if (fileToOpen == null)
+      {
+       if (!startDashQ)
+         args = new String[] { "libandroid-emacs.so", };
+       else
+         args = new String[] { "libandroid-emacs.so", "-Q", };
+      }
     else
-      args = new String[] { "libandroid-emacs.so", "-Q", };
+      {
+       if (!startDashQ)
+         args = new String[] { "libandroid-emacs.so",
+                               fileToOpen, };
+       else
+         args = new String[] { "libandroid-emacs.so", "-Q",
+                               fileToOpen, };
+      }
 
     paramsClosure.run ();
 
     /* Run the native code now.  */
+    Log.d (TAG, "run: " + Arrays.toString (args));
     EmacsNative.initEmacs (args, EmacsApplication.dumpFileName,
                           Build.VERSION.SDK_INT);
   }
diff --git a/lisp/term/android-win.el b/lisp/term/android-win.el
index 94fe4d6489b..fc393681ac4 100644
--- a/lisp/term/android-win.el
+++ b/lisp/term/android-win.el
@@ -56,10 +56,10 @@ DISPLAY is ignored on Android."
 (cl-defmethod frame-creation-function (params &context (window-system android))
   (x-create-frame-with-faces params))
 
-(cl-defmethod handle-args-function (_ignored &context (window-system android))
-  ;; Nothing to do here: Android has no command line to provide
-  ;; arguments on.
-  (ignore))
+(cl-defmethod handle-args-function (args &context (window-system android))
+  ;; Android has no command line to provide arguments on.
+  ;; However, call x-handle-args to handle file name args.
+  (x-handle-args args))
 
 
 ;;; Selection support.



reply via email to

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