Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.2.1]

### 2026-06-15

- Fix: Return error when user rejects request to turn on location with `enableLocationManagerFallback=true`. Prior to this fix, it would try to retrieve the location nonetheless and timeout.

## [2.2.0]

### 2026-02-02
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ In your app-level gradle file, import the `ion-android-geolocation` library like

```
dependencies {
implementation("io.ionic.libs:iongeolocation-android:2.2.0")
implementation("io.ionic.libs:iongeolocation-android:2.2.1")
}
```

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ android {
defaultConfig {
minSdk 23
targetSdk 36
versionCode 3
versionName "2.2.0"
versionCode 4
versionName "2.2.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.ionic.libs</groupId>
<artifactId>iongeolocation-android</artifactId>
<version>2.2.0</version>
<version>2.2.1</version>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,13 @@ class IONGLOCController internal constructor(
}

/**
* @return true if the the settings result is such that the location request must fail
* @return true if the settings result is such that the location request must fail
* (even if enableLocationManagerFallback=true), or false otherwise
*/
private fun Result<Unit>.shouldNotProceed(options: IONGLOCLocationOptions): Boolean =
isFailure && (!options.enableLocationManagerFallback ||
exceptionOrNull() is IONGLOCException.IONGLOCLocationAndNetworkDisabledException)
exceptionOrNull() is IONGLOCException.IONGLOCLocationAndNetworkDisabledException ||
exceptionOrNull() is IONGLOCException.IONGLOCRequestDeniedException)

companion object {
private const val LOG_TAG = "IONGeolocationController"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class IONGLOCFallbackHelper(
*/
@SuppressLint("MissingPermission")
internal suspend fun getCurrentLocation(options: IONGLOCLocationOptions): Location = try {
withTimeout(options.timeout) {
withTimeout(timeMillis = options.timeout) {
suspendCancellableCoroutine { continuation ->
getValidCachedLocation(options)?.let { validCacheLocation ->
continuation.resume(validCacheLocation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,28 @@ class IONGLOCControllerTest {
assertTrue(result.exceptionOrNull() is IONGLOCException.IONGLOCRequestDeniedException)
}

@Test
fun `given location is off and user does not resolve location settings, when getCurrentLocation is called with enableLocationFallback=True, IONGLOCRequestDeniedException returned`() =
runTest {
givenSuccessConditions() // to instantiate mocks
givenResolvableApiException(Activity.RESULT_CANCELED)
// unlike the test above for enableLocationFallback=false
// this line is explicitly needed, because otherwise
// the SUT would not assume resolving is needed for the fallback
// and would try to await a location (which is the bug that gets fixed by
// https://github.com/ionic-team/ion-android-geolocation/pull/12)
every { LocationManagerCompat.isLocationEnabled(any()) } returns false

val result = sut.getCurrentPosition(
mockk<Activity>(),
locationOptions.copy(enableLocationManagerFallback = true)
)
testScheduler.advanceTimeBy(DELAY)

assertTrue(result.isFailure)
assertTrue(result.exceptionOrNull() is IONGLOCException.IONGLOCRequestDeniedException)
}

@Test
fun `given location settings check fails, when getCurrentLocation is called, IONGLOCSettingsException is returned`() =
runTest {
Expand Down Expand Up @@ -562,7 +584,12 @@ class IONGLOCControllerTest {
fun `given SETTINGS_CHANGE_UNAVAILABLE error and network+location disabled and enableLocationManagerFallback=true, when getCurrentLocation is called, IONGLOCLocationAndNetworkDisabledException is returned`() =
runTest {
givenSuccessConditions() // to instantiate mocks
coEvery { locationSettingsTask.await() } throws ApiException(Status(8502, "SETTINGS_CHANGE_UNAVAILABLE"))
coEvery { locationSettingsTask.await() } throws ApiException(
Status(
8502,
"SETTINGS_CHANGE_UNAVAILABLE"
)
)
every { LocationManagerCompat.isLocationEnabled(any()) } returns false

val result = sut.getCurrentPosition(mockk<Activity>(), locationOptionsWithFallback)
Expand Down
Loading