feat:设备日志模块
feat:定时任务 feat:设置页面用路由重构
This commit is contained in:
1 parent
1033f403b1
commit
2efa7a3c19
60 files changed
+6560
-643
No files matched your search
@@ -110,6 +110,87 @@ class AppNetworkSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
/// Android 进程与设备资源快照。
|
||||
///
|
||||
/// CPU 使用率需要比较两次 [processCpuTimeMillis],原生层只返回累计值,避免在平台通道内
|
||||
/// 持有采样定时器;内存和存储同时保留总量,便于顶栏给出百分比并在 Tooltip 展示明细。
|
||||
class AppPerformanceSnapshot {
|
||||
/// Android 进程从启动至采样时累计消耗的 CPU 时间,单位为毫秒。
|
||||
final int processCpuTimeMillis;
|
||||
|
||||
/// Android Runtime 报告的逻辑处理器数量,最小按 1 处理。
|
||||
final int logicalProcessorCount;
|
||||
|
||||
/// 系统物理内存总量,单位为字节;平台数据不可用时为 0。
|
||||
final int systemMemoryTotalBytes;
|
||||
|
||||
/// 系统当前可用物理内存,单位为字节;平台数据不可用时为 0。
|
||||
final int systemMemoryAvailableBytes;
|
||||
|
||||
/// 当前应用进程的 PSS 内存占用,单位为字节。
|
||||
final int appMemoryBytes;
|
||||
|
||||
/// 应用文件目录所在存储卷的总容量,单位为字节;平台数据不可用时为 0。
|
||||
final int storageTotalBytes;
|
||||
|
||||
/// 应用文件目录所在存储卷的可用容量,单位为字节;平台数据不可用时为 0。
|
||||
final int storageAvailableBytes;
|
||||
|
||||
/// 创建一份原生平台已经完成单位换算的资源快照。
|
||||
const AppPerformanceSnapshot({
|
||||
required this.processCpuTimeMillis,
|
||||
required this.logicalProcessorCount,
|
||||
required this.systemMemoryTotalBytes,
|
||||
required this.systemMemoryAvailableBytes,
|
||||
required this.appMemoryBytes,
|
||||
required this.storageTotalBytes,
|
||||
required this.storageAvailableBytes,
|
||||
});
|
||||
|
||||
/// 创建平台通道不可用时的空快照,百分比 Getter 将稳定返回 0。
|
||||
const AppPerformanceSnapshot.empty()
|
||||
: processCpuTimeMillis = 0,
|
||||
logicalProcessorCount = 1,
|
||||
systemMemoryTotalBytes = 0,
|
||||
systemMemoryAvailableBytes = 0,
|
||||
appMemoryBytes = 0,
|
||||
storageTotalBytes = 0,
|
||||
storageAvailableBytes = 0;
|
||||
|
||||
/// 从 Android MethodChannel 返回值解析资源快照,缺失或类型异常字段按 0 处理。
|
||||
factory AppPerformanceSnapshot.fromMap(Map<dynamic, dynamic>? data) {
|
||||
int value(String key) => (data?[key] as num?)?.toInt() ?? 0;
|
||||
return AppPerformanceSnapshot(
|
||||
processCpuTimeMillis: value('processCpuTimeMs'),
|
||||
logicalProcessorCount:
|
||||
value('logicalProcessorCount').clamp(1, 256).toInt(),
|
||||
systemMemoryTotalBytes: value('memoryTotalBytes'),
|
||||
systemMemoryAvailableBytes: value('memoryAvailableBytes'),
|
||||
appMemoryBytes: value('appMemoryBytes'),
|
||||
storageTotalBytes: value('storageTotalBytes'),
|
||||
storageAvailableBytes: value('storageAvailableBytes'),
|
||||
);
|
||||
}
|
||||
|
||||
/// 系统内存已使用比例,范围为 0 到 1;总量未知时返回 0。
|
||||
double get memoryUsageRatio => _usedRatio(
|
||||
total: systemMemoryTotalBytes,
|
||||
available: systemMemoryAvailableBytes,
|
||||
);
|
||||
|
||||
/// 应用所在存储卷已使用比例,范围为 0 到 1;总量未知时返回 0。
|
||||
double get storageUsageRatio => _usedRatio(
|
||||
total: storageTotalBytes,
|
||||
available: storageAvailableBytes,
|
||||
);
|
||||
|
||||
/// 根据总量和可用量计算受限于 0 到 1 的占用比例,容忍原生瞬时采样误差。
|
||||
static double _usedRatio({required int total, required int available}) {
|
||||
if (total <= 0) return 0;
|
||||
return ((total - available) / total).clamp(0, 1).toDouble();
|
||||
}
|
||||
}
|
||||
|
||||
/// 统一管理虚拟机识别和硬件手动输入模式,避免各业务页面自行猜测设备能力。
|
||||
abstract class AppRuntimeTool {
|
||||
static const MethodChannel _channel = MethodChannel(
|
||||
@@ -208,6 +289,18 @@ abstract class AppRuntimeTool {
|
||||
}
|
||||
}
|
||||
|
||||
/// 读取一次 Android 进程、内存和存储快照;通道失败时返回可安全展示的空快照。
|
||||
static Future<AppPerformanceSnapshot> getPerformanceSnapshot() async {
|
||||
try {
|
||||
final data = await _channel.invokeMapMethod<dynamic, dynamic>(
|
||||
'getPerformanceSnapshot',
|
||||
);
|
||||
return AppPerformanceSnapshot.fromMap(data);
|
||||
} on PlatformException {
|
||||
return const AppPerformanceSnapshot.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/// 查询插件当前 Presentation 是否仍在展示,用于避免 showSubDisplay() 先关后开造成闪屏。
|
||||
static Future<bool> isSubScreenShowing() async {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user