Add remote DNS setting #991

This commit is contained in:
Max Lv
2016-11-30 15:26:49 +08:00
parent a7c729883e
commit d197ec2fc5
10 changed files with 38 additions and 8 deletions
@@ -123,10 +123,11 @@ class ShadowsocksNatService extends BaseService {
, "-c" , getApplicationInfo.dataDir + "/ss-tunnel-nat.conf")
cmd += "-L"
if (profile.route == Route.CHINALIST)
cmd += "114.114.114.114:53"
else
if (profile.remoteDns == null)
cmd += "8.8.8.8:53"
else
cmd += profile.remoteDns + ":53"
if (profile.auth) cmd += "-A"
@@ -42,7 +42,7 @@ object ShadowsocksSettings {
private final val TAG = "ShadowsocksSettings"
private val PROXY_PREFS = Array(Key.name, Key.host, Key.remotePort, Key.localPort, Key.password, Key.method,
Key.auth, Key.kcp, Key.kcpPort, Key.kcpcli)
private val FEATURE_PREFS = Array(Key.route, Key.proxyApps, Key.udpdns, Key.ipv6)
private val FEATURE_PREFS = Array(Key.route, Key.remoteDns, Key.proxyApps, Key.udpdns, Key.ipv6)
// Helper functions
def updateDropDownPreference(pref: Preference, value: String) {
@@ -76,6 +76,10 @@ object ShadowsocksSettings {
case Key.password =>
updateEditTextPreference(pref, profile.password)
pref.setSummary(if (demo) "\u2022" * 32 else "%s")
case Key.remoteDns =>
updateEditTextPreference(pref, profile.remoteDns)
if (profile.remoteDns != null)
pref.setSummary(if (demo) "8.8.8.8" else "%s")
case Key.method => updateDropDownPreference(pref, profile.method)
case Key.route => updateDropDownPreference(pref, profile.route)
case Key.proxyApps => updateSwitchPreference(pref, profile.proxyApps)
@@ -129,6 +133,10 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
profile.route = value.asInstanceOf[String]
app.profileManager.updateProfile(profile)
})
findPreference(Key.remoteDns).setOnPreferenceChangeListener((_, value) => {
profile.remoteDns = value.asInstanceOf[String]
app.profileManager.updateProfile(profile)
})
findPreference(Key.kcp).setOnPreferenceChangeListener((_, value) => {
profile.kcp = value.asInstanceOf[Boolean]
@@ -274,10 +274,11 @@ class ShadowsocksVpnService extends VpnService with BaseService {
, "-c", getApplicationInfo.dataDir + "/ss-tunnel-vpn.conf")
cmd += "-L"
if (profile.route == Route.CHINALIST)
cmd += "114.114.114.114:53"
else
if (profile.remoteDns == null)
cmd += "8.8.8.8:53"
else
cmd += profile.remoteDns + ":53"
if (profile.auth) cmd += "-A"
@@ -46,7 +46,7 @@ object DBHelper {
}
class DBHelper(val context: Context)
extends OrmLiteSqliteOpenHelper(context, DBHelper.PROFILE, null, 20) {
extends OrmLiteSqliteOpenHelper(context, DBHelper.PROFILE, null, 21) {
import DBHelper._
lazy val profileDao: Dao[Profile, Int] = getDao(classOf[Profile])
@@ -125,6 +125,10 @@ class DBHelper(val context: Context)
} else if (oldVersion < 19) {
profileDao.executeRawNoArgs("UPDATE `profile` SET kcpPort = 8399 WHERE kcpPort = 0;")
}
if (oldVersion < 21) {
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN remoteDns VARCHAR DEFAULT '8.8.8.8';")
}
} catch {
case ex: Exception =>
app.track(ex)
@@ -52,6 +52,9 @@ class Profile {
@DatabaseField
var route: String = "all"
@DatabaseField
var remoteDns: String = "8.8.8.8"
@DatabaseField
var proxyApps: Boolean = false
@@ -149,6 +149,7 @@ object Key {
val method = "encMethod"
val remotePort = "remotePortNum"
val localPort = "localPortNum"
val remoteDns = "remoteDns"
val profileTip = "profileTip"