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

77 lines
2.2 KiB
C++
Raw Normal View History

2022-12-23 17:32:20 +03:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
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 <QJniEnvironment>
#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
virtual ~AndroidController() override = default;
bool initialize();
2021-11-26 17:43:02 +03:00
ErrorCode start();
void stop();
void resumeStart();
void checkStatus();
void setNotificationText(const QString &title, const QString &message, int timerSec);
void shareConfig(const QString &data, const QString &suggestedName);
2021-11-26 17:43:02 +03:00
void setFallbackConnectedNotification();
void getBackendLogs(std::function<void(const QString &)> &&callback);
2021-11-26 17:43:02 +03:00
void cleanupBackendLogs();
const QJsonObject &vpnConfig() const;
void setVpnConfig(const QJsonObject &newVpnConfig);
2023-02-22 14:22:03 +03:00
void startQrReaderActivity();
2021-11-26 17:43:02 +03:00
signals:
void connectionStateChanged(Vpn::ConnectionState state);
2021-11-26 17:43:02 +03:00
// This signal is emitted when the controller is initialized. Note that the
// VPN tunnel can be already active. In this case, "connected" should be set
// to true and the "connectionDate" should be set to the activation date if
// known.
// If "status" is set to false, the backend service is considered unavailable.
void initialized(bool status, bool connected, const QDateTime &connectionDate);
2021-11-26 17:43:02 +03:00
2022-12-14 18:52:19 +03:00
void statusUpdated(QString totalRx, QString totalTx, QString endpoint, QString deviceIPv4);
void scheduleStatusCheckSignal();
void importConfigFromOutside(QString &data);
2021-11-26 17:43:02 +03:00
protected slots:
2022-12-14 18:52:19 +03:00
void scheduleStatusCheckSlot();
2021-11-26 17:43:02 +03:00
private:
2022-12-23 17:32:20 +03:00
bool m_init = false;
2023-01-18 15:54:19 +03:00
2021-11-26 17:43:02 +03:00
QJsonObject m_vpnConfig;
bool m_serviceConnected = false;
std::function<void(const QString &)> m_logCallback;
2021-11-26 17:43:02 +03:00
static void startActivityForResult(JNIEnv *env, jobject /*thiz*/, jobject intent);
2021-11-26 17:43:02 +03:00
2022-12-14 18:52:19 +03:00
bool isConnected = false;
void scheduleStatusCheck();
2021-11-26 17:43:02 +03:00
};
#endif // ANDROID_CONTROLLER_H