NetworkInformation/Android: Delete member only used for validity check
And instead base the isValid function on the success of registering callbacks. The registerReceiver call has no way to report failures so I assume it always succeeds. Task-number: QTBUG-104188 Change-Id: I2b002f791d03f2ebc72fe5cfa215f8f8a1dabdf8 Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
parent
ba36f7947a
commit
72cfcf13c5
@ -55,11 +55,6 @@ AndroidConnectivityManager::AndroidConnectivityManager()
|
||||
if (!registerNatives())
|
||||
return;
|
||||
|
||||
m_connectivityManager = QJniObject::callStaticObjectMethod<QtJniTypes::ConnectivityManager>(
|
||||
networkInformationClass, "getConnectivityManager", QAndroidApplication::context());
|
||||
if (!m_connectivityManager.isValid())
|
||||
return;
|
||||
|
||||
QJniObject::callStaticMethod<void>(networkInformationClass, "registerReceiver",
|
||||
QAndroidApplication::context());
|
||||
}
|
||||
@ -73,15 +68,20 @@ AndroidConnectivityManager *AndroidConnectivityManager::getInstance()
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
bool AndroidConnectivityManager::isValid() const
|
||||
{
|
||||
return registerNatives();
|
||||
}
|
||||
|
||||
AndroidConnectivityManager::~AndroidConnectivityManager()
|
||||
{
|
||||
QJniObject::callStaticMethod<void>(networkInformationClass, "unregisterReceiver",
|
||||
QAndroidApplication::context());
|
||||
}
|
||||
|
||||
bool AndroidConnectivityManager::registerNatives()
|
||||
bool AndroidConnectivityManager::registerNatives() const
|
||||
{
|
||||
static bool registered = []() {
|
||||
static const bool registered = []() {
|
||||
QJniEnvironment env;
|
||||
return env.registerNativeMethods(networkInformationClass, {
|
||||
Q_JNI_NATIVE_METHOD(networkConnectivityChanged),
|
||||
|
@ -33,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);
|
||||
@ -44,8 +44,7 @@ Q_SIGNALS:
|
||||
private:
|
||||
friend struct AndroidConnectivityManagerInstance;
|
||||
AndroidConnectivityManager();
|
||||
bool registerNatives();
|
||||
QJniObject m_connectivityManager;
|
||||
bool registerNatives() const;
|
||||
|
||||
Q_DISABLE_COPY_MOVE(AndroidConnectivityManager);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user