mirror of
https://github.com/DefinedNet/mobile_nebula.git
synced 2025-02-28 13:55:26 +00:00
Add safety to unbindService (#266)
This commit is contained in:
parent
f6016f5da8
commit
69b0a4dafa
1 changed files with 14 additions and 1 deletions
|
@ -36,6 +36,10 @@ class MainActivity: FlutterActivity() {
|
||||||
private var apiClient: APIClient? = null
|
private var apiClient: APIClient? = null
|
||||||
private var sites: Sites? = null
|
private var sites: Sites? = null
|
||||||
|
|
||||||
|
// Don't attempt to unbind from the service unless the client has received some
|
||||||
|
// information about the service's state.
|
||||||
|
private var isServiceBound = false
|
||||||
|
|
||||||
// When starting a site we may need to request VPN permissions. These variables help us
|
// When starting a site we may need to request VPN permissions. These variables help us
|
||||||
// maintain state while waiting for a permission result.
|
// maintain state while waiting for a permission result.
|
||||||
private var startResult: MethodChannel.Result? = null
|
private var startResult: MethodChannel.Result? = null
|
||||||
|
@ -440,6 +444,7 @@ class MainActivity: FlutterActivity() {
|
||||||
private val connection = object : ServiceConnection {
|
private val connection = object : ServiceConnection {
|
||||||
override fun onServiceConnected(className: ComponentName, service: IBinder) {
|
override fun onServiceConnected(className: ComponentName, service: IBinder) {
|
||||||
outMessenger = Messenger(service)
|
outMessenger = Messenger(service)
|
||||||
|
isServiceBound = true
|
||||||
|
|
||||||
// We want to monitor the service for as long as we are connected to it.
|
// We want to monitor the service for as long as we are connected to it.
|
||||||
try {
|
try {
|
||||||
|
@ -461,6 +466,7 @@ class MainActivity: FlutterActivity() {
|
||||||
|
|
||||||
override fun onServiceDisconnected(arg0: ComponentName) {
|
override fun onServiceDisconnected(arg0: ComponentName) {
|
||||||
outMessenger = null
|
outMessenger = null
|
||||||
|
isServiceBound = false
|
||||||
if (activeSiteId != null) {
|
if (activeSiteId != null) {
|
||||||
//TODO: this indicates the service died, notify that it is disconnected
|
//TODO: this indicates the service died, notify that it is disconnected
|
||||||
}
|
}
|
||||||
|
@ -510,7 +516,14 @@ class MainActivity: FlutterActivity() {
|
||||||
msg.replyTo = inMessenger
|
msg.replyTo = inMessenger
|
||||||
outMessenger!!.send(msg)
|
outMessenger!!.send(msg)
|
||||||
// Unbind
|
// Unbind
|
||||||
unbindService(connection)
|
if (isServiceBound) {
|
||||||
|
try {
|
||||||
|
unbindService(connection)
|
||||||
|
isServiceBound = false
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
Log.e(TAG, e.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
outMessenger = null
|
outMessenger = null
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue