From f10c70e7c16eec4c6790cb9c2ef0f8332a2fb11b Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 11:53:03 +0300 Subject: [PATCH 1/5] Pin the sealed envelope's wire form The sealed session envelope is what the session layer stores on disk, and its backend tag is the one spelling a TV's saved login cannot survive a change of. Nothing pinned it: the persistence fixtures carry the keymanager3 tag inside the session wrapper and only read it back, and palm_keymanager appeared in no fixture at all. The test serializes a Sealed for each tag the type can name today and compares the JSON with a literal written from today's code, then reads the literal back and compares the value. A second test pins that a member an earlier build wrote (the 0.6.3 to 0.6.5 files carry an identity member the type has no field for) is still ignored on read. Co-Authored-By: Claude --- rust-modules/os/src/tv/secure.rs | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/rust-modules/os/src/tv/secure.rs b/rust-modules/os/src/tv/secure.rs index c96153549..4cae406a5 100644 --- a/rust-modules/os/src/tv/secure.rs +++ b/rust-modules/os/src/tv/secure.rs @@ -141,6 +141,50 @@ pub fn set_mode_for_test(mode: StoreMode) -> ModeReset { mod tests { use super::*; + /// **The sealed envelope's wire form, pinned for every backend tag a TV may have written.** The + /// envelope is what `plex::session` stores on disk, so a changed spelling of a tag would leave + /// every saved session on every TV unreadable. The literals are what this type wrote when the + /// test was added; a refactor of `Backend` must keep them byte for byte, in both directions. + /// `tests/fixtures/persistence/v0.6.*/secure-envelope-v1.json` carries the `keymanager3` tag + /// inside the session file's wrapper, and nothing pinned `palm_keymanager` at all. + #[test] + fn the_sealed_envelope_keeps_its_wire_form_for_every_backend_tag() { + let sealed = |backend| Sealed { + backend, + key: "plxnative.session.v1".into(), + iv: "MDEyMzQ1Njc4OWFi".into(), + data: "Y2lwaGVydGV4dA==".into(), + }; + let cases = [ + ( + Backend::Keymanager3, + r#"{"backend":"keymanager3","key":"plxnative.session.v1","iv":"MDEyMzQ1Njc4OWFi","data":"Y2lwaGVydGV4dA=="}"#, + ), + ( + Backend::PalmKeymanager, + r#"{"backend":"palm_keymanager","key":"plxnative.session.v1","iv":"MDEyMzQ1Njc4OWFi","data":"Y2lwaGVydGV4dA=="}"#, + ), + ]; + for (backend, literal) in cases { + let value = sealed(backend); + assert_eq!(serde_json::to_string(&value).unwrap(), literal, "{value:?} serializes to its literal"); + assert_eq!(serde_json::from_str::(literal).unwrap(), value, "{literal} reads back as {value:?}"); + } + } + + /// The 0.6.3 to 0.6.5 files carry an `identity` member the envelope has no field for: it is + /// ignored on read, and a rewrite no longer carries it. Pinned beside the tags above because + /// both are the same promise: a file an earlier build wrote still opens. + #[test] + fn an_envelope_with_a_member_this_type_no_longer_has_still_reads() { + let literal = r#"{"backend":"keymanager3","key":"plxnative.session.v1","iv":"MDEyMzQ1Njc4OWFi","data":"Y2lwaGVydGV4dA==","identity":"named"}"#; + let read: Sealed = serde_json::from_str(literal).unwrap(); + assert_eq!(read.backend, Backend::Keymanager3); + assert_eq!(read.key, "plxnative.session.v1"); + assert_eq!(read.iv, "MDEyMzQ1Njc4OWFi"); + assert_eq!(read.data, "Y2lwaGVydGV4dA=="); + } + #[test] fn the_default_mode_is_durable() { let _serial = plx_base::testlock::serial(); From f25f6edaf2d61e0d32e54529019b944f82526d20 Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 12:03:35 +0300 Subject: [PATCH 2/5] The secure envelope's Backend becomes an opaque tag Backend was a closed enum naming the two webOS key managers, in the one type the stored session envelope shares with every platform. It becomes an opaque string tag, serde transparent, so the wire form is the bare string it always was and a platform can name its own store in its own code (Backend::new). The two spellings a TV has already written stay as constants, KEYMANAGER3 and PALM_KEYMANAGER; the pinned envelope literals from the previous commit pass unchanged. A tag no installed platform knows now parses instead of failing the whole envelope, so the refusal moves to open: keymanager's open answers None for it (the session layer reports the file locked, as it did for the parse failure) and its remove asks no service and leaves the backend cache alone, so a foreign tag is never handed to keymanager3 on the strength of the shared key name. Tests pin both in keymanager and one through the session file, with a control that the platform's own tag still opens. Co-Authored-By: Claude --- rust-modules/os/src/keymanager.rs | 60 +++++++++++++---- rust-modules/os/src/tv.rs | 4 +- rust-modules/os/src/tv/secure.rs | 65 +++++++++++++++++-- .../src/plex/session_persistence_tests.rs | 49 +++++++++++++- 4 files changed, 152 insertions(+), 26 deletions(-) diff --git a/rust-modules/os/src/keymanager.rs b/rust-modules/os/src/keymanager.rs index fad80c915..0bf228480 100644 --- a/rust-modules/os/src/keymanager.rs +++ b/rust-modules/os/src/keymanager.rs @@ -52,11 +52,14 @@ pub fn open(sealed: &Sealed) -> Option> { if sealed.key != KEY_NAME { return None; } - match sealed.backend { - Backend::Keymanager3 => modern_crypt(sealed.data.as_bytes(), Some(&sealed.iv)), - // Kept only so an interim/pre-release envelope deserializes as locked instead of being - // mistaken for plaintext. AES-CFB does not authenticate the file, so never open it. - Backend::PalmKeymanager => None, + if sealed.backend == Backend::KEYMANAGER3 { + modern_crypt(sealed.data.as_bytes(), Some(&sealed.iv)) + } else { + // `PALM_KEYMANAGER` is kept only so an interim/pre-release envelope deserializes as locked + // instead of being mistaken for plaintext: AES-CFB does not authenticate the file, so never + // open it. A tag this platform has no key manager for is refused the same way, and is never + // handed to keymanager3 on the strength of its key name alone. + None } .and_then(|s| b64::decode(&s.data)) } @@ -65,15 +68,20 @@ pub fn remove(backend: &Backend, key: &str) { if key != KEY_NAME { return; } - let _ = match backend { - Backend::Keymanager3 => call( + let _ = if *backend == Backend::KEYMANAGER3 { + call( "luna://com.webos.service.keymanager3/removeKey", &json!({"name": key}), - ), - Backend::PalmKeymanager => call( + ) + } else if *backend == Backend::PALM_KEYMANAGER { + call( "luna://com.palm.keymanager/remove", &json!({"keyname": key}), - ), + ) + } else { + // Not a store this platform has: no service is asked, and the backend cache below is left + // as it was (nothing was deleted). + return; }; // `clear()` deletes the key and the file in one sign-out. A later sign-in in the same process // must run key creation again rather than trusting the now-stale backend cache. @@ -166,7 +174,7 @@ fn modern_crypt(input: &[u8], iv: Option<&str>) -> Option { return None; } Some(Sealed { - backend: Backend::Keymanager3, + backend: Backend::KEYMANAGER3, key: KEY_NAME.to_string(), iv: generated_iv, data: finish.get("output")?.as_str()?.to_string(), @@ -298,14 +306,14 @@ mod tests { fn removing_the_key_invalidates_the_backend_cache() { let _guard = plx_base::testlock::serial(); SELECTED.store(MODERN, Ordering::Relaxed); - remove(&Backend::Keymanager3, super::KEY_NAME); + remove(&Backend::KEYMANAGER3, super::KEY_NAME); assert_eq!(SELECTED.load(Ordering::Relaxed), UNKNOWN); } #[test] fn unauthenticated_legacy_ciphertext_is_never_opened() { let sealed = Sealed { - backend: Backend::PalmKeymanager, + backend: Backend::PALM_KEYMANAGER, key: super::KEY_NAME.into(), iv: "legacy-iv".into(), data: b64::encode(b"attacker-controlled ciphertext"), @@ -313,6 +321,30 @@ mod tests { assert!(open(&sealed).is_none()); } + /// A tag this platform has no key manager for (another platform's, or one from the future) is + /// refused on open and ignored on remove, with the bus never asked: it must not be handed to + /// keymanager3 because its key name happens to match, and a sign-out must not delete the + /// keymanager3 key on the strength of a file some other store wrote. + #[test] + fn an_envelope_tagged_for_a_store_this_platform_lacks_is_refused_without_asking_a_service() { + let _guard = plx_base::testlock::serial(); + reset_for_test(); + RPC_FOR_TEST.with(|hook| hook.set(Some(|uri, _| panic!("a service was asked: {uri}")))); + let foreign = Backend::new("host_file"); + let sealed = Sealed { + backend: foreign.clone(), + key: super::KEY_NAME.into(), + iv: "iv".into(), + data: b64::encode(b"sealed by another platform"), + }; + assert!(open(&sealed).is_none()); + SELECTED.store(MODERN, Ordering::Relaxed); + remove(&foreign, super::KEY_NAME); + assert_eq!(SELECTED.load(Ordering::Relaxed), MODERN, "nothing was removed, so the cache is not stale"); + RPC_FOR_TEST.with(|hook| hook.set(None)); + reset_for_test(); + } + /// The protocol round trip, over a synthetic LS2 transport that returns what it was given: it /// does not claim to test cryptography or firmware availability, only that `seal` and `open` /// walk generateKey, begin and finish in order and agree on the envelope. @@ -332,7 +364,7 @@ mod tests { Ok(response.to_string()) }))); let sealed = seal(b"secret").expect("the synthetic transport seals"); - assert_eq!(sealed.backend, Backend::Keymanager3); + assert_eq!(sealed.backend, Backend::KEYMANAGER3); assert_eq!(sealed.key, super::KEY_NAME); assert_eq!(sealed.iv, "synthetic-iv"); assert_eq!(open(&sealed).as_deref(), Some(&b"secret"[..])); diff --git a/rust-modules/os/src/tv.rs b/rust-modules/os/src/tv.rs index 558ecb9aa..67eef2b9c 100644 --- a/rust-modules/os/src/tv.rs +++ b/rust-modules/os/src/tv.rs @@ -163,14 +163,14 @@ mod tests { assert!(matches!(sound_output(), sound::Reply::NoPlatform)); let sealed = secure::Sealed { - backend: secure::Backend::Keymanager3, + backend: secure::Backend::KEYMANAGER3, key: "k".into(), iv: "i".into(), data: "d".into(), }; assert!(seal(b"secret").is_none()); assert!(open(&sealed).is_none()); - remove(&secure::Backend::PalmKeymanager, "k"); + remove(&secure::Backend::PALM_KEYMANAGER, "k"); assert_eq!(mode, secure::StoreMode::Durable, "no key manager is not a memory-only platform"); go_home(); diff --git a/rust-modules/os/src/tv/secure.rs b/rust-modules/os/src/tv/secure.rs index 4cae406a5..c4712dd24 100644 --- a/rust-modules/os/src/tv/secure.rs +++ b/rust-modules/os/src/tv/secure.rs @@ -4,12 +4,40 @@ //! Beside them, [`StoreMode`] says whether this platform keeps a credential across launches at //! all. use serde::{Deserialize, Serialize}; +use std::borrow::Cow; +/// Which key store sealed an envelope: an opaque tag, written to disk exactly as spelled. +/// +/// It is not a closed set. The tag is the only thing in the stored envelope that says which +/// platform's store can open it, and a platform names its own in its own code ([`Backend::new`]); +/// no shared code branches on one. A tag that no installed platform knows is REFUSED when the +/// envelope is opened (the platform's `open` answers `None`, the session layer reports the file +/// locked) and is never read as another store's: the stored text is not ours to reinterpret. +/// +/// Serde-transparent, so the wire form is the bare string: an envelope written before this type +/// stopped being an enum reads back unchanged, and one written now reads in an older build. +/// `the_sealed_envelope_keeps_its_wire_form_for_every_backend_tag` pins both directions. #[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)] -#[serde(rename_all = "snake_case")] -pub enum Backend { - Keymanager3, - PalmKeymanager, +#[serde(transparent)] +pub struct Backend(Cow<'static, str>); + +impl Backend { + /// webOS's public `com.webos.service.keymanager3`: AES-GCM under a key the service holds. + pub const KEYMANAGER3: Backend = Backend::new("keymanager3"); + /// webOS's archival `com.palm.keymanager`. Only ever READ from a file an interim build + /// wrote: nothing seals with it and nothing opens it (its AES-CFB does not authenticate). + pub const PALM_KEYMANAGER: Backend = Backend::new("palm_keymanager"); + + /// A tag a platform names for its own store. The spelling is a wire format: it is stored in + /// every sealed session, so it never changes once a build has written it. + pub const fn new(tag: &'static str) -> Self { + Self(Cow::Borrowed(tag)) + } + + /// The tag as stored. + pub fn as_str(&self) -> &str { + &self.0 + } } #[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)] @@ -157,11 +185,11 @@ mod tests { }; let cases = [ ( - Backend::Keymanager3, + Backend::KEYMANAGER3, r#"{"backend":"keymanager3","key":"plxnative.session.v1","iv":"MDEyMzQ1Njc4OWFi","data":"Y2lwaGVydGV4dA=="}"#, ), ( - Backend::PalmKeymanager, + Backend::PALM_KEYMANAGER, r#"{"backend":"palm_keymanager","key":"plxnative.session.v1","iv":"MDEyMzQ1Njc4OWFi","data":"Y2lwaGVydGV4dA=="}"#, ), ]; @@ -179,12 +207,35 @@ mod tests { fn an_envelope_with_a_member_this_type_no_longer_has_still_reads() { let literal = r#"{"backend":"keymanager3","key":"plxnative.session.v1","iv":"MDEyMzQ1Njc4OWFi","data":"Y2lwaGVydGV4dA==","identity":"named"}"#; let read: Sealed = serde_json::from_str(literal).unwrap(); - assert_eq!(read.backend, Backend::Keymanager3); + assert_eq!(read.backend, Backend::KEYMANAGER3); assert_eq!(read.key, "plxnative.session.v1"); assert_eq!(read.iv, "MDEyMzQ1Njc4OWFi"); assert_eq!(read.data, "Y2lwaGVydGV4dA=="); } + /// A tag nobody here has a name for is carried through as written, and no constant equals it: + /// it is the platform's `open` that refuses it, never this type that reads it as another store. + #[test] + fn a_tag_no_platform_knows_is_kept_verbatim_and_equals_no_known_tag() { + let literal = r#"{"backend":"host_file","key":"plxnative.session.v1","iv":"aXY=","data":"ZGF0YQ=="}"#; + let read: Sealed = serde_json::from_str(literal).unwrap(); + assert_eq!(read.backend.as_str(), "host_file"); + assert_ne!(read.backend, Backend::KEYMANAGER3); + assert_ne!(read.backend, Backend::PALM_KEYMANAGER); + assert_eq!(serde_json::to_string(&read).unwrap(), literal, "written back as it was read"); + assert_eq!(read.backend, Backend::new("host_file")); + } + + /// With no platform installed nothing opens an envelope, whatever its tag: a refusal is the + /// absence of an answer, not a reinterpretation. + #[test] + fn no_installed_platform_opens_any_tag() { + for backend in [Backend::KEYMANAGER3, Backend::PALM_KEYMANAGER, Backend::new("host_file")] { + let sealed = Sealed { backend, key: "k".into(), iv: "i".into(), data: "d".into() }; + assert!(open(&sealed).is_none(), "{sealed:?}"); + } + } + #[test] fn the_default_mode_is_durable() { let _serial = plx_base::testlock::serial(); diff --git a/rust-modules/plex/src/plex/session_persistence_tests.rs b/rust-modules/plex/src/plex/session_persistence_tests.rs index a94c281dc..779cfbcc6 100644 --- a/rust-modules/plex/src/plex/session_persistence_tests.rs +++ b/rust-modules/plex/src/plex/session_persistence_tests.rs @@ -766,7 +766,7 @@ fn an_unopenable_secure_session_is_preserved_without_plaintext_downgrade() { format: SECURE_FORMAT.to_string(), version: 1, sealed: plx_os::tv::secure::Sealed { - backend: plx_os::tv::secure::Backend::Keymanager3, + backend: plx_os::tv::secure::Backend::KEYMANAGER3, key: "plxnative.session.v1".to_string(), iv: "AAAAAAAAAAAAAAAAAAAAAA==".to_string(), data: "c2VjcmV0".to_string(), @@ -830,6 +830,49 @@ fn an_unknown_secure_envelope_version_is_locked_and_never_rewritten_as_plaintext ); } +/// A sealed envelope for `signed_in()` under `backend`, in the file format `save` writes. +fn envelope_for_signed_in(backend: plx_os::tv::secure::Backend) -> Vec { + serde_json::to_vec_pretty(&SecureEnvelope { + format: SECURE_FORMAT.to_string(), + version: 1, + sealed: plx_os::tv::secure::Sealed { + backend, + key: "plxnative.session.v1".to_string(), + iv: "synthetic-iv".to_string(), + data: plx_base::b64::encode(&serde_json::to_vec_pretty(&signed_in()).unwrap()), + }, + }) + .unwrap() +} + +/// The control for the test below: the same plaintext, sealed under the tag the synthetic +/// platform does know, opens. +#[test] +fn an_envelope_with_the_platforms_own_backend_tag_opens() { + let _g = plx_base::testlock::serial(); + let _keymanager = SyntheticKeymanager::new(); + let t = TempSession::new("secure-own-tag"); + std::fs::write(t.file(), envelope_for_signed_in(plx_os::tv::secure::Backend::KEYMANAGER3)).unwrap(); + assert_eq!(load().account_token, "acct"); +} + +/// The backend tag is an opaque string, so an envelope naming a store no installed platform knows +/// still parses. It is REFUSED on open and never reinterpreted as the platform's own store: the +/// file stays locked ciphertext and the run signs in again. +#[test] +fn an_envelope_with_a_backend_tag_no_platform_knows_is_locked_and_left_as_it_was() { + let _g = plx_base::testlock::serial(); + let _keymanager = SyntheticKeymanager::new(); + let t = TempSession::new("secure-foreign-tag"); + let foreign = envelope_for_signed_in(plx_os::tv::secure::Backend::new("host_file")); + std::fs::write(t.file(), &foreign).unwrap(); + + let loaded = load(); + assert!(loaded.account_token.is_empty(), "a tag nobody knows opens nothing"); + assert!(!loaded.client_id.is_empty(), "the run still gets an ephemeral id"); + assert_eq!(std::fs::read(t.file()).unwrap(), foreign, "reading it rewrites nothing"); +} + #[test] fn a_precreated_tmp_symlink_cannot_redirect_session_bytes() { use std::os::unix::fs::symlink; @@ -1721,13 +1764,13 @@ fn signout_sweeps_cannot_complete_while_a_recovery_flush_is_pending() { struct SyntheticKeymanager; static STORE: plx_os::tv::secure::TestStore = plx_os::tv::secure::TestStore { seal: |plain| Some(plx_os::tv::secure::Sealed { - backend: plx_os::tv::secure::Backend::Keymanager3, + backend: plx_os::tv::secure::Backend::KEYMANAGER3, key: "plxnative.session.v1".into(), iv: "synthetic-iv".into(), data: plx_base::b64::encode(plain), }), open: |sealed| { - if sealed.backend == plx_os::tv::secure::Backend::Keymanager3 && sealed.key == "plxnative.session.v1" { + if sealed.backend == plx_os::tv::secure::Backend::KEYMANAGER3 && sealed.key == "plxnative.session.v1" { plx_base::b64::decode(&sealed.data) } else { None From 1604abcf0921d152d83fa12ed40732ea1736f9cf Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 12:11:40 +0300 Subject: [PATCH 3/5] The television's webOS-shaped types become neutral ones (W3d) tv::sandbox becomes tv::native_video. Its verdict is Available, Blocked(reason) or NotApplicable, where webOS's old Ok, Missing and NotApplicable map one to one and the reason word stays "missing", so the devjail: log line, the rtkmem telemetry context and PRIVACY.md read exactly as before. The repair is an optional hook, Services.identity.repair_native_video, and a platform that states none answers Unsupported, the answer the all-None services gave. The readers in media, appkit, screens, telemetry and the application follow the rename. The platform publishes the name and version the Plex headers report. tv::device keeps a once-set Platform, webOS's probe states the release it read (or the "4.5" literal when the set named none) and plex::identity::platform() and platform_version() answer it, falling back to "webOS" and the old release-or-"4.5" when nothing is published. The X-Plex headers are the same bytes on every path; the client no longer carries a copy of the platform name. device::Info keeps release, build and major; codename, API version and name move to a WebosDetail behind Info::webos, and the readers (the probe log line, devcaps, the Sentry and PostHog contexts, the diagnostics panel, the lab snapshot) print the same text. devcaps reads its files through the platform. The parsed model stays and keeps its paths and its log lines; the reads go through tv::device::Files, which Services.identity states and which webOS fills from the file system. devcaps::probe() and caps() keep their paths and signatures. Not on the host and so read by hand: the ARM-only Sentry block in telemetry/native.rs now reads the same three strings from info.webos. Co-Authored-By: Claude --- ci/module-layers.ini | 2 +- docs/module-layers.md | 30 +-- rust-modules/appkit/src/player_hud/state.rs | 8 +- rust-modules/media/src/player/adapter.rs | 10 +- rust-modules/media/src/player/machine.rs | 14 +- rust-modules/media/src/player/mod.rs | 12 +- rust-modules/media/src/player/route_start.rs | 2 +- rust-modules/media/src/route/decision.rs | 6 +- rust-modules/os/src/devcaps.rs | 87 ++++++++- rust-modules/os/src/tv.rs | 27 ++- rust-modules/os/src/tv/device.rs | 80 +++++++- rust-modules/os/src/tv/native_video.rs | 181 ++++++++++++++++++ rust-modules/os/src/tv/sandbox.rs | 129 ------------- rust-modules/os/src/webos.rs | 117 ++++++++--- rust-modules/os/src/webos/jail_repair.rs | 2 +- rust-modules/plex/src/plex/account.rs | 2 +- rust-modules/plex/src/plex/client.rs | 4 +- rust-modules/plex/src/plex/identity.rs | 40 +++- rust-modules/screens/src/player/mod.rs | 10 +- rust-modules/src/app/diagnostics.rs | 15 +- rust-modules/src/app/playback.rs | 2 +- rust-modules/src/lab/snapshot.rs | 6 +- rust-modules/src/port.rs | 3 +- rust-modules/telemetry/src/diag/schema.rs | 8 +- .../telemetry/src/telemetry/native.rs | 10 +- .../telemetry/src/telemetry/sentry.rs | 8 +- 26 files changed, 554 insertions(+), 261 deletions(-) create mode 100644 rust-modules/os/src/tv/native_video.rs delete mode 100644 rust-modules/os/src/tv/sandbox.rs diff --git a/ci/module-layers.ini b/ci/module-layers.ini index e0dacdde5..5bbf04599 100644 --- a/ci/module-layers.ini +++ b/ci/module-layers.ini @@ -59,7 +59,7 @@ members = machine present landgate landing job motion idle_regression_tests pres # the codec table, the artwork cache, the localization catalog, and the Cloud Lab session file # (`labcfg`: `lab.json` plus the trigger-key / menu-row answers `ui/` and `screens/` ask of it). # `webos` and `keymanager` are also in [platform webos]. `tv` holds the interfaces the webOS port fills -# at boot (step L15): device identity, the sandbox verdict, the key store, home, toast, the window +# at boot (step L15): device identity, the native-video verdict, the key store, home, toast, the window # and the video sink trait. uses = base machine members = webos storage keymanager devcaps imgcache i18n labcfg tv playback_trace diff --git a/docs/module-layers.md b/docs/module-layers.md index 4561d00c5..a02d169c2 100644 --- a/docs/module-layers.md +++ b/docs/module-layers.md @@ -330,10 +330,10 @@ proves the references are gone and nothing more; L15b is open. | **L12** media owns its lifecycle seams — **done** | 7 / 28 | The foreground-resume machine is `player::lifecycle`, its drivers `player::foreground` and the transport-pause contract `player::transport` (`app::lifecycle` re-exports them), the stats switch is `player::DIAG_READOUT_ON`, `Venc::open` takes the capture socket writer as an argument, and `route` takes the HUD context line as a parameter, with the up-next still prefetch a hook the app installs. | | **L13** tests move up to the layer that owns their parts — **done** | 41 / 96 | Part a moved the auth, plex, i18n, task and fontcov tests that named upper layers to `app/` (`session_*_tests.rs`), `screens/login_text_fit_tests.rs`, `plex`, `auth::owner` and `storage::client`, and moved `fontcov`'s `Measure` impl beside the trait, with `ui::machine`'s new `BareArg`/`BareMeasure` fixtures for the rest; part b moved the data, media and ui ones to `app/` (`dispatch_return_tests.rs`, `overscan_audit_tests.rs`) and `screens/` (`plaintext_question`, `library/labels_tests.rs`, `search/tests.rs`, `player`), and rewrote two against their own layer. | | **L14** session-layer presentation to screens — **done** | 2 / 4 | `auth::signed_in_reason` is a private fn of `screens::login`, its only caller, with its two tests; `auth` already handed over the plain account name. | -| **L15** the webOS port — **gate-complete** | 44 / 205 | Everything outside `[platform webos]` reaches the television through the `tv` interfaces in `os` that the port fills at boot: `tv::{device, sandbox, secure, home, toast}` (the window, the bus pump and the frame probe are `app::platform`'s `Shell` and `FrameProbe` since W2), `devcaps::dv`, and `tv::sink::VideoSink`, a Starfish-shaped verb trait that `plx_os::webos::video_sink::StarfishSink` and `plx_play_feed::ffi_host::HostSink` implement. `plex_run` is `port::plex_run`. The allowlist is empty. Not "done": the sink is not OS-neutral and the simulator is not its own port (L15b). | +| **L15** the webOS port — **gate-complete** | 44 / 205 | Everything outside `[platform webos]` reaches the television through the `tv` interfaces in `os` that the port fills at boot: `tv::{device, native_video, secure, home, toast}` (the window, the bus pump and the frame probe are `app::platform`'s `Shell` and `FrameProbe` since W2), `devcaps::dv`, and `tv::sink::VideoSink`, a Starfish-shaped verb trait that `plx_os::webos::video_sink::StarfishSink` and `plx_play_feed::ffi_host::HostSink` implement. `plex_run` is `port::plex_run`. The allowlist is empty. Not "done": the sink is not OS-neutral and the simulator is not its own port (L15b). | | **L15b** the OS-neutral port — **open** | — | An OS-neutral video sink with the ACB bind sequence behind it, the simulator as its own port, and the webOS facts the gate cannot see. See below. | | **L15c** the platform value and the three contracts — **planned** | — | Wave R (the rename that gave this page `os` and `[platform webos]`) landed as #1474; W2 has landed (`tv::Port` became `tv::Services`, with four groups of hooks; the shell and the frame probes moved to `app::Platform`), and what is planned is W3a to W3c: who may persist credentials, what evidence admits a URI player, who ends the process. See "L15c to L15h" below. | -| **L15d** neutral types and the simulator as its own platform (L15b item 2) — **planned** | — | W3d (the opaque `Backend` tag, `sandbox` to `native_video`, identity publishes a platform name and version, `device::Info` loses its webOS fields) and W4 (a second fence section, `[platform desktop]`, with its own value; the simulator's host arms leave `system` and `port`, the other `hostsim` terms of the fence go, and the simulator's stand-ins in `webos` and `keymanager` stay, compiled for tests and `test-support`: `docs/platform-ports.md`, W4). The desktop platform is the second implementation. | +| **L15d** neutral types and the simulator as its own platform (L15b item 2) — **W3d landed, W4 planned** | — | W3d has landed (the opaque `Backend` tag, `sandbox` to `native_video`, identity publishes a platform name and version, `device::Info` keeps its webOS fields in `WebosDetail`, and `devcaps` reads its files through the platform), and what is planned is W4 (a second fence section, `[platform desktop]`, with its own value; the simulator's host arms leave `system` and `port`, the other `hostsim` terms of the fence go, and the simulator's stand-ins in `webos` and `keymanager` stay, compiled for tests and `test-support`: `docs/platform-ports.md`, W4). The desktop platform is the second implementation. | | **L15e** events, the shell and composition — **planned** | — | W5 (`HostEvent` with `Option`), W6b (platform-supplied composition in two boot phases), W6 (`plx_shell_sdl`, a `[shell_sdl]` layer) and W6c (a URI-only and a two-driver composition play an ordinary title). | | **L15f** extract the platform crates — **planned** | — | W7: a narrow public `host` module in the application crate, `rust-modules/platform-webos` and `platform-desktop` as crates above `app`, and the gate learning "a platform is a crate above `app`". After L15d, before L15g and L15h. | | **L15g** the webOS facts and the remaining `hostsim` (L15b item 3) — **planned** | — | W8: the `target_arch = "arm"` and `target_os = "linux"` sites sorted into "is webOS" (a platform value or runner) and "is 32-bit ARM" or "is Linux" (stays), then the library name lists, `paths`, the packaging and the 363 `feature = "hostsim"` lines outside the fence (360 cfg lines and three doc comments). | @@ -363,16 +363,16 @@ Only `tv`'s own modules read the table. Two things leave it: the sink, through `play-uri` driver receives that transport and a shared `DisplaySink` as injected ports; it does not read the webOS port registry or the feed-only `VideoSink` itself. Lazily computed facts (device identity, the sandbox verdict, the Dolby Vision capability) are -published values rather than hooks: the webOS code writes them into `tv::device`, `tv::sandbox` and +published values rather than hooks: the webOS code writes them into `tv::device`, `tv::native_video` and `devcaps::dv` at the same boot moment as before, so readers keep their `OnceLock` semantics. | interface | where it went | named from | |---|---|---| -| device identity | `tv::device::{info, device, Info, Hardware}`, published by `webos::probe` | `telemetry`, `diag::schema`, `plex::identity`, `plex::session`'s tests, `screens::login`, `lab::snapshot`, `app`, `player` | +| device identity | `tv::device::{info, device, platform, files, Info, WebosDetail, Hardware, Platform, Files}`, published by `webos::probe` (`Info` is the release, build and major every platform states; `WebosDetail` is the codename, API version and name only a webOS firmware file has; `Platform` is the name and version the Plex headers report, which `plex::identity` defaults to `webOS` until one is published; `Files` is the reader `devcaps::probe` parses through, a field of `Services.identity`) | `telemetry`, `diag::schema`, `plex::identity`, `plex::session`'s tests, `screens::login`, `lab::snapshot`, `app`, `player` | | playback capability | `devcaps::dv::{capability, probe, DvCapability}`, published by `webos::caps`; `tv::start_capability_probe` starts the probe | `metadata`, `route`, `player::engine`, `app` | -| native-video availability and repair | `tv::sandbox::{blocks_native_video, context, repair, Verdict, State, Failure, FORCE_BLOCKED}`; the verdict is published by `webos::probe` and the repair is a port hook | `player`, `route`, `appkit::player_hud`, `screens::player`, `app::playback` | +| native-video availability and repair | `tv::native_video::{blocked, context, repair, Verdict, State, Failure, FORCE_BLOCKED}`, `Verdict` being `Available`, `Blocked(reason)` or `NotApplicable`; the verdict is published by `webos::probe` and the repair is an optional port hook (`Services.identity.repair_native_video`) | `player`, `route`, `appkit::player_hud`, `screens::player`, `app::playback` | | video sink | `tv::sink::VideoSink`, implemented by `plx_os::webos::video_sink::StarfishSink` and `HostSink` (`plx_play_feed::ffi_host`), installed in `Services.legacy_webos_media.sink` and read through `tv::sink::installed` | `player::{adapter, test_physical}`, `plx_play_feed::{native_executor, native_load, physical, seek}` (which receive it injected), `app::adapters::backends` (which resolves `installed` and `display_installed`) | -| secure store | `tv::secure::{seal, open, remove, Sealed, Backend}` | `plex::session` | +| secure store | `tv::secure::{seal, open, remove, Sealed, Backend}`; `Backend` is an opaque tag (a string on the wire, with constants for the two webOS spellings) | `plex::session` | | storage backend | `storage::client::install_activator`, which the port calls with `webos::activate_storage_helper` | `port::plex_run` | | locale | `tv::system_locale` and `tv::LocaleReply`; `i18n` still owns the parse and the log lines | `i18n` | | sound output | `tv::sound::{output, parse_output, Reply}`, filled by `Services.identity.sound_output` (`webos::sound_output`); a blocking read, so never on the frame thread, and asked only on a stack whose lead follows the output (`liblxa` and 2018's `audiosink_new`; `devcaps::audio_stack`; the `lgaudiosink` stack's lead does not depend on the output, and the others have none, so they never ask) | `player::threads` (through `player::engine`, which owns the lead table) | @@ -441,18 +441,22 @@ still webOS's. Three things are left: simulator runs today (`launch_home`, `system_locale`, `sound_output`, `bind_window`, the keymanager client, `deliver`, `call_hbc` among them), and they stay compiled for tests and `test-support` with only their `hostsim` term gone (`docs/platform-ports.md`, W4). The - webOS-shaped types in `tv` also need neutral shapes then: `tv::secure::Backend` names the two - webOS key managers and is part of the on-disk envelope, and `tv::sandbox`'s verdict and repair - describe webOS's own device jail. + webOS-shaped types in `tv` needed neutral shapes then, and have them since W3d: `tv::secure::Backend` + is an opaque tag that stays a string on the wire (the two webOS spellings are constants, and a tag no + installed platform knows is refused on open), `tv::sandbox` is `tv::native_video` with a verdict that is + `Available`, `Blocked(reason)` or `NotApplicable` and an optional repair hook, and `tv::device::Info` + keeps the release, build and major while the codename, API version and name sit in a `WebosDetail`. 3. **The webOS facts the gate cannot see.** The gate sees names, not literals, and not modules that stay where they are. The port takes these too: - `devcaps` reads webOS's own table, `/etc/umediaserver/device_codec_capability_config.json`. - The parsed model stays and the reader moves. + The parsed model stays and the reader moved in W3d: `devcaps::probe` reads its files through + `tv::device::files()`, the `Files` that `Services.identity` states. - The libraries the app loads at run time are the television's: `libcurl` (`net`, `curlio`) and `libEGLfk` (`egl`). The bundled FFmpeg in `ff` is loaded by absolute path and is not one of them. - - `plex::identity`'s platform constant and client headers. + - `plex::identity`'s platform constant and client headers (W3d: the platform publishes its name and + version to `tv::device`, and `PLATFORM` is the default until it does). - The Magic Remote's key codes and pointer in `app::{input, boot, events}`. - `paths`'s fallback install prefix. - Outside `rust-modules/src`: `src/starfish.c`, `src/main.c`'s boot shim, the storage helper @@ -497,7 +501,7 @@ layer below it. Since L14 the first half holds for every layer and the second fo listed 134 such items after L14 (8 in `base`, 11 `machine`, 13 `os`, 8 `gfx`, 10 `net`, 21 `plex`, 8 `telemetry`, 12 `ui`, 25 `data`, 4 `session`, 6 `media`, 4 `appkit`, 4 `screens`). L15 replaced `webos::FORCE_JAIL_BLOCKED`, `webos::home_requests` and `keymanager::RPC_FOR_TEST` with -`cfg(test)` seams of `tv` (`sandbox::FORCE_BLOCKED`, `home::home_requests`, +`cfg(test)` seams of `tv` (`native_video::FORCE_BLOCKED`, `home::home_requests`, `secure::{STORE_FOR_TEST, TestStore}`) that other layers' tests still name, so `--report` listed 136 (15 in `os`, the rest as above) before Split 3 took the 15 with it; run it for the current count. The @@ -729,7 +733,7 @@ suite is 5603 tests before and after (157 + 66 + 218 + 5162). What it taught bey times alone before trusting them. - **No orphan-rule hazard, and nothing was dead because of a trait.** `os` defines traits (`tv::sink::VideoSink`) and the application implements them for its own types, which is legal; the - compiler is the checker, as in Split 2. `tv::sandbox::Failure::Timeout` had a + compiler is the checker, as in Split 2. `tv::native_video::Failure::Timeout` (then `tv::sandbox`) had a `cfg_attr(..., expect(dead_code))` that became an unfulfilled expectation once the enum was `pub`; it is gone. - **FFI moved byte for byte.** `webos.rs`'s `extern "C"` blocks and `storage_service/{auxv,bus}.rs` diff --git a/rust-modules/appkit/src/player_hud/state.rs b/rust-modules/appkit/src/player_hud/state.rs index 9acb821e2..d9da6e84d 100644 --- a/rust-modules/appkit/src/player_hud/state.rs +++ b/rust-modules/appkit/src/player_hud/state.rs @@ -587,9 +587,9 @@ fn failure_glyph(kind: plx_media::player::FailureKind) -> plx_ui::icons::Icon { impl FailureReadout { /// Pure projection of the app's complete failure snapshot, including the repair status. pub fn captured(mut e: plx_media::player::ErrorShape, actions: Vec, - support: String, repair_status: plx_os::tv::sandbox::State) -> Self { + support: String, repair_status: plx_os::tv::native_video::State) -> Self { if e.kind == plx_media::player::FailureKind::JailMissingRtkmem { - use plx_os::tv::sandbox::State; + use plx_os::tv::native_video::State; match repair_status { State::Idle => {} State::Running => { @@ -726,8 +726,8 @@ pub fn failure_row_drawn(busy: Busy) -> bool { } /// Product copy is resolved here; the worker's technical error identity stays unchanged. -fn repair_failure_message(reason: plx_os::tv::sandbox::Failure) -> &'static str { - use plx_os::tv::sandbox::Failure; +fn repair_failure_message(reason: plx_os::tv::native_video::Failure) -> &'static str { + use plx_os::tv::native_video::Failure; match reason { Failure::StartFailed => plx_os::i18n::msg::widgets_repair_start_failed(), Failure::HbcUnavailable => plx_os::i18n::msg::widgets_repair_hbc_unavailable(), diff --git a/rust-modules/media/src/player/adapter.rs b/rust-modules/media/src/player/adapter.rs index 6388c782a..0dcfcf7f1 100644 --- a/rust-modules/media/src/player/adapter.rs +++ b/rust-modules/media/src/player/adapter.rs @@ -507,7 +507,7 @@ pub struct PlayerAdapter { abr_inbox: Option<(crate::route::RouteStartAttempt, crate::adaptive::AbrInbox)>, /// Backend-independent periodic reporting resource for the current physical attempt. timeline: Option, - repair: Option<(u64, std::sync::mpsc::Receiver>)>, + repair: Option<(u64, std::sync::mpsc::Receiver>)>, release: super::release::NativeRelease, /// Effects produced by an addressed URI release while the backend poll has no session /// borrow. The release machine owns the sole queued transaction; these are only its IO work. @@ -1759,11 +1759,11 @@ impl PlayerAdapter { let Some(token) = owner.begin(supported) else { return; }; let (tx, rx) = std::sync::mpsc::channel(); if plx_base::task::spawn_small("jail repair", move || { - let _ = tx.send(plx_os::tv::sandbox::repair()); + let _ = tx.send(plx_os::tv::native_video::repair()); }) { self.repair = Some((token, rx)); } else { - owner.complete(token, Err(plx_os::tv::sandbox::Failure::StartFailed)); + owner.complete(token, Err(plx_os::tv::native_video::Failure::StartFailed)); } } @@ -1773,7 +1773,7 @@ impl PlayerAdapter { let result = match rx.try_recv() { Ok(result) => result, Err(std::sync::mpsc::TryRecvError::Empty) => return false, - Err(std::sync::mpsc::TryRecvError::Disconnected) => Err(plx_os::tv::sandbox::Failure::StartFailed), + Err(std::sync::mpsc::TryRecvError::Disconnected) => Err(plx_os::tv::native_video::Failure::StartFailed), }; let changed = owner.complete(*token, result); self.repair = None; @@ -2254,7 +2254,7 @@ impl PlayerAdapter { #[cfg(test)] mod repair_receipt_tests { use super::*; - use plx_os::tv::sandbox::{Failure, State}; + use plx_os::tv::native_video::{Failure, State}; #[test] fn local_metric_history_evicts_old_effects_after_real_reducer_results() { use super::super::attempt_metrics::{Origin, RequestOutcome, Tick, Fx}; diff --git a/rust-modules/media/src/player/machine.rs b/rust-modules/media/src/player/machine.rs index dc9ed736a..b1aec7038 100644 --- a/rust-modules/media/src/player/machine.rs +++ b/rust-modules/media/src/player/machine.rs @@ -130,21 +130,21 @@ impl Default for Player { /// Logical repair authority; resource handles live in PlayerAdapter. No reset-on-playback API. pub struct RepairAttempt { - state: plx_os::tv::sandbox::State, + state: plx_os::tv::native_video::State, } impl RepairAttempt { - pub const fn new() -> Self { Self { state: plx_os::tv::sandbox::State::Idle } } - pub fn state(&self) -> plx_os::tv::sandbox::State { self.state } + pub const fn new() -> Self { Self { state: plx_os::tv::native_video::State::Idle } } + pub fn state(&self) -> plx_os::tv::native_video::State { self.state } pub fn begin(&mut self, supported: bool) -> Option { - use plx_os::tv::sandbox::{State, Failure}; + use plx_os::tv::native_video::{State, Failure}; if self.state != State::Idle { return None; } if !supported { self.state = State::Failed(Failure::Unsupported); return None; } self.state = State::Running; Some(1) } /// The single issued token can land only once. Wrong/duplicate completions cannot rewrite it. - pub fn complete(&mut self, token: u64, result: Result<(), plx_os::tv::sandbox::Failure>) -> bool { - use plx_os::tv::sandbox::State; + pub fn complete(&mut self, token: u64, result: Result<(), plx_os::tv::native_video::Failure>) -> bool { + use plx_os::tv::native_video::State; if token != 1 || self.state != State::Running { return false; } self.state = match result { Ok(()) => State::Repaired, Err(e) => State::Failed(e) }; true @@ -154,7 +154,7 @@ impl RepairAttempt { #[cfg(test)] mod repair_tests { use super::*; - use plx_os::tv::sandbox::Failure; + use plx_os::tv::native_video::Failure; // `repair_survives_screen_and_session_recreation_and_rejects_stale_completions` builds a // `PlayerScreen`, which `player` may not name: it lives in `screens::player`'s // `repair_confirmation_tests`, beside the screen it recreates. diff --git a/rust-modules/media/src/player/mod.rs b/rust-modules/media/src/player/mod.rs index 06dcdf7bc..a4335fd36 100644 --- a/rust-modules/media/src/player/mod.rs +++ b/rust-modules/media/src/player/mod.rs @@ -998,7 +998,7 @@ pub enum FailureKind { TvPipeline, /// This device's jail is missing `/dev/rtkmem` on a SoC where that is a known cause of /// native A/V crashes — the Load was never attempted. Community-tier finding: see - /// [`plx_os::tv::sandbox::blocks_native_video`]'s doc. + /// [`plx_os::tv::native_video::blocked`]'s doc. JailMissingRtkmem, /// Issue #74 D.1.4's `NATIVE_LOAD_BUDGET` fired — either the native `Load` call never /// returned, or it returned but `loadCompleted` never arrived. Distinct from @@ -1157,7 +1157,7 @@ pub fn failure_context_captured(ps: &crate::route::PlaybackSession, diagnostic_f FailureContext { forced: crate::route::forced_direct_play(ps) || diagnostic_forced, can_retry: crate::route::can_retry_current_play(ps), - repair_idle: ps.repair_status == plx_os::tv::sandbox::State::Idle, + repair_idle: ps.repair_status == plx_os::tv::native_video::State::Idle, } } @@ -1227,9 +1227,9 @@ fn live_runtime_failure(ps: &crate::route::PlaybackSession) -> RuntimeFailure { /// [`error_shape`], because it precedes route resolution entirely: it names a device finding, not /// a decision the server or the runtime made. Phrased as a FINDING throughout — "found... known /// to..." — never as a certain diagnosis, matching the community-tier evidence it is built on -/// (see [`plx_os::tv::sandbox::blocks_native_video`]'s doc). Caption and readout are kept short for +/// (see [`plx_os::tv::native_video::blocked`]'s doc). Caption and readout are kept short for /// legibility from a phone photograph, same bar as every other arm here; the remedy's detail goes -/// in `detail`. `Player.repair` (see `tv::sandbox`) can actually attempt the Homebrew +/// in `detail`. `Player.repair` (see `tv::native_video`) can actually attempt the Homebrew /// Channel service call that patches the jail profile, so the remedy text points at that confirmed /// in-app repair rather than at a bare reinstall. fn jail_error_shape() -> ErrorShape { @@ -4754,7 +4754,7 @@ mod native_failure_regressions { use super::*; struct JailGuard; impl Drop for JailGuard { - fn drop(&mut self) { plx_os::tv::sandbox::FORCE_BLOCKED.store(false, Relaxed); } + fn drop(&mut self) { plx_os::tv::native_video::FORCE_BLOCKED.store(false, Relaxed); } } #[test] fn jail_refusal_enters_error_without_engine_and_retires_on_exit() { @@ -4764,7 +4764,7 @@ mod native_failure_regressions { crate::route::reset_player_control_for_test(&ps); crate::player::reset_session_for_test(); let mut pa = adapter::PlayerAdapter::new_fed(unsafe { plx_base::task::MainThread::assume() }); - plx_os::tv::sandbox::FORCE_BLOCKED.store(true, Relaxed); + plx_os::tv::native_video::FORCE_BLOCKED.store(true, Relaxed); assert!(start_bufferfeed(&mut ps, &mut pa)); assert!(!pa.is_live()); assert_eq!(state(&ps), PlaybackState::Error); diff --git a/rust-modules/media/src/player/route_start.rs b/rust-modules/media/src/player/route_start.rs index e59eaa4e9..88ddfa276 100644 --- a/rust-modules/media/src/player/route_start.rs +++ b/rust-modules/media/src/player/route_start.rs @@ -56,7 +56,7 @@ pub fn start_bufferfeed_tracked(ps: &mut crate::route::PlaybackSession, pa: &mut let uri_chosen = matches!(ps.backend_offer(), crate::route::backend_policy::Selection::Open(offer) if offer.backend == plx_playback_contract::BackendKind::Uri); - if !uri_chosen && plx_os::tv::sandbox::blocks_native_video() { + if !uri_chosen && plx_os::tv::native_video::blocked() { ps.jail_load_blocked = true; log("start_bufferfeed: refusing native video; affected chassis cannot read /dev/rtkmem"); if let Some(ticket) = crate::route::begin_route_start() { diff --git a/rust-modules/media/src/route/decision.rs b/rust-modules/media/src/route/decision.rs index b6dd22a25..d150d6b92 100644 --- a/rust-modules/media/src/route/decision.rs +++ b/rust-modules/media/src/route/decision.rs @@ -196,7 +196,7 @@ pub struct PlaybackSession { /// and a scrobble on top would be a second view. Read and cleared by [`scrobble_stop`]. pub finished: bool, /// Read-only publication of Player.repair for the HUD. Never authorizes a resource effect. - pub repair_status: plx_os::tv::sandbox::State, + pub repair_status: plx_os::tv::native_video::State, /// The request which produced this attempt, retained for terminal Retry / Choose quality. /// Written synchronously by [`request_play`] rather than by [`apply_plan`], because the /// server can refuse before a playable plan exists. @@ -1690,7 +1690,7 @@ impl PlaybackSession { native_start_refused: None, engine_failure: None, finished: false, - repair_status: plx_os::tv::sandbox::State::Idle, + repair_status: plx_os::tv::native_video::State::Idle, request: None, requested_resume_ns: 0, url: String::new(), @@ -11540,7 +11540,7 @@ fn apply_plan(ps: &mut PlaybackSession, meta: &mut plx_data::stores::metadata::M native_start_refused: None, engine_failure: None, finished: false, - repair_status: plx_os::tv::sandbox::State::Idle, + repair_status: plx_os::tv::native_video::State::Idle, request, requested_resume_ns, url: plan.url, diff --git a/rust-modules/os/src/devcaps.rs b/rust-modules/os/src/devcaps.rs index dee51183d..f2c1934c6 100644 --- a/rust-modules/os/src/devcaps.rs +++ b/rust-modules/os/src/devcaps.rs @@ -39,6 +39,7 @@ //! before this module. Misreading the table must degrade to yesterday's behavior, not invent a //! weaker television: the issue-#22 lesson cuts both ways, and a client that suddenly transcodes //! everything on a healthy 4K panel is as wrong as one that direct-plays HEVC to a SoC without it. +use crate::tv::device::Files; use std::borrow::Cow; use std::sync::OnceLock; @@ -334,7 +335,7 @@ pub enum Limit { /// takes only an IDR first ([`Limit::DvFirstPictureIdr`]), which the player answers by withdrawing the /// declaration at a landing the splitter would skip. /// -/// The key is the firmware codename (`tv::device::Info::codename`, nyx's `webos_release_codename`), +/// The key is the firmware codename (`tv::device::WebosDetail::codename`, nyx's `webos_release_codename`), /// the one identity the app reads reliably on every set: it groups the sets that run the same /// build of the media stack, which is what decides the decoder's behaviour, where the retail model /// name (`product_id`, absent on some firmware) and the SoC class would split one stack or merge two. @@ -1525,11 +1526,12 @@ impl Drop for AudioStackGuard { } } -/// Read the table once and log what was derived. Called at boot right after `webos::probe`, -/// before anything can fail; safe when the file does not exist (older/odd firmware → assumed). -pub fn probe() { +/// The device table and `gstcool.conf` through `files`, parsed and logged: the caps this set +/// announces before the firmware exclusions, and whether they were READ ([`MEASURED`]) or are the +/// assumed fallback. Every failure to read or parse lands on [`Caps::assumed`], with its line. +fn read_caps(files: &Files) -> (Caps, bool) { let mut measured = false; - let caps = match std::fs::read_to_string(CAPS_TABLE) { + let caps = match (files.read)(CAPS_TABLE) { Ok(s) => match parse(&s) { Some(c) => { measured = true; @@ -1547,7 +1549,7 @@ pub fn probe() { plx_base::eventlog::log(&format!("devcaps: table audio rows: {}", table_audio_rows(&s))); c.vp9_bit_depth = vp9_bit_depth_for(crate::tv::device::info().major); // Before the exclusions: a codec the conf lists as switched off is not a candidate to limit. - let (gst_dropped, gst_unlisted) = match std::fs::read_to_string(GST_CONF) { + let (gst_dropped, gst_unlisted) = match (files.read)(GST_CONF) { Ok(conf) => apply_gst_decoders(&mut c, &conf), Err(_) => (Vec::new(), Vec::new()), }; @@ -1586,6 +1588,15 @@ pub fn probe() { Caps::assumed() } }; + (caps, measured) +} + +/// Read the table once and log what was derived. Called at boot right after `webos::probe`, +/// before anything can fail; safe when the file does not exist (older/odd firmware → assumed). +/// The files are read the platform's way (`tv::device::files`); this model only parses them. +pub fn probe() { + let files = crate::tv::device::files(); + let (caps, measured) = read_caps(&files); let _ = MEASURED.set(measured); let info = crate::tv::device::info(); let (wide, learn, forget) = ( @@ -1600,10 +1611,10 @@ pub fn probe() { // the AUDIO exclusions (a row's `dv_first_picture` stays, it is not an audio fact) and the learned // layer (`nativeaudiolearn` beside it keeps the layer), // `nativeaudioforget` the record. - let stack = audio_stack_from(|path| std::path::Path::new(path).exists()); + let stack = audio_stack_from(|path| (files.exists)(path)); let _ = AUDIO_STACK.set(stack); let mut boot = caps.clone(); - let excluded = apply_exclusions(&mut boot, &info.codename, wide, EXCLUSIONS); + let excluded = apply_exclusions(&mut boot, &info.webos.codename, wide, EXCLUSIONS); if plx_base::devtrig::flag("appdecodelossy") { boot = boot.with_app_lossy(); #[cfg(feature = "devtriggers")] @@ -1636,7 +1647,7 @@ pub fn probe() { )); plx_base::eventlog::log(&format!( "devcaps: firmware={:?} build={:?} audio stack={} audio layers: table+gst={} | exclusions: {} | -> audio={}{}{}", - info.codename, + info.webos.codename, info.build, stack.label(), caps.audio, @@ -1649,7 +1660,7 @@ pub fn probe() { }, if forget { " (nativeaudioforget: stored refusals ignored this run)" } else { "" }, )); - let _ = BOOT.set(Boot::new(boot, info.codename.clone(), info.build.clone(), (wide, learn, forget))); + let _ = BOOT.set(Boot::new(boot, info.webos.codename.clone(), info.build.clone(), (wide, learn, forget))); } /// Whether [`caps`] reflects THIS set's table or the assumed profile — see [`MEASURED`]. @@ -3184,4 +3195,60 @@ mod tests { let capped = Caps { video_ceiling: [("av1".to_owned(), (1280, 720))].into(), ..caps }; assert_eq!(capped.raster_bound("av1"), (1280, 720)); } + + /// A platform serving the real device table and a `gstcool.conf` with DTS switched off. + const SERVES_TABLE_AND_CONF: Files = Files { + read: |path| match path { + CAPS_TABLE => Ok(REAL.to_owned()), + GST_CONF => Ok(GST_C1.replace("dts_audiodec=290", "dts_audiodec=0")), + _ => Err(std::io::ErrorKind::NotFound.into()), + }, + exists: |path| path == LXAUDIOSINK_PLUGIN, + }; + + /// A platform serving the table and no `gstcool.conf` (the conf is optional: a set without it keeps + /// every codec the table lists). + const SERVES_TABLE_ONLY: Files = Files { + read: |path| match path { + CAPS_TABLE => Ok(REAL.to_owned()), + _ => Err(std::io::ErrorKind::NotFound.into()), + }, + exists: |_| false, + }; + + /// A platform whose table is not the JSON this model reads. + const SERVES_GARBAGE: Files = Files { + read: |_| Ok("not a device table".to_owned()), + exists: |_| false, + }; + + /// The model parses what the platform READ and performs no read of its own: a platform with no + /// files is the assumed profile, unmeasured, which is what a set whose table is absent answers. + #[test] + fn a_platform_with_no_device_files_gets_the_assumed_profile_unmeasured() { + assert_eq!(read_caps(&Files::NONE), (Caps::assumed(), false)); + } + + #[test] + fn a_table_the_model_cannot_parse_gets_the_assumed_profile_unmeasured() { + assert_eq!(read_caps(&SERVES_GARBAGE), (Caps::assumed(), false)); + } + + /// The caps are the table's, minus what the conf the platform served switches off, and measured. + #[test] + fn the_table_and_conf_the_platform_serves_are_parsed_into_measured_caps() { + let (caps, measured) = read_caps(&SERVES_TABLE_AND_CONF); + assert!(measured); + let mut expected = parse(REAL).unwrap(); + expected.vp9_bit_depth = vp9_bit_depth_for(crate::tv::device::info().major); + let conf = GST_C1.replace("dts_audiodec=290", "dts_audiodec=0"); + assert_eq!(apply_gst_decoders(&mut expected, &conf).0, ["dts"]); + assert_eq!(caps, expected); + assert!(!caps.audio_has("dts"), "the served conf switched DTS off"); + assert_eq!(caps.hevc_row, (4096, 2176, 60)); + + let (kept, measured) = read_caps(&SERVES_TABLE_ONLY); + assert!(measured, "a missing gstcool.conf does not make the table any less read"); + assert!(kept.audio_has("dts"), "without the conf nothing is dropped"); + } } diff --git a/rust-modules/os/src/tv.rs b/rust-modules/os/src/tv.rs index 67eef2b9c..752c3bc93 100644 --- a/rust-modules/os/src/tv.rs +++ b/rust-modules/os/src/tv.rs @@ -2,8 +2,8 @@ pub mod device; pub mod home; pub mod launch; +pub mod native_video; pub mod plane; -pub mod sandbox; pub mod secure; pub mod sink; pub mod sound; @@ -35,7 +35,12 @@ pub struct Services { pub struct IdentityHooks { pub probe_device: fn(), pub start_capability_probe: fn(), - pub repair_sandbox: fn() -> Result<(), sandbox::Failure>, + /// The user-confirmed repair of a blocked native video path ([`native_video::repair`]), for a + /// platform that has one. `None` is a platform with nothing to repair: the repair then answers + /// [`native_video::Failure::Unsupported`]. + pub repair_native_video: Option Result<(), native_video::Failure>>, + /// The files the capability probe parses, read the platform's way ([`device::files`]). + pub device_files: device::Files, pub system_locale: fn() -> LocaleReply, pub sound_output: fn() -> sound::Reply, } @@ -71,12 +76,13 @@ pub struct LegacyWebosMedia { fn nothing() {} impl IdentityHooks { - /// A platform with no identity of its own to publish: nothing is probed, the sandbox cannot be + /// A platform with no identity of its own to publish: nothing is probed, native video cannot be /// repaired and there is no settings service to ask. pub const NONE: Self = Self { probe_device: nothing, start_capability_probe: nothing, - repair_sandbox: || Err(sandbox::Failure::Unsupported), + repair_native_video: None, + device_files: device::Files::NONE, system_locale: || LocaleReply::NoPlatform, sound_output: || sound::Reply::NoPlatform, }; @@ -150,7 +156,7 @@ mod tests { #[test] fn the_host_test_services_answer_nothing_and_say_so() { let Services { - identity: IdentityHooks { probe_device, start_capability_probe, repair_sandbox, system_locale, sound_output }, + identity: IdentityHooks { probe_device, start_capability_probe, repair_native_video, device_files, system_locale, sound_output }, secure: SecureHooks { seal, open, remove, mode }, system: SystemHooks { go_home, poll_home, deliver_toast }, legacy_webos_media: LegacyWebosMedia { sink, display_sink, uri_media }, @@ -158,7 +164,14 @@ mod tests { probe_device(); start_capability_probe(); - assert_eq!(repair_sandbox(), Err(sandbox::Failure::Unsupported)); + assert!(repair_native_video.is_none(), "a platform with nothing to repair states no hook"); + assert_eq!(native_video::repair(), Err(native_video::Failure::Unsupported)); + assert_eq!( + (device_files.read)("/etc/umediaserver/device_codec_capability_config.json").unwrap_err().kind(), + std::io::ErrorKind::NotFound, + "no files: a read fails as a missing file does" + ); + assert!(!(device_files.exists)("/"), "and nothing exists"); assert!(matches!(system_locale(), LocaleReply::NoPlatform)); assert!(matches!(sound_output(), sound::Reply::NoPlatform)); @@ -197,7 +210,7 @@ mod tests { // override another test may hold while this one runs. assert_eq!(services().secure.mode, secure::StoreMode::Durable); assert!(secure::seal(b"secret").is_none()); - assert_eq!(sandbox::repair(), Err(sandbox::Failure::Unsupported)); + assert_eq!(native_video::repair(), Err(native_video::Failure::Unsupported)); assert_eq!(uri::installed().open(uri::Shape::Anon), Err("no bus".into())); } } diff --git a/rust-modules/os/src/tv/device.rs b/rust-modules/os/src/tv/device.rs index a7474574c..d9e824da7 100644 --- a/rust-modules/os/src/tv/device.rs +++ b/rust-modules/os/src/tv/device.rs @@ -1,10 +1,14 @@ -//! Which television this is: the firmware ([`Info`]) and the set ([`Hardware`]). The webOS port -//! reads them at boot and publishes them here; everything else reads them from here. +//! Which television this is: the firmware ([`Info`]) and the set ([`Hardware`]), what the platform +//! calls itself to a Plex server ([`Platform`]) and the files its capability probe reads +//! ([`Files`]). The webOS port reads and publishes them at boot; everything else reads them from here. use std::sync::OnceLock; /// What the set said about itself. Owned strings rather than borrows into the file, because the /// file is read once and dropped; `OnceLock` because this is written exactly once, at boot, and /// read from the render thread every frame the diagnostics panel is up. +/// +/// `release`, `build` and `major` are the OS-version facts every platform states. What only a webOS +/// firmware file says is [`WebosDetail`], behind [`Info::webos`]. #[derive(Debug, Default, Clone)] pub struct Info { /// e.g. "4.10.2" — empty when unknown @@ -14,30 +18,38 @@ pub struct Info { /// when the release came from `/usr/lib/os-release`, which names no build). A /// patch within one release changes this and not `release`. pub build: String, + /// leading component of `release`, or 0 when unknown + pub major: u32, + /// What only a webOS firmware says about itself. All-empty on every other platform. + pub webos: WebosDetail, +} + +/// The firmware facts that are webOS's alone: three keys of nyx's `os_info.json`. The webOS +/// platform owns them: its probe is the only writer, no other platform has a value to put here, and +/// a reader that prints one prints a webOS fact (the codename is also the key the firmware +/// exclusions and the learned refusals are filed under). Empty when unknown, like [`Info`]'s own. +#[derive(Debug, Default, Clone, PartialEq, Eq)] +pub struct WebosDetail { /// e.g. "goldilocks2-grampians" — webosbrew buckets firmware by this pub codename: String, /// e.g. "4.1.0" pub api: String, /// e.g. "webOS TV" pub name: String, - /// leading component of `release`, or 0 when unknown - pub major: u32, } static INFO: OnceLock = OnceLock::new(); static NO_INFO: Info = Info { release: String::new(), build: String::new(), - codename: String::new(), - api: String::new(), - name: String::new(), major: 0, + webos: WebosDetail { codename: String::new(), api: String::new(), name: String::new() }, }; /// What the set reported. All-empty with `major == 0` when neither `os_info.json` nor /// `/usr/lib/os-release` could be read — which is the honest answer and is what the panel prints. -/// A release that only `/usr/lib/os-release` named leaves the codename, API version, name and -/// build empty. A plain `get()` (never `get_or_init`), so a read +/// A release that only `/usr/lib/os-release` named leaves the [`WebosDetail`] (codename, API +/// version, name) and the build empty. A plain `get()` (never `get_or_init`), so a read /// that races ahead of the boot probe sees the empty answer for itself and leaves the cell open for /// [`publish_info`]. pub fn info() -> &'static Info { @@ -179,6 +191,56 @@ pub fn publish_probe(probe: Probe) { let _ = PROBE.set(probe); } +/// What the platform calls itself to a Plex server: the `X-Plex-Platform` and +/// `X-Plex-Platform-Version` every request carries. The platform states them once at boot +/// ([`publish_platform`]); `plex::identity` reports its own default until it does. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Platform { + /// e.g. "webOS" + pub name: &'static str, + /// The platform's version as a Plex server should read it, e.g. "6.5.2". + pub version: String, +} + +static PLATFORM: OnceLock = OnceLock::new(); + +/// What the platform published, or `None` before it has (a read racing ahead of the boot probe, or +/// a host test). A plain `get()` like [`info`], so an early read leaves the cell open for +/// [`publish_platform`]. +pub fn platform() -> Option<&'static Platform> { + PLATFORM.get() +} + +/// The boot probe's answer. First write wins, like the `OnceLock` it lands in. +pub fn publish_platform(platform: Platform) { + let _ = PLATFORM.set(platform); +} + +/// The files the capability probe (`devcaps::probe`) parses, read by the platform. The probe owns +/// what a file means and where the model looks for it; the platform owns reading it, so the model +/// performs no IO of its own. The platform states them as `Services.identity.device_files`. +#[derive(Clone, Copy)] +pub struct Files { + /// The text of the file at an absolute path, or why it could not be read: the error is logged + /// by the caller, verbatim. + pub read: fn(&str) -> std::io::Result, + /// Whether a file or directory exists at an absolute path (a stat, never an open). + pub exists: fn(&str) -> bool, +} + +impl Files { + /// A platform with no such files: every read fails as a missing file does, and nothing exists. + pub const NONE: Self = Self { + read: |_| Err(std::io::ErrorKind::NotFound.into()), + exists: |_| false, + }; +} + +/// The installed platform's [`Files`]. +pub fn files() -> Files { + super::services().identity.device_files +} + #[cfg(test)] mod tests { use super::*; diff --git a/rust-modules/os/src/tv/native_video.rs b/rust-modules/os/src/tv/native_video.rs new file mode 100644 index 000000000..70cce9c83 --- /dev/null +++ b/rust-modules/os/src/tv/native_video.rs @@ -0,0 +1,181 @@ +//! Whether this set may start a native video Load, and the user-confirmed repair of a refusal. The +//! platform's boot probe publishes the verdict here and the player gates on it. webOS answers it +//! by probing `/dev/rtkmem`; a platform with nothing to ask publishes nothing, and the verdict is +//! then `NotApplicable`. +use std::sync::OnceLock; + +/// What the boot-time probe found, cached for the process. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Verdict { + /// The platform probed and the video path is there. On webOS: the SoC matched the affected + /// family and `/dev/rtkmem` is readable. + Available, + /// The platform probed and the video path is not usable here, so a Load must not be attempted. + /// The reason is a constant word the platform names; it is printed, in the log and as the + /// report's context ([`context`]), and no shared code branches on it. On webOS: the SoC matched + /// the affected family and `/dev/rtkmem` is missing (or unreadable) from this jail, reason + /// `"missing"`. + Blocked(&'static str), + /// There is nothing to ask: nothing was probed, or the platform's probe found the set outside + /// the family it asks about. On webOS: the SoC did not match, so `/dev/rtkmem` was never probed. + NotApplicable, +} + +static VERDICT: OnceLock = OnceLock::new(); + +/// The boot probe's verdict, once per boot. First write wins, like the `OnceLock` it lands in. +pub fn publish(verdict: Verdict) { + let _ = VERDICT.set(verdict); +} + +/// TEST ONLY: force [`blocked`] to report blocked, without touching the process-wide `VERDICT` +/// `OnceLock` — a real boot sets that exactly once via the platform's probe, and no test can +/// re-init it to exercise the blocked path. Mirrors `ffi_host.rs`'s `FORCE_*` controls. There is no +/// separate "release" call: `false` is the default, so a test that sets this to `true` must reset +/// it to `false` before returning, under `plx_base::testlock::serial()`. +#[cfg(any(test, feature = "test-support"))] +pub static FORCE_BLOCKED: std::sync::atomic::AtomicBool = + std::sync::atomic::AtomicBool::new(false); + +/// True only when this session must not attempt a native video Load: the platform's probe found +/// the video path unusable ([`Verdict::Blocked`]). On webOS that is the SoC matching the affected +/// family AND `/dev/rtkmem` missing from this jail; the community-tier evidence it is built on is +/// in the webOS port's `probe_jail` section doc. `player::mod` calls this before the first Load of +/// every session. +/// +/// Reads with a plain `get()` (never `get_or_init`) so a call that races ahead of the platform's +/// probe sees `NotApplicable` for itself but leaves the cell EMPTY — a later [`publish`] can still +/// `set()` the real verdict, and every subsequent call observes it. `get_or_init` would instead +/// latch `NotApplicable` permanently on that first early call, silently discarding the real +/// probe's `set()` and leaving the `devjail: … rtkmem=missing` log line contradicted by a gate +/// that reports not-blocked forever. +pub fn blocked() -> bool { + #[cfg(any(test, feature = "test-support"))] + if FORCE_BLOCKED.load(std::sync::atomic::Ordering::Relaxed) { + return true; + } + blocks(&VERDICT) +} + +/// PURE half of [`blocked`]'s verdict, taking the cell as a parameter — so the +/// early-read-vs-later-write race it exists to guard against can be tested against a throwaway +/// local `OnceLock`, rather than by writing into the real process-wide `VERDICT` (which a test can +/// never un-set, and which every later test's `blocked()` call also reads). +fn blocks(cell: &OnceLock) -> bool { + matches!(verdict_of(cell), Verdict::Blocked(_)) +} + +/// What `cell` holds, or [`Verdict::NotApplicable`] when nothing has been published: the one +/// fallback [`blocked`] and [`context`] share, so the gate and the report cannot disagree about a +/// call that raced ahead of the probe. +fn verdict_of(cell: &OnceLock) -> Verdict { + cell.get().copied().unwrap_or(Verdict::NotApplicable) +} + +/// The closed word for a verdict: `ok` for [`Verdict::Available`], `n/a` for +/// [`Verdict::NotApplicable`] and the platform's own reason for [`Verdict::Blocked`] (`missing` on +/// webOS). The vocabulary the telemetry schema and `PRIVACY.md` document. +fn word(verdict: Verdict) -> &'static str { + match verdict { + Verdict::Available => "ok", + Verdict::NotApplicable => "n/a", + Verdict::Blocked(reason) => reason, + } +} + +/// The closed native-video fact for every telemetry event — `ok` / `missing` / `n/a` on webOS — read +/// from the SAME cached verdict [`blocked`] gates playback on, never a second probe of the device. +/// An unset cell (a call racing ahead of boot's probe, the same race [`blocked`]'s doc describes) +/// reads as `n/a` — the same fallback that function uses, so a telemetry event and the gate it +/// would have been diagnosing this attempt's failure against can never disagree about what this +/// jail carries. +pub fn context() -> &'static str { + word(verdict_of(&VERDICT)) +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Failure { + StartFailed, + HbcUnavailable, + NotRoot, + CommandFailed, + // The simulator has no LS2 timeout; development fixtures and tests still construct it. The + // enum is public to the application crate, so the variant is never dead in this crate. + Timeout, + Unreadable, + Unsupported, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum State { + Idle, + Running, + Repaired, + Failed(Failure), +} + +/// Called only by the PlayerAdapter worker after the owner accepts explicit confirmation. A platform +/// with no repair (`Services.identity.repair_native_video` is `None`) answers +/// [`Failure::Unsupported`]. +pub fn repair() -> Result<(), Failure> { + match super::services().identity.repair_native_video { + Some(hook) => hook(), + None => Err(Failure::Unsupported), + } +} + +#[cfg(test)] +mod tests { + use super::*; + + /// Regression for `rtkmem-verdict-defeated-by-get-or-init-default`: an early call to + /// `blocked()` (before the platform's probe has ever run) must NOT permanently latch + /// `NotApplicable` into the cell. With the old `get_or_init(|| NotApplicable)` reader this + /// first call would win the race and every later `VERDICT.set(Blocked(..))` from the real probe + /// would be silently dropped (`OnceLock::set` returns `Err` once already initialized) — the + /// gate would report "not blocked" forever while the boot log said `rtkmem=missing`. + /// + /// Exercised against a throwaway local cell via `blocks`, not the process-wide `VERDICT` + /// static — that `OnceLock` can never be un-set, so writing into the real one here would + /// permanently latch `blocked()` to `true` for every other test in this process, + /// un-serialized. See finding + /// `rtkmem-probe-test-permanently-sets-the-process-wide-oncelock`. + #[test] + fn early_read_does_not_defeat_a_later_blocked_verdict() { + let cell: OnceLock = OnceLock::new(); + assert!(!blocks(&cell), "cell must start empty/unset"); + cell.set(Verdict::Blocked("missing")) + .expect("cell was still empty, so this must be the first, winning set()"); + assert!( + blocks(&cell), + "a verdict set after an earlier read must still take effect" + ); + } + + /// The three verdicts, mapped: only a blocked one blocks, and an unpublished cell reads as not + /// applicable for both the gate and the report. + #[test] + fn only_a_blocked_verdict_blocks_and_an_unpublished_one_is_not_applicable() { + for (verdict, blocks_load) in [ + (Verdict::Available, false), + (Verdict::NotApplicable, false), + (Verdict::Blocked("missing"), true), + ] { + let cell = OnceLock::new(); + cell.set(verdict).unwrap(); + assert_eq!(blocks(&cell), blocks_load, "{verdict:?}"); + } + let unset: OnceLock = OnceLock::new(); + assert_eq!(verdict_of(&unset), Verdict::NotApplicable); + assert!(!blocks(&unset)); + } + + /// The words telemetry, the log and `PRIVACY.md` carry for the jail pre-flight. A blocked + /// verdict reads as the reason its platform named, which on webOS is `missing`. + #[test] + fn the_context_words_are_ok_missing_and_not_applicable() { + assert_eq!(word(Verdict::Available), "ok"); + assert_eq!(word(Verdict::Blocked("missing")), "missing"); + assert_eq!(word(Verdict::NotApplicable), "n/a"); + } +} diff --git a/rust-modules/os/src/tv/sandbox.rs b/rust-modules/os/src/tv/sandbox.rs deleted file mode 100644 index a23cad15d..000000000 --- a/rust-modules/os/src/tv/sandbox.rs +++ /dev/null @@ -1,129 +0,0 @@ -//! The jail's verdict on the video path, and the user-confirmed repair of it. The webOS port -//! probes `/dev/rtkmem` at boot and publishes the verdict here; the player gates on it. -use std::sync::OnceLock; - -/// The three outcomes of the boot-time probe, cached for the process. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum Verdict { - /// The SoC did not match the affected family — `/dev/rtkmem` was never probed. - NotApplicable, - /// The SoC matched and `/dev/rtkmem` is readable. - Ok, - /// The SoC matched and `/dev/rtkmem` is missing (or unreadable) from this jail. - Missing, -} - -static VERDICT: OnceLock = OnceLock::new(); - -/// The boot probe's verdict, once per boot. First write wins, like the `OnceLock` it lands in. -pub fn publish(verdict: Verdict) { - let _ = VERDICT.set(verdict); -} - -/// TEST ONLY: force [`blocks_native_video`] to report blocked, without touching the process-wide -/// `VERDICT` `OnceLock` — a real boot sets that exactly once via the port's probe, and no test can -/// re-init it to exercise the blocked path. Mirrors `ffi_host.rs`'s `FORCE_*` controls. There is no -/// separate "release" call: `false` is the default, so a test that sets this to `true` must reset -/// it to `false` before returning, under `plx_base::testlock::serial()`. -#[cfg(any(test, feature = "test-support"))] -pub static FORCE_BLOCKED: std::sync::atomic::AtomicBool = - std::sync::atomic::AtomicBool::new(false); - -/// True only when this session must not attempt a native video Load: the SoC matched the -/// affected family AND `/dev/rtkmem` was missing from this jail. The community-tier evidence it is -/// built on is in the webOS port's `probe_jail` section doc. `player::mod` calls this before the -/// first Load of every session. -/// -/// Reads with a plain `get()` (never `get_or_init`) so a call that races ahead of the port's -/// probe sees `NotApplicable` for itself but leaves the cell EMPTY — a later [`publish`] can still -/// `set()` the real verdict, and every subsequent call observes it. `get_or_init` would instead -/// latch `NotApplicable` permanently on that first early call, silently discarding the real -/// probe's `set()` and leaving the `devjail: … rtkmem=missing` log line contradicted by a gate -/// that reports not-blocked forever. -pub fn blocks_native_video() -> bool { - #[cfg(any(test, feature = "test-support"))] - if FORCE_BLOCKED.load(std::sync::atomic::Ordering::Relaxed) { - return true; - } - blocks(&VERDICT) -} - -/// PURE half of [`blocks_native_video`]'s verdict, taking the cell as a parameter — so the -/// early-read-vs-later-write race it exists to guard against can be tested against a throwaway -/// local `OnceLock`, rather than by writing into the real process-wide `VERDICT` (which a test can -/// never un-set, and which every later test's `blocks_native_video()` call also reads). -fn blocks(cell: &OnceLock) -> bool { - matches!( - cell.get().copied().unwrap_or(Verdict::NotApplicable), - Verdict::Missing - ) -} - -/// The closed-enum sandbox fact for every telemetry event — `ok` / `missing` / `n/a` — read from -/// the SAME cached verdict [`blocks_native_video`] gates playback on, never a second probe of -/// `/dev/rtkmem`. An unset cell (a call racing ahead of boot's probe, the same race -/// [`blocks_native_video`]'s doc describes) reads as `n/a` — the same fallback that function uses, -/// so a telemetry event and the gate it would have been diagnosing this attempt's failure against -/// can never disagree about what this jail carries. -pub fn context() -> &'static str { - match VERDICT.get().copied().unwrap_or(Verdict::NotApplicable) { - Verdict::NotApplicable => "n/a", - Verdict::Ok => "ok", - Verdict::Missing => "missing", - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum Failure { - StartFailed, - HbcUnavailable, - NotRoot, - CommandFailed, - // The simulator has no LS2 timeout; development fixtures and tests still construct it. The - // enum is public to the application crate, so the variant is never dead in this crate. - Timeout, - Unreadable, - Unsupported, -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum State { - Idle, - Running, - Repaired, - Failed(Failure), -} - -/// Called only by the PlayerAdapter worker after the owner accepts explicit confirmation. -pub fn repair() -> Result<(), Failure> { - (super::services().identity.repair_sandbox)() -} - -#[cfg(test)] -mod tests { - use super::*; - - /// Regression for `rtkmem-verdict-defeated-by-get-or-init-default`: an early call to - /// `blocks_native_video()` (before the port's probe has ever run) must NOT permanently latch - /// `NotApplicable` into the cell. With the old `get_or_init(|| NotApplicable)` reader this - /// first call would win the race and every later `VERDICT.set(Missing)` from the real probe - /// would be silently dropped (`OnceLock::set` returns `Err` once already initialized) — the - /// gate would report "not blocked" forever while the boot log said `rtkmem=missing`. - /// - /// Exercised against a throwaway local cell via `blocks`, not the process-wide `VERDICT` - /// static — that `OnceLock` can never be un-set, so writing into the real one here would - /// permanently latch `blocks_native_video()` to `true` for every other test in this process, - /// un-serialized. See finding - /// `rtkmem-probe-test-permanently-sets-the-process-wide-oncelock`. - #[test] - fn early_read_does_not_defeat_a_later_missing_verdict() { - let cell: OnceLock = OnceLock::new(); - assert!(!blocks(&cell), "cell must start empty/unset"); - cell.set(Verdict::Missing) - .expect("cell was still empty, so this must be the first, winning set()"); - assert!( - blocks(&cell), - "a verdict set after an earlier read must still take effect" - ); - } -} diff --git a/rust-modules/os/src/webos.rs b/rust-modules/os/src/webos.rs index 74d2c11ca..d8ff5013f 100644 --- a/rust-modules/os/src/webos.rs +++ b/rust-modules/os/src/webos.rs @@ -40,7 +40,7 @@ //! for service replies: [`caps`] uses `serde_json` and strict types because uncertainty there is a //! playback-safety decision. The capability query deliberately does not fill a missing webOS //! version; no public version key or anonymous permission for one is evidenced. -use crate::tv::device::{Hardware, Info, NyxFile}; +use crate::tv::device::{Hardware, Info, NyxFile, Platform, WebosDetail}; pub mod jail_repair; pub mod caps; @@ -78,10 +78,12 @@ fn parse(s: &str) -> Info { Info { release, build, - codename: get("webos_release_codename"), - api: get("webos_api_version"), - name: get("webos_name"), major, + webos: WebosDetail { + codename: get("webos_release_codename"), + api: get("webos_api_version"), + name: get("webos_name"), + }, } } @@ -109,15 +111,43 @@ pub fn probe() { } else if info.major > 0 { plx_base::eventlog::log(&format!( "webos: {} release={} codename={} api={} major={}", - info.name, info.release, info.codename, info.api, info.major + info.webos.name, info.release, info.webos.codename, info.webos.api, info.major )); } crate::tv::device::publish_info(info); + // From what `publish_info` kept (the first write wins), so the platform's version and `info()` + // cannot name two releases. + crate::tv::device::publish_platform(plex_platform(&crate::tv::device::info().release)); let device_info = probe_hw(); crate::tv::device::publish_probe(crate::tv::device::Probe { os_info, device_info }); probe_jail(); } +/// What webOS calls itself to a Plex server: `X-Plex-Platform`. +const PLEX_PLATFORM: &str = "webOS"; + +/// The `X-Plex-Platform-Version` for a firmware that names no release: the literal every release +/// before the real version was read has reported, rather than an empty value no server has ever +/// been shown. +const PLEX_PLATFORM_VERSION_UNKNOWN: &str = "4.5"; + +/// PURE: the platform webOS publishes to `tv::device` for a firmware `release`: the real release, +/// or [`PLEX_PLATFORM_VERSION_UNKNOWN`] when the set did not name one. The values `plex::identity` +/// reported before the platform published them, byte for byte. +fn plex_platform(release: &str) -> Platform { + Platform { + name: PLEX_PLATFORM, + version: if release.is_empty() { PLEX_PLATFORM_VERSION_UNKNOWN.to_string() } else { release.to_string() }, + } +} + +/// The files `devcaps::probe` parses, read from the file system: webOS's own paths, named by the +/// model. The simulator's host has none of them and so answers "unreadable", as it always did. +pub const DEVICE_FILES: crate::tv::device::Files = crate::tv::device::Files { + read: |path| std::fs::read_to_string(path), + exists: |path| std::path::Path::new(path).exists(), +}; + // ---- which SET this is, as opposed to which webOS --------------------------------------------- /// nyx's other file. Same directory, same flat shape, written by the same platform component. @@ -147,9 +177,9 @@ fn os_info_from(text: Option<&str>) -> (Info, NyxFile) { }; let info = parse(text); let answered = !info.release.is_empty() - || !info.codename.is_empty() - || !info.api.is_empty() - || !info.name.is_empty(); + || !info.webos.codename.is_empty() + || !info.webos.api.is_empty() + || !info.webos.name.is_empty(); (info, if answered { NyxFile::Ok } else { NyxFile::NoKeys }) } @@ -323,20 +353,31 @@ pub fn is_realtek_k5lp_family(machine_name: &str) -> bool { /// [`probe`] and [`probe_hw`] already follow for their own unreadable files. fn probe_jail() { let name = read_machine_name(); - let result = if is_realtek_k5lp_family(&name) { - let readable = std::ffi::CString::new(RTKMEM_DEVICE) + let result = jail_verdict(&name, || { + std::ffi::CString::new(RTKMEM_DEVICE) .map(|path| unsafe { libc::access(path.as_ptr(), libc::R_OK) } == 0) - .unwrap_or(false); - if readable { - crate::tv::sandbox::Verdict::Ok - } else { - crate::tv::sandbox::Verdict::Missing - } + .unwrap_or(false) + }); + crate::tv::native_video::publish(result); + plx_base::eventlog::log(&format!("devjail: soc={name} rtkmem={}", crate::tv::native_video::context())); +} + +/// The reason webOS names for a blocked native video path, and so the word the `devjail:` line, the +/// telemetry `rtkmem` context and `PRIVACY.md` carry for it. +const RTKMEM_MISSING: &str = "missing"; + +/// PURE: the native-video verdict for a machine name. A name outside the affected family is never +/// probed (`rtkmem_readable` is not called); inside it, a readable `/dev/rtkmem` is `Available` and +/// an unreadable one is `Blocked` with [`RTKMEM_MISSING`]. +fn jail_verdict(machine_name: &str, rtkmem_readable: impl FnOnce() -> bool) -> crate::tv::native_video::Verdict { + use crate::tv::native_video::Verdict; + if !is_realtek_k5lp_family(machine_name) { + Verdict::NotApplicable + } else if rtkmem_readable() { + Verdict::Available } else { - crate::tv::sandbox::Verdict::NotApplicable - }; - crate::tv::sandbox::publish(result); - plx_base::eventlog::log(&format!("devjail: soc={name} rtkmem={}", crate::tv::sandbox::context())); + Verdict::Blocked(RTKMEM_MISSING) + } } // ---- the ROOT press: give the screen back, without ending the process ------------------------- @@ -1330,7 +1371,7 @@ mod tests { // No codename, API version or name is in the file, and none is invented. Nor is a build: // `core_os_release` ("6.5.3-47") carries a build id this file does not, and a build that // read "6.5.3" on this boot and "6.5.3-47" on a nyx boot would look like two builds. - assert!(i.codename.is_empty() && i.api.is_empty() && i.name.is_empty() && i.build.is_empty(), "{i:?}"); + assert!(i.webos == WebosDetail::default() && i.build.is_empty(), "{i:?}"); let i = os_release_info(OS_RELEASE_562).expect("5.6.2 firmware names its release"); assert_eq!((i.release.as_str(), i.major), ("5.6.2", 5)); } @@ -1397,7 +1438,7 @@ mod tests { fn a_nyx_file_that_was_read_is_never_second_guessed() { let fw = firmware_from(Some(REAL), Some(OS_RELEASE_653)); assert_eq!((fw.info.release.as_str(), fw.info.major), ("4.10.2", 4)); - assert_eq!(fw.info.codename, "goldilocks2-grampians"); + assert_eq!(fw.info.webos.codename, "goldilocks2-grampians"); assert_eq!(fw.info.build, "4.10.2-31"); assert_eq!(fw.os_info, NyxFile::Ok); assert!(!fw.from_os_release); @@ -1411,7 +1452,7 @@ mod tests { fn an_unreadable_nyx_file_falls_back_to_os_release_and_is_still_reported_unreadable() { let fw = firmware_from(None, Some(OS_RELEASE_653)); assert_eq!((fw.info.release.as_str(), fw.info.major), ("6.5.3", 6)); - assert!(fw.info.codename.is_empty() && fw.info.api.is_empty() && fw.info.build.is_empty()); + assert!(fw.info.webos == WebosDetail::default() && fw.info.build.is_empty()); // The verdict on nyx's own file (the event log line and the crash report's `hardware.probe` // field) stays `unreadable`; it is not a statement about whether the release is known. assert_eq!(fw.os_info, NyxFile::Unreadable); @@ -1437,8 +1478,9 @@ mod tests { fn parses_the_whole_record() { let i = parse(REAL); assert_eq!((i.release.as_str(), i.major), ("4.10.2", 4)); - assert_eq!(i.codename, "goldilocks2-grampians"); - assert_eq!(i.name, "webOS TV"); + assert_eq!(i.webos.codename, "goldilocks2-grampians"); + assert_eq!(i.webos.api, "4.1.0"); + assert_eq!(i.webos.name, "webOS TV"); } /// The unknown case must be EMPTY with major 0, never a plausible-looking default. A panel that @@ -1447,7 +1489,7 @@ mod tests { fn an_unreadable_file_yields_no_version_rather_than_a_guess() { let i = parse("not json at all"); assert_eq!(i.major, 0); - assert!(i.release.is_empty() && i.codename.is_empty()); + assert!(i.release.is_empty() && i.webos.codename.is_empty()); } /// A two-component release still yields its major — LG has shipped "6.0" as well as "4.10.2". @@ -1473,4 +1515,27 @@ mod tests { assert!(!is_realtek_k5lp_family("prefix-k5lp")); assert!(!is_realtek_k5lp_family("K5LP")); } + + /// What webOS tells a Plex server: the name it always sent, the real release when the set named + /// one and the old literal when it did not. + #[test] + fn the_published_platform_is_the_webos_the_headers_always_named() { + assert_eq!(plex_platform("6.5.2"), Platform { name: "webOS", version: "6.5.2".into() }); + assert_eq!(plex_platform(""), Platform { name: "webOS", version: "4.5".into() }); + } + + /// webOS's three answers on the neutral verdict, one per old one: a readable `/dev/rtkmem` on + /// the family is `Available` (was `Ok`), an unreadable one is `Blocked` with the word telemetry + /// has always carried (was `Missing`), and a set outside the family is not probed at all. + #[test] + fn the_jail_verdict_maps_each_old_answer_to_its_native_video_variant() { + use crate::tv::native_video::Verdict; + assert_eq!(jail_verdict("k5lp", || true), Verdict::Available); + assert_eq!(jail_verdict("k3lp.something", || false), Verdict::Blocked("missing")); + assert_eq!( + jail_verdict("o22", || panic!("a set outside the family is never probed")), + Verdict::NotApplicable + ); + assert_eq!(jail_verdict("", || panic!("an unreadable machine name is never probed")), Verdict::NotApplicable); + } } diff --git a/rust-modules/os/src/webos/jail_repair.rs b/rust-modules/os/src/webos/jail_repair.rs index a9d1c6342..324dc52dc 100644 --- a/rust-modules/os/src/webos/jail_repair.rs +++ b/rust-modules/os/src/webos/jail_repair.rs @@ -4,7 +4,7 @@ //! explicit confirmation. That app-owned attempt survives every screen and session reset, //! including timeout: the remote shell may still run after LS2 gives up. -use crate::tv::sandbox::Failure; +use crate::tv::native_video::Failure; use serde_json::Value; use std::path::Path; #[cfg(all(not(feature = "hostsim"), not(any(test, feature = "test-support"))))] diff --git a/rust-modules/plex/src/plex/account.rs b/rust-modules/plex/src/plex/account.rs index a86d3c6e1..3d810a337 100644 --- a/rust-modules/plex/src/plex/account.rs +++ b/rust-modules/plex/src/plex/account.rs @@ -440,7 +440,7 @@ impl AccountClient { "Accept: application/json".to_string(), format!("X-Plex-Product: {}", id::PRODUCT), format!("X-Plex-Version: {}", id::version()), - format!("X-Plex-Platform: {}", id::PLATFORM), + format!("X-Plex-Platform: {}", id::platform()), format!("X-Plex-Platform-Version: {}", id::platform_version()), format!("X-Plex-Device: {}", id::DEVICE), format!("X-Plex-Device-Name: {}", id::device_name()), diff --git a/rust-modules/plex/src/plex/client.rs b/rust-modules/plex/src/plex/client.rs index 418064726..b7a241f39 100644 --- a/rust-modules/plex/src/plex/client.rs +++ b/rust-modules/plex/src/plex/client.rs @@ -114,7 +114,6 @@ pub struct Client { pub(super) client_id: String, // X-Plex-Client-Identifier — stable device id (NEVER per-item) pub(super) product: String, // "PlxNative" pub(super) version: String, // "0.1.0" - pub(super) platform: String, // "webOS" // Token generation, PER SERVER. Bumped by `set_token`; read by caches keyed on a path that // bakes the token in (`app::adapters::poster::built_key`'s memo). This used to be a process-global // `static TOKEN_GEN`, which cannot express "server B's token changed" — with a registry that @@ -272,7 +271,6 @@ impl Client { client_id: client_id.to_owned(), product: super::identity::PRODUCT.into(), version: super::identity::version().into(), - platform: super::identity::PLATFORM.into(), token_gen: AtomicU32::new(generation), grant_epoch: AtomicU32::new(generation), instance_gen: generation, @@ -304,7 +302,7 @@ impl Client { ("X-Plex-Client-Identifier", &self.client_id), ("X-Plex-Product", &self.product), ("X-Plex-Version", &self.version), - ("X-Plex-Platform", &self.platform), + ("X-Plex-Platform", super::identity::platform()), ("X-Plex-Platform-Version", super::identity::platform_version()), ("X-Plex-Device", DEVICE), ("X-Plex-Device-Name", device_name()), diff --git a/rust-modules/plex/src/plex/identity.rs b/rust-modules/plex/src/plex/identity.rs index 316c63d47..f90c7f20d 100644 --- a/rust-modules/plex/src/plex/identity.rs +++ b/rust-modules/plex/src/plex/identity.rs @@ -83,19 +83,35 @@ pub fn version() -> &'static str { } } +/// The platform name this client reports until the platform states its own +/// ([`plx_os::tv::device::publish_platform`]). It is webOS's, which is the only name every release +/// so far has reported, so a build or a test that never publishes still sends exactly what it sent. pub const PLATFORM: &str = "webOS"; -/// The OS version — the REAL one, read off the set at boot ([`plx_os::tv::device`]), because the -/// app runs on webOS 4 through 11 now and a literal is wrong on every set but one. This was -/// `const … = "4.5"` while the app was packaged `>=4.0, <5.0`; the webosbrew reviewer flagged it -/// reporting 4.5 from a 6.5.2 television (issue #22). PMS augments our named Generic profile -/// from the X-Plex-Client-Profile-Extra we send, so the version is informational today — but it -/// is also how a server-side profile could ever distinguish firmware generations, and a false -/// one poisons that forever. The fallback when neither `os_info.json` nor `/usr/lib/os-release` names a release keeps the literal +/// `X-Plex-Platform`: the name the platform published at boot, else [`PLATFORM`]. Read per request, +/// like [`platform_version`], so a request built before the boot probe (a host test) still names a +/// platform and one built after it names the real one. +pub fn platform() -> &'static str { + plx_os::tv::device::platform().map_or(PLATFORM, |p| p.name) +} + +/// `X-Plex-Platform-Version`: the version the platform published at boot ([`platform`]'s +/// companion), else the OS version off the set ([`plx_os::tv::device`]). +/// +/// The platform states it because the app runs on webOS 4 through 11 now and a literal is wrong on +/// every set but one. This was `const … = "4.5"` while the app was packaged `>=4.0, <5.0`; the +/// webosbrew reviewer flagged it reporting 4.5 from a 6.5.2 television (issue #22). PMS augments +/// our named Generic profile from the X-Plex-Client-Profile-Extra we send, so the version is +/// informational today — but it is also how a server-side profile could ever distinguish +/// firmware generations, and a false one poisons that forever. The fallback when nothing was +/// published and neither `os_info.json` nor `/usr/lib/os-release` names a release keeps the literal /// this replaces — the exact claim every release so far has made — rather than inventing an /// empty-string case no server has ever been shown. Safe by boot order: `tv::probe_device()` runs /// before any PMS request, so none can precede the read. pub fn platform_version() -> &'static str { + if let Some(published) = plx_os::tv::device::platform() { + return &published.version; + } let r = &plx_os::tv::device::info().release; if r.is_empty() { "4.5" @@ -229,6 +245,16 @@ mod tests { assert_eq!(super::platform_version(), "4.5"); } + /// Until a platform publishes its own name (`plx_os::tv::device::publish_platform`, which only the + /// webOS boot probe calls) the client says what every release so far has said, so a request + /// built before the probe, or in a host test, is unchanged. + #[test] + fn an_unpublished_platform_names_webos() { + assert!(plx_os::tv::device::platform().is_none(), "no host test publishes a platform"); + assert_eq!(super::platform(), super::PLATFORM); + assert_eq!(super::platform(), "webOS"); + } + #[test] fn a_process_locale_becomes_a_safe_plex_language_tag() { assert_eq!( diff --git a/rust-modules/screens/src/player/mod.rs b/rust-modules/screens/src/player/mod.rs index 049cedfb1..301941bec 100644 --- a/rust-modules/screens/src/player/mod.rs +++ b/rust-modules/screens/src/player/mod.rs @@ -1258,7 +1258,7 @@ impl PlayerScreen { A::TryAgain => Self::ask(fx, PlayerReq::RetryPlayback), A::ChangeQuality => Self::ask(fx, PlayerReq::OpenOverlay(overlay::OverlayKind::More { page: Some(plx_appkit::more_menu::MorePage::Quality) })), A::Repair => { - if ps.repair_status == plx_os::tv::sandbox::State::Idle && !self.repair_alert.visible() { + if ps.repair_status == plx_os::tv::native_video::State::Idle && !self.repair_alert.visible() { self.repair_scroll = 0; self.repair_alert.open_with_body(plx_os::i18n::msg::widgets_repair_question_c(), plx_os::i18n::msg::widgets_repair_body()); Self::repair_focus(fx, GROUP_REPAIR); @@ -5980,7 +5980,7 @@ mod repair_confirmation_tests { std::fs::write(&path, "jail").unwrap(); let mut ps = plx_media::route::PlaybackSession::IDLE; plx_media::route::reset_player_control_for_test(&ps); - let hardware_verdict = plx_os::tv::sandbox::blocks_native_video(); + let hardware_verdict = plx_os::tv::native_video::blocked(); plx_media::player::failure_fixture(&mut ps); let mut page = PlayerScreen::new(EntryId(1), plx_appkit::player_hud::loaded::classic_for_test()); assert!(deliver(&mut page, &ps, None, key_event(consts::SDLK_RETURN, 0)).is_empty()); @@ -5988,7 +5988,7 @@ mod repair_confirmation_tests { assert!(deliver(&mut page, &ps, Some(REPAIR_CANCEL), ScreenEvent::Tick(Tick { ms: 16, dt_us: 16_000 })).is_empty()); assert!(page.repair_alert.is_open(), "Tick must not retire the jail fixture confirmation"); assert!(ps.jail_load_blocked); - assert_eq!(plx_os::tv::sandbox::blocks_native_video(), hardware_verdict, "the fixture must not alter the cached hardware verdict"); + assert_eq!(plx_os::tv::native_video::blocked(), hardware_verdict, "the fixture must not alter the cached hardware verdict"); ps.jail_load_blocked = false; deliver(&mut page, &ps, None, ScreenEvent::Tick(Tick { ms: 32, dt_us: 16_000 })); assert!(!page.repair_alert.is_open(), "retiring the session still closes its confirmation"); @@ -6042,7 +6042,7 @@ mod repair_confirmation_tests { /// `player` may not name `screens`. The attempt is the `Player` machine's, not the screen's. #[test] fn repair_survives_screen_and_session_recreation_and_rejects_stale_completions() { - use plx_os::tv::sandbox::{Failure, State}; + use plx_os::tv::native_video::{Failure, State}; let mut player = plx_media::player::machine::Player::new(); let token = player.repair.begin(true).unwrap(); assert!(!player.repair.complete(token + 1, Ok(()))); @@ -6058,7 +6058,7 @@ mod repair_confirmation_tests { #[test] fn accepted_attempt_hides_forward_action_after_screen_recreation() { let _g = plx_base::testlock::serial(); - for state in [plx_os::tv::sandbox::State::Running, plx_os::tv::sandbox::State::Repaired, plx_os::tv::sandbox::State::Failed(plx_os::tv::sandbox::Failure::Timeout)] { + for state in [plx_os::tv::native_video::State::Running, plx_os::tv::native_video::State::Repaired, plx_os::tv::native_video::State::Failed(plx_os::tv::native_video::Failure::Timeout)] { let mut ps = blocked(); ps.repair_status = state; plx_media::route::reset_player_control_for_test(&ps); let row = super::overlay_tests::failure_fixture(&ps).actions().to_vec(); diff --git a/rust-modules/src/app/diagnostics.rs b/rust-modules/src/app/diagnostics.rs index 6df2e71e9..e7d157768 100644 --- a/rust-modules/src/app/diagnostics.rs +++ b/rust-modules/src/app/diagnostics.rs @@ -462,10 +462,10 @@ impl Diagnostics { /// no API version, and the line must not end in an `api` label with nothing after it. fn firmware_head(w: &plx_os::tv::device::Info) -> String { let release = plx_os::i18n::webos_release_line(w); - if w.major == 0 || w.api.is_empty() { + if w.major == 0 || w.webos.api.is_empty() { release } else { - format!("{release} · api {}", w.api) + format!("{release} · api {}", w.webos.api) } } @@ -593,7 +593,7 @@ fn device_rows() -> Vec { // image somebody else can go and look at. v.push(Field::new( plx_os::i18n::msg::browse_diagnostics_field_firmware(), - match (i.name.as_str(), i.codename.as_str()) { + match (i.webos.name.as_str(), i.webos.codename.as_str()) { // Bare "unknown": with neither file read the head line above already carries the REASON // ("webOS unknown — os_info.json unreadable"). When `/usr/lib/os-release` named the // release instead, the head line reads `webOS 6.5.3` and this row is the codename, @@ -3523,9 +3523,14 @@ mod tests { /// line must not end in an `api` label with nothing after it. #[test] fn the_firmware_text_names_the_api_only_when_it_is_known() { - use plx_os::tv::device::Info; + use plx_os::tv::device::{Info, WebosDetail}; let _g = plx_base::testlock::serial(); - let nyx = Info { release: "4.10.2".into(), api: "4.1.0".into(), major: 4, ..Info::default() }; + let nyx = Info { + release: "4.10.2".into(), + major: 4, + webos: WebosDetail { api: "4.1.0".into(), ..WebosDetail::default() }, + ..Info::default() + }; assert_eq!(firmware_head(&nyx), "webOS 4.10.2 · api 4.1.0", "the nyx spelling is unchanged"); let os_release = Info { release: "6.5.3".into(), major: 6, ..Info::default() }; assert_eq!(firmware_head(&os_release), "webOS 6.5.3"); diff --git a/rust-modules/src/app/playback.rs b/rust-modules/src/app/playback.rs index c54ddcec0..c8196e575 100644 --- a/rust-modules/src/app/playback.rs +++ b/rust-modules/src/app/playback.rs @@ -835,7 +835,7 @@ pub(crate) fn player_requests( } PlayerReq::RepairSandbox => { if player.session.jail_load_blocked { - pa.repair_sandbox(&mut player.repair, plx_os::tv::sandbox::blocks_native_video()); + pa.repair_sandbox(&mut player.repair, plx_os::tv::native_video::blocked()); player.session.repair_status = player.repair.state(); pages.present.note_in_scope(plx_machine::present::Scope::Page, plx_machine::present::PresentEvent::Damage(plx_machine::present::Provenance::Input)); } diff --git a/rust-modules/src/lab/snapshot.rs b/rust-modules/src/lab/snapshot.rs index e992eab51..7d27d2e31 100644 --- a/rust-modules/src/lab/snapshot.rs +++ b/rust-modules/src/lab/snapshot.rs @@ -276,9 +276,9 @@ fn device() -> Device { let d = plx_os::tv::device::device(); Device { webos_release: i.release.clone(), - webos_codename: i.codename.clone(), - webos_api: i.api.clone(), - webos_name: i.name.clone(), + webos_codename: i.webos.codename.clone(), + webos_api: i.webos.api.clone(), + webos_name: i.webos.name.clone(), model: d.model.clone(), board: d.board.clone(), hw_revision: d.hw_revision.clone(), diff --git a/rust-modules/src/port.rs b/rust-modules/src/port.rs index 060fad039..6214eecef 100644 --- a/rust-modules/src/port.rs +++ b/rust-modules/src/port.rs @@ -30,7 +30,8 @@ static SERVICES: plx_os::tv::Services = plx_os::tv::Services { identity: plx_os::tv::IdentityHooks { probe_device: plx_os::webos::probe, start_capability_probe: plx_os::webos::caps::start_probe, - repair_sandbox: plx_os::webos::jail_repair::execute, + repair_native_video: Some(plx_os::webos::jail_repair::execute), + device_files: plx_os::webos::DEVICE_FILES, system_locale: plx_os::webos::system_locale, sound_output: plx_os::webos::sound_output, }, diff --git a/rust-modules/telemetry/src/diag/schema.rs b/rust-modules/telemetry/src/diag/schema.rs index 0cf2e32f2..3b8b6cf20 100644 --- a/rust-modules/telemetry/src/diag/schema.rs +++ b/rust-modules/telemetry/src/diag/schema.rs @@ -316,7 +316,7 @@ pub struct UsageContext { #[serde(default, skip_serializing_if = "Option::is_none")] pub ip_version: Option, /// issue #74: the k5lp/k3lp `/dev/rtkmem` sandbox pre-flight — `ok` / `missing` / `n/a` — the - /// SAME closed enum [`plx_os::tv::sandbox::context`] reports, never a free-text probe result. + /// SAME closed enum [`plx_os::tv::native_video::context`] reports, never a free-text probe result. /// Present on every event so a chassis's crash-at-start rate is queryable by sandbox rather /// than only discoverable from a single reported issue. #[serde(default = "rtkmem_default")] @@ -397,14 +397,14 @@ impl UsageContext { Self { app_version: dimension(crate::telemetry::app_version()), webos_release: dimension(&os.release), - webos_api: dimension(&os.api), - webos_codename: dimension(&os.codename), + webos_api: dimension(&os.webos.api), + webos_codename: dimension(&os.webos.codename), device_model: dimension(&hw.model), soc: dimension(&hw.board), hardware_revision: dimension(&hw.hw_revision), server_connection: connection.map(|(c, _)| c.to_string()), ip_version: connection.map(|(_, ip)| ip.to_string()), - rtkmem: plx_os::tv::sandbox::context().into(), + rtkmem: plx_os::tv::native_video::context().into(), install: plx_base::paths::install_kind().into(), } } diff --git a/rust-modules/telemetry/src/telemetry/native.rs b/rust-modules/telemetry/src/telemetry/native.rs index b2df49ab4..766e1bda6 100644 --- a/rust-modules/telemetry/src/telemetry/native.rs +++ b/rust-modules/telemetry/src/telemetry/native.rs @@ -289,7 +289,7 @@ pub(super) const OS_FIELDS: &[&str] = &["type", "name", "version", "build", "ker /// `sentry::attach_hardware_context` builds, and [`preview_event`] leaves it out because a real /// native crash event does not carry it. pub(super) const WEBOS_FIELDS: &[&str] = &["type", "name", "release", "build", "codename", "api"]; -/// issue #74: `rtkmem` (`ok`/`missing`/`n/a`, from [`plx_os::tv::sandbox::context`]) and `install` +/// issue #74: `rtkmem` (`ok`/`missing`/`n/a`, from [`plx_os::tv::native_video::context`]) and `install` /// (`devmode`/`homebrew`/`unknown`, from [`plx_base::paths::install_kind`]) ride on every native /// crash report beside the existing hardware compatibility class — the same two closed-enum /// sandbox facts PostHog's usage envelope carries as super-properties (`telemetry::posthog`'s @@ -890,17 +890,17 @@ mod sdk { return; }; let webos = plx_os::tv::device::info(); - let webos_name = cstring(webos.name.as_bytes()); + let webos_name = cstring(webos.webos.name.as_bytes()); let webos_release = cstring(webos.release.as_bytes()); - let webos_codename = cstring(webos.codename.as_bytes()); - let webos_api = cstring(webos.api.as_bytes()); + let webos_codename = cstring(webos.webos.codename.as_bytes()); + let webos_api = cstring(webos.webos.api.as_bytes()); let hardware = plx_os::tv::device::device(); let model = cstring(hardware.model.as_bytes()); let soc = cstring(hardware.board.as_bytes()); let hardware_revision = cstring(hardware.hw_revision.as_bytes()); // issue #74: the same two closed-enum sandbox facts the PostHog envelope carries, so a // native crash report can be graded by chassis AND sandbox without a second dashboard. - let rtkmem = cstring(plx_os::tv::sandbox::context().as_bytes()); + let rtkmem = cstring(plx_os::tv::native_video::context().as_bytes()); let install = cstring(plx_base::paths::install_kind().as_bytes()); let ptr = |value: &Option| { value diff --git a/rust-modules/telemetry/src/telemetry/sentry.rs b/rust-modules/telemetry/src/telemetry/sentry.rs index 91b0d2e2c..d758b5405 100644 --- a/rust-modules/telemetry/src/telemetry/sentry.rs +++ b/rust-modules/telemetry/src/telemetry/sentry.rs @@ -545,13 +545,13 @@ pub fn attach_hardware_context(body: &mut serde_json::Value) { .or_insert_with(|| serde_json::json!({})); contexts["webos"] = serde_json::json!({ "type": "webos", - "name": webos.name, + "name": webos.webos.name, "release": webos.release, // The exact firmware build (nyx's `core_os_release`, e.g. `6.5.3-47`), which a patch within // one release changes and `release` does not: what a refusal is learned against. "build": webos.build, - "codename": webos.codename, - "api": webos.api, + "codename": webos.webos.codename, + "api": webos.webos.api, }); contexts["hardware"] = serde_json::json!({ "type": "hardware", @@ -562,7 +562,7 @@ pub fn attach_hardware_context(body: &mut serde_json::Value) { // two files (`/`, each `ok` / `no_keys` / `unreadable`, or // `unprobed`). Four fixed words, never free text. "probe": plx_os::tv::device::probe().code(), - "rtkmem": plx_os::tv::sandbox::context(), + "rtkmem": plx_os::tv::native_video::context(), "install": plx_base::paths::install_kind(), }); } From d36ff4ec922a5e851250fb3a4e30ae872d8222ef Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 12:33:52 +0300 Subject: [PATCH 4/5] Docs: L15c is done, and the Backend doc names its one shared reader The L15c row still said W3a to W3c were planned; #1477, #1478 and #1479 landed them, and the row beside it now says W3d has. The Backend doc said no shared code branches on a tag, but the legacy-migration decoder in plex::session::persistence compares the one spelling earlier builds wrote. Co-Authored-By: Claude --- docs/module-layers.md | 2 +- rust-modules/os/src/tv/secure.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/module-layers.md b/docs/module-layers.md index a02d169c2..31ac64876 100644 --- a/docs/module-layers.md +++ b/docs/module-layers.md @@ -332,7 +332,7 @@ proves the references are gone and nothing more; L15b is open. | **L14** session-layer presentation to screens — **done** | 2 / 4 | `auth::signed_in_reason` is a private fn of `screens::login`, its only caller, with its two tests; `auth` already handed over the plain account name. | | **L15** the webOS port — **gate-complete** | 44 / 205 | Everything outside `[platform webos]` reaches the television through the `tv` interfaces in `os` that the port fills at boot: `tv::{device, native_video, secure, home, toast}` (the window, the bus pump and the frame probe are `app::platform`'s `Shell` and `FrameProbe` since W2), `devcaps::dv`, and `tv::sink::VideoSink`, a Starfish-shaped verb trait that `plx_os::webos::video_sink::StarfishSink` and `plx_play_feed::ffi_host::HostSink` implement. `plex_run` is `port::plex_run`. The allowlist is empty. Not "done": the sink is not OS-neutral and the simulator is not its own port (L15b). | | **L15b** the OS-neutral port — **open** | — | An OS-neutral video sink with the ACB bind sequence behind it, the simulator as its own port, and the webOS facts the gate cannot see. See below. | -| **L15c** the platform value and the three contracts — **planned** | — | Wave R (the rename that gave this page `os` and `[platform webos]`) landed as #1474; W2 has landed (`tv::Port` became `tv::Services`, with four groups of hooks; the shell and the frame probes moved to `app::Platform`), and what is planned is W3a to W3c: who may persist credentials, what evidence admits a URI player, who ends the process. See "L15c to L15h" below. | +| **L15c** the platform value and the three contracts — **done** | — | Wave R (the rename that gave this page `os` and `[platform webos]`) landed as #1474; W2 landed (`tv::Port` became `tv::Services`, with four groups of hooks; the shell and the frame probes moved to `app::Platform`), and so did the three contracts, W3a to W3c: who may persist credentials (#1477), what evidence admits a URI player (#1478), who ends the process (#1479). See "L15c to L15h" below. | | **L15d** neutral types and the simulator as its own platform (L15b item 2) — **W3d landed, W4 planned** | — | W3d has landed (the opaque `Backend` tag, `sandbox` to `native_video`, identity publishes a platform name and version, `device::Info` keeps its webOS fields in `WebosDetail`, and `devcaps` reads its files through the platform), and what is planned is W4 (a second fence section, `[platform desktop]`, with its own value; the simulator's host arms leave `system` and `port`, the other `hostsim` terms of the fence go, and the simulator's stand-ins in `webos` and `keymanager` stay, compiled for tests and `test-support`: `docs/platform-ports.md`, W4). The desktop platform is the second implementation. | | **L15e** events, the shell and composition — **planned** | — | W5 (`HostEvent` with `Option`), W6b (platform-supplied composition in two boot phases), W6 (`plx_shell_sdl`, a `[shell_sdl]` layer) and W6c (a URI-only and a two-driver composition play an ordinary title). | | **L15f** extract the platform crates — **planned** | — | W7: a narrow public `host` module in the application crate, `rust-modules/platform-webos` and `platform-desktop` as crates above `app`, and the gate learning "a platform is a crate above `app`". After L15d, before L15g and L15h. | diff --git a/rust-modules/os/src/tv/secure.rs b/rust-modules/os/src/tv/secure.rs index c4712dd24..c35d0b966 100644 --- a/rust-modules/os/src/tv/secure.rs +++ b/rust-modules/os/src/tv/secure.rs @@ -10,7 +10,9 @@ use std::borrow::Cow; /// /// It is not a closed set. The tag is the only thing in the stored envelope that says which /// platform's store can open it, and a platform names its own in its own code ([`Backend::new`]); -/// no shared code branches on one. A tag that no installed platform knows is REFUSED when the +/// no shared code branches on one, but the legacy-migration decoder +/// (`plex::session::persistence::decode_legacy_at_depth`), which accepts only `keymanager3` from +/// the files earlier builds wrote. A tag that no installed platform knows is REFUSED when the /// envelope is opened (the platform's `open` answers `None`, the session layer reports the file /// locked) and is never read as another store's: the stored text is not ours to reinterpret. /// From 3e128d0152bdfc87f545fc7ea1cfe1c8c1d6f6c8 Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 13:07:40 +0300 Subject: [PATCH 5/5] Platform plan: the identity hooks list matches the code W3d landed Target shape 1 still listed repair_sandbox in the identity group. After W3d the group carries repair_native_video, an optional hook, and device_files, the reader devcaps parses through, as tv.rs's IdentityHooks does. Co-Authored-By: Claude --- docs/platform-ports.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/platform-ports.md b/docs/platform-ports.md index c516f7c55..45f9329ff 100644 --- a/docs/platform-ports.md +++ b/docs/platform-ports.md @@ -842,7 +842,10 @@ split by who reads it (critic M4): 1. `tv::Services` (`plx_os::tv`, installed once by `run_application`) holds what LOWER layers read through the private `tv::port()` (F5): - - `identity { probe_device, start_capability_probe, repair_sandbox, system_locale, sound_output }`; + - `identity { probe_device, start_capability_probe, repair_native_video: Option Result<(), Failure>>, + device_files: Files, system_locale, sound_output }` (`repair_native_video` is optional: `None` is a platform + with nothing to repair, and the repair then answers `Failure::Unsupported`; `device_files` is the reader + `devcaps` parses through, `Files::NONE` for a platform with none); - `secure { seal, open, remove, mode }` (Target shape 4; until W2 `mode` is W3a's own once-set value); - `system { go_home, poll_home, deliver_toast }`; - `legacy_webos_media { sink, display_sink, uri_media }`: the Starfish, ACB and `com.webos.media` verbs (F31),