Skip to content

Commit 80a1bd3

Browse files
committed
resolve issue betrusted-io#267
1 parent 4dc7135 commit 80a1bd3

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

services/gam/src/api.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ pub(crate) enum Opcode {
201201
Bip39toBytes = 30,
202202
BytestoBip39 = 31,
203203
Bip39Suggestions = 32,
204+
205+
/// Allow main menu activation. Used by the PDDB to turn ungate the main menu once it is mounted.
206+
/// This resolves race conditions that depend upon the PDDB configurations.
207+
AllowMainMenu = 33,
204208
}
205209

206210
// small wart -- we have to reset the size of a modal to max size for resize computations

services/gam/src/contexts.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ pub(crate) struct ContextManager {
100100
/// for internal generation of deface states
101101
pub trng: trng::Trng,
102102
tt: ticktimer_server::Ticktimer,
103+
/// used to suppress the main menu from activating until the boot PIN has been requested
104+
allow_mainmenu: bool,
103105
}
104106
impl ContextManager {
105107
pub fn new(xns: &xous_names::XousNames) -> Self {
@@ -122,6 +124,7 @@ impl ContextManager {
122124
main_menu_app_token: None,
123125
trng: trng::Trng::new(&xns).expect("couldn't connect to trng"),
124126
tt: ticktimer_server::Ticktimer::new().unwrap(),
127+
allow_mainmenu: false,
125128
}
126129
}
127130
pub(crate) fn claim_token(&mut self, name: &str) -> Option<[u32; 4]> {
@@ -582,6 +585,9 @@ impl ContextManager {
582585
}
583586
Err(xous::Error::ServerNotFound)
584587
}
588+
pub(crate) fn allow_mainmenu(&mut self) {
589+
self.allow_mainmenu = true;
590+
}
585591
pub(crate) fn key_event(&mut self, keys: [char; 4],
586592
gfx: &graphics_server::Gfx,
587593
canvases: &mut HashMap<Gid, Canvas>,
@@ -591,13 +597,19 @@ impl ContextManager {
591597
if keys[0] == '∴' {
592598
if let Some(context) = self.get_context_by_token(self.focused_context.unwrap()) {
593599
if context.layout.behavior() == LayoutBehavior::App {
594-
if let Some(menu_token) = self.find_app_token_by_name(MAIN_MENU_NAME) {
595-
// set the menu to the active context
596-
match self.activate(gfx, canvases, menu_token, false) {
597-
Ok(_) => (),
598-
Err(_) => log::warn!("Couldn't raise menu, user will have to try again."),
600+
log::info!("allow_mainmenu: {:?}", self.allow_mainmenu);
601+
if self.allow_mainmenu {
602+
if let Some(menu_token) = self.find_app_token_by_name(MAIN_MENU_NAME) {
603+
// set the menu to the active context
604+
match self.activate(gfx, canvases, menu_token, false) {
605+
Ok(_) => (),
606+
Err(_) => log::warn!("Couldn't raise menu, user will have to try again."),
607+
}
608+
// don't pass the initial key hit back to the menu app, just eat it and return
609+
return;
599610
}
600-
// don't pass the initial key hit back to the menu app, just eat it and return
611+
} else {
612+
// eat the key and return if it is hit before the boot PIN was entered
601613
return;
602614
}
603615
}

services/gam/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ impl Gam {
102102
).map(|_|())
103103
}
104104

105+
/// Inform the GAM that the main menu can be activated. This blocks until the message has been delivered to the GAM.
106+
pub fn allow_mainmenu(&self) -> Result<(), xous::Error> {
107+
send_message(self.conn,
108+
Message::new_blocking_scalar(Opcode::AllowMainMenu.to_usize().unwrap(), 0, 0, 0, 0)
109+
).map(|_|())
110+
}
111+
105112
pub fn powerdown_request(&self) -> Result<bool, xous::Error> {
106113
let response = send_message(self.conn,
107114
Message::new_blocking_scalar(Opcode::PowerDownRequest.to_usize().unwrap(), 0, 0, 0, 0))?;

services/gam/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,10 @@ fn wrapped_main() -> ! {
664664
}
665665
buffer.replace(spec).unwrap();
666666
}
667+
Some(Opcode::AllowMainMenu) => {
668+
context_mgr.allow_mainmenu();
669+
xous::return_scalar(msg.sender, 0).ok();
670+
}
667671
Some(Opcode::Quit) => break,
668672
None => {log::error!("unhandled message {:?}", msg);}
669673
}

services/pddb/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,10 @@ fn wrapped_main() -> ! {
701701
failcount.min(u32::MAX as u64) as usize
702702
).expect("couldn't return scalar"),
703703
}
704+
// get a handle to the GAM and inform it that main menu should be allowed. The handle is dropped when this routine finishes.
705+
let gam = gam::Gam::new(&xns).unwrap();
706+
gam.allow_mainmenu().expect("coudln't allow main menu activation");
707+
// setup the heap
704708
initial_heap = heap_usage();
705709
latest_heap = initial_heap;
706710
latest_cache = basis_cache.cache_size();

0 commit comments

Comments
 (0)