Skip to content

Commit 4c2ff6a

Browse files
Protactinium234nan-licursoragent
authored andcommitted
fix: prevent location permission crashes from FusedLocation API calls (#2653)
Co-authored-by: Nan <nan@onesignal.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 3dd1e84 commit 4c2ff6a

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

OneSignalSDK/onesignal/location/src/main/java/com/onesignal/location/internal/controller/impl/FusedLocationApiWrapperImpl.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ internal class FusedLocationApiWrapperImpl : IFusedLocationApiWrapper {
1313
googleApiClient: GoogleApiClient,
1414
locationListener: LocationListener,
1515
) {
16-
if (googleApiClient.isConnected) {
17-
LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, locationListener)
18-
} else {
19-
Logging.warn("GoogleApiClient is not connected. Unable to cancel location updates.")
16+
try {
17+
if (googleApiClient.isConnected) {
18+
LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, locationListener)
19+
} else {
20+
Logging.warn("GoogleApiClient is not connected. Unable to cancel location updates.")
21+
}
22+
} catch (t: Throwable) {
23+
Logging.warn("FusedLocationApi.cancelLocationUpdates failed!", t)
2024
}
2125
}
2226

@@ -38,8 +42,12 @@ internal class FusedLocationApiWrapperImpl : IFusedLocationApiWrapper {
3842
}
3943

4044
override fun getLastLocation(googleApiClient: GoogleApiClient): Location? {
41-
if (googleApiClient.isConnected) {
42-
return LocationServices.FusedLocationApi.getLastLocation(googleApiClient)
45+
try {
46+
if (googleApiClient.isConnected) {
47+
return LocationServices.FusedLocationApi.getLastLocation(googleApiClient)
48+
}
49+
} catch (t: Throwable) {
50+
Logging.warn("FusedLocationApi.getLastLocation failed!", t)
4351
}
4452
return null
4553
}

0 commit comments

Comments
 (0)