From d8b49e6b51007d6f0a9faec82a66b95dc7ccf541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 4 Mar 2020 16:33:51 +0100 Subject: QtNetwork: Delete bearer management All remaining pieces are gone, configuration included. Relevant CMakeLists and configure.cmake were regenerated. Fixes: QTBUG-76502 Change-Id: I667b5da7e3802830d236d50b5e9190c2ee9c19e2 Reviewed-by: Lars Knoll --- .../src/wrappers/androidconnectivitymanager.cpp | 387 --------------------- .../src/wrappers/androidconnectivitymanager.h | 168 --------- .../bearer/android/src/wrappers/wrappers.pri | 6 - 3 files changed, 561 deletions(-) delete mode 100644 src/plugins/bearer/android/src/wrappers/androidconnectivitymanager.cpp delete mode 100644 src/plugins/bearer/android/src/wrappers/androidconnectivitymanager.h delete mode 100644 src/plugins/bearer/android/src/wrappers/wrappers.pri (limited to 'src/plugins/bearer/android/src/wrappers') diff --git a/src/plugins/bearer/android/src/wrappers/androidconnectivitymanager.cpp b/src/plugins/bearer/android/src/wrappers/androidconnectivitymanager.cpp deleted file mode 100644 index 6787690246..0000000000 --- a/src/plugins/bearer/android/src/wrappers/androidconnectivitymanager.cpp +++ /dev/null @@ -1,387 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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$ -** -****************************************************************************/ - -#include "androidconnectivitymanager.h" -#include -#include - -QT_BEGIN_NAMESPACE - -static inline bool exceptionCheckAndClear(JNIEnv *env) -{ - if (!env->ExceptionCheck()) - return false; - -#ifdef QT_DEBUG - env->ExceptionDescribe(); -#endif // QT_DEBUG - env->ExceptionClear(); - - return true; -} - -struct AndroidConnectivityManagerInstance -{ - AndroidConnectivityManagerInstance() - : connManager(new AndroidConnectivityManager) - { } - ~AndroidConnectivityManagerInstance() - { - delete connManager; - } - - AndroidConnectivityManager* connManager; -}; - -Q_GLOBAL_STATIC(AndroidConnectivityManagerInstance, androidConnManagerInstance) - -static const char networkReceiverClass[] = "org/qtproject/qt5/android/bearer/QtNetworkReceiver"; -static const char trafficStatsClass[] = "android/net/TrafficStats"; - -/** - * Returns the number of bytes transmitted over the mobile network since last device boot. - */ -qint64 AndroidTrafficStats::getMobileTxBytes() -{ - return QJNIObjectPrivate::callStaticMethod(trafficStatsClass, - "getMobileTxBytes", - "()J"); -} - -/** - * Returns the number of bytes received over the mobile network since last device boot. - */ -qint64 AndroidTrafficStats::getMobileRxBytes() -{ - return QJNIObjectPrivate::callStaticMethod(trafficStatsClass, - "getMobileRxBytes", - "()J"); -} - -/** - * Returns the total transmitted bytes since last device boot. - */ -qint64 AndroidTrafficStats::getTotalTxBytes() -{ - return QJNIObjectPrivate::callStaticMethod(trafficStatsClass, - "getTotalTxBytes", - "()J"); -} - -/** - * Returns the total received bytes since last device boot. - */ -qint64 AndroidTrafficStats::getTotalRxBytes() -{ - return QJNIObjectPrivate::callStaticMethod(trafficStatsClass, - "getTotalRxBytes", - "()J"); -} - -bool AndroidTrafficStats::isTrafficStatsSupported() -{ - // Before API level 18 DataStatistics might not be supported, so make sure that we get something - // else then -1 from from getXXBytes(). - return (AndroidTrafficStats::getMobileRxBytes() != -1 - && AndroidTrafficStats::getTotalRxBytes() != -1); -} - -static AndroidNetworkInfo::NetworkState stateForName(const QString &stateName) -{ - if (stateName == QLatin1String("CONNECTED")) - return AndroidNetworkInfo::Connected; - else if (stateName == QLatin1String("CONNECTING")) - return AndroidNetworkInfo::Connecting; - else if (stateName == QLatin1String("DISCONNECTED")) - return AndroidNetworkInfo::Disconnected; - else if (stateName == QLatin1String("DISCONNECTING")) - return AndroidNetworkInfo::Disconnecting; - else if (stateName == QLatin1String("SUSPENDED")) - return AndroidNetworkInfo::Suspended; - - return AndroidNetworkInfo::UnknownState; -} - -AndroidNetworkInfo::NetworkState AndroidNetworkInfo::getDetailedState() const -{ - QJNIObjectPrivate enumObject = m_networkInfo.callObjectMethod("getDetailedState", - "()Landroid/net/NetworkInfo$DetailedState;"); - if (!enumObject.isValid()) - return UnknownState; - - QJNIObjectPrivate enumName = enumObject.callObjectMethod("name"); - if (!enumName.isValid()) - return UnknownState; - - return stateForName(enumName.toString()); -} - -QString AndroidNetworkInfo::getExtraInfo() const -{ - QJNIObjectPrivate extraInfo = m_networkInfo.callObjectMethod("getExtraInfo"); - if (!extraInfo.isValid()) - return QString(); - - return extraInfo.toString(); -} - -QString AndroidNetworkInfo::getReason() const -{ - QJNIObjectPrivate reason = m_networkInfo.callObjectMethod("getReason"); - if (!reason.isValid()) - return QString(); - - return reason.toString(); -} - -AndroidNetworkInfo::NetworkState AndroidNetworkInfo::getState() const -{ - QJNIObjectPrivate enumObject = m_networkInfo.callObjectMethod("getState", - "()Landroid/net/NetworkInfo$State;"); - if (!enumObject.isValid()) - return UnknownState; - - QJNIObjectPrivate enumName = enumObject.callObjectMethod("name"); - if (!enumName.isValid()) - return UnknownState; - - return stateForName(enumName.toString()); -} - -AndroidNetworkInfo::NetworkSubType AndroidNetworkInfo::getSubtype() const -{ - return AndroidNetworkInfo::NetworkSubType(m_networkInfo.callMethod("getSubtype")); -} - -QString AndroidNetworkInfo::getSubtypeName() const -{ - QJNIObjectPrivate subtypeName = m_networkInfo.callObjectMethod("getSubtypeName"); - if (!subtypeName.isValid()) - return QString(); - - return subtypeName.toString(); -} - -AndroidNetworkInfo::NetworkType AndroidNetworkInfo::getType() const -{ - return AndroidNetworkInfo::NetworkType(m_networkInfo.callMethod("getType")); -} - -QString AndroidNetworkInfo::getTypeName() const -{ - QJNIObjectPrivate typeName = m_networkInfo.callObjectMethod("getTypeName"); - if (!typeName.isValid()) - return QString(); - - return typeName.toString(); -} - -bool AndroidNetworkInfo::isAvailable() const -{ - return m_networkInfo.callMethod("isAvailable"); -} - -bool AndroidNetworkInfo::isConnected() const -{ - return m_networkInfo.callMethod("isConnected"); -} - -bool AndroidNetworkInfo::isConnectedOrConnecting() const -{ - return m_networkInfo.callMethod("isConnectedOrConnecting"); -} - -bool AndroidNetworkInfo::isFailover() const -{ - return m_networkInfo.callMethod("isFailover"); -} - -bool AndroidNetworkInfo::isRoaming() const -{ - return m_networkInfo.callMethod("isRoaming"); -} - -bool AndroidNetworkInfo::isValid() const -{ - return m_networkInfo.isValid(); -} - -AndroidConnectivityManager::AndroidConnectivityManager() -{ - QJNIEnvironmentPrivate env; - if (!registerNatives(env)) - return; - - m_connectivityManager = QJNIObjectPrivate::callStaticObjectMethod(networkReceiverClass, - "getConnectivityManager", - "(Landroid/content/Context;)Landroid/net/ConnectivityManager;", - QtAndroidPrivate::context()); - if (!m_connectivityManager.isValid()) - return; - - QJNIObjectPrivate::callStaticMethod(networkReceiverClass, - "registerReceiver", - "(Landroid/content/Context;)V", - QtAndroidPrivate::context()); -} - -AndroidConnectivityManager *AndroidConnectivityManager::getInstance() -{ - return androidConnManagerInstance->connManager->isValid() - ? androidConnManagerInstance->connManager - : 0; -} - -AndroidConnectivityManager::~AndroidConnectivityManager() -{ - QJNIObjectPrivate::callStaticMethod(networkReceiverClass, - "unregisterReceiver", - "(Landroid/content/Context;)V", - QtAndroidPrivate::context()); -} - -AndroidNetworkInfo AndroidConnectivityManager::getActiveNetworkInfo() const -{ - QJNIObjectPrivate networkInfo = m_connectivityManager.callObjectMethod("getActiveNetworkInfo", - "()Landroid/net/NetworkInfo;"); - return networkInfo; -} - -QList AndroidConnectivityManager::getAllNetworkInfo() const -{ - QJNIEnvironmentPrivate env; - QJNIObjectPrivate objArray = m_connectivityManager.callObjectMethod("getAllNetworkInfo", - "()[Landroid/net/NetworkInfo;"); - QList list; - if (!objArray.isValid()) - return list; - - const jsize length = env->GetArrayLength(static_cast(objArray.object())); - if (exceptionCheckAndClear(env)) - return list; - - for (int i = 0; i != length; ++i) { - jobject lref = env->GetObjectArrayElement(static_cast(objArray.object()), i); - if (exceptionCheckAndClear(env)) - break; - - list << AndroidNetworkInfo(QJNIObjectPrivate::fromLocalRef(lref)); - } - - return list; -} - -bool AndroidConnectivityManager::getBackgroundDataSetting() const -{ - return m_connectivityManager.callMethod("getBackgroundDataSetting"); -} - -AndroidNetworkInfo AndroidConnectivityManager::getNetworkInfo(int networkType) const -{ - QJNIObjectPrivate networkInfo = m_connectivityManager.callObjectMethod("getNetworkInfo", - "(I)Landroid/net/NetworkInfo;", - networkType); - return networkInfo; -} - -int AndroidConnectivityManager::getNetworkPreference() const -{ - return m_connectivityManager.callMethod("getNetworkPreference"); -} - -bool AndroidConnectivityManager::isActiveNetworkMetered() const -{ - return m_connectivityManager.callMethod("isActiveNetworkMetered"); -} - -bool AndroidConnectivityManager::isNetworkTypeValid(int networkType) -{ - return QJNIObjectPrivate::callStaticMethod("android/net/ConnectivityManager", - "isNetworkTypeValid", - "(I)Z", - networkType); -} - -bool AndroidConnectivityManager::requestRouteToHost(int networkType, int hostAddress) -{ - return m_connectivityManager.callMethod("requestRouteToHost", "(II)Z", networkType, hostAddress); -} - -void AndroidConnectivityManager::setNetworkPreference(int preference) -{ - m_connectivityManager.callMethod("setNetworkPreference", "(I)V", preference); -} - -int AndroidConnectivityManager::startUsingNetworkFeature(int networkType, const QString &feature) -{ - QJNIObjectPrivate jfeature = QJNIObjectPrivate::fromString(feature); - return m_connectivityManager.callMethod("startUsingNetworkFeature", - "(ILjava/lang/String;)I", - networkType, - jfeature.object()); -} - -int AndroidConnectivityManager::stopUsingNetworkFeature(int networkType, const QString &feature) -{ - QJNIObjectPrivate jfeature = QJNIObjectPrivate::fromString(feature); - return m_connectivityManager.callMethod("stopUsingNetworkFeature", - "(ILjava/lang/String;)I", - networkType, - jfeature.object()); -} - -static void activeNetworkInfoChanged() -{ - Q_EMIT androidConnManagerInstance->connManager->activeNetworkChanged(); -} - -bool AndroidConnectivityManager::registerNatives(JNIEnv *env) -{ - QJNIObjectPrivate networkReceiver(networkReceiverClass); - if (!networkReceiver.isValid()) - return false; - - jclass clazz = env->GetObjectClass(networkReceiver.object()); - static JNINativeMethod method = {"activeNetworkInfoChanged", "()V", reinterpret_cast(activeNetworkInfoChanged)}; - const bool ret = (env->RegisterNatives(clazz, &method, 1) == JNI_OK); - env->DeleteLocalRef(clazz); - return ret; -} - -QT_END_NAMESPACE diff --git a/src/plugins/bearer/android/src/wrappers/androidconnectivitymanager.h b/src/plugins/bearer/android/src/wrappers/androidconnectivitymanager.h deleted file mode 100644 index 7c410b0087..0000000000 --- a/src/plugins/bearer/android/src/wrappers/androidconnectivitymanager.h +++ /dev/null @@ -1,168 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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$ -** -****************************************************************************/ - -#ifndef ANDROIDCONNECTIVITYMANAGER_H -#define ANDROIDCONNECTIVITYMANAGER_H - -#include -#include - -QT_BEGIN_NAMESPACE - -class AndroidTrafficStats -{ -public: - static qint64 getMobileTxBytes(); - static qint64 getMobileRxBytes(); - static qint64 getTotalTxBytes(); - static qint64 getTotalRxBytes(); - static bool isTrafficStatsSupported(); -}; - -class AndroidNetworkInfo -{ -public: - // Needs to be in sync with the values from the android api. - enum NetworkState { - UnknownState, - Authenticating, - Blocked, - CaptivePortalCheck, - Connected, - Connecting, - Disconnected, - Disconnecting, - Failed, - Idle, - ObtainingIpAddr, - Scanning, - Suspended, - VerifyingPoorLink - }; - - enum NetworkType { - Mobile, - Wifi, - MobileMms, - MobileSupl, - MobileDun, - MobileHipri, - Wimax, - Bluetooth, - Dummy, - Ethernet, - UnknownType - }; - - enum NetworkSubType { - UnknownSubType, - Gprs, - Edge, - Umts, - Cdma, - Evdo0, - EvdoA, - Cdma1xRTT, - Hsdpa, - Hsupa, - Hspa, - Iden, - EvdoB, - Lte, - Ehrpd, - Hspap - }; - - inline AndroidNetworkInfo(const QJNIObjectPrivate &obj) : m_networkInfo(obj) - { } - - NetworkState getDetailedState() const; - QString getExtraInfo() const; - QString getReason() const; - NetworkState getState() const; - NetworkSubType getSubtype() const; - QString getSubtypeName() const; - NetworkType getType() const; - QString getTypeName() const; - bool isAvailable() const; - bool isConnected() const; - bool isConnectedOrConnecting() const; - bool isFailover() const; - bool isRoaming() const; - bool isValid() const; - -private: - QJNIObjectPrivate m_networkInfo; -}; - -class AndroidConnectivityManager : public QObject -{ - Q_OBJECT -public: - static AndroidConnectivityManager *getInstance(); - ~AndroidConnectivityManager(); - - AndroidNetworkInfo getActiveNetworkInfo() const; - QList getAllNetworkInfo() const; - bool getBackgroundDataSetting() const; - AndroidNetworkInfo getNetworkInfo(int networkType) const; - int getNetworkPreference() const; - bool isActiveNetworkMetered() const; - static bool isNetworkTypeValid(int networkType); - bool requestRouteToHost(int networkType, int hostAddress); - void setNetworkPreference(int preference); - int startUsingNetworkFeature(int networkType, const QString &feature); - int stopUsingNetworkFeature(int networkType, const QString &feature); - inline bool isValid() const - { - return m_connectivityManager.isValid(); - } - - Q_SIGNAL void activeNetworkChanged(); - -private: - friend struct AndroidConnectivityManagerInstance; - AndroidConnectivityManager(); - bool registerNatives(JNIEnv *env); - QJNIObjectPrivate m_connectivityManager; -}; - -QT_END_NAMESPACE - -#endif // ANDROIDCONNECTIVITYMANAGER_H diff --git a/src/plugins/bearer/android/src/wrappers/wrappers.pri b/src/plugins/bearer/android/src/wrappers/wrappers.pri deleted file mode 100644 index 209b76e533..0000000000 --- a/src/plugins/bearer/android/src/wrappers/wrappers.pri +++ /dev/null @@ -1,6 +0,0 @@ -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/androidconnectivitymanager.h -SOURCES += \ - $$PWD/androidconnectivitymanager.cpp -- cgit v1.2.3