Limit log file size to 5MB. Background location fixes
This commit is contained in:
parent
3e6229cf3e
commit
216276e5f3
@ -91,7 +91,7 @@ class LocationManager {
|
|||||||
},
|
},
|
||||||
frequency: interval,
|
frequency: interval,
|
||||||
initialDelay: Duration(minutes: delay),
|
initialDelay: Duration(minutes: delay),
|
||||||
existingWorkPolicy: workManager.ExistingWorkPolicy.replace,
|
existingWorkPolicy: workManager.ExistingWorkPolicy.keep,
|
||||||
backoffPolicy: workManager.BackoffPolicy.linear,
|
backoffPolicy: workManager.BackoffPolicy.linear,
|
||||||
backoffPolicyDelay: interval,
|
backoffPolicyDelay: interval,
|
||||||
constraints: workManager.Constraints(
|
constraints: workManager.Constraints(
|
||||||
@ -104,7 +104,7 @@ class LocationManager {
|
|||||||
|
|
||||||
_stopLocationService() async {
|
_stopLocationService() async {
|
||||||
Logger.d("Canceling previous schedule if any...");
|
Logger.d("Canceling previous schedule if any...");
|
||||||
await workManager.Workmanager.cancelByTag(backgroundTaskTag);
|
await workManager.Workmanager.cancelAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDeviceLocation() async {
|
updateDeviceLocation() async {
|
||||||
@ -196,16 +196,6 @@ void updateDeviceLocationIsolate() {
|
|||||||
logData += ' || Location: success, ${location.latitude} ${location.longitude} (${location.timestamp})';
|
logData += ' || Location: success, ${location.latitude} ${location.longitude} (${location.timestamp})';
|
||||||
data["data"]["gps"] = [location.latitude, location.longitude];
|
data["data"]["gps"] = [location.latitude, location.longitude];
|
||||||
data["data"]["gps_accuracy"] = location.accuracy;
|
data["data"]["gps_accuracy"] = location.accuracy;
|
||||||
} else {
|
|
||||||
logData += ' || Location: error, location is null';
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
//print("[Background $backgroundTask] Error getting location: $e. Setting fake one in the middle of the Black See");
|
|
||||||
data["data"]["gps"] = [43.373750, 34.026441];
|
|
||||||
data["data"]["gps_accuracy"] = 200;
|
|
||||||
logData += ' || Location: error, $e';
|
|
||||||
}
|
|
||||||
//print("[Background $backgroundTask] Sending data home.");
|
|
||||||
try {
|
try {
|
||||||
http.Response response = await http.post(
|
http.Response response = await http.post(
|
||||||
url,
|
url,
|
||||||
@ -220,12 +210,25 @@ void updateDeviceLocationIsolate() {
|
|||||||
} catch(e) {
|
} catch(e) {
|
||||||
logData += ' || Post: error, $e';
|
logData += ' || Post: error, $e';
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
logData += ' || Location: error, location is null';
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logData += ' || Location: error, $e';
|
||||||
|
}
|
||||||
|
//print("[Background $backgroundTask] Sending data home.");
|
||||||
} else {
|
} else {
|
||||||
logData += 'Not configured';
|
logData += 'Not configured';
|
||||||
}
|
}
|
||||||
print("[Background $backgroundTask] Writing log data...");
|
print("[Background $backgroundTask] Writing log data...");
|
||||||
try {
|
try {
|
||||||
await logFile.writeAsString('$logData\n', mode: FileMode.append);
|
var fileMode;
|
||||||
|
if (logFile.lengthSync() < 5000000) {
|
||||||
|
fileMode = FileMode.append;
|
||||||
|
} else {
|
||||||
|
fileMode = FileMode.write;
|
||||||
|
}
|
||||||
|
await logFile.writeAsString('$logData\n', mode: fileMode);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("[Background $backgroundTask] Error writing log: $e");
|
print("[Background $backgroundTask] Error writing log: $e");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user