Skip to content

Commit

Permalink
Location: Handle rare sidecases
Browse files Browse the repository at this point in the history
Fixes #1963, #2005
  • Loading branch information
mar-v-in committed Aug 30, 2023
1 parent 839248f commit ecfc7c7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ class LocationManager(private val context: Context, private val lifecycle: Lifec
}
} catch (e: SecurityException) {
// Ignore
} catch (e: Exception) {
// Ignore
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.google.android.gms.location.internal.*
import com.google.android.gms.location.internal.DeviceOrientationRequestUpdateData.REMOVE_UPDATES
import com.google.android.gms.location.internal.DeviceOrientationRequestUpdateData.REQUEST_UPDATES
import org.microg.gms.common.NonCancelToken
import org.microg.gms.location.hasNetworkLocationServiceBuiltIn
import org.microg.gms.utils.warnOnTransactionIssues

class LocationManagerInstance(
Expand Down Expand Up @@ -158,7 +159,7 @@ class LocationManagerInstance(
lifecycleScope.launchWhenStarted {
val locationManager = context.getSystemService<android.location.LocationManager>()
val gpsPresent = locationManager?.allProviders?.contains(GPS_PROVIDER) == true
val networkPresent = locationManager?.allProviders?.contains(NETWORK_PROVIDER) == true
val networkPresent = locationManager?.allProviders?.contains(NETWORK_PROVIDER) == true || context.hasNetworkLocationServiceBuiltIn()
val gpsUsable = gpsPresent && locationManager?.isProviderEnabled(GPS_PROVIDER) == true &&
context.packageManager.checkPermission(ACCESS_FINE_LOCATION, clientIdentity.packageName) == PERMISSION_GRANTED
val networkUsable = networkPresent && locationManager?.isProviderEnabled(NETWORK_PROVIDER) == true &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class LocationRequestManager(private val context: Context, private val lifecycle
return request.priority
}
val maxUpdateDelayMillis: Long
get() = max(request.maxUpdateDelayMillis, intervalMillis)
get() = max(max(request.maxUpdateDelayMillis, intervalMillis), 1000L)
val intervalMillis: Long
get() = request.intervalMillis
val updatesPending: Int
Expand Down Expand Up @@ -415,6 +415,7 @@ class LocationRequestManager(private val context: Context, private val lifecycle

fun check() {
if (!context.checkAppOpForEffectiveGranularity(clientIdentity, effectiveGranularity)) throw RuntimeException("Lack of permission")
if (effectiveGranularity > permissionGranularity) throw RuntimeException("Lack of permission")
if (timePendingMillis < 0) throw RuntimeException("duration limit reached (active for ${(SystemClock.elapsedRealtime() - start).formatDuration()}, duration ${request.durationMillis.formatDuration()})")
if (updatesPending <= 0) throw RuntimeException("max updates reached")
if (callback?.asBinder()?.isBinderAlive == false) throw RuntimeException("Binder died")
Expand All @@ -426,7 +427,7 @@ class LocationRequestManager(private val context: Context, private val lifecycle
if (lastLocation != null && location.distanceTo(lastLocation!!) < request.minUpdateDistanceMeters) return false
if (lastLocation == location) return false
val returnedLocation = if (effectiveGranularity > permissionGranularity) {
throw RuntimeException("lack of permission")
throw RuntimeException("Lack of permission")
} else {
if (!context.noteAppOpForEffectiveGranularity(clientIdentity, effectiveGranularity)) {
throw RuntimeException("app op denied")
Expand Down

0 comments on commit ecfc7c7

Please sign in to comment.