|
...
|
...
|
@@ -193,26 +193,22 @@ class AppleHealthRawDataCoreService { |
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> shareNativeAppleHealthObserverRecord() async {
|
|
|
|
if (!_isDebug) return false;
|
|
|
|
return _rawDataApi.shareNativeAppleHealthObserverRecord();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> shareFlutterObserverRecord() async {
|
|
|
|
if (!_isDebug) return false;
|
|
|
|
return _rawDataApi.shareFlutterObserverRecord();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> shareUploadTaskRecord() async {
|
|
|
|
if (!_isDebug) return false;
|
|
|
|
return _rawDataApi.shareUploadTaskRecord();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<String> readLocalNotificationDebugLogText() {
|
|
|
|
return _localNotificationDebugStore.readText(isDebug: _isDebug);
|
|
|
|
return _localNotificationDebugStore.readText();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> shareLocalNotificationDebugRecord() async {
|
|
|
|
if (!_isDebug) return false;
|
|
|
|
return _shareNativeLocalNotificationDebugRecord();
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -1477,7 +1473,6 @@ class AppleHealthRawDataCoreService { |
|
|
|
required String apiName,
|
|
|
|
required Object? result,
|
|
|
|
}) async {
|
|
|
|
if (!_isDebug) return;
|
|
|
|
final file = await _uploadApiLogFile();
|
|
|
|
await file.parent.create(recursive: true);
|
|
|
|
final line =
|
|
...
|
...
|
@@ -1486,7 +1481,6 @@ class AppleHealthRawDataCoreService { |
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _saveNativeCallFlutterChange(List<int>? dataTypes) async {
|
|
|
|
if (!_isDebug) return;
|
|
|
|
try {
|
|
|
|
await _rawDataApi.saveNativeCallFlutterChange(
|
|
|
|
relativeDataTypes: dataTypes ?? const <int>[],
|
|
...
|
...
|
@@ -1497,7 +1491,6 @@ class AppleHealthRawDataCoreService { |
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _saveFlutterCaculateFinished(List<int> dataTypes) async {
|
|
|
|
if (!_isDebug) return;
|
|
|
|
try {
|
|
|
|
await _rawDataApi.saveFlutterCaculateFinished(
|
|
|
|
relativeDataTypes: dataTypes,
|
|
...
|
...
|
@@ -1510,7 +1503,6 @@ class AppleHealthRawDataCoreService { |
|
|
|
Future<void> _saveLocalNotificationDebugEvent(
|
|
|
|
Map<String, Object?> event,
|
|
|
|
) async {
|
|
|
|
if (!_isDebug) return;
|
|
|
|
try {
|
|
|
|
await _localNotificationDebugStore.append(event);
|
|
|
|
await _saveNativeLocalNotificationDebugEvent(event);
|
|
...
|
...
|
@@ -2229,7 +2221,7 @@ class HealthRawStressLocalStore { |
|
|
|
final db = await factory.openDatabase(
|
|
|
|
path,
|
|
|
|
options: OpenDatabaseOptions(
|
|
|
|
version: 7,
|
|
|
|
version: 8,
|
|
|
|
onCreate: (db, version) async {
|
|
|
|
await _createTables(db);
|
|
|
|
},
|
|
...
|
...
|
@@ -2253,6 +2245,9 @@ class HealthRawStressLocalStore { |
|
|
|
if (oldVersion < 7) {
|
|
|
|
await _createSleepResultsTable(db);
|
|
|
|
}
|
|
|
|
if (oldVersion < 8) {
|
|
|
|
await _addUpdateTimeColumns(db);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
...
|
...
|
@@ -2278,7 +2273,8 @@ CREATE TABLE IF NOT EXISTS $hrvResultsTable ( |
|
|
|
is_workout_recovery INTEGER NOT NULL DEFAULT 0,
|
|
|
|
is_sleep_likely INTEGER NOT NULL DEFAULT 0,
|
|
|
|
is_suspected_activity INTEGER NOT NULL DEFAULT 0,
|
|
|
|
uploaded INTEGER NOT NULL DEFAULT 0
|
|
|
|
uploaded INTEGER NOT NULL DEFAULT 0,
|
|
|
|
update_time INTEGER NOT NULL DEFAULT 0
|
|
|
|
)
|
|
|
|
''');
|
|
|
|
await db.execute('''
|
|
...
|
...
|
@@ -2293,7 +2289,8 @@ CREATE TABLE IF NOT EXISTS $realtimeStressResultsTable ( |
|
|
|
is_workout_recovery INTEGER NOT NULL DEFAULT 0,
|
|
|
|
is_sleep_likely INTEGER NOT NULL DEFAULT 0,
|
|
|
|
is_suspected_activity INTEGER NOT NULL DEFAULT 0,
|
|
|
|
uploaded INTEGER NOT NULL DEFAULT 0
|
|
|
|
uploaded INTEGER NOT NULL DEFAULT 0,
|
|
|
|
update_time INTEGER NOT NULL DEFAULT 0
|
|
|
|
)
|
|
|
|
''');
|
|
|
|
await _createDailyStressTable(db);
|
|
...
|
...
|
@@ -2309,7 +2306,8 @@ CREATE TABLE IF NOT EXISTS $dailyStressResultsTable ( |
|
|
|
stress_score INTEGER NOT NULL,
|
|
|
|
state INTEGER NOT NULL,
|
|
|
|
data_time INTEGER NOT NULL,
|
|
|
|
uploaded INTEGER NOT NULL DEFAULT 0
|
|
|
|
uploaded INTEGER NOT NULL DEFAULT 0,
|
|
|
|
update_time INTEGER NOT NULL DEFAULT 0
|
|
|
|
)
|
|
|
|
''');
|
|
|
|
}
|
|
...
|
...
|
@@ -2325,11 +2323,29 @@ CREATE TABLE IF NOT EXISTS $sleepResultsTable ( |
|
|
|
in_bed_minutes INTEGER NOT NULL,
|
|
|
|
awak_minutes INTEGER NOT NULL,
|
|
|
|
sleep_minutes INTEGER NOT NULL,
|
|
|
|
uploaded INTEGER NOT NULL DEFAULT 0
|
|
|
|
uploaded INTEGER NOT NULL DEFAULT 0,
|
|
|
|
update_time INTEGER NOT NULL DEFAULT 0
|
|
|
|
)
|
|
|
|
''');
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _addUpdateTimeColumns(DatabaseExecutor db) async {
|
|
|
|
for (final table in const [
|
|
|
|
hrvResultsTable,
|
|
|
|
realtimeStressResultsTable,
|
|
|
|
dailyStressResultsTable,
|
|
|
|
sleepResultsTable,
|
|
|
|
]) {
|
|
|
|
try {
|
|
|
|
await db.execute(
|
|
|
|
'ALTER TABLE $table ADD COLUMN update_time INTEGER NOT NULL DEFAULT 0',
|
|
|
|
);
|
|
|
|
} on DatabaseException catch (error) {
|
|
|
|
if (!error.isDuplicateColumnError()) rethrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _addFlagColumns(DatabaseExecutor db, String table) async {
|
|
|
|
for (final column in const [
|
|
|
|
'is_workout',
|
|
...
|
...
|
@@ -2491,6 +2507,7 @@ CREATE TABLE IF NOT EXISTS $sleepResultsTable ( |
|
|
|
'baseline_resting_hr': point.baselineRestingHr,
|
|
|
|
..._flagsRow(point.flags),
|
|
|
|
'uploaded': point.uploaded ? 1 : 0,
|
|
|
|
'update_time': _currentUnixSeconds(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -2504,6 +2521,7 @@ CREATE TABLE IF NOT EXISTS $sleepResultsTable ( |
|
|
|
'source_end_time': point.sourceEndTime,
|
|
|
|
..._flagsRow(point.flags),
|
|
|
|
'uploaded': point.uploaded ? 1 : 0,
|
|
|
|
'update_time': _currentUnixSeconds(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -2516,6 +2534,7 @@ CREATE TABLE IF NOT EXISTS $sleepResultsTable ( |
|
|
|
'state': point.state.value,
|
|
|
|
'data_time': point.dataTime,
|
|
|
|
'uploaded': point.uploaded ? 1 : 0,
|
|
|
|
'update_time': _currentUnixSeconds(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -2530,6 +2549,7 @@ CREATE TABLE IF NOT EXISTS $sleepResultsTable ( |
|
|
|
'awak_minutes': result.awakMinutes,
|
|
|
|
'sleep_minutes': result.sleepMinutes,
|
|
|
|
'uploaded': result.uploaded ? 1 : 0,
|
|
|
|
'update_time': _currentUnixSeconds(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -2560,6 +2580,12 @@ CREATE TABLE IF NOT EXISTS $sleepResultsTable ( |
|
|
|
final existingRow = existing.first;
|
|
|
|
if (_matchesStoredValues(
|
|
|
|
existingRow, row, _rawResultStoredValueKeys(row))) {
|
|
|
|
await db.update(
|
|
|
|
table,
|
|
|
|
<String, Object?>{'update_time': row['update_time']},
|
|
|
|
where: 'raw_end_time = ?',
|
|
|
|
whereArgs: [row['raw_end_time']],
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final uploadPayloadChanged = !_matchesStoredValues(
|
|
...
|
...
|
@@ -2590,6 +2616,7 @@ CREATE TABLE IF NOT EXISTS $sleepResultsTable ( |
|
|
|
'is_sleep_likely': row['is_sleep_likely'],
|
|
|
|
'is_suspected_activity': row['is_suspected_activity'],
|
|
|
|
'uploaded': uploadPayloadChanged ? 0 : existingRow['uploaded'],
|
|
|
|
'update_time': row['update_time'],
|
|
|
|
},
|
|
|
|
where: 'raw_end_time = ?',
|
|
|
|
whereArgs: [row['raw_end_time']],
|
|
...
|
...
|
@@ -2629,6 +2656,7 @@ CREATE TABLE IF NOT EXISTS $sleepResultsTable ( |
|
|
|
'state': row['state'],
|
|
|
|
'data_time': row['data_time'],
|
|
|
|
'uploaded': isToday ? 0 : (valueChanged ? 0 : existingRow['uploaded']),
|
|
|
|
'update_time': row['update_time'],
|
|
|
|
},
|
|
|
|
where: 'date = ?',
|
|
|
|
whereArgs: [row['date']],
|
|
...
|
...
|
@@ -2674,12 +2702,17 @@ CREATE TABLE IF NOT EXISTS $sleepResultsTable ( |
|
|
|
'awak_minutes': row['awak_minutes'],
|
|
|
|
'sleep_minutes': row['sleep_minutes'],
|
|
|
|
'uploaded': valueChanged ? 0 : existingRow['uploaded'],
|
|
|
|
'update_time': row['update_time'],
|
|
|
|
},
|
|
|
|
where: 'date = ?',
|
|
|
|
whereArgs: [row['date']],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
int _currentUnixSeconds() {
|
|
|
|
return DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<String> _rawResultStoredValueKeys(Map<String, Object?> row) {
|
|
|
|
return <String>[
|
|
|
|
'user_id',
|
...
|
...
|
|