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

View file

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

View file

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

View file

@ -23,8 +23,10 @@ Proto currentProto = amnezia::Proto::Any;
} }
IOSVpnProtocol::IOSVpnProtocol(Proto proto, const QJsonObject &configuration, QObject* parent) IOSVpnProtocol::IOSVpnProtocol(Proto proto, const QJsonObject &configuration, QObject* parent)
: VpnProtocol(configuration, parent), : VpnProtocol(configuration, parent), m_protocol(proto)
m_protocol(proto) {} {
connect(this, &IOSVpnProtocol::newTransmitedDataCount, this, &IOSVpnProtocol::setBytesChanged);
}
IOSVpnProtocol* IOSVpnProtocol::instance() { IOSVpnProtocol* IOSVpnProtocol::instance() {
return s_instance; return s_instance;
@ -205,8 +207,7 @@ void IOSVpnProtocol::checkStatus()
qDebug() << "ServerIpv4Gateway:" << QString::fromNSString(serverIpv4Gateway) qDebug() << "ServerIpv4Gateway:" << QString::fromNSString(serverIpv4Gateway)
<< "DeviceIpv4Address:" << QString::fromNSString(deviceIpv4Address) << "DeviceIpv4Address:" << QString::fromNSString(deviceIpv4Address)
<< "RxBytes:" << rxBytes << "TxBytes:" << txBytes; << "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_settings(settings),
m_configurator(configurator), m_configurator(configurator),
m_serverController(serverController), m_serverController(serverController),
m_receivedBytes(0),
m_sentBytes(0),
m_isIOSConnected(false) m_isIOSConnected(false)
{ {
} }
@ -52,11 +50,7 @@ VpnConnection::~VpnConnection()
void VpnConnection::onBytesChanged(quint64 receivedBytes, quint64 sentBytes) void VpnConnection::onBytesChanged(quint64 receivedBytes, quint64 sentBytes)
{ {
emit bytesChanged(receivedBytes - m_receivedBytes, sentBytes - m_sentBytes); emit bytesChanged(receivedBytes, sentBytes);
m_receivedBytes = receivedBytes;
m_sentBytes = sentBytes;
} }
void VpnConnection::onConnectionStateChanged(VpnProtocol::VpnConnectionState state) void VpnConnection::onConnectionStateChanged(VpnProtocol::VpnConnectionState state)

View file

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