Closed stevegaunt closed 4 months ago
An interesting observation , we have added logic to stop the background location, set the updated config to background location, and then start the background location when authentication state gets updated in our app.
we debug the state before restarting, and it did show the correct refresh payload from the previous config update, but it wasn't currently be used as Transistor Soft log was showing this
2022-06-10 13:34:16.207 ⚠️-[TSAuthorization resolve:success:failure:]_block_invoke 🔑 Token refresh failed to receive token from host api-v1.yepic.io. HTTP STATUS: 400
restarting seemed to force it to pick up the config
@christocracy quick question just asking if you had a chance to look at bg.BackgroundGeolocation.setConfig not being updated??
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.
This issue was closed because it has been inactive for 14 days since being marked as stale.
Sometimes (not all the time) when setting config on the background location, the updates do not seem to always get applied and still use old configuration values.
eg. var baseConfig = await getBaseLocationConfig();
Your Environment
Plugin version: 4.4.0
Platform: iOS ( but could also be Android, testing this now on android)
OS version: IOS - 15.5
Device manufacturer / model: iPhone 12
Flutter info (
flutter doctor
): [✓] Flutter (Channel stable, 2.8.1, on macOS 12.4 21F79 darwin-x64, locale en-GB) [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 13.4.1) [✓] Chrome - develop for the web [!] Android Studio (not installed) [✓] IntelliJ IDEA Ultimate Edition (version 2021.2) [✓] Connected device (2 available)Plugin config:
Expected Behavior
The new configuration should be applied to the background location sdk.
Actual Behavior
The old authorisation config is still present. It's the authorization object we are trying to update, as the refreshPayload may have the old username before signing back into the app with an old username.
Steps to Reproduce
Context
Update the authorization object with updated refreshURL body should the access token timeout so the refresh url will generate the new access token.
Debug logs
I've added the code snippet just before the output of the log. it's the refreshPayload that is different from the configuration after the starting the background location sdk. I've replaced the real values for context sensitive reasons.
Logs
``` await bg.BackgroundGeolocation.setConfig(baseConfig); log('[Location Tracking] start() SetConfig(baseConfig): ${baseConfig.toMap()}'); [Location Tracking] start() SetConfig(baseConfig): {desiredAccuracy: -1, distanceFilter: 50.0, elasticityMultiplier: 4.0, url: https://weburl/userLocationLog, headers: {App-Version: 0.7.23, Language-Accept: en_GB, Platform-Version: 15.5, Device-Manufacturer: Apple, Device-Name: iPhone13,1, Platform: iOS, x-api-key: C3}, autoSync: true, autoSyncThreshold: 20, batchSync: true, maxBatchSize: 500, maxDaysToPersist: 7, maxRecordsToPersist: 100000, authorization: {strategy: jwt, accessToken: eyJra, refreshToken: eyJj, refreshUrl: https://refreshurl/auth/refresh_tokens, refreshPayload: {refresh_token: {refreshToken}, username: NEWUSER}, expires: -1}, stopOnTerminate: false, startOnBoot: true, debug: false, logLevel: 3, logMaxDays: 1, reset: false, locationAuthorizationRequest: Always, geofenceModeHighAccuracy: true, enableHeadless: false, backgroundPermissionRationale: {title: Allow {applicationName} to access this device's location even when closed or not in use?, message: This enables the automatic logging of visits for your Yepics, positiveAction: Change to "{backgroundPermissionOptionLabel}", negativeAction: }} final currentState = await bg.BackgroundGeolocation.state(); log('[Location Tracking] current state before start config: ${currentState.map}'); [Location Tracking] current state before start config: {showsBackgroundLocationIndicator: false, activityType: 1, elasticityMultiplier: 4.0, disableStopDetection: false, didLaunchInBackground: false, autoSync: true, desiredAccuracy: -1.0, stopTimeout: 5.0, minimumActivityRecognitionConfidence: 70, useSignificantChangesOnly: false, stopDetectionDelay: 0.0, autoSyncThreshold: 20, batchSync: true, disableElasticity: false, enableTimestampMeta: false, locationAuthorizationAlert: {titleWhenOff: Location services are off, cancelButton: Cancel, titleWhenNotEnabled: Background location is not enabled, instructions: To use background location, you must enable '{locationAuthorizationRequest}' in the Location Services settings, settingsButton: Settings}, url: https://weburl/userLocationLog, stopOnStationary: false, isFirstBoot: false, startOnBoot: true, locationAuthorizationRequest: Always, httpTimeout: 60000, lastLocationAuthorizationStatus: 3, stopOnTerminate: false, maxBatchSize: 500, didRequestUpgradeLocationAuthorization: true, maxRecordsToPersist: 100000, activityRecognitionInterval: 10000.0, isMoving: false, trackingMode: 1, stationaryRadius: 25.0, preventSuspend: false, extras: {}, didDeviceReboot: false, disableMotionActivityUpdates: false, odometer: 5534996.190027132, locationTimeout: 60.0, params: {}, method: POST, logMaxDays: 1, geofenceInitialTriggerEntry: true, iOSHasWarnedLocationServicesOff: false, disableLocationAuthorizationAlert: false, distanceFilter: 50.0, headers: {Language-Accept: en_GB, App-Version: 0.7.23, Device-Name: iPhone13,1, x-api-key: C3, Platform-Version: 15.5, Device-Manufacturer: Apple, Platform: iOS}, heartbeatInterval: 60.0, httpRootProperty: location, disableAutoSyncOnCellular: false, desiredOdometerAccuracy: 100.0, locationTemplate: , locationsOrderDirection: ASC, persistMode: 2, stopAfterElapsedMinutes: -1.0, schedule: [], authorization: {refreshToken: eyJj, refreshUrl: https://refeshurl/auth/refresh_tokens, accessToken: eyJra, refreshPayload: {username: OLDUSER, refresh_token: {refreshToken}}, expires: -1.0, strategy: jwt}, schedulerEnabled: false, debug: false, pausesLocationUpdatesAutomatically: true, geofenceProximityRadius: 2000.0, geofenceTemplate: , maxDaysToPersist: 7, logLevel: 3, enabled: false} 16:11:17 final newState = await bg.BackgroundGeolocation.start(); log('[Location Tracking] current state after start config: ${newState.map}'); [Location Tracking] current state after start config: {showsBackgroundLocationIndicator: false, activityType: 1, elasticityMultiplier: 4.0, disableStopDetection: false, didLaunchInBackground: false, autoSync: true, desiredAccuracy: -1.0, stopTimeout: 5.0, minimumActivityRecognitionConfidence: 70, useSignificantChangesOnly: false, stopDetectionDelay: 0.0, autoSyncThreshold: 20, batchSync: true, disableElasticity: false, enableTimestampMeta: false, locationAuthorizationAlert: {titleWhenOff: Location services are off, cancelButton: Cancel, titleWhenNotEnabled: Background location is not enabled, instructions: To use background location, you must enable '{locationAuthorizationRequest}' in the Location Services settings, settingsButton: Settings}, url: https:/weburl/userLocationLog, stopOnStationary: false, isFirstBoot: false, startOnBoot: true, locationAuthorizationRequest: Always, httpTimeout: 60000, lastLocationAuthorizationStatus: 3, stopOnTerminate: false, maxBatchSize: 500, didRequestUpgradeLocationAuthorization: true, maxRecordsToPersist: 100000, activityRecognitionInterval: 10000.0, isMoving: false, trackingMode: 1, stationaryRadius: 25.0, preventSuspend: false, extras: {}, didDeviceReboot: false, disableMotionActivityUpdates: false, odometer: 5534996.190027132, locationTimeout: 60.0, params: {}, method: POST, logMaxDays: 1, geofenceInitialTriggerEntry: true, iOSHasWarnedLocationServicesOff: false, disableLocationAuthorizationAlert: false, distanceFilter: 50.0, headers: {Language-Accept: en_GB, App-Version: 0.7.23, Device-Name: iPhone13,1, x-api-key: C3, Platform-Version: 15.5, Device-Manufacturer: Apple, Platform: iOS}, heartbeatInterval: 60.0, httpRootProperty: location, disableAutoSyncOnCellular: false, desiredOdometerAccuracy: 100.0, locationTemplate: , locationsOrderDirection: ASC, persistMode: 2, stopAfterElapsedMinutes: -1.0, schedule: [], authorization: {refreshToken: eyJj, refreshUrl: https://refreshurl/auth/refresh_tokens, accessToken: eyJra, refreshPayload: {username: OLDUSER, refresh_token: {refreshToken}}, expires: -1.0, strategy: jwt}, schedulerEnabled: false, debug: false, pausesLocationUpdatesAutomatically: true, geofenceProximityRadius: 2000.0, geofenceTemplate: , maxDaysToPersist: 7, logLevel: 3, enabled: true} AS consequence of the refreshPayload not being updated, we get this logs from TSLocationManager 2022-06-10 13:34:14.757 ✅-[TSLocationManager locationManager:didUpdateLocations:] Acquired motionchange position: <+53.70687057,-1.91364788> +/- 35.00m (speed -1.00 mps / course -1.00) @ 10/06/2022, 13:34:14 British Summer Time 2022-06-10 13:34:14.757 🎾-[TSLocationManager startUpdatingLocation] Location-services: ON 2022-06-10 13:34:14.757 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 4.6 2022-06-10 13:34:14.758 🔵-[TSConfig incrementOdometer:] 5541573.7 2022-06-10 13:34:14.759 ℹ️+[LocationAuthorization run:onCancel:] status: 3 2022-06-10 13:34:14.760 ℹ️-[LocationDAO shrink:]_block_invoke maxRecordsToPersist: 100000 2022-06-10 13:34:14.760 ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: 6C386186-A536-4029-B583-A5DA76CEA9E1 2022-06-10 13:34:14.760 ⚠️-[TSHttpService flush:] Busy with previous request 2022-06-10 13:34:15.002 ⚠️-[HttpResponse handleResponse] HTTP ERROR: 401 *** * {"message":"The incoming token has expired"} 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: B8452AB5-A08B-4AEB-90DB-68BEC0AFB105 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: 1E515A1A-FB69-46D3-B32C-8DD6B4D9D20E 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: 5190E671-530F-4FA3-9735-9983EC65B6B4 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: 1A94C2CE-FB42-43C2-A6D1-0405D6A625E9 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: E4E53228-812C-4064-A933-B6D6AF10608B 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: F4CBC249-A7A5-4980-91CB-721EEF667EE0 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: FDC9CD4C-38F0-4B87-B051-D0DE30164DA1 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: 20913FEC-3FB5-4CD7-8F27-7A7EF6195629 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: 4DF48266-D99D-4106-A471-0351F0E513E7 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: 4B95F6BC-125A-45E1-BC0E-FD806644D6ED 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: C138DBE2-C876-4114-BA5A-BBDB80C45E05 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: 59BC1F33-D243-4129-BCC7-562C2D20C583 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: 4DFC6786-D261-4D30-B1FE-3888045A5ABB 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: BDD23715-7B8D-4644-9C0F-258A0BDBF419 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: 0F8BDD25-6C59-4FDA-A4C0-D3EA684FE3DA 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: AC91BFCB-3AA4-4F35-927D-0CB8B2179AB3 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: 884A50F9-164A-465B-9BF8-094712AA0562 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: A2BDF70B-DDAE-4104-8CCE-C395E56D5FC8 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: 1E2A1E70-610F-40A9-B280-937024196120 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: BA865EA5-D45C-454E-9FBF-AB2753C48CBC 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: D1F51A1B-6F5B-49CC-8A30-642CE72D5D2A 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: 0FC625DA-018E-4107-B11B-754DEE65FEBF 2022-06-10 13:34:15.003 🔵-[LocationDAO unlockAll:] UNLOCK: D4410364-351A-4FA6-BA5B-71573C872DA3 2022-06-10 13:34:15.010 ✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 443 OF ( 443 ) 2022-06-10 13:34:16.207 ⚠️-[TSAuthorization resolve:success:failure:]_block_invoke 🔑 Token refresh failed to receive token from host api-v1.yepic.io. HTTP STATUS: 400 ```