android update
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
package ZeroTier;
|
package ZeroTier;
|
||||||
public class SDK {
|
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
|
static { System.loadLibrary("ZeroTierOneJNI"); } // Loads JNI code
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.example.joseph.example_app;
|
|||||||
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import ZeroTier.SDK;
|
import ZeroTier.SDK;
|
||||||
|
|
||||||
@@ -15,19 +16,28 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
|
final SDK wrapper = new SDK();
|
||||||
|
final String homeDir = "sdcard/zerotier";
|
||||||
|
|
||||||
|
// Service thread
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
SDK wrapper = new SDK();
|
wrapper.startOneService(homeDir); // Calls to JNI code
|
||||||
wrapper.startOneService(); // Calls to JNI code
|
|
||||||
}
|
}
|
||||||
}).start();
|
}).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
|
// Set up example proxy connection to SDK proxy server
|
||||||
Log.d("ZTSDK-InJavaland", "Setting up connection to SDK proxy server");
|
Log.d("ZTSDK-InJavaland", "Setting up connection to SDK proxy server");
|
||||||
Socket s = new Socket();
|
Socket s = new Socket();
|
||||||
SocketAddress proxyAddr = new InetSocketAddress("0.0.0.0", 1337);
|
SocketAddress proxyAddr = new InetSocketAddress("0.0.0.0", 1337);
|
||||||
Proxy proxy = new Proxy(Proxy.Type.SOCKS, proxyAddr);
|
Proxy proxy = new Proxy(Proxy.Type.SOCKS, proxyAddr);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
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
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
|||||||
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
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
|
||||||
|
|||||||
Binary file not shown.
@@ -83,10 +83,10 @@ ios_unity3d_bundle:
|
|||||||
android_jni_lib:
|
android_jni_lib:
|
||||||
cd $(INT)/android/android_jni_lib/proj; ./gradlew assembleDebug
|
cd $(INT)/android/android_jni_lib/proj; ./gradlew assembleDebug
|
||||||
# copy binary into example android project dir
|
# 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
|
||||||
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
|
# 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
|
# cp docs/android_zt_sdk.md $(BUILD)/README.md
|
||||||
|
|
||||||
remove_only_intermediates:
|
remove_only_intermediates:
|
||||||
-find . -type f \( -name '*.o' -o -name '*.so' \) -delete
|
-find . -type f \( -name '*.o' -o -name '*.so' \) -delete
|
||||||
|
|||||||
@@ -82,22 +82,53 @@ void zt_init_rpc(const char * path, const char * nwid);
|
|||||||
|
|
||||||
void join_network(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)) {
|
if(!ZeroTier::OSUtils::mkdir(netDir)) {
|
||||||
LOGV("unable to create %s\n", netDir.c_str());
|
LOGV("unable to create %s\n", netDir.c_str());
|
||||||
}
|
}
|
||||||
if(!ZeroTier::OSUtils::writeFile(confFile.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);
|
zt1Service->join(nwid);
|
||||||
zt_init_rpc(homeDir.c_str(), nwid); // This provides the shim API with the RPC information
|
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 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(); }
|
bool zt_is_running() { return zt1Service->isRunning(); }
|
||||||
void zt_terminate() { zt1Service->terminate(); }
|
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__)
|
#if !defined(__ANDROID__)
|
||||||
/*
|
/*
|
||||||
@@ -134,8 +165,9 @@ void zt_init_rpc(const char * path, const char * nwid);
|
|||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
// JNI naming convention: Java_PACKAGENAME_CLASSNAME_METHODNAME
|
// JNI naming convention: Java_PACKAGENAME_CLASSNAME_METHODNAME
|
||||||
JNIEXPORT void JNICALL Java_ZeroTier_SDK_startOneService(JNIEnv *env, jobject thisObj, jstring path) {
|
JNIEXPORT void JNICALL Java_ZeroTier_SDK_startOneService(JNIEnv *env, jobject thisObj, jstring path) {
|
||||||
//char * path;
|
if(path) {
|
||||||
homeDir = env->GetStringUTFChars(path, NULL);
|
homeDir = env->GetStringUTFChars(path, NULL);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
void *startOneService(void *thread_id) {
|
void *startOneService(void *thread_id) {
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ extern std::string homeDir;
|
|||||||
Java application you *must* follow that convention and any corresponding Java package/classes
|
Java application you *must* follow that convention and any corresponding Java package/classes
|
||||||
in your Android project must match this as well */
|
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_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
|
#else
|
||||||
void *startOneService(void *thread_id);
|
void *startOneService(void *thread_id);
|
||||||
void init_service(int key, const char * path);
|
void init_service(int key, const char * path);
|
||||||
|
|||||||
Reference in New Issue
Block a user