Skip to content

Commit

Permalink
chore: fix disabled not logging
Browse files Browse the repository at this point in the history
  • Loading branch information
yamilmedina committed Feb 23, 2024
1 parent f68ccfe commit e5bd130
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 58 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ android {
// For all other flavors use the "nonfree" sourceSets
} else {
getByName("main") {
java.srcDirs("src/nonfree/kotlin")
java.srcDirs("src/main/kotlin", "src/nonfree/kotlin")
println("Building with non-free sourceSets")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,68 +24,12 @@ import android.location.Location
import android.location.LocationListener
import android.location.LocationManager
import androidx.core.location.LocationManagerCompat
<<<<<<< HEAD
=======
import com.google.android.gms.location.LocationServices
import com.google.android.gms.location.Priority
import com.google.android.gms.tasks.CancellationTokenSource
import com.wire.android.AppJsonStyledLogger
import com.wire.android.util.extension.isGoogleServicesAvailable
import com.wire.kalium.logger.KaliumLogLevel
>>>>>>> 7c45511ab (chore: add structured logs to location and fix permission handling (WPB-6358) (#2734))
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject

<<<<<<< HEAD
open class LocationPickerHelper @Inject constructor(@ApplicationContext val context: Context) {
=======
@Singleton
class LocationPickerHelper @Inject constructor(@ApplicationContext val context: Context) {

suspend fun getLocation(onSuccess: (GeoLocatedAddress) -> Unit, onError: () -> Unit) {
if (context.isGoogleServicesAvailable()) {
getLocationWithGms(
onSuccess = onSuccess,
onError = onError
)
} else {
getLocationWithoutGms(
onSuccess = onSuccess,
onError = onError
)
}
}

/**
* Choosing the best location estimate by docs.
* https://developer.android.com/develop/sensors-and-location/location/retrieve-current#BestEstimate
*/
@SuppressLint("MissingPermission")
private suspend fun getLocationWithGms(onSuccess: (GeoLocatedAddress) -> Unit, onError: () -> Unit) {
if (isLocationServicesEnabled()) {
AppJsonStyledLogger.log(
level = KaliumLogLevel.INFO,
leadingMessage = "GetLocation",
jsonStringKeyValues = mapOf("isUsingGms" to true)
)
val locationProvider = LocationServices.getFusedLocationProviderClient(context)
val currentLocation =
locationProvider.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, CancellationTokenSource().token).await()
val address = Geocoder(context).getFromLocation(currentLocation.latitude, currentLocation.longitude, 1).orEmpty()
onSuccess(GeoLocatedAddress(address.firstOrNull(), currentLocation))
} else {
AppJsonStyledLogger.log(
level = KaliumLogLevel.WARN,
leadingMessage = "GetLocation",
jsonStringKeyValues = mapOf(
"isUsingGms" to true,
"error" to "Location services are not enabled"
)
)
onError()
}
}
>>>>>>> 7c45511ab (chore: add structured logs to location and fix permission handling (WPB-6358) (#2734))

@SuppressLint("MissingPermission")
protected fun getLocationWithoutGms(onSuccess: (GeoLocatedAddress) -> Unit, onError: () -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import android.location.Geocoder
import com.google.android.gms.location.LocationServices
import com.google.android.gms.location.Priority
import com.google.android.gms.tasks.CancellationTokenSource
import com.wire.android.AppJsonStyledLogger
import com.wire.android.util.extension.isGoogleServicesAvailable
import com.wire.kalium.logger.KaliumLogLevel
import kotlinx.coroutines.tasks.await
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.tasks.await

@Singleton
class LocationPickerHelperFlavor @Inject constructor(context: Context) : LocationPickerHelper(context) {
Expand All @@ -52,12 +54,25 @@ class LocationPickerHelperFlavor @Inject constructor(context: Context) : Locatio
@SuppressLint("MissingPermission")
private suspend fun getLocationWithGms(onSuccess: (GeoLocatedAddress) -> Unit, onError: () -> Unit) {
if (isLocationServicesEnabled()) {
AppJsonStyledLogger.log(
level = KaliumLogLevel.INFO,
leadingMessage = "GetLocation",
jsonStringKeyValues = mapOf("isUsingGms" to true)
)
val locationProvider = LocationServices.getFusedLocationProviderClient(context)
val currentLocation =
locationProvider.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, CancellationTokenSource().token).await()
val address = Geocoder(context).getFromLocation(currentLocation.latitude, currentLocation.longitude, 1).orEmpty()
onSuccess(GeoLocatedAddress(address.firstOrNull(), currentLocation))
} else {
AppJsonStyledLogger.log(
level = KaliumLogLevel.WARN,
leadingMessage = "GetLocation",
jsonStringKeyValues = mapOf(
"isUsingGms" to true,
"error" to "Location services are not enabled"
)
)
onError()
}
}
Expand Down

0 comments on commit e5bd130

Please sign in to comment.