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