Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Use io.flutter.Build.API_LEVELS rather than android.os.Build.VERSION_CODES #51171

Merged
merged 14 commits into from
Mar 8, 2024

Conversation

dnfield
Copy link
Contributor

@dnfield dnfield commented Mar 4, 2024

Updates the linting script to ban the use of VERSION_CODES.

We currently have a mish-mash of using the integers, using VERSION_CODES, and even how we import the version codes. This makes it more confusing when doing things like #51070 - I think it is clearer to see 22 than LOLLIPOP_MR1.

I'd like to get LGTM (or at least no opinion) from all the requested reviewers here.

Copy link
Contributor

@matanlurey matanlurey left a comment

Choose a reason for hiding this comment

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

As long as we're consistent one way or another (and it works with our linting strategy), I'm LGTM.

Copy link
Member

@gmackall gmackall left a comment

Choose a reason for hiding this comment

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

I'm fine with either way (but agreed we should have only one way). I find the integers more readable but I also like that the codes are more easily searchable

Copy link
Contributor

@camsim99 camsim99 left a comment

Choose a reason for hiding this comment

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

Also LGTM! Glad to have something consistent moving forward.

@johnmccutchan
Copy link
Contributor

This seems like a step backwards in terms of code readability.

Before: "Build.VERSION_FOO"
After: "18"

We lose our ability to search for something meaningful.

Why are we making this change?

At the very least, why don't we introduce our own "AndroidBuild.VERSION_N" for all N and use that instead of the raw integer?

Copy link
Contributor

@johnmccutchan johnmccutchan left a comment

Choose a reason for hiding this comment

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

See my comment on the issue.

@dnfield
Copy link
Contributor Author

dnfield commented Mar 5, 2024

At the very least, why don't we introduce our own "AndroidBuild.VERSION_N" for all N and use that instead of the raw integer?

I think this works for me - but I'd want the raw integer in there, e.g. io.flutter.Build.VERSION_CODES.API_24, not whatever the Android team decided to use as a maybe single letter or maybe whole word or maybe service release code in a given year.

@dnfield
Copy link
Contributor Author

dnfield commented Mar 5, 2024

I have two reasons for wanting this change:

  1. Consistency. Right now we use a mixture of integers and VERSION_CODES. We also use different style for how we import the version codes.
  2. The numbers correspond to what the Android docs actually use - e.g. they will say Introduced in API 28, not Introduced in Android P.
  3. It will be harder to lint that we do not use integers and keep introducing the inconsistency - although we could at least lint that you use our special class and not the VERSION_CODES class from Android.

Copy link
Member

@gmackall gmackall left a comment

Choose a reason for hiding this comment

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

LGTM! Glad we found a solution that maximizes both searchability and readability

@johnmccutchan
Copy link
Contributor

Thanks for making my requested changes @dnfield

@dnfield dnfield requested a review from johnmccutchan March 5, 2024 23:55

/** A replacement of utilities from android.os.Build. */
public class Build {
/** For use in place of the Android VERSION CODES class. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Rewrite the comment so if someone searched for the official class they would find this:

/** For use in place of Build.VERSION_CODES class */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do that, but I'll have to special case the forbidden imports script to allow it in this file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can the linter detect that text is contained inside of a comment?

import android.view.PointerIcon;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import io.flutter.embedding.engine.systemchannels.MouseCursorChannel;
import java.util.HashMap;

/** A mandatory plugin that handles mouse cursor requests. */
@TargetApi(Build.VERSION_CODES.N)
@RequiresApi(Build.VERSION_CODES.N)
@TargetApi(24)
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix here and below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I lost track of what these were - I'll update them all.

@@ -134,8 +136,8 @@ private void cacheResolveInfos() {
* <p>When an activity does not return a value. the request is completed successfully and returns
* null.
*/
@TargetApi(Build.VERSION_CODES.M)
@RequiresApi(Build.VERSION_CODES.M)
@TargetApi(23)
Copy link
Contributor

Choose a reason for hiding this comment

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

fix here and below

@@ -789,8 +791,8 @@ private void releaseAccessibilityNodeProvider() {
// -------- Start: Mouse -------

@Override
@TargetApi(Build.VERSION_CODES.N)
@RequiresApi(Build.VERSION_CODES.N)
@TargetApi(24)
Copy link
Contributor

Choose a reason for hiding this comment

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

fix here and here

@@ -253,7 +255,7 @@ private void closeCurrentImage() {

@TargetApi(29)
Copy link
Contributor

Choose a reason for hiding this comment

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

fix

@@ -25,7 +26,7 @@

@Config(
manifest = Config.NONE,
minSdk = 24,
minSdk = API_LEVELS.API_24,
shadows = {})
@RunWith(AndroidJUnit4.class)
@TargetApi(24)
Copy link
Contributor

Choose a reason for hiding this comment

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

fix

@@ -24,10 +23,10 @@

@Config(manifest = Config.NONE)
@RunWith(AndroidJUnit4.class)
@TargetApi(P)
@TargetApi(28)
Copy link
Contributor

Choose a reason for hiding this comment

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

fix

@@ -36,8 +35,8 @@
import org.mockito.ArgumentCaptor;

@RunWith(AndroidJUnit4.class)
@TargetApi(Build.VERSION_CODES.N)
@RequiresApi(Build.VERSION_CODES.N)
@TargetApi(24)
Copy link
Contributor

Choose a reason for hiding this comment

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

fix here and below

@dnfield dnfield requested a review from johnmccutchan March 6, 2024 03:33
@dnfield dnfield changed the title Use integer version codes rather than Build.VERSION_CODES Use io.flutter.Build.API_LEVELS rather than android.os.Build.VERSION_CODES Mar 6, 2024
@@ -81,7 +82,7 @@ public void itDescribesNonTextFieldsWithAContentDescription() {
}

@Config(sdk = 28)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think all the @config values in this file should change to API_LEVELS.*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -82,7 +81,7 @@ public void testRotatedMediaSurface_270() throws Exception {
}

@Test
@SdkSuppress(minSdkVersion = VERSION_CODES.M)
@SdkSuppress(minSdkVersion = 23)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these not API_LEVELS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

FLUTTER_LOG_CLASS) or CheckBadFiles(
bad_trace_files, 'android[x].tracing.Trace', FLUTTER_TRACE_CLASS
) or CheckBadFiles(
bad_version_codes_files, 'android.os.Build.VERSION_CODES',
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding either a description here or a pointer to why these are considered bad files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some comments.

@dnfield dnfield added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 8, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 8, 2024
Copy link
Contributor

auto-submit bot commented Mar 8, 2024

auto label is removed for flutter/engine/51171, due to - The status or check suite Linux linux_android_debug_engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@dnfield dnfield added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 8, 2024
@auto-submit auto-submit bot merged commit e099277 into flutter:main Mar 8, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 8, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Mar 8, 2024
…144844)

flutter/engine@05fdf94...e099277

2024-03-08 [email protected] Use `io.flutter.Build.API_LEVELS` rather than `android.os.Build.VERSION_CODES` (flutter/engine#51171)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants