iOS fix + Android connection status restoration fix

This commit is contained in:
Dmitriy Karpushin 2022-12-15 18:46:15 +03:00
parent d417fa58ab
commit 54dc363231
6 changed files with 40 additions and 22 deletions

View file

@ -41,6 +41,7 @@ import java.io.Closeable
import java.io.File
import java.io.FileDescriptor
import java.io.IOException
import java.lang.Exception
import android.net.VpnService as BaseVpnService
@ -306,9 +307,16 @@ class VPNService : BaseVpnService(), LocalDnsService.Interface {
return mConnectionTime
}
var isUp: Boolean
var isUp: Boolean = false
get() {
return currentTunnelHandle >= 0
return when (mProtocol) {
"openvpn" -> {
field
}
else -> {
currentTunnelHandle >= 0
}
}
}
set(value) {
if (value) {
@ -344,8 +352,8 @@ class VPNService : BaseVpnService(), LocalDnsService.Interface {
Status(
getConfigValue("rx_bytes"),
getConfigValue("tx_bytes"),
mConfig?.getJSONObject("server")?.getString("ipv4Gateway"),
mConfig?.getJSONObject("device")?.getString("ipv4Address")
if (mConfig!!.has("server")) { mConfig?.getJSONObject("server")?.getString("ipv4Gateway") } else {""},
if (mConfig!!.has("server")) {mConfig?.getJSONObject("device")?.getString("ipv4Address") } else {""}
)
}
}
@ -712,6 +720,8 @@ class VPNService : BaseVpnService(), LocalDnsService.Interface {
private fun startOpenVpn() {
mOpenVPNThreadv3 = OpenVPNThreadv3(this)
isUp = true
Thread({
mOpenVPNThreadv3?.run()
}).start()

View file

@ -266,16 +266,27 @@ bool AndroidController::VPNBinder::onTransact(int code,
QString buffer;
switch (code) {
case EVENT_INIT:
{
qDebug() << "Transact: init";
doc = QJsonDocument::fromJson(data.readData());
emit m_controller->initialized(
true, doc.object()["connected"].toBool(),
QDateTime::fromMSecsSinceEpoch(
doc.object()["time"].toVariant().toLongLong()));
bool isConnected = doc.object()["connected"].toBool();
QDateTime time = QDateTime::fromMSecsSinceEpoch(
doc.object()["time"].toVariant().toLongLong());
emit m_controller->initialized(true, isConnected, time);
// Pass a localised version of the Fallback string for the Notification
m_controller->setFallbackConnectedNotification();
m_controller->isConnected = isConnected;
if (isConnected) {
emit m_controller->scheduleStatusCheckSignal();
}
break;
}
case EVENT_CONNECTED:
qDebug() << "Transact: connected";
emit m_controller->connectionStateChanged(VpnProtocol::Connected);
@ -299,7 +310,10 @@ bool AndroidController::VPNBinder::onTransact(int code,
QString deviceIPv4 = doc.object()["deviceIpv4"].toString();
emit m_controller->statusUpdated(rx, tx, endpoint, deviceIPv4);
emit m_controller->scheduleStatusCheckSignal();
if (m_controller->isConnected) {
emit m_controller->scheduleStatusCheckSignal();
}
break;
}

View file

@ -36,6 +36,7 @@ public:
void cleanupBackendLogs();
signals:
void newTransmitedDataCount(quint64 rxBytes, quint64 txBytes);
protected slots:

View file

@ -23,8 +23,10 @@ Proto currentProto = amnezia::Proto::Any;
}
IOSVpnProtocol::IOSVpnProtocol(Proto proto, const QJsonObject &configuration, QObject* parent)
: VpnProtocol(configuration, parent),
m_protocol(proto) {}
: VpnProtocol(configuration, parent), m_protocol(proto)
{
connect(this, &IOSVpnProtocol::newTransmitedDataCount, this, &IOSVpnProtocol::setBytesChanged);
}
IOSVpnProtocol* IOSVpnProtocol::instance() {
return s_instance;
@ -205,8 +207,7 @@ void IOSVpnProtocol::checkStatus()
qDebug() << "ServerIpv4Gateway:" << QString::fromNSString(serverIpv4Gateway)
<< "DeviceIpv4Address:" << QString::fromNSString(deviceIpv4Address)
<< "RxBytes:" << rxBytes << "TxBytes:" << txBytes;
emit bytesChanged(rxBytes, txBytes);
emit newTransmitedDataCount(rxBytes, txBytes);
}];
}

View file

@ -36,8 +36,6 @@ VpnConnection::VpnConnection(std::shared_ptr<Settings> settings,
m_settings(settings),
m_configurator(configurator),
m_serverController(serverController),
m_receivedBytes(0),
m_sentBytes(0),
m_isIOSConnected(false)
{
}
@ -52,11 +50,7 @@ VpnConnection::~VpnConnection()
void VpnConnection::onBytesChanged(quint64 receivedBytes, quint64 sentBytes)
{
emit bytesChanged(receivedBytes - m_receivedBytes, sentBytes - m_sentBytes);
m_receivedBytes = receivedBytes;
m_sentBytes = sentBytes;
emit bytesChanged(receivedBytes, sentBytes);
}
void VpnConnection::onConnectionStateChanged(VpnProtocol::VpnConnectionState state)

View file

@ -93,8 +93,6 @@ private:
QJsonObject m_vpnConfiguration;
QJsonObject m_routeMode;
QString m_remoteAddress;
quint64 m_receivedBytes;
quint64 m_sentBytes;
bool m_isIOSConnected; //remove later move to isConnected,
#ifdef AMNEZIA_DESKTOP