Commit 6c047eca authored by Mygod's avatar Mygod

Add error message if failed

parent a31e7538
......@@ -7,6 +7,7 @@ import android.content.{Intent, SharedPreferences}
import android.net.Uri
import android.os.Bundle
import android.preference.{Preference, PreferenceFragment, SwitchPreference}
import android.support.design.widget.Snackbar
import android.support.v7.app.AlertDialog
import android.webkit.{WebView, WebViewClient}
import com.github.shadowsocks.ShadowsocksApplication.app
......@@ -158,7 +159,9 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
tfo.setChecked(TcpFastOpen.sendEnabled)
tfo.setOnPreferenceChangeListener((_, v) => {
val value = v.asInstanceOf[Boolean]
TcpFastOpen.enabled(value)
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
})
if (!TcpFastOpen.supported) {
......
......@@ -4,6 +4,8 @@ import java.io.File
import eu.chainfire.libsuperuser.Shell
import scala.collection.JavaConverters._
/**
* @author Mygod
*/
......@@ -26,11 +28,24 @@ object TcpFastOpen {
file.canRead && (Utils.readAllLines(file).toInt & 1) > 0
}
def enabled(value: Boolean) = if (supported) {
def enabled(value: Boolean) = if (true) {
val fastopen = "echo " + (if (value) 3 else 0) + " > /proc/sys/net/ipv4/tcp_fastopen"
Shell.SU.run(Array(
"mount -o remount,rw /system && " + fastopen + " && echo '#!/system/bin/sh\n" + fastopen +
"' > /etc/init.d/tcp_fastopen && chmod 755 /etc/init.d/tcp_fastopen",
"mount -o remount,ro /system"))
}
Shell.run("su", Array(
"if " + fastopen + "; then",
" success=-1",
" if mount -o remount,rw /system; then",
" echo '#!/system/bin/sh",
fastopen + "' > /etc/init.d/tcp_fastopen && chmod 755 /etc/init.d/tcp_fastopen",
" success=$?",
" mount -o remount,ro /system",
" fi",
" if [ $success -eq 0 ]; then",
" echo Success.",
" else",
" echo Warning: Unable to create boot script.",
" fi",
"else",
" echo Failed.",
"fi"), null, true).asScala.mkString("\n")
} else null
}
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