Commit 020a2a5d authored by Mygod's avatar Mygod

Refine "Catch IOExpections when reading ACLs"

This commit refines 37856ab4.
parent 7624f4ac
......@@ -28,6 +28,7 @@ import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.utils.Subnet
import com.github.shadowsocks.utils.asIterable
import java.io.File
import java.io.IOException
import java.io.Reader
import java.net.URL
......@@ -50,11 +51,7 @@ class Acl {
get() {
val acl = Acl()
val str = DataStore.publicStore.getString(CUSTOM_RULES) ?: return acl
try {
acl.fromReader(str.reader())
} catch (_: Exception) {
// Ignore
}
if (!acl.bypass) {
acl.subnets.clear()
acl.hostnames.clear()
......@@ -152,14 +149,17 @@ class Acl {
return this
}
fun fromId(id: String): Acl = try { fromReader(Acl.getFile(id).bufferedReader()) } catch (_: Exception) { Acl() }
fun fromId(id: String): Acl = try {
fromReader(Acl.getFile(id).bufferedReader())
} catch (_: IOException) { this }
fun flatten(depth: Int): Acl {
if (depth > 0) for (url in urls.asIterable()) {
val child = try {
Acl().fromReader(url.openStream().bufferedReader(), bypass).flatten(depth - 1)
} catch (_: Exception) {
Acl()
val child = Acl()
try {
child.fromReader(url.openStream().bufferedReader(), bypass).flatten(depth - 1)
} catch (_: IOException) {
continue
}
if (bypass != child.bypass) {
Log.w(TAG, "Imported network ACL has a conflicting mode set. " +
......
......@@ -29,7 +29,7 @@ import android.support.graphics.drawable.AnimatedVectorDrawableCompat
import android.support.v7.widget.TooltipCompat
import android.util.AttributeSet
import android.view.View
import com.github.shadowsocks.App
import com.github.shadowsocks.App.Companion.app
import com.github.shadowsocks.R
import com.github.shadowsocks.bg.BaseService
import java.util.*
......@@ -85,7 +85,7 @@ class ServiceButton @JvmOverloads constructor(context: Context, attrs: Attribute
}
refreshDrawableState()
isEnabled = false
if (state == BaseService.CONNECTED || state == BaseService.STOPPED) App.app.handler.postDelayed(
if (state == BaseService.CONNECTED || state == BaseService.STOPPED) app.handler.postDelayed(
{ isEnabled = state == BaseService.CONNECTED || state == BaseService.STOPPED }, 1000)
}
......
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