Revert commented location (activity) for tracker

This commit is contained in:
max-klaus 2021-01-14 17:09:54 +03:00
parent 588057fb82
commit 2714a9403b
2 changed files with 10 additions and 10 deletions

View file

@ -87,13 +87,12 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve
@SuppressLint("MissingPermission") @SuppressLint("MissingPermission")
fun resumeAllUpdates() { fun resumeAllUpdates() {
/*
val service = app.getSystemService(Context.LOCATION_SERVICE) as LocationManager val service = app.getSystemService(Context.LOCATION_SERVICE) as LocationManager
if (app.isInternetConnectionAvailable) { if (app.isInternetConnectionAvailable) {
if (System.currentTimeMillis() - agpsDataLastTimeDownloaded > AGPS_TO_REDOWNLOAD) { if (System.currentTimeMillis() - agpsDataLastTimeDownloaded > AGPS_TO_REDOWNLOAD) {
//force an updated check for internet connectivity here before destroying A-GPS-data //force an updated check for internet connectivity here before destroying A-GPS-data
if (app.isInternetConnectionAvailable(true)) { if (app.isInternetConnectionAvailable(true)) {
redownloadAGPS() //redownloadAGPS()
} }
} }
} }
@ -135,12 +134,11 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve
} }
} }
*/
registerOrUnregisterCompassListener(true) registerOrUnregisterCompassListener(true)
} }
private fun redownloadAGPS() { private fun redownloadAGPS() {
/*
try { try {
val service = app.getSystemService(Context.LOCATION_SERVICE) as LocationManager val service = app.getSystemService(Context.LOCATION_SERVICE) as LocationManager
service.sendExtraCommand(LocationManager.GPS_PROVIDER, "delete_aiding_data", null) service.sendExtraCommand(LocationManager.GPS_PROVIDER, "delete_aiding_data", null)
@ -152,7 +150,6 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve
agpsDataLastTimeDownloaded = 0L agpsDataLastTimeDownloaded = 0L
e.printStackTrace() e.printStackTrace()
} }
*/
} }
private fun getGpsStatusListener(service: LocationManager): GpsStatus.Listener { private fun getGpsStatusListener(service: LocationManager): GpsStatus.Listener {
@ -219,7 +216,6 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve
@Synchronized @Synchronized
fun registerOrUnregisterCompassListener(register: Boolean) { fun registerOrUnregisterCompassListener(register: Boolean) {
/*
if (sensorRegistered && !register) { if (sensorRegistered && !register) {
Log.d(PlatformUtil.TAG, "Disable sensor") //$NON-NLS-1$ Log.d(PlatformUtil.TAG, "Disable sensor") //$NON-NLS-1$
(app.getSystemService(Context.SENSOR_SERVICE) as SensorManager).unregisterListener(this) (app.getSystemService(Context.SENSOR_SERVICE) as SensorManager).unregisterListener(this)
@ -260,7 +256,6 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve
} }
sensorRegistered = true sensorRegistered = true
} }
*/
} }
override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) {} override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) {}
@ -394,14 +389,12 @@ class TelegramLocationProvider(private val app: TelegramApplication) : SensorEve
} }
private fun stopLocationRequests() { private fun stopLocationRequests() {
/*
val service = app.getSystemService(Context.LOCATION_SERVICE) as LocationManager val service = app.getSystemService(Context.LOCATION_SERVICE) as LocationManager
service.removeGpsStatusListener(gpsStatusListener) service.removeGpsStatusListener(gpsStatusListener)
service.removeUpdates(gpsListener) service.removeUpdates(gpsListener)
while (!networkListeners.isEmpty()) { while (!networkListeners.isEmpty()) {
service.removeUpdates(networkListeners.poll()) service.removeUpdates(networkListeners.poll())
} }
*/
} }
fun pauseAllUpdates() { fun pauseAllUpdates() {

View file

@ -505,7 +505,6 @@ class TelegramSettings(private val app: TelegramApplication) {
val currentTimeMillis = System.currentTimeMillis() val currentTimeMillis = System.currentTimeMillis()
val currentTime = currentTimeMillis / 1000 val currentTime = currentTimeMillis / 1000
statusChangeTime = currentTimeMillis statusChangeTime = currentTimeMillis
val gpsEnabled = false
/* /*
val lm = app.getSystemService(Context.LOCATION_SERVICE) as LocationManager val lm = app.getSystemService(Context.LOCATION_SERVICE) as LocationManager
val gpsEnabled = try { val gpsEnabled = try {
@ -521,6 +520,14 @@ class TelegramSettings(private val app: TelegramApplication) {
false false
} }
*/ */
val gpsEnabled = try {
val loc = app.locationProvider.lastKnownLocation
val gpsActive = loc != null && ((currentTimeMillis - loc.time) / 1000) < GPS_UPDATE_EXPIRED_TIME
val lastSentLocationExpired = ((currentTimeMillis - app.shareLocationHelper.lastLocationUpdateTime) / 1000) > GPS_UPDATE_EXPIRED_TIME
(gpsActive || !lastSentLocationExpired)
} catch (ex: Exception) {
false
}
var initializing = false var initializing = false
var sendChatsErrors = false var sendChatsErrors = false