1414#include <sys/types.h>
1515#include <errno.h>
1616
17+ #include "bootstrap_name.h"
18+ #ifndef BOOTSTRAP_USES_NO_SDL_HEADERS
1719#include "SDL.h"
18- #include "android/log.h"
1920#include "SDL_opengles2.h"
21+ #endif
22+ #ifdef BOOTSTRAP_NAME_PYGAME
23+ #include "jniwrapperstuff.h"
24+ #endif
25+ #include "android/log.h"
2026
2127#define ENTRYPOINT_MAXLEN 128
2228#define LOG (n , x ) __android_log_write(ANDROID_LOG_INFO, (n), (x))
@@ -76,7 +82,7 @@ int main(int argc, char *argv[]) {
7682 int ret = 0 ;
7783 FILE * fd ;
7884
79- setenv ("P4A_BOOTSTRAP" , "SDL2" , 1 ); // env var to identify p4a to applications
85+ setenv ("P4A_BOOTSTRAP" , bootstrap_name , 1 ); // env var to identify p4a to applications
8086
8187 LOGP ("Initializing Python for Android" );
8288 env_argument = getenv ("ANDROID_ARGUMENT" );
@@ -135,7 +141,6 @@ int main(int argc, char *argv[]) {
135141 LOGP ("calculated paths to be..." );
136142 LOGP (paths );
137143
138-
139144 #if PY_MAJOR_VERSION >= 3
140145 wchar_t * wchar_paths = Py_DecodeLocale (paths , NULL );
141146 Py_SetPath (wchar_paths );
@@ -179,7 +184,7 @@ int main(int argc, char *argv[]) {
179184 PyRun_SimpleString ("import sys, posix\n" );
180185 if (dir_exists ("lib" )) {
181186 /* If we built our own python, set up the paths correctly */
182- LOGP ("Setting up python from ANDROID_PRIVATE " );
187+ LOGP ("Setting up python from ANDROID_APP_PATH " );
183188 PyRun_SimpleString ("private = posix.environ['ANDROID_APP_PATH']\n"
184189 "argument = posix.environ['ANDROID_ARGUMENT']\n"
185190 "sys.path[:] = [ \n"
@@ -318,19 +323,30 @@ int main(int argc, char *argv[]) {
318323}
319324
320325JNIEXPORT void JNICALL Java_org_kivy_android_PythonService_nativeStart (
321- JNIEnv * env , jobject thiz , jstring j_android_private ,
322- jstring j_android_argument , jstring j_service_entrypoint ,
323- jstring j_python_name , jstring j_python_home , jstring j_python_path ,
326+ JNIEnv * env ,
327+ jobject thiz ,
328+ jstring j_android_private ,
329+ jstring j_android_argument ,
330+ #if (!defined(BOOTSTRAP_NAME_PYGAME ))
331+ jstring j_service_entrypoint ,
332+ jstring j_python_name ,
333+ #endif
334+ jstring j_python_home ,
335+ jstring j_python_path ,
324336 jstring j_arg ) {
325337 jboolean iscopy ;
326338 const char * android_private =
327339 (* env )-> GetStringUTFChars (env , j_android_private , & iscopy );
328340 const char * android_argument =
329341 (* env )-> GetStringUTFChars (env , j_android_argument , & iscopy );
342+ #if (!defined(BOOTSTRAP_NAME_PYGAME ))
330343 const char * service_entrypoint =
331344 (* env )-> GetStringUTFChars (env , j_service_entrypoint , & iscopy );
332345 const char * python_name =
333346 (* env )-> GetStringUTFChars (env , j_python_name , & iscopy );
347+ #else
348+ const char python_name [] = "python2" ;
349+ #endif
334350 const char * python_home =
335351 (* env )-> GetStringUTFChars (env , j_python_home , & iscopy );
336352 const char * python_path =
@@ -340,13 +356,16 @@ JNIEXPORT void JNICALL Java_org_kivy_android_PythonService_nativeStart(
340356 setenv ("ANDROID_PRIVATE" , android_private , 1 );
341357 setenv ("ANDROID_ARGUMENT" , android_argument , 1 );
342358 setenv ("ANDROID_APP_PATH" , android_argument , 1 );
359+
360+ #if (!defined(BOOTSTRAP_NAME_PYGAME ))
343361 setenv ("ANDROID_ENTRYPOINT" , service_entrypoint , 1 );
362+ #endif
344363 setenv ("PYTHONOPTIMIZE" , "2" , 1 );
345364 setenv ("PYTHON_NAME" , python_name , 1 );
346365 setenv ("PYTHONHOME" , python_home , 1 );
347366 setenv ("PYTHONPATH" , python_path , 1 );
348367 setenv ("PYTHON_SERVICE_ARGUMENT" , arg , 1 );
349- setenv ("P4A_BOOTSTRAP" , "SDL2" , 1 );
368+ setenv ("P4A_BOOTSTRAP" , bootstrap_name , 1 );
350369
351370 char * argv [] = {"." };
352371 /* ANDROID_ARGUMENT points to service subdir,
@@ -355,4 +374,46 @@ JNIEXPORT void JNICALL Java_org_kivy_android_PythonService_nativeStart(
355374 main (1 , argv );
356375}
357376
377+ #ifdef BOOTSTRAP_NAME_WEBVIEW
378+ // Webview uses some more functions:
379+
380+ void Java_org_kivy_android_PythonActivity_nativeSetEnv (
381+ JNIEnv * env , jclass jcls ,
382+ jstring j_name , jstring j_value )
383+ /* JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeSetEnv( */
384+ /* JNIEnv* env, jclass jcls, */
385+ /* jstring j_name, jstring j_value) */
386+ {
387+ jboolean iscopy ;
388+ const char * name = (* env )-> GetStringUTFChars (env , j_name , & iscopy );
389+ const char * value = (* env )-> GetStringUTFChars (env , j_value , & iscopy );
390+ setenv (name , value , 1 );
391+ (* env )-> ReleaseStringUTFChars (env , j_name , name );
392+ (* env )-> ReleaseStringUTFChars (env , j_value , value );
393+ }
394+
395+
396+ void Java_org_kivy_android_PythonActivity_nativeInit (JNIEnv * env , jclass cls , jobject obj )
397+ {
398+ /* This nativeInit follows SDL2 */
399+
400+ /* This interface could expand with ABI negotiation, calbacks, etc. */
401+ /* SDL_Android_Init(env, cls); */
402+
403+ /* SDL_SetMainReady(); */
404+
405+ /* Run the application code! */
406+ int status ;
407+ char * argv [2 ];
408+ argv [0 ] = "Python_app" ;
409+ argv [1 ] = NULL ;
410+ /* status = SDL_main(1, argv); */
411+
412+ main (1 , argv );
413+
414+ /* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
415+ /* exit(status); */
416+ }
417+ #endif
418+
358419#endif
0 commit comments