From 80a1bd36545628d00120e8e3415fe05fbf6b02c6 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 3 Nov 2022 23:18:13 +0800 Subject: [PATCH] resolve issue #267 --- services/gam/src/api.rs | 4 ++++ services/gam/src/contexts.rs | 24 ++++++++++++++++++------ services/gam/src/lib.rs | 7 +++++++ services/gam/src/main.rs | 4 ++++ services/pddb/src/main.rs | 4 ++++ 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/services/gam/src/api.rs b/services/gam/src/api.rs index 3b86e8265..52cdf0230 100644 --- a/services/gam/src/api.rs +++ b/services/gam/src/api.rs @@ -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 diff --git a/services/gam/src/contexts.rs b/services/gam/src/contexts.rs index 6b13d8e00..c45bc1241 100644 --- a/services/gam/src/contexts.rs +++ b/services/gam/src/contexts.rs @@ -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 { @@ -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]> { @@ -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, @@ -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; } } diff --git a/services/gam/src/lib.rs b/services/gam/src/lib.rs index c53417d7b..afac5afce 100644 --- a/services/gam/src/lib.rs +++ b/services/gam/src/lib.rs @@ -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 { let response = send_message(self.conn, Message::new_blocking_scalar(Opcode::PowerDownRequest.to_usize().unwrap(), 0, 0, 0, 0))?; diff --git a/services/gam/src/main.rs b/services/gam/src/main.rs index 6b252bb0c..7de3e1b59 100644 --- a/services/gam/src/main.rs +++ b/services/gam/src/main.rs @@ -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);} } diff --git a/services/pddb/src/main.rs b/services/pddb/src/main.rs index 414dffba8..f74bc4810 100644 --- a/services/pddb/src/main.rs +++ b/services/pddb/src/main.rs @@ -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();