package expo.modules.location import android.content.Context import android.location.Location import android.location.LocationManager import expo.modules.location.records.LocationLastKnownOptions class SharedHelpers { companion object { /** * Checks whether given location didn't exceed given `maxAge` and fits in the required accuracy. */ internal fun isLocationValid(location: Location?, options: LocationLastKnownOptions): Boolean { if (location == null) { return false } val maxAge = options.maxAge ?: Double.MAX_VALUE val requiredAccuracy = options.requiredAccuracy ?: Double.MAX_VALUE val timeDiff = (System.currentTimeMillis() - location.time).toDouble() return timeDiff <= maxAge && location.accuracy <= requiredAccuracy } fun hasNetworkProviderEnabled(context: Context?): Boolean { if (context == null) { return false } val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as? LocationManager return locationManager != null && locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) } } }