6#include "wifimonitor_p.h"
11#include <private/qandroidextras_p.h>
12#include <QCoreApplication>
13#include <QJniEnvironment>
19class WifiMonitorBackend :
public QSharedData
22 void setSsid(
const QString &ssid);
23 void setStatus(
int statusCode);
25 std::vector<WifiMonitor*> frontends;
26 WifiMonitor::Status status = WifiMonitor::NotAvailable;
27 QJniObject wifiMonitor;
31void WifiMonitorBackend::setSsid(
const QString &ssid)
33 for (
auto m : frontends) {
38void WifiMonitorBackend::setStatus(
int statusCode)
40 if (status == statusCode) {
43 status =
static_cast<WifiMonitor::Status
>(statusCode);
44 for (
auto m : frontends) {
45 Q_EMIT m->statusChanged();
49static WifiMonitorBackend *s_backend =
nullptr;
51static void setSsid(JNIEnv *env, [[maybe_unused]] jobject that, jstring ssid)
54 const char *str = env->GetStringUTFChars(ssid,
nullptr);
56 env->ReleaseStringUTFChars(ssid, str);
60static void setStatus([[maybe_unused]] JNIEnv *env, [[maybe_unused]] jobject that, jint statusCode)
63 s_backend->setStatus(statusCode);
67static const JNINativeMethod methods[] = {
68 {
"setSsid",
"(Ljava/lang/String;)V", (
void *)setSsid},
69 {
"setStatus",
"(I)V", (
void *)setStatus},
72WifiMonitor::WifiMonitor(QObject *parent)
75 static bool nativesRegistered =
false;
76 if (!nativesRegistered) {
78 jclass cls = env->FindClass(
"org/kde/publictransport/onboard/WifiMonitor");
79 if (env->RegisterNatives(cls, methods,
sizeof(methods) /
sizeof(JNINativeMethod)) < 0) {
80 qCWarning(
Log) <<
"Failed to register native functions!";
82 nativesRegistered =
true;
86 s_backend =
new WifiMonitorBackend;
87#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
90 s_backend->wifiMonitor =
QJniObject(
"org/kde/publictransport/onboard/WifiMonitor",
"(Landroid/content/Context;)V",
96 s_backend->frontends.push_back(
this);
99WifiMonitor::~WifiMonitor()
101 s_backend->ref.deref();
102 if (!s_backend->ref) {
106 auto it = std::find(s_backend->frontends.begin(), s_backend->frontends.end(),
this);
107 if (it != s_backend->frontends.end()) {
108 s_backend->frontends.erase(it);
113WifiMonitor::Status WifiMonitor::status()
const
115 return s_backend->status;
118void WifiMonitor::requestPermissions()
122 s_backend->wifiMonitor.callMethod<
void>(
"checkStatus",
"()V");
Query operations and data types for accessing realtime public transport information from online servi...
QString fromUtf8(QByteArrayView str)
QFuture< QtAndroidPrivate::PermissionResult > requestPermission(const QString &permission)