diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java index 83aa6ab2f..d18dcb9e8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java @@ -29,6 +29,7 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ITEMS; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_END; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_START; +import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_EXPOSE_HR_THIRDPARTY; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_LANGUAGE; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_END; @@ -287,6 +288,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat { addPreferenceHandlerFor(PREF_DATEFORMAT); addPreferenceHandlerFor(PREF_DISPLAY_ITEMS); addPreferenceHandlerFor(PREF_LANGUAGE); + addPreferenceHandlerFor(PREF_EXPOSE_HR_THIRDPARTY); String displayOnLiftState = prefs.getString(PREF_ACTIVATE_DISPLAY_ON_LIFT, PREF_DO_NOT_DISTURB_OFF); boolean displayOnLiftScheduled = displayOnLiftState.equals(PREF_DO_NOT_DISTURB_SCHEDULED); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiConst.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiConst.java index d595f37f0..fe47cb21f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiConst.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiConst.java @@ -61,7 +61,7 @@ public class HuamiConst { public static final String PREF_DISPLAY_ITEMS = "display_items"; public static final String PREF_LANGUAGE = "language"; public static final String PREF_DATEFORMAT = "dateformat"; - + public static final String PREF_EXPOSE_HR_THIRDPARTY = "expose_hr_thirdparty"; public static int toActivityKind(int rawType) { switch (rawType) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java index 0c1951c58..d7bf1d353 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java @@ -251,6 +251,11 @@ public abstract class HuamiCoordinator extends AbstractDeviceCoordinator { return prefs.getBoolean(MiBandConst.PREF_SWIPE_UNLOCK, false); } + public static boolean getExposeHRThirdParty(String deviceAddress) { + Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(deviceAddress)); + return prefs.getBoolean(HuamiConst.PREF_EXPOSE_HR_THIRDPARTY, false); + } + protected static Date getTimePreference(String key, String defaultValue, String deviceAddress) { Prefs prefs; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiService.java index 86fd89ff2..b18466afc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiService.java @@ -139,6 +139,8 @@ public class HuamiService { public static final byte[] DATEFORMAT_TIME_12_HOURS = new byte[] {ENDPOINT_DISPLAY, 0x02, 0x0, 0x0 }; public static final byte[] DATEFORMAT_TIME_24_HOURS = new byte[] {ENDPOINT_DISPLAY, 0x02, 0x0, 0x1 }; public static final byte[] DATEFORMAT_DATE_MM_DD_YYYY = new byte[]{ENDPOINT_DISPLAY, 30, 0x00, 'M', 'M', '/', 'd', 'd', '/', 'y', 'y', 'y', 'y'}; + public static final byte[] COMMAND_ENBALE_HR_CONNECTION = new byte[]{ENDPOINT_DISPLAY, 0x01, 0x00, 0x01}; + public static final byte[] COMMAND_DISABLE_HR_CONNECTION = new byte[]{ENDPOINT_DISPLAY, 0x01, 0x00, 0x00}; public static final byte[] COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x01}; public static final byte[] COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x00}; public static final byte[] COMMAND_SCHEDULE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00}; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipCoordinator.java index 547a9be75..1971dd48c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipCoordinator.java @@ -83,6 +83,7 @@ public class AmazfitBipCoordinator extends HuamiCoordinator { R.xml.devicesettings_amazfitbip, R.xml.devicesettings_liftwrist_display, R.xml.devicesettings_disconnectnotification, + R.xml.devicesettings_expose_hr_thirdparty, R.xml.devicesettings_pairingkey }; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcor/AmazfitCorCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcor/AmazfitCorCoordinator.java index 0fa0fdbda..96ac2e9fc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcor/AmazfitCorCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcor/AmazfitCorCoordinator.java @@ -86,6 +86,8 @@ public class AmazfitCorCoordinator extends HuamiCoordinator { R.xml.devicesettings_amazfitcor, R.xml.devicesettings_liftwrist_display, R.xml.devicesettings_disconnectnotification, - R.xml.devicesettings_pairingkey}; + R.xml.devicesettings_expose_hr_thirdparty, + R.xml.devicesettings_pairingkey + }; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband3/MiBand3Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband3/MiBand3Coordinator.java index 4c2404159..ad757c876 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband3/MiBand3Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband3/MiBand3Coordinator.java @@ -108,6 +108,7 @@ public class MiBand3Coordinator extends HuamiCoordinator { R.xml.devicesettings_donotdisturb_withauto, R.xml.devicesettings_liftwrist_display, R.xml.devicesettings_swipeunlock, + R.xml.devicesettings_expose_hr_thirdparty, R.xml.devicesettings_pairingkey }; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband4/MiBand4Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband4/MiBand4Coordinator.java index 31c0796d6..fba3a5856 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband4/MiBand4Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband4/MiBand4Coordinator.java @@ -92,6 +92,7 @@ public class MiBand4Coordinator extends HuamiCoordinator { R.xml.devicesettings_nightmode, R.xml.devicesettings_liftwrist_display, R.xml.devicesettings_swipeunlock, + R.xml.devicesettings_expose_hr_thirdparty, R.xml.devicesettings_pairingkey }; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java index b8f1f7624..8accd9e62 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java @@ -1568,6 +1568,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport { case HuamiConst.PREF_LANGUAGE: setLanguage(builder); break; + case HuamiConst.PREF_EXPOSE_HR_THIRDPARTY: + setExposeHRThridParty(builder); + break; } builder.queue(getQueue()); } catch (IOException e) { @@ -2095,6 +2098,20 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport { return this; } + + private HuamiSupport setExposeHRThridParty(TransactionBuilder builder) { + boolean enable = HuamiCoordinator.getExposeHRThirdParty(gbDevice.getAddress()); + LOG.info("Setting exposure of HR to third party apps to: " + enable); + + if (enable) { + builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_ENBALE_HR_CONNECTION); + } else { + builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_DISABLE_HR_CONNECTION); + } + + return this; + } + protected void writeToChunked(TransactionBuilder builder, int type, byte[] data) { final int MAX_CHUNKLENGTH = 17; int remaining = data.length; @@ -2145,6 +2162,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport { setInactivityWarnings(builder); setHeartrateSleepSupport(builder); setDisconnectNotification(builder); + setExposeHRThridParty(builder); setHeartrateMeasurementInterval(builder, getHeartRateMeasurementInterval()); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a7eb31a4c..16289fdc8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -165,6 +165,9 @@ Enable background JS When enabled, allows watchfaces to show weather, battery info etc. Reconnection attempts + Allows other apps to access HR data in realtime while Gadgetbridge is connected + 3rd party realtime HR access + Units Time format diff --git a/app/src/main/res/xml/devicesettings_expose_hr_thirdparty.xml b/app/src/main/res/xml/devicesettings_expose_hr_thirdparty.xml new file mode 100644 index 000000000..4a5ab035c --- /dev/null +++ b/app/src/main/res/xml/devicesettings_expose_hr_thirdparty.xml @@ -0,0 +1,9 @@ + + + +