feat(storage): 新增只读 SMART 辅助服务与寿命通电详情
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import Foundation
|
||||
|
||||
nonisolated enum DiskSMARTReader {
|
||||
static func readReport() async -> DiskHealthMetrics? {
|
||||
await withCheckedContinuation { continuation in
|
||||
DispatchQueue.global(qos: .utility).async {
|
||||
guard let values = try? URL(fileURLWithPath: NSHomeDirectory()).resourceValues(forKeys: [.volumeURLKey]),
|
||||
let volume = values.volume else { continuation.resume(returning: nil); return }
|
||||
let process = Process()
|
||||
process.executableURL = URL(fileURLWithPath: "/usr/sbin/diskutil")
|
||||
process.arguments = ["info", "-plist", volume.path]
|
||||
let pipe = Pipe()
|
||||
process.standardOutput = pipe
|
||||
process.standardError = FileHandle.nullDevice
|
||||
do { try process.run() }
|
||||
catch { continuation.resume(returning: nil); return }
|
||||
let deadline = DispatchWorkItem { if process.isRunning { process.terminate() } }
|
||||
DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + 10, execute: deadline)
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
process.waitUntilExit()
|
||||
deadline.cancel()
|
||||
continuation.resume(returning: process.terminationStatus == 0 && data.count <= 262_144 ? DiskHealthReport.parse(data) : nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0"><dict>
|
||||
<key>CFBundleDevelopmentRegion</key><string>en</string>
|
||||
<key>CFBundleExecutable</key><string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key><string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key><string>6.0</string>
|
||||
<key>CFBundleName</key><string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key><string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key><string>1.0</string>
|
||||
<key>CFBundleVersion</key><string>1</string>
|
||||
<key>XPCService</key><dict><key>ServiceType</key><string>Application</string></dict>
|
||||
</dict></plist>
|
||||
@@ -0,0 +1,32 @@
|
||||
import Foundation
|
||||
|
||||
final class SMARTService: NSObject, SMARTServiceProtocol {
|
||||
func readSMART(withReply reply: @escaping (NSNumber?, NSNumber?) -> Void) {
|
||||
Task {
|
||||
let result = await DiskSMARTReader.readReport()
|
||||
reply(result?.remainingLife.map(NSNumber.init(value:)), result?.powerOnHours.map(NSNumber.init(value:)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class ServiceDelegate: NSObject, NSXPCListenerDelegate {
|
||||
// Bind the peer to the containing app's actual designated signature, including ad-hoc builds.
|
||||
private let requirement: String? = {
|
||||
let host = Bundle.main.bundleURL.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()
|
||||
return CodeIdentity.requirement(at: host)
|
||||
}()
|
||||
|
||||
func listener(_ listener: NSXPCListener, shouldAcceptNewConnection connection: NSXPCConnection) -> Bool {
|
||||
guard connection.effectiveUserIdentifier == getuid(), let requirement else { return false }
|
||||
connection.setCodeSigningRequirement(requirement)
|
||||
connection.exportedInterface = NSXPCInterface(with: SMARTServiceProtocol.self)
|
||||
connection.exportedObject = SMARTService()
|
||||
connection.resume()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
let delegate = ServiceDelegate()
|
||||
let listener = NSXPCListener.service()
|
||||
listener.delegate = delegate
|
||||
listener.resume()
|
||||
@@ -25,3 +25,5 @@
|
||||
|
||||
- [C 阶段实施与验证](stage-c-plan.md)
|
||||
- [B 阶段专项验证留档](stage-b-followups.md)
|
||||
|
||||
- [磁盘 SMART 只读辅助服务实施方案](disk-smart-helper-plan.md)
|
||||
|
||||
@@ -129,3 +129,13 @@ SystemSampler actor 统一持有 NetworkMonitor 基线,每轮串行调用网
|
||||
### 系统报告健康度(替代原始容量比)
|
||||
|
||||
按用户要求,SystemBatteryHealthMonitor actor 读取系统报告的 maximum-capacity 百分比,不再使用原始容量除法。统一采样器仅在检测到内置电池时调用;首次及缓存到期时等待 utility queue 上的 system_profiler 报告,成功缓存一小时,失败缓存十分钟,并发复用同一任务。没有独立 Timer、不新增权限;运行命令限制 SPPowerDataType、JSON、mini 和超时,仅读取百分比,报告不持久化。失败为 nil,界面 --。Core 电池基础状态/时间/循环仍由 IOKit 采样器读取。视图删除容量算法说明,健康字段标题使用系统报告「最大容量」。
|
||||
|
||||
### 磁盘 SMART 展示与访问边界
|
||||
|
||||
DiskHealthMetrics 为 Core 模型,DiskHealthMonitor actor 由 SystemSampler 调用,缓存一小时(失败十分钟),通过 SMARTServiceClient 连接随应用嵌入的 SMARTService.xpc。直接沙盒查询返回空字典的问题已改由用户授权的独立非沙盒服务解决。只保留预计剩余寿命与通电小时;未读取/不支持为 --,多物理设备卷不合成单值。
|
||||
|
||||
SMARTService/ 是独立 Target,不属于 kymo/ 的同步源码目录。共享最小协议 SMARTServiceProtocol、CodeIdentity、DiskHealthMetrics、纯解析 DiskHealthReport;不依赖 Features/UI。主应用继续 App Sandbox,XPC 服务以当前用户权限按需启动、非沙盒,无 root、LaunchAgent 或开机项。固定查询用户目录所属卷挂载点的 diskutil info -plist,不接受来自客户端的路径、命令或可写操作,只返回 NSNumber 形式的寿命/小时,不返回完整报告。
|
||||
|
||||
连接两侧设置代码签名要求:客户端由嵌入服务的 designated requirement 校验服务;服务由宿主应用的 designated requirement 校验调用方,且 uid 必须相同。无法取得要求时拒绝服务;支持本地 ad-hoc Debug 签名,不使用标识字符串白名单代替签名。客户端在回复/中断/错误/15 秒超时竞争时用锁保证 continuation 只恢复一次,失效后释放连接;服务内部查询十秒终止。无额外轮询 Timer。Xcode 构建依赖与 Embed XPC Services 阶段负责先构建、签名并嵌入服务。
|
||||
|
||||
此非沙盒服务只覆盖当前独立分发路径,不符合 Mac App Store 全组件沙盒要求,商店分发需另行设计。GPU 不接入本服务;当前 IOReport 订阅失败尚未证明与 SMART 同因。
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# 磁盘 SMART 只读辅助服务实施方案
|
||||
|
||||
## 背景与目标
|
||||
|
||||
用户授权增加辅助进程读取磁盘寿命及通电时间。已确认普通终端 diskutil 可读,沙盒子进程返回空 SMART 字典;GPU 仅确认 IOReport 订阅失败,原因未确定,不视为同一根因,也不纳入本轮辅助服务功能。
|
||||
|
||||
## 设计与范围
|
||||
|
||||
采用随应用嵌入的按需 XPC 服务(Contents/XPCServices),主应用保留 App Sandbox;服务独立、非沙盒、当前用户权限,不使用 root、不注册开机项、不安装 LaunchAgent。服务只支持读取预定义主卷 SMART 指标,不接受路径、命令或任意参数;固定 diskutil info -plist 查询,不写磁盘、不访问网络。只返回两个数值,不传完整系统报告或序列号。连接必须验证调用方代码签名;服务自身失败时主应用降级 --。
|
||||
|
||||
Core 新增 XPC 协议/客户端,沿用 DiskHealthMonitor 一小时成功缓存/十分钟失败缓存。辅助 Target 独立于 kymo/ 同步目录,避免入口与资源污染主 Target;共享最小协议/模型/解析源码由工程明确加入辅助 Target。App 仍只负责场景装配,Features/UI 仅展示。
|
||||
|
||||
## 分步实施
|
||||
|
||||
1. 完成两项展示、SMART 边界解析及沙盒失败留档。
|
||||
2. 添加独立 XPC Target、严格固定读接口、调用方签名验证、主应用连接超时/失效处理与工程嵌入签名。
|
||||
3. Debug 构建、解析/采样回归、带原有沙盒签名的主应用端到端验证;核对辅助进程无 root、主应用沙盒不变、进程按需生命周期及失败降级。
|
||||
4. 更新架构、监控方案及验证文档,精确提交,不自动推送。
|
||||
|
||||
## 风险与兼容性
|
||||
|
||||
非沙盒 XPC 服务不适用于 Mac App Store 的全组件沙盒分发要求;当前仅本地/独立分发路径,不宣称已满足发布签名、公证或商店审核。硬盘型号、桥接设备和系统版本可能缺失 SMART 字段,多物理存储不合成寿命。缓存跨暂停保留;辅助请求不额外定时轮询。不得为 GPU 或其他指标扩大辅助接口;如以后需要另行评估。
|
||||
|
||||
|
||||
## 实施结果(2026-10-30)
|
||||
|
||||
用户确认「可以增加辅助进程」。已完成步骤 1–3:独立 SMARTService Target 及嵌入、双向 designated requirement 签名要求和同 uid 验证、固定只读查询、缓存及客户端超时/失效降级。主应用仍为沙盒,服务为当前用户(本机 uid 501)非 root、非沙盒进程,没有注册常驻服务。
|
||||
|
||||
Debug 与 Release 构建通过,嵌套签名严格校验通过。Debug 实际端到端十个样本均读到剩余寿命 98%、通电 1121 小时;普通终端对应消耗 2%、通电 1121 小时。去除服务的独立测试应用重新签名后仍持续采样 CPU/内存,SMART 为未知,验证缺服务降级。SMART 边界检查与 SamplingChecks 通过;CodeIdentityChecks 验证宿主/服务自身要求通过、对方身份要求拒绝及代码缺失。原生 UI 按测试副本路径读取仍超时,新增两行布局未自动验收。
|
||||
|
||||
只清理本轮测试应用和辅助进程,未向用户原有 Xcode 进程发送退出命令。Release 构建通过不代表发布身份签名、公证或 App Store 验收。辅助只读接口不扩展到 GPU;当前原因未核实。
|
||||
|
||||
最终 Release 签名应用也完成四次端到端采样,均为 98% / 1121 小时。长期资源预算需要包含辅助进程,短时样本不证明能耗/内存达标。
|
||||
@@ -351,3 +351,5 @@ Debug 构建、语言匹配/回退/持久化/实际资源查词及呈现回归
|
||||
B 未验证专项按用户指示单独留档于 stage-b-followups.md,不阻塞 C。C 基础实现后,本轮补网络 64 位接口计数、系统路径状态、存储卷列表与块设备 IO、电池循环/估算健康度/系统时间预估及三项趋势。详细设计、并发边界、验证结果和专项见 stage-c-plan.md 与 architecture.md。
|
||||
|
||||
本机签名沙盒应用采样已验证;构建与独立核心/趋势检查通过。UI 工具读取测试副本超时,因此扩展布局、真实断网/热插拔、充放电和无电池机型仍待验收,不标记 C 全阶段通过。不修改系统网络、电源或权限设置,不退出用户 Xcode 应用。
|
||||
|
||||
C 增量按用户授权新增嵌入式只读 SMART XPC 服务,主程序保留沙盒;独立分发与商店兼容性、模块及验证边界见 [disk-smart-helper-plan.md](disk-smart-helper-plan.md)。
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
| 内存 | 已用/可用、各分类(wired / compressed / app)、内存压力、Swap | P0 | A 阶段首批已实现,运行验收中 |
|
||||
| 网络 | 每接口上下行速率、累计流量、连接状态 | P1 | C 网络路径/64 位差分及存储卷/块设备 IO 已实现,专项验收中 |
|
||||
| 磁盘 | 各卷容量占用、读写速率 | P1 | C 网络路径/64 位差分及存储卷/块设备 IO 已实现,专项验收中 |
|
||||
| 磁盘寿命 | NVMe 预计剩余寿命、通电时间 | P1 | 只读 XPC 已实现,本机沙盒主应用读取通过,其他设备待验证 |
|
||||
| 电池 | 电量、充放电状态、循环次数、系统报告最大容量 | P2 | C 电源/时间/循环/系统报告最大容量已实现,专项验收中 |
|
||||
| 传感器 | CPU/GPU 温度、风扇转速 | P2(v0.4) | 规划中(SMC,失败降级隐藏) |
|
||||
| GPU | 利用率、显存 | P0(菜单栏默认指标,v0.2) | 本机 IOReport 订阅返回空,暂降级不可用 |
|
||||
@@ -49,3 +50,6 @@
|
||||
- 差分类指标(CPU、网络、磁盘 IO)采样器内部持有上一次快照,自行做差分;
|
||||
- 菜单栏设计默认展示 CPU + GPU + 内存;当前 GPU 订阅不可用,降级为 CPU + 内存;
|
||||
- 采样间隔可配置(1–10s),设置中提供「暂停监控」开关。
|
||||
|
||||
|
||||
磁盘寿命通过用户授权的嵌入式非沙盒 XPC 服务低频读取 `diskutil info -plist`,主应用保留沙盒。NVMe 寿命消耗字段换算预计剩余寿命,通电小时读取 128 位计数的可表示部分;高位非零不截断展示。SMART 数据是物理设备级,多个 APFS 卷不重复合算,缺失/多物理存储显示 --。服务固定只读查询,无管理员权限或系统开机项,详见 disk-smart-helper-plan.md。
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ B 阶段功能代码及本机主要交互/当前场景视觉验收已完成(
|
||||
- [ ] 底部品牌标识与操作区(暂停 / 设置 / 退出)
|
||||
- [x] 外观三选项与强调色(本机切换、自选配色联动及重启保存已验收;全组合视觉验收仍保留)
|
||||
- [x] 三语 String Catalog 接入(zh-Hans / zh-Hant / en;应用内切换、详情同步与重启保留已获用户验收,独立窗口三语深浅色走查通过)
|
||||
- [ ] 网络与存储监控(采样/详情/趋势已实现,本机网络开关与滚动通过,其余多接口/磁盘热插拔专项待验收)
|
||||
- [ ] 网络与存储监控(采样/详情/趋势已实现,本机网络开关与滚动通过,SMART 寿命/通电时间已接入只读辅助服务,其余多接口/磁盘热插拔专项待验收)
|
||||
- [ ] 电池监控(状态/时间/循环/系统最大容量已实现,本机电源热插拔通过,放电时间与多机型待验收)
|
||||
|
||||
## v0.4 设置与权限
|
||||
|
||||
@@ -56,3 +56,24 @@ Debug 构建、StageCChecks 与 SamplingChecks 回归通过;新增充放电/
|
||||
新增 SystemBatteryHealthMonitor actor:成功缓存一小时、失败十分钟后重试,并发读取共用在途任务;由统一采样器按需调用,无额外轮询 Timer。进程与管道等待放到 utility queue,不阻塞 MainActor 或协作执行器;命令内部超时 5 秒,10 秒仍运行发送终止。完整报告只在内存解析、不写日志或持久化,最终保留一个健康度数值。读取失败显示 --,不扩大权限。
|
||||
|
||||
验证:Debug 构建通过;保留测试前已有 Xcode 进程 PID 23343,不对其发送退出命令。仅启动临时构建副本,签名沙盒保持开启,诊断连续四次采样 batteryHealth=1(100%),与同机 system_profiler 和用户截图一致;测试副本自行清理。StageCChecks 检查 100%/83%/越界/缺失/错误 JSON,SamplingChecks 回归暂停恢复;说明已从视图与资源中删除。最终文字仍待用户重新运行查看,不声称 UI 自动验收。
|
||||
|
||||
## 第五轮:磁盘寿命与通电时间(2026-10-30)
|
||||
|
||||
按用户要求在主卷存储详情新增「预计剩余寿命」「通电时间」,三语一致。磁盘归属先由用户目录的 volumeURL 解析挂载点,再读取 diskutil info -plist;不能直接把用户目录路径传入 diskutil。SMART 是物理设备数据,不按 APFS 各卷重复展示。
|
||||
|
||||
新增 DiskHealthMonitor actor 与 DiskHealthMetrics。寿命按 NVMe PERCENTAGE_USED 换算 max(0,100-used);通电时间读取 POWER_ON_HOURS_0,128 位高位非零时不截断显示。拒绝负数、布尔、无效消耗值,多物理存储卷不合成为单盘寿命。结果成功缓存一小时、失败十分钟;并发复用一次查询,IO 在 utility queue 上等待,十秒未结束发终止,不新增轮询 Timer、依赖或权限。完整报告不持久化,显式诊断仅写出最终两个值。
|
||||
|
||||
关键限制:本机普通终端可读消耗 2%、通电 1121 小时;带原签名沙盒的应用测试副本执行 diskutil 成功(状态 0),但 SMARTDeviceSpecificKeysMayVaryNotGuaranteed 是空字典,两个数值均缺失。挂载点、物理存储数量和原始字段名逐项核对后仍成立,判定为本轮沙盒路径受限,不能用终端结果冒充应用可读。界面显示 --;未关闭沙盒、未添加 entitlement、未安装辅助进程。
|
||||
|
||||
已向用户说明需要另行评估独立非沙盒读取辅助进程,并请求确定是否扩展此范围;未获得答复前不实施辅助进程。当前完成展示、解析边界与安全降级,不宣称实值读取完成。
|
||||
|
||||
Debug 构建通过;DiskHealthChecks 覆盖正常数据、寿命超 100%、缺失/负值/布尔/异常计数、通电高位溢出及多物理存储、空 SMART 字典;SamplingChecks 回归通过。已有 Xcode 进程 PID 24267 未退出,仅清理本轮 /private/tmp 测试副本。小时三语插值实际键核对为 disk.hours %llu;新增两项实际布局仍待用户运行验收。
|
||||
|
||||
|
||||
## 第六轮:用户授权的 SMART XPC 服务(2026-10-30)
|
||||
|
||||
用户确认可增加辅助进程,并询问 GPU 是否同因。GPU 只有 IOReport 订阅失败证据,不能与已确认的 SMART 沙盒空字典等同。按 docs/disk-smart-helper-plan.md 实施嵌入式只读 XPC 服务,主应用保留沙盒,不安装常驻服务或使用 root。
|
||||
|
||||
本轮取代第五轮「等待授权/实际数值不可用」边界:Debug 端到端连续十次读到剩余寿命 98%、通电 1121 小时,主程序 entitlements app-sandbox=true,服务无 app-sandbox、运行 uid 501;两项归属用户目录所在卷的物理设备。服务缺失测试保持 CPU/内存采样、SMART 未知。Debug/Release 构建、严格嵌套签名校验、SMART 解析边界与采样回归通过。原生 UI getApp(测试副本路径) 仍超时,不声称新增两行布局已自动验收。辅助服务按需生命周期随本轮应用结束已清理,未更改用户系统网络/电源/登录项。
|
||||
|
||||
最终 Release 端到端四次采样均读到 98% / 1121 小时;签名身份检查覆盖各自合法与对方身份拒绝。临时测试文件及构建产物清理,长期资源预算仍需计入新增辅助进程。
|
||||
|
||||
+102
-14
@@ -6,28 +6,55 @@
|
||||
objectVersion = 110;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
BB000000000000000000001E /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB000000000000000000000A; };
|
||||
BB000000000000000000001F /* DiskSMARTReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB000000000000000000000B; };
|
||||
BB0000000000000000000020 /* SMARTServiceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB000000000000000000000C; };
|
||||
BB0000000000000000000021 /* CodeIdentity.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB000000000000000000000D; };
|
||||
BB0000000000000000000022 /* DiskHealthMetrics.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB000000000000000000000E; };
|
||||
BB0000000000000000000023 /* DiskHealthReport.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB000000000000000000000F; };
|
||||
BB0000000000000000000024 /* SMARTService.xpc in Embed XPC Services */ = {isa = PBXBuildFile; fileRef = BB0000000000000000000002; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
BB0000000000000000000004 /* Embed XPC Services */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = Contents/XPCServices;
|
||||
dstSubfolderSpec = 1;
|
||||
files = (BB0000000000000000000024, );
|
||||
name = "Embed XPC Services";
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
BB0000000000000000000008 = {isa = PBXContainerItemProxy; containerPortal = D9E51E6B309338B0000608DE; proxyType = 1; remoteGlobalIDString = BB0000000000000000000001; remoteInfo = SMARTService; };
|
||||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXTargetDependency section */
|
||||
BB0000000000000000000009 = {isa = PBXTargetDependency; target = BB0000000000000000000001; targetProxy = BB0000000000000000000008; };
|
||||
/* End PBXTargetDependency section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
D9E51E73309338B0000608DE /* kymo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = kymo.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
BB000000000000000000000A /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = main.swift; path = SMARTService/main.swift; sourceTree = SOURCE_ROOT; };
|
||||
BB000000000000000000000B /* DiskSMARTReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = DiskSMARTReader.swift; path = SMARTService/DiskSMARTReader.swift; sourceTree = SOURCE_ROOT; };
|
||||
BB000000000000000000000C /* SMARTServiceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SMARTServiceProtocol.swift; path = kymo/Core/Services/SMARTServiceProtocol.swift; sourceTree = SOURCE_ROOT; };
|
||||
BB000000000000000000000D /* CodeIdentity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CodeIdentity.swift; path = kymo/Core/Services/CodeIdentity.swift; sourceTree = SOURCE_ROOT; };
|
||||
BB000000000000000000000E /* DiskHealthMetrics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = DiskHealthMetrics.swift; path = kymo/Core/Models/DiskHealthMetrics.swift; sourceTree = SOURCE_ROOT; };
|
||||
BB000000000000000000000F /* DiskHealthReport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = DiskHealthReport.swift; path = kymo/Core/Monitors/DiskHealthReport.swift; sourceTree = SOURCE_ROOT; };
|
||||
BB0000000000000000000002 /* SMARTService.xpc */ = {isa = PBXFileReference; explicitFileType = "wrapper.xpc-service"; includeInIndex = 0; path = SMARTService.xpc; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
BB0000000000000000000016 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = SMARTService/Info.plist; sourceTree = SOURCE_ROOT; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFileSystemSynchronizedRootGroup section */
|
||||
D9E51E75309338B0000608DE /* kymo */ = {
|
||||
isa = PBXFileSystemSynchronizedRootGroup;
|
||||
exceptions = (
|
||||
AA00000000000000000000A1 /* Exceptions for "kymo" folder in "kymo" target */,
|
||||
);
|
||||
path = kymo;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXFileSystemSynchronizedRootGroup section */
|
||||
|
||||
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
|
||||
AA00000000000000000000A1 /* Exceptions for "kymo" folder in "kymo" target */ = {
|
||||
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
|
||||
membershipExceptions = (
|
||||
Core/Extensions/.gitkeep,
|
||||
Core/Monitors/.gitkeep,
|
||||
Core/Models/.gitkeep,
|
||||
Core/Monitors/.gitkeep,
|
||||
Core/README.md,
|
||||
Features/Dashboard/.gitkeep,
|
||||
Features/README.md,
|
||||
@@ -41,12 +68,24 @@
|
||||
};
|
||||
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
|
||||
|
||||
/* Begin PBXFileSystemSynchronizedRootGroup section */
|
||||
D9E51E75309338B0000608DE /* kymo */ = {
|
||||
isa = PBXFileSystemSynchronizedRootGroup;
|
||||
exceptions = (
|
||||
AA00000000000000000000A1 /* Exceptions for "kymo" folder in "kymo" target */,
|
||||
);
|
||||
path = kymo;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXFileSystemSynchronizedRootGroup section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
D9E51E70309338B0000608DE /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
files = (
|
||||
);
|
||||
};
|
||||
BB0000000000000000000005 = {isa = PBXFrameworksBuildPhase; files = (); };
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
@@ -54,6 +93,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D9E51E75309338B0000608DE /* kymo */,
|
||||
BB0000000000000000000003 /* SMART Service */,
|
||||
D9E51E74309338B0000608DE /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
@@ -62,10 +102,12 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D9E51E73309338B0000608DE /* kymo.app */,
|
||||
BB0000000000000000000002 /* SMARTService.xpc */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
BB0000000000000000000003 /* SMART Service */ = {isa = PBXGroup; name = "SMART Service"; children = (BB0000000000000000000016, BB000000000000000000000A, BB000000000000000000000B, BB000000000000000000000C, BB000000000000000000000D, BB000000000000000000000E, BB000000000000000000000F, ); sourceTree = "<group>"; };
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
@@ -76,9 +118,11 @@
|
||||
D9E51E6F309338B0000608DE /* Sources */,
|
||||
D9E51E70309338B0000608DE /* Frameworks */,
|
||||
D9E51E71309338B0000608DE /* Resources */,
|
||||
BB0000000000000000000004 /* Embed XPC Services */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (BB0000000000000000000009, );
|
||||
fileSystemSynchronizedGroups = (
|
||||
D9E51E75309338B0000608DE /* kymo */,
|
||||
);
|
||||
@@ -87,6 +131,17 @@
|
||||
productReference = D9E51E73309338B0000608DE /* kymo.app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
BB0000000000000000000001 /* SMARTService */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = BB0000000000000000000007;
|
||||
buildPhases = (BB0000000000000000000006, BB0000000000000000000005, );
|
||||
buildRules = ();
|
||||
dependencies = ();
|
||||
name = SMARTService;
|
||||
productName = SMARTService;
|
||||
productReference = BB0000000000000000000002;
|
||||
productType = "com.apple.product-type.xpc-service";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
@@ -119,6 +174,7 @@
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
D9E51E72309338B0000608DE /* kymo */,
|
||||
BB0000000000000000000001 /* SMARTService */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
@@ -137,6 +193,7 @@
|
||||
files = (
|
||||
);
|
||||
};
|
||||
BB0000000000000000000006 = {isa = PBXSourcesBuildPhase; files = (BB000000000000000000001E, BB000000000000000000001F, BB0000000000000000000020, BB0000000000000000000021, BB0000000000000000000022, BB0000000000000000000023, ); };
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
@@ -270,8 +327,8 @@
|
||||
ENABLE_PREVIEWS = YES;
|
||||
ENABLE_USER_SELECTED_FILES = readonly;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_KEY_NSHumanReadableCopyright = "";
|
||||
INFOPLIST_KEY_LSUIElement = YES;
|
||||
INFOPLIST_KEY_NSHumanReadableCopyright = "";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
@@ -301,8 +358,8 @@
|
||||
ENABLE_PREVIEWS = YES;
|
||||
ENABLE_USER_SELECTED_FILES = readonly;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_KEY_NSHumanReadableCopyright = "";
|
||||
INFOPLIST_KEY_LSUIElement = YES;
|
||||
INFOPLIST_KEY_NSHumanReadableCopyright = "";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
@@ -320,6 +377,36 @@
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
BB0000000000000000000028 = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
ENABLE_APP_SANDBOX = NO;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
GENERATE_INFOPLIST_FILE = NO;
|
||||
INFOPLIST_FILE = SMARTService/Info.plist;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = cn.airnan.kymo.SMARTService;
|
||||
PRODUCT_NAME = SMARTService;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
BB0000000000000000000029 = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
ENABLE_APP_SANDBOX = NO;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
GENERATE_INFOPLIST_FILE = NO;
|
||||
INFOPLIST_FILE = SMARTService/Info.plist;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = cn.airnan.kymo.SMARTService;
|
||||
PRODUCT_NAME = SMARTService;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
@@ -339,6 +426,7 @@
|
||||
);
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
BB0000000000000000000007 = {isa = XCConfigurationList; buildConfigurations = (BB0000000000000000000028, BB0000000000000000000029, ); defaultConfigurationName = Release; };
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = D9E51E6B309338B0000608DE /* Project object */;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import Foundation
|
||||
|
||||
nonisolated struct DiskHealthMetrics: Sendable {
|
||||
/// NVMe vendor endurance estimate, not a probability of remaining failure-free.
|
||||
let remainingLife: Double?
|
||||
let powerOnHours: UInt64?
|
||||
}
|
||||
@@ -24,6 +24,7 @@ nonisolated struct MetricsSnapshot: Sendable {
|
||||
var network: [NetworkInterfaceMetrics]?
|
||||
var networkPath: NetworkPathStatus?
|
||||
var disk: DiskMetrics?
|
||||
var diskHealth: DiskHealthMetrics?
|
||||
var diskIO: DiskIOMetrics?
|
||||
var volumes: [VolumeMetrics]?
|
||||
var battery: BatteryMetrics?
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import Foundation
|
||||
|
||||
/// SMART belongs to the physical storage backing the home volume, not each APFS volume.
|
||||
actor DiskHealthMonitor {
|
||||
private var cached: DiskHealthMetrics?
|
||||
private var nextRead: TimeInterval = 0
|
||||
private var pending: Task<DiskHealthMetrics?, Never>?
|
||||
|
||||
func sample() async -> DiskHealthMetrics? {
|
||||
if let pending { return await pending.value }
|
||||
guard ProcessInfo.processInfo.systemUptime >= nextRead else { return cached }
|
||||
let task = Task { await SMARTServiceClient.read() }
|
||||
pending = task
|
||||
cached = await task.value
|
||||
pending = nil
|
||||
nextRead = ProcessInfo.processInfo.systemUptime + (cached == nil ? 600 : 3600)
|
||||
return cached
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import Foundation
|
||||
|
||||
nonisolated enum DiskHealthReport {
|
||||
static func parse(_ data: Data) -> DiskHealthMetrics? {
|
||||
guard let root = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any],
|
||||
let smart = root["SMARTDeviceSpecificKeysMayVaryNotGuaranteed"] as? [String: Any] else { return nil }
|
||||
// Multiple physical stores cannot be represented as one device's lifetime.
|
||||
if let stores = root["APFSPhysicalStores"] as? [Any], stores.count != 1 { return nil }
|
||||
func integer(_ key: String) -> UInt64? {
|
||||
guard let value = smart[key] as? NSNumber,
|
||||
CFGetTypeID(value) != CFBooleanGetTypeID() else { return nil }
|
||||
return UInt64(value.stringValue)
|
||||
}
|
||||
let used = integer("PERCENTAGE_USED").flatMap { $0 <= 255 ? $0 : nil }
|
||||
let remaining = used.map { Double(100 - min(100, $0)) / 100 }
|
||||
let hours = integer("POWER_ON_HOURS_1") == 0 ? integer("POWER_ON_HOURS_0") : nil
|
||||
guard remaining != nil || hours != nil else { return nil }
|
||||
return DiskHealthMetrics(remainingLife: remaining, powerOnHours: hours)
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import Darwin
|
||||
/// Serial ownership keeps CPU baselines coherent and system calls off MainActor.
|
||||
actor SystemSampler {
|
||||
private var cpu = CPUMonitor()
|
||||
private let diskHealth = DiskHealthMonitor()
|
||||
private let batteryHealth = SystemBatteryHealthMonitor()
|
||||
|
||||
private var network = NetworkMonitor()
|
||||
@@ -21,6 +22,7 @@ actor SystemSampler {
|
||||
result.network = network.sample()
|
||||
result.networkPath = networkPath.snapshot()
|
||||
result.disk = DiskMonitor.sample()
|
||||
result.diskHealth = await diskHealth.sample()
|
||||
result.diskIO = diskIO.sample()
|
||||
let now = ProcessInfo.processInfo.systemUptime
|
||||
if volumeSampleTime == nil || now - (volumeSampleTime ?? 0) >= 30 {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import Foundation
|
||||
import Security
|
||||
|
||||
nonisolated enum CodeIdentity {
|
||||
static func requirement(at url: URL) -> String? {
|
||||
var code: SecStaticCode?
|
||||
guard SecStaticCodeCreateWithPath(url as CFURL, [], &code) == errSecSuccess,
|
||||
let code else { return nil }
|
||||
var requirement: SecRequirement?
|
||||
guard SecCodeCopyDesignatedRequirement(code, [], &requirement) == errSecSuccess,
|
||||
let requirement else { return nil }
|
||||
var text: CFString?
|
||||
guard SecRequirementCopyString(requirement, [], &text) == errSecSuccess else { return nil }
|
||||
return text as String?
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import Foundation
|
||||
|
||||
nonisolated enum SMARTServiceClient {
|
||||
static func read() async -> DiskHealthMetrics? {
|
||||
let url = Bundle.main.bundleURL.appendingPathComponent("Contents/XPCServices/SMARTService.xpc")
|
||||
guard let requirement = CodeIdentity.requirement(at: url) else { return nil }
|
||||
return await withCheckedContinuation { continuation in
|
||||
let connection = NSXPCConnection(serviceName: "cn.airnan.kymo.SMARTService")
|
||||
connection.setCodeSigningRequirement(requirement)
|
||||
connection.remoteObjectInterface = NSXPCInterface(with: SMARTServiceProtocol.self)
|
||||
let reply = Reply(connection: connection, continuation: continuation)
|
||||
connection.invalidationHandler = { reply.finish(nil) }
|
||||
connection.interruptionHandler = { reply.finish(nil) }
|
||||
connection.resume()
|
||||
guard let proxy = connection.remoteObjectProxyWithErrorHandler({ _ in reply.finish(nil) }) as? SMARTServiceProtocol else {
|
||||
reply.finish(nil); return
|
||||
}
|
||||
proxy.readSMART { remaining, hours in
|
||||
let life = remaining?.doubleValue
|
||||
let validLife = life.flatMap { $0.isFinite && (0...1).contains($0) ? $0 : nil }
|
||||
let validHours = hours.flatMap { UInt64($0.stringValue) }
|
||||
reply.finish(validLife != nil || validHours != nil ? DiskHealthMetrics(remainingLife: validLife, powerOnHours: validHours) : nil)
|
||||
}
|
||||
DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + 15) { reply.finish(nil) }
|
||||
}
|
||||
}
|
||||
|
||||
/// Error, interruption, timeout and reply may race; resume exactly once.
|
||||
private final class Reply: @unchecked Sendable {
|
||||
private let lock = NSLock()
|
||||
private var continuation: CheckedContinuation<DiskHealthMetrics?, Never>?
|
||||
private let connection: NSXPCConnection
|
||||
|
||||
init(connection: NSXPCConnection, continuation: CheckedContinuation<DiskHealthMetrics?, Never>) {
|
||||
self.connection = connection
|
||||
self.continuation = continuation
|
||||
}
|
||||
|
||||
func finish(_ value: DiskHealthMetrics?) {
|
||||
lock.lock()
|
||||
let callback = continuation
|
||||
continuation = nil
|
||||
lock.unlock()
|
||||
guard let callback else { return }
|
||||
connection.invalidationHandler = nil
|
||||
connection.interruptionHandler = nil
|
||||
connection.invalidate()
|
||||
callback.resume(returning: value)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
/// Fixed read-only operation: no caller-supplied paths or commands.
|
||||
@objc protocol SMARTServiceProtocol {
|
||||
nonisolated func readSMART(withReply reply: @escaping (NSNumber?, NSNumber?) -> Void)
|
||||
}
|
||||
@@ -21,6 +21,8 @@ nonisolated enum SamplingDiagnostics {
|
||||
payload["networkPath"] = snapshot.networkPath.map { String(describing: $0) }
|
||||
payload["networkDownload"] = snapshot.downloadRate
|
||||
payload["networkInterfaces"] = snapshot.network?.map(\.name)
|
||||
payload["diskRemainingLife"] = snapshot.diskHealth?.remainingLife
|
||||
payload["diskPowerOnHours"] = snapshot.diskHealth?.powerOnHours
|
||||
payload["diskRead"] = snapshot.diskIO?.read
|
||||
payload["diskWrite"] = snapshot.diskIO?.written
|
||||
payload["volumeCount"] = snapshot.volumes?.count
|
||||
|
||||
@@ -55,6 +55,14 @@ struct MenuPanelView: View {
|
||||
Text("disk.homeVolume").foregroundStyle(.secondary)
|
||||
detailLine("disk.total", MetricFormat.bytes(metrics.snapshot.disk?.total))
|
||||
detailLine("memory.available", MetricFormat.bytes(metrics.snapshot.disk?.available))
|
||||
detailLine("disk.remainingLife", MetricFormat.percent(metrics.snapshot.diskHealth?.remainingLife))
|
||||
HStack {
|
||||
Text("disk.powerOnHours").foregroundStyle(.secondary)
|
||||
Spacer()
|
||||
if let hours = metrics.snapshot.diskHealth?.powerOnHours {
|
||||
Text("disk.hours \(hours)").monospacedDigit()
|
||||
} else { Text(verbatim: "--") }
|
||||
}
|
||||
Divider()
|
||||
Text("disk.physicalIO").foregroundStyle(.secondary)
|
||||
detailLine("disk.read", rate(metrics.snapshot.diskIO?.read))
|
||||
|
||||
@@ -1583,6 +1583,72 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"disk.remainingLife": {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Estimated remaining life"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "预计剩余寿命"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "預計剩餘壽命"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"disk.powerOnHours": {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Power-on time"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "通电时间"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "通電時間"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"disk.hours %llu": {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "%llu hours"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "%llu 小时"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "%llu 小時"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"version": "1.0"
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import Foundation
|
||||
import Security
|
||||
|
||||
@main struct CodeIdentityChecks {
|
||||
static func main() {
|
||||
precondition(CommandLine.arguments.count == 3)
|
||||
let host = URL(fileURLWithPath: CommandLine.arguments[1])
|
||||
let service = URL(fileURLWithPath: CommandLine.arguments[2])
|
||||
func accepts(_ url: URL, requirement text: String) -> Bool {
|
||||
var code: SecStaticCode?
|
||||
var requirement: SecRequirement?
|
||||
guard SecStaticCodeCreateWithPath(url as CFURL, [], &code) == errSecSuccess,
|
||||
SecRequirementCreateWithString(text as CFString, [], &requirement) == errSecSuccess,
|
||||
let code, let requirement else { return false }
|
||||
return SecStaticCodeCheckValidity(code, [], requirement) == errSecSuccess
|
||||
}
|
||||
let hostRequirement = CodeIdentity.requirement(at: host)!
|
||||
let serviceRequirement = CodeIdentity.requirement(at: service)!
|
||||
precondition(accepts(host, requirement: hostRequirement))
|
||||
precondition(accepts(service, requirement: serviceRequirement))
|
||||
precondition(!accepts(service, requirement: hostRequirement))
|
||||
precondition(!accepts(host, requirement: serviceRequirement))
|
||||
precondition(CodeIdentity.requirement(at: host.appendingPathComponent("missing")) == nil)
|
||||
print("PASS: valid host/service identities, foreign signature rejection and missing code")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import Foundation
|
||||
|
||||
@main struct DiskHealthChecks {
|
||||
static func main() throws {
|
||||
func report(used: Any? = 2, low: Any? = 1121, high: Any? = 0, stores: Int = 1) -> Data {
|
||||
var smart: [String: Any] = [:]
|
||||
smart["PERCENTAGE_USED"] = used
|
||||
smart["POWER_ON_HOURS_0"] = low
|
||||
smart["POWER_ON_HOURS_1"] = high
|
||||
return try! PropertyListSerialization.data(fromPropertyList: [
|
||||
"SMARTDeviceSpecificKeysMayVaryNotGuaranteed": smart,
|
||||
"APFSPhysicalStores": Array(repeating: ["APFSPhysicalStore": "disk0s2"], count: stores)
|
||||
], format: .xml, options: 0)
|
||||
}
|
||||
let valid = DiskHealthReport.parse(report())!
|
||||
precondition(valid.remainingLife == 0.98 && valid.powerOnHours == 1121)
|
||||
precondition(DiskHealthReport.parse(report(used: 102))?.remainingLife == 0)
|
||||
precondition(DiskHealthReport.parse(report(used: -1))?.remainingLife == nil)
|
||||
precondition(DiskHealthReport.parse(report(used: true))?.remainingLife == nil)
|
||||
precondition(DiskHealthReport.parse(report(used: 256))?.remainingLife == nil)
|
||||
precondition(DiskHealthReport.parse(report(used: nil))?.powerOnHours == 1121)
|
||||
precondition(DiskHealthReport.parse(report(high: 1))?.powerOnHours == nil)
|
||||
precondition(DiskHealthReport.parse(report(low: -1))?.powerOnHours == nil)
|
||||
precondition(DiskHealthReport.parse(report(stores: 2)) == nil)
|
||||
precondition(DiskHealthReport.parse(report(used: nil, low: nil, high: nil)) == nil)
|
||||
precondition(DiskHealthReport.parse(Data("bad plist".utf8)) == nil)
|
||||
print("PASS: disk endurance, missing SMART, invalid counters, overflow and multi-store boundaries")
|
||||
}
|
||||
}
|
||||
@@ -68,3 +68,19 @@ C 阶段基础边界与本机采样检查:
|
||||
swiftc -module-cache-path /private/tmp/kymo-c-cache kymo/Core/Monitors/NetworkMonitor.swift kymo/Core/Monitors/DiskMonitor.swift kymo/Core/Monitors/DiskIOMonitor.swift kymo/Core/Monitors/BatteryMonitor.swift kymo/Core/Monitors/SystemBatteryHealthMonitor.swift kymoTests/StageCChecks.swift -o /private/tmp/kymo-c-check
|
||||
/private/tmp/kymo-c-check
|
||||
```
|
||||
|
||||
磁盘 SMART 解析边界检查(不证明应用沙盒可读取 SMART):
|
||||
|
||||
```bash
|
||||
swiftc -module-cache-path /private/tmp/kymo-disk-check-cache kymo/Core/Models/DiskHealthMetrics.swift kymo/Core/Monitors/DiskHealthReport.swift kymoTests/DiskHealthChecks.swift -o /private/tmp/kymo-disk-check
|
||||
/private/tmp/kymo-disk-check
|
||||
```
|
||||
|
||||
XPC 两端签名要求校验(先构建带辅助服务的实际应用):
|
||||
|
||||
```bash
|
||||
swiftc -module-cache-path /private/tmp/kymo-identity-cache kymo/Core/Services/CodeIdentity.swift kymoTests/CodeIdentityChecks.swift -o /private/tmp/kymo-identity-check
|
||||
/private/tmp/kymo-identity-check /absolute/path/to/kymo.app /absolute/path/to/kymo.app/Contents/XPCServices/SMARTService.xpc
|
||||
```
|
||||
|
||||
验证各自合法签名通过、对方身份要求拒绝及缺失代码降级;不替代主应用与 XPC 的实际端到端采样。方案与进程生命周期见 [辅助服务实施方案](../docs/disk-smart-helper-plan.md)。
|
||||
|
||||
Reference in New Issue
Block a user