Skip to content

[Compile Warnings As Errors] WordPress Module - Resolve PreferenceManager Deprecated Warnings#17215

Merged
ParaskP7 merged 5 commits intotrunkfrom
analysis/wordpress-preference-manager-deprecated-warnings
Oct 11, 2022
Merged

[Compile Warnings As Errors] WordPress Module - Resolve PreferenceManager Deprecated Warnings#17215
ParaskP7 merged 5 commits intotrunkfrom
analysis/wordpress-preference-manager-deprecated-warnings

Conversation

@ParaskP7
Copy link
Copy Markdown
Contributor

@ParaskP7 ParaskP7 commented Sep 27, 2022

Parent: #17173
Partially Closes: #17181

This PR resolves all PreferenceManager related Deprecated warnings for the WordPress module and beyond (Analytics and Editor modules):

Modules:


PS: @RenanLukas @AjeshRPai I added you as the main reviewer, that is, in addition to @wordpress-mobile/apps-infrastructure team itself, but randomly, since I want someone from the WordPress Android team to primarily sign-off on that change. 🥇

FYI: I am going to randomly add more of you in those PRs that will follow, just so you become more aware of this change and how close we are on enabling allWarningsAsErrors by default everywhere. 🎉


To test:

  • Smoke test both, the WordPress and Jetpack apps, and see if their settings and preference related functionalities are working as expected. For example, and per module, you could test the following:
    • Analytics: Switch on and off the Collect Information privacy setting and verify that the Logcat is showing/hiding the 🔵 Tracked: xyz related information. To find this setting go to: My Site tab -> Me options -> App Settings -> Privacy settings
    • Editor: Switch on and off the Use Block Editor site setting and verify that the Dialog that appears when using the legacy editor is showing/hiding. The dialog's title should be Try the new Block Editor. To find this setting go to: My Site tab -> Site Settings configuration
    • WordPress: Update the interface language and verify that the app's language changes accordingly. To find this setting got to: My Site tab -> Me options -> App Settings -> Interface Language

PS: The above testing should be enough to verify that all other setting related affecting changes are also working as expected.


Regression Notes

  1. Potential unintended areas of impact

The settings and preference related functionalities are not working as expected.

  1. What I did to test those areas of impact (or what existing automated tests I relied on)

See To test section above.

  1. What automated tests I added (or what prevented me from doing so)

N/A


PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Warning Message: "'PreferenceManager' is deprecated. Deprecated in Java"

The 'android.preference.PreferenceManager' class was deprecated in API
level 29 (Android 10), From there onwards, it is recommended to use the
corresponding 'AndroidX Preference Library' for a consistent behavior
across all devices.

For more info see:
- android.preference.PreferenceManager (Documentation):
https://developer.android.com/reference/kotlin/android/preference/
PreferenceManager
- androidx.preference.PreferenceManager (Documentation):
https://developer.android.com/reference/androidx/preference/
PreferenceManager

PS: This commit also adds the 'androidx.preference:preference'
dependency to the 'analytics' module since it wasn't there already.
Warning Message: "'PreferenceManager' is deprecated. Deprecated in Java"

The 'android.preference.PreferenceManager' class was deprecated in API
level 29 (Android 10), From there onwards, it is recommended to use the
corresponding 'AndroidX Preference Library' for a consistent behavior
across all devices.

For more info see:
- android.preference.PreferenceManager (Documentation):
https://developer.android.com/reference/kotlin/android/preference/
PreferenceManager
- androidx.preference.PreferenceManager (Documentation):
https://developer.android.com/reference/androidx/preference/
PreferenceManager

PS: This commit also adds the 'androidx.preference:preference'
dependency to the 'analytics' module since it wasn't there already.
Warning Message: "'PreferenceManager' is deprecated. Deprecated in Java"

The 'android.preference.PreferenceManager' class was deprecated in API
level 29 (Android 10), From there onwards, it is recommended to use the
corresponding 'AndroidX Preference Library' for a consistent behavior
across all devices.

For more info see:
- android.preference.PreferenceManager (Documentation):
https://developer.android.com/reference/kotlin/android/preference/
PreferenceManager
- androidx.preference.PreferenceManager (Documentation):
https://developer.android.com/reference/androidx/preference/
PreferenceManager

PS: Actually, this 'WordPress' module was already using the
'androidx.preference.PreferenceManager' class instead of the
deprecated 'android.preference.PreferenceManager' class here and there,
hence it being defined as a dependency on this module already.
@ParaskP7 ParaskP7 added this to the 20.9 milestone Sep 27, 2022
@ParaskP7 ParaskP7 requested review from a team and RenanLukas September 27, 2022 12:12
@ParaskP7 ParaskP7 requested a review from a team as a code owner September 27, 2022 12:12
@ParaskP7 ParaskP7 self-assigned this Sep 27, 2022
@wpmobilebot
Copy link
Copy Markdown
Contributor

Found 1 violations:

The PR caused the following dependency changes:

++--- project :libs:analytics
+|    \--- androidx.preference:preference:1.1.0 (*)
+\--- project :libs:editor
+     \--- androidx.preference:preference:1.1.0 (*)

Please review and act accordingly

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Sep 27, 2022

WordPress📲 You can test these changes on WordPress by downloading wordpress-installable-build-pr17215-dcfb3d1.apk
💡 Scan this QR code with your Android phone to download and install the APK directly on it.
AppWordPress
Build FlavorJalapeno
Build TypeDebug
Commitdcfb3d1
Note: This installable build uses the JalapenoDebug build flavor, and does not support Google Login.

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Sep 27, 2022

Jetpack📲 You can test these changes on Jetpack by downloading jetpack-installable-build-pr17215-dcfb3d1.apk
💡 Scan this QR code with your Android phone to download and install the APK directly on it.
AppJetpack
Build FlavorJalapeno
Build TypeDebug
Commitdcfb3d1
Note: This installable build uses the JalapenoDebug build flavor, and does not support Google Login.

After updating the 'android.preference.PreferenceManager' import to
'androidx.preference.PreferenceManager' the below
'java.lang.ClassCastException' started appearing on 'EditPostActivity':
org.wordpress.android.ui.prefs.EditTextPreferenceWithValidation
cannot be cast to androidx.preference.Preference

This crash happens because the [PreferenceManager.setDefaultValues(...)]
is instantiating an 'EditTextPreferenceWithValidation' preference, via
the 'R.xml.account_settings' preference file, which is a type of
'android.preference.EditTextPreference' and thus a type of
'android.preference.Preference'. Because 'android.preference.Preference'
is not an 'androidx.preference.Preference', as expected, a class cast
exception is thrown.

As such, reverting the 'androidx.preference.PreferenceManager' change is
the only logical solution, for now, and until a full migration of
'android.preference.Preference' to 'androidx.preference.Preference'
occurs.
@ParaskP7 ParaskP7 changed the title [Compile Warnings As Errors] WordPress Module - Resolve PreferenceManager Deprecated Warnings #17210 [Compile Warnings As Errors] WordPress Module - Resolve PreferenceManager Deprecated Warnings Sep 27, 2022
@AliSoftware AliSoftware modified the milestones: 20.9, 21.0 Oct 3, 2022
@ParaskP7
Copy link
Copy Markdown
Contributor Author

ParaskP7 commented Oct 4, 2022

👋 @RenanLukas !

Apologies for the direct ping, but I wonder if you have the capacity for reviewing and testing this PR. Let me know, and if not, I can assign it to another engineer. I would like to avoid keeping this PR open for much longer, risking it becoming stale.

@ParaskP7
Copy link
Copy Markdown
Contributor Author

👋 @RenanLukas !

As I am seeing you being busy with other priorities I am assigning this PR review to @AjeshRPai for now. Ajesh, let me know if that's okay with you too. I have updated the PR description accordingly. Thank you all for helping out in reviewing, testings and ultimately merging this to trunk. 🙇

@ParaskP7 ParaskP7 requested review from AjeshRPai and removed request for RenanLukas October 10, 2022 08:52
@AjeshRPai
Copy link
Copy Markdown
Contributor

@ParaskP7 Thanks for the ping 👍🏼 . I will review the PR tomorrow. I hope the PR is not urgent. Let me know if a review is needed before that.

@ParaskP7
Copy link
Copy Markdown
Contributor Author

ParaskP7 commented Oct 10, 2022

@ParaskP7 Thanks for the ping 👍🏼 . I will review the PR tomorrow. I hope the PR is not urgent. Let me know if a review is needed before that.

Thank you so much @AjeshRPai ! 🙇

PS: No, this PR is not that urgent, so please feel free to review it when you get some extra time this week. It is just that this needs to be done sooner than later in order to avoid having it become stale.

… into analysis/wordpress-preference-manager-deprecated-warnings

� Conflicts:
�	WordPress/src/main/java/org/wordpress/android/util/analytics/AnalyticsUtils.java
Copy link
Copy Markdown
Contributor

@AjeshRPai AjeshRPai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing me with all the details for the review in the commit messages as well as in the description. 🙌🏼

I have

  • tested the PR by going through the changes in every commit and reading the reference links mentioned in the commit messages and everything LGTM
  • done a smoke testing of the WordPress and everything looks fine here
    • Logcat is showing/hiding the 🔵 Tracked: XYZ related information 🟢
    • New block editor dialogue is shown 🟢
    • Changed Interface language 🟢

Am going to approve but not merge the PR so that anyone from @wordpress-mobile/apps-infrastructure can have a look. Please feel free to merge the PR at your convenience.

@ParaskP7
Copy link
Copy Markdown
Contributor Author

Awesome, thank you so much for reviewing and testing this PR @AjeshRPai, you rock! 🙇 ❤️ 🚀

@ParaskP7 ParaskP7 merged commit 971c18d into trunk Oct 11, 2022
@ParaskP7 ParaskP7 deleted the analysis/wordpress-preference-manager-deprecated-warnings branch October 11, 2022 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler Warnings as Errors - WordPress Module

4 participants