Disable background location log
This commit is contained in:
parent
32c8e76855
commit
7625099d74
@ -149,17 +149,17 @@ class LocationManager {
|
|||||||
|
|
||||||
void updateDeviceLocationIsolate() {
|
void updateDeviceLocationIsolate() {
|
||||||
workManager.Workmanager.executeTask((backgroundTask, data) async {
|
workManager.Workmanager.executeTask((backgroundTask, data) async {
|
||||||
print("[Background $backgroundTask] Started");
|
//print("[Background $backgroundTask] Started");
|
||||||
Geolocator geolocator = Geolocator();
|
Geolocator geolocator = Geolocator();
|
||||||
var battery = Battery();
|
var battery = Battery();
|
||||||
String webhookId = data["webhookId"];
|
String webhookId = data["webhookId"];
|
||||||
String httpWebHost = data["httpWebHost"];
|
String httpWebHost = data["httpWebHost"];
|
||||||
String logData = '==> ${DateTime.now()} [Background $backgroundTask]:';
|
//String logData = '==> ${DateTime.now()} [Background $backgroundTask]:';
|
||||||
print("[Background $backgroundTask] Getting path for log file...");
|
//print("[Background $backgroundTask] Getting path for log file...");
|
||||||
final logFileDirectory = await getExternalStorageDirectory();
|
//final logFileDirectory = await getExternalStorageDirectory();
|
||||||
print("[Background $backgroundTask] Opening log file...");
|
//print("[Background $backgroundTask] Opening log file...");
|
||||||
File logFile = File('${logFileDirectory.path}/ha-client-background-log.txt');
|
//File logFile = File('${logFileDirectory.path}/ha-client-background-log.txt');
|
||||||
print("[Background $backgroundTask] Log file path: ${logFile.path}");
|
//print("[Background $backgroundTask] Log file path: ${logFile.path}");
|
||||||
if (webhookId != null && webhookId.isNotEmpty) {
|
if (webhookId != null && webhookId.isNotEmpty) {
|
||||||
String url = "$httpWebHost/api/webhook/$webhookId";
|
String url = "$httpWebHost/api/webhook/$webhookId";
|
||||||
Map<String, String> headers = {};
|
Map<String, String> headers = {};
|
||||||
@ -172,27 +172,27 @@ void updateDeviceLocationIsolate() {
|
|||||||
"battery": 100
|
"battery": 100
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
print("[Background $backgroundTask] Getting battery level...");
|
//print("[Background $backgroundTask] Getting battery level...");
|
||||||
int batteryLevel;
|
int batteryLevel;
|
||||||
try {
|
try {
|
||||||
batteryLevel = await battery.batteryLevel;
|
batteryLevel = await battery.batteryLevel;
|
||||||
print("[Background $backgroundTask] Got battery level: $batteryLevel");
|
//print("[Background $backgroundTask] Got battery level: $batteryLevel");
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
print("[Background $backgroundTask] Error getting battery level: $e. Setting zero");
|
//print("[Background $backgroundTask] Error getting battery level: $e. Setting zero");
|
||||||
batteryLevel = 0;
|
batteryLevel = 0;
|
||||||
logData += 'Battery: error, $e';
|
//logData += 'Battery: error, $e';
|
||||||
}
|
}
|
||||||
if (batteryLevel != null) {
|
if (batteryLevel != null) {
|
||||||
data["data"]["battery"] = batteryLevel;
|
data["data"]["battery"] = batteryLevel;
|
||||||
logData += 'Battery: success, $batteryLevel';
|
//logData += 'Battery: success, $batteryLevel';
|
||||||
} else {
|
}/* else {
|
||||||
logData += 'Battery: error, level is null';
|
logData += 'Battery: error, level is null';
|
||||||
}
|
}*/
|
||||||
Position location;
|
Position location;
|
||||||
try {
|
try {
|
||||||
location = await geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high, locationPermissionLevel: GeolocationPermission.locationAlways);
|
location = await geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high, locationPermissionLevel: GeolocationPermission.locationAlways);
|
||||||
if (location != null && location.latitude != null) {
|
if (location != null && location.latitude != null) {
|
||||||
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;
|
||||||
try {
|
try {
|
||||||
@ -201,26 +201,26 @@ void updateDeviceLocationIsolate() {
|
|||||||
headers: headers,
|
headers: headers,
|
||||||
body: json.encode(data)
|
body: json.encode(data)
|
||||||
);
|
);
|
||||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
/*if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||||
logData += ' || Post: success, ${response.statusCode}';
|
logData += ' || Post: success, ${response.statusCode}';
|
||||||
} else {
|
} else {
|
||||||
logData += ' || Post: error, ${response.statusCode}';
|
logData += ' || Post: error, ${response.statusCode}';
|
||||||
}
|
}*/
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
logData += ' || Post: error, $e';
|
//logData += ' || Post: error, $e';
|
||||||
}
|
}
|
||||||
} else {
|
}/* else {
|
||||||
logData += ' || Location: error, location is null';
|
logData += ' || Location: error, location is null';
|
||||||
}
|
}*/
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("[Background $backgroundTask] Location error: $e");
|
//print("[Background $backgroundTask] Location error: $e");
|
||||||
logData += ' || Location: error, $e';
|
//logData += ' || Location: error, $e';
|
||||||
}
|
}
|
||||||
} else {
|
}/* else {
|
||||||
logData += 'Not configured';
|
logData += 'Not configured';
|
||||||
}
|
}*/
|
||||||
print("[Background $backgroundTask] Writing log data...");
|
//print("[Background $backgroundTask] Writing log data...");
|
||||||
try {
|
/*try {
|
||||||
var fileMode;
|
var fileMode;
|
||||||
if (logFile.existsSync() && logFile.lengthSync() < 5000000) {
|
if (logFile.existsSync() && logFile.lengthSync() < 5000000) {
|
||||||
fileMode = FileMode.append;
|
fileMode = FileMode.append;
|
||||||
@ -231,7 +231,7 @@ void updateDeviceLocationIsolate() {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("[Background $backgroundTask] Error writing log: $e");
|
print("[Background $backgroundTask] Error writing log: $e");
|
||||||
}
|
}
|
||||||
print("[Background $backgroundTask] Finished.");
|
print("[Background $backgroundTask] Finished.");*/
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
Reference in New Issue
Block a user