Skip to content

Commit

Permalink
api/bootloader: do not wait 5s after upgrade
Browse files Browse the repository at this point in the history
If a delay is desired, it should not be in this library, but done by
the library client (wallet app).

Before this commit, the device screen was stuck at 100% for 5s while
this library waited to continue, which was confusing.
  • Loading branch information
benma committed Mar 21, 2024
1 parent e8463f4 commit 550b80d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 43 deletions.
9 changes: 0 additions & 9 deletions api/bootloader/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/binary"
"io"
"math"
"time"

"github.com/digitalbitbox/bitbox02-api-go/api/common"
"github.com/digitalbitbox/bitbox02-api-go/util/errp"
Expand Down Expand Up @@ -62,7 +61,6 @@ type Status struct {
Progress float64 `json:"progress"`
UpgradeSuccessful bool `json:"upgradeSuccessful"`
ErrMsg string `json:"errMsg"`
RebootSeconds int `json:"rebootSeconds"`
}

func toByte(b bool) byte {
Expand All @@ -78,7 +76,6 @@ type Device struct {
product common.Product
status *Status
onStatusChanged func(*Status)
sleep func(time.Duration)
}

// NewDevice creates a new instance of Device.
Expand All @@ -93,7 +90,6 @@ func NewDevice(
product: product,
status: &Status{},
onStatusChanged: onStatusChanged,
sleep: time.Sleep,
}
}

Expand Down Expand Up @@ -301,11 +297,6 @@ func (device *Device) UpgradeFirmware(firmware []byte) error {
device.status.Progress = 0
device.status.UpgradeSuccessful = true
device.onStatusChanged(device.status)
for seconds := 5; seconds > 0; seconds-- {
device.status.RebootSeconds = seconds
device.onStatusChanged(device.status)
device.sleep(time.Second)
}
return device.Reboot()
}

Expand Down
21 changes: 0 additions & 21 deletions api/bootloader/device_export_test.go

This file was deleted.

14 changes: 1 addition & 13 deletions api/bootloader/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"io/ioutil"
"testing"
"time"

"github.com/digitalbitbox/bitbox02-api-go/api/bootloader"
"github.com/digitalbitbox/bitbox02-api-go/api/common"
Expand Down Expand Up @@ -259,16 +258,6 @@ func TestUpgradeFirmware(t *testing.T) {
return nil
}

const rebootSeconds = 5
sleepCalls := 0
env.device.TstSetSleep(func(d time.Duration) {
require.Equal(t, time.Second, d)
require.Less(t, sleepCalls, rebootSeconds)
require.True(t, currentStatus.UpgradeSuccessful)
require.Equal(t, rebootSeconds-sleepCalls, currentStatus.RebootSeconds)
sleepCalls++
})

require.Zero(t, *env.device.Status())
require.NoError(t, env.device.UpgradeFirmware(signedFirmware))

Expand Down Expand Up @@ -319,9 +308,8 @@ func TestUpgradeFirmware(t *testing.T) {
require.True(t, status.UpgradeSuccessful)

// reboot
msg, status = takeOne()
msg, _ = takeOne()
require.Equal(t, byte('r'), msg[0])
require.Equal(t, 1, status.RebootSeconds)
})
}

Expand Down

0 comments on commit 550b80d

Please sign in to comment.