Commit 95916bcd authored by Max Lv's avatar Max Lv

add flush dns cache

parent 1bed08a7
...@@ -5,8 +5,8 @@ import sbtandroid._ ...@@ -5,8 +5,8 @@ import sbtandroid._
import sbtandroid.AndroidKeys._ import sbtandroid.AndroidKeys._
object App { object App {
val version = "1.7.7" val version = "1.8.0"
val versionCode = 44 val versionCode = 45
} }
object General { object General {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_SUPERUSER"/> <uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-feature <uses-feature
android:name="android.hardware.touchscreen" android:name="android.hardware.touchscreen"
......
...@@ -73,6 +73,7 @@ ...@@ -73,6 +73,7 @@
<string name="about_title">Shadowsocks %s</string> <string name="about_title">Shadowsocks %s</string>
<string name="donate">Donate</string> <string name="donate">Donate</string>
<string name="donate_address">http://buildbot.sinaapp.com/donate.html</string> <string name="donate_address">http://buildbot.sinaapp.com/donate.html</string>
<string name="flush_dnscache">Flush DNS Cache</string>
<string name="flushing">Flushing</string>
</resources> </resources>
/* Shadowsocks - A shadowsocks client for Android /*
* Copyright (C) 2012 <max.c.lv@gmail.com> * Shadowsocks - A shadowsocks client for Android
* Copyright (C) 2013 <max.c.lv@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/*
* Shadowsocks - A shadowsocks client for Android
* Copyright (C) 2013 <max.c.lv@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* ___====-_ _-====___
* _--^^^#####// \\#####^^^--_
* _-^##########// ( ) \\##########^-_
* -############// |\^^/| \\############-
* _/############// (@::@) \\############\_
* /#############(( \\// ))#############\
* -###############\\ (oo) //###############-
* -#################\\ / VV \ //#################-
* -###################\\/ \//###################-
* _#/|##########/\######( /\ )######/\##########|\#_
* |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \|
* ` |/ V V ` V \#\| | | |/#/ V ' V V \| '
* ` ` ` ` / | | | | \ ' ' ' '
* ( | | | | )
* __\ | | | | /__
* (vvv(VVV)(VVV)vvv)
*
* HERE BE DRAGONS
*
*/
package com.github.shadowsocks package com.github.shadowsocks
import android.app.Activity import android.app.Activity
......
/* Shadowsocks - A shadowsocks client for Android /*
* Copyright (C) 2012 <max.c.lv@gmail.com> * Shadowsocks - A shadowsocks client for Android
* Copyright (C) 2013 <max.c.lv@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -35,6 +36,7 @@ ...@@ -35,6 +36,7 @@
* HERE BE DRAGONS * HERE BE DRAGONS
* *
*/ */
package com.github.shadowsocks package com.github.shadowsocks
import android.app._ import android.app._
......
/* Shadowsocks - A shadowsocks client for Android /*
* Shadowsocks - A shadowsocks client for Android
* Copyright (C) 2012 <max.c.lv@gmail.com> * Copyright (C) 2012 <max.c.lv@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
...@@ -124,7 +125,7 @@ object Shadowsocks { ...@@ -124,7 +125,7 @@ object Shadowsocks {
} }
} }
class FeatureFragment extends UnifiedPreferenceFragment with OnSharedPreferenceChangeListener{ class FeatureFragment extends UnifiedPreferenceFragment with OnSharedPreferenceChangeListener {
var receiver: BroadcastReceiver = null var receiver: BroadcastReceiver = null
...@@ -269,7 +270,7 @@ class Shadowsocks ...@@ -269,7 +270,7 @@ class Shadowsocks
private def copyFile(in: InputStream, out: OutputStream) { private def copyFile(in: InputStream, out: OutputStream) {
val buffer: Array[Byte] = new Array[Byte](1024) val buffer: Array[Byte] = new Array[Byte](1024)
var read: Int = 0 var read: Int = 0
while ({ while ( {
read = in.read(buffer) read = in.read(buffer)
read read
} != -1) { } != -1) {
...@@ -363,8 +364,6 @@ class Shadowsocks ...@@ -363,8 +364,6 @@ class Shadowsocks
setHeaderRes(R.xml.shadowsocks_headers) setHeaderRes(R.xml.shadowsocks_headers)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
val switchLayout = getLayoutInflater val switchLayout = getLayoutInflater
.inflate(R.layout.layout_switch, null) .inflate(R.layout.layout_switch, null)
.asInstanceOf[RelativeLayout] .asInstanceOf[RelativeLayout]
...@@ -427,6 +426,10 @@ class Shadowsocks ...@@ -427,6 +426,10 @@ class Shadowsocks
.add(0, 1, 1, R.string.about) .add(0, 1, 1, R.string.about)
.setIcon(android.R.drawable.ic_menu_info_details) .setIcon(android.R.drawable.ic_menu_info_details)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT) .setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT)
menu
.add(0, 2, 2, R.string.flush_dnscache)
.setIcon(android.R.drawable.ic_menu_revert)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT)
true true
} }
...@@ -453,6 +456,10 @@ class Shadowsocks ...@@ -453,6 +456,10 @@ class Shadowsocks
EasyTracker.getTracker.sendEvent(Shadowsocks.TAG, "about", getVersionName, 0L) EasyTracker.getTracker.sendEvent(Shadowsocks.TAG, "about", getVersionName, 0L)
showAbout() showAbout()
} }
case 2 => {
EasyTracker.getTracker.sendEvent(Shadowsocks.TAG, "flush_dnscache", getVersionName, 0L)
flushDnsCache()
}
} }
super.onOptionsItemSelected(item) super.onOptionsItemSelected(item)
} }
...@@ -559,6 +566,20 @@ class Shadowsocks ...@@ -559,6 +566,20 @@ class Shadowsocks
} }
} }
private def flushDnsCache() {
clearDialog()
progressDialog = ProgressDialog.show(this, "", getString(R.string.flushing), true, true)
val h: Handler = new Handler {
override def handleMessage(msg: Message) {
clearDialog()
}
}
spawn {
Utils.toggleAirplaneMode(getBaseContext)
h.sendEmptyMessage(0)
}
}
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
resultCode match { resultCode match {
case Activity.RESULT_OK => { case Activity.RESULT_OK => {
......
/* Shadowsocks - A shadowsocks client for Android /*
* Copyright (C) 2012 <max.c.lv@gmail.com> * Shadowsocks - A shadowsocks client for Android
* Copyright (C) 2013 <max.c.lv@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/*
* Shadowsocks - A shadowsocks client for Android
* Copyright (C) 2013 <max.c.lv@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* ___====-_ _-====___
* _--^^^#####// \\#####^^^--_
* _-^##########// ( ) \\##########^-_
* -############// |\^^/| \\############-
* _/############// (@::@) \\############\_
* /#############(( \\// ))#############\
* -###############\\ (oo) //###############-
* -#################\\ / VV \ //#################-
* -###################\\/ \//###################-
* _#/|##########/\######( /\ )######/\##########|\#_
* |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \|
* ` |/ V V ` V \#\| | | |/#/ V ' V V \| '
* ` ` ` ` / | | | | \ ' ' ' '
* ( | | | | )
* __\ | | | | /__
* (vvv(VVV)(VVV)vvv)
*
* HERE BE DRAGONS
*
*/
package com.github.shadowsocks package com.github.shadowsocks
import android.app.backup.{SharedPreferencesBackupHelper, BackupAgentHelper} import android.app.backup.{SharedPreferencesBackupHelper, BackupAgentHelper}
......
/* Shadowsocks - A shadowsocks client for Android /*
* Copyright (C) 2012 <max.c.lv@gmail.com> * Shadowsocks - A shadowsocks client for Android
* Copyright (C) 2013 <max.c.lv@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/* Shadowsocks - A shadowsocks client for Android /*
* Copyright (C) 2012 <max.c.lv@gmail.com> * Shadowsocks - A shadowsocks client for Android
* Copyright (C) 2013 <max.c.lv@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -35,6 +36,7 @@ ...@@ -35,6 +36,7 @@
* HERE BE DRAGONS * HERE BE DRAGONS
* *
*/ */
package com.github.shadowsocks package com.github.shadowsocks
import android.app.Notification import android.app.Notification
......
/* Shadowsocks - A shadowsocks client for Android /*
* Shadowsocks - A shadowsocks client for Android
* Copyright (C) 2012 <max.c.lv@gmail.com> * Copyright (C) 2012 <max.c.lv@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
...@@ -50,6 +51,8 @@ import org.xbill.DNS._ ...@@ -50,6 +51,8 @@ import org.xbill.DNS._
import scala.Some import scala.Some
import android.graphics.{Canvas, Bitmap} import android.graphics.{Canvas, Bitmap}
import android.app.ActivityManager import android.app.ActivityManager
import android.os.Build
import android.provider.Settings
object Config { object Config {
val SHADOWSOCKS = "{\"server\": [%s], \"server_port\": %d, \"local_port\": %d, \"password\": %s, \"timeout\": %d}" val SHADOWSOCKS = "{\"server\": [%s], \"server_port\": %d, \"local_port\": %d, \"password\": %s, \"timeout\": %d}"
...@@ -100,7 +103,11 @@ object Config { ...@@ -100,7 +103,11 @@ object Config {
def printToFile(f: java.io.File)(op: java.io.PrintWriter => Unit) { def printToFile(f: java.io.File)(op: java.io.PrintWriter => Unit) {
val p = new java.io.PrintWriter(f) val p = new java.io.PrintWriter(f)
try { op(p) } finally { p.close() } try {
op(p)
} finally {
p.close()
}
} }
} }
...@@ -252,6 +259,38 @@ object Utils { ...@@ -252,6 +259,38 @@ object Utils {
var data_path: String = null var data_path: String = null
var rootTries = 0 var rootTries = 0
// Blocked > 3 seconds
def toggleAirplaneMode(context: Context) {
if (Build.VERSION.SDK_INT >= 17) {
toggleAboveApiLevel17()
} else {
toggleBelowApiLevel17(context)
}
}
private def toggleAboveApiLevel17() {
// Android 4.2 and above
Utils.runRootCommand("settings put global airplane_mode_on 1\n"
+ "am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true\n"
+ "settings put global airplane_mode_on 0\n"
+ "am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false\n"
)
}
private def toggleBelowApiLevel17(context: Context) {
// Android 4.2 below
Settings.System.putInt(context.getContentResolver, Settings.System.AIRPLANE_MODE_ON, 1)
val enableIntent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED)
enableIntent.putExtra("state", true)
context.sendBroadcast(enableIntent)
Thread.sleep(3000)
Settings.System.putInt(context.getContentResolver, Settings.System.AIRPLANE_MODE_ON, 0)
val disableIntent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED)
disableIntent.putExtra("state", false)
context.sendBroadcast(disableIntent)
}
def isServiceStarted(name: String, context: Context): Boolean = { def isServiceStarted(name: String, context: Context): Boolean = {
import scala.collection.JavaConversions._ import scala.collection.JavaConversions._
......
/*
* Shadowsocks - A shadowsocks client for Android
* Copyright (C) 2013 <max.c.lv@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* ___====-_ _-====___
* _--^^^#####// \\#####^^^--_
* _-^##########// ( ) \\##########^-_
* -############// |\^^/| \\############-
* _/############// (@::@) \\############\_
* /#############(( \\// ))#############\
* -###############\\ (oo) //###############-
* -#################\\ / VV \ //#################-
* -###################\\/ \//###################-
* _#/|##########/\######( /\ )######/\##########|\#_
* |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \|
* ` |/ V V ` V \#\| | | |/#/ V ' V V \| '
* ` ` ` ` / | | | | \ ' ' ' '
* ( | | | | )
* __\ | | | | /__
* (vvv(VVV)(VVV)vvv)
*
* HERE BE DRAGONS
*
*/
package com.github.shadowsocks.preferences package com.github.shadowsocks.preferences
import android.content.Context import android.content.Context
......
/*
* Shadowsocks - A shadowsocks client for Android
* Copyright (C) 2013 <max.c.lv@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* ___====-_ _-====___
* _--^^^#####// \\#####^^^--_
* _-^##########// ( ) \\##########^-_
* -############// |\^^/| \\############-
* _/############// (@::@) \\############\_
* /#############(( \\// ))#############\
* -###############\\ (oo) //###############-
* -#################\\ / VV \ //#################-
* -###################\\/ \//###################-
* _#/|##########/\######( /\ )######/\##########|\#_
* |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \|
* ` |/ V V ` V \#\| | | |/#/ V ' V V \| '
* ` ` ` ` / | | | | \ ' ' ' '
* ( | | | | )
* __\ | | | | /__
* (vvv(VVV)(VVV)vvv)
*
* HERE BE DRAGONS
*
*/
package com.github.shadowsocks.preferences package com.github.shadowsocks.preferences
import android.content.Context import android.content.Context
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment