Skip to content

Commit c9db4c8

Browse files
committed
sdcard: auto-detection of insertion and delete 'remove sd card' feature
It seems that big share of the sd card support tickets are customers not clicking the upper right corner after inserting their sd card. That's why auto-detection of sd card in the device is critical. With this commit, when 'insert sd card' option is called from api, BitBox02 device will start listening its sd card port and automatically recognize if an sd card is inserted. Furthermore, we noticed that 'remove sd card' feature is not used in any of our libraries. That's why we removed it from api and Python library. Signed-off-by: asi345 <[email protected]>
1 parent e0e9742 commit c9db4c8

File tree

12 files changed

+42
-59
lines changed

12 files changed

+42
-59
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ customers cannot upgrade their bootloader, its changes are recorded separately.
1212
- Bitcoin: UX improvements for payment request confirmations
1313
- Ethereum: display the addresses on device in the same case as the user input
1414
- Allow exiting the screen asking to insert the microSD card
15+
- SD card: Remove API to prompt removal of the microSD card
16+
- SD card: add auto-detection of insertion
1517

1618
### 9.19.0
1719
- Display device name on screen before unlock

py/bitbox02/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## [Unreleased]
44

5+
# 8.0.0
6+
- SD card: Remove API to prompt removal of the microSD card from the device
7+
58
# 7.0.0
69
- get_info: add optional device initialized boolean to returned tuple
710
- eth_sign: add address_case field, which should be initialized by the client

py/bitbox02/bitbox02/bitbox02/bitbox02.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -648,16 +648,6 @@ def insert_sdcard(self) -> None:
648648
)
649649
self._msg_query(request, expected_response="success")
650650

651-
def remove_sdcard(self) -> None:
652-
# pylint: disable=no-member
653-
request = hww.Request()
654-
request.insert_remove_sdcard.CopyFrom(
655-
bitbox02_system.InsertRemoveSDCardRequest(
656-
action=bitbox02_system.InsertRemoveSDCardRequest.REMOVE_CARD
657-
)
658-
)
659-
self._msg_query(request, expected_response="success")
660-
661651
def root_fingerprint(self) -> bytes:
662652
"""
663653
Get the root fingerprint from the bitbox02

py/send_message.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ def backup_sd() -> None:
220220
return
221221
print("Backup created sucessfully")
222222
print("Please Remove SD Card")
223-
self._device.remove_sdcard()
224223

225224
def backup_mnemonic() -> None:
226225
if self._device.version < semver.VersionInfo(9, 13, 0):
@@ -284,7 +283,6 @@ def _restore_backup_workflow(self) -> None:
284283
eprint("Restoring backup failed")
285284
return
286285
print("Please Remove SD Card")
287-
self._device.remove_sdcard()
288286

289287
def _restore_from_mnemonic(self) -> None:
290288
try:
@@ -317,9 +315,6 @@ def _insert_sdcard(self) -> None:
317315
except UserAbortException:
318316
print("Aborted by user")
319317

320-
def _remove_sdcard(self) -> None:
321-
self._device.remove_sdcard()
322-
323318
def _get_root_fingerprint(self) -> None:
324319
print(f"Root fingerprint: {self._device.root_fingerprint().hex()}")
325320

@@ -1390,7 +1385,6 @@ def _menu_init(self) -> None:
13901385
("Reboot into bootloader", self._reboot),
13911386
("Check if SD card inserted", self._check_sd_presence),
13921387
("Insert SD card", self._insert_sdcard),
1393-
("Remove SD card", self._remove_sdcard),
13941388
("Toggle BIP39 Mnemonic Passphrase", self._toggle_mnemonic_passphrase),
13951389
("Retrieve Ethereum xpub", self._get_eth_xpub),
13961390
("Retrieve Ethereum address", self._display_eth_address),

src/rust/bitbox02-rust/src/hww/api/sdcard.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@ pub async fn process(
2424
&pb::InsertRemoveSdCardRequest { action }: &pb::InsertRemoveSdCardRequest,
2525
) -> Result<Response, Error> {
2626
let inserted = bitbox02::sd::sdcard_inserted();
27-
let action = match SdCardAction::try_from(action) {
28-
Ok(action) => action,
29-
Err(_) => return Ok(Response::Success(pb::Success {})),
27+
match SdCardAction::try_from(action) {
28+
Ok(SdCardAction::InsertCard) => {},
29+
_ => return Ok(Response::Success(pb::Success {})),
3030
};
31-
// No action required, already inserted (INSERT request) or not inserted (REMOVE request)
32-
if (action == SdCardAction::InsertCard && inserted)
33-
|| (action == SdCardAction::RemoveCard && !inserted)
31+
if inserted
3432
{
3533
return Ok(Response::Success(pb::Success {}));
3634
}
37-
sdcard::sdcard(action == SdCardAction::InsertCard).await?;
35+
sdcard::sdcard().await?;
3836
Ok(Response::Success(pb::Success {}))
3937
}
4038

@@ -75,7 +73,6 @@ mod tests {
7573
// insert
7674
mock(Data {
7775
sdcard_inserted: Some(false),
78-
ui_sdcard_create_arg: Some(true),
7976
..Default::default()
8077
});
8178
assert_eq!(
@@ -88,7 +85,6 @@ mod tests {
8885
// remove
8986
mock(Data {
9087
sdcard_inserted: Some(true),
91-
ui_sdcard_create_arg: Some(false),
9288
..Default::default()
9389
});
9490
assert_eq!(

src/rust/bitbox02-rust/src/workflow/sdcard.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ use core::cell::RefCell;
1717

1818
pub struct UserAbort;
1919

20-
pub async fn sdcard(insert: bool) -> Result<(), UserAbort> {
20+
pub async fn sdcard() -> Result<(), UserAbort> {
2121
let result = RefCell::new(None as Option<Result<(), UserAbort>>);
22-
let mut component = bitbox02::ui::sdcard_create(insert, |sd_done| {
22+
let mut component = bitbox02::ui::sdcard_create(|sd_done| {
2323
*result.borrow_mut() = if sd_done {
2424
Some(Ok(()))
2525
} else {

src/rust/bitbox02/src/testing.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use crate::keystore;
2525
pub struct Data {
2626
pub ui_confirm_create: Option<Box<dyn Fn(&super::ui::ConfirmParams) -> bool>>,
2727
pub sdcard_inserted: Option<bool>,
28-
pub ui_sdcard_create_arg: Option<bool>,
2928
pub ui_transaction_address_create: Option<Box<dyn Fn(&str, &str) -> bool>>,
3029
pub ui_transaction_fee_create: Option<Box<dyn Fn(&str, &str, bool) -> bool>>,
3130
pub ui_trinary_input_string_create:
@@ -40,7 +39,6 @@ unsafe impl Sync for SafeData {}
4039
pub static DATA: SafeData = SafeData(RefCell::new(Data {
4140
ui_confirm_create: None,
4241
sdcard_inserted: None,
43-
ui_sdcard_create_arg: None,
4442
ui_transaction_address_create: None,
4543
ui_transaction_fee_create: None,
4644
ui_trinary_input_string_create: None,

src/rust/bitbox02/src/ui/ui.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ where
197197
}
198198
}
199199

200-
pub fn sdcard_create<'a, F>(insert: bool, callback: F) -> Component<'a>
200+
pub fn sdcard_create<'a, F>(callback: F) -> Component<'a>
201201
where
202202
// Callback must outlive component.
203203
F: FnMut(bool) + 'a,
@@ -214,7 +214,6 @@ where
214214

215215
let component = unsafe {
216216
bitbox02_sys::sdcard_create(
217-
insert,
218217
Some(c_callback::<F>),
219218
// passed to the C callback as `param`
220219
Box::into_raw(Box::new(callback)) as *mut _,

src/rust/bitbox02/src/ui/ui_stub.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,10 @@ where
9393
}
9494
}
9595

96-
pub fn sdcard_create<'a, F>(insert: bool, mut callback: F) -> Component<'a>
96+
pub fn sdcard_create<'a, F>(mut callback: F) -> Component<'a>
9797
where
9898
F: FnMut(bool) + 'a,
9999
{
100-
let data = crate::testing::DATA.0.borrow();
101-
assert_eq!(data.ui_sdcard_create_arg.unwrap(), insert);
102100
callback(true);
103101
Component {
104102
is_pushed: false,

src/rust/bitbox02/src/ui/ui_stub_c_unit_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ where
100100
}
101101
}
102102

103-
pub fn sdcard_create<'a, F>(_insert: bool, mut callback: F) -> Component<'a>
103+
pub fn sdcard_create<'a, F>(mut callback: F) -> Component<'a>
104104
where
105105
F: FnMut(bool) + 'a,
106106
{

0 commit comments

Comments
 (0)