From 3e70dea0f8ed2e9b21d6736fa0a00798e30ae787 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 27 Jun 2022 16:03:11 +0800 Subject: [PATCH] start to lay in suspend/resume automation for vault it doesn't work yet -- but we need to get a push into CI for other testing now. --- Cargo.lock | 1 + apps/vault/Cargo.toml | 1 + apps/vault/src/main.rs | 20 ++++++++++++++++++++ apps/vault/src/ux/framework.rs | 8 ++++++++ 4 files changed, 30 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 0cf4d4780..7535f72df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3940,6 +3940,7 @@ dependencies = [ "sha2", "sntpc", "subtle", + "susres", "ticktimer-server", "trng", "tts-frontend", diff --git a/apps/vault/Cargo.toml b/apps/vault/Cargo.toml index a01d2a0e8..87cbd98c1 100644 --- a/apps/vault/Cargo.toml +++ b/apps/vault/Cargo.toml @@ -21,6 +21,7 @@ usbd-human-interface-device = "0.2.1" pddb = {path = "../../services/pddb" } modals = {path = "../../services/modals" } trng = {path="../../services/trng"} +susres = {path = "../../services/susres"} ime-plugin-api = {path = "../../services/ime-plugin-api"} content-plugin-api = {path = "../../services/content-plugin-api"} # all content canvas providers must provide this API diff --git a/apps/vault/src/main.rs b/apps/vault/src/main.rs index 82118d9f3..d521ffea7 100644 --- a/apps/vault/src/main.rs +++ b/apps/vault/src/main.rs @@ -2,6 +2,7 @@ #![cfg_attr(target_os = "none", no_main)] mod ux; +use susres::SuspendOrder; use ux::*; use num_traits::*; use xous_ipc::Buffer; @@ -132,6 +133,9 @@ pub(crate) enum VaultOp { /// PDDB basis change BasisChange, + /// Suspend/resume notifications + SuspendResume, + /// Nop while waiting for prerequisites to be filled Nop, @@ -263,6 +267,12 @@ fn main() -> ! { // starts a thread to keep NTP up-to-date ntp_updater(time_conn); + // register with the susres so we can enforce our USB policy + let mut susres = susres::Susres::new( + Some(SuspendOrder::Early), &xns, + VaultOp::SuspendResume as u32, conn + ).expect("couldn't create suspend/resume object"); + let modals = modals::Modals::new(&xns).unwrap(); let tt = ticktimer_server::Ticktimer::new().unwrap(); loop { @@ -270,6 +280,16 @@ fn main() -> ! { let opcode: Option = FromPrimitive::from_usize(msg.body.id()); log::debug!("{:?}", opcode); match opcode { + Some(VaultOp::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, { + vaultux.suspend(); + susres.suspend_until_resume(token).expect("couldn't execute suspend/resume"); + if allow_redraw { + // if we're in the foreground, we set the USB policy. This is a cooperative measure, + // nothing prevents other processes from being stupid about this, but see + // issue #178: https://github.com/betrusted-io/xous-core/issues/178 + vaultux.resume(); + } + }), Some(VaultOp::IncrementalLine) => { if action_active.load(Ordering::SeqCst) { log::trace!("action active, skipping incremental input"); diff --git a/apps/vault/src/ux/framework.rs b/apps/vault/src/ux/framework.rs index 590a067b4..0325bd5a2 100644 --- a/apps/vault/src/ux/framework.rs +++ b/apps/vault/src/ux/framework.rs @@ -182,6 +182,14 @@ impl VaultUx { } } + pub(crate) fn suspend(&self) { + // nothing to do in particular. PDDB should sync itself. + } + pub(crate) fn resume(&self) { + self.usb_dev.switch_to_core(usb_device_xous::UsbDeviceType::Hid).unwrap(); + self.usb_dev.restrict_debug_access(true).unwrap(); + } + pub(crate) fn update_mode(&mut self) { self.title_dirty = true; self.filtered_list.clear();