Skip to content

Commit

Permalink
Location: Handle network location learning not possible due to lack o…
Browse files Browse the repository at this point in the history
…f GPS

Fixes #2005
  • Loading branch information
mar-v-in committed Sep 13, 2023
1 parent 23d1b18 commit 0234fee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class NetworkLocationService : LifecycleService(), WifiDetailsCallback, CellDeta
private val cache by lazy { LocationCacheDatabase(this) }
private val movingWifiHelper by lazy { MovingWifiHelper(this) }
private val settings by lazy { LocationSettings(this) }
private val wifiScanCache = LruCache<String?, Location>(100)
private val wifiScanCache = LruCache<String, Location>(100)

private var lastHighPowerScanRealtime = 0L
private var lastLowPowerScanRealtime = 0L
Expand Down Expand Up @@ -98,6 +98,8 @@ class NetworkLocationService : LifecycleService(), WifiDetailsCallback, CellDeta
)
}
} catch (e: SecurityException) {
Log.d(TAG, "GPS location retriever not initialized due to lack of permission")
} catch (e: Exception) {
Log.d(TAG, "GPS location retriever not initialized", e)
}
}
Expand Down Expand Up @@ -439,7 +441,7 @@ class NetworkLocationService : LifecycleService(), WifiDetailsCallback, CellDeta
}
}

private operator fun <K, V> LruCache<K, V>.set(key: K, value: V) {
private operator fun <K : Any, V : Any> LruCache<K, V>.set(key: K, value: V) {
put(key, value)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

package org.microg.gms.location.ui

import android.annotation.SuppressLint
import android.location.LocationManager
import android.os.Build.VERSION.SDK_INT
import android.os.Bundle
import androidx.core.content.getSystemService
import androidx.core.os.bundleOf
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
Expand Down Expand Up @@ -90,8 +91,10 @@ class LocationPreferencesFragment : PreferenceFragmentCompat() {
networkProviderCategory.isVisible = requireContext().hasNetworkLocationServiceBuiltIn()
wifiMls.isVisible = requireContext().hasMozillaLocationServiceSupport()
cellMls.isVisible = requireContext().hasMozillaLocationServiceSupport()
wifiLearning.isVisible = SDK_INT >= 17
cellLearning.isVisible = SDK_INT >= 17
wifiLearning.isVisible =
SDK_INT >= 17 && requireContext().getSystemService<LocationManager>()?.allProviders.orEmpty().contains(LocationManager.GPS_PROVIDER)
cellLearning.isVisible =
SDK_INT >= 17 && requireContext().getSystemService<LocationManager>()?.allProviders.orEmpty().contains(LocationManager.GPS_PROVIDER)
}

override fun onResume() {
Expand Down

0 comments on commit 0234fee

Please sign in to comment.