ecere/drivers/Android: Tweaks to run with latest Android SDK/NDK on Nexus 9
authorJerome St-Louis <jerome@ecere.com>
Tue, 9 Jun 2015 04:29:46 +0000 (00:29 -0400)
committerJerome St-Louis <jerome@ecere.com>
Thu, 15 Oct 2015 00:19:46 +0000 (20:19 -0400)
- Harcoded library path for ARM64 and Nexus 9 locations
- Need to fix socket code to convert to/from network byte order as ntohs macros were breaking

ecere/src/com/instance.c
ecere/src/com/instance.ec
ecere/src/gui/drivers/AndroidInterface.ec
ecere/src/net/Service.ec
ecere/src/net/Socket.ec

index 3539e8d..56a41be 100644 (file)
@@ -477,7 +477,10 @@ void * Instance_Module_Load(const char * libLocation, const char * name, void **
 #endif
 
 #if !defined(__EMSCRIPTEN__)
+   // dlerror();
    library = dlopen(fileName, RTLD_LAZY);
+   // if(!library)
+      // printf("Error opening %s: %s", fileName, dlerror());
 #endif
    while(!library && attempts < sizeof(paths)/sizeof(paths[0]))
    {
index 9ee3934..b80b3fa 100644 (file)
@@ -89,7 +89,7 @@ private:
 
 #if defined(__ANDROID__)
 
-default const char * AndroidInterface_GetLibLocation();
+default const char * AndroidInterface_GetLibLocation(Module m);
 
 #include <android/log.h>
 #include <android/native_activity.h>
@@ -5499,7 +5499,7 @@ static Module Module_Load(Module fromModule, const char * name, AccessMode impor
       {
          const char * libLocation = null;
 #if defined(__ANDROID__)
-         libLocation = AndroidInterface_GetLibLocation();
+         libLocation = AndroidInterface_GetLibLocation(fromModule.application);
 #endif
          library = Instance_Module_Load(libLocation, name, &Load, &Unload);
       }
index d40677c..8bfbea1 100644 (file)
@@ -10,6 +10,7 @@ import "Condition"
 #include <locale.h>
 #include <pthread.h>
 #include <unistd.h>
+#include <sys/prctl.h>
 
 #include <android/configuration.h>
 #include <android/looper.h>
@@ -199,7 +200,7 @@ private:
 
    void pre_exec_cmd(AppCommand cmd)
    {
-      PrintLn("pre_exec_cmd: ", cmd);
+      //PrintLn("pre_exec_cmd: ", cmd);
       switch(cmd)
       {
          case inputChanged:
@@ -242,7 +243,7 @@ private:
 
    void post_exec_cmd(AppCommand cmd)
    {
-      PrintLn("post_exec_cmd: ", cmd);
+      //PrintLn("post_exec_cmd: ", cmd);
       switch(cmd)
       {
          case termWindow:
@@ -477,6 +478,8 @@ default dllexport void ANativeActivity_onCreate(ANativeActivity* activity, void*
    __thisModule = null;
    __androidCurrentModule = null;
 
+   prctl(PR_SET_DUMPABLE, 1);
+
    LOGI("Creating: %p\n", activity);
 
    //(*activity->vm)->AttachCurrentThread(activity->vm, &env, 0);
@@ -495,12 +498,14 @@ default dllexport void ANativeActivity_onCreate(ANativeActivity* activity, void*
    eModule_Load(__androidCurrentModule, "ecere", publicAccess);
 
 
+   /*
    if(activity->internalDataPath) PrintLn("internalDataPath is ", activity->internalDataPath);
    if(activity->externalDataPath) PrintLn("externalDataPath is ", activity->externalDataPath);
    {
       char tmp[256];
       PrintLn("cwd is ", GetWorkingDir(tmp, sizeof(tmp)));
    }
+   */
 
    ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_FULLSCREEN|AWINDOW_FLAG_KEEP_SCREEN_ON, 0 );
    app = AndroidActivity { activity = activity, moduleName = moduleName };
@@ -903,15 +908,12 @@ struct SavedState
 
 static AndroidActivity androidActivity;
 
-default const char * AndroidInterface_GetLibLocation()
+default const char * AndroidInterface_GetLibLocation(Application a)
 {
-   if(androidActivity)
-   {
-      static char loc[MAX_LOCATION];
-      sprintf(loc, "/data/data/com.ecere.%s/lib/lib", androidActivity.moduleName);
-      return loc;
-   }
-   return null;
+   static char loc[MAX_LOCATION];
+   // sprintf(loc, "/data/data/com.ecere.%s/lib/lib", a.argv[0]);
+   sprintf(loc, "/data/app/com.ecere.%s-1/lib/arm64/lib", a.argv[0]);
+   return loc;
 }
 
 static bool gotInit;
index fb28e93..3b5af5a 100644 (file)
@@ -44,6 +44,14 @@ typedef struct in_addr IN_ADDR;
 
 import "network"
 
+#ifdef __ANDROID__
+// TOFIX:
+#undef ntohs
+#undef htons
+#define ntohs(x) (x)
+#define htons(x) (x)
+#endif
+
 public class Service
 {
 public:
index 6292783..56dd0fa 100644 (file)
@@ -41,6 +41,14 @@ typedef struct in_addr IN_ADDR;
 
 import "network"
 
+#ifdef __ANDROID__
+// TOFIX:
+#undef ntohs
+#undef htons
+#define ntohs(x) (x)
+#define htons(x) (x)
+#endif
+
 #define GETLEDWORD(b) (uint32)(((b)[3] << 24) | ((b)[2] << 16) | ((b)[1] << 8) | (b)[0])
 
 #define PUTLEDWORD(b, d) \