From 8923c93b6e984f54e8f15a64aef382fabf437666 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sat, 28 Jun 2014 19:02:38 +0800 Subject: [PATCH] update travis --- .gitignore | 2 + .travis.yml | 3 +- build-ndk.sh | 18 +++++ jni/Application.mk.16 | 4 + jni/{Application.mk => Application.mk.9} | 0 .../com/github/shadowsocks/Shadowsocks.scala | 75 ++++++++++++------- .../shadowsocks/ShadowsocksNatService.scala | 30 ++++++-- 7 files changed, 94 insertions(+), 38 deletions(-) create mode 100644 jni/Application.mk.16 rename jni/{Application.mk => Application.mk.9} (100%) diff --git a/.gitignore b/.gitignore index bae30917..2d654430 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,8 @@ src/main/libs src/main/assets/armeabi src/main/assets/armeabi-v7a src/main/assets/x86 +src/main/assets/api-16/ src/main/jni +jni/Application.mk obj libs diff --git a/.travis.yml b/.travis.yml index bed6d677..ee7fd518 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,8 @@ before_install: - export ANDROID_NDK_HOME=`pwd`/android-ndk-r9d - export ANDROID_HOME=`pwd`/android-sdk-linux - export PATH=${PATH}:${ANDROID_NDK_HOME}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools -- echo -e "y\ny\ny" | android update sdk --filter tools,platform-tools,build-tools-19.0.3,android-19,extra-google-m2repository,extra-android-m2repository --no-ui --no-https -a +- echo "y" | android update sdk --filter tools,platform-tools,build-tools-19.0.3,android-19,extra-google-m2repository --no-ui --no-https -a +- echo "y" | android update sdk --filter extra-android-m2repository --no-ui --no-https -a - ln -s $ANDROID_HOME/build-tools/20.0.0/zipalign $ANDROID_HOME/tools/ install: - gem install --version 0.8.9 faraday diff --git a/build-ndk.sh b/build-ndk.sh index 6678ff04..170dfc7e 100755 --- a/build-ndk.sh +++ b/build-ndk.sh @@ -1,4 +1,7 @@ #!/bin/bash + +# Target 9 +cp jni/Application.mk.9 jni/Application.mk ndk-build clean ndk-build mkdir -p src/main/assets/armeabi @@ -12,3 +15,18 @@ do done rm -rf src/main/jni mv libs src/main/jni + +# Target 16 +cp jni/Application.mk.16 jni/Application.mk +ndk-build clean +ndk-build +mkdir -p src/main/assets/api-16/armeabi +mkdir -p src/main/assets/api-16/armeabi-v7a +mkdir -p src/main/assets/api-16/x86 +for app in pdnsd redsocks ss-tunnel +do + mv libs/armeabi/$app src/main/assets/api-16/armeabi/ + mv libs/armeabi-v7a/$app src/main/assets/api-16/armeabi-v7a/ + mv libs/x86/$app src/main/assets/api-16/x86/ +done + diff --git a/jni/Application.mk.16 b/jni/Application.mk.16 new file mode 100644 index 00000000..73844094 --- /dev/null +++ b/jni/Application.mk.16 @@ -0,0 +1,4 @@ +APP_ABI := armeabi armeabi-v7a x86 +APP_PLATFORM := android-16 +APP_STL := stlport_static +NDK_TOOLCHAIN_VERSION := 4.8 diff --git a/jni/Application.mk b/jni/Application.mk.9 similarity index 100% rename from jni/Application.mk rename to jni/Application.mk.9 diff --git a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala index d087bf4e..e559a99f 100644 --- a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala +++ b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala @@ -38,41 +38,37 @@ */ package com.github.shadowsocks +import java.util +import java.io.{OutputStream, InputStream, ByteArrayInputStream, ByteArrayOutputStream, IOException, FileOutputStream} + +import android.app.backup.BackupManager import android.app.{Activity, AlertDialog, ProgressDialog} import android.content._ +import android.content.pm.{PackageInfo, PackageManager} import android.content.res.AssetManager -import android.graphics.{Color, Bitmap, Typeface} +import android.graphics.{Bitmap, Color, Typeface} +import android.net.{Uri, VpnService} import android.os._ import android.preference._ -import android.util.{Log, DisplayMetrics} +import android.util.{DisplayMetrics, Log} import android.view._ +import android.webkit.{WebView, WebViewClient} import android.widget._ -import com.google.analytics.tracking.android.{MapBuilder, EasyTracker} -import de.keyboardsurfer.android.widget.crouton.{Crouton, Style, Configuration} -import java.util.Hashtable import com.actionbarsherlock.app.SherlockPreferenceActivity -import org.jraf.android.backport.switchwidget.Switch -import android.content.pm.{PackageInfo, PackageManager} -import android.net.{Uri, VpnService} -import android.webkit.{WebViewClient, WebView} -import android.app.backup.BackupManager -import scala.concurrent.ops._ -import com.google.android.gms.ads.{AdRequest, AdSize, AdView} -import net.simonvt.menudrawer.MenuDrawer - +import com.github.shadowsocks.aidl.{IShadowsocksService, IShadowsocksServiceCallback} import com.github.shadowsocks.database._ -import scala.collection.mutable.{ArrayBuffer, ListBuffer} -import com.github.shadowsocks.database.Profile -import com.nostra13.universalimageloader.core.download.BaseImageDownloader -import com.github.shadowsocks.preferences.{ProfileEditTextPreference, PasswordEditTextPreference, SummaryEditTextPreference} +import com.github.shadowsocks.preferences.{PasswordEditTextPreference, ProfileEditTextPreference, SummaryEditTextPreference} import com.github.shadowsocks.utils._ +import com.google.analytics.tracking.android.{EasyTracker, MapBuilder} +import com.google.android.gms.ads.{AdRequest, AdSize, AdView} import com.google.zxing.integration.android.IntentIntegrator -import com.github.shadowsocks.aidl.{IShadowsocksServiceCallback, IShadowsocksService} -import java.io._ -import scala.Some -import com.github.shadowsocks.database.Item -import com.github.shadowsocks.database.Category -import com.github.shadowsocks.utils.Console +import com.nostra13.universalimageloader.core.download.BaseImageDownloader +import de.keyboardsurfer.android.widget.crouton.{Configuration, Crouton, Style} +import net.simonvt.menudrawer.MenuDrawer +import org.jraf.android.backport.switchwidget.Switch + +import scala.collection.mutable.{ArrayBuffer, ListBuffer} +import scala.concurrent.ops._ class ProfileIconDownloader(context: Context, connectTimeout: Int, readTimeout: Int) extends BaseImageDownloader(context, connectTimeout, readTimeout) { @@ -113,7 +109,7 @@ object Typefaces { } private final val TAG = "Typefaces" - private final val cache = new Hashtable[String, Typeface] + private final val cache = new util.Hashtable[String, Typeface] } object Shadowsocks { @@ -128,8 +124,8 @@ object Shadowsocks { val FEATRUE_PREFS = Array(Key.isGFWList, Key.isGlobalProxy, Key.proxyedApps, Key.isTrafficStat, Key.isUdpDns, Key.isAutoConnect) - val EXECUTABLES = Array(Executable.IPTABLES, Executable.PDNSD, Executable.REDSOCKS, - Executable.SS_LOCAL, Executable.SS_TUNNEL, Executable.TUN2SOCKS) + val SYSTEM_EXECUTABLES = Array(Executable.PDNSD, Executable.REDSOCKS,Executable.SS_TUNNEL) + val EXECUTABLES = Array(Executable.IPTABLES) ++ SYSTEM_EXECUTABLES // Helper functions def updateListPreference(pref: Preference, value: String) { @@ -427,7 +423,7 @@ class Shadowsocks if (settings.getString(Key.proxy, "") == "198.199.101.152") { val layoutView = { if (Build.VERSION.SDK_INT > 10) { - drawer.getContentContainer.asInstanceOf[ViewGroup].getChildAt(0) + drawer.getContentContainer.getChildAt(0) } else { getLayoutView(drawer.getContentContainer.getParent) } @@ -803,9 +799,30 @@ class Shadowsocks new BackupManager(this).dataChanged() } + def copyToSystem() { + val ab = new ArrayBuffer[String] + ab.append("mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system") + for (executable <- Shadowsocks.SYSTEM_EXECUTABLES) { + ab.append("cp %s%s /system/bin/".format(Path.BASE, executable)) + } + ab.append("mount -o ro,remount -t yaffs2 /dev/block/mtdblock3 /system") + Console.runRootCommand(ab.toArray) + + } + def reset() { + crash_recovery() - copyAssets(System.getABI) + + if (Build.VERSION.SDK_INT >= 16) { + copyAssets("api-16/" + System.getABI) + } else { + copyAssets(System.getABI) + } + + if (Build.VERSION.SDK_INT >= 20) { + copyToSystem() + } val ab = new ArrayBuffer[String] for (executable <- Shadowsocks.EXECUTABLES) { diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala index 93163739..3e350478 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala @@ -118,10 +118,14 @@ class ShadowsocksNatService extends Service with BaseService { }) } - val args = (Path.BASE + - "ss-local -b 127.0.0.1 -s %s -p %d -l %d -k %s -m %s -f " + + val raw_args = ("ss-local -b 127.0.0.1 -s %s -p %d -l %d -k %s -m %s -f " + Path.BASE + "ss-local.pid") .format(config.proxy, config.remotePort, config.localPort, config.sitekey, config.encMethod) + val args = if (Build.VERSION.SDK_INT >= 20) { + raw_args + } else { + Path.BASE + raw_args + } val cmd = if (config.isGFWList && isACLEnabled) args + " --acl " + Path.BASE + "chn.acl" else args if (BuildConfig.DEBUG) Log.d(TAG, cmd) @@ -129,9 +133,8 @@ class ShadowsocksNatService extends Service with BaseService { } def startDnsDaemon() { - val cmd = if (config.isUdpDns) { - (Path.BASE + - "ss-tunnel -b 127.0.0.1 -s '%s' -p '%d' -l '%d' -k '%s' -m '%s' -L 8.8.8.8:53 -u -f " + + val args = if (config.isUdpDns) { + ("ss-tunnel -b 127.0.0.1 -s '%s' -p '%d' -l '%d' -k '%s' -m '%s' -L 8.8.8.8:53 -u -f " + Path.BASE + "ss-tunnel.pid") .format(config.proxy, config.remotePort, 8153, config.sitekey, config.encMethod) } else { @@ -144,7 +147,13 @@ class ShadowsocksNatService extends Service with BaseService { ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => { p.println(conf) }) - Path.BASE + "pdnsd -c " + Path.BASE + "pdnsd.conf" + "pdnsd -c " + Path.BASE + "pdnsd.conf" + } + + val cmd = if (Build.VERSION.SDK_INT >= 20) { + args + } else { + Path.BASE + args } if (BuildConfig.DEBUG) Log.d(TAG, cmd) Console.runRootCommand(cmd) @@ -164,11 +173,16 @@ class ShadowsocksNatService extends Service with BaseService { def startRedsocksDaemon() { val conf = ConfigUtils.REDSOCKS.format(config.localPort) - val cmd = "%sredsocks -p %sredsocks.pid -c %sredsocks.conf" - .format(Path.BASE, Path.BASE, Path.BASE) + val args = "redsocks -p %sredsocks.pid -c %sredsocks.conf" + .format(Path.BASE, Path.BASE) ConfigUtils.printToFile(new File(Path.BASE + "redsocks.conf"))(p => { p.println(conf) }) + val cmd = if (Build.VERSION.SDK_INT >= 20) { + args + } else { + Path.BASE + args + } Console.runRootCommand(cmd) }