Add passing the VPN connection status when rebinding to the service
This commit is contained in:
parent
5835a756ce
commit
dc6e3ec53b
8 changed files with 65 additions and 28 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package org.amnezia.vpn.protocol
|
||||
|
||||
// keep synchronized with client/platforms/android/android_controller.h ConnectionState
|
||||
enum class ProtocolState {
|
||||
CONNECTED,
|
||||
CONNECTING,
|
||||
|
|
|
|||
|
|
@ -2,19 +2,19 @@ package org.amnezia.vpn.protocol
|
|||
|
||||
import android.os.Bundle
|
||||
|
||||
private const val IS_CONNECTED_KEY = "isConnected"
|
||||
private const val STATE_KEY = "state"
|
||||
|
||||
@Suppress("DataClassPrivateConstructor")
|
||||
data class Status private constructor(
|
||||
val isConnected: Boolean = false
|
||||
val state: ProtocolState
|
||||
) {
|
||||
private constructor(builder: Builder) : this(builder.isConnected)
|
||||
private constructor(builder: Builder) : this(builder.state)
|
||||
|
||||
class Builder {
|
||||
var isConnected: Boolean = false
|
||||
lateinit var state: ProtocolState
|
||||
private set
|
||||
|
||||
fun setConnected(isConnected: Boolean) = apply { this.isConnected = isConnected }
|
||||
fun setState(state: ProtocolState) = apply { this.state = state }
|
||||
|
||||
fun build(): Status = Status(this)
|
||||
}
|
||||
|
|
@ -24,11 +24,11 @@ data class Status private constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun Bundle.putStatus(statistics: Status) {
|
||||
putBoolean(IS_CONNECTED_KEY, statistics.isConnected)
|
||||
fun Bundle.putStatus(status: Status) {
|
||||
putInt(STATE_KEY, status.state.ordinal)
|
||||
}
|
||||
|
||||
fun Bundle.getStatus(): Status =
|
||||
Status.build {
|
||||
setConnected(getBoolean(IS_CONNECTED_KEY))
|
||||
setState(ProtocolState.entries[getInt(STATE_KEY)])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,8 +62,8 @@ class AmneziaActivity : QtActivity() {
|
|||
ServiceEvent.STATUS -> {
|
||||
if (isWaitingStatus) {
|
||||
isWaitingStatus = false
|
||||
msg.data?.getStatus()?.let { (isConnected) ->
|
||||
QtAndroidController.onStatus(isConnected)
|
||||
msg.data?.getStatus()?.let { (state) ->
|
||||
QtAndroidController.onStatus(state.ordinal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ class AmneziaVpnService : VpnService() {
|
|||
clientMessenger.send {
|
||||
ServiceEvent.STATUS.packToMessage {
|
||||
putStatus(Status.build {
|
||||
setConnected(this@AmneziaVpnService.isConnected)
|
||||
setState(this@AmneziaVpnService.protocolState.value)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ package org.amnezia.vpn.qt
|
|||
* called by events in the Android part of the client
|
||||
*/
|
||||
object QtAndroidController {
|
||||
external fun onStatus(isVpnConnected: Boolean)
|
||||
external fun onStatus(stateCode: Int)
|
||||
external fun onServiceDisconnected()
|
||||
external fun onServiceError()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue