Add network state listening and reconnection
Vpn reconnects when the default network is changed
This commit is contained in:
parent
8cc5846808
commit
1576aed1ea
15 changed files with 240 additions and 223 deletions
|
|
@ -67,6 +67,14 @@ AndroidController::AndroidController() : QObject()
|
|||
},
|
||||
Qt::QueuedConnection);
|
||||
|
||||
connect(
|
||||
this, &AndroidController::vpnReconnecting, this,
|
||||
[this]() {
|
||||
qDebug() << "Android event: VPN reconnecting";
|
||||
emit connectionStateChanged(Vpn::ConnectionState::Reconnecting);
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
|
||||
connect(
|
||||
this, &AndroidController::configImported, this,
|
||||
[]() {
|
||||
|
|
@ -101,6 +109,7 @@ bool AndroidController::initialize()
|
|||
{"onVpnPermissionRejected", "()V", reinterpret_cast<void *>(onVpnPermissionRejected)},
|
||||
{"onVpnConnected", "()V", reinterpret_cast<void *>(onVpnConnected)},
|
||||
{"onVpnDisconnected", "()V", reinterpret_cast<void *>(onVpnDisconnected)},
|
||||
{"onVpnReconnecting", "()V", reinterpret_cast<void *>(onVpnReconnecting)},
|
||||
{"onStatisticsUpdate", "(JJ)V", reinterpret_cast<void *>(onStatisticsUpdate)},
|
||||
{"onConfigImported", "()V", reinterpret_cast<void *>(onConfigImported)},
|
||||
{"decodeQrCode", "(Ljava/lang/String;)Z", reinterpret_cast<bool *>(decodeQrCode)}
|
||||
|
|
@ -187,6 +196,7 @@ Vpn::ConnectionState AndroidController::convertState(AndroidController::Connecti
|
|||
case AndroidController::ConnectionState::CONNECTING: return Vpn::ConnectionState::Connecting;
|
||||
case AndroidController::ConnectionState::DISCONNECTED: return Vpn::ConnectionState::Disconnected;
|
||||
case AndroidController::ConnectionState::DISCONNECTING: return Vpn::ConnectionState::Disconnecting;
|
||||
case AndroidController::ConnectionState::RECONNECTING: return Vpn::ConnectionState::Reconnecting;
|
||||
case AndroidController::ConnectionState::UNKNOWN: return Vpn::ConnectionState::Unknown;
|
||||
}
|
||||
}
|
||||
|
|
@ -199,6 +209,7 @@ QString AndroidController::textConnectionState(AndroidController::ConnectionStat
|
|||
case AndroidController::ConnectionState::CONNECTING: return "CONNECTING";
|
||||
case AndroidController::ConnectionState::DISCONNECTED: return "DISCONNECTED";
|
||||
case AndroidController::ConnectionState::DISCONNECTING: return "DISCONNECTING";
|
||||
case AndroidController::ConnectionState::RECONNECTING: return "RECONNECTING";
|
||||
case AndroidController::ConnectionState::UNKNOWN: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
|
@ -260,6 +271,15 @@ void AndroidController::onVpnDisconnected(JNIEnv *env, jobject thiz)
|
|||
emit AndroidController::instance()->vpnDisconnected();
|
||||
}
|
||||
|
||||
// static
|
||||
void AndroidController::onVpnReconnecting(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
Q_UNUSED(env);
|
||||
Q_UNUSED(thiz);
|
||||
|
||||
emit AndroidController::instance()->vpnReconnecting();
|
||||
}
|
||||
|
||||
// static
|
||||
void AndroidController::onStatisticsUpdate(JNIEnv *env, jobject thiz, jlong rxBytes, jlong txBytes)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue