diff --git a/integrations/android/example_app/app/src/main/java/ZeroTier/SDK.java b/integrations/android/example_app/app/src/main/java/ZeroTier/SDK.java index f172041..e974c52 100644 --- a/integrations/android/example_app/app/src/main/java/ZeroTier/SDK.java +++ b/integrations/android/example_app/app/src/main/java/ZeroTier/SDK.java @@ -1,5 +1,9 @@ package ZeroTier; public class SDK { - public native void startOneService(); + public native void startOneService(String homeDir); + public native void joinNetwork(String nwid); + public native void leaveNetwork(String nwid); + public native boolean isRunning(); + static { System.loadLibrary("ZeroTierOneJNI"); } // Loads JNI code } \ No newline at end of file diff --git a/integrations/android/example_app/app/src/main/java/com/example/joseph/example_app/MainActivity.java b/integrations/android/example_app/app/src/main/java/com/example/joseph/example_app/MainActivity.java index 996d011..41507f7 100644 --- a/integrations/android/example_app/app/src/main/java/com/example/joseph/example_app/MainActivity.java +++ b/integrations/android/example_app/app/src/main/java/com/example/joseph/example_app/MainActivity.java @@ -2,6 +2,7 @@ package com.example.joseph.example_app; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.util.Log; import ZeroTier.SDK; @@ -15,19 +16,28 @@ public class MainActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + final SDK wrapper = new SDK(); + final String homeDir = "sdcard/zerotier"; + + // Service thread new Thread(new Runnable() { public void run() { - SDK wrapper = new SDK(); - wrapper.startOneService(); // Calls to JNI code + wrapper.startOneService(homeDir); // Calls to JNI code } }).start(); + // Wait for service before joining network + Log.d("SDK-Javaland", "Waiting for service to start...\n"); + while(!wrapper.isRunning()) { + Log.d("SDK-Javaland", "Waiting...\n"); + } + Log.d("SDK-Javaland","Joining network...\n"); + wrapper.joinNetwork("e5cd7a9e1c3511dd"); // Set up example proxy connection to SDK proxy server Log.d("ZTSDK-InJavaland", "Setting up connection to SDK proxy server"); Socket s = new Socket(); SocketAddress proxyAddr = new InetSocketAddress("0.0.0.0", 1337); Proxy proxy = new Proxy(Proxy.Type.SOCKS, proxyAddr); - } } \ No newline at end of file diff --git a/integrations/android/example_app/build.gradle b/integrations/android/example_app/build.gradle index 12df91c..aff4f41 100644 --- a/integrations/android/example_app/build.gradle +++ b/integrations/android/example_app/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.0-alpha1' + classpath 'com.android.tools.build:gradle:2.1.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/integrations/android/example_app/gradle/wrapper/gradle-wrapper.properties b/integrations/android/example_app/gradle/wrapper/gradle-wrapper.properties index 122a0dc..bb42b01 100644 --- a/integrations/android/example_app/gradle/wrapper/gradle-wrapper.properties +++ b/integrations/android/example_app/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip +distributionUrl=https://downloads.gradle.org/distributions/gradle-2.14-all.zip diff --git a/integrations/apple/example_app/Example_iOS_App/Example_iOS_App.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate b/integrations/apple/example_app/Example_iOS_App/Example_iOS_App.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate index f7b63f1..1aff161 100644 Binary files a/integrations/apple/example_app/Example_iOS_App/Example_iOS_App.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate and b/integrations/apple/example_app/Example_iOS_App/Example_iOS_App.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/make-mac.mk b/make-mac.mk index 25181e1..b1d53ba 100644 --- a/make-mac.mk +++ b/make-mac.mk @@ -83,10 +83,10 @@ ios_unity3d_bundle: android_jni_lib: cd $(INT)/android/android_jni_lib/proj; ./gradlew assembleDebug # copy binary into example android project dir - cp $(INT)/android/android_jni_lib/java/libs/* build - mv $(INT)/android/android_jni_lib/java/libs/* build - cd build; for res_f in *; do mv "$res_f" "android_jni_lib_$res_f"; done - #cp docs/android_zt_sdk.md $(BUILD)/README.md + # mv $(INT)/android/android_jni_lib/java/libs/* build + mv $(INT)/android/android_jni_lib/java/libs/* $(INT)/android/example_app/app/src/main/jniLibs + # cd build; for res_f in *; do mv "$res_f" "android_jni_lib_$res_f"; done + # cp docs/android_zt_sdk.md $(BUILD)/README.md remove_only_intermediates: -find . -type f \( -name '*.o' -o -name '*.so' \) -delete diff --git a/src/SDK_ServiceSetup.cpp b/src/SDK_ServiceSetup.cpp index e5149dc..d189477 100644 --- a/src/SDK_ServiceSetup.cpp +++ b/src/SDK_ServiceSetup.cpp @@ -82,22 +82,53 @@ void zt_init_rpc(const char * path, const char * nwid); void join_network(const char * nwid) { - std::string confFile = netDir + "/" + nwid + ".conf"; + std::string confFile = zt1Service->givenHomePath() + "/networks.d/" + nwid + ".conf"; + LOGV("writing conf file = %s\n", confFile.c_str()); if(!ZeroTier::OSUtils::mkdir(netDir)) { LOGV("unable to create %s\n", netDir.c_str()); } if(!ZeroTier::OSUtils::writeFile(confFile.c_str(), "")) { - LOGV("unable to write network conf file: %s\n", nwid); + LOGV("unable to write network conf file: %s\n", confFile.c_str()); } zt1Service->join(nwid); zt_init_rpc(homeDir.c_str(), nwid); // This provides the shim API with the RPC information } void leave_network(const char *nwid) { zt1Service->leave(nwid); } - void zt_join_network(char * nwid) { join_network(nwid); } - void zt_leave_network(char * nwid) { leave_network(nwid); } + + void zt_join_network(const char * nwid) { join_network(nwid); } + void zt_leave_network(const char * nwid) { leave_network(nwid); } bool zt_is_running() { return zt1Service->isRunning(); } void zt_terminate() { zt1Service->terminate(); } + + +#if defined(__ANDROID__) + // JNI naming convention: Java_PACKAGENAME_CLASSNAME_METHODNAME + JNIEXPORT void JNICALL Java_ZeroTier_SDK_joinNetwork(JNIEnv *env, jobject thisObj, jstring nwid) { + const char *nwidstr; + if(nwid) { + nwidstr = env->GetStringUTFChars(nwid, NULL); + zt_join_network(nwidstr); + } + } + // JNI naming convention: Java_PACKAGENAME_CLASSNAME_METHODNAME + JNIEXPORT void JNICALL Java_ZeroTier_SDK_leaveNetwork(JNIEnv *env, jobject thisObj, jstring nwid) { + const char *nwidstr; + if(nwid) { + nwidstr = env->GetStringUTFChars(nwid, NULL); + zt_leave_network(nwidstr); + } + } + // JNI naming convention: Java_PACKAGENAME_CLASSNAME_METHODNAME + JNIEXPORT jboolean JNICALL Java_ZeroTier_SDK_isRunning(JNIEnv *env, jobject thisObj) { + if(zt1Service) + return zt1Service->isRunning(); + return false; + } +#endif + + + #if !defined(__ANDROID__) /* @@ -134,8 +165,9 @@ void zt_init_rpc(const char * path, const char * nwid); #if defined(__ANDROID__) // JNI naming convention: Java_PACKAGENAME_CLASSNAME_METHODNAME JNIEXPORT void JNICALL Java_ZeroTier_SDK_startOneService(JNIEnv *env, jobject thisObj, jstring path) { - //char * path; - homeDir = env->GetStringUTFChars(path, NULL); + if(path) { + homeDir = env->GetStringUTFChars(path, NULL); + } #else void *startOneService(void *thread_id) { #endif diff --git a/src/SDK_ServiceSetup.hpp b/src/SDK_ServiceSetup.hpp index 493698b..f2320ea 100644 --- a/src/SDK_ServiceSetup.hpp +++ b/src/SDK_ServiceSetup.hpp @@ -51,6 +51,9 @@ extern std::string homeDir; Java application you *must* follow that convention and any corresponding Java package/classes in your Android project must match this as well */ JNIEXPORT void JNICALL Java_ZeroTier_SDK_startOneService(JNIEnv *env, jobject thisObj, jstring path); + JNIEXPORT void JNICALL Java_ZeroTier_SDK_joinNetwork(JNIEnv *env, jobject thisObj, jstring nwid); + JNIEXPORT void JNICALL Java_ZeroTier_SDK_leaveNetwork(JNIEnv *env, jobject thisObj, jstring nwid); + JNIEXPORT jboolean JNICALL Java_ZeroTier_SDK_isRunning(JNIEnv *env, jobject thisObj); #else void *startOneService(void *thread_id); void init_service(int key, const char * path);