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

Commit a8a7de77 authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

fix:2397: Fake also the last location

parent 26f0c1f0
Loading
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -15,15 +15,15 @@ object FakeLocationResolver {

    private data class FakeLocation(var latitude: Double, var longitude: Double)

    fun fakeLocations(
    fun fakeLocation(
        context: Context,
        identity: ClientIdentity,
        baseLocations: List<Location>
    ): List<Location> {
        baseLocation: Location
    ): Location {
        val latLon = getFakeLocation(context, identity.packageName, identity.uid)
            ?: return baseLocations
            ?: return baseLocation

        return baseLocations.map { overrideLatLon(it, latLon) }
        return overrideLatLon(baseLocation, latLon)
    }

    private fun getFakeLocation(context: Context, packageName: String, uid: Int): FakeLocation? {
+6 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ class LocationManager(private val context: Context, override val lifecycle: Life
        val permissionGranularity = context.granularityFromPermission(clientIdentity)
        var effectiveGranularity = getEffectiveGranularity(request.granularity, permissionGranularity)
        if (effectiveGranularity == GRANULARITY_FINE && database.getForceCoarse(clientIdentity.packageName) && !clientIdentity.isSelfUser()) effectiveGranularity = GRANULARITY_COARSE
        val returnedLocation = if (effectiveGranularity > permissionGranularity) {
        val baseLocation = if (effectiveGranularity > permissionGranularity) {
            // No last location available at requested granularity due to lack of permission
            null
        } else {
@@ -99,6 +99,11 @@ class LocationManager(private val context: Context, override val lifecycle: Life
                processedLocation
            }
        }

        val returnedLocation = baseLocation?.let {
            FakeLocationResolver.fakeLocation(context, clientIdentity, it)
        }

        if (!clientIdentity.isSelfUser()) database.noteAppLocation(clientIdentity.packageName, returnedLocation)
        return returnedLocation?.let { Location(it).apply { provider = "fused" } }
    }
+3 −3
Original line number Diff line number Diff line
@@ -476,9 +476,9 @@ class LocationRequestManager(private val context: Context, override val lifecycl
                    }
                }

                val result = LocationResult.create(FakeLocationResolver.fakeLocations(
                    context, clientIdentity, listOf(returnedLocation)
                ))
                val result = LocationResult.create(listOf(FakeLocationResolver.fakeLocation(
                    context, clientIdentity, returnedLocation
                )))

                callback?.onLocationResult(result)
                pendingIntent?.send(context, 0, Intent().apply { putExtra(LocationResult.EXTRA_LOCATION_RESULT, result) })