Commit 45b86476 authored by Mygod's avatar Mygod

Catch RemoteException

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