Files
amnezia-client/client/platforms/android/android_controller.h
T

78 lines
2.6 KiB
C++
Raw Normal View History

2021-11-26 17:43:02 +03:00
#ifndef ANDROID_CONTROLLER_H
#define ANDROID_CONTROLLER_H
2022-12-23 17:32:20 +03:00
#include <QJniObject>
2021-11-26 17:43:02 +03:00
#include "protocols/vpnprotocol.h"
2023-01-18 15:54:19 +03:00
2021-11-26 17:43:02 +03:00
using namespace amnezia;
2022-12-23 17:32:20 +03:00
class AndroidController : public QObject
2021-11-26 17:43:02 +03:00
{
Q_OBJECT
public:
explicit AndroidController();
static AndroidController *instance();
2021-11-26 17:43:02 +03:00
bool initialize();
2021-11-26 17:43:02 +03:00
// keep synchronized with org.amnezia.vpn.protocol.ProtocolState
enum class ConnectionState {
CONNECTED,
CONNECTING,
DISCONNECTED,
DISCONNECTING,
RECONNECTING,
UNKNOWN
};
ErrorCode start(const QJsonObject &vpnConfig);
2021-11-26 17:43:02 +03:00
void stop();
void setNotificationText(const QString &title, const QString &message, int timerSec);
void saveFile(const QString& fileName, const QString &data);
2023-02-22 14:22:03 +03:00
void startQrReaderActivity();
2021-11-26 17:43:02 +03:00
signals:
void connectionStateChanged(Vpn::ConnectionState state);
void status(ConnectionState state);
void serviceDisconnected();
void serviceError();
void vpnPermissionRejected();
void vpnConnected();
void vpnDisconnected();
void vpnReconnecting();
void statisticsUpdated(quint64 rxBytes, quint64 txBytes);
2023-12-11 22:56:01 +03:00
void configImported(QString config);
void importConfigFromOutside(QString config);
2023-12-06 15:36:26 +03:00
void initConnectionState(Vpn::ConnectionState state);
2021-11-26 17:43:02 +03:00
private:
2023-11-23 20:30:03 +03:00
bool isWaitingStatus = true;
void qtAndroidControllerInitialized();
static Vpn::ConnectionState convertState(ConnectionState state);
static QString textConnectionState(ConnectionState state);
// JNI functions called by Android
static void onStatus(JNIEnv *env, jobject thiz, jint stateCode);
static void onServiceDisconnected(JNIEnv *env, jobject thiz);
static void onServiceError(JNIEnv *env, jobject thiz);
static void onVpnPermissionRejected(JNIEnv *env, jobject thiz);
static void onVpnConnected(JNIEnv *env, jobject thiz);
static void onVpnDisconnected(JNIEnv *env, jobject thiz);
static void onVpnReconnecting(JNIEnv *env, jobject thiz);
static void onStatisticsUpdate(JNIEnv *env, jobject thiz, jlong rxBytes, jlong txBytes);
2023-12-11 22:56:01 +03:00
static void onConfigImported(JNIEnv *env, jobject thiz, jstring data);
2023-11-21 22:48:52 +03:00
static bool decodeQrCode(JNIEnv *env, jobject thiz, jstring data);
template <typename Ret, typename ...Args>
static auto callActivityMethod(const char *methodName, const char *signature,
const std::function<Ret()> &defValue, Args &&...args);
template <typename ...Args>
static void callActivityMethod(const char *methodName, const char *signature, Args &&...args);
2021-11-26 17:43:02 +03:00
};
#endif // ANDROID_CONTROLLER_H