Просмотр исходного кода

Update Android Library to use 'gomobile bind'

* Migrate from old library build and format to new, gomobile-style
  build process and AAR library
* Remove Docker build script
* Move Psibot to SampleApps
* Update Psibot to use new library format
* Psibot project uses latest Android Studio/Gradle settings
* Update AndroidLibrary README documentation
Rod Hynes 10 лет назад
Родитель
Сommit
25e368e090
66 измененных файлов с 79 добавлено и 1284 удалено
  1. 0 5
      AndroidApp/.idea/encodings.xml
  2. 0 8
      AndroidApp/.idea/misc.xml
  3. 0 5
      AndroidApp/.idea/scopes/scope_settings.xml
  4. 0 47
      AndroidApp/app/src/main/java/go/Go.java
  5. 0 263
      AndroidApp/app/src/main/java/go/Seq.java
  6. 0 146
      AndroidApp/app/src/main/java/go/psi/Psi.java
  7. 0 67
      AndroidLibrary/Dockerfile
  8. 8 60
      AndroidLibrary/README.md
  9. 0 115
      AndroidLibrary/go_psi/go_psi.go
  10. 0 28
      AndroidLibrary/java_golang/LICENSE
  11. 0 47
      AndroidLibrary/java_golang/go/Go.java
  12. 0 263
      AndroidLibrary/java_golang/go/Seq.java
  13. 0 146
      AndroidLibrary/java_psi/go/psi/Psi.java
  14. 0 20
      AndroidLibrary/libpsi/main.go
  15. 0 40
      AndroidLibrary/make.bash
  16. 0 0
      SampleApps/Psibot/.gitignore
  17. 0 0
      SampleApps/Psibot/.idea/.name
  18. 1 2
      SampleApps/Psibot/.idea/compiler.xml
  19. 0 0
      SampleApps/Psibot/.idea/copyright/profiles_settings.xml
  20. 3 3
      SampleApps/Psibot/.idea/gradle.xml
  21. 46 0
      SampleApps/Psibot/.idea/misc.xml
  22. 2 3
      SampleApps/Psibot/.idea/modules.xml
  23. 1 2
      SampleApps/Psibot/.idea/vcs.xml
  24. 0 0
      SampleApps/Psibot/AndroidApp.iml
  25. 0 0
      SampleApps/Psibot/README.md
  26. 0 0
      SampleApps/Psibot/app/.gitignore
  27. 17 13
      SampleApps/Psibot/app/app.iml
  28. 0 0
      SampleApps/Psibot/app/build.gradle
  29. 0 0
      SampleApps/Psibot/app/proguard-rules.pro
  30. 0 0
      SampleApps/Psibot/app/src/androidTest/java/ca/psiphon/psibot/ApplicationTest.java
  31. 0 0
      SampleApps/Psibot/app/src/main/AndroidManifest.xml
  32. 0 0
      SampleApps/Psibot/app/src/main/java/ca/psiphon/PsiphonVpn.java
  33. 0 0
      SampleApps/Psibot/app/src/main/java/ca/psiphon/psibot/App.java
  34. 0 0
      SampleApps/Psibot/app/src/main/java/ca/psiphon/psibot/Log.java
  35. 0 0
      SampleApps/Psibot/app/src/main/java/ca/psiphon/psibot/LogFragment.java
  36. 0 0
      SampleApps/Psibot/app/src/main/java/ca/psiphon/psibot/MainActivity.java
  37. 0 0
      SampleApps/Psibot/app/src/main/java/ca/psiphon/psibot/Service.java
  38. 0 0
      SampleApps/Psibot/app/src/main/java/ca/psiphon/psibot/SettingsActivity.java
  39. 0 0
      SampleApps/Psibot/app/src/main/jniLibs/armeabi-v7a/libtun2socks.so
  40. 0 0
      SampleApps/Psibot/app/src/main/res/drawable-hdpi/ic_launcher.png
  41. 0 0
      SampleApps/Psibot/app/src/main/res/drawable-hdpi/ic_notification.png
  42. 0 0
      SampleApps/Psibot/app/src/main/res/drawable-mdpi/ic_launcher.png
  43. 0 0
      SampleApps/Psibot/app/src/main/res/drawable-mdpi/ic_notification.png
  44. 0 0
      SampleApps/Psibot/app/src/main/res/drawable-xhdpi/ic_launcher.png
  45. 0 0
      SampleApps/Psibot/app/src/main/res/drawable-xhdpi/ic_notification.png
  46. 0 0
      SampleApps/Psibot/app/src/main/res/drawable-xxhdpi/ic_launcher.png
  47. 0 0
      SampleApps/Psibot/app/src/main/res/drawable-xxhdpi/ic_notification.png
  48. 0 0
      SampleApps/Psibot/app/src/main/res/layout/activity_main.xml
  49. 0 0
      SampleApps/Psibot/app/src/main/res/layout/log_entry_row.xml
  50. 0 0
      SampleApps/Psibot/app/src/main/res/menu/main.xml
  51. 0 0
      SampleApps/Psibot/app/src/main/res/raw/psiphon_config_stub
  52. 0 0
      SampleApps/Psibot/app/src/main/res/values-v21/styles.xml
  53. 0 0
      SampleApps/Psibot/app/src/main/res/values-w820dp/dimens.xml
  54. 0 0
      SampleApps/Psibot/app/src/main/res/values/dimens.xml
  55. 0 0
      SampleApps/Psibot/app/src/main/res/values/strings.xml
  56. 0 0
      SampleApps/Psibot/app/src/main/res/values/styles.xml
  57. 0 0
      SampleApps/Psibot/app/src/main/res/values/symbols.xml
  58. 0 0
      SampleApps/Psibot/app/src/main/res/xml/preferences.xml
  59. 1 1
      SampleApps/Psibot/build.gradle
  60. 0 0
      SampleApps/Psibot/gradle.properties
  61. 0 0
      SampleApps/Psibot/gradle/wrapper/gradle-wrapper.jar
  62. 0 0
      SampleApps/Psibot/gradle/wrapper/gradle-wrapper.properties
  63. 0 0
      SampleApps/Psibot/gradlew
  64. 0 0
      SampleApps/Psibot/gradlew.bat
  65. 0 0
      SampleApps/Psibot/make.bash
  66. 0 0
      SampleApps/Psibot/settings.gradle

+ 0 - 5
AndroidApp/.idea/encodings.xml

@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
-</project>
-

+ 0 - 8
AndroidApp/.idea/misc.xml

@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="EntryPointsManager">
-    <entry_points version="2.0" />
-  </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK" />
-</project>
-

+ 0 - 5
AndroidApp/.idea/scopes/scope_settings.xml

@@ -1,5 +0,0 @@
-<component name="DependencyValidationManager">
-  <state>
-    <option name="SKIP_IMPORT_STATEMENTS" value="false" />
-  </state>
-</component>

+ 0 - 47
AndroidApp/app/src/main/java/go/Go.java

@@ -1,47 +0,0 @@
-package go;
-
-import android.content.Context;
-import android.os.Looper;
-import android.util.Log;
-
-// Go is an entry point for libraries compiled in Go.
-// In an app's Application.onCreate, call:
-//
-// 	Go.init(getApplicationContext());
-//
-// When the function returns, it is safe to start calling
-// Go code.
-public final class Go {
-	// init loads libgojni.so and starts the runtime.
-	public static void init(Context context) {
-		if (Looper.myLooper() != Looper.getMainLooper()) {
-			Log.wtf("Go", "Go.init must be called from main thread (looper="+Looper.myLooper().toString()+")");
-		}
-		if (running) {
-			return;
-		}
-		running = true;
-
-		// TODO(crawshaw): setenv TMPDIR to context.getCacheDir().getAbsolutePath()
-		// TODO(crawshaw): context.registerComponentCallbacks for runtime.GC
-
-		System.loadLibrary("gojni");
-
-		new Thread("GoMain") {
-			public void run() {
-				Go.run();
-			}
-		}.start();
-
-		Go.waitForRun();
-
-        new Thread("GoReceive") {
-            public void run() { Seq.receive(); }
-        }.start();
-	}
-
-	private static boolean running = false;
-
-	private static native void run();
-	private static native void waitForRun();
-}

+ 0 - 263
AndroidApp/app/src/main/java/go/Seq.java

@@ -1,263 +0,0 @@
-package go;
-
-import android.util.SparseArray;
-import android.util.SparseIntArray;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-// Seq is a sequence of machine-dependent encoded values.
-// Used by automatically generated language bindings to talk to Go.
-public class Seq {
-	@SuppressWarnings("UnusedDeclaration")
-	private long memptr; // holds C-allocated pointer
-
-	public Seq() {
-		ensure(64);
-	}
-
-	// Ensure that at least size bytes can be written to the Seq.
-	// Any existing data in the buffer is preserved.
-	public native void ensure(int size);
-
-	// Moves the internal buffer offset back to zero.
-	// Length and contents are maintained. Data can be read after a reset.
-	public native void resetOffset();
-
-	public native void log(String label);
-
-	public native byte readInt8();
-	public native short readInt16();
-	public native int readInt32();
-	public native long readInt64();
-	public long readInt() { return readInt64(); }
-
-	public native float readFloat32();
-	public native double readFloat64();
-	public native String readUTF16();
-	public native byte[] readByteArray();
-
-	public native void writeInt8(byte v);
-	public native void writeInt16(short v);
-	public native void writeInt32(int v);
-	public native void writeInt64(long v);
-	public void writeInt(long v) { writeInt64(v); }
-
-	public native void writeFloat32(float v);
-	public native void writeFloat64(double v);
-	public native void writeUTF16(String v);
-	public native void writeByteArray(byte[] v);
-
-	public void writeRef(Ref ref) {
-		writeInt32(ref.refnum);
-	}
-
-	public Ref readRef() {
-		int refnum = readInt32();
-		return tracker.get(refnum);
-	}
-
-	// Informs the Go ref tracker that Java is done with this ref.
-	static native void destroyRef(int refnum);
-
-	// createRef creates a Ref to a Java object.
-	public static Ref createRef(Seq.Object o) {
-		return tracker.createRef(o);
-	}
-
-	// sends a function invocation request to Go.
-	//
-	// Blocks until the function completes.
-	// If the request is for a method, the first element in src is
-	// a Ref to the receiver.
-	public static native void send(String descriptor, int code, Seq src, Seq dst);
-
-	// recv returns the next request from Go for a Java call.
-	static native void recv(Seq in, Receive params);
-
-	// recvRes sends the result of a Java call back to Go.
-	static native void recvRes(int handle, Seq out);
-
-	static final class Receive {
-		int refnum;
-		int code;
-		int handle;
-	}
-
-	protected void finalize() throws Throwable {
-		super.finalize();
-		free();
-	}
-	private native void free();
-
-	private static final ExecutorService receivePool = Executors.newCachedThreadPool();
-
-	// receive listens for callback requests from Go, invokes them on a thread
-	// pool and sends the responses.
-	public static void receive() {
-		Seq.Receive params = new Seq.Receive();
-		while (true) {
-			final Seq in = new Seq();
-			Seq.recv(in, params);
-
-			final int code = params.code;
-			final int handle = params.handle;
-			final int refnum = params.refnum;
-
-			if (code == -1) {
-				// Special signal from seq.FinalizeRef.
-				tracker.dec(refnum);
-				Seq out = new Seq();
-				Seq.recvRes(handle, out);
-				continue;
-			}
-
-			receivePool.execute(new Runnable() {
-				public void run() {
-					Ref r = tracker.get(refnum);
-					Seq out = new Seq();
-					r.obj.call(code, in, out);
-					Seq.recvRes(handle, out);
-				}
-			});
-		}
-	}
-
-	// An Object is a Java object that matches a Go object.
-	// The implementation of the object may be in either Java or Go,
-	// with a proxy instance in the other language passing calls
-	// through to the other language.
-	//
-	// Don't implement an Object directly. Instead, look for the
-	// generated abstract Stub.
-	public interface Object {
-		public Ref ref();
-		public void call(int code, Seq in, Seq out);
-	}
-
-	// A Ref is an object tagged with an integer for passing back and
-	// forth across the language boundary.
-	//
-	// A Ref may represent either an instance of a Java Object subclass,
-	// or an instance of a Go object. The explicit allocation of a Ref
-	// is used to pin Go object instances when they are passed to Java.
-	// The Go Seq library maintains a reference to the instance in a map
-	// keyed by the Ref number. When the JVM calls finalize, we ask Go
-	// to clear the entry in the map.
-	public static final class Ref {
-		// ref < 0: Go object tracked by Java
-		// ref > 0: Java object tracked by Go
-		int refnum;
-		public Seq.Object obj;
-
-		private Ref(int refnum, Seq.Object o) {
-			this.refnum = refnum;
-			this.obj = o;
-			tracker.inc(refnum);
-		}
-
-		@Override
-		protected void finalize() throws Throwable {
-			tracker.dec(refnum);
-			super.finalize();
-		}
-	}
-
-	static final RefTracker tracker = new RefTracker();
-
-	static final class RefTracker {
-		// Next Java object reference number.
-		//
-		// Reference numbers are positive for Java objects,
-		// and start, arbitrarily at a different offset to Go
-		// to make debugging by reading Seq hex a little easier.
-		private int next = 42; // next Java object ref
-
-		// TODO(crawshaw): We could cut down allocations for frequently
-		// sent Go objects by maintaining a map to weak references. This
-		// however, would require allocating two objects per reference
-		// instead of one. It also introduces weak references, the bane
-		// of any Java debugging session.
-		//
-		// When we have real code, examine the tradeoffs.
-
-		// Number of active references to a Go object. refnum -> count
-		private SparseIntArray goObjs = new SparseIntArray();
-
-		// Java objects that have been passed to Go. refnum -> Ref
-		// The Ref obj field is non-null.
-		// This map pins Java objects so they don't get GCed while the
-		// only reference to them is held by Go code.
-		private SparseArray<Ref> javaObjs = new SparseArray<Ref>();
-
-		// inc increments the reference count to a Go object.
-		synchronized void inc(int refnum) {
-			if (refnum > 0) {
-				return; // we don't count java objects
-			}
-			int count = goObjs.get(refnum);
-			if (count == Integer.MAX_VALUE) {
-				throw new RuntimeException("refnum " + refnum + " overflow");
-			}
-			goObjs.put(refnum, count+1);
-		}
-
-		// dec decrements the reference count to a Go object.
-		// If the count reaches zero, the Go reference tracker is informed.
-		synchronized void dec(int refnum) {
-			if (refnum > 0) {
-				// Java objects are removed on request of Go.
-
-				// TEMP FIX -- this can remove references for valid objects
-                // The problem appears to be that references are added when
-                // a Java object is created (only once) but removed after the
-                // object is passed to Go and then no longer referenced by Go
-                // (via runtime.SetFinalizer: https://github.com/golang/mobile/blob/b2e453e1cda693a5a97d5c97cc9f3016a64b7dfa/bind/seq/buffer.go#L110)
-                // But if the same Java object is passed to Go again, then it
-                // will no longer be in javaObjs (after Go GCs the Ref)!
-                // This temp fix keeps eternal references to Java objects,
-                // which is ok for us since we only have one. Another workaround
-                // would be to create temporary proxy objects, once per call into Go.
-
-				// javaObjs.remove(refnum);
-
-				return;
-			}
-			int count = goObjs.get(refnum);
-			if (count == 0) {
-				throw new RuntimeException("refnum " + refnum + " underflow");
-			}
-			count--;
-			if (count <= 0) {
-				goObjs.delete(refnum);
-				Seq.destroyRef(refnum);
-			} else {
-				goObjs.put(refnum, count);
-			}
-		}
-
-		synchronized Ref createRef(Seq.Object o) {
-			// TODO(crawshaw): use single Ref for null.
-			if (next == Integer.MAX_VALUE) {
-				throw new RuntimeException("createRef overflow for " + o);
-			}
-			int refnum = next++;
-			Ref ref = new Ref(refnum, o);
-			javaObjs.put(refnum, ref);
-			return ref;
-		}
-
-		// get returns an existing Ref to either a Java or Go object.
-		// It may be the first time we have seen the Go object.
-		synchronized Ref get(int refnum) {
-			if (refnum > 0) {
-				Ref ref = javaObjs.get(refnum);
-				if (ref == null) {
-					throw new RuntimeException("unknown java Ref: "+refnum);
-				}
-				return ref;
-			}
-			return new Ref(refnum, null);
-		}
-	}
-}

+ 0 - 146
AndroidApp/app/src/main/java/go/psi/Psi.java

@@ -1,146 +0,0 @@
-// Java Package psi is a proxy for talking to a Go program.
-//   gobind -lang=java github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary/psi
-//
-// File is generated by gobind. Do not edit.
-package go.psi;
-
-import go.Seq;
-
-public abstract class Psi {
-    private Psi() {} // uninstantiable
-    
-    public interface PsiphonProvider extends go.Seq.Object {
-        public void BindToDevice(long fileDescriptor) throws Exception;
-        
-        public String GetDnsServer();
-        
-        public long HasNetworkConnectivity();
-        
-        public void Notice(String noticeJSON);
-        
-        public static abstract class Stub implements PsiphonProvider {
-            static final String DESCRIPTOR = "go.psi.PsiphonProvider";
-            
-            private final go.Seq.Ref ref;
-            public Stub() {
-                ref = go.Seq.createRef(this);
-            }
-            
-            public go.Seq.Ref ref() { return ref; }
-            
-            public void call(int code, go.Seq in, go.Seq out) {
-                switch (code) {
-                case Proxy.CALL_BindToDevice: {
-                    long param_fileDescriptor = in.readInt();
-                    try {
-                        this.BindToDevice(param_fileDescriptor);
-                        out.writeUTF16(null);
-                    } catch (Exception e) {
-                        out.writeUTF16(e.getMessage());
-                    }
-                    return;
-                }
-                case Proxy.CALL_GetDnsServer: {
-                    String result = this.GetDnsServer();
-                    out.writeUTF16(result);
-                    return;
-                }
-                case Proxy.CALL_HasNetworkConnectivity: {
-                    long result = this.HasNetworkConnectivity();
-                    out.writeInt(result);
-                    return;
-                }
-                case Proxy.CALL_Notice: {
-                    String param_noticeJSON = in.readUTF16();
-                    this.Notice(param_noticeJSON);
-                    return;
-                }
-                default:
-                    throw new RuntimeException("unknown code: "+ code);
-                }
-            }
-        }
-        
-        static final class Proxy implements PsiphonProvider {
-            static final String DESCRIPTOR = Stub.DESCRIPTOR;
-        
-            private go.Seq.Ref ref;
-        
-            Proxy(go.Seq.Ref ref) { this.ref = ref; }
-        
-            public go.Seq.Ref ref() { return ref; }
-        
-            public void call(int code, go.Seq in, go.Seq out) {
-                throw new RuntimeException("cycle: cannot call proxy");
-            }
-        
-            public void BindToDevice(long fileDescriptor) throws Exception {
-                go.Seq _in = new go.Seq();
-                go.Seq _out = new go.Seq();
-                _in.writeRef(ref);
-                _in.writeInt(fileDescriptor);
-                Seq.send(DESCRIPTOR, CALL_BindToDevice, _in, _out);
-                String _err = _out.readUTF16();
-                if (_err != null) {
-                    throw new Exception(_err);
-                }
-            }
-            
-            public String GetDnsServer() {
-                go.Seq _in = new go.Seq();
-                go.Seq _out = new go.Seq();
-                String _result;
-                _in.writeRef(ref);
-                Seq.send(DESCRIPTOR, CALL_GetDnsServer, _in, _out);
-                _result = _out.readUTF16();
-                return _result;
-            }
-            
-            public long HasNetworkConnectivity() {
-                go.Seq _in = new go.Seq();
-                go.Seq _out = new go.Seq();
-                long _result;
-                _in.writeRef(ref);
-                Seq.send(DESCRIPTOR, CALL_HasNetworkConnectivity, _in, _out);
-                _result = _out.readInt();
-                return _result;
-            }
-            
-            public void Notice(String noticeJSON) {
-                go.Seq _in = new go.Seq();
-                go.Seq _out = new go.Seq();
-                _in.writeRef(ref);
-                _in.writeUTF16(noticeJSON);
-                Seq.send(DESCRIPTOR, CALL_Notice, _in, _out);
-            }
-            
-            static final int CALL_BindToDevice = 0x10a;
-            static final int CALL_GetDnsServer = 0x20a;
-            static final int CALL_HasNetworkConnectivity = 0x30a;
-            static final int CALL_Notice = 0x40a;
-        }
-    }
-    
-    public static void Start(String configJson, String embeddedServerEntryList, PsiphonProvider provider) throws Exception {
-        go.Seq _in = new go.Seq();
-        go.Seq _out = new go.Seq();
-        _in.writeUTF16(configJson);
-        _in.writeUTF16(embeddedServerEntryList);
-        _in.writeRef(provider.ref());
-        Seq.send(DESCRIPTOR, CALL_Start, _in, _out);
-        String _err = _out.readUTF16();
-        if (_err != null) {
-            throw new Exception(_err);
-        }
-    }
-    
-    public static void Stop() {
-        go.Seq _in = new go.Seq();
-        go.Seq _out = new go.Seq();
-        Seq.send(DESCRIPTOR, CALL_Stop, _in, _out);
-    }
-    
-    private static final int CALL_Start = 1;
-    private static final int CALL_Stop = 2;
-    private static final String DESCRIPTOR = "psi";
-}

+ 0 - 67
AndroidLibrary/Dockerfile

@@ -1,67 +0,0 @@
-# Dockerfile to build an image with the local version of psiphon-tunnel-core.
-#
-# See README.md for usage instructions.
-
-FROM ubuntu:12.04
-
-ENV GOVERSION=go1.4.1
-
-# Install system-level dependencies.
-ENV DEBIAN_FRONTEND=noninteractive
-RUN echo "debconf shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections && \
-  echo "debconf shared/accepted-oracle-license-v1-1 seen true" | debconf-set-selections && \
-  apt-get update && \
-  apt-get -y install build-essential python-software-properties bzip2 unzip curl \
-    git subversion mercurial bzr \
-    libncurses5:i386 libstdc++6:i386 zlib1g:i386 && \
-  add-apt-repository ppa:webupd8team/java && \
-  apt-get update && \
-  apt-get -y install oracle-java7-installer
-
-# Install Ant.
-RUN echo "INSTALLING ANT" && \
-  curl -L https://archive.apache.org/dist/ant/binaries/apache-ant-1.9.4-bin.tar.gz | tar xz -C /usr/local
-ENV ANT_HOME=/usr/local/apache-ant-1.9.4
-
-# Install Android SDK.
-ENV ANDROID_HOME=/usr/local/android-sdk-linux
-RUN echo "INSTALLING ANDROID SDK" && \
-  curl -L https://dl.google.com/android/android-sdk_r24.0.1-linux.tgz | tar xz -C /usr/local && \
-  echo y | $ANDROID_HOME/tools/android update sdk --no-ui --all --filter build-tools-21.1.2 && \
-  echo y | $ANDROID_HOME/tools/android update sdk --no-ui --all --filter platform-tools && \
-  echo y | $ANDROID_HOME/tools/android update sdk --no-ui --all --filter android-21
-  
-# Install Android NDK.
-ENV NDK_ROOT=/usr/local/android-ndk-r10d
-RUN echo "INSTALLING ANDROID NDK" && \
-  wget https://dl.google.com/android/ndk/android-ndk-r10d-linux-x86_64.bin && \
-  chmod a+x android-ndk-r10d-linux-x86_64.bin && ./android-ndk-r10d-linux-x86_64.bin && \
-  mv android-ndk-r10d /usr/local && \
-  $NDK_ROOT/build/tools/make-standalone-toolchain.sh --platform=android-9 --arch=arm --install-dir=$NDK_ROOT --system=linux-x86_64
-
-# Install Gradle
-# : android-gradle compatibility
-#   http://tools.android.com/tech-docs/new-build-system/version-compatibility
-RUN echo "INSTALLING GRADLE" && \
-  curl -L https://services.gradle.org/distributions/gradle-2.2.1-all.zip -o /tmp/gradle-2.2.1-all.zip && \
-  unzip /tmp/gradle-2.2.1-all.zip -d /usr/local && rm /tmp/gradle-2.2.1-all.zip
-ENV GRADLE_HOME=/usr/local/gradle-2.2.1
-
-# Update PATH for the above.
-ENV PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$NDK_ROOT:$ANT_HOME/bin:$GRADLE_HOME/bin
-
-# Install Go.
-ENV GOROOT=/go \
-  GOPATH=/
-ENV PATH=$PATH:$GOROOT/bin
-RUN echo "INSTALLING GO" && \
-  curl -L https://github.com/golang/go/archive/$GOVERSION.zip -o /tmp/go.zip && \
-  unzip /tmp/go.zip && \
-  rm /tmp/go.zip && \
-  mv /go-$GOVERSION $GOROOT && \
-  echo devel > $GOROOT/VERSION && \
-  cd $GOROOT/src && \
-  ./all.bash && \
-  CC_FOR_TARGET=$NDK_ROOT/bin/arm-linux-androideabi-gcc GOOS=android GOARCH=arm GOARM=7 ./make.bash
-
-WORKDIR $GOPATH/src

+ 8 - 60
AndroidLibrary/README.md

@@ -17,71 +17,19 @@ Building From Source
 --------------------------------------------------------------------------------
 
 Follow Go Android documentation:
-* [Overview README](https://code.google.com/p/go/source/browse/README?repo=mobile)
-* [Sample JNI App README](https://code.google.com/p/go/source/browse/example/libhello/README?repo=mobile)
-* [gobind documentation](http://godoc.org/golang.org/x/mobile/cmd/gobind)
-
-```
-/AndroidLibrary
-  README.md                - this file
-  libgojni.so              - build binary output
-  /psi
-    psi.go                 - main library source
-  /go_psi
-    go_psi.go              - gobind output
-  /java_psi/go/psi
-    Psi.java               - gobind output
-  /java_golang/go
-    Go.java                - fork of Go/Java integration file
-    Seq.java               - fork of Go/Java integration file
-  /libpsi
-    main.go                - stub main package for library
-```
-
-* Requires Go 1.4 or later.
-* Install Go from source. The Android instructions are here:
-[https://code.google.com/p/go/source/browse/README?repo=mobile](https://code.google.com/p/go/source/browse/README?repo=mobile).
-  * In summary, download and install the Android NDK, use a script to make a [standalone toolchain](https://developer.android.com/tools/sdk/ndk/index.html#Docs), and use that toolchain to build android/arm support within the Go source install. Then cross compile as usual.
-* `$GOPATH/bin/gobind -lang=go github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary/psi > go_psi/go_psi.go`
-* `$GOPATH/bin/gobind -lang=java github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary/psi > java_psi/go/psi/Psi.java`
-* In `/libpsi` `CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 go build -ldflags="-shared"` and copy output file to `gojni.so`
-
-### Building with Docker
-
-Note that you may need to use `sudo docker` below, depending on your OS.
-
-Create the build image:
-
-```bash
-# While in the same directory as the Dockerfile...
-$ docker build --no-cache=true -t psigoandroid .
-# That will take a long time to complete.
-# After it's done, you'll have an image called "psigoandroid". Check with...
-$ docker images
-```
-
-To do the build:
-
-```bash
-$ docker run --rm -v $GOPATH/src:/src psigoandroid /bin/bash -c 'cd /src/github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary && ./make.bash'
-```
-
-When that command completes, the compiled library will be located at `libs/armeabi-v7a/libgojni.so`.
-
+* [gomobile documentation](https://godoc.org/golang.org/x/mobile/cmd/gomobile)
+* Requires Go 1.5 or later.
+* Build command: `gomobile bind -target=android github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary/psi`
+* Output: `psi.aar`
 
 Using
 --------------------------------------------------------------------------------
 
-1. Build the shared object library from source or use the [binary release](https://github.com/Psiphon-Labs/psiphon-tunnel-core/releases) and Java source files
-1. Add Go/Java integration files `java_golang/go/*.java` to your `$src/go`
-1. Add `java_psi/go/psi/Psi.java` to your `$src/go/psi`
-1. Add `libgojni.so` to your Android app
-
-NOTE: may change to Psiphon-specific library name and init.
-
-[AndroidApp README](../AndroidApp/README.md)
+1. Build `psi.aar` from source or use the [binary release](https://github.com/Psiphon-Labs/psiphon-tunnel-core/releases)
+1. Add `psi.aar` to your Android Studio project as described in the [gomobile documentation](https://godoc.org/golang.org/x/mobile/cmd/gomobile)
+1. Example usage in [Psibot sample app](../SampleApps/Psibot/README.md)
 
-See sample usage in [Psiphon.java](../AndroidApp/app/src/main/java/ca/psiphon/psibot/Psiphon.java). Uses `gobind` conventions for data passing.
+See sample API usage in [Psibot's PsiphonVpn.java](../SampleApps/Psibot/app/src/main/java/ca/psiphon/PsiphonVpn.java). Uses `gobind` conventions for data passing.
 
 1. Embed a [config file](../README.md#setup)
 1. Call `Go.init(getApplicationContext());` in `Application.onCreate()`

+ 0 - 115
AndroidLibrary/go_psi/go_psi.go

@@ -1,115 +0,0 @@
-// Package go_psi is an autogenerated binder stub for package psi.
-//   gobind -lang=go github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary/psi
-//
-// File is generated by gobind. Do not edit.
-package go_psi
-
-import (
-	"github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary/psi"
-	"golang.org/x/mobile/bind/seq"
-)
-
-const (
-	proxyPsiphonProviderDescriptor                 = "go.psi.PsiphonProvider"
-	proxyPsiphonProviderBindToDeviceCode           = 0x10a
-	proxyPsiphonProviderGetDnsServerCode           = 0x20a
-	proxyPsiphonProviderHasNetworkConnectivityCode = 0x30a
-	proxyPsiphonProviderNoticeCode                 = 0x40a
-)
-
-func proxyPsiphonProviderBindToDevice(out, in *seq.Buffer) {
-	ref := in.ReadRef()
-	v := ref.Get().(psi.PsiphonProvider)
-	param_fileDescriptor := in.ReadInt()
-	err := v.BindToDevice(param_fileDescriptor)
-	if err == nil {
-		out.WriteUTF16("")
-	} else {
-		out.WriteUTF16(err.Error())
-	}
-}
-
-func proxyPsiphonProviderGetDnsServer(out, in *seq.Buffer) {
-	ref := in.ReadRef()
-	v := ref.Get().(psi.PsiphonProvider)
-	res := v.GetDnsServer()
-	out.WriteUTF16(res)
-}
-
-func proxyPsiphonProviderHasNetworkConnectivity(out, in *seq.Buffer) {
-	ref := in.ReadRef()
-	v := ref.Get().(psi.PsiphonProvider)
-	res := v.HasNetworkConnectivity()
-	out.WriteInt(res)
-}
-
-func proxyPsiphonProviderNotice(out, in *seq.Buffer) {
-	ref := in.ReadRef()
-	v := ref.Get().(psi.PsiphonProvider)
-	param_noticeJSON := in.ReadUTF16()
-	v.Notice(param_noticeJSON)
-}
-
-func init() {
-	seq.Register(proxyPsiphonProviderDescriptor, proxyPsiphonProviderBindToDeviceCode, proxyPsiphonProviderBindToDevice)
-	seq.Register(proxyPsiphonProviderDescriptor, proxyPsiphonProviderGetDnsServerCode, proxyPsiphonProviderGetDnsServer)
-	seq.Register(proxyPsiphonProviderDescriptor, proxyPsiphonProviderHasNetworkConnectivityCode, proxyPsiphonProviderHasNetworkConnectivity)
-	seq.Register(proxyPsiphonProviderDescriptor, proxyPsiphonProviderNoticeCode, proxyPsiphonProviderNotice)
-}
-
-type proxyPsiphonProvider seq.Ref
-
-func (p *proxyPsiphonProvider) BindToDevice(fileDescriptor int) error {
-	in := new(seq.Buffer)
-	in.WriteInt(fileDescriptor)
-	out := seq.Transact((*seq.Ref)(p), proxyPsiphonProviderBindToDeviceCode, in)
-	res_0 := out.ReadError()
-	return res_0
-}
-
-func (p *proxyPsiphonProvider) GetDnsServer() string {
-	in := new(seq.Buffer)
-	out := seq.Transact((*seq.Ref)(p), proxyPsiphonProviderGetDnsServerCode, in)
-	res_0 := out.ReadUTF16()
-	return res_0
-}
-
-func (p *proxyPsiphonProvider) HasNetworkConnectivity() int {
-	in := new(seq.Buffer)
-	out := seq.Transact((*seq.Ref)(p), proxyPsiphonProviderHasNetworkConnectivityCode, in)
-	res_0 := out.ReadInt()
-	return res_0
-}
-
-func (p *proxyPsiphonProvider) Notice(noticeJSON string) {
-	in := new(seq.Buffer)
-	in.WriteUTF16(noticeJSON)
-	seq.Transact((*seq.Ref)(p), proxyPsiphonProviderNoticeCode, in)
-}
-
-func proxy_Start(out, in *seq.Buffer) {
-	param_configJson := in.ReadUTF16()
-	param_embeddedServerEntryList := in.ReadUTF16()
-	var param_provider psi.PsiphonProvider
-	param_provider_ref := in.ReadRef()
-	if param_provider_ref.Num < 0 { // go object
-		param_provider = param_provider_ref.Get().(psi.PsiphonProvider)
-	} else { // foreign object
-		param_provider = (*proxyPsiphonProvider)(param_provider_ref)
-	}
-	err := psi.Start(param_configJson, param_embeddedServerEntryList, param_provider)
-	if err == nil {
-		out.WriteUTF16("")
-	} else {
-		out.WriteUTF16(err.Error())
-	}
-}
-
-func proxy_Stop(out, in *seq.Buffer) {
-	psi.Stop()
-}
-
-func init() {
-	seq.Register("psi", 1, proxy_Start)
-	seq.Register("psi", 2, proxy_Stop)
-}

+ 0 - 28
AndroidLibrary/java_golang/LICENSE

@@ -1,28 +0,0 @@
-Copyright (c) 2009 The Go Authors. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
-   * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
-   * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
-   * Neither the name of Google Inc. nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-

+ 0 - 47
AndroidLibrary/java_golang/go/Go.java

@@ -1,47 +0,0 @@
-package go;
-
-import android.content.Context;
-import android.os.Looper;
-import android.util.Log;
-
-// Go is an entry point for libraries compiled in Go.
-// In an app's Application.onCreate, call:
-//
-// 	Go.init(getApplicationContext());
-//
-// When the function returns, it is safe to start calling
-// Go code.
-public final class Go {
-	// init loads libgojni.so and starts the runtime.
-	public static void init(Context context) {
-		if (Looper.myLooper() != Looper.getMainLooper()) {
-			Log.wtf("Go", "Go.init must be called from main thread (looper="+Looper.myLooper().toString()+")");
-		}
-		if (running) {
-			return;
-		}
-		running = true;
-
-		// TODO(crawshaw): setenv TMPDIR to context.getCacheDir().getAbsolutePath()
-		// TODO(crawshaw): context.registerComponentCallbacks for runtime.GC
-
-		System.loadLibrary("gojni");
-
-		new Thread("GoMain") {
-			public void run() {
-				Go.run();
-			}
-		}.start();
-
-		Go.waitForRun();
-
-        new Thread("GoReceive") {
-            public void run() { Seq.receive(); }
-        }.start();
-	}
-
-	private static boolean running = false;
-
-	private static native void run();
-	private static native void waitForRun();
-}

+ 0 - 263
AndroidLibrary/java_golang/go/Seq.java

@@ -1,263 +0,0 @@
-package go;
-
-import android.util.SparseArray;
-import android.util.SparseIntArray;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-// Seq is a sequence of machine-dependent encoded values.
-// Used by automatically generated language bindings to talk to Go.
-public class Seq {
-	@SuppressWarnings("UnusedDeclaration")
-	private long memptr; // holds C-allocated pointer
-
-	public Seq() {
-		ensure(64);
-	}
-
-	// Ensure that at least size bytes can be written to the Seq.
-	// Any existing data in the buffer is preserved.
-	public native void ensure(int size);
-
-	// Moves the internal buffer offset back to zero.
-	// Length and contents are maintained. Data can be read after a reset.
-	public native void resetOffset();
-
-	public native void log(String label);
-
-	public native byte readInt8();
-	public native short readInt16();
-	public native int readInt32();
-	public native long readInt64();
-	public long readInt() { return readInt64(); }
-
-	public native float readFloat32();
-	public native double readFloat64();
-	public native String readUTF16();
-	public native byte[] readByteArray();
-
-	public native void writeInt8(byte v);
-	public native void writeInt16(short v);
-	public native void writeInt32(int v);
-	public native void writeInt64(long v);
-	public void writeInt(long v) { writeInt64(v); }
-
-	public native void writeFloat32(float v);
-	public native void writeFloat64(double v);
-	public native void writeUTF16(String v);
-	public native void writeByteArray(byte[] v);
-
-	public void writeRef(Ref ref) {
-		writeInt32(ref.refnum);
-	}
-
-	public Ref readRef() {
-		int refnum = readInt32();
-		return tracker.get(refnum);
-	}
-
-	// Informs the Go ref tracker that Java is done with this ref.
-	static native void destroyRef(int refnum);
-
-	// createRef creates a Ref to a Java object.
-	public static Ref createRef(Seq.Object o) {
-		return tracker.createRef(o);
-	}
-
-	// sends a function invocation request to Go.
-	//
-	// Blocks until the function completes.
-	// If the request is for a method, the first element in src is
-	// a Ref to the receiver.
-	public static native void send(String descriptor, int code, Seq src, Seq dst);
-
-	// recv returns the next request from Go for a Java call.
-	static native void recv(Seq in, Receive params);
-
-	// recvRes sends the result of a Java call back to Go.
-	static native void recvRes(int handle, Seq out);
-
-	static final class Receive {
-		int refnum;
-		int code;
-		int handle;
-	}
-
-	protected void finalize() throws Throwable {
-		super.finalize();
-		free();
-	}
-	private native void free();
-
-	private static final ExecutorService receivePool = Executors.newCachedThreadPool();
-
-	// receive listens for callback requests from Go, invokes them on a thread
-	// pool and sends the responses.
-	public static void receive() {
-		Seq.Receive params = new Seq.Receive();
-		while (true) {
-			final Seq in = new Seq();
-			Seq.recv(in, params);
-
-			final int code = params.code;
-			final int handle = params.handle;
-			final int refnum = params.refnum;
-
-			if (code == -1) {
-				// Special signal from seq.FinalizeRef.
-				tracker.dec(refnum);
-				Seq out = new Seq();
-				Seq.recvRes(handle, out);
-				continue;
-			}
-
-			receivePool.execute(new Runnable() {
-				public void run() {
-					Ref r = tracker.get(refnum);
-					Seq out = new Seq();
-					r.obj.call(code, in, out);
-					Seq.recvRes(handle, out);
-				}
-			});
-		}
-	}
-
-	// An Object is a Java object that matches a Go object.
-	// The implementation of the object may be in either Java or Go,
-	// with a proxy instance in the other language passing calls
-	// through to the other language.
-	//
-	// Don't implement an Object directly. Instead, look for the
-	// generated abstract Stub.
-	public interface Object {
-		public Ref ref();
-		public void call(int code, Seq in, Seq out);
-	}
-
-	// A Ref is an object tagged with an integer for passing back and
-	// forth across the language boundary.
-	//
-	// A Ref may represent either an instance of a Java Object subclass,
-	// or an instance of a Go object. The explicit allocation of a Ref
-	// is used to pin Go object instances when they are passed to Java.
-	// The Go Seq library maintains a reference to the instance in a map
-	// keyed by the Ref number. When the JVM calls finalize, we ask Go
-	// to clear the entry in the map.
-	public static final class Ref {
-		// ref < 0: Go object tracked by Java
-		// ref > 0: Java object tracked by Go
-		int refnum;
-		public Seq.Object obj;
-
-		private Ref(int refnum, Seq.Object o) {
-			this.refnum = refnum;
-			this.obj = o;
-			tracker.inc(refnum);
-		}
-
-		@Override
-		protected void finalize() throws Throwable {
-			tracker.dec(refnum);
-			super.finalize();
-		}
-	}
-
-	static final RefTracker tracker = new RefTracker();
-
-	static final class RefTracker {
-		// Next Java object reference number.
-		//
-		// Reference numbers are positive for Java objects,
-		// and start, arbitrarily at a different offset to Go
-		// to make debugging by reading Seq hex a little easier.
-		private int next = 42; // next Java object ref
-
-		// TODO(crawshaw): We could cut down allocations for frequently
-		// sent Go objects by maintaining a map to weak references. This
-		// however, would require allocating two objects per reference
-		// instead of one. It also introduces weak references, the bane
-		// of any Java debugging session.
-		//
-		// When we have real code, examine the tradeoffs.
-
-		// Number of active references to a Go object. refnum -> count
-		private SparseIntArray goObjs = new SparseIntArray();
-
-		// Java objects that have been passed to Go. refnum -> Ref
-		// The Ref obj field is non-null.
-		// This map pins Java objects so they don't get GCed while the
-		// only reference to them is held by Go code.
-		private SparseArray<Ref> javaObjs = new SparseArray<Ref>();
-
-		// inc increments the reference count to a Go object.
-		synchronized void inc(int refnum) {
-			if (refnum > 0) {
-				return; // we don't count java objects
-			}
-			int count = goObjs.get(refnum);
-			if (count == Integer.MAX_VALUE) {
-				throw new RuntimeException("refnum " + refnum + " overflow");
-			}
-			goObjs.put(refnum, count+1);
-		}
-
-		// dec decrements the reference count to a Go object.
-		// If the count reaches zero, the Go reference tracker is informed.
-		synchronized void dec(int refnum) {
-			if (refnum > 0) {
-				// Java objects are removed on request of Go.
-
-				// TEMP FIX -- this can remove references for valid objects
-                // The problem appears to be that references are added when
-                // a Java object is created (only once) but removed after the
-                // object is passed to Go and then no longer referenced by Go
-                // (via runtime.SetFinalizer: https://github.com/golang/mobile/blob/b2e453e1cda693a5a97d5c97cc9f3016a64b7dfa/bind/seq/buffer.go#L110)
-                // But if the same Java object is passed to Go again, then it
-                // will no longer be in javaObjs (after Go GCs the Ref)!
-                // This temp fix keeps eternal references to Java objects,
-                // which is ok for us since we only have one. Another workaround
-                // would be to create temporary proxy objects, once per call into Go.
-
-				// javaObjs.remove(refnum);
-
-				return;
-			}
-			int count = goObjs.get(refnum);
-			if (count == 0) {
-				throw new RuntimeException("refnum " + refnum + " underflow");
-			}
-			count--;
-			if (count <= 0) {
-				goObjs.delete(refnum);
-				Seq.destroyRef(refnum);
-			} else {
-				goObjs.put(refnum, count);
-			}
-		}
-
-		synchronized Ref createRef(Seq.Object o) {
-			// TODO(crawshaw): use single Ref for null.
-			if (next == Integer.MAX_VALUE) {
-				throw new RuntimeException("createRef overflow for " + o);
-			}
-			int refnum = next++;
-			Ref ref = new Ref(refnum, o);
-			javaObjs.put(refnum, ref);
-			return ref;
-		}
-
-		// get returns an existing Ref to either a Java or Go object.
-		// It may be the first time we have seen the Go object.
-		synchronized Ref get(int refnum) {
-			if (refnum > 0) {
-				Ref ref = javaObjs.get(refnum);
-				if (ref == null) {
-					throw new RuntimeException("unknown java Ref: "+refnum);
-				}
-				return ref;
-			}
-			return new Ref(refnum, null);
-		}
-	}
-}

+ 0 - 146
AndroidLibrary/java_psi/go/psi/Psi.java

@@ -1,146 +0,0 @@
-// Java Package psi is a proxy for talking to a Go program.
-//   gobind -lang=java github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary/psi
-//
-// File is generated by gobind. Do not edit.
-package go.psi;
-
-import go.Seq;
-
-public abstract class Psi {
-    private Psi() {} // uninstantiable
-    
-    public interface PsiphonProvider extends go.Seq.Object {
-        public void BindToDevice(long fileDescriptor) throws Exception;
-        
-        public String GetDnsServer();
-        
-        public long HasNetworkConnectivity();
-        
-        public void Notice(String noticeJSON);
-        
-        public static abstract class Stub implements PsiphonProvider {
-            static final String DESCRIPTOR = "go.psi.PsiphonProvider";
-            
-            private final go.Seq.Ref ref;
-            public Stub() {
-                ref = go.Seq.createRef(this);
-            }
-            
-            public go.Seq.Ref ref() { return ref; }
-            
-            public void call(int code, go.Seq in, go.Seq out) {
-                switch (code) {
-                case Proxy.CALL_BindToDevice: {
-                    long param_fileDescriptor = in.readInt();
-                    try {
-                        this.BindToDevice(param_fileDescriptor);
-                        out.writeUTF16(null);
-                    } catch (Exception e) {
-                        out.writeUTF16(e.getMessage());
-                    }
-                    return;
-                }
-                case Proxy.CALL_GetDnsServer: {
-                    String result = this.GetDnsServer();
-                    out.writeUTF16(result);
-                    return;
-                }
-                case Proxy.CALL_HasNetworkConnectivity: {
-                    long result = this.HasNetworkConnectivity();
-                    out.writeInt(result);
-                    return;
-                }
-                case Proxy.CALL_Notice: {
-                    String param_noticeJSON = in.readUTF16();
-                    this.Notice(param_noticeJSON);
-                    return;
-                }
-                default:
-                    throw new RuntimeException("unknown code: "+ code);
-                }
-            }
-        }
-        
-        static final class Proxy implements PsiphonProvider {
-            static final String DESCRIPTOR = Stub.DESCRIPTOR;
-        
-            private go.Seq.Ref ref;
-        
-            Proxy(go.Seq.Ref ref) { this.ref = ref; }
-        
-            public go.Seq.Ref ref() { return ref; }
-        
-            public void call(int code, go.Seq in, go.Seq out) {
-                throw new RuntimeException("cycle: cannot call proxy");
-            }
-        
-            public void BindToDevice(long fileDescriptor) throws Exception {
-                go.Seq _in = new go.Seq();
-                go.Seq _out = new go.Seq();
-                _in.writeRef(ref);
-                _in.writeInt(fileDescriptor);
-                Seq.send(DESCRIPTOR, CALL_BindToDevice, _in, _out);
-                String _err = _out.readUTF16();
-                if (_err != null) {
-                    throw new Exception(_err);
-                }
-            }
-            
-            public String GetDnsServer() {
-                go.Seq _in = new go.Seq();
-                go.Seq _out = new go.Seq();
-                String _result;
-                _in.writeRef(ref);
-                Seq.send(DESCRIPTOR, CALL_GetDnsServer, _in, _out);
-                _result = _out.readUTF16();
-                return _result;
-            }
-            
-            public long HasNetworkConnectivity() {
-                go.Seq _in = new go.Seq();
-                go.Seq _out = new go.Seq();
-                long _result;
-                _in.writeRef(ref);
-                Seq.send(DESCRIPTOR, CALL_HasNetworkConnectivity, _in, _out);
-                _result = _out.readInt();
-                return _result;
-            }
-            
-            public void Notice(String noticeJSON) {
-                go.Seq _in = new go.Seq();
-                go.Seq _out = new go.Seq();
-                _in.writeRef(ref);
-                _in.writeUTF16(noticeJSON);
-                Seq.send(DESCRIPTOR, CALL_Notice, _in, _out);
-            }
-            
-            static final int CALL_BindToDevice = 0x10a;
-            static final int CALL_GetDnsServer = 0x20a;
-            static final int CALL_HasNetworkConnectivity = 0x30a;
-            static final int CALL_Notice = 0x40a;
-        }
-    }
-    
-    public static void Start(String configJson, String embeddedServerEntryList, PsiphonProvider provider) throws Exception {
-        go.Seq _in = new go.Seq();
-        go.Seq _out = new go.Seq();
-        _in.writeUTF16(configJson);
-        _in.writeUTF16(embeddedServerEntryList);
-        _in.writeRef(provider.ref());
-        Seq.send(DESCRIPTOR, CALL_Start, _in, _out);
-        String _err = _out.readUTF16();
-        if (_err != null) {
-            throw new Exception(_err);
-        }
-    }
-    
-    public static void Stop() {
-        go.Seq _in = new go.Seq();
-        go.Seq _out = new go.Seq();
-        Seq.send(DESCRIPTOR, CALL_Stop, _in, _out);
-    }
-    
-    private static final int CALL_Start = 1;
-    private static final int CALL_Stop = 2;
-    private static final String DESCRIPTOR = "psi";
-}

+ 0 - 20
AndroidLibrary/libpsi/main.go

@@ -1,20 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This is the Go entry point for the libpsi app.
-// It is invoked from Java.
-//
-// See README for details.
-package main
-
-import (
-	"golang.org/x/mobile/app"
-
-	_ "github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary/go_psi"
-	_ "golang.org/x/mobile/bind/java"
-)
-
-func main() {
-	app.Run(app.Callbacks{})
-}

+ 0 - 40
AndroidLibrary/make.bash

@@ -1,40 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-#set -exv # verbose output for testing
-
-if [ ! -f make.bash ]; then
-  echo 'make.bash must be run from $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary'
-  exit 1
-fi
-
-# Make sure we have our dependencies
-echo -e "go-getting dependencies...\n"
-go get -d -v ./...
-
-# Force an update of the go-mobile package, since it's being improved rapidly
-# NOTE: for some reason this either doesn't complete or stalls for a very long time.
-#echo -e "Updating go-mobile...\n"
-#go get -u -d -v golang.org/x/mobile/...
-
-LIB_BASENAME="libgojni"
-BUILDINFOFILE="${LIB_BASENAME}_buildinfo.txt"
-BUILDDATE=$(date --iso-8601=seconds)
-BUILDREPO=$(git config --get remote.origin.url)
-BUILDREV=$(git rev-parse HEAD)
-LDFLAGS="\
--X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildDate $BUILDDATE \
--X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildRepo $BUILDREPO \
--X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildRev $BUILDREV \
-"
-echo -e "${BUILDDATE}\n${BUILDREPO}\n${BUILDREV}\n" > $BUILDINFOFILE
-echo -e "LDFLAGS=$LDFLAGS\n"
-
-echo -e "Building library...\n"
-CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 \
-  go build -a -v -ldflags="-shared $LDFLAGS" -o ${LIB_BASENAME}.so ./libpsi
-
-mkdir -p libs/armeabi-v7a
-mv -f ${LIB_BASENAME}.so libs/armeabi-v7a/${LIB_BASENAME}.so
-
-echo -e "Library can be found at: libs/armeabi-v7a/${LIB_BASENAME}.so\n"

+ 0 - 0
AndroidApp/.gitignore → SampleApps/Psibot/.gitignore


+ 0 - 0
AndroidApp/.idea/.name → SampleApps/Psibot/.idea/.name


+ 1 - 2
AndroidApp/.idea/compiler.xml → SampleApps/Psibot/.idea/compiler.xml

@@ -19,5 +19,4 @@
       </profile>
     </annotationProcessing>
   </component>
-</project>
-
+</project>

+ 0 - 0
AndroidApp/.idea/copyright/profiles_settings.xml → SampleApps/Psibot/.idea/copyright/profiles_settings.xml


+ 3 - 3
AndroidApp/.idea/gradle.xml → SampleApps/Psibot/.idea/gradle.xml

@@ -5,7 +5,8 @@
       <GradleProjectSettings>
         <option name="distributionType" value="LOCAL" />
         <option name="externalProjectPath" value="$PROJECT_DIR$" />
-        <option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.2.1" />
+        <option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.4" />
+        <option name="gradleJvm" value="1.8" />
         <option name="modules">
           <set>
             <option value="$PROJECT_DIR$" />
@@ -15,5 +16,4 @@
       </GradleProjectSettings>
     </option>
   </component>
-</project>
-
+</project>

+ 46 - 0
SampleApps/Psibot/.idea/misc.xml

@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="EntryPointsManager">
+    <entry_points version="2.0" />
+  </component>
+  <component name="NullableNotNullManager">
+    <option name="myDefaultNullable" value="android.support.annotation.Nullable" />
+    <option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
+    <option name="myNullables">
+      <value>
+        <list size="4">
+          <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
+          <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
+          <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
+          <item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
+        </list>
+      </value>
+    </option>
+    <option name="myNotNulls">
+      <value>
+        <list size="4">
+          <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
+          <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
+          <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
+          <item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
+        </list>
+      </value>
+    </option>
+  </component>
+  <component name="ProjectLevelVcsManager" settingsEditedManually="false">
+    <OptionsSetting value="true" id="Add" />
+    <OptionsSetting value="true" id="Remove" />
+    <OptionsSetting value="true" id="Checkout" />
+    <OptionsSetting value="true" id="Update" />
+    <OptionsSetting value="true" id="Status" />
+    <OptionsSetting value="true" id="Edit" />
+    <ConfirmationsSetting value="0" id="Add" />
+    <ConfirmationsSetting value="0" id="Remove" />
+  </component>
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+    <output url="file://$PROJECT_DIR$/build/classes" />
+  </component>
+  <component name="ProjectType">
+    <option name="id" value="Android" />
+  </component>
+</project>

+ 2 - 3
AndroidApp/.idea/modules.xml → SampleApps/Psibot/.idea/modules.xml

@@ -2,9 +2,8 @@
 <project version="4">
   <component name="ProjectModuleManager">
     <modules>
-      <module fileurl="file://$PROJECT_DIR$/AndroidApp.iml" filepath="$PROJECT_DIR$/AndroidApp.iml" />
+      <module fileurl="file://$PROJECT_DIR$/Psibot.iml" filepath="$PROJECT_DIR$/Psibot.iml" />
       <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
     </modules>
   </component>
-</project>
-
+</project>

+ 1 - 2
AndroidApp/.idea/vcs.xml → SampleApps/Psibot/.idea/vcs.xml

@@ -3,5 +3,4 @@
   <component name="VcsDirectoryMappings">
     <mapping directory="" vcs="" />
   </component>
-</project>
-
+</project>

+ 0 - 0
AndroidApp/AndroidApp.iml → SampleApps/Psibot/AndroidApp.iml


+ 0 - 0
AndroidApp/README.md → SampleApps/Psibot/README.md


+ 0 - 0
AndroidApp/app/.gitignore → SampleApps/Psibot/app/.gitignore


+ 17 - 13
AndroidApp/app/app.iml → SampleApps/Psibot/app/app.iml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
+<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="Psibot" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
   <component name="FacetManager">
     <facet type="android-gradle" name="Android-Gradle">
       <configuration>
@@ -9,11 +9,15 @@
     <facet type="android" name="Android">
       <configuration>
         <option name="SELECTED_BUILD_VARIANT" value="debug" />
+        <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
         <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
         <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
-        <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
-        <option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
-        <option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
+        <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
+        <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
+        <afterSyncTasks>
+          <task>generateDebugAndroidTestSources</task>
+          <task>generateDebugSources</task>
+        </afterSyncTasks>
         <option name="ALLOW_USER_CONFIGURATION" value="false" />
         <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
         <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
@@ -22,8 +26,9 @@
       </configuration>
     </facet>
   </component>
-  <component name="NewModuleRootManager" inherit-compiler-output="false">
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
     <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
+    <output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
     <exclude-output />
     <content url="file://$MODULE_DIR$">
       <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
@@ -32,12 +37,12 @@
       <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
       <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
       <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
-      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
-      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
-      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
-      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
-      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
-      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
       <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
       <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
       <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
@@ -84,5 +89,4 @@
     <orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
     <orderEntry type="sourceFolder" forTests="false" />
   </component>
-</module>
-
+</module>

+ 0 - 0
AndroidApp/app/build.gradle → SampleApps/Psibot/app/build.gradle


+ 0 - 0
AndroidApp/app/proguard-rules.pro → SampleApps/Psibot/app/proguard-rules.pro


+ 0 - 0
AndroidApp/app/src/androidTest/java/ca/psiphon/psibot/ApplicationTest.java → SampleApps/Psibot/app/src/androidTest/java/ca/psiphon/psibot/ApplicationTest.java


+ 0 - 0
AndroidApp/app/src/main/AndroidManifest.xml → SampleApps/Psibot/app/src/main/AndroidManifest.xml


+ 0 - 0
AndroidApp/app/src/main/java/ca/psiphon/PsiphonVpn.java → SampleApps/Psibot/app/src/main/java/ca/psiphon/PsiphonVpn.java


+ 0 - 0
AndroidApp/app/src/main/java/ca/psiphon/psibot/App.java → SampleApps/Psibot/app/src/main/java/ca/psiphon/psibot/App.java


+ 0 - 0
AndroidApp/app/src/main/java/ca/psiphon/psibot/Log.java → SampleApps/Psibot/app/src/main/java/ca/psiphon/psibot/Log.java


+ 0 - 0
AndroidApp/app/src/main/java/ca/psiphon/psibot/LogFragment.java → SampleApps/Psibot/app/src/main/java/ca/psiphon/psibot/LogFragment.java


+ 0 - 0
AndroidApp/app/src/main/java/ca/psiphon/psibot/MainActivity.java → SampleApps/Psibot/app/src/main/java/ca/psiphon/psibot/MainActivity.java


+ 0 - 0
AndroidApp/app/src/main/java/ca/psiphon/psibot/Service.java → SampleApps/Psibot/app/src/main/java/ca/psiphon/psibot/Service.java


+ 0 - 0
AndroidApp/app/src/main/java/ca/psiphon/psibot/SettingsActivity.java → SampleApps/Psibot/app/src/main/java/ca/psiphon/psibot/SettingsActivity.java


+ 0 - 0
AndroidApp/app/src/main/jniLibs/armeabi-v7a/libtun2socks.so → SampleApps/Psibot/app/src/main/jniLibs/armeabi-v7a/libtun2socks.so


+ 0 - 0
AndroidApp/app/src/main/res/drawable-hdpi/ic_launcher.png → SampleApps/Psibot/app/src/main/res/drawable-hdpi/ic_launcher.png


+ 0 - 0
AndroidApp/app/src/main/res/drawable-hdpi/ic_notification.png → SampleApps/Psibot/app/src/main/res/drawable-hdpi/ic_notification.png


+ 0 - 0
AndroidApp/app/src/main/res/drawable-mdpi/ic_launcher.png → SampleApps/Psibot/app/src/main/res/drawable-mdpi/ic_launcher.png


+ 0 - 0
AndroidApp/app/src/main/res/drawable-mdpi/ic_notification.png → SampleApps/Psibot/app/src/main/res/drawable-mdpi/ic_notification.png


+ 0 - 0
AndroidApp/app/src/main/res/drawable-xhdpi/ic_launcher.png → SampleApps/Psibot/app/src/main/res/drawable-xhdpi/ic_launcher.png


+ 0 - 0
AndroidApp/app/src/main/res/drawable-xhdpi/ic_notification.png → SampleApps/Psibot/app/src/main/res/drawable-xhdpi/ic_notification.png


+ 0 - 0
AndroidApp/app/src/main/res/drawable-xxhdpi/ic_launcher.png → SampleApps/Psibot/app/src/main/res/drawable-xxhdpi/ic_launcher.png


+ 0 - 0
AndroidApp/app/src/main/res/drawable-xxhdpi/ic_notification.png → SampleApps/Psibot/app/src/main/res/drawable-xxhdpi/ic_notification.png


+ 0 - 0
AndroidApp/app/src/main/res/layout/activity_main.xml → SampleApps/Psibot/app/src/main/res/layout/activity_main.xml


+ 0 - 0
AndroidApp/app/src/main/res/layout/log_entry_row.xml → SampleApps/Psibot/app/src/main/res/layout/log_entry_row.xml


+ 0 - 0
AndroidApp/app/src/main/res/menu/main.xml → SampleApps/Psibot/app/src/main/res/menu/main.xml


+ 0 - 0
AndroidApp/app/src/main/res/raw/psiphon_config_stub → SampleApps/Psibot/app/src/main/res/raw/psiphon_config_stub


+ 0 - 0
AndroidApp/app/src/main/res/values-v21/styles.xml → SampleApps/Psibot/app/src/main/res/values-v21/styles.xml


+ 0 - 0
AndroidApp/app/src/main/res/values-w820dp/dimens.xml → SampleApps/Psibot/app/src/main/res/values-w820dp/dimens.xml


+ 0 - 0
AndroidApp/app/src/main/res/values/dimens.xml → SampleApps/Psibot/app/src/main/res/values/dimens.xml


+ 0 - 0
AndroidApp/app/src/main/res/values/strings.xml → SampleApps/Psibot/app/src/main/res/values/strings.xml


+ 0 - 0
AndroidApp/app/src/main/res/values/styles.xml → SampleApps/Psibot/app/src/main/res/values/styles.xml


+ 0 - 0
AndroidApp/app/src/main/res/values/symbols.xml → SampleApps/Psibot/app/src/main/res/values/symbols.xml


+ 0 - 0
AndroidApp/app/src/main/res/xml/preferences.xml → SampleApps/Psibot/app/src/main/res/xml/preferences.xml


+ 1 - 1
AndroidApp/build.gradle → SampleApps/Psibot/build.gradle

@@ -5,7 +5,7 @@ buildscript {
         jcenter()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:1.0.0-rc1'
+        classpath 'com.android.tools.build:gradle:1.2.3'
 
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files

+ 0 - 0
AndroidApp/gradle.properties → SampleApps/Psibot/gradle.properties


+ 0 - 0
AndroidApp/gradle/wrapper/gradle-wrapper.jar → SampleApps/Psibot/gradle/wrapper/gradle-wrapper.jar


+ 0 - 0
AndroidApp/gradle/wrapper/gradle-wrapper.properties → SampleApps/Psibot/gradle/wrapper/gradle-wrapper.properties


+ 0 - 0
AndroidApp/gradlew → SampleApps/Psibot/gradlew


+ 0 - 0
AndroidApp/gradlew.bat → SampleApps/Psibot/gradlew.bat


+ 0 - 0
AndroidApp/make.bash → SampleApps/Psibot/make.bash


+ 0 - 0
AndroidApp/settings.gradle → SampleApps/Psibot/settings.gradle