aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2023-03-13 13:25:02 +0800
committerPo Lu2023-03-13 13:25:02 +0800
commitb776feb7f2737fb6b3fca05ae3b786dc67a2a9ae (patch)
treebd584cbbcfb65de14c1f612c6bac42731c7d6cb9
parentc3524b15aa77b309f325fcb806fe9e9c91c4e99e (diff)
downloademacs-b776feb7f2737fb6b3fca05ae3b786dc67a2a9ae.tar.gz
emacs-b776feb7f2737fb6b3fca05ae3b786dc67a2a9ae.zip
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.
-rw-r--r--doc/emacs/android.texi5
-rw-r--r--java/org/gnu/emacs/EmacsOpenActivity.java15
-rw-r--r--java/org/gnu/emacs/EmacsService.java7
-rw-r--r--java/org/gnu/emacs/EmacsThread.java29
-rw-r--r--lisp/term/android-win.el8
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
133and the name of the file being opened. Then, upon success, the focus 133and the name of the file being opened. Then, upon success, the focus
134is transferred to any open Emacs frame. 134is transferred to any open Emacs frame.
135 135
136 However, if Emacs is not running at the time the wrapper is opened,
137it starts Emacs and gives it the file to open as an argument. Note
138that if that Emacs in turn does not start the Emacs server, subsequent
139attempts to open the file with the wrapper will fail.
140
136@cindex /content directory, android 141@cindex /content directory, android
137 Some files are given to Emacs as ``content identifiers'', which the 142 Some files are given to Emacs as ``content identifiers'', which the
138system provides access to outside the normal filesystem APIs. Emacs 143system 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
72 DialogInterface.OnCancelListener 72 DialogInterface.OnCancelListener
73{ 73{
74 private static final String TAG = "EmacsOpenActivity"; 74 private static final String TAG = "EmacsOpenActivity";
75 public static String fileToOpen;
75 76
76 private class EmacsClientThread extends Thread 77 private class EmacsClientThread extends Thread
77 { 78 {
@@ -317,6 +318,20 @@ public final class EmacsOpenActivity extends Activity
317 Process process; 318 Process process;
318 EmacsClientThread thread; 319 EmacsClientThread thread;
319 File file; 320 File file;
321 Intent intent;
322
323 /* If the Emacs service is not running, then start Emacs and make
324 it open this file. */
325
326 if (EmacsService.SERVICE == null)
327 {
328 fileToOpen = fileName;
329 intent = new Intent (EmacsOpenActivity.this,
330 EmacsActivity.class);
331 finish ();
332 startActivity (intent);
333 return;
334 }
320 335
321 libDir = EmacsService.getLibraryDirectory (this); 336 libDir = EmacsService.getLibraryDirectory (this);
322 builder = new ProcessBuilder (libDir + "/libemacsclient.so", 337 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
215 classPath = getApkFile (); 215 classPath = getApkFile ();
216 216
217 Log.d (TAG, "Initializing Emacs, where filesDir = " + filesDir 217 Log.d (TAG, "Initializing Emacs, where filesDir = " + filesDir
218 + ", libDir = " + libDir + ", and classPath = " + classPath); 218 + ", libDir = " + libDir + ", and classPath = " + classPath
219 + "; fileToOpen = " + EmacsOpenActivity.fileToOpen);
219 220
220 /* Start the thread that runs Emacs. */ 221 /* Start the thread that runs Emacs. */
221 thread = new EmacsThread (this, new Runnable () { 222 thread = new EmacsThread (this, new Runnable () {
@@ -228,7 +229,9 @@ public final class EmacsService extends Service
228 (float) pixelDensityY, 229 (float) pixelDensityY,
229 classPath, EmacsService.this); 230 classPath, EmacsService.this);
230 } 231 }
231 }, needDashQ); 232 }, needDashQ,
233 /* If any file needs to be opened, open it now. */
234 EmacsOpenActivity.fileToOpen);
232 thread.start (); 235 thread.start ();
233 } 236 }
234 catch (IOException exception) 237 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/>. */
20package org.gnu.emacs; 20package org.gnu.emacs;
21 21
22import java.lang.Thread; 22import java.lang.Thread;
23import java.util.Arrays;
23 24
24import android.os.Build; 25import android.os.Build;
26import android.util.Log;
25 27
26public class EmacsThread extends Thread 28public class EmacsThread extends Thread
27{ 29{
30 private static final String TAG = "EmacsThread";
31
28 /* Whether or not Emacs should be started -Q. */ 32 /* Whether or not Emacs should be started -Q. */
29 private boolean startDashQ; 33 private boolean startDashQ;
30 34
31 /* Runnable run to initialize Emacs. */ 35 /* Runnable run to initialize Emacs. */
32 private Runnable paramsClosure; 36 private Runnable paramsClosure;
33 37
38 /* Whether or not to open a file after starting Emacs. */
39 private String fileToOpen;
40
34 public 41 public
35 EmacsThread (EmacsService service, Runnable paramsClosure, 42 EmacsThread (EmacsService service, Runnable paramsClosure,
36 boolean startDashQ) 43 boolean startDashQ, String fileToOpen)
37 { 44 {
38 super ("Emacs main thread"); 45 super ("Emacs main thread");
39 this.startDashQ = startDashQ; 46 this.startDashQ = startDashQ;
40 this.paramsClosure = paramsClosure; 47 this.paramsClosure = paramsClosure;
48 this.fileToOpen = fileToOpen;
41 } 49 }
42 50
43 @Override 51 @Override
@@ -46,14 +54,27 @@ public class EmacsThread extends Thread
46 { 54 {
47 String args[]; 55 String args[];
48 56
49 if (!startDashQ) 57 if (fileToOpen == null)
50 args = new String[] { "libandroid-emacs.so", }; 58 {
59 if (!startDashQ)
60 args = new String[] { "libandroid-emacs.so", };
61 else
62 args = new String[] { "libandroid-emacs.so", "-Q", };
63 }
51 else 64 else
52 args = new String[] { "libandroid-emacs.so", "-Q", }; 65 {
66 if (!startDashQ)
67 args = new String[] { "libandroid-emacs.so",
68 fileToOpen, };
69 else
70 args = new String[] { "libandroid-emacs.so", "-Q",
71 fileToOpen, };
72 }
53 73
54 paramsClosure.run (); 74 paramsClosure.run ();
55 75
56 /* Run the native code now. */ 76 /* Run the native code now. */
77 Log.d (TAG, "run: " + Arrays.toString (args));
57 EmacsNative.initEmacs (args, EmacsApplication.dumpFileName, 78 EmacsNative.initEmacs (args, EmacsApplication.dumpFileName,
58 Build.VERSION.SDK_INT); 79 Build.VERSION.SDK_INT);
59 } 80 }
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."
56(cl-defmethod frame-creation-function (params &context (window-system android)) 56(cl-defmethod frame-creation-function (params &context (window-system android))
57 (x-create-frame-with-faces params)) 57 (x-create-frame-with-faces params))
58 58
59(cl-defmethod handle-args-function (_ignored &context (window-system android)) 59(cl-defmethod handle-args-function (args &context (window-system android))
60 ;; Nothing to do here: Android has no command line to provide 60 ;; Android has no command line to provide arguments on.
61 ;; arguments on. 61 ;; However, call x-handle-args to handle file name args.
62 (ignore)) 62 (x-handle-args args))
63 63
64 64
65;;; Selection support. 65;;; Selection support.