Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/geolocation_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class GeolocationService {

static Future<void> onEnabledChange(bool enabled) async {
FirebaseCrashlytics.instance.log('geolocation_enabled:$enabled');
// Auto-restart if tracking lock is enabled and service was disabled
if (!enabled && (Preferences.instance.getBool(Preferences.trackingLock) ?? false)) {
FirebaseCrashlytics.instance.log('tracking_lock_restart');
await bg.BackgroundGeolocation.start();
}
if (Preferences.instance.getBool(Preferences.wakelock) ?? false) {
if (!enabled) {
await WakelockPartialAndroid.release();
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"bufferLabel": "Offline buffering",
"wakelockLabel": "Wake lock",
"stopDetectionLabel": "Stop detection",
"trackingLockLabel": "Prevent tracking from being disabled automatically",
"trackingLockMessage": "Tracking is locked. Disable lock in settings to turn off.",
"trackingLabel": "Continuous tracking",
"advancedLabel": "Advanced settings",
"passwordLabel": "Password",
Expand Down
12 changes: 12 additions & 0 deletions lib/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ class _MainScreenState extends State<MainScreen> {
);
}
} else {
// Check if tracking lock is enabled
if (Preferences.instance.getBool(Preferences.trackingLock) ?? false) {
if (mounted) {
messengerKey.currentState?.showSnackBar(
SnackBar(
content: Text(AppLocalizations.of(context)!.trackingLockMessage),
duration: const Duration(seconds: 2),
),
);
}
return;
}
FirebaseCrashlytics.instance.log('tracking_toggle_stop');
bg.BackgroundGeolocation.stop();
}
Expand Down
3 changes: 2 additions & 1 deletion lib/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Preferences {
static const String wakelock = 'wakelock';
static const String stopDetection = 'stop_detection';
static const String password = 'password';
static const String trackingLock = 'tracking_lock';

static const String lastTimestamp = 'lastTimestamp';
static const String lastLatitude = 'lastLatitude';
Expand All @@ -40,7 +41,7 @@ class Preferences {
cacheOptions: SharedPreferencesWithCacheOptions(
allowList: {
id, url, accuracy, distance, interval, angle, heartbeat,
fastestInterval, buffer, wakelock, stopDetection, password,
fastestInterval, buffer, wakelock, stopDetection, password, trackingLock,
lastTimestamp, lastLatitude, lastLongitude, lastHeading,
},
),
Expand Down
5 changes: 4 additions & 1 deletion lib/push_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ class PushService {
case 'positionPeriodic':
await bg.BackgroundGeolocation.start();
case 'positionStop':
await bg.BackgroundGeolocation.stop();
if (!(Preferences.instance.getBool(Preferences.trackingLock) ?? false)) {
await bg.BackgroundGeolocation.stop();
}
break;
case 'factoryReset':
await PasswordService.setPassword('');
}
Expand Down
6 changes: 5 additions & 1 deletion lib/quick_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:quick_actions/quick_actions.dart';
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;
import 'package:traccar_client/preferences.dart';

import 'l10n/app_localizations.dart';

Expand All @@ -27,7 +28,10 @@ class _QuickActionsInitializerState extends State<QuickActionsInitializer> {
case 'start':
await bg.BackgroundGeolocation.start();
case 'stop':
await bg.BackgroundGeolocation.stop();
if (!(Preferences.instance.getBool(Preferences.trackingLock) ?? false)) {
await bg.BackgroundGeolocation.stop();
}
break;
case 'sos':
try {
await bg.BackgroundGeolocation.getCurrentPosition(samples: 1, persist: true, extras: {'alarm': 'sos'});
Expand Down
9 changes: 9 additions & 0 deletions lib/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ class _SettingsScreenState extends State<SettingsScreen> {
setState(() {});
},
),
if (advanced)
SwitchListTile(
title: Text(AppLocalizations.of(context)!.trackingLockLabel),
value: Preferences.instance.getBool(Preferences.trackingLock) ?? false,
onChanged: (value) async {
await Preferences.instance.setBool(Preferences.trackingLock, value);
setState(() {});
},
),
if (advanced)
ListTile(
title: Text(AppLocalizations.of(context)!.passwordLabel),
Expand Down