summaryrefslogtreecommitdiffstats
path: root/src/plugins/networkinformation/android
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/networkinformation/android')
-rw-r--r--src/plugins/networkinformation/android/CMakeLists.txt9
-rw-r--r--src/plugins/networkinformation/android/jar/build.gradle6
-rw-r--r--src/plugins/networkinformation/android/jar/src/org/qtproject/qt/android/networkinformation/QtAndroidNetworkInformation.java48
-rw-r--r--src/plugins/networkinformation/android/qandroidnetworkinformationbackend.cpp40
-rw-r--r--src/plugins/networkinformation/android/wrapper/androidconnectivitymanager.cpp107
-rw-r--r--src/plugins/networkinformation/android/wrapper/androidconnectivitymanager.h45
6 files changed, 51 insertions, 204 deletions
diff --git a/src/plugins/networkinformation/android/CMakeLists.txt b/src/plugins/networkinformation/android/CMakeLists.txt
index 0883ec74e2..07d9201bbb 100644
--- a/src/plugins/networkinformation/android/CMakeLists.txt
+++ b/src/plugins/networkinformation/android/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
set(java_sources
jar/src/org/qtproject/qt/android/networkinformation/QtAndroidNetworkInformation.java
@@ -9,8 +12,10 @@ qt_internal_add_jar(Qt${QtBase_VERSION_MAJOR}AndroidNetworkInformationBackend
OUTPUT_DIR "${QT_BUILD_DIR}/jar"
)
+qt_path_join(destination ${INSTALL_DATADIR} "jar")
+
install_jar(Qt${QtBase_VERSION_MAJOR}AndroidNetworkInformationBackend
- DESTINATION jar
+ DESTINATION ${destination}
COMPONENT Devel
)
@@ -24,8 +29,6 @@ qt_internal_add_plugin(QAndroidNetworkInformationPlugin
wrapper/androidconnectivitymanager.cpp wrapper/androidconnectivitymanager.h
LIBRARIES
Qt::NetworkPrivate
- DEFINES
- QT_USE_QSTRINGBUILDER
)
set_property(
diff --git a/src/plugins/networkinformation/android/jar/build.gradle b/src/plugins/networkinformation/android/jar/build.gradle
index c947852f79..68a9381ad2 100644
--- a/src/plugins/networkinformation/android/jar/build.gradle
+++ b/src/plugins/networkinformation/android/jar/build.gradle
@@ -7,7 +7,7 @@ buildscript {
}
dependencies {
- classpath 'com.android.tools.build:gradle:7.0.2'
+ classpath 'com.android.tools.build:gradle:8.0.2'
}
}
@@ -23,12 +23,10 @@ repositories {
}
android {
- compileSdkVersion 31
- buildToolsVersion "31.0.3"
+ compileSdk 34
defaultConfig {
minSdkVersion 23
- targetSdkVersion 31
}
sourceSets {
diff --git a/src/plugins/networkinformation/android/jar/src/org/qtproject/qt/android/networkinformation/QtAndroidNetworkInformation.java b/src/plugins/networkinformation/android/jar/src/org/qtproject/qt/android/networkinformation/QtAndroidNetworkInformation.java
index a35424f8e8..6a56c506b0 100644
--- a/src/plugins/networkinformation/android/jar/src/org/qtproject/qt/android/networkinformation/QtAndroidNetworkInformation.java
+++ b/src/plugins/networkinformation/android/jar/src/org/qtproject/qt/android/networkinformation/QtAndroidNetworkInformation.java
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
package org.qtproject.qt.android.networkinformation;
@@ -51,9 +15,9 @@ import android.os.Build;
public class QtAndroidNetworkInformation {
private static final String LOG_TAG = "QtAndroidNetworkInformation";
- private static native void connectivityChanged(AndroidConnectivity connectivity);
+ private static native void networkConnectivityChanged(int connectivity);
private static native void genericInfoChanged(boolean captivePortal, boolean metered);
- private static native void transportMediumChanged(Transport transportMedium);
+ private static native void transportMediumChanged(int transportMedium);
private static QtNetworkInformationCallback m_callback = null;
private static final Object m_lock = new Object();
@@ -132,14 +96,14 @@ public class QtAndroidNetworkInformation {
private void setState(AndroidConnectivity s) {
if (previousState != s) {
previousState = s;
- connectivityChanged(s);
+ networkConnectivityChanged(s.ordinal());
}
}
private void setTransportMedium(Transport t) {
if (previousTransport != t) {
previousTransport = t;
- transportMediumChanged(t);
+ transportMediumChanged(t.ordinal());
}
}
diff --git a/src/plugins/networkinformation/android/qandroidnetworkinformationbackend.cpp b/src/plugins/networkinformation/android/qandroidnetworkinformationbackend.cpp
index 2e4149f686..44e4d447d2 100644
--- a/src/plugins/networkinformation/android/qandroidnetworkinformationbackend.cpp
+++ b/src/plugins/networkinformation/android/qandroidnetworkinformationbackend.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtNetwork module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <QtNetwork/private/qnetworkinformation_p.h>
diff --git a/src/plugins/networkinformation/android/wrapper/androidconnectivitymanager.cpp b/src/plugins/networkinformation/android/wrapper/androidconnectivitymanager.cpp
index 5c1230bfaa..3c9f952968 100644
--- a/src/plugins/networkinformation/android/wrapper/androidconnectivitymanager.cpp
+++ b/src/plugins/networkinformation/android/wrapper/androidconnectivitymanager.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "androidconnectivitymanager.h"
@@ -56,14 +20,15 @@ Q_GLOBAL_STATIC(AndroidConnectivityManagerInstance, androidConnManagerInstance)
static const char networkInformationClass[] =
"org/qtproject/qt/android/networkinformation/QtAndroidNetworkInformation";
-static void networkConnectivityChanged(JNIEnv *env, jobject obj, jobject enumValue)
+static void networkConnectivityChanged(JNIEnv *env, jobject obj, jint enumValue)
{
Q_UNUSED(env);
Q_UNUSED(obj);
- const jint value = QJniObject(enumValue).callMethod<jint>("ordinal");
- const auto connectivity = static_cast<AndroidConnectivityManager::AndroidConnectivity>(value);
+ const auto connectivity =
+ static_cast<AndroidConnectivityManager::AndroidConnectivity>(enumValue);
Q_EMIT androidConnManagerInstance->connManager->connectivityChanged(connectivity);
}
+Q_DECLARE_JNI_NATIVE_METHOD(networkConnectivityChanged)
static void genericInfoChanged(JNIEnv *env, jobject obj, jboolean captivePortal, jboolean metered)
{
@@ -72,30 +37,26 @@ static void genericInfoChanged(JNIEnv *env, jobject obj, jboolean captivePortal,
Q_EMIT androidConnManagerInstance->connManager->captivePortalChanged(captivePortal);
Q_EMIT androidConnManagerInstance->connManager->meteredChanged(metered);
}
+Q_DECLARE_JNI_NATIVE_METHOD(genericInfoChanged)
-static void transportMediumChangedCallback(JNIEnv *env, jobject obj, jobject enumValue)
+static void transportMediumChanged(JNIEnv *env, jobject obj, jint enumValue)
{
Q_UNUSED(env);
Q_UNUSED(obj);
- const jint value = QJniObject(enumValue).callMethod<jint>("ordinal");
- const auto transport = static_cast<AndroidConnectivityManager::AndroidTransport>(value);
+ const auto transport = static_cast<AndroidConnectivityManager::AndroidTransport>(enumValue);
emit androidConnManagerInstance->connManager->transportMediumChanged(transport);
}
+Q_DECLARE_JNI_NATIVE_METHOD(transportMediumChanged)
+
+Q_DECLARE_JNI_CLASS(ConnectivityManager, "android/net/ConnectivityManager")
AndroidConnectivityManager::AndroidConnectivityManager()
{
if (!registerNatives())
return;
- m_connectivityManager = QJniObject::callStaticObjectMethod(
- networkInformationClass, "getConnectivityManager",
- "(Landroid/content/Context;)Landroid/net/ConnectivityManager;",
- QAndroidApplication::context());
- if (!m_connectivityManager.isValid())
- return;
-
QJniObject::callStaticMethod<void>(networkInformationClass, "registerReceiver",
- "(Landroid/content/Context;)V", QAndroidApplication::context());
+ QAndroidApplication::context());
}
AndroidConnectivityManager *AndroidConnectivityManager::getInstance()
@@ -107,36 +68,30 @@ AndroidConnectivityManager *AndroidConnectivityManager::getInstance()
: nullptr;
}
+bool AndroidConnectivityManager::isValid() const
+{
+ return registerNatives();
+}
+
AndroidConnectivityManager::~AndroidConnectivityManager()
{
QJniObject::callStaticMethod<void>(networkInformationClass, "unregisterReceiver",
- "(Landroid/content/Context;)V", QAndroidApplication::context());
+ QAndroidApplication::context());
}
-bool AndroidConnectivityManager::registerNatives()
+bool AndroidConnectivityManager::registerNatives() const
{
- QJniEnvironment env;
- QJniObject networkReceiver(networkInformationClass);
- if (!networkReceiver.isValid())
- return false;
-
- const QByteArray connectivityEnumSig =
- QByteArray("(L") + networkInformationClass + "$AndroidConnectivity;)V";
- const QByteArray transportEnumSig =
- QByteArray("(L") + networkInformationClass + "$Transport;)V";
-
- jclass clazz = env->GetObjectClass(networkReceiver.object());
- static JNINativeMethod methods[] = {
- { "connectivityChanged", connectivityEnumSig.data(),
- reinterpret_cast<void *>(networkConnectivityChanged) },
- { "genericInfoChanged", "(ZZ)V",
- reinterpret_cast<void *>(genericInfoChanged) },
- { "transportMediumChanged", transportEnumSig.data(),
- reinterpret_cast<void *>(transportMediumChangedCallback) },
- };
- const bool ret = (env->RegisterNatives(clazz, methods, std::size(methods)) == JNI_OK);
- env->DeleteLocalRef(clazz);
- return ret;
+ static const bool registered = []() {
+ QJniEnvironment env;
+ return env.registerNativeMethods(networkInformationClass, {
+ Q_JNI_NATIVE_METHOD(networkConnectivityChanged),
+ Q_JNI_NATIVE_METHOD(genericInfoChanged),
+ Q_JNI_NATIVE_METHOD(transportMediumChanged),
+ });
+ }();
+ return registered;
}
QT_END_NAMESPACE
+
+#include "moc_androidconnectivitymanager.cpp"
diff --git a/src/plugins/networkinformation/android/wrapper/androidconnectivitymanager.h b/src/plugins/networkinformation/android/wrapper/androidconnectivitymanager.h
index 414ef2748a..d15faf0e8e 100644
--- a/src/plugins/networkinformation/android/wrapper/androidconnectivitymanager.h
+++ b/src/plugins/networkinformation/android/wrapper/androidconnectivitymanager.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef ANDROIDCONNECTIVITYMANAGER_H
#define ANDROIDCONNECTIVITYMANAGER_H
@@ -69,7 +33,7 @@ public:
static AndroidConnectivityManager *getInstance();
~AndroidConnectivityManager();
- inline bool isValid() const { return m_connectivityManager.isValid(); }
+ inline bool isValid() const;
Q_SIGNALS:
void connectivityChanged(AndroidConnectivity connectivity);
@@ -80,8 +44,7 @@ Q_SIGNALS:
private:
friend struct AndroidConnectivityManagerInstance;
AndroidConnectivityManager();
- bool registerNatives();
- QJniObject m_connectivityManager;
+ bool registerNatives() const;
Q_DISABLE_COPY_MOVE(AndroidConnectivityManager);
};