Skip to content
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
7 changes: 7 additions & 0 deletions src/rust/bitbox02-rust/src/hww.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ fn api_attestation(usb_in: &[u8]) -> Vec<u8> {
}

async fn _process_packet(hal: &mut impl crate::hal::Hal, usb_in: Vec<u8>) -> Vec<u8> {
// Update the waiting screen from "See the BitBoxApp" to the logo, now that the host is
// connected. When the device is initialized, we delay this until the unlock call, otherwise
// there would be a flicker where the logo would be shown before the host invokes unlock.
if !bitbox02::memory::is_initialized() || usb_in.as_slice() == [OP_UNLOCK] {
bitbox02::ui::screen_process_waiting_switch_to_logo();
}

match usb_in.split_first() {
Some((&OP_UNLOCK, b"")) => return api_unlock(hal).await,
Some((&OP_ATTESTATION, rest)) => return api_attestation(rest),
Expand Down
2 changes: 0 additions & 2 deletions src/rust/bitbox02-rust/src/hww/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ pub(crate) async fn process(
) -> Result<(), Error> {
match usb_in.split_first() {
Some((&OP_I_CAN_HAS_HANDSHAEK, b"")) => {
// The previous screen was "See the BitBoxApp".
// Since a handshake was requested, a client was connected, so we pop that screen.
// Pairing is the start of a session, so we clean the screen stack in case
// we started a new session in the middle of something.
bitbox02::ui::screen_stack_pop_all();
Expand Down
1 change: 1 addition & 0 deletions src/rust/bitbox02-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const ALLOWLIST_FNS: &[&str] = &[
"reset_ble",
"screen_print_debug",
"screen_process",
"screen_process_waiting_switch_to_logo",
"screen_saver_disable",
"screen_saver_enable",
"sd_card_inserted",
Expand Down
4 changes: 4 additions & 0 deletions src/rust/bitbox02/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ mod types;
mod ui;

pub use ui::*;

pub fn screen_process_waiting_switch_to_logo() {
unsafe { bitbox02_sys::screen_process_waiting_switch_to_logo() }
}
47 changes: 38 additions & 9 deletions src/ui/components/waiting.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "waiting.h"
#include "lockscreen.h"

#include "image.h"
#include "ui_images.h"
Expand All @@ -21,13 +22,12 @@
#include <screen.h>
#include <ui/ui_util.h>

#include <stdbool.h>
#include <string.h>

static void _render(component_t* component)
{
// TODO - add an interesting animation?
ui_util_component_render_subcomponents(component);
}
typedef struct {
bool show_logo;
} data_t;

/********************************** Component Functions **********************************/

Expand All @@ -36,7 +36,7 @@ static void _render(component_t* component)
*/
static component_functions_t _component_functions = {
.cleanup = ui_util_component_cleanup,
.render = _render,
.render = ui_util_component_render_subcomponents,
.on_event = NULL,
};

Expand All @@ -47,6 +47,12 @@ static component_functions_t _component_functions = {
*/
component_t* waiting_create(void)
{
data_t* data = malloc(sizeof(data_t));
if (!data) {
Abort("Error: malloc waiting data");
}
memset(data, 0, sizeof(data_t));

component_t* waiting = malloc(sizeof(component_t));
if (!waiting) {
Abort("Error: malloc waiting");
Expand All @@ -57,14 +63,37 @@ component_t* waiting_create(void)
waiting->dimension.height = SCREEN_HEIGHT;
waiting->position.top = 0;
waiting->position.left = 0;
waiting->data = data;

ui_util_add_sub_component(waiting, lockscreen_create());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the lockscreen isn't a screen anymore, but a subcomponent, should we rename it to something like locked_device_background instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a need, in the end it's doing the same as before 🤷


return waiting;
}

void waiting_switch_to_logo(component_t* component)
{
data_t* data = (data_t*)component->data;
if (data->show_logo) {
return;
}
data->show_logo = true;

if (component->sub_components.amount != 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be an ASSERT. The subcomponent is clearly added in the constructor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with ASSERT is that they don't run in prod, and if the assumption is wrong for some reason, there will be a memory bug. I could do Abort(...) instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, Abort is fine as well if you want it to be checked in prod

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// Sanity check to avoid memory bugs, should never happen.
Abort("waiting_switch_to_logo");
return;
}

ui_util_component_cleanup(component->sub_components.sub_components[0]);

image_logo_data_t logo = image_logo_data();
component_t* bb2_logo = image_create(
logo.buffer.data,
logo.buffer.len,
logo.dimensions.width,
logo.dimensions.height,
CENTER,
waiting);
ui_util_add_sub_component(waiting, bb2_logo);
return waiting;
component);

component->sub_components.sub_components[0] = bb2_logo;
}
8 changes: 7 additions & 1 deletion src/ui/components/waiting.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@
#include <ui/component.h>

/**
* Creates a waiting screen.
* Creates a waiting screen. It starts out with a lockscreen (see lockscreen.c). Once
* `waiting_switch_to_logo()` is called, the waiting screen will switch to showing the logo image.
*/
component_t* waiting_create(void);

/**
* Switch the waiting screen to show the BitBox logo instead.
*/
void waiting_switch_to_logo(component_t* component);

#endif
15 changes: 10 additions & 5 deletions src/ui/screen_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,21 @@ void ui_screen_render_component(component_t* component)
UG_SendBuffer();
}

static component_t* _waiting_screen = NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This static could be inside _get_waiting_screen.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, as it is needed by screen_process_host_connected() (now renamed to screen_process_waiting_switch_to_logo().

static component_t* _get_waiting_screen(void)
{
static component_t* waiting_screen = NULL;
if (waiting_screen == NULL) {
waiting_screen = waiting_create();
if (waiting_screen == NULL) {
if (_waiting_screen == NULL) {
_waiting_screen = waiting_create();
if (_waiting_screen == NULL) {
Abort("Could not create\nwaiting screen");
}
}
return waiting_screen;
return _waiting_screen;
}

void screen_process_waiting_switch_to_logo(void)
{
waiting_switch_to_logo(_get_waiting_screen());
}

component_t* screen_process_get_top_component(void)
Expand Down
5 changes: 5 additions & 0 deletions src/ui/screen_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ void ui_screen_render_component(component_t* component);
*/
component_t* screen_process_get_top_component(void);

/**
* Wraps `waiting_switch_to_logo()` for the waiting screen.
*/
void screen_process_waiting_switch_to_logo(void);

/**
* Runs the UI once.
*
Expand Down
1 change: 0 additions & 1 deletion src/workflow/orientation_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ static void _idle_timer_cb(const struct timer_task* const timer_task)
}

usb_start();
ui_screen_stack_push(lockscreen_create());
}
#endif

Expand Down