Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Fix crash and make BLE background scanner configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
andyboeh committed Feb 18, 2019
1 parent a339dcb commit e069af3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
import java.util.Set;
import java.util.UUID;

import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.Logging;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.service.AbstractDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.CheckInitializedAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.AbstractBleProfile;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;

/**
* Abstract base class for all devices connected through Bluetooth Low Energy (LE) aka
Expand Down Expand Up @@ -74,7 +76,14 @@ public boolean connect() {
if (mQueue == null) {
mQueue = new BtLEQueue(getBluetoothAdapter(), getDevice(), this, this, getContext(), mSupportedServerServices);
mQueue.setAutoReconnect(getAutoReconnect());
mQueue.setBleScannerForReconnect(useBleScannerForReconnect());
GBPrefs prefs = GBApplication.getGBPrefs();
boolean autoReconnectScan = GBPrefs.AUTO_RECONNECT_SCAN_DEFAULT;
if (prefs != null) {
autoReconnectScan = prefs.getAutoReconnectScan();
}
// Override the user preference if required by the device
autoReconnectScan = autoReconnectScan || useBleScannerForReconnect();
mQueue.setBleScannerForReconnect(autoReconnectScan);
}
return mQueue.connect();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,9 @@ public void dispose() {
mDisposed = true;
// try {
disconnect();
stopBleBackgroundScan();
if(mUseBleScannerForReconnect) {
stopBleBackgroundScan();
}
dispatchThread.interrupt();
dispatchThread = null;
// dispatchThread.join();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class GBPrefs {
public static final String PACKAGE_BLACKLIST = "package_blacklist";
public static final String PACKAGE_PEBBLEMSG_BLACKLIST = "package_pebblemsg_blacklist";
public static final String CALENDAR_BLACKLIST = "calendar_blacklist";
public static final String AUTO_RECONNECT_SCAN = "general_autoreconnectscan";
public static final String AUTO_RECONNECT = "general_autocreconnect";
private static final String AUTO_START = "general_autostartonboot";
public static final String AUTO_EXPORT_ENABLED = "auto_export_enabled";
Expand All @@ -35,6 +36,7 @@ public class GBPrefs {
public static final String RTL_SUPPORT = "rtl";
public static final String RTL_CONTEXTUAL_ARABIC = "contextualArabic";
public static boolean AUTO_RECONNECT_DEFAULT = true;
public static boolean AUTO_RECONNECT_SCAN_DEFAULT = false;

public static final String USER_NAME = "mi_user_alias";
public static final String USER_NAME_DEFAULT = "gadgetbridge-user";
Expand All @@ -53,6 +55,10 @@ public boolean getAutoReconnect() {
return mPrefs.getBoolean(AUTO_RECONNECT, AUTO_RECONNECT_DEFAULT);
}

public boolean getAutoReconnectScan() {
return mPrefs.getBoolean(AUTO_RECONNECT_SCAN, AUTO_RECONNECT_SCAN_DEFAULT);
}

public boolean getAutoStart() {
return mPrefs.getBoolean(AUTO_START, AUTO_START_DEFAULT);
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -644,4 +644,5 @@
<string name="mode_configuration">Modus-Konfiguration</string>
<string name="save_configuration">Konfiguration speichern</string>
<string name="appwidget_not_connected">Nicht verbunden, Alarm nicht eingestellt.</string>
</resources>
<string name="pref_title_general_autoreconnectscan">BLE Scanner zur Wiederherstellung der Verbindung verwenden</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -690,4 +690,5 @@
<string name="mode_configuration">Mode Configuration</string>
<string name="save_configuration">Save Configuration</string>
<string name="appwidget_not_connected">Not connected, alarm not set.</string>
<string name="pref_title_general_autoreconnectscan">Use BLE Scanner for Reconnect</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
android:defaultValue="false"
android:key="general_autocreconnect"
android:title="@string/pref_title_general_autoreconnect" />
<CheckBoxPreference
android:layout="@layout/preference_checkbox"
android:defaultValue="false"
android:key="general_autoreconnectscan"
android:title="@string/pref_title_general_autoreconnectscan" />
<ListPreference
android:defaultValue="default"
android:key="audio_player"
Expand Down

0 comments on commit e069af3

Please sign in to comment.