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

116 lines
4.0 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>
2024-04-01 18:45:00 +07:00
#include <QPixmap>
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
2023-12-26 17:00:06 +03:00
enum class ConnectionState
{
2024-03-04 18:08:55 +03:00
DISCONNECTED,
CONNECTED,
CONNECTING,
DISCONNECTING,
RECONNECTING,
UNKNOWN
};
ErrorCode start(const QJsonObject &vpnConfig);
2021-11-26 17:43:02 +03:00
void stop();
2024-03-04 18:08:55 +03:00
void resetLastServer(int serverIndex);
2023-12-26 17:00:06 +03:00
void saveFile(const QString &fileName, const QString &data);
2023-12-26 16:23:05 +03:00
QString openFile(const QString &filter);
2024-12-31 04:16:52 +01:00
int getFd(const QString &fileName);
void closeFd();
QString getFileName(const QString &uri);
bool isCameraPresent();
2024-08-06 12:41:44 +03:00
bool isOnTv();
2025-11-04 11:43:36 +08:00
bool isEdgeToEdgeEnabled();
int getStatusBarHeight();
int getNavigationBarHeight();
2023-02-22 14:22:03 +03:00
void startQrReaderActivity();
2024-01-20 16:40:12 +03:00
void setSaveLogs(bool enabled);
void exportLogsFile(const QString &fileName);
void clearLogs();
2024-03-06 04:18:19 +03:00
void setScreenshotsEnabled(bool enabled);
2024-09-09 14:36:33 +03:00
void setNavigationBarColor(unsigned int color);
void minimizeApp();
2024-04-01 18:45:00 +07:00
QJsonArray getAppList();
QPixmap getAppIcon(const QString &package, QSize *size, const QSize &requestedSize);
2024-05-12 18:04:14 +03:00
bool isNotificationPermissionGranted();
void requestNotificationPermission();
2024-09-09 14:36:33 +03:00
bool requestAuthentication();
2024-12-31 04:16:52 +01:00
void sendTouch(float x, float y);
2024-01-20 16:40:12 +03:00
static bool initLogging();
static void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message);
2023-02-22 14:22:03 +03:00
2021-11-26 17:43:02 +03:00
signals:
void connectionStateChanged(Vpn::ConnectionState state);
void status(ConnectionState state);
void serviceDisconnected();
void serviceError();
void vpnPermissionRejected();
2024-05-12 18:04:14 +03:00
void notificationStateChanged();
2024-03-04 18:08:55 +03:00
void vpnStateChanged(ConnectionState state);
void statisticsUpdated(quint64 rxBytes, quint64 txBytes);
2023-12-26 16:23:05 +03:00
void fileOpened(QString uri);
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);
2024-09-09 14:36:33 +03:00
void authenticationResult(bool result);
2025-11-11 17:03:27 +03:00
void imeInsetsChanged(int heightDp);
void systemBarsInsetsChanged(int navBarHeightDp, int statusBarHeightDp);
2021-11-26 17:43:02 +03:00
private:
2023-11-23 20:30:03 +03:00
bool isWaitingStatus = true;
2024-01-20 16:40:12 +03:00
static jclass log;
static jmethodID logDebug;
static jmethodID logInfo;
static jmethodID logWarning;
static jmethodID logError;
static jmethodID logFatal;
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);
2024-05-12 18:04:14 +03:00
static void onNotificationStateChanged(JNIEnv *env, jobject thiz);
2024-03-04 18:08:55 +03:00
static void onVpnStateChanged(JNIEnv *env, jobject thiz, jint stateCode);
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-12-26 16:23:05 +03:00
static void onFileOpened(JNIEnv *env, jobject thiz, jstring uri);
2024-09-09 14:36:33 +03:00
static void onAuthResult(JNIEnv *env, jobject thiz, jboolean result);
2023-11-21 22:48:52 +03:00
static bool decodeQrCode(JNIEnv *env, jobject thiz, jstring data);
2025-11-11 17:03:27 +03:00
static void onImeInsetsChanged(JNIEnv *env, jobject thiz, jint heightDp);
static void onSystemBarsInsetsChanged(JNIEnv *env, jobject thiz, jint navBarHeightDp, jint statusBarHeightDp);
template <typename Ret, typename ...Args>
2024-01-20 16:40:12 +03:00
static auto callActivityMethod(const char *methodName, const char *signature, 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