From 481feec24da3e951e1328a03b60d1c049a8f4d46 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Fri, 26 Feb 2021 17:56:56 +0300 Subject: [PATCH] Revert "Improve tracker location update" This reverts commit 1867b3d07d4b2ff894e268f61aca9db3879d6baa. --- .../net/osmand/telegram/TelegramLocationProvider.kt | 13 ++++--------- .../src/net/osmand/telegram/TelegramService.kt | 9 +++------ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramLocationProvider.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramLocationProvider.kt index 3b2ddc572a..719e21b886 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramLocationProvider.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramLocationProvider.kt @@ -4,7 +4,7 @@ import android.annotation.SuppressLint import android.content.Context import android.hardware.* import android.location.Location -import android.os.HandlerThread +import android.os.Looper import android.util.Log import com.google.android.gms.location.* import net.osmand.PlatformUtil @@ -43,12 +43,11 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve var lastKnownLocation: net.osmand.Location? = null private set - private val locationUpdateHandlerThread = HandlerThread("LocationProviderUpdateHandlerThread") private var fusedLocationProviderClient: FusedLocationProviderClient? = null private val locationRequest = LocationRequest().apply { interval = 1000 - //fastestInterval = 500 - maxWaitTime = 0 + fastestInterval = 500 + maxWaitTime = 2000 priority = LocationRequest.PRIORITY_HIGH_ACCURACY } private val locationCallback = object : LocationCallback() { @@ -82,10 +81,6 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve fun updateCompassValue(value: Float) } - init { - locationUpdateHandlerThread.start() - } - @SuppressLint("MissingPermission") fun resumeAllUpdates() { if (AndroidUtils.isLocationPermissionAvailable(app) && fusedLocationProviderClient == null) { @@ -94,7 +89,7 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve try { fusedLocationProviderClient?.requestLocationUpdates( - locationRequest, locationCallback, locationUpdateHandlerThread.looper) + locationRequest, locationCallback, Looper.myLooper()) } catch (unlikely: SecurityException) { Log.d(PlatformUtil.TAG, "Lost location permissions. Couldn't request updates. $unlikely") } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt index bc0773b7e4..2d85e971b0 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt @@ -38,7 +38,6 @@ class TelegramService : Service(), TelegramIncomingMessagesListener, private var updateWidgetHandler: Handler? = null private var updateWidgetThread = HandlerThread("WidgetUpdateServiceThread") - private var locationUpdateHandlerThread = HandlerThread("LocationUpdateServiceThread") // FusedLocationProviderClient - Main class for receiving location updates. private lateinit var fusedLocationProviderClient: FusedLocationProviderClient @@ -63,7 +62,6 @@ class TelegramService : Service(), TelegramIncomingMessagesListener, mHandlerThread.start() tracksHandlerThread.start() updateWidgetThread.start() - locationUpdateHandlerThread.start() updateShareInfoHandler = Handler(mHandlerThread.looper) updateTracksHandler = Handler(tracksHandlerThread.looper) updateWidgetHandler = Handler(updateWidgetThread.looper) @@ -84,11 +82,11 @@ class TelegramService : Service(), TelegramIncomingMessagesListener, // Sets the fastest rate for active location updates. This interval is exact, and your // application will never receive updates more frequently than this value. - //fastestInterval = 500 + fastestInterval = 500 // Sets the maximum time when batched location updates are delivered. Updates may be // delivered sooner than this interval. - maxWaitTime = 0 + maxWaitTime = 2000 priority = LocationRequest.PRIORITY_HIGH_ACCURACY } @@ -168,7 +166,6 @@ class TelegramService : Service(), TelegramIncomingMessagesListener, tracksHandlerThread.quit() mHandlerThread.quit() updateWidgetThread.quit() - locationUpdateHandlerThread.quit() app().showLocationHelper.addOrUpdateStatusWidget(-1, false) usedBy = 0 @@ -201,7 +198,7 @@ class TelegramService : Service(), TelegramIncomingMessagesListener, // request location updates try { fusedLocationProviderClient.requestLocationUpdates( - locationRequest, locationCallback, locationUpdateHandlerThread.looper) + locationRequest, locationCallback, Looper.myLooper()) } catch (unlikely: SecurityException) { Toast.makeText(this, R.string.no_location_permission, Toast.LENGTH_LONG).show() Log.d(PlatformUtil.TAG, "Lost location permissions. Couldn't request updates. $unlikely")