Skip to content

Commit

Permalink
resolve issue #267
Browse files Browse the repository at this point in the history
  • Loading branch information
bunnie committed Nov 3, 2022
1 parent 4dc7135 commit 80a1bd3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
4 changes: 4 additions & 0 deletions services/gam/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ pub(crate) enum Opcode {
Bip39toBytes = 30,
BytestoBip39 = 31,
Bip39Suggestions = 32,

/// Allow main menu activation. Used by the PDDB to turn ungate the main menu once it is mounted.
/// This resolves race conditions that depend upon the PDDB configurations.
AllowMainMenu = 33,
}

// small wart -- we have to reset the size of a modal to max size for resize computations
Expand Down
24 changes: 18 additions & 6 deletions services/gam/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ pub(crate) struct ContextManager {
/// for internal generation of deface states
pub trng: trng::Trng,
tt: ticktimer_server::Ticktimer,
/// used to suppress the main menu from activating until the boot PIN has been requested
allow_mainmenu: bool,
}
impl ContextManager {
pub fn new(xns: &xous_names::XousNames) -> Self {
Expand All @@ -122,6 +124,7 @@ impl ContextManager {
main_menu_app_token: None,
trng: trng::Trng::new(&xns).expect("couldn't connect to trng"),
tt: ticktimer_server::Ticktimer::new().unwrap(),
allow_mainmenu: false,
}
}
pub(crate) fn claim_token(&mut self, name: &str) -> Option<[u32; 4]> {
Expand Down Expand Up @@ -582,6 +585,9 @@ impl ContextManager {
}
Err(xous::Error::ServerNotFound)
}
pub(crate) fn allow_mainmenu(&mut self) {
self.allow_mainmenu = true;
}
pub(crate) fn key_event(&mut self, keys: [char; 4],
gfx: &graphics_server::Gfx,
canvases: &mut HashMap<Gid, Canvas>,
Expand All @@ -591,13 +597,19 @@ impl ContextManager {
if keys[0] == '∴' {
if let Some(context) = self.get_context_by_token(self.focused_context.unwrap()) {
if context.layout.behavior() == LayoutBehavior::App {
if let Some(menu_token) = self.find_app_token_by_name(MAIN_MENU_NAME) {
// set the menu to the active context
match self.activate(gfx, canvases, menu_token, false) {
Ok(_) => (),
Err(_) => log::warn!("Couldn't raise menu, user will have to try again."),
log::info!("allow_mainmenu: {:?}", self.allow_mainmenu);
if self.allow_mainmenu {
if let Some(menu_token) = self.find_app_token_by_name(MAIN_MENU_NAME) {
// set the menu to the active context
match self.activate(gfx, canvases, menu_token, false) {
Ok(_) => (),
Err(_) => log::warn!("Couldn't raise menu, user will have to try again."),
}
// don't pass the initial key hit back to the menu app, just eat it and return
return;
}
// don't pass the initial key hit back to the menu app, just eat it and return
} else {
// eat the key and return if it is hit before the boot PIN was entered
return;
}
}
Expand Down
7 changes: 7 additions & 0 deletions services/gam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ impl Gam {
).map(|_|())
}

/// Inform the GAM that the main menu can be activated. This blocks until the message has been delivered to the GAM.
pub fn allow_mainmenu(&self) -> Result<(), xous::Error> {
send_message(self.conn,
Message::new_blocking_scalar(Opcode::AllowMainMenu.to_usize().unwrap(), 0, 0, 0, 0)
).map(|_|())
}

pub fn powerdown_request(&self) -> Result<bool, xous::Error> {
let response = send_message(self.conn,
Message::new_blocking_scalar(Opcode::PowerDownRequest.to_usize().unwrap(), 0, 0, 0, 0))?;
Expand Down
4 changes: 4 additions & 0 deletions services/gam/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,10 @@ fn wrapped_main() -> ! {
}
buffer.replace(spec).unwrap();
}
Some(Opcode::AllowMainMenu) => {
context_mgr.allow_mainmenu();
xous::return_scalar(msg.sender, 0).ok();
}
Some(Opcode::Quit) => break,
None => {log::error!("unhandled message {:?}", msg);}
}
Expand Down
4 changes: 4 additions & 0 deletions services/pddb/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,10 @@ fn wrapped_main() -> ! {
failcount.min(u32::MAX as u64) as usize
).expect("couldn't return scalar"),
}
// get a handle to the GAM and inform it that main menu should be allowed. The handle is dropped when this routine finishes.
let gam = gam::Gam::new(&xns).unwrap();
gam.allow_mainmenu().expect("coudln't allow main menu activation");
// setup the heap
initial_heap = heap_usage();
latest_heap = initial_heap;
latest_cache = basis_cache.cache_size();
Expand Down

0 comments on commit 80a1bd3

Please sign in to comment.