wordpress-mobile / WordPress-Android

WordPress for Android
http://android.wordpress.org
GNU General Public License v2.0
2.92k stars 1.3k forks source link

QR Code Scanning: Prevent illegalStateException #20650

Closed zwarm closed 4 weeks ago

zwarm commented 4 weeks ago

Fixes #20643

This PR addresses an issue where the app may encounter an IllegalStateException when attempting to set a fragment result after its lifecycle has reached the STOPPED state or beyond. To prevent this potential issue the following changes have been made:

Changed the lifecycle state in the observeCameraPermissionState from Lifecycle.State.CREATED to Lifecycle.State.STARTED. This ensures that the code block is executed only when the fragment is at least in the STARTED state, eliminating potential IllegalStateExceptions.

Introduced a check for isAdded in the setFragmentResultAndPopStack method. The isAdded property returns true if the fragment is currently added to its activity, providing a way to ensure that the fragment is still attached to its activity before executing UI-related code.

I was unable to recreate this crash, but according to the logs it happens when the app is backgrounded while the scanner is opened for QR Code login.


To Test:

Pre-req

[JP] Scan Login Code Step.1:

Step.2:

(STOP) Step.3:

[JP] Super Fast Media Upload


Regression Notes

  1. Potential unintended areas of impact

    • Bar scanner no longer works
  2. What I did to test those areas of impact (or what existing automated tests I relied on) Manul testing

  3. What automated tests I added (or what prevented me from doing so) N/A

PR Submission Checklist:


Testing Checklist (strike-out the not-applying and unnecessary ones): N/A

sonarcloud[bot] commented 4 weeks ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

wpmobilebot commented 4 weeks ago
WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr20650-1cecdbc
Commit1cecdbcef88f8eeaffb8d9d78e9aa7f4dec834a4
Direct Downloadwordpress-prototype-build-pr20650-1cecdbc.apk
Note: Google Login is not supported on these builds.
wpmobilebot commented 4 weeks ago
Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr20650-1cecdbc
Commit1cecdbcef88f8eeaffb8d9d78e9aa7f4dec834a4
Direct Downloadjetpack-prototype-build-pr20650-1cecdbc.apk
Note: Google Login is not supported on these builds.