Add a check for location services being enabled in BtWiFi setup

This commit is contained in:
Michael Zanetti 2022-12-07 20:18:05 +01:00
parent e73eb3ed7a
commit 2b15ad34aa
8 changed files with 103 additions and 3 deletions

View File

@ -218,3 +218,5 @@ win32 {
target.path = /usr/bin
INSTALLS += target
DISTFILES +=

View File

@ -239,6 +239,11 @@ void PlatformHelper::shareFile(const QString &fileName)
QDesktopServices::openUrl(QUrl(fileName));
}
bool PlatformHelper::locationServicesEnabled() const
{
return true;
}
QObject *PlatformHelper::platformHelperProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine)

View File

@ -57,6 +57,7 @@ class PlatformHelper : public QObject
Q_PROPERTY(QColor bottomPanelColor READ bottomPanelColor WRITE setBottomPanelColor NOTIFY bottomPanelColorChanged)
Q_PROPERTY(bool darkModeEnabled READ darkModeEnabled NOTIFY darkModeEnabledChanged)
Q_PROPERTY(QVariantList pendingNotificationActions READ pendingNotificationActions NOTIFY pendingNotificationActionsChanged)
Q_PROPERTY(bool locationServicesEnabled READ locationServicesEnabled NOTIFY locationServicesEnabledChanged)
public:
enum HapticsFeedback {
@ -108,6 +109,8 @@ public:
void notificationActionReceived(const QString &nymeaData);
virtual bool locationServicesEnabled() const;
signals:
void screenTimeoutChanged();
void screenBrightnessChanged();
@ -116,6 +119,7 @@ signals:
void darkModeEnabledChanged();
void splashVisibleChanged();
void pendingNotificationActionsChanged();
void locationServicesEnabledChanged();
protected:
explicit PlatformHelper(QObject *parent = nullptr);

View File

@ -13,6 +13,9 @@ import android.os.Vibrator;
import android.net.Uri;
import android.support.v4.content.FileProvider;
import android.content.res.Configuration;
import android.content.IntentFilter;
import android.content.BroadcastReceiver;
import android.location.LocationManager;
public class NymeaAppActivity extends org.qtproject.qt5.android.bindings.QtActivity
{
@ -21,6 +24,17 @@ public class NymeaAppActivity extends org.qtproject.qt5.android.bindings.QtActiv
private static native void darkModeEnabledChangedJNI();
private static native void notificationActionReceivedJNI(String data);
private static native void locationServicesEnabledChangedJNI();
private BroadcastReceiver m_gpsSwitchStateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "**** Intent received!!!" + intent.getAction());
if (LocationManager.MODE_CHANGED_ACTION.equals(intent.getAction())) {
locationServicesEnabledChangedJNI();
}
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
@ -37,6 +51,21 @@ public class NymeaAppActivity extends org.qtproject.qt5.android.bindings.QtActiv
}
}
@Override
public void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter(LocationManager.MODE_CHANGED_ACTION);
// filter.addAction(Intent.ACTION_PROVIDER_CHANGED);
registerReceiver(m_gpsSwitchStateReceiver, filter);
}
@Override
public void onPause() {
super.onPause();
unregisterReceiver(m_gpsSwitchStateReceiver);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
@ -93,4 +122,9 @@ public class NymeaAppActivity extends org.qtproject.qt5.android.bindings.QtActiv
public boolean darkModeEnabled() {
return (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
}
public boolean locationServicesEnabled() {
LocationManager lm = (LocationManager)getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
return lm.isLocationEnabled();
}
}

View File

@ -0,0 +1,20 @@
package io.guh.nymeaapp;
import android.util.Log;
import android.content.Context;
import android.content.Intent;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
public class NymeaAppBroadcastReceiver extends BroadcastReceiver
{
private static final String TAG = "nymea-app: BroadcastReceiver";
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d(TAG, "Broadcast received: " + action);
}
}

View File

@ -34,6 +34,7 @@
#include <QtAndroid>
#include <QDebug>
#include <QAndroidIntent>
#include <QApplication>
// WindowManager.LayoutParams
@ -49,6 +50,7 @@ static PlatformHelperAndroid *m_instance = nullptr;
static JNINativeMethod methods[] = {
{ "darkModeEnabledChangedJNI", "()V", (void *)PlatformHelperAndroid::darkModeEnabledChangedJNI },
{ "notificationActionReceivedJNI", "(Ljava/lang/String;)V", (void *)PlatformHelperAndroid::notificationActionReceivedJNI },
{ "locationServicesEnabledChangedJNI", "()V", (void *)PlatformHelperAndroid::locationServicesEnabledChangedJNI },
};
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/)
@ -82,6 +84,13 @@ PlatformHelperAndroid::PlatformHelperAndroid(QObject *parent) : PlatformHelper(p
if (!notificationData.isNull()) {
notificationActionReceived(notificationData);
}
connect(qApp, &QApplication::applicationStateChanged, this, [this](Qt::ApplicationState state){
qCritical() << "******* app state change";
if (state == Qt::ApplicationActive) {
emit locationServicesEnabledChanged();
}
});
}
void PlatformHelperAndroid::hideSplashScreen()
@ -247,6 +256,12 @@ bool PlatformHelperAndroid::darkModeEnabled() const
return QtAndroid::androidActivity().callMethod<jboolean>("darkModeEnabled");
}
bool PlatformHelperAndroid::locationServicesEnabled() const
{
jboolean enabled = QtAndroid::androidActivity().callMethod<jboolean>("locationServicesEnabled", "()Z");
return enabled;
}
void PlatformHelperAndroid::shareFile(const QString &fileName)
{
QtAndroid::androidActivity().callMethod<void>("shareFile", "(Ljava/lang/String;)V",
@ -270,3 +285,11 @@ void PlatformHelperAndroid::notificationActionReceivedJNI(JNIEnv *env, jobject,
platformHelper->notificationActionReceived(env->GetStringUTFChars(data, nullptr));
}
}
void PlatformHelperAndroid::locationServicesEnabledChangedJNI()
{
PlatformHelper* platformHelper = PlatformHelperAndroid::instance(false);
if (platformHelper) {
emit platformHelper->locationServicesEnabledChanged();
}
}

View File

@ -62,10 +62,13 @@ public:
bool darkModeEnabled() const override;
bool locationServicesEnabled() const override;
void shareFile(const QString &fileName) override;
static void darkModeEnabledChangedJNI();
static void notificationActionReceivedJNI(JNIEnv *env, jobject /*thiz*/, jstring data);
static void locationServicesEnabledChangedJNI();
private:
static void permissionRequestFinished(const QtAndroid::PermissionResultMap &);

View File

@ -491,7 +491,7 @@ WizardPageBase {
BluetoothDiscovery {
id: bluetoothDiscovery
discoveryEnabled: pageStack.currentItem === wirelessBluetoothDiscoveryPage
discoveryEnabled: pageStack.currentItem === wirelessBluetoothDiscoveryPage && PlatformHelper.locationServicesEnabled
}
content: ListView {
@ -510,7 +510,7 @@ WizardPageBase {
BusyIndicator {
anchors.centerIn: parent
visible: bluetoothDiscovery.discovering && deviceInfosProxy.count == 0
visible: bluetoothDiscovery.discovering && deviceInfosProxy.count == 0 && bluetoothDiscovery.bluetoothAvailable && bluetoothDiscovery.bluetoothEnabled && PlatformHelper.locationServicesEnabled
}
delegate: NymeaSwipeDelegate {
@ -529,7 +529,7 @@ WizardPageBase {
width: parent.width - Style.margins * 2
anchors.centerIn: parent
spacing: Style.bigMargins
visible: !bluetoothDiscovery.bluetoothAvailable || !bluetoothDiscovery.bluetoothEnabled
visible: !bluetoothDiscovery.bluetoothAvailable || !bluetoothDiscovery.bluetoothEnabled || !PlatformHelper.locationServicesEnabled
ColorIcon {
name: "/ui/images/connections/bluetooth.svg"
@ -542,10 +542,19 @@ WizardPageBase {
Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap
visible: !bluetoothDiscovery.bluetoothAvailable || !bluetoothDiscovery.bluetoothEnabled
text: !bluetoothDiscovery.bluetoothAvailable
? qsTr("Bluetooth doesn't seem to be available on this system.")
: qsTr("Bluetooth is turned off. Please enable Bluetooth on this device.")
}
Label {
Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap
visible: !PlatformHelper.locationServicesEnabled
text: qsTr("Location services are disabled. Please enable location services on this device in order to search for nearby nymea:energy gateways.")
}
}
}