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

Update minSdkVersion (from 21 to 24) #2564

Merged
merged 11 commits into from
Nov 16, 2022
Merged

Conversation

ParaskP7
Copy link
Contributor

@ParaskP7 ParaskP7 commented Nov 8, 2022

This PR upgrades FluxC to minSdkVersion to 24. This has been unblocked because:

  • WPAndroid was already on minSdkVersion = 24, for some time now (see here).
  • WCAndroid has been recently upgraded to minSdkVersion = 24 as well (see here).

Warning (⚠️): This update is currently blocked by the common upgrade of targetSdkVersion to 31 (see here).


As part of this minSdkVersion = 24 upgrade the below changes were also applied in order to fix any additional warnings that this change brought-up:

Warnings Resolution List:

  1. Resolve obsolete sdk int lint warning for well sql config.
  2. Resolve obsolete sdk int lint warning for open jdk cookie mng.
  3. Resolve obsolete sdk int lint warning for leaderboard prd item.
  4. Resolve obsolete sdk int lint warning for mocked statck test.

PS: @hichamboushaba @ovitrif I added you as the main reviewers, that is, in addition to the @wordpress-mobile/apps-infrastructure team itself, but randomly, since I just wanted someone from both, the WordPress and Woo Commerce teams, to sign-off on that change for WPAndroid and WCAndroid alike.


Testing instructions

  • There is nothing much to test here.
  • Verifying that all the CI checks are successful should be enough.
  • However, if you want to be thorough about reviewing this change, you could:
    • Quickly smoke test the FluxC Example app and see if it works as expected.
    • Try and install the FluxC Example app on Android 5 (API 21/22) and Android 6 (API 23) devices and verify that you can't (see API Levels).

Merge instructions

  • Wait for Update targetSdkVersion (from 22 to 31) #2563 to be approved and merged to trunk.
  • Make sure this PR's base is automatically updated to trunk.
  • Update PR with latest trunk.
  • Remove [PR] Not Ready For Merge] label.
  • Merge PR to trunk.

Although the 'assemble' and 'lint' task run successfully, a quick
analysis showed that updating to 'minSdkVersion = 24' added/removed the
below extra warnings:

Lint Warnings:
- +2 x ObsoleteSdkInt (plugins:woocommerce)

All these newly created warnings will be dealt with in subsequent
commits. Also, any existing such warnings will be resolved too.
Warning Message: "Unnecessary; SDK_INT is always >= 24"

This 'VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN' check was, and
is, no longer necessary as the 'minSdkVersion' is now '24'.
Warning Message: "Unnecessary; SDK_INT is always >= 24"

This 'VERSION.SDK_INT >= Build.VERSION_CODES.N' check is no longer
necessary as the 'minSdkVersion' is now '24'. As such, the if condition
has been simplified.
Warning Message: "Unnecessary; SDK_INT is always >= 24"

Both, this '@RequiresApi(VERSION_CODES.N)' annotation and
'VERSION.SDK_INT >= Build.VERSION_CODES.N' check, are no longer
necessary as the 'minSdkVersion' is now '24'.
Warning Message: "Unnecessary; SDK_INT is always >= 24"

This 'assumeTrue(Build.VERSION.SDK_INT >= 23)' test assertion is no
longer necessary as the 'minSdkVersion' is now '24'.
Copy link
Member

@hichamboushaba hichamboushaba left a comment

Choose a reason for hiding this comment

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

Looks good, thanks @ParaskP7 for working on this.
I left one comment, but it's not blocking, so I'm pre-approving.

Comment on lines 176 to 178
private fun fromHtmlWithSafeApiCall(source: String?) = source?.let {
Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY)
} ?: Html.fromHtml(source)
Copy link
Member

Choose a reason for hiding this comment

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

I think we can simplify this function by removing the call to the parameterless fromHtml, as it's equivalent to the other one using FROM_HTML_MODE_LEGACY: https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String). This was necessary before because of the takeIf, but not anymore I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, thanks for the comment @hichamboushaba ! I agree, the cleaner the better, I'll apply this change and let you know as soon as I push its commit. 🙇

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👋 @hichamboushaba !

This is now done, see ba0b906 and 8637d1c.

You will note that I went a bit further and tried to also resolve the Deprecated warning, but I only could go as far as doing so for 1/3 of those. You will find further detail in the commit description itself. Let me know what you think and thank you! 🙇

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @ParaskP7 for making the changes 🙏 , I left some comments below.
All of this is minor, so no need for spending too much time on it 🙂.

@ParaskP7
Copy link
Contributor Author

ParaskP7 commented Nov 9, 2022

Thank you so much for reviewing and testing this PR @hichamboushaba , you rock! 🙏

This 'fromHtmlWithSafeApiCall(...)' function served a purpose only when
it was combined with `takeIf`. However, now that this was removed due to
the 'minSdkVersion = 24' upgrade, this whole function is no longer
necessary and can be replaced with a direct 'Html.fromHtml(...)' call.
Replacing 'Html.fromHtml(html)' with the
'HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY)' compat
related version is the recommended action to resolve this kind of Lint
warnings.

However, note that this was only possible for 'priceAmountHtmlTag'.
Doing the same for the other two, 'priceAmountHtmlTag' and
'itemHtmlTag', isn't possible as those fields can end up being nullable,
that is, due to the fact that the 'LeaderboardItemRow.display'
constructor argument is nullable as well. As such, and because
'HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY)' accepts a
non-null String 'source', it is not possible to resolve these two Lint
warnings.
@@ -84,7 +85,7 @@ class LeaderboardProductItem(
?.split(";")
?.filter { it.contains("&#") }
?.reduce { total, new -> "$total$new" }
?.run { Html.fromHtml(this) }
?.run { HtmlCompat.fromHtml(this, HtmlCompat.FROM_HTML_MODE_LEGACY) }
Copy link
Member

Choose a reason for hiding this comment

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

np, you don't have to change it.
HtmlCompat is useful only for apps with minSdk less than 24, for us, we can directly call the method that was introduced in API 24 https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String,%20int)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thank you @hichamboushaba , you are totally right, I somehow got afraid of the fact that the String source is neither marked @NonNull nor @Nullable on the Html.java side and thus didn't want to make this change, but that doesn't matter, you have to trust that it works for @Nullable just like that as it anyways defaults to using the same mechanism underneath.

Thus, done, this update seems safe and apologies for the trouble with this review (😅): 5acc19a

@@ -150,7 +150,7 @@ class LeaderboardProductItem(
* using the [SpannableStringBuilder] implementation in order to parse it
*/
private val link by lazy {
fromHtmlWithSafeApiCall(itemHtmlTag)
Html.fromHtml(itemHtmlTag)
Copy link
Member

Choose a reason for hiding this comment

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

For using the new API instead of the deprecated one, WDYT about something like this?

itemHtmlTag?.let { Html.fromHtml(it, Html.FROM_HTML_MODE_LEGACY) }
                  ?.run { this as? SpannableStringBuilder }
                 ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👋 @hichamboushaba !

I think maybe this change is enough for now, wdyt? 🤔

PS: I really don't want to change any of the functionality, even by that slight bit, not that it will change much, but you know, you can never be too careful, and then you need to really test that, even if you change that little bit.

Copy link
Member

Choose a reason for hiding this comment

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

Good point, and I think we are safe, when the argument is null, we were already calling Html#fromHtml(String) which proxies the call to the same function we are using now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, once more, thank YOU Hicham ! 🙇

As correctly noted 'HtmlCompat' is only useful for apps with
`minSdkVersion` less than '24', thus it is now unneeded and can be
completely replaced with the direct usage of 'Html'.

See discussion here: https://github.com/wordpress-mobile/
WordPress-FluxC-Android/pull/2564#discussion_r1018958379
Copy link
Contributor

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

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

Changes LGTM 🎉

Though I wonder with regards to the existing discussion here, in WPAndroid we always use HtmlCompat, yet minSdkVersion is 24, isn't it then in fact not necessary? 😅

@ParaskP7
Copy link
Contributor Author

Thank you for the review and testing @ovitrif ! 🙇 ❤️ 🚀

Though I wonder with regards to the existing discussion here, in WPAndroid we always use HtmlCompat, yet minSdkVersion is 24, isn't it then in fact not necessary? 😅

Yeap, yeap, this is indeed the case, I just copy-pasted my solution from WCAndroid into WPAndroid, and since I used HtmlCompat there, I used it blindly as is on WPAndroid as well. But this is indeed not necessary and we could optimize on it. 💯

PS: Feel free to do a quick PR on it if you like, else I'll get to that at some point myself. 👍

Base automatically changed from build/update-target-sdk-version-to-31 to trunk November 16, 2022 13:36
…ndroid into build/update-min-sdk-version-to-24

� Conflicts:
�	settings.gradle
This is done once more, due to the fact that a merge conflict resulting
in that update being lost.
Since the 'targetSdkVersion' has been now update to point to '31',
disabling this 'ExpiredTargetSdkVersion' Lint error is no longer
necessary.
@ParaskP7 ParaskP7 merged commit 5a4f813 into trunk Nov 16, 2022
@ParaskP7 ParaskP7 deleted the build/update-min-sdk-version-to-24 branch November 16, 2022 14:17
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.

3 participants