Skip to content

Commit

Permalink
SDK release 5.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuli Määttä committed Sep 28, 2023
1 parent fdb5bd0 commit d1e692a
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class BDDeviceSessionImpl extends BleDeviceSession implements BleGattTxIn
private final Context context;
private final Handler handler;

private final List<String> brandsNotImplementingAndroid13Api = Arrays.asList("OnePlus", "Oppo", "Realme");

BDDeviceSessionImpl(Context context,
BluetoothDevice bluetoothDevice,
BDScanCallback scanCallback,
Expand Down Expand Up @@ -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;
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,13 @@ abstract class PolarBleApi(val features: Set<PolarBleSdkFeature>) : 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ object PolarBleApiDefaultImpl {
*/
@JvmStatic
fun versionInfo(): String {
return "5.3.0"
return "5.4.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,20 @@ class BDBleApiImpl private constructor(context: Context, features: Set<PolarBleS
}
}

override fun doFactoryReset(identifier: String, preservePairingInformation: Boolean): Completable {
val session = try {
sessionPsFtpClientReady(identifier)
} catch (error: Throwable) {
return Completable.error(error)
}
val client = session.fetchClient(BlePsFtpUtils.RFC77_PFTP_SERVICE) as BlePsFtpClient? ?: return Completable.error(PolarServiceNotAvailable())
val params = PftpNotification.PbPFtpFactoryResetParams.newBuilder()
params.sleep = false
params.otaFwupdate = preservePairingInformation
BleLogger.d(TAG, "send factory reset notification to device $identifier")
return client.sendNotification(PftpNotification.PbPFtpHostToDevNotification.RESET.ordinal, params.build().toByteArray())
}

private fun <T : Any> startStreaming(identifier: String, type: PmdMeasurementType, setting: PolarSensorSetting, observer: Function<BlePMDClient, Flowable<T>>): Flowable<T> {
return try {
val session = sessionPmdClientReady(identifier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<PolarSensorSetting> {
do {
let session = try sessionPmdClientReady(identifier)
Expand Down

0 comments on commit d1e692a

Please sign in to comment.