From 020a2a5d4301f780e217a7b8fa3b7677d70708cc Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 19 Dec 2017 17:36:12 -0800 Subject: [PATCH] Refine "Catch IOExpections when reading ACLs" This commit refines 37856ab4d2fc998dbad0bf0cc7949dea84aef50b. --- .../java/com/github/shadowsocks/acl/Acl.kt | 20 +++++++++---------- .../shadowsocks/widget/ServiceButton.kt | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt b/mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt index a8107947..ef8f3037 100644 --- a/mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt +++ b/mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt @@ -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 - } + acl.fromReader(str.reader()) 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. " + diff --git a/mobile/src/main/java/com/github/shadowsocks/widget/ServiceButton.kt b/mobile/src/main/java/com/github/shadowsocks/widget/ServiceButton.kt index af926432..0c06c15c 100644 --- a/mobile/src/main/java/com/github/shadowsocks/widget/ServiceButton.kt +++ b/mobile/src/main/java/com/github/shadowsocks/widget/ServiceButton.kt @@ -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) }