feat(settings): settings app: apps list + per-capability allow/revoke, about (who/role), sign out; system-only caps permissions/session (install refused); pm MANAGE_BADGE copy (list/apps/allow/revoke only), APPS op; init WHO + session pass-on; factory decisions seeded for new system apps; k-ui list_item/toggle, screens/back/scroll
This commit is contained in:
@@ -100,6 +100,15 @@ impl Apps {
|
||||
Ok(len)
|
||||
}
|
||||
|
||||
/// Every installed app, for a program to read (see `entries`), into
|
||||
/// `out`; how much.
|
||||
pub fn apps(&self, out: &mut [u8]) -> Result<usize> {
|
||||
let (len, _) = self.with_page(wire::APPS, 0)?;
|
||||
let len = len.min(out.len()).min(PAGE_SIZE);
|
||||
self.page.copy_to(ByteOffset::ZERO, &mut out[..len]);
|
||||
Ok(len)
|
||||
}
|
||||
|
||||
/// Takes the capability with catalog index `capability` away from app
|
||||
/// `id` (stopping it if it runs with it).
|
||||
pub fn revoke(&self, id: &str, capability: usize) -> Result<()> {
|
||||
@@ -114,3 +123,37 @@ impl Apps {
|
||||
self.with_page(wire::ALLOW, capability).map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
/// One installed app, as `Apps::apps` lists it.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct AppEntry<'a> {
|
||||
pub id: &'a str,
|
||||
pub name: &'a str,
|
||||
/// Capability bits (`manifest::Capabilities`).
|
||||
pub required: u32,
|
||||
pub optional: u32,
|
||||
pub granted: u32,
|
||||
}
|
||||
|
||||
/// The apps in a listing; a line that does not parse is skipped.
|
||||
pub fn entries(text: &str) -> impl Iterator<Item = AppEntry<'_>> {
|
||||
text.lines().filter_map(|line| {
|
||||
let mut f = line.split('\t');
|
||||
let (id, name) = (f.next()?, f.next()?);
|
||||
let mut bits = || f.next()?.parse().ok();
|
||||
Some(AppEntry { id, name, required: bits()?, optional: bits()?, granted: bits()? })
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_listing_parses_and_bad_lines_are_skipped() {
|
||||
let text = "kos.snake\tSnake\t1\t0\t1\nnonsense\nkos.notes\tNotes\t0\t3\t2\n";
|
||||
let all: alloc::vec::Vec<_> = entries(text).collect();
|
||||
assert_eq!(all.len(), 2);
|
||||
assert_eq!(all[1], AppEntry { id: "kos.notes", name: "Notes", required: 0, optional: 3, granted: 2 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user