diff options
| author | Po Lu | 2023-02-06 22:55:42 +0800 |
|---|---|---|
| committer | Po Lu | 2023-02-06 22:55:42 +0800 |
| commit | 9b79f429edd173efd6ecbdcb2f0a5fafa8d6e523 (patch) | |
| tree | 2238081f61d08370b2e848112ddf5a5e6e8ba33e /java | |
| parent | e1c7b8ad61a213014ae3bf87db197301ab2bac29 (diff) | |
| download | emacs-9b79f429edd173efd6ecbdcb2f0a5fafa8d6e523.tar.gz emacs-9b79f429edd173efd6ecbdcb2f0a5fafa8d6e523.zip | |
Port emacsclient wrapper to Android 7.1 and earlier
* java/org/gnu/emacs/EmacsNative.java (EmacsNative): Load every
native library on which Emacs depends prior to loading libemacs
itself.
* java/org/gnu/emacs/EmacsOpenActivity.java (readEmacsClientLog)
(EmacsOpenActivity, startEmacsClient): Don't use redirectError
on Android 7.1 and earlier.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsNative.java | 152 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsOpenActivity.java | 33 |
2 files changed, 177 insertions, 8 deletions
diff --git a/java/org/gnu/emacs/EmacsNative.java b/java/org/gnu/emacs/EmacsNative.java index aba356051cd..939348ba420 100644 --- a/java/org/gnu/emacs/EmacsNative.java +++ b/java/org/gnu/emacs/EmacsNative.java | |||
| @@ -159,6 +159,158 @@ public class EmacsNative | |||
| 159 | 159 | ||
| 160 | static | 160 | static |
| 161 | { | 161 | { |
| 162 | /* Older versions of Android cannot link correctly with shared | ||
| 163 | libraries that link with other shared libraries built along | ||
| 164 | Emacs unless all requisite shared libraries are explicitly | ||
| 165 | loaded from Java. | ||
| 166 | |||
| 167 | Every time you add a new shared library dependency to Emacs, | ||
| 168 | please add it here as well. */ | ||
| 169 | |||
| 170 | try | ||
| 171 | { | ||
| 172 | System.loadLibrary ("png_emacs"); | ||
| 173 | } | ||
| 174 | catch (UnsatisfiedLinkError exception) | ||
| 175 | { | ||
| 176 | /* Ignore this exception. */ | ||
| 177 | } | ||
| 178 | |||
| 179 | try | ||
| 180 | { | ||
| 181 | System.loadLibrary ("selinux_emacs"); | ||
| 182 | } | ||
| 183 | catch (UnsatisfiedLinkError exception) | ||
| 184 | { | ||
| 185 | /* Ignore this exception. */ | ||
| 186 | } | ||
| 187 | |||
| 188 | try | ||
| 189 | { | ||
| 190 | System.loadLibrary ("crypto_emacs"); | ||
| 191 | } | ||
| 192 | catch (UnsatisfiedLinkError exception) | ||
| 193 | { | ||
| 194 | /* Ignore this exception. */ | ||
| 195 | } | ||
| 196 | |||
| 197 | try | ||
| 198 | { | ||
| 199 | System.loadLibrary ("pcre_emacs"); | ||
| 200 | } | ||
| 201 | catch (UnsatisfiedLinkError exception) | ||
| 202 | { | ||
| 203 | /* Ignore this exception. */ | ||
| 204 | } | ||
| 205 | |||
| 206 | try | ||
| 207 | { | ||
| 208 | System.loadLibrary ("packagelistparser_emacs"); | ||
| 209 | } | ||
| 210 | catch (UnsatisfiedLinkError exception) | ||
| 211 | { | ||
| 212 | /* Ignore this exception. */ | ||
| 213 | } | ||
| 214 | |||
| 215 | try | ||
| 216 | { | ||
| 217 | System.loadLibrary ("gnutls_emacs"); | ||
| 218 | } | ||
| 219 | catch (UnsatisfiedLinkError exception) | ||
| 220 | { | ||
| 221 | /* Ignore this exception. */ | ||
| 222 | } | ||
| 223 | |||
| 224 | try | ||
| 225 | { | ||
| 226 | System.loadLibrary ("gmp_emacs"); | ||
| 227 | } | ||
| 228 | catch (UnsatisfiedLinkError exception) | ||
| 229 | { | ||
| 230 | /* Ignore this exception. */ | ||
| 231 | } | ||
| 232 | |||
| 233 | try | ||
| 234 | { | ||
| 235 | System.loadLibrary ("nettle_emacs"); | ||
| 236 | } | ||
| 237 | catch (UnsatisfiedLinkError exception) | ||
| 238 | { | ||
| 239 | /* Ignore this exception. */ | ||
| 240 | } | ||
| 241 | |||
| 242 | try | ||
| 243 | { | ||
| 244 | System.loadLibrary ("p11-kit_emacs"); | ||
| 245 | } | ||
| 246 | catch (UnsatisfiedLinkError exception) | ||
| 247 | { | ||
| 248 | /* Ignore this exception. */ | ||
| 249 | } | ||
| 250 | |||
| 251 | try | ||
| 252 | { | ||
| 253 | System.loadLibrary ("tasn1_emacs"); | ||
| 254 | } | ||
| 255 | catch (UnsatisfiedLinkError exception) | ||
| 256 | { | ||
| 257 | /* Ignore this exception. */ | ||
| 258 | } | ||
| 259 | |||
| 260 | try | ||
| 261 | { | ||
| 262 | System.loadLibrary ("hogweed_emacs"); | ||
| 263 | } | ||
| 264 | catch (UnsatisfiedLinkError exception) | ||
| 265 | { | ||
| 266 | /* Ignore this exception. */ | ||
| 267 | } | ||
| 268 | |||
| 269 | try | ||
| 270 | { | ||
| 271 | System.loadLibrary ("jansson_emacs"); | ||
| 272 | } | ||
| 273 | catch (UnsatisfiedLinkError exception) | ||
| 274 | { | ||
| 275 | /* Ignore this exception. */ | ||
| 276 | } | ||
| 277 | |||
| 278 | try | ||
| 279 | { | ||
| 280 | System.loadLibrary ("jpeg_emacs"); | ||
| 281 | } | ||
| 282 | catch (UnsatisfiedLinkError exception) | ||
| 283 | { | ||
| 284 | /* Ignore this exception. */ | ||
| 285 | } | ||
| 286 | |||
| 287 | try | ||
| 288 | { | ||
| 289 | System.loadLibrary ("tiff_emacs"); | ||
| 290 | } | ||
| 291 | catch (UnsatisfiedLinkError exception) | ||
| 292 | { | ||
| 293 | /* Ignore this exception. */ | ||
| 294 | } | ||
| 295 | |||
| 296 | try | ||
| 297 | { | ||
| 298 | System.loadLibrary ("xml2_emacs"); | ||
| 299 | } | ||
| 300 | catch (UnsatisfiedLinkError exception) | ||
| 301 | { | ||
| 302 | /* Ignore this exception. */ | ||
| 303 | } | ||
| 304 | |||
| 305 | try | ||
| 306 | { | ||
| 307 | System.loadLibrary ("icuuc_emacs"); | ||
| 308 | } | ||
| 309 | catch (UnsatisfiedLinkError exception) | ||
| 310 | { | ||
| 311 | /* Ignore this exception. */ | ||
| 312 | } | ||
| 313 | |||
| 162 | System.loadLibrary ("emacs"); | 314 | System.loadLibrary ("emacs"); |
| 163 | }; | 315 | }; |
| 164 | }; | 316 | }; |
diff --git a/java/org/gnu/emacs/EmacsOpenActivity.java b/java/org/gnu/emacs/EmacsOpenActivity.java index e987e067a73..baf31039ecd 100644 --- a/java/org/gnu/emacs/EmacsOpenActivity.java +++ b/java/org/gnu/emacs/EmacsOpenActivity.java | |||
| @@ -125,6 +125,16 @@ public class EmacsOpenActivity extends Activity | |||
| 125 | int rc; | 125 | int rc; |
| 126 | String what; | 126 | String what; |
| 127 | 127 | ||
| 128 | /* Because the ProcessBuilder functions necessary to redirect | ||
| 129 | process output are not implemented on Android 7 and earlier, | ||
| 130 | print a generic error message. */ | ||
| 131 | |||
| 132 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) | ||
| 133 | return ("This is likely because the Emacs server" | ||
| 134 | + " is not running, or because you did" | ||
| 135 | + " not grant Emacs permission to access" | ||
| 136 | + " external storage."); | ||
| 137 | |||
| 128 | cache = getCacheDir (); | 138 | cache = getCacheDir (); |
| 129 | file = new File (cache, "emacsclient.log"); | 139 | file = new File (cache, "emacsclient.log"); |
| 130 | what = ""; | 140 | what = ""; |
| @@ -199,7 +209,8 @@ public class EmacsOpenActivity extends Activity | |||
| 199 | 209 | ||
| 200 | Use TITLE as the title of the dialog. If TEXT is non-NULL, | 210 | Use TITLE as the title of the dialog. If TEXT is non-NULL, |
| 201 | display that text in the dialog. Otherwise, use the contents of | 211 | display that text in the dialog. Otherwise, use the contents of |
| 202 | emacsclient.log in the cache directory instead. */ | 212 | emacsclient.log in the cache directory instead, or describe why |
| 213 | that file cannot be read. */ | ||
| 203 | 214 | ||
| 204 | public void | 215 | public void |
| 205 | finishFailure (final String title, final String text) | 216 | finishFailure (final String title, final String text) |
| @@ -240,20 +251,26 @@ public class EmacsOpenActivity extends Activity | |||
| 240 | EmacsClientThread thread; | 251 | EmacsClientThread thread; |
| 241 | File file; | 252 | File file; |
| 242 | 253 | ||
| 243 | file = new File (getCacheDir (), "emacsclient.log"); | ||
| 244 | |||
| 245 | libDir = getLibraryDirectory (); | 254 | libDir = getLibraryDirectory (); |
| 246 | builder = new ProcessBuilder (libDir + "/libemacsclient.so", | 255 | builder = new ProcessBuilder (libDir + "/libemacsclient.so", |
| 247 | fileName, "--reuse-frame", | 256 | fileName, "--reuse-frame", |
| 248 | "--timeout=10", "--no-wait"); | 257 | "--timeout=10", "--no-wait"); |
| 249 | 258 | ||
| 250 | /* Redirect standard error to a file so that errors can be | 259 | /* Redirection is unfortunately not possible in Android 7 and |
| 251 | meaningfully reported. */ | 260 | earlier. */ |
| 252 | 261 | ||
| 253 | if (file.exists ()) | 262 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) |
| 254 | file.delete (); | 263 | { |
| 264 | file = new File (getCacheDir (), "emacsclient.log"); | ||
| 255 | 265 | ||
| 256 | builder.redirectError (file); | 266 | /* Redirect standard error to a file so that errors can be |
| 267 | meaningfully reported. */ | ||
| 268 | |||
| 269 | if (file.exists ()) | ||
| 270 | file.delete (); | ||
| 271 | |||
| 272 | builder.redirectError (file); | ||
| 273 | } | ||
| 257 | 274 | ||
| 258 | /* Track process output in a new thread, since this is the UI | 275 | /* Track process output in a new thread, since this is the UI |
| 259 | thread and doing so here can cause deadlocks when EmacsService | 276 | thread and doing so here can cause deadlocks when EmacsService |