@@ -112,7 +112,6 @@
|
||||
|
||||
<SwitchPreference
|
||||
android:key="tcp_fastopen"
|
||||
android:persistent="false"
|
||||
android:summary="@string/tcp_fastopen_summary"
|
||||
android:title="TCP Fast Open"/>
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ import android.app.Application
|
||||
import android.preference.PreferenceManager
|
||||
import android.support.v7.app.AppCompatDelegate
|
||||
import com.github.shadowsocks.database.{DBHelper, ProfileManager}
|
||||
import com.github.shadowsocks.utils.{Key, Utils}
|
||||
import com.github.shadowsocks.utils.{Key, Utils, TcpFastOpen}
|
||||
import com.google.android.gms.analytics.{GoogleAnalytics, HitBuilders, StandardExceptionParser}
|
||||
import com.google.android.gms.common.api.ResultCallback
|
||||
import com.google.android.gms.tagmanager.{ContainerHolder, TagManager}
|
||||
@@ -111,6 +111,13 @@ class ShadowsocksApplication extends Application {
|
||||
}
|
||||
}
|
||||
pending.setResultCallback(callback, 2, TimeUnit.SECONDS)
|
||||
|
||||
// TFO
|
||||
val tfo = settings.getBoolean(Key.tfo, false)
|
||||
if (tfo && !TcpFastOpen.isEnabled)
|
||||
{
|
||||
TcpFastOpen.enabled(true)
|
||||
}
|
||||
}
|
||||
|
||||
def refreshContainerHolder {
|
||||
|
||||
@@ -105,7 +105,7 @@ class ShadowsocksNatService extends BaseService {
|
||||
|
||||
if (profile.auth) cmd += "-A"
|
||||
|
||||
if (TcpFastOpen.sendEnabled) cmd += "--fast-open"
|
||||
if (TcpFastOpen.isEnabled) cmd += "--fast-open"
|
||||
|
||||
if (profile.route != Route.ALL) {
|
||||
cmd += "--acl"
|
||||
|
||||
@@ -155,14 +155,17 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
|
||||
}
|
||||
switch.setChecked(BootReceiver.getEnabled(activity))
|
||||
|
||||
val tfo = findPreference("tcp_fastopen").asInstanceOf[SwitchPreference]
|
||||
tfo.setChecked(TcpFastOpen.sendEnabled)
|
||||
if (getPreferenceManager.getSharedPreferences.getBoolean(Key.tfo, false) && !TcpFastOpen.isEnabled) {
|
||||
TcpFastOpen.enabled(true)
|
||||
}
|
||||
val tfo = findPreference(Key.tfo).asInstanceOf[SwitchPreference]
|
||||
tfo.setChecked(TcpFastOpen.isEnabled)
|
||||
tfo.setOnPreferenceChangeListener((_, v) => {
|
||||
val value = v.asInstanceOf[Boolean]
|
||||
val result = TcpFastOpen.enabled(value)
|
||||
if (result != null && result != "Success.")
|
||||
Snackbar.make(activity.findViewById(android.R.id.content), result, Snackbar.LENGTH_LONG).show()
|
||||
value == TcpFastOpen.sendEnabled
|
||||
value == TcpFastOpen.isEnabled
|
||||
})
|
||||
if (!TcpFastOpen.supported) {
|
||||
tfo.setEnabled(false)
|
||||
|
||||
@@ -266,7 +266,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
cmd += (getApplicationInfo.dataDir + "/acl.list")
|
||||
}
|
||||
|
||||
if (TcpFastOpen.sendEnabled) cmd += "--fast-open"
|
||||
if (TcpFastOpen.isEnabled) cmd += "--fast-open"
|
||||
|
||||
if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" "))
|
||||
|
||||
|
||||
@@ -171,6 +171,8 @@ object Key {
|
||||
val kcp = "kcp"
|
||||
val kcpPort = "kcpPort"
|
||||
val kcpcli = "kcpcli"
|
||||
|
||||
val tfo = "tcp_fastopen"
|
||||
}
|
||||
|
||||
object State {
|
||||
|
||||
@@ -23,28 +23,18 @@ object TcpFastOpen {
|
||||
case _ => false
|
||||
}
|
||||
|
||||
def sendEnabled = {
|
||||
def isEnabled = {
|
||||
val file = new File("/proc/sys/net/ipv4/tcp_fastopen")
|
||||
file.canRead && (Utils.readAllLines(file).toInt & 1) > 0
|
||||
}
|
||||
|
||||
def enabled(value: Boolean) =
|
||||
Shell.run("su", Array(
|
||||
def enabled(value: Boolean): String = {
|
||||
val res = Shell.run("su", Array(
|
||||
"if echo " + (if (value) 3 else 0) + " > /proc/sys/net/ipv4/tcp_fastopen; then",
|
||||
" success=-1",
|
||||
" if mount -o rw,remount /dev/block/platform/msm_sdcc.1/by-name/system /system; then",
|
||||
if (value) " echo '#!/system/bin/sh\n" +
|
||||
"echo 3 > /proc/sys/net/ipv4/tcp_fastopen' > /etc/init.d/tcp_fastopen && chmod 755 /etc/init.d/tcp_fastopen"
|
||||
else "rm -f /etc/init.d/tcp_fastopen",
|
||||
" success=$?",
|
||||
" mount -o ro,remount /dev/block/platform/msm_sdcc.1/by-name/system /system",
|
||||
" fi",
|
||||
" if [ $success -eq 0 ]; then",
|
||||
" echo Success.",
|
||||
" else",
|
||||
" echo Warning: Unable to create boot script.",
|
||||
" fi",
|
||||
" echo Success.",
|
||||
"else",
|
||||
" echo Failed.",
|
||||
"fi"), null, true).asScala.mkString("\n")
|
||||
"fi"), null, true)
|
||||
if (res != null) res.asScala.mkString("\n") else null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user