diff --git a/.gitignore b/.gitignore index bed9cfa..72d1571 100644 --- a/.gitignore +++ b/.gitignore @@ -1,96 +1,11 @@ -# Created by .ignore support plugin (hsz.mobi) -### Scala template -*.class -*.log - -# sbt specific -.cache -.history -.lib/ -dist/* -target -lib_managed/ -src_managed/ -project/boot/ -project/plugins/project/ - -# Scala-IDE specific -.scala_dependencies -.worksheet - -# ENSIME specific -.ensime_cache/ -.ensime -### JetBrains template -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -## File-based project format: -*.iws - -## Plugin-specific files: - -# IntelliJ -/out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties -### SBT template -# Simple Build Tool -# http://www.scala-sbt.org/release/docs/Getting-Started/Directories.html#configuring-version-control - -### Android template -# Built application files -*.apk -*.ap_ - -# Files for the ART/Dalvik VM -*.dex - -# Java class files - -# Generated files -bin/ -gen/ -out/ -src/.deps - -# Gradle files -.gradle/ -build/ - -# Local configuration file (sdk path, etc) -local.properties - -# Proguard folder generated by Eclipse -proguard/ - -# Log Files - -# Android Studio Navigation editor temp files -.navigation/ - -# Android Studio captures folder -captures/ - -# Intellij -.idea/ -proguard-sbt.txt - -# Keystore files -*.jks - -# External native build folder generated in Android Studio 2.2 and later +*.iml +.gradle +/.idea +/local.properties +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store +/build +/captures .externalNativeBuild - -/.deps/ -/src/main/libs diff --git a/.gitmodules b/.gitmodules index f0ce053..7085c88 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,8 +1,8 @@ [submodule "src/go"] - path = src/go + path = app/src/go url = https://github.com/shadowsocks/go.git branch = shadowsocks [submodule "src/kcptun"] - path = src/kcptun + path = app/src/kcptun url = https://github.com/shadowsocks/kcptun.git branch = shadowsocks diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..654afc0 --- /dev/null +++ b/app/.gitignore @@ -0,0 +1,6 @@ +/build +# no tests written yet +/src/androidTest +/src/test +/src/bin +/.deps diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..5abad32 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,78 @@ +import org.apache.tools.ant.taskdefs.condition.Os + +import java.util.regex.Matcher +import java.util.regex.Pattern + +apply plugin: 'com.android.application' + +apply plugin: 'kotlin-android' + +def getCurrentFlavor() { + String task = getGradle().getStartParameter().getTaskRequests().toString() + Matcher matcher = Pattern.compile("(assemble|generate)\\w*(Release|Debug)").matcher(task) + if (matcher.find()) return matcher.group(2).toLowerCase() else { + println "Warning: No match found for $task" + return "debug" + } +} + +android { + compileSdkVersion rootProject.sdkVersion + defaultConfig { + applicationId "com.github.shadowsocks.plugin.kcptun" + minSdkVersion rootProject.minSdkVersion + targetSdkVersion rootProject.sdkVersion + versionCode 10000 + versionName "0.1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + sourceSets.main.jniLibs.srcDirs += new File(projectDir, "src/bin") +} + +task goBuild(type: Exec) { + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + println "Warning: Building on Windows is not supported" + } else { + executable "sh" + args "-c", "src/make.bash " + minSdkVersion + } +} + +task goClean(type: Exec) { + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + println "Warning: Building on Windows is not supported" + } else { + executable "sh" + args "-c", "src/clean.bash" + } +} + +tasks.whenTaskAdded { task -> + if ((task.name == 'javaPreCompileDebug' || + task.name == 'javaPreCompileRelease')) { + task.dependsOn(goBuild) + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion" + implementation 'com.github.shadowsocks:plugin:0.1.1' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.1' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' +} + +ext.abiCodes = ['armeabi-v7a': 1, 'arm64-v8a': 2, x86: 3] +if (getCurrentFlavor() == 'release') android.applicationVariants.all { variant -> + variant.outputs.each { output -> + def offset = project.ext.abiCodes.get(output.getFilter(OutputFile.ABI)) + if (offset != null) output.versionCodeOverride = variant.versionCode + offset + } +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..97f6f95 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,22 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +-keepattributes SourceFile,LineNumberTable +-dontobfuscate + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/clean.bash b/app/src/clean.bash new file mode 100755 index 0000000..60bfbc7 --- /dev/null +++ b/app/src/clean.bash @@ -0,0 +1,10 @@ +#!/bin/bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +DEPS=$DIR/.deps + +rm -rf $DEPS +rm -rf $DIR/go/bin +rm -rf $DIR/bin + +echo "Successfully clean kcptun" diff --git a/app/src/go b/app/src/go new file mode 160000 index 0000000..486515f --- /dev/null +++ b/app/src/go @@ -0,0 +1 @@ +Subproject commit 486515fc9846cf408a75d3e3e173e3ba927a7fd2 diff --git a/app/src/kcptun b/app/src/kcptun new file mode 160000 index 0000000..4bfc48f --- /dev/null +++ b/app/src/kcptun @@ -0,0 +1 @@ +Subproject commit 4bfc48ffc733a123836210c64569418f5c357aa2 diff --git a/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml similarity index 89% rename from src/main/AndroidManifest.xml rename to app/src/main/AndroidManifest.xml index 39ba977..ec9f30c 100644 --- a/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,15 +1,15 @@ - + android:authorities="com.github.shadowsocks.plugin.kcptun.BinaryProvider" + tools:ignore="ExportedContentProvider"> @@ -25,7 +25,7 @@ android:value="crypt=none;mode=normal;mtu=1200;nocomp;dscp=46;parityshard=0"/> + android:theme="@style/Theme.AppCompat.Translucent"> diff --git a/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png similarity index 100% rename from src/main/ic_launcher-web.png rename to app/src/main/ic_launcher-web.png diff --git a/app/src/main/java/com/github/shadowsocks/plugin/kcptun/BinaryProvider.kt b/app/src/main/java/com/github/shadowsocks/plugin/kcptun/BinaryProvider.kt new file mode 100644 index 0000000..1fd8e65 --- /dev/null +++ b/app/src/main/java/com/github/shadowsocks/plugin/kcptun/BinaryProvider.kt @@ -0,0 +1,19 @@ +package com.github.shadowsocks.plugin.kcptun + +import android.net.Uri +import android.os.ParcelFileDescriptor +import com.github.shadowsocks.plugin.NativePluginProvider +import com.github.shadowsocks.plugin.PathProvider +import java.io.File +import java.io.FileNotFoundException + +class BinaryProvider : NativePluginProvider() { + override fun populateFiles(provider: PathProvider) { + provider.addPath("kcptun", "755") + } + override fun getExecutable() = context.applicationInfo.nativeLibraryDir + "/libkcptun.so" + override fun openFile(uri: Uri?): ParcelFileDescriptor = when (uri?.path) { + "/kcptun" -> ParcelFileDescriptor.open(File(getExecutable()), ParcelFileDescriptor.MODE_READ_ONLY) + else -> throw FileNotFoundException() + } +} diff --git a/app/src/main/java/com/github/shadowsocks/plugin/kcptun/HelpCallback.kt b/app/src/main/java/com/github/shadowsocks/plugin/kcptun/HelpCallback.kt new file mode 100644 index 0000000..5399ce1 --- /dev/null +++ b/app/src/main/java/com/github/shadowsocks/plugin/kcptun/HelpCallback.kt @@ -0,0 +1,29 @@ +package com.github.shadowsocks.plugin.kcptun + +import com.github.shadowsocks.plugin.PluginOptions + +class HelpCallback : com.github.shadowsocks.plugin.HelpCallback() { + override fun produceHelpMessage(options: PluginOptions): CharSequence = + ProcessBuilder(applicationInfo.nativeLibraryDir + "/libkcptun.so", "--help") + .redirectErrorStream(true) + .start() + .inputStream.bufferedReader().useLines { + it.dropWhile { it != "GLOBAL OPTIONS:" } + .drop(1) + .takeWhile { it.length > 3 } + .filter { + !it.startsWith(" --localaddr ") && + !it.startsWith(" --remoteaddr ") && + !it.startsWith(" -c ") && + !it.startsWith(" -V ") && + !it.startsWith(" --fast-open ") && + !it.startsWith(" --help,") && + !it.startsWith(" --version,") + } + .joinToString("\n") + .replace(Regex(" {2,}"), "\n") + .replace("--", "") + .replace(" value", "=value") + .substring(1) // remove 1st \n + } +} diff --git a/app/src/main/libs/arm64-v8a/libkcptun.so b/app/src/main/libs/arm64-v8a/libkcptun.so new file mode 100755 index 0000000..d382aa4 Binary files /dev/null and b/app/src/main/libs/arm64-v8a/libkcptun.so differ diff --git a/app/src/main/libs/armeabi-v7a/libkcptun.so b/app/src/main/libs/armeabi-v7a/libkcptun.so new file mode 100755 index 0000000..000d397 Binary files /dev/null and b/app/src/main/libs/armeabi-v7a/libkcptun.so differ diff --git a/app/src/main/libs/x86/libkcptun.so b/app/src/main/libs/x86/libkcptun.so new file mode 100755 index 0000000..dcd19b6 Binary files /dev/null and b/app/src/main/libs/x86/libkcptun.so differ diff --git a/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from src/main/res/mipmap-hdpi/ic_launcher.png rename to app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from src/main/res/mipmap-mdpi/ic_launcher.png rename to app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from src/main/res/mipmap-xhdpi/ic_launcher.png rename to app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from src/main/res/mipmap-xxhdpi/ic_launcher.png rename to app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png similarity index 100% rename from src/main/res/mipmap-xxxhdpi/ic_launcher.png rename to app/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/src/make.bash b/app/src/make.bash similarity index 57% rename from src/make.bash rename to app/src/make.bash index 9a1c412..ab28d4d 100755 --- a/src/make.bash +++ b/app/src/make.bash @@ -8,9 +8,11 @@ function try () { DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" MIN_API=$1 +TARGET=$DIR/bin DEPS=$(pwd)/.deps + ANDROID_ARM_TOOLCHAIN=$DEPS/android-toolchain-${MIN_API}-arm -ANDROID_ARM64_TOOLCHAIN=$DEPS/android-toolchain-21-arm64 +ANDROID_ARM64_TOOLCHAIN=$DEPS/android-toolchain-${MIN_API}-arm64 ANDROID_X86_TOOLCHAIN=$DEPS/android-toolchain-${MIN_API}-x86 ANDROID_ARM_CC=$ANDROID_ARM_TOOLCHAIN/bin/arm-linux-androideabi-clang @@ -22,7 +24,7 @@ ANDROID_ARM64_STRIP=$ANDROID_ARM64_TOOLCHAIN/bin/aarch64-linux-android-strip ANDROID_X86_CC=$ANDROID_X86_TOOLCHAIN/bin/i686-linux-android-clang ANDROID_X86_STRIP=$ANDROID_X86_TOOLCHAIN/bin/i686-linux-android-strip -try mkdir -p $DEPS $DIR/main/libs/armeabi-v7a $DIR/main/libs/x86 $DIR/main/libs/arm64-v8a +try mkdir -p $DEPS $TARGET/armeabi-v7a $TARGET/x86 $TARGET/arm64-v8a if [ ! -d "$ANDROID_ARM_TOOLCHAIN" ]; then echo "Make standalone toolchain for ARM arch" @@ -58,25 +60,37 @@ export PATH=$GOROOT/bin:$PATH pushd $DIR/kcptun/client -echo "Get dependences for kcptun" -go get -u github.com/xtaci/kcp-go -go get -u github.com/xtaci/smux -go get - -echo "Cross compile kcptun for arm" -try env CGO_ENABLED=1 CC=$ANDROID_ARM_CC GOOS=android GOARCH=arm GOARM=7 go build -ldflags="-s -w" -try $ANDROID_ARM_STRIP client -try mv client $DIR/main/libs/armeabi-v7a/libkcptun.so - -echo "Cross compile kcptun for arm64" -try env CGO_ENABLED=1 CC=$ANDROID_ARM64_CC GOOS=android GOARCH=arm64 go build -ldflags="-s -w" -try $ANDROID_ARM64_STRIP client -try mv client $DIR/main/libs//arm64-v8a/libkcptun.so - -echo "Cross compile kcptun for x86" -try env CGO_ENABLED=1 CC=$ANDROID_X86_CC GOOS=android GOARCH=386 go build -ldflags="-s -w" -try $ANDROID_X86_STRIP client -try mv client $DIR/main/libs/x86/libkcptun.so -popd +if [ ! -f "$TARGET/armeabi-v7a/libkcptun.so" ] || [ ! -f "$TARGET/arm64-v8a/libkcptun.so" ] || + [ ! -f "$TARGET/x86/libkcptun.so" ]; then + + echo "Get dependences for kcptun" + go get -u github.com/xtaci/kcp-go + go get -u github.com/xtaci/smux + go get + + echo "Cross compile kcptun for arm" + if [ ! -f "$TARGET/armeabi-v7a/liboverture.so" ]; then + try env CGO_ENABLED=1 CC=$ANDROID_ARM_CC GOOS=android GOARCH=arm GOARM=7 go build -ldflags="-s -w" + try $ANDROID_ARM_STRIP client + try mv client $TARGET/armeabi-v7a/libkcptun.so + fi + + echo "Cross compile kcptun for arm64" + if [ ! -f "$TARGET/arm64-v8a/liboverture.so" ]; then + try env CGO_ENABLED=1 CC=$ANDROID_ARM64_CC GOOS=android GOARCH=arm64 go build -ldflags="-s -w" + try $ANDROID_ARM64_STRIP client + try mv client $TARGET/arm64-v8a/libkcptun.so + fi + + echo "Cross compile kcptun for x86" + if [ ! -f "$TARGET/x86/liboverture.so" ]; then + try env CGO_ENABLED=1 CC=$ANDROID_X86_CC GOOS=android GOARCH=386 go build -ldflags="-s -w" + try $ANDROID_X86_STRIP client + try mv client $TARGET/x86/libkcptun.so + fi + + popd + +fi echo "Successfully build kcptun" diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..09c395e --- /dev/null +++ b/build.gradle @@ -0,0 +1,31 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +apply plugin: 'com.github.ben-manes.versions' + +buildscript { + ext { + kotlinVersion = '1.2.31' + minSdkVersion = 21 + sdkVersion = 27 + } + repositories { + google() + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:3.1.1' + classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" + } +} + +allprojects { + repositories { + google() + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/build.sbt b/build.sbt deleted file mode 100644 index f6b1b96..0000000 --- a/build.sbt +++ /dev/null @@ -1,34 +0,0 @@ -scalaVersion := "2.11.8" - -enablePlugins(AndroidApp) -android.useSupportVectors - -resolvers += Resolver.jcenterRepo - -name := "kcptun" -organization := "com.github.shadowsocks" -version := "0.0.6" -versionCode := Some(6) - -platformTarget := "android-26" - -compileOrder := CompileOrder.JavaThenScala -javacOptions ++= "-source" :: "1.7" :: "-target" :: "1.7" :: Nil -scalacOptions ++= "-target:jvm-1.7" :: "-Xexperimental" :: Nil - -proguardVersion := "5.3.3" -proguardCache := Seq() - -shrinkResources := true -typedResources := false -resConfigs := Seq("ja", "ko", "ru", "zh-rCN", "zh-rTW") - -libraryDependencies += "com.github.shadowsocks" %% "plugin" % "0.0.4" - -lazy val goBuild = TaskKey[Unit]("go-build", "Build go and kcptun") -goBuild := { - Process(Seq("src/make.bash", minSdkVersion.value)) ! streams.value.log match { - case 0 => // Success! - case n => sys.error(s"Native build script exit code: $n") - } -} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..743d692 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,13 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7a3265e Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..098ffce --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Apr 09 22:29:00 PDT 2018 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..e95643d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/local.properties.example b/local.properties.example deleted file mode 100644 index d23c53e..0000000 --- a/local.properties.example +++ /dev/null @@ -1,3 +0,0 @@ -key.alias: your_key_alias -key.store: /path/to/your/key/store -key.store.password: your_key_password diff --git a/project/plugins.sbt b/project/plugins.sbt deleted file mode 100644 index 9dc595e..0000000 --- a/project/plugins.sbt +++ /dev/null @@ -1,5 +0,0 @@ -addSbtPlugin("org.scala-android" % "sbt-android" % "1.7.8") - -addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.10") - -addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.8.2") diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..e7b4def --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':app' diff --git a/src/go b/src/go deleted file mode 160000 index 26db64c..0000000 --- a/src/go +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 26db64c76604b35e756f593d8ce25da5a83af6b6 diff --git a/src/kcptun b/src/kcptun deleted file mode 160000 index a68085f..0000000 --- a/src/kcptun +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a68085ff380fb843ab09edde144f5ef550026c9a diff --git a/src/main/scala/com/github/shadowsocks/plugin/kcptun/BinaryProvider.scala b/src/main/scala/com/github/shadowsocks/plugin/kcptun/BinaryProvider.scala deleted file mode 100644 index f83522d..0000000 --- a/src/main/scala/com/github/shadowsocks/plugin/kcptun/BinaryProvider.scala +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.shadowsocks.plugin.kcptun - -import java.io.{File, FileNotFoundException} - -import android.net.Uri -import android.os.ParcelFileDescriptor -import com.github.shadowsocks.plugin.{NativePluginProvider, PathProvider} - -/** - * @author Mygod - */ -final class BinaryProvider extends NativePluginProvider { - override protected def populateFiles(provider: PathProvider): Unit = provider.addPath("kcptun", "755") - - override def getExecutable: String = getContext.getApplicationInfo.nativeLibraryDir + "/libkcptun.so" - - override def openFile(uri: Uri): ParcelFileDescriptor = uri.getPath match { - case "/kcptun" => ParcelFileDescriptor.open(new File(getExecutable), ParcelFileDescriptor.MODE_READ_ONLY) - case _ => throw new FileNotFoundException() - } -} diff --git a/src/main/scala/com/github/shadowsocks/plugin/kcptun/HelpCallback.scala b/src/main/scala/com/github/shadowsocks/plugin/kcptun/HelpCallback.scala deleted file mode 100644 index cc5c74e..0000000 --- a/src/main/scala/com/github/shadowsocks/plugin/kcptun/HelpCallback.scala +++ /dev/null @@ -1,35 +0,0 @@ -package com.github.shadowsocks.plugin.kcptun - -import com.github.shadowsocks.plugin.PluginOptions - -import scala.io.Source - -/** - * @author Mygod - */ -class HelpCallback extends com.github.shadowsocks.plugin.HelpCallback { - override def produceHelpMessage(options: PluginOptions): CharSequence = { - val process = new ProcessBuilder(getApplicationInfo.nativeLibraryDir + "/libkcptun.so", "--help") - .redirectErrorStream(true) - .start() - process.waitFor() - Source.fromInputStream(process.getInputStream()) - .getLines() - .dropWhile(line => line != "GLOBAL OPTIONS:") - .drop(1) - .takeWhile(line => line.length() > 3) - .filter(line => - !line.startsWith(" --localaddr ") && - !line.startsWith(" --remoteaddr ") && - !line.startsWith(" -c ") && - !line.startsWith(" -V ") && - !line.startsWith(" --fast-open ") && - !line.startsWith(" --help,") && - !line.startsWith(" --version,")) - .mkString("\n") - .replaceAll(" {2,}", "\n") - .replaceAll("--", "") - .replaceAll(" value", "=value;") - .substring(1) // remove 1st \n - } -}