mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-11 01:21:56 +01:00
Allow to set discovery scanning level to prevent freezing
This commit is contained in:
parent
5b936db9b6
commit
a9cd3412ee
@ -198,6 +198,8 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
||||
}
|
||||
}
|
||||
};
|
||||
int CallbackType = android.bluetooth.le.ScanSettings.CALLBACK_TYPE_ALL_MATCHES;
|
||||
int MatchMode = android.bluetooth.le.ScanSettings.MATCH_MODE_STICKY;
|
||||
|
||||
public void logMessageContent(byte[] value) {
|
||||
if (value != null) {
|
||||
@ -654,17 +656,17 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
||||
private ScanSettings getScanSettings() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
return new ScanSettings.Builder()
|
||||
.setCallbackType(android.bluetooth.le.ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
|
||||
.setCallbackType(CallbackType)
|
||||
.setScanMode(android.bluetooth.le.ScanSettings.SCAN_MODE_LOW_LATENCY)
|
||||
.setMatchMode(android.bluetooth.le.ScanSettings.MATCH_MODE_AGGRESSIVE)
|
||||
.setMatchMode(MatchMode)
|
||||
.setPhy(android.bluetooth.le.ScanSettings.PHY_LE_ALL_SUPPORTED)
|
||||
.setNumOfMatches(android.bluetooth.le.ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT)
|
||||
.build();
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
return new ScanSettings.Builder()
|
||||
.setCallbackType(android.bluetooth.le.ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
|
||||
.setCallbackType(CallbackType)
|
||||
.setScanMode(android.bluetooth.le.ScanSettings.SCAN_MODE_LOW_LATENCY)
|
||||
.setMatchMode(android.bluetooth.le.ScanSettings.MATCH_MODE_AGGRESSIVE)
|
||||
.setMatchMode(MatchMode)
|
||||
.setNumOfMatches(android.bluetooth.le.ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT)
|
||||
.build();
|
||||
} else {
|
||||
@ -910,6 +912,26 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
||||
if (oldBleScanning) {
|
||||
LOG.info("New BLE scanning disabled via settings, using old method");
|
||||
}
|
||||
int level = prefs.getInt("scanning_intensity", 1);
|
||||
switch (level) {
|
||||
case 0:
|
||||
CallbackType = android.bluetooth.le.ScanSettings.CALLBACK_TYPE_FIRST_MATCH;
|
||||
MatchMode = android.bluetooth.le.ScanSettings.MATCH_MODE_STICKY;
|
||||
break;
|
||||
case 1:
|
||||
CallbackType = android.bluetooth.le.ScanSettings.CALLBACK_TYPE_FIRST_MATCH;
|
||||
MatchMode = android.bluetooth.le.ScanSettings.MATCH_MODE_AGGRESSIVE;
|
||||
break;
|
||||
case 2:
|
||||
CallbackType = android.bluetooth.le.ScanSettings.CALLBACK_TYPE_ALL_MATCHES;
|
||||
MatchMode = android.bluetooth.le.ScanSettings.MATCH_MODE_STICKY;
|
||||
break;
|
||||
case 3:
|
||||
CallbackType = android.bluetooth.le.ScanSettings.CALLBACK_TYPE_ALL_MATCHES;
|
||||
MatchMode = android.bluetooth.le.ScanSettings.MATCH_MODE_AGGRESSIVE;
|
||||
break;
|
||||
}
|
||||
LOG.debug("Device discovery - scanning level: " + level + " " + CallbackType + " " + MatchMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,14 +18,33 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
|
||||
public class DiscoveryPairingPreferenceActivity extends AbstractSettingsActivity {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AbstractSettingsActivity.class);
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.discovery_pairing_preferences);
|
||||
|
||||
final Prefs prefs = GBApplication.getPrefs();
|
||||
final Preference pref = findPreference("scanning_intensity");
|
||||
pref.setSummary(String.valueOf(prefs.getInt("scanning_intensity", 2)));
|
||||
|
||||
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
||||
preference.setSummary(newVal.toString());
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
|
@ -387,6 +387,8 @@
|
||||
<string name="pref_auto_fetch_limit_fetches">Minimum time between fetches</string>
|
||||
<string name="pref_auto_fetch_limit_fetches_summary">Fetches every %d minutes</string>
|
||||
<!-- developer/debug preferences-->
|
||||
<string name="discovery_scanning_intensity">Scanning intensity</string>
|
||||
<string name="discovery_scanning_intensity_warning">If you experience freezing or unresponsiveness, try to set Scanning intensity to lower level. If your device is not being discovered, try to set Scanning intensity to higher level.</string>
|
||||
<string name="pref_disable_new_ble_scanning">Disable new BLE scanning</string>
|
||||
<string name="pref_summary_disable_new_ble_scanning">Check this option if your device cannot be found during discovery</string>
|
||||
<string name="not_connected">Not connected</string>
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<PreferenceCategory
|
||||
android:key="pref_discovery_pairing"
|
||||
android:title="@string/activity_prefs_discovery_pairing">
|
||||
@ -27,5 +28,17 @@
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:summary="@string/discover_unsupported_devices_description"
|
||||
android:title="@string/discover_unsupported_devices" />
|
||||
<SeekBarPreference
|
||||
android:key="scanning_intensity"
|
||||
android:max="3"
|
||||
android:min="0"
|
||||
android:title="@string/discovery_scanning_intensity"
|
||||
app:defaultValue="2"
|
||||
app:showSeekBarValue="true" />
|
||||
<Preference
|
||||
android:selectable="false"
|
||||
android:persistent="false"
|
||||
android:summary="@string/discovery_scanning_intensity_warning" />
|
||||
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
Loading…
Reference in New Issue
Block a user