Skip to content

Commit

Permalink
Do not use blockingGet to save backup files polarofficial#517
Browse files Browse the repository at this point in the history
  • Loading branch information
korzonkiee committed Dec 9, 2024
1 parent 734c1f1 commit 290a93a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,10 @@ class BDBleApiImpl private constructor(context: Context, features: Set<PolarBleS
backupManager.backupDevice()
.toFlowable()
.flatMap {
backup.addAll(it)

BleLogger.d(TAG, "Device backup completed: $it, starting firmware update to version ${firmwareUpdateResponse.version}")

firmwareUpdateApi.getFirmwareUpdatePackage(firmwareUpdateResponse.fileUrl)
.toFlowable()
.flatMap { firmwareBytes ->
Expand Down Expand Up @@ -2048,10 +2052,6 @@ class BDBleApiImpl private constructor(context: Context, features: Set<PolarBleS
Flowable.error(error)
}
}
.doOnSubscribe {
BleLogger.d(TAG, "Preparing for firmware update started, fetching backup content...")
backup.addAll(backupManager.backupDevice().blockingGet())
}
.doFinally {
val disposable = setLocalTime(identifier, Calendar.getInstance())
.andThen(Completable.fromAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ class PolarBackupManager(private val client: BlePsFtpClient) {
* @return Single emitting the list of backed up file data.
*/
fun backupDevice(): Single<List<BackupFileData>> {
BleLogger.d(TAG, "Backing up device")

return Single.fromCallable {
BleLogger.d(TAG, "Requesting backup content")

val builder = PftpRequest.PbPFtpOperation.newBuilder()
builder.command = PftpRequest.PbPFtpOperation.Command.GET
builder.path = ARABICA_SYS_FOLDER
Expand Down Expand Up @@ -111,6 +115,8 @@ class PolarBackupManager(private val client: BlePsFtpClient) {
}.onErrorReturn {
BleLogger.e(TAG, "Failed to get backup content, error: $it")
emptyList()
}.doOnSuccess { backupFiles ->
BleLogger.d(TAG, "Backup completed, files backed up: ${backupFiles.size}")
}
}

Expand Down

0 comments on commit 290a93a

Please sign in to comment.