增加作弊数据检测
This commit is contained in:
@@ -7,6 +7,7 @@ import 'package:device_info_plus/device_info_plus.dart';
|
||||
// --- 本地导入 ---
|
||||
import '../models/device_matching.dart';
|
||||
import '../models/saf_permission_state.dart';
|
||||
import '../models/data_abnormal_type.dart'; // 🆕 1.7.0
|
||||
import '../services/database_service.dart';
|
||||
import '../services/battery_data_service.dart';
|
||||
import '../services/saf_storage_service.dart';
|
||||
@@ -381,8 +382,11 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
}
|
||||
}
|
||||
|
||||
// 🟢 1.7.0 容量有效性校验
|
||||
final validatedCap = _validateCapacity(finalCap, _designCap);
|
||||
|
||||
setState(() {
|
||||
_currentCap = (finalCap ?? _currentCap).toDouble();
|
||||
_currentCap = (validatedCap ?? _currentCap).toDouble();
|
||||
_cycleCount = cycle;
|
||||
_batteryTemp = temp;
|
||||
_batteryVolt = volt;
|
||||
@@ -409,6 +413,53 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 🆕 1.7.0 容量有效性校验 ----------
|
||||
int? _validateCapacity(int? capacity, int designCap) {
|
||||
if (capacity == null) return null;
|
||||
|
||||
// 容量必须大于 0
|
||||
if (capacity <= 0) {
|
||||
dev.log('⚠️ 容量异常:<= 0,已忽略', name: 'BatteryHealth');
|
||||
return null;
|
||||
}
|
||||
|
||||
// 容量不能低于设计容量的 60%
|
||||
if (capacity < designCap * 0.6) {
|
||||
dev.log(
|
||||
'⚠️ 容量异常:低于设计容量 60%($capacity < ${designCap * 0.6}),已忽略',
|
||||
name: 'BatteryHealth',
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 容量不能超过设计容量的 115%
|
||||
if (capacity > designCap * 1.15) {
|
||||
dev.log(
|
||||
'⚠️ 容量异常:高于设计容量 115%($capacity > ${designCap * 1.15}),已忽略',
|
||||
name: 'BatteryHealth',
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
return capacity;
|
||||
}
|
||||
|
||||
// ---------- 🆕 1.7.0 异常检测(供 UI 使用) ----------
|
||||
DataAbnormalType _checkAbnormalType(
|
||||
double currentCap,
|
||||
int designCap,
|
||||
double voltage,
|
||||
) {
|
||||
// 容量异常:高于 115% 或低于 60%
|
||||
if (currentCap > designCap * 1.15) return DataAbnormalType.capacityTooHigh;
|
||||
if (currentCap < designCap * 0.6) return DataAbnormalType.capacityTooLow;
|
||||
|
||||
// 电压异常:低于 3.0V 或高于 5.0V
|
||||
if (voltage < 3.0 || voltage > 5.0) return DataAbnormalType.voltageAbnormal;
|
||||
|
||||
return DataAbnormalType.none;
|
||||
}
|
||||
|
||||
// ---------- 辅助提取方法 ----------
|
||||
int _extractCycle(String line) {
|
||||
final reg = RegExp(r'cycle=(\d+)');
|
||||
@@ -568,6 +619,13 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
? '充电中 · ${_getChargeTypeLabel()} · ${_getDisplayPower()}'
|
||||
: '';
|
||||
|
||||
// 🆕 1.7.0 异常检测
|
||||
final abnormalType = _checkAbnormalType(
|
||||
_currentCap,
|
||||
_designCap,
|
||||
_batteryVolt,
|
||||
);
|
||||
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: const SystemUiOverlayStyle(
|
||||
statusBarColor: Color.fromRGBO(157, 212, 237, 0.1),
|
||||
@@ -635,14 +693,12 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
body: _hasData
|
||||
? Column(
|
||||
children: [
|
||||
// 🟢 可滚动区域(带 RepaintBoundary)
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 设备型号
|
||||
Text(
|
||||
_deviceModel,
|
||||
style: const TextStyle(
|
||||
@@ -653,19 +709,19 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
|
||||
// 🟢 BatterySummary 用 RepaintBoundary 隔离
|
||||
// 🟢 BatterySummary(带异常检测)
|
||||
RepaintBoundary(
|
||||
child: BatterySummary(
|
||||
healthPercent: healthPercent,
|
||||
cycleCount: _cycleCount,
|
||||
currentCap: _currentCap,
|
||||
designCap: _designCap,
|
||||
abnormalType: abnormalType, // 🆕 1.7.0
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 🟢 TrendChart 用 RepaintBoundary 隔离
|
||||
RepaintBoundary(
|
||||
child: TrendChart(
|
||||
data: _trendData,
|
||||
@@ -675,7 +731,6 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// 🟢 充电条目 - 保留 AnimatedOpacity,但加 RepaintBoundary
|
||||
RepaintBoundary(
|
||||
child: AnimatedOpacity(
|
||||
opacity: _isCharging ? 1.0 : 0.0,
|
||||
@@ -706,7 +761,7 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
|
||||
const SizedBox(height: 4),
|
||||
|
||||
// 🟢 BatteryInfoPanel 也用 RepaintBoundary
|
||||
// 🟢 BatteryInfoPanel(带异常检测)
|
||||
RepaintBoundary(
|
||||
child: BatteryInfoPanel(
|
||||
batteryVolt: _batteryVolt,
|
||||
@@ -715,6 +770,7 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
minVolt: _minVolt,
|
||||
maxTemp: _maxTemp,
|
||||
minTemp: _minTemp,
|
||||
abnormalType: abnormalType, // 🆕 1.7.0
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart'; // 🟢 添加这一行
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
|
||||
class ChangelogPage extends StatefulWidget {
|
||||
|
||||
Reference in New Issue
Block a user