Skip to content

Commit

Permalink
Update method on Android so that it perform factory reset before and …
Browse files Browse the repository at this point in the history
…after writing firmware files polarofficial#524
  • Loading branch information
korzonkiee committed Dec 10, 2024
1 parent 734c1f1 commit 9089bf8
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1990,9 +1990,7 @@ class BDBleApiImpl private constructor(context: Context, features: Set<PolarBleS
}

doFactoryReset(identifier, true)
.andThen(Completable.timer(30, TimeUnit.SECONDS))
.andThen(waitDeviceSessionToOpen(identifier, factoryResetMaxWaitTimeSeconds, waitForDeviceDownSeconds = 10L))
.andThen(Completable.timer(5, TimeUnit.SECONDS))
.andThen(
Flowable.fromIterable(firmwareFiles)
.concatMap { firmwareFile ->
Expand All @@ -2013,18 +2011,22 @@ class BDBleApiImpl private constructor(context: Context, features: Set<PolarBleS
.concatMap { status ->
if (status is FirmwareUpdateStatus.FinalizingFwUpdate) {
BleLogger.d(TAG, "Starting finalization of firmware update")
Completable.timer(rebootTriggeredWaitTimeSeconds, TimeUnit.SECONDS)
.andThen(
waitDeviceSessionToOpen(identifier, factoryResetMaxWaitTimeSeconds, if (isDeviceSensor) 0L else 120L)
.andThen(
Completable.fromCallable {
BleLogger.d(TAG, "Restoring backup to device after version ${firmwareUpdateResponse.version}")
sendInitializationAndStartSyncNotifications(client)
backupManager.restoreBackup(backup).subscribe()
}
)
)
.andThen(Flowable.just(FirmwareUpdateStatus.FinalizingFwUpdate()))
BleLogger.d(TAG, "Waiting for device session to open after reboot")
waitDeviceSessionToOpen(identifier, factoryResetMaxWaitTimeSeconds, waitForDeviceDownSeconds = 10L)
.andThen(Completable.defer {
BleLogger.d(TAG, "Performing factory reset while preserving pairing information")
return@defer doFactoryReset(identifier, true)
})
.andThen(Completable.defer {
BleLogger.d(TAG, "Waiting for device session to open after factory reset")
return@defer waitDeviceSessionToOpen(identifier, factoryResetMaxWaitTimeSeconds, waitForDeviceDownSeconds = 10L)
})
.andThen(Completable.defer {
BleLogger.d(TAG, "Restoring backup to device after version ${firmwareUpdateResponse.version}")
sendInitializationAndStartSyncNotifications(client)
return@defer backupManager.restoreBackup(backup)
})
.andThen(Flowable.just(status))
} else {
Flowable.just(status)
}
Expand Down

0 comments on commit 9089bf8

Please sign in to comment.