Repository Public License
1<!--2ORIX Secure3File: docs/architecture/diagnostics.md4Description: Device snapshot fields and their API sources, platform limits, battery and performance advice rules,5 and what the app deliberately does not offer.6Author: Simon-Pierre Boucher7Contact: contact@spboucher.ai8-->910# ORIX Secure — Device diagnostics1112Sources: `Packages/ORIXSecureEngines/Sources/ORIXSecureEngines/` — `DeviceSnapshot.swift`,13`SystemDeviceProbe.swift`, `DeviceDiagnosticsEngine.swift`; screens `App/Sources/Features/DeviceDiagnostics/DeviceView.swift`14and `App/Sources/Features/Battery/BatteryView.swift`; report in `App/Sources/Core/ReportBuilders.swift`.1516## 1. Flow1718```mermaid19flowchart TD20 subgraph APIs["Public APIs"]21 A1["uname(3)"]22 A2["ProcessInfo"]23 A3["UIDevice"]24 A4["UIScreen of the first UIWindowScene"]25 A5["URL.resourceValues (volume keys)"]26 A6["sysctl kern.boottime"]27 A7["os_proc_available_memory()"]28 A8["task_info(TASK_VM_INFO)"]29 end30 A1 --> P31 A2 --> P32 A3 --> P33 A4 --> P34 A5 --> P35 A6 --> P36 A7 --> P37 A8 --> P38 P["SystemDeviceProbe.snapshot()<br/>@MainActor"] --> S["DeviceSnapshot<br/>plain values and Reading fields"]39 S --> D["DeviceDiagnosticsEngine.diagnostics(_:)"]40 S --> F["DeviceDiagnosticsEngine.findings(_:)"]41 S --> ADV["DeviceDiagnosticsEngine.advice(_:)"]42 L["PlatformLimits.deviceMeasurements"] --> D43 D --> DD["DeviceDiagnostics<br/>5 sections of DiagnosticRow,<br/>findings, unavailable"]44 F --> DD45 DD --> V1["DeviceView"]46 ADV --> V2["BatteryView"]47 NO["DeviceDiagnosticsEngine.notOffered"] --> V248 DD --> R["ReportBuilder.device(_:advice:)<br/>ReportDocument kind .device"]49 ADV --> R50 F --> RA["AppModel.recommendedActions<br/>attention findings only"]51 S --> SEC["SecurityAssessmentEngine<br/>os.outdated, restart"]52 S --> STO["StorageAnalysisEngine.overview(volume:)"]53```5455The snapshot is taken in `AppModel.init` and on every `AppModel.refresh()` (scene becomes active, or an56explicit refresh). Nothing is sampled in the background and no history of readings is kept.5758## 2. `DeviceSnapshot` fields5960| Field | Type | API source | Notes |61|---|---|---|---|62| `modelIdentifier` | `String` | `uname(3)` `machine`; in the Simulator, environment variable `SIMULATOR_MODEL_IDENTIFIER` | `"unknown"` if `uname` fails. |63| `modelFamily` | `String` | `UIDevice.current.model` | `"Mac"` when UIKit is absent. |64| `idiom` | `DeviceIdiom` | `UIDevice.current.userInterfaceIdiom` | `phone`, `pad`, `mac`, `vision`, `other`. |65| `isSimulator` | `Bool` | `SIMULATOR_MODEL_IDENTIFIER != nil` | Drives the simulator notes and probe short-cuts. |66| `systemName` | `String` | `UIDevice.current.systemName` | |67| `systemVersion`, `systemMajorVersion` | `String`, `Int` | `ProcessInfo.operatingSystemVersion` | Patch component omitted when 0. |68| `builtAgainstSDKVersion` | `String?` | `Bundle.main` Info.plist key `DTPlatformVersion` | Dated reference for `device.os.outdated`. |69| `screen` | `Reading<ScreenInfo>` | `UIScreen.bounds`, `nativeBounds`, `scale`, `maximumFramesPerSecond` | `.failed` when no window scene is connected. |70| `processorCount`, `activeProcessorCount` | `Int` | `ProcessInfo.processorCount`, `activeProcessorCount` | |71| `physicalMemory` | `Int64` | `ProcessInfo.physicalMemory` | Installed memory. |72| `appAvailableMemory` | `Reading<Int64>` | `os_proc_available_memory()` | What this app may still allocate; not device free memory. `.failed` when it returns 0. |73| `appMemoryFootprint` | `Reading<Int64>` | `task_info(mach_task_self_, TASK_VM_INFO)` → `phys_footprint` | This app only. |74| `thermal` | `ThermalLevel` | `ProcessInfo.thermalState` | `nominal`, `fair`, `serious`, `critical`; unknown future cases map to `nominal`. |75| `lowPowerMode` | `Bool` | `ProcessInfo.isLowPowerModeEnabled` | |76| `batteryLevel` | `Reading<Double>` | `UIDevice.batteryLevel` | 0…1. Negative values give `.failed`; `.simulator` in the Simulator. |77| `batteryState` | `Reading<BatteryChargeState>` | `UIDevice.batteryState` | `unplugged`, `charging`, `full`; `.unknown` gives `.failed`. |78| `volume` | `VolumeCapacity` | `URLResourceKey` values of the home directory | Four readings, see [storage.md](storage.md). |79| `lastBoot` | `Reading<Date>` | `sysctl(CTL_KERN, KERN_BOOTTIME)` | Declared in the privacy manifest (`SystemBootTime`, reason `35F9.1`). |80| `capturedAt` | `Date` | — | Used as `assessedAt` of the diagnostic findings. |8182Battery monitoring: the probe sets `UIDevice.isBatteryMonitoringEnabled = true`, reads level and state, and83restores the previous value if monitoring was off. It does not subscribe to battery notifications.8485Non-iOS builds (package tests on macOS) leave `screen`, `batteryLevel` and `batteryState` at86`.unavailable(.unsupportedOnDevice, …)`.8788## 3. Diagnostic sections8990`DeviceDiagnosticsEngine.diagnostics(_:)` returns five `DiagnosticSection`s. Each `DiagnosticRow` has a91`Reading<String>` value, an optional note and the technical `source` string shown in the UI.9293| Section id | Rows (id → label) |94|---|---|95| `identity` | `model` Model identifier, `family` Model family, `os` System, `boot` Last restart |96| `display` | `points` Size in points, `pixels` Native resolution, `scale` Scale, `fps` Maximum refresh rate |97| `processing` | `cores` Processor cores, `activeCores` Active cores, `ram` Installed memory, `appMemory` Memory used by ORIX Secure, `appAvailable` Memory ORIX Secure may still use |98| `power` | `battery` Battery level, `charging` Power state, `lowPower` Low Power Mode, `thermal` Thermal state |99| `storage` | `capacity` Capacity, `available` Available (`bestAvailable`), `free` Free on the file system |100101Rows built from a `Reading` use `Reading.map`, so an unavailable reading stays unavailable in the row and the102UI shows the reason. In a report, `ReportBuilder.device` writes such a row as "Not available — <detail>".103In the Simulator the `model` row carries the note that hardware readings describe the simulated device or104the host Mac, and the report's device facts add an "Environment: Simulator" line.105106## 4. Diagnostic findings107108`DeviceDiagnosticsEngine.findings(_:)` — all `category: .performance`, `confidence: .measured`,109`verification: .publicAPI`.110111| Finding id | Condition | State | Severity |112|---|---|---|---|113| `device.thermal` | `thermal` is `nominal` or `fair` | `verified` | `none` |114| `device.thermal` | `thermal` is `serious` | `attention` | `low` |115| `device.thermal` | `thermal` is `critical` | `attention` | `moderate` |116| `device.cores` | `activeProcessorCount < processorCount` | `attention` | `low` |117| `device.lowPower` | `lowPowerMode` is true | `verified` (informational) | `none` |118119`device.thermal` always exists; the other two appear only when their condition holds. The thermal finding's120`notInspected` states that this is a four-level state, not a temperature. `AppModel.recommendedActions`121merges the `attention` ones with the security, privacy and storage actions.122123## 5. `PlatformLimits.deviceMeasurements`124125Nine `UnavailableMeasurement` entries, shown as they are and never replaced by an estimate. They are attached126to every `DeviceDiagnostics.unavailable`, listed in `CapabilitiesView` (Settings › "What ORIX Secure can and127cannot do") and written to the `unavailable` list of the device report.128129| id | Title | Reason given | Where the user can see it |130|---|---|---|---|131| `battery.cycles` | Battery cycle count | No public API | Settings › Battery › Battery Health |132| `battery.capacity` | Battery maximum capacity | No public API for battery health | Settings › Battery › Battery Health |133| `battery.perapp` | Battery use by other apps | An app observes its own energy use only | Settings › Battery |134| `cpu.temperature` | Processor temperature | iOS reports a four-level thermal state, not degrees | — |135| `cpu.system` | System-wide processor use | An app measures its own processor time only | — |136| `memory.others` | Memory used by other apps | The sandbox hides other processes | — |137| `hardware.faults` | Hardware fault and repair history | Belongs to Apple's service tools | Settings › General › About › Parts & Service History |138| `kernel` | Kernel and system process state | Not inspectable by apps | — |139| `storage.categories` | Storage used by each app and category | iOS gives volume capacity and the app's own files only | Settings › General › iPhone Storage |140141`StorageAnalysisEngine.overview` reuses the `storage.categories` entry as `StorageOverview.notExposed`.142143## 6. Battery and performance advice144145`DeviceDiagnosticsEngine.advice(_:)` returns `Advice` values of three kinds: `observation` (derived from a146reading taken now, with the reading in `basis`), `userCheck` (something only the user can look at) and147`guidance` (general, independent of readings).148149Observation rules, evaluated in this order:150151| Advice id | Condition |152|---|---|153| `battery.low` | `batteryLevel ≤ 0.2` and `batteryState == .unplugged` and Low Power Mode off |154| `battery.full` | `batteryLevel ≥ 0.95` and `batteryState` is `.charging` or `.full` |155| `thermal.hot` | `thermal` is `serious` or `critical` |156| `thermal.charging` | `thermal != .nominal` and `batteryState == .charging` |157| `lowPower.on` | `lowPowerMode` is true |158| `storage.pressure` | `volume.usedFraction > 0.9` and `bestAvailable` is measured |159160The two battery rules require a measured `batteryLevel`; when the level is unavailable (Simulator, macOS)161neither fires. `thermal.charging` likewise needs a measured charging state.162163Always appended, with an empty `basis`:164165| Advice id | Kind | Subject |166|---|---|---|167| `check.health` | `userCheck` | Settings › Battery › Battery Health (maximum capacity, cycle count; the text states iOS does not give these to apps) |168| `check.usage` | `userCheck` | Settings › Battery per-app list and Background App Refresh |169| `guide.forceclose` | `guidance` | Closing apps does not save battery |170| `guide.update` | `guidance` | Higher battery use for a day or two after an iOS update is normal |171172The engine never infers battery health from the level or the thermal state.173174## 7. Deliberately not offered175176`DeviceDiagnosticsEngine.notOffered` (rendered in `BatteryView`, accessibility id `battery.notOffered`):1771781. No "RAM boost": an app cannot free other apps' memory, and iOS manages memory itself.1792. No battery "repair" or "calibration": software cannot restore a worn battery's capacity.1803. No force-closing of other apps and no override of iOS power management.1814. No system cache cleaning: an app can delete its own files only.182183Consistent with this, the codebase contains no benchmark, no CPU load generator, no continuous battery184sampling and no background task registration.185186## 8. Relation to other engines187188- `SecurityAssessmentEngine` consumes `systemMajorVersion`, `builtAgainstSDKVersion`, `lastBoot`,189 `isSimulator` ([security-engine.md](security-engine.md)).190- `StorageAnalysisEngine` consumes `volume` ([storage.md](storage.md)).191- `InvestigationEngine` reads thermal state, Low Power Mode, battery, last restart and storage as192 observations for the `batteryDrain`, `crashes` and `storageAnomaly` symptoms, and derives two conditions193 from the snapshot: "hot" (`serious` or `critical`) and "low storage" (`usedFraction > 0.95`).194195## 9. Verification status196197- `DeviceStoragePrivacyTests` runs the engine against fixed snapshots (sections, thermal and core findings,198 advice grounded in readings) and runs `SystemDeviceProbe` on the test Mac199 (`systemProbeReturnsRealValuesOnThisMac`).200- In the iOS Simulator `batteryLevel` and `batteryState` are `.unavailable(.simulator)`, so the battery rows,201 the `battery.low` / `battery.full` / `thermal.charging` advice and the real `UIDevice` battery path have202 not been observed with device values. Thermal states other than `nominal`, reduced `activeProcessorCount`203 and the 5 % battery granularity stated in the UI note are likewise unobserved on hardware.204- `os_proc_available_memory()` and `kern.boottime` were read in the Simulator, where they describe the host205 environment.206- The tests were not re-run while writing this document.207