Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 0234feed authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Location: Handle network location learning not possible due to lack of GPS

Fixes #2005
parent 23d1b18e
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -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
@@ -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)
        }
    }
@@ -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)
}

+6 −3
Original line number Diff line number Diff line
@@ -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
@@ -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() {