1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 21:06:50 +01:00

Mi Band 1+2: make BT pairing optional

(Attemts to fix #512, #514, #518)
This commit is contained in:
cpfeiffer 2017-01-25 22:59:32 +01:00
parent d103d09fcf
commit 4c26c2933b
5 changed files with 28 additions and 6 deletions

View File

@ -19,6 +19,7 @@ public final class MiBandConst {
public static final String PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS = "mi_device_time_offset_hours"; public static final String PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS = "mi_device_time_offset_hours";
public static final String PREF_MI2_DATEFORMAT = "mi2_dateformat"; public static final String PREF_MI2_DATEFORMAT = "mi2_dateformat";
public static final String PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT = "mi2_activate_display_on_lift_wrist"; public static final String PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT = "mi2_activate_display_on_lift_wrist";
public static final String PREF_MIBAND_SETUP_BT_PAIRING = "mi_setup_bt_pairing";
public static final String ORIGIN_INCOMING_CALL = "incoming_call"; public static final String ORIGIN_INCOMING_CALL = "incoming_call";

View File

@ -159,20 +159,33 @@ public class MiBandPairingActivity extends GBActivity {
} }
private void startPairing() { private void startPairing() {
BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(macAddress);
if (device == null) {
GB.toast(this, "No such Bluetooth Device: " + macAddress, Toast.LENGTH_LONG, GB.ERROR);
return;
}
isPairing = true; isPairing = true;
message.setText(getString(R.string.pairing, macAddress)); message.setText(getString(R.string.pairing, macAddress));
if (!shouldSetupBTLevelPairing()) {
// there are connection problems on certain Galaxy S devices at least;
// try to connect without BT pairing (bonding)
attemptToConnect();
return;
}
IntentFilter filter = new IntentFilter(GBDevice.ACTION_DEVICE_CHANGED); IntentFilter filter = new IntentFilter(GBDevice.ACTION_DEVICE_CHANGED);
LocalBroadcastManager.getInstance(this).registerReceiver(mPairingReceiver, filter); LocalBroadcastManager.getInstance(this).registerReceiver(mPairingReceiver, filter);
filter = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED); filter = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
registerReceiver(mBondingReceiver, filter); registerReceiver(mBondingReceiver, filter);
BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(macAddress); performBluetoothPair(device);
if (device != null) { }
performBluetoothPair(device);
} else { private boolean shouldSetupBTLevelPairing() {
GB.toast(this, "No such Bluetooth Device: " + macAddress, Toast.LENGTH_LONG, GB.ERROR); Prefs prefs = GBApplication.getPrefs();
} return prefs.getPreferences().getBoolean(MiBandConst.PREF_MIBAND_SETUP_BT_PAIRING, true);
} }
private void pairingFinished(boolean pairedSuccessfully, String macAddress) { private void pairingFinished(boolean pairedSuccessfully, String macAddress) {

View File

@ -25,6 +25,7 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PR
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_FITNESS_GOAL; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_FITNESS_GOAL;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_SETUP_BT_PAIRING;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_USER_ALIAS; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_USER_ALIAS;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_COUNT; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_COUNT;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefKey; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefKey;

View File

@ -380,4 +380,6 @@
<string name="pebble_pairing_hint">A pairing dialog is expected to pop up on your Android device. If that does not happen, look in the notification drawer and accept the pairing request. After that accept the pairing request on your Pebble</string> <string name="pebble_pairing_hint">A pairing dialog is expected to pop up on your Android device. If that does not happen, look in the notification drawer and accept the pairing request. After that accept the pairing request on your Pebble</string>
<string name="weather_notification_label">Make sure that this skin is enabled in the Weather Notification app to get weather information on your Pebble.\n\nNo configuration is needed here.\n\nYou can enable the system weather app of your Pebble from the app management.\n\nSupported watchfaces will show the weather automatically.</string> <string name="weather_notification_label">Make sure that this skin is enabled in the Weather Notification app to get weather information on your Pebble.\n\nNo configuration is needed here.\n\nYou can enable the system weather app of your Pebble from the app management.\n\nSupported watchfaces will show the weather automatically.</string>
<string name="pref_title_setup_bt_pairing">Enable Bluetooth pairing</string>
<string name="pref_summary_setup_bt_pairing">Deactivate this if you have trouble connecting</string>
</resources> </resources>

View File

@ -275,6 +275,11 @@
<PreferenceCategory <PreferenceCategory
android:key="pref_key_development" android:key="pref_key_development"
android:title="@string/pref_header_development"> android:title="@string/pref_header_development">
<CheckBoxPreference
android:key="mi_setup_bt_pairing"
android:title="@string/pref_title_setup_bt_pairing"
android:summary="@string/pref_summary_setup_bt_pairing"
android:defaultValue="true" />
<EditTextPreference <EditTextPreference
android:digits="0123456789ABCDEF:" android:digits="0123456789ABCDEF:"
android:key="development_miaddr" android:key="development_miaddr"