Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Catch IllegalStateException on call to Google's location library #1940

Merged
merged 2 commits into from
Dec 15, 2023

Conversation

jennantilla
Copy link
Contributor

@jennantilla jennantilla commented Dec 13, 2023

Description

One Line Summary

Catch IllegalStateException on call to Google's location library to avoid crash.

Details

Motivation

IllegalStateException was reported in #1821, potentially due to and issue with a device's "Google Play services" app. Catching these exceptions and logging them will avoid crashes on calls to Google's location library.

OPTIONAL - Other

While the original crash was not reproducible, adding this try/catch block to log the exception should prevent the app from crashing.

Manual testing

Since crash was not reproducible, just tested running app to ensure that change does not impact location sharing on Android.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

Catch IllegalStateException and log them to avoid crashes on calls to Google's location library
@nan-li
Copy link
Contributor

nan-li commented Dec 13, 2023

Are there other reports of IllegalStateException aside from GoogleApiClient is not connected yet?

I think it may be clearer to check for googleApiClient.isConnected instead of using a try-catch, such as in the getLastLocation() or refreshRequest() method.

        fun getLastLocation(googleApiClient: GoogleApiClient): Location? {
            if (googleApiClient.isConnected) {
                return LocationServices.FusedLocationApi.getLastLocation(googleApiClient)
            }
            return null
        }
        private fun refreshRequest() {
            if (!googleApiClient.isConnected) {
                Logging.warn("Attempt to refresh location request but not currently connected!")
                return
            }
            // ... stuff

@jennantilla
Copy link
Contributor Author

I've updated the method per @nan-li's suggestion. Let me know if this looks good! cc @jkasten2

@jennantilla jennantilla force-pushed the fix/catch_exception_for_location_lib branch from 202e0f9 to d690988 Compare December 14, 2023 22:48
@jennantilla jennantilla force-pushed the fix/catch_exception_for_location_lib branch from d690988 to 85689d8 Compare December 14, 2023 22:49
@jennantilla jennantilla merged commit 8863284 into user-model/main Dec 15, 2023
2 checks passed
@jennantilla jennantilla deleted the fix/catch_exception_for_location_lib branch December 15, 2023 20:20
@jennantilla jennantilla mentioned this pull request Dec 28, 2023
jinliu9508 pushed a commit that referenced this pull request Jan 31, 2024
…ion_lib

Fix: Catch IllegalStateException on call to Google's location library
jinliu9508 pushed a commit that referenced this pull request Jan 31, 2024
…ion_lib

Fix: Catch IllegalStateException on call to Google's location library
jinliu9508 pushed a commit that referenced this pull request Feb 6, 2024
…ion_lib

Fix: Catch IllegalStateException on call to Google's location library
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants