Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use blockingGet to save backup files #517 #518

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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