From d1e692a94e348dda0b03dabd7e2c5149b5f41a85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuli=20M=C3=A4=C3=A4tt=C3=A4?= Date: Thu, 28 Sep 2023 11:56:28 +0300 Subject: [PATCH] SDK release 5.4.0 --- .../bluedroid/host/BDDeviceSessionImpl.java | 9 ++++++++- .../sdk/java/com/polar/sdk/api/PolarBleApi.kt | 9 +++++++++ .../polar/sdk/api/PolarBleApiDefaultImpl.kt | 2 +- .../java/com/polar/sdk/impl/BDBleApiImpl.kt | 14 ++++++++++++++ .../src/sdk/proto/pftp_notification.proto | 7 +++++++ .../PolarBleSdk/sdk/api/PolarBleApi.swift | 10 ++++++++++ .../sdk/api/PolarBleApiDefaultImpl.swift | 2 +- .../PolarBleSdk/sdk/impl/PolarBleApiImpl.swift | 18 ++++++++++++++++++ 8 files changed, 68 insertions(+), 3 deletions(-) diff --git a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/enpoints/ble/bluedroid/host/BDDeviceSessionImpl.java b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/enpoints/ble/bluedroid/host/BDDeviceSessionImpl.java index c9a7a38a..a0c2cf4e 100755 --- a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/enpoints/ble/bluedroid/host/BDDeviceSessionImpl.java +++ b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/enpoints/ble/bluedroid/host/BDDeviceSessionImpl.java @@ -69,6 +69,8 @@ public class BDDeviceSessionImpl extends BleDeviceSession implements BleGattTxIn private final Context context; private final Handler handler; + private final List brandsNotImplementingAndroid13Api = Arrays.asList("OnePlus", "Oppo", "Realme"); + BDDeviceSessionImpl(Context context, BluetoothDevice bluetoothDevice, BDScanCallback scanCallback, @@ -299,7 +301,8 @@ private boolean sendNextAttributeOperation(AttributeOperation operation) throws //Note, some manufacturers, e.g. OnePlus haven't properly implemented the new API. //Ignore with third party devices. final boolean isThirdPartyDevice = getPolarDeviceType().isEmpty(); - if (getBuildVersion() >= Build.VERSION_CODES.TIRAMISU && (!getBrand().equals("OnePlus") || isThirdPartyDevice)) { + if (getBuildVersion() >= Build.VERSION_CODES.TIRAMISU + && (isBrandImplementingAndroid13Api(getBrand()) || isThirdPartyDevice)) { int status = gatt.writeDescriptor(descriptor, value); if (status == BluetoothStatusCodes.SUCCESS) { return true; @@ -323,6 +326,10 @@ private boolean sendNextAttributeOperation(AttributeOperation operation) throws } } + private boolean isBrandImplementingAndroid13Api(final String brandName) { + return brandsNotImplementingAndroid13Api.stream().noneMatch(name -> name.equalsIgnoreCase(brandName)); + } + @Override public void gattClientRequestStopScanning() { BleLogger.d(TAG, "GATT client request stop scanning"); diff --git a/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/PolarBleApi.kt b/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/PolarBleApi.kt index 3c29ecb3..5fc365ce 100644 --- a/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/PolarBleApi.kt +++ b/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/PolarBleApi.kt @@ -253,4 +253,13 @@ abstract class PolarBleApi(val features: Set) : PolarOnlineS * @return [Completable] emitting success or error */ abstract fun enableLedAnimation(identifier: String, enable: Boolean): Completable + + /** + * Perform factory reset to given device. + * + * @param identifier Polar device ID or BT address + * @param preservePairingInformation preserve pairing information during factory reset + * @return [Completable] emitting success or error + */ + abstract fun doFactoryReset(identifier: String, preservePairingInformation: Boolean): Completable } \ No newline at end of file diff --git a/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/PolarBleApiDefaultImpl.kt b/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/PolarBleApiDefaultImpl.kt index 270107e9..4a021135 100644 --- a/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/PolarBleApiDefaultImpl.kt +++ b/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/PolarBleApiDefaultImpl.kt @@ -25,6 +25,6 @@ object PolarBleApiDefaultImpl { */ @JvmStatic fun versionInfo(): String { - return "5.3.0" + return "5.4.0" } } \ No newline at end of file diff --git a/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/impl/BDBleApiImpl.kt b/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/impl/BDBleApiImpl.kt index 347b1854..131b8db5 100644 --- a/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/impl/BDBleApiImpl.kt +++ b/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/impl/BDBleApiImpl.kt @@ -919,6 +919,20 @@ class BDBleApiImpl private constructor(context: Context, features: Set startStreaming(identifier: String, type: PmdMeasurementType, setting: PolarSensorSetting, observer: Function>): Flowable { return try { val session = sessionPmdClientReady(identifier) diff --git a/sources/Android/android-communications/library/src/sdk/proto/pftp_notification.proto b/sources/Android/android-communications/library/src/sdk/proto/pftp_notification.proto index 503df423..bcaf6446 100644 --- a/sources/Android/android-communications/library/src/sdk/proto/pftp_notification.proto +++ b/sources/Android/android-communications/library/src/sdk/proto/pftp_notification.proto @@ -5,6 +5,13 @@ package protocol; enum PbPFtpHostToDevNotification { START_SYNC = 0; STOP_SYNC = 1; + RESET = 2; INITIALIZE_SESSION = 8; TERMINATE_SESSION = 9; } + +message PbPFtpFactoryResetParams { + required bool sleep = 1; + optional bool do_factory_defaults = 2 [default = true]; + optional bool ota_fwupdate = 3 [default = false]; +} diff --git a/sources/iOS/ios-communications/Sources/PolarBleSdk/sdk/api/PolarBleApi.swift b/sources/iOS/ios-communications/Sources/PolarBleSdk/sdk/api/PolarBleApi.swift index 1677bc19..aec4f2da 100644 --- a/sources/iOS/ios-communications/Sources/PolarBleSdk/sdk/api/PolarBleApi.swift +++ b/sources/iOS/ios-communications/Sources/PolarBleSdk/sdk/api/PolarBleApi.swift @@ -270,6 +270,16 @@ public protocol PolarBleApi: PolarOfflineRecordingApi, PolarOnlineStreamingApi, /// - success: when enable or disable sent to device /// - onError: see `PolarErrors` for possible errors invoked func enableLedAnimation(_ identifier: String, enable: Bool) -> Completable + + /// Perform factory reset to given device. + /// + /// - Parameters: + /// - identifier: polar device id or UUID + /// - preservePairingInformation: preserve pairing information during factory reset + /// - Returns: Completable stream + /// - success: when factory reset notification sent to device + /// - onError: see `PolarErrors` for possible errors invoked + func doFactoryReset(_ identifier: String, preservePairingInformation: Bool) -> Completable /// Common GAP (Generic access profile) observer var observer: PolarBleApiObserver? { get set } diff --git a/sources/iOS/ios-communications/Sources/PolarBleSdk/sdk/api/PolarBleApiDefaultImpl.swift b/sources/iOS/ios-communications/Sources/PolarBleSdk/sdk/api/PolarBleApiDefaultImpl.swift index 6481bf0c..7b5f3cd9 100644 --- a/sources/iOS/ios-communications/Sources/PolarBleSdk/sdk/api/PolarBleApiDefaultImpl.swift +++ b/sources/iOS/ios-communications/Sources/PolarBleSdk/sdk/api/PolarBleApiDefaultImpl.swift @@ -18,6 +18,6 @@ public class PolarBleApiDefaultImpl { /// /// - Returns: version in format major.minor.patch public static func versionInfo() -> String { - return "5.3.0" + return "5.4.0" } } diff --git a/sources/iOS/ios-communications/Sources/PolarBleSdk/sdk/impl/PolarBleApiImpl.swift b/sources/iOS/ios-communications/Sources/PolarBleSdk/sdk/impl/PolarBleApiImpl.swift index e409cfa5..1d7514e9 100644 --- a/sources/iOS/ios-communications/Sources/PolarBleSdk/sdk/impl/PolarBleApiImpl.swift +++ b/sources/iOS/ios-communications/Sources/PolarBleSdk/sdk/impl/PolarBleApiImpl.swift @@ -1634,6 +1634,24 @@ extension PolarBleApiImpl: PolarBleApi { } } + func doFactoryReset(_ identifier: String, preservePairingInformation: Bool) -> Completable { + do { + let session = try sessionFtpClientReady(identifier) + + guard let client = session.fetchGattClient(BlePsFtpClient.PSFTP_SERVICE) as? BlePsFtpClient else { + return Completable.error(PolarErrors.serviceNotFound) + } + + var builder = Protocol_PbPFtpFactoryResetParams() + builder.sleep = false + builder.otaFwupdate = preservePairingInformation + BleLogger.trace("Send do factory reset to device: \(identifier)") + return try client.sendNotification(Protocol_PbPFtpHostToDevNotification.reset.rawValue, parameters: builder.serializedData() as NSData) + } catch let err { + return Completable.error(err) + } + } + private func querySettings(_ identifier: String, type: PmdMeasurementType, recordingType: PmdRecordingType) -> Single { do { let session = try sessionPmdClientReady(identifier)