Commit 45b86476 authored by Mygod's avatar Mygod

Catch RemoteException

parent 73faf2a1
......@@ -24,7 +24,6 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.DeadObjectException
import android.os.Handler
import android.os.IBinder
import android.os.RemoteException
......@@ -89,7 +88,7 @@ class ShadowsocksConnection(private val handler: Handler = Handler(),
if (bandwidthTimeout != value && service != null) try {
if (value > 0) service.startListeningForBandwidth(serviceCallback, value)
else service.stopListeningForBandwidth(serviceCallback)
} catch (_: DeadObjectException) { }
} catch (_: RemoteException) { }
field = value
}
var service: IShadowsocksService? = null
......@@ -146,7 +145,9 @@ class ShadowsocksConnection(private val handler: Handler = Handler(),
connectionActive = false
if (listenForDeath) binder?.unlinkToDeath(this, 0)
binder = null
try {
service?.stopListeningForBandwidth(serviceCallback)
} catch (_: RemoteException) { }
service = null
callback = null
}
......
......@@ -115,7 +115,7 @@ object BaseService {
repeat(callbacks.beginBroadcast()) {
try {
work(callbacks.getBroadcastItem(it))
} catch (_: DeadObjectException) {
} catch (_: RemoteException) {
} catch (e: Exception) {
printLog(e)
}
......
......@@ -26,8 +26,8 @@ import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.VpnService
import android.os.Bundle
import android.os.DeadObjectException
import android.os.Handler
import android.os.RemoteException
import android.util.Log
import android.view.KeyCharacterMap
import android.view.KeyEvent
......@@ -133,7 +133,7 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref
private val connection = ShadowsocksConnection(handler, true)
override fun onServiceConnected(service: IShadowsocksService) = changeState(try {
BaseService.State.values()[service.state]
} catch (_: DeadObjectException) {
} catch (_: RemoteException) {
BaseService.State.Idle
})
override fun onServiceDisconnected() = changeState(BaseService.State.Idle)
......
......@@ -26,8 +26,8 @@ import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.VpnService
import android.os.Bundle
import android.os.DeadObjectException
import android.os.Handler
import android.os.RemoteException
import android.text.format.Formatter
import android.util.Log
import android.widget.Toast
......@@ -139,7 +139,7 @@ class MainPreferenceFragment : LeanbackPreferenceFragmentCompat(), ShadowsocksCo
private val connection = ShadowsocksConnection(handler, true)
override fun onServiceConnected(service: IShadowsocksService) = changeState(try {
BaseService.State.values()[service.state]
} catch (_: DeadObjectException) {
} catch (_: RemoteException) {
BaseService.State.Idle
})
override fun onServiceDisconnected() = changeState(BaseService.State.Idle)
......
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