emacs-diffs
[Top][All Lists]
Advanced

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

feature/android d70bb47aeb5: Update emacsbug and version.el for the Andr


From: Po Lu
Subject: feature/android d70bb47aeb5: Update emacsbug and version.el for the Android port
Date: Fri, 17 Feb 2023 08:09:22 -0500 (EST)

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

    Update emacsbug and version.el for the Android port
    
    * java/Makefile.in (install_temp/assets/version): New generated
    file.
    * lisp/loadup.el: Set emacs versions appropriately prior to
    dumping on Android.
    * lisp/mail/emacsbug.el (emacs-build-description): Insert
    Android build fingerprint.
    * lisp/version.el (emacs-repository-version-android)
    (emacs-repository-get-version, emacs-repository-get-branch):
    Implement for Android.
    * src/androidterm.c (android_set_build_fingerprint): New
    function.
    (syms_of_androidterm): New variable `android-build-fingerprint'.
---
 java/Makefile.in      | 10 ++++--
 lisp/loadup.el        |  7 ++++
 lisp/mail/emacsbug.el |  6 ++++
 lisp/version.el       | 38 ++++++++++++++++++++--
 src/androidterm.c     | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 145 insertions(+), 4 deletions(-)

diff --git a/java/Makefile.in b/java/Makefile.in
index 92c03469c69..f732c9211ee 100644
--- a/java/Makefile.in
+++ b/java/Makefile.in
@@ -192,12 +192,18 @@ ifneq ($(NDK_BUILD_SHARED),)
          install_temp/lib/$(ANDROID_ABI)
 endif
 
-install_temp/assets/directory-tree: $(libsrc)/asset-directory-tool install_temp
+install_temp/assets/directory-tree: $(libsrc)/asset-directory-tool \
+  install_temp install_temp/assets/version
        $(AM_V_GEN) $(libsrc)/asset-directory-tool install_temp/assets \
          install_temp/assets/directory-tree
 
+install_temp/assets/version: install_temp
+       $(AM_V_GEN) { (git rev-parse HEAD || echo "Unknown")            \
+                       && (git rev-parse --abbrev-ref HEAD             \
+                           || echo "Unknown") } 2> /dev/null > $@
+
 emacs.apk-in: install_temp install_temp/assets/directory-tree \
-       AndroidManifest.xml
+  install_temp/assets/version AndroidManifest.xml
 # Package everything.  Specifying the assets on this command line is
 # necessary for AAssetManager_getNextFileName to work on old versions
 # of Android.  Make sure not to generate R.java, as it's already been
diff --git a/lisp/loadup.el b/lisp/loadup.el
index 1747d1d960a..3b30414b146 100644
--- a/lisp/loadup.el
+++ b/lisp/loadup.el
@@ -439,6 +439,13 @@ lost after dumping")))
       (defconst emacs-build-number
        (if versions (1+ (apply #'max versions)) 1))))
 
+;; Just set the repository branch during initial dumping on Android.
+(if (and (eq system-type 'android)
+         (not (pdumper-stats)))
+    (setq emacs-repository-version
+          (ignore-errors (emacs-repository-get-version))
+          emacs-repository-branch
+          (ignore-errors (emacs-repository-get-branch))))
 
 (message "Finding pointers to doc strings...")
 (if (and (or (and (fboundp 'dump-emacs)
diff --git a/lisp/mail/emacsbug.el b/lisp/mail/emacsbug.el
index f686c04536c..68f9dcfea0b 100644
--- a/lisp/mail/emacsbug.el
+++ b/lisp/mail/emacsbug.el
@@ -408,6 +408,12 @@ copy text to your preferred mail program.\n"
                   "', version "
                  (mapconcat #'number-to-string (x-server-version) ".") "\n")
        (error t)))
+  (when (and (boundp 'android-build-fingerprint)
+             (symbol-value 'android-build-fingerprint))
+    ;; This is used on Android.
+    (insert "Android version and manufacturer: "
+            (symbol-value 'android-build-fingerprint)
+            "\n"))
   (let ((os (ignore-errors (report-emacs-bug--os-description))))
     (if (stringp os)
         (insert "System Description: " os "\n\n")))
diff --git a/lisp/version.el b/lisp/version.el
index 9cadc59237f..38a9f9c2be5 100644
--- a/lisp/version.el
+++ b/lisp/version.el
@@ -130,9 +130,22 @@ or if we could not determine the revision.")
                  (looking-at "[[:xdigit:]]\\{40\\}"))
           (match-string 0)))))
 
+(defun emacs-repository-version-android ()
+  "Return the Emacs repository revision Emacs was built from.
+Value is nil if Emacs was not built from a repository checkout.
+Use information from the `/assets/version' special file."
+  (with-temp-buffer
+    (insert-file-contents "/assets/version")
+    (let ((string (buffer-substring 1 (line-end-position))))
+      (and (not (equal string "Unknown")) string))))
+
 (defun emacs-repository-get-version (&optional dir _external)
   "Try to return as a string the repository revision of the Emacs sources.
 The format of the returned string is dependent on the VCS in use.
+
+If Emacs is built for Android, use the version information
+embedded in the Emacs installation package.
+
 Value is nil if the sources do not seem to be under version
 control, or if we could not determine the revision.  Note that
 this reports on the current state of the sources, which may not
@@ -140,13 +153,27 @@ correspond to the running Emacs.
 
 Optional argument DIR is a directory to use instead of `source-directory'.
 Optional argument EXTERNAL is ignored."
-  (emacs-repository-version-git (or dir source-directory)))
+  (cond ((eq system-type 'android)
+         (emacs-repository-version-android))
+        (t (emacs-repository-version-git
+            (or dir source-directory)))))
 
 (defvar emacs-repository-branch nil
   "String giving the repository branch from which this Emacs was built.
 Value is nil if Emacs was not built from a repository checkout,
 or if we could not determine the branch.")
 
+(defun emacs-repository-branch-android ()
+  "Return the Emacs repository branch Emacs was built from.
+Value is nil if Emacs was not built from a repository checkout.
+Use information from the `/assets/version' special file."
+  (with-temp-buffer
+    (insert-file-contents "/assets/version")
+    (end-of-line)
+    (forward-char)
+    (let ((string (buffer-substring (point) (line-end-position))))
+      (and (not (equal string "Unknown")) string))))
+
 (defun emacs-repository-branch-git (dir)
   "Ask git itself for the branch information for directory DIR."
   (message "Waiting for git...")
@@ -162,12 +189,19 @@ or if we could not determine the branch.")
 (defun emacs-repository-get-branch (&optional dir)
   "Try to return as a string the repository branch of the Emacs sources.
 The format of the returned string is dependent on the VCS in use.
+
+If Emacs is built for Android, use the version information
+embedded in the Emacs installation package.
+
 Value is nil if the sources do not seem to be under version
 control, or if we could not determine the branch.  Note that
 this reports on the current state of the sources, which may not
 correspond to the running Emacs.
 
 Optional argument DIR is a directory to use instead of `source-directory'."
-  (emacs-repository-branch-git (or dir source-directory)))
+  (cond ((eq system-type 'android)
+         (emacs-repository-branch-android))
+        (t (emacs-repository-branch-git
+            (or dir source-directory)))))
 
 ;;; version.el ends here
diff --git a/src/androidterm.c b/src/androidterm.c
index c6f75ec9219..8a07bfa7455 100644
--- a/src/androidterm.c
+++ b/src/androidterm.c
@@ -33,6 +33,7 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #include "window.h"
 #include "textconv.h"
 #include "coding.h"
+#include "pdumper.h"
 
 /* This is a chain of structures for all the X displays currently in
    use.  */
@@ -5413,6 +5414,84 @@ android_term_init (void)
 
 
 
+/* Set Vandroid_build_fingerprint to a reasonable value.  */
+
+static void
+android_set_build_fingerprint (void)
+{
+#ifdef ANDROID_STUBIFY
+  Vandroid_build_fingerprint = Qnil;
+#else
+  jclass class;
+  jfieldID field;
+  jobject string;
+  const char *data;
+
+  /* Set class to NULL so freeing an uninitialized local ref can be
+     avoided.  */
+  class = NULL;
+
+  /* Likewise for string.  */
+  string = NULL;
+
+  if (!android_init_gui)
+    goto fail;
+  else
+    {
+      /* Obtain Build.FINGERPRINT.  Clear exceptions after each query;
+        JNI can't find Build.FINGERPRIN on some systems.  */
+
+      class = (*android_java_env)->FindClass (android_java_env,
+                                             "android/os/Build");
+      (*android_java_env)->ExceptionClear (android_java_env);
+
+      if (!class)
+       goto fail;
+
+      field = (*android_java_env)->GetStaticFieldID (android_java_env,
+                                                    class,
+                                                    "FINGERPRINT",
+                                                    "Ljava/lang/String;");
+      (*android_java_env)->ExceptionClear (android_java_env);
+
+      if (!field)
+       goto fail;
+
+      string
+       = (*android_java_env)->GetStaticObjectField (android_java_env,
+                                                    class, field);
+      (*android_java_env)->ExceptionClear (android_java_env);
+
+      if (!string)
+       goto fail;
+
+      data = (*android_java_env)->GetStringUTFChars (android_java_env,
+                                                    string, NULL);
+      (*android_java_env)->ExceptionClear (android_java_env);
+
+      if (!data)
+       goto fail;
+
+      Vandroid_build_fingerprint = build_string_from_utf8 (data);
+      (*android_java_env)->ReleaseStringUTFChars (android_java_env,
+                                                 string, data);
+    }
+
+  if (string)
+    ANDROID_DELETE_LOCAL_REF (string);
+
+  ANDROID_DELETE_LOCAL_REF (class);
+
+  return;
+
+ fail:
+  if (class)
+    ANDROID_DELETE_LOCAL_REF (class);
+
+  Vandroid_build_fingerprint = Qnil;
+#endif
+}
+
 void
 syms_of_androidterm (void)
 {
@@ -5441,6 +5520,15 @@ If set to a non-float value, there will be no wait at 
all.  */);
               x_underline_at_descent_line,
      doc: /* SKIP: real doc in xterm.c.  */);
   x_underline_at_descent_line = false;
+
+  DEFVAR_LISP ("android-build-fingerprint", Vandroid_build_fingerprint,
+    doc: /* String identifying the device's OS version.
+This is a string that uniquely identifies the version of Android
+Emacs is running on.  */);
+
+  /* Avoid dumping Vandroid_build_fingerprint.  */
+  pdumper_do_now_and_after_load (android_set_build_fingerprint);
+
   DEFSYM (Qx_underline_at_descent_line, "x-underline-at-descent-line");
 }
 



reply via email to

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