aboutsummaryrefslogtreecommitdiffstats
path: root/src/android.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/android.c')
-rw-r--r--src/android.c114
1 files changed, 95 insertions, 19 deletions
diff --git a/src/android.c b/src/android.c
index c186b462360..8c4442e3397 100644
--- a/src/android.c
+++ b/src/android.c
@@ -145,6 +145,10 @@ char *android_game_path;
145/* The directory used to store temporary files. */ 145/* The directory used to store temporary files. */
146char *android_cache_dir; 146char *android_cache_dir;
147 147
148/* The list of archive files within which the Java virtual macine
149 looks for class files. */
150char *android_class_path;
151
148/* The display's pixel densities. */ 152/* The display's pixel densities. */
149double android_pixel_density_x, android_pixel_density_y; 153double android_pixel_density_x, android_pixel_density_y;
150 154
@@ -1315,6 +1319,7 @@ NATIVE_NAME (setEmacsParams) (JNIEnv *env, jobject object,
1315 jobject cache_dir, 1319 jobject cache_dir,
1316 jfloat pixel_density_x, 1320 jfloat pixel_density_x,
1317 jfloat pixel_density_y, 1321 jfloat pixel_density_y,
1322 jobject class_path,
1318 jobject emacs_service_object) 1323 jobject emacs_service_object)
1319{ 1324{
1320 int pipefd[2]; 1325 int pipefd[2];
@@ -1372,19 +1377,30 @@ NATIVE_NAME (setEmacsParams) (JNIEnv *env, jobject object,
1372 object from being deleted. */ 1377 object from being deleted. */
1373 (*env)->NewGlobalRef (env, local_asset_manager); 1378 (*env)->NewGlobalRef (env, local_asset_manager);
1374 1379
1375 /* Create a pipe and duplicate it to stdout and stderr. Next, make 1380 if (emacs_service_object)
1376 a thread that prints stderr to the system log. */ 1381 {
1382 /* Create a pipe and duplicate it to stdout and stderr. Next,
1383 make a thread that prints stderr to the system log.
1377 1384
1378 if (pipe2 (pipefd, O_CLOEXEC) < 0) 1385 Notice that this function is called in one of two ways. The
1379 emacs_abort (); 1386 first is when Emacs is being started as a GUI application by
1387 the system, and the second is when Emacs is being started by
1388 libandroid-emacs.so as an ordinary noninteractive Emacs.
1380 1389
1381 if (dup2 (pipefd[1], 2) < 0) 1390 In the second case, stderr is usually connected to a PTY, so
1382 emacs_abort (); 1391 this is unnecessary. */
1383 close (pipefd[1]);
1384 1392
1385 if (pthread_create (&thread, NULL, android_run_debug_thread, 1393 if (pipe2 (pipefd, O_CLOEXEC) < 0)
1386 (void *) (intptr_t) pipefd[0])) 1394 emacs_abort ();
1387 emacs_abort (); 1395
1396 if (dup2 (pipefd[1], 2) < 0)
1397 emacs_abort ();
1398 close (pipefd[1]);
1399
1400 if (pthread_create (&thread, NULL, android_run_debug_thread,
1401 (void *) (intptr_t) pipefd[0]))
1402 emacs_abort ();
1403 }
1388 1404
1389 /* Now set the path to the site load directory. */ 1405 /* Now set the path to the site load directory. */
1390 1406
@@ -1430,6 +1446,23 @@ NATIVE_NAME (setEmacsParams) (JNIEnv *env, jobject object,
1430 (*env)->ReleaseStringUTFChars (env, (jstring) cache_dir, 1446 (*env)->ReleaseStringUTFChars (env, (jstring) cache_dir,
1431 java_string); 1447 java_string);
1432 1448
1449 if (class_path)
1450 {
1451 java_string = (*env)->GetStringUTFChars (env, (jstring) class_path,
1452 NULL);
1453
1454 if (!java_string)
1455 emacs_abort ();
1456
1457 android_class_path = strdup ((const char *) java_string);
1458
1459 if (!android_files_dir)
1460 emacs_abort ();
1461
1462 (*env)->ReleaseStringUTFChars (env, (jstring) class_path,
1463 java_string);
1464 }
1465
1433 /* Calculate the site-lisp path. */ 1466 /* Calculate the site-lisp path. */
1434 1467
1435 android_site_load_path = malloc (PATH_MAX + 1); 1468 android_site_load_path = malloc (PATH_MAX + 1);
@@ -1450,16 +1483,32 @@ NATIVE_NAME (setEmacsParams) (JNIEnv *env, jobject object,
1450 "Site-lisp directory: %s\n" 1483 "Site-lisp directory: %s\n"
1451 "Files directory: %s\n" 1484 "Files directory: %s\n"
1452 "Native code directory: %s\n" 1485 "Native code directory: %s\n"
1453 "Game score path: %s\n", 1486 "Game score path: %s\n"
1487 "Class path: %s\n",
1454 android_site_load_path, 1488 android_site_load_path,
1455 android_files_dir, 1489 android_files_dir,
1456 android_lib_dir, android_game_path); 1490 android_lib_dir, android_game_path,
1491 (android_class_path
1492 ? android_class_path
1493 : "None"));
1494
1495 if (android_class_path)
1496 /* Set EMACS_CLASS_PATH to the class path where
1497 EmacsNoninteractive can be found. */
1498 setenv ("EMACS_CLASS_PATH", android_class_path, 1);
1499
1500 /* Set LD_LIBRARY_PATH to an appropriate value. */
1501 setenv ("LD_LIBRARY_PATH", android_lib_dir, 1);
1457 1502
1458 /* Make a reference to the Emacs service. */ 1503 /* Make a reference to the Emacs service. */
1459 emacs_service = (*env)->NewGlobalRef (env, emacs_service_object);
1460 1504
1461 if (!emacs_service) 1505 if (emacs_service_object)
1462 emacs_abort (); 1506 {
1507 emacs_service = (*env)->NewGlobalRef (env, emacs_service_object);
1508
1509 if (!emacs_service)
1510 emacs_abort ();
1511 }
1463 1512
1464 /* Set up events. */ 1513 /* Set up events. */
1465 android_init_events (); 1514 android_init_events ();
@@ -1660,12 +1709,14 @@ android_init_emacs_window (void)
1660} 1709}
1661 1710
1662extern JNIEXPORT void JNICALL 1711extern JNIEXPORT void JNICALL
1663NATIVE_NAME (initEmacs) (JNIEnv *env, jobject object, jarray argv) 1712NATIVE_NAME (initEmacs) (JNIEnv *env, jobject object, jarray argv,
1713 jobject dump_file_object)
1664{ 1714{
1665 char **c_argv; 1715 char **c_argv;
1666 jsize nelements, i; 1716 jsize nelements, i;
1667 jobject argument; 1717 jobject argument;
1668 const char *c_argument; 1718 const char *c_argument;
1719 char *dump_file;
1669 1720
1670 android_java_env = env; 1721 android_java_env = env;
1671 1722
@@ -1705,9 +1756,34 @@ NATIVE_NAME (initEmacs) (JNIEnv *env, jobject object, jarray argv)
1705 __android_log_print (ANDROID_LOG_WARN, __func__, 1756 __android_log_print (ANDROID_LOG_WARN, __func__,
1706 "chdir: %s", strerror (errno)); 1757 "chdir: %s", strerror (errno));
1707 1758
1708 /* Initialize the Android GUI. */ 1759 /* Initialize the Android GUI as long as the service object was
1709 android_init_gui = true; 1760 set. */
1710 android_emacs_init (nelements, c_argv); 1761
1762 if (emacs_service)
1763 android_init_gui = true;
1764
1765 /* Now see if a dump file has been specified and should be used. */
1766 dump_file = NULL;
1767
1768 if (dump_file_object)
1769 {
1770 c_argument
1771 = (*env)->GetStringUTFChars (env, (jstring) dump_file_object,
1772 NULL);
1773
1774 /* Copy the Java string data once. */
1775 dump_file = strdup (c_argument);
1776
1777 /* Release the Java string data. */
1778 (*env)->ReleaseStringUTFChars (env, (jstring) dump_file_object,
1779 c_argument);
1780 }
1781
1782 /* Delete local references to objects that are no longer needed. */
1783 ANDROID_DELETE_LOCAL_REF (argv);
1784 ANDROID_DELETE_LOCAL_REF (dump_file_object);
1785
1786 android_emacs_init (nelements, c_argv, dump_file);
1711 /* android_emacs_init should never return. */ 1787 /* android_emacs_init should never return. */
1712 emacs_abort (); 1788 emacs_abort ();
1713} 1789}