Commit 8716c202 authored by Mygod's avatar Mygod

Refine code style

parent 734056ea
...@@ -110,7 +110,7 @@ object Core { ...@@ -110,7 +110,7 @@ object Core {
// handle data restored/crash // handle data restored/crash
if (Build.VERSION.SDK_INT >= 24 && DataStore.directBootAware && if (Build.VERSION.SDK_INT >= 24 && DataStore.directBootAware &&
app.getSystemService<UserManager>()?.isUserUnlocked == true) DirectBoot.flushTrafficStats() app.getSystemService<UserManager>()?.isUserUnlocked == true) DirectBoot.flushTrafficStats()
if (DataStore.tcpFastOpen && !TcpFastOpen.sendEnabled) TcpFastOpen.enabledAsync() if (DataStore.tcpFastOpen && !TcpFastOpen.sendEnabled) TcpFastOpen.enableAsync()
if (DataStore.publicStore.getLong(Key.assetUpdateTime, -1) != packageInfo.lastUpdateTime) { if (DataStore.publicStore.getLong(Key.assetUpdateTime, -1) != packageInfo.lastUpdateTime) {
val assetManager = app.assets val assetManager = app.assets
for (dir in arrayOf("acl", "overture")) for (dir in arrayOf("acl", "overture"))
......
...@@ -179,7 +179,7 @@ object PluginManager { ...@@ -179,7 +179,7 @@ object PluginManager {
Os.chmod(file.absolutePath, when (cursor.getType(1)) { Os.chmod(file.absolutePath, when (cursor.getType(1)) {
Cursor.FIELD_TYPE_INTEGER -> cursor.getInt(1) Cursor.FIELD_TYPE_INTEGER -> cursor.getInt(1)
Cursor.FIELD_TYPE_STRING -> cursor.getString(1).toInt(8) Cursor.FIELD_TYPE_STRING -> cursor.getString(1).toInt(8)
else -> throw IllegalArgumentException() else -> throw IllegalArgumentException("File mode should be of type int")
}) })
if (path == options.id) initialized = true if (path == options.id) initialized = true
} while (cursor.moveToNext()) } while (cursor.moveToNext())
......
...@@ -48,14 +48,13 @@ object TcpFastOpen { ...@@ -48,14 +48,13 @@ object TcpFastOpen {
return file.canRead() && file.bufferedReader().use { it.readText() }.trim().toInt() and 1 > 0 return file.canRead() && file.bufferedReader().use { it.readText() }.trim().toInt() and 1 > 0
} }
fun enabled(): String? { fun enable(): String? {
return try { return try {
val process = ProcessBuilder("su", "-c", "echo 3 > $PATH") ProcessBuilder("su", "-c", "echo 3 > $PATH").redirectErrorStream(true).start()
.redirectErrorStream(true).start() .inputStream.bufferedReader().readText()
process.inputStream.bufferedReader().readText()
} catch (e: IOException) { } catch (e: IOException) {
e.localizedMessage e.localizedMessage
} }
} }
fun enabledAsync() = thread("TcpFastOpen") { enabled() }.join(1000) fun enableAsync() = thread("TcpFastOpen") { enable() }.join(1000)
} }
...@@ -55,7 +55,7 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() { ...@@ -55,7 +55,7 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() {
tfo.isChecked = DataStore.tcpFastOpen tfo.isChecked = DataStore.tcpFastOpen
tfo.setOnPreferenceChangeListener { _, value -> tfo.setOnPreferenceChangeListener { _, value ->
if (value as Boolean && !TcpFastOpen.sendEnabled) { if (value as Boolean && !TcpFastOpen.sendEnabled) {
val result = TcpFastOpen.enabled()?.trim() val result = TcpFastOpen.enable()?.trim()
if (TcpFastOpen.sendEnabled) true else { if (TcpFastOpen.sendEnabled) true else {
(activity as MainActivity).snackbar( (activity as MainActivity).snackbar(
if (result.isNullOrEmpty()) getText(R.string.tcp_fastopen_failure) else result).show() if (result.isNullOrEmpty()) getText(R.string.tcp_fastopen_failure) else result).show()
......
...@@ -171,7 +171,7 @@ class MainPreferenceFragment : LeanbackPreferenceFragment(), ShadowsocksConnecti ...@@ -171,7 +171,7 @@ class MainPreferenceFragment : LeanbackPreferenceFragment(), ShadowsocksConnecti
tfo.isChecked = DataStore.tcpFastOpen tfo.isChecked = DataStore.tcpFastOpen
tfo.setOnPreferenceChangeListener { _, value -> tfo.setOnPreferenceChangeListener { _, value ->
if (value as Boolean && !TcpFastOpen.sendEnabled) { if (value as Boolean && !TcpFastOpen.sendEnabled) {
val result = TcpFastOpen.enabled()?.trim() val result = TcpFastOpen.enable()?.trim()
if (TcpFastOpen.sendEnabled) true else { if (TcpFastOpen.sendEnabled) true else {
Toast.makeText(activity, if (result.isNullOrEmpty()) Toast.makeText(activity, if (result.isNullOrEmpty())
getText(R.string.tcp_fastopen_failure) else result, Toast.LENGTH_SHORT).show() getText(R.string.tcp_fastopen_failure) else result, Toast.LENGTH_SHORT).show()
......
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