Move config files to files directory

It looks nicer.

Other changes btw:

* Removes duplicated logcats from GuardedProcess;
* local_port is moved to command line options since that's not sensitive;
* pdnsd uses cache dir;
* Refinements to Utils.
This commit is contained in:
Mygod
2017-01-20 17:57:28 +08:00
committed by Max Lv
parent 7491a667a5
commit 2e3baa727d
13 changed files with 93 additions and 142 deletions
@@ -37,6 +37,8 @@ object IOUtils {
}
}
def writeString(file: File, content: String): Unit =
autoClose(new FileWriter(file))(writer => writer.write(content))
def writeString(file: String, content: String): Unit =
autoClose(new FileWriter(file))(writer => writer.write(content))
@@ -25,6 +25,7 @@ import java.io.File
import eu.chainfire.libsuperuser.Shell
import scala.collection.JavaConverters._
import scala.io.Source
/**
* @author Mygod
@@ -45,7 +46,7 @@ object TcpFastOpen {
def sendEnabled: Boolean = {
val file = new File("/proc/sys/net/ipv4/tcp_fastopen")
file.canRead && (Utils.readAllLines(file).toInt & 1) > 0
file.canRead && (Source.fromFile(file).mkString.toInt & 1) > 0
}
def enabled(value: Boolean): String = if (sendEnabled != value) {
@@ -32,7 +32,7 @@ import com.github.shadowsocks.ShadowsocksApplication.app
class TrafficMonitorThread(context: Context) extends Thread {
val TAG = "TrafficMonitorThread"
lazy val PATH: String = context.getApplicationInfo.dataDir + "/stat_path"
val stat = new File(context.getFilesDir, "/stat_path")
@volatile var serverSocket: LocalServerSocket = _
@volatile var isRunning: Boolean = true
@@ -55,11 +55,11 @@ class TrafficMonitorThread(context: Context) extends Thread {
override def run() {
new File(PATH).delete()
stat.delete()
try {
val localSocket = new LocalSocket
localSocket.bind(new LocalSocketAddress(PATH, LocalSocketAddress.Namespace.FILESYSTEM))
localSocket.bind(new LocalSocketAddress(stat.getAbsolutePath, LocalSocketAddress.Namespace.FILESYSTEM))
serverSocket = new LocalServerSocket(localSocket.getFileDescriptor)
} catch {
case e: IOException =>
@@ -20,10 +20,8 @@
package com.github.shadowsocks.utils
import java.io.File
import java.net._
import java.security.MessageDigest
import java.util.Scanner
import android.content.pm.PackageManager
import android.content.{Context, Intent}
@@ -78,22 +76,6 @@ object Utils {
toast
}
def readAllLines(f: File): String = {
val scanner = new Scanner(f)
try {
scanner.useDelimiter("\\Z")
scanner.next()
} finally scanner.close()
}
def printToFile(f: java.io.File)(op: java.io.PrintWriter => Unit) {
val p = new java.io.PrintWriter(f)
try {
op(p)
} finally {
p.close()
}
}
def resolve(host: String, addrType: Int): Option[String] = {
try {
val lookup = new Lookup(host, addrType)
@@ -131,20 +113,16 @@ object Utils {
/**
* If there exists a valid IPv6 interface
*/
def isIPv6Support: Boolean = {
try {
for (intf <- enumerationAsScalaIterator(NetworkInterface.getNetworkInterfaces))
for (addr <- enumerationAsScalaIterator(intf.getInetAddresses))
if (addr.isInstanceOf[Inet6Address] && !addr.isLoopbackAddress && !addr.isLinkLocalAddress) {
if (BuildConfig.DEBUG) Log.d(TAG, "IPv6 address detected")
return true
}
} catch {
case ex: Exception =>
Log.e(TAG, "Failed to get interfaces' addresses.", ex)
app.track(ex)
}
false
def isIPv6Support: Boolean = try {
val result = NetworkInterface.getNetworkInterfaces.flatMap(_.getInetAddresses)
.count(addr => addr.isInstanceOf[Inet6Address] && !addr.isLoopbackAddress && !addr.isLinkLocalAddress) > 0
if (result && BuildConfig.DEBUG) Log.d(TAG, "IPv6 address detected")
result
} catch {
case ex: Exception =>
Log.e(TAG, "Failed to get interfaces' addresses.", ex)
app.track(ex)
false
}
def startSsService(context: Context) {