Files
mdm/log_mapping_analysis.md

178 lines
7.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 日志映射分析报告
## 已验证的日志模式
### Update Logs (category="update")
- **Profile Apply**:
- 服务类: `DeviceReportService`
- 方法: `logProfileState`
- 字符串格式: `"Configuration profile '%s(%s)' has been applied."`
- 位置: DeviceReportService_javap.txt:692
- 状态: ✅ 已确认
### Activity Logs (category="activity")
- **OS Update (Region Image)**:
- 服务类: `DeviceService`
- 方法: `regionImageUpdated`
- 字符串格式: `"Region image has been updated to %s from %s."`
- Category: "activity"
- 位置: DeviceService_javap.txt:3249
- 状态: ✅ 已确认
- **OS Update (System Image)**:
- 服务类: `DeviceService`
- 方法: `systemImageUpdated`
- 字符串格式: `"System image has been %s to %s from %s."`
- Category: "activity"
- 位置: DeviceService_javap.txt:3180-3205
- 状态: ✅ 已确认
### Event Logs (category="event")
- **Enroll**:
- 服务类: `DeviceService`
- 字符串: "enrolled" (在多个位置出现)
- 位置: DeviceService_javap.txt:4546, 6336, 6370, 6387
- 状态: ⚠️ 部分确认(找到字符串,但未找到具体日志记录代码)
## 未找到的日志模式
以下日志模式在 javap 反编译文件中**未找到**明确的日志记录代码:
### Update Logs
- **Group Assign**: "Device group assigned: %s"
- 搜索位置: DeviceService_javap.txt
- 结果: ❌ 未找到
### Activity Logs
- **App Install**: "App(%s) has been added."
- 搜索位置: DeviceReportService_javap.txt, DeviceAppsService_javap.txt
- 结果: ❌ 未找到
- **App Uninstall**: "App(%s) has been removed."
- 搜索位置: DeviceAppsService_javap.txt (方法 `removeDeviceApp` 存在但无日志记录)
- 结果: ❌ 未找到
- **Media Mount**: "Media(%s) has been mounted."
- 搜索位置: DeviceReportService_javap.txt
- 结果: ❌ 未找到
- **Media Unmount**: "Media(%s) has been unmounted."
- 搜索位置: DeviceReportService_javap.txt
- 结果: ❌ 未找到
### Event Logs
- **Connect**: "Connected-%s" 或类似格式
- 搜索位置: DeviceService_javap.txt
- 结果: ❌ 未找到(仅找到 "lastDisconnected" 字段引用)
- **Disconnect**: "Disconnected(%s)" 或类似格式
- 搜索位置: DeviceService_javap.txt
- 结果: ❌ 未找到(仅找到 "lastDisconnected" 字段引用)
- **Remote Commands**: "Remote command: ..."
- 搜索位置: DeviceService_javap.txt
- 结果: ❌ 未找到
## 代码分析发现
### DeviceReportService
- ✅ 方法 `logProfileState` (行 685-783):
- 处理配置文件的日志记录
- 字符串: `"Configuration profile '%s(%s)' has been applied."`
- Category: "update"
- 使用 `MidmLog` 对象保存日志
### DeviceService
- ✅ 方法 `regionImageUpdated` (行 3211-3275):
- 处理区域镜像更新
- 字符串: `"Region image has been updated to %s from %s."`
- Category: "activity"
- 使用 `logService.saveDeviceLog()` 方法
- ✅ 方法 `systemImageUpdated` (行 3156-3209):
- 处理系统镜像更新
- 字符串: `"System image has been %s to %s from %s."`
- Category: "activity"
- 使用 `logService.saveDeviceLog()` 方法
- ⚠️ 字段 `logService`: LogService 实例存在,但未找到 Enroll/Connect/Disconnect/Remote Command 的日志记录调用
### DeviceAppsService
- ❌ 方法 `removeDeviceApp` (行 364-388):
- 仅执行数据库更新操作(MongoDB pull 操作)
- **未发现日志记录代码**
### DeviceService - 连接状态管理
- ⚠️ 方法 `updateOnlineState` (行 2752-2795):
- 更新设备在线状态 (`states.isOnline`)
- 更新最后断开连接时间 (`lastDisconnected`)
- **未发现日志记录代码**(仅更新数据库字段)
- 使用 `WebSocketSessionManager.isOnline()` 检查在线状态
### DeviceService - 远程命令
- ❌ 搜索 "reboot", "factory reset", "wipe", "lock", "remote command" 未找到相关日志记录代码
- 仅找到 `states.blocked` 相关的阻塞状态管理代码
## 可能的原因
1. **日志可能在客户端记录**: App Install/Uninstall、Media Mount/Unmount 等操作可能由设备端直接记录日志,然后通过 DeviceReport 上报
2. **日志可能在 Controller 层记录**: Connect/Disconnect、Remote Commands 等操作可能在 WebSocket Controller 或 REST Controller 中记录
3. **日志可能使用不同的格式**: 实际日志格式可能与推断的不同
4. **日志可能在其他服务类中**: 可能存在独立的 LogService 或 EventService 处理这些日志
5. **状态更新而非日志记录**: Connect/Disconnect 可能只更新设备状态字段(`states.isOnline`, `lastDisconnected`),而不记录日志条目
## 搜索进度总结
### ✅ 已完成
1. **Service 层搜索**:
- ✅ DeviceService_javap.txt (7613 行) - 完整搜索
- ✅ DeviceReportService_javap.txt (2541 行) - 完整搜索
- ✅ DeviceAppsService_javap.txt (413 行) - 完整搜索
- ✅ StoreOtaService_javap.txt (608 行) - 已读取
- 结果: 找到 3 个已验证的日志模式,10 个未找到
2. **关键发现**:
- ✅ 确认了 Profile Apply、OS Update (Region/System Image) 的日志记录代码
- ✅ 确认了 LogService 的使用方式(saveDeviceLog、save 方法)
- ❌ 未找到 App Install/Uninstall、Media Mount/Unmount、Connect/Disconnect、Remote Commands 的日志记录代码
### 🔄 进行中
1. **Controller 层搜索**:
- 发现 Controller 类文件(.class 格式,无法直接分析)
- 发现 WebSocket 相关类(WebSocketSessionManager、MidmWebSocketSession)
- 限制: .class 文件需要反编译才能分析
### ⏳ 待完成
1. **反编译 Controller 类**:
- DeviceController.class
- WebSocketSessionManager.class
- MidmWebSocketSession.class
- 其他 Controller 类
2. **搜索其他服务类**:
- LogService.class(需要反编译)
- 其他可能的服务类
3. **检查 DeviceReport 数据**:
- 查看 DeviceReport 模型结构
- 检查是否包含日志信息字段
4. **实际数据库验证**:
- 查看实际日志数据库中的记录
- 验证日志格式和内容
## 关键结论
基于当前分析,可以得出以下结论:
1. **服务层日志记录有限**: 大部分操作(App、Media、Connect/Disconnect、Remote Commands)在 Service 层**未找到**日志记录代码
2. **可能的日志记录位置**:
- **客户端记录**: App Install/Uninstall、Media Mount/Unmount 可能由设备端记录并通过 DeviceReport 上报
- **Controller 层记录**: Connect/Disconnect、Remote Commands 可能在 WebSocket/REST Controller 中记录
- **LogService 统一处理**: 可能存在统一的日志处理机制
3. **已验证的模式**: 只有 Profile Apply 和 OS Update 在服务层明确记录日志
## 建议的下一步
1. ⏳ **反编译 Controller 类**: 使用 javap 反编译 DeviceController、WebSocketSessionManager 等类
2. ⏳ **反编译 LogService**: 查看 LogService 的完整实现,了解日志记录机制
3. ⏳ **检查 DeviceReport 模型**: 查看 DeviceReport 是否包含日志相关字段
4. ⏳ **实际数据验证**: 如果有访问权限,查看实际日志数据库中的记录格式