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

[camera_android] Fix Android lint warnings #3716

Merged
merged 7 commits into from
Apr 21, 2023

Conversation

bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Apr 14, 2023

Removes the lint-baseline.xml file, and fixes all issues.

The KotlinPropertyAccess doesn't seem to work well with generics. For example,

class CameraFeature<T> {
  T getValue();
}

class ExposureFeature extends CameraFeature<Exposure> {
  @Override
  Exposure getValue() {
    ...
  }
}

The ExposureFeature.getValue causes the lint warning. I went ahead and suppressed this for all CameraFeatures.

I also added @Nonnull or @Nullable to some private fields that weren't required. This helped deduce whether a value was always nonnull or not.

Part of flutter/flutter#88011

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@bparrishMines bparrishMines requested a review from camsim99 as a code owner April 14, 2023 18:02
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@@ -97,11 +97,6 @@ private void maybeStartListening(
BinaryMessenger messenger,
PermissionsRegistry permissionsRegistry,
TextureRegistry textureRegistry) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

min version is 21 already

Copy link
Contributor Author

@bparrishMines bparrishMines Apr 14, 2023

Choose a reason for hiding this comment

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

Went through https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics to verify which could or could not be nullable.

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.

The changes seem reasonable! Just left one question about a deprecation warning suppression

EGL14.EGL_NONE
};
int[] attribList;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch!

@@ -260,6 +265,8 @@ PlatformChannel.DeviceOrientation getUIOrientation() {
} else {
return PlatformChannel.DeviceOrientation.LANDSCAPE_RIGHT;
}
case Configuration.ORIENTATION_SQUARE:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this if it is deprecated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's deprecated, but there was a warning for missing a case:

/Users/bmparr/Development/packages/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManager.java:255: Error: Switch statement on an int with known associated constant missing case Configuration.ORIENTATION_SQUARE [SwitchIntDef]
    switch (orientation) {
    ~~~~~~

The alternative was to suppress the warning that not all of the cases were handled. I thought this would be worse since it wouldn't notify us when a new one was added.

@stuartmorgan
Copy link
Contributor

I also added @Nonnull or @Nullable to some private fields that weren't required. This helped deduce whether a value was always nonnull or not.

Yeah, I've run into that too; I wish we could make it a warning everywhere just for our own benefit.

@@ -27,49 +27,56 @@
* android.hardware.camera2.CaptureRequest}.
*/
public class CameraFeatureFactoryImpl implements CameraFeatureFactory {

@NonNull
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, it doesn't matter where this goes? I would have thought it would need be next to the type (@Override public @NonNull AutoFocusFeature).

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've didn't even know you could put it after the public modifier. But, yea this worked for me. I assumed the same pattern as Dart.

@bparrishMines bparrishMines added autosubmit Merge PR when tree becomes green via auto submit App and removed needs tests labels Apr 20, 2023
@bparrishMines bparrishMines added autosubmit Merge PR when tree becomes green via auto submit App and removed autosubmit Merge PR when tree becomes green via auto submit App labels Apr 21, 2023
@auto-submit auto-submit bot merged commit 9989606 into flutter:main Apr 21, 2023
@bparrishMines bparrishMines deleted the camera_android_lint branch April 21, 2023 20:05
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 24, 2023
pro100andrey added a commit to pro100andrey/packages that referenced this pull request Apr 25, 2023
* main: (144 commits)
  Update test golden images for the latest Skia roll (flutter#3787)
  [various] Adds Android namespace (flutter#3791)
  [shared_preferences] Update gradle/agp in example apps (flutter#3809)
  [go_router] Adds name to TypedGoRoute (flutter#3702)
  [webview_flutter] Adds support to receive permission requests (flutter#3543)
  [google_sign_in] Fix Android Java warnings (flutter#3762)
  [local_auth] Fix enum return on Android (flutter#3780)
  [pigeon] Warn when trying to use enums in collections (flutter#3782)
  [webview_flutter_android] [webview_flutter_wkwebview] Platform implementations for supporting permission requests (flutter#3792)
  [pigeon] Update for compatibility with a future change to the analyzer. (flutter#3789)
  [camera_android] Fix Android lint warnings  (flutter#3716)
  [webview_flutter_platform_interface] Adds method to receive permission requests (flutter#3767)
  [image_picker_ios] In unit test write and read kCGImagePropertyExifUserComment property (flutter#3783)
  [go_router_builder] Fixed the return value of the generated push method (flutter#3650)
  [image_picker] Mention `launchMode: singleInstance` in README (flutter#3759)
  Revert "[pigeon] Add an initial example app" (flutter#3785)
  [google_maps_flutter] Add examples for different iOS versions (flutter#3757)
  [pigeon] Add an initial example app (flutter#3761)
  [google_maps_flutter_web] Allow marker position updates (flutter#3697)
  [Tool] [Code Excerpt] allow excerpts in example readme (flutter#3758)
  ...

# Conflicts:
#	packages/camera/camera/pubspec.yaml
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 1, 2023
Roll Packages from 7e3f5da to de6131d (41 revisions)

flutter/packages@7e3f5da...de6131d

2023-05-01 reidbaker@google.com I122213 update non examples (flutter/packages#3846)
2023-04-29 47866232+chunhtai@users.noreply.github.com [go_router] Cleans up route match API and introduces dart fix (flutter/packages#3819)
2023-04-29 43054281+camsim99@users.noreply.github.com [camerax] Add `LifecycleOwner` Proxy (flutter/packages#3837)
2023-04-29 stuartmorgan@google.com [file_selector] Add getDirectoryPaths implementation for Windows (flutter/packages#3704)
2023-04-29 stuartmorgan@google.com [various] Update Android example min SDKs (flutter/packages#3847)
2023-04-28 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 2.2.12 to 2.3.2 (flutter/packages#3838)
2023-04-28 43054281+camsim99@users.noreply.github.com [camerax] Implement Image Streaming (flutter/packages#3454)
2023-04-28 reidbaker@google.com [various] update agp and gradle for all examples in packages (flutter/packages#3822)
2023-04-28 54558023+keyonghan@users.noreply.github.com Update xcode to 14c18 (flutter/packages#3774)
2023-04-28 andrewjohncoutts@gmail.com [camera_android] Add NV21 as an image stream format #3277 (flutter/packages#3639)
2023-04-28 gautier.bayzelon@gmail.com [go_router] Remove unused navigator keys (flutter/packages#3708)
2023-04-28 JeroenWeener@users.noreply.github.com [image_picker] Move I/O operations to a separate thread (flutter/packages#3506)
2023-04-28 49699333+dependabot[bot]@users.noreply.github.com [pigeon]: Bump org.jetbrains.kotlin:kotlin-gradle-plugin from 1.8.20 to 1.8.21 in /packages/pigeon/platform_tests/test_plugin/android (flutter/packages#3824)
2023-04-28 stuartmorgan@google.com [pigeon] Reland: Add an initial example app (flutter/packages#3832)
2023-04-28 engine-flutter-autoroll@skia.org Roll Flutter from c9004ff to 66fa4c5 (68 revisions) (flutter/packages#3830)
2023-04-28 stuartmorgan@google.com [various] Conditionalize the namespace in all Android plugins (flutter/packages#3836)
2023-04-27 49699333+dependabot[bot]@users.noreply.github.com [in_app_pur]: Bump com.android.billingclient:billing from 5.1.0 to 5.2.0 in /packages/in_app_purchase/in_app_purchase_android/android (flutter/packages#3672)
2023-04-27 ychris@google.com [auick_action_ios] Retries multiple times to not fail ci when there is a flake (flutter/packages#3823)
2023-04-26 magder@google.com Swap some iOS package CODEOWNERS (flutter/packages#3793)
2023-04-26 stuartmorgan@google.com [various] Add `targetCompatibility` to build.gradle (flutter/packages#3825)
2023-04-26 stuartmorgan@google.com [various] Set cmake_policy versions (flutter/packages#3828)
2023-04-26 stuartmorgan@google.com [path_provider] Allow `win32` up to version 4.x (flutter/packages#3820)
2023-04-26 stuartmorgan@google.com [tool] Move Android lint checks (flutter/packages#3816)
2023-04-25 evace93@gmail.com [google_maps_flutter_android] Fix Android lint warnings (flutter/packages#3751)
2023-04-25 49699333+dependabot[bot]@users.noreply.github.com [in_app_pur]: Bump androidx.annotation:annotation from 1.5.0 to 1.6.0 in /packages/in_app_purchase/in_app_purchase_android/android (flutter/packages#3381)
2023-04-25 jason-simmons@users.noreply.github.com Update test golden images for the latest Skia roll (flutter/packages#3787)
2023-04-25 stuartmorgan@google.com [various] Adds Android namespace (flutter/packages#3791)
2023-04-25 reidbaker@google.com [shared_preferences] Update gradle/agp in example apps (flutter/packages#3809)
2023-04-24 43640732+dancamdev@users.noreply.github.com [go_router] Adds name to TypedGoRoute (flutter/packages#3702)
2023-04-22 10687576+bparrishMines@users.noreply.github.com [webview_flutter] Adds support to receive permission requests (flutter/packages#3543)
2023-04-21 stuartmorgan@google.com [google_sign_in] Fix Android Java warnings (flutter/packages#3762)
2023-04-21 stuartmorgan@google.com [local_auth] Fix enum return on Android (flutter/packages#3780)
2023-04-21 stuartmorgan@google.com [pigeon] Warn when trying to use enums in collections (flutter/packages#3782)
2023-04-21 10687576+bparrishMines@users.noreply.github.com [webview_flutter_android] [webview_flutter_wkwebview] Platform implementations for supporting permission requests (flutter/packages#3792)
2023-04-21 scheglov@google.com [pigeon] Update for compatibility with a future change to the analyzer. (flutter/packages#3789)
2023-04-21 10687576+bparrishMines@users.noreply.github.com [camera_android] Fix Android lint warnings  (flutter/packages#3716)
2023-04-21 10687576+bparrishMines@users.noreply.github.com [webview_flutter_platform_interface] Adds method to receive permission requests (flutter/packages#3767)
2023-04-21 magder@google.com [image_picker_ios] In unit test write and read kCGImagePropertyExifUserComment property (flutter/packages#3783)
2023-04-21 widrans@gmail.com [go_router_builder] Fixed the return value of the generated push method (flutter/packages#3650)
2023-04-21 JeroenWeener@users.noreply.github.com [image_picker] Mention `launchMode: singleInstance` in README (flutter/packages#3759)
2023-04-21 stuartmorgan@google.com Revert "[pigeon] Add an initial example app" (flutter/packages#3785)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human
...
nploi pushed a commit to nploi/packages that referenced this pull request Jul 16, 2023
Removes the lint-baseline.xml file, and fixes all issues.

The `KotlinPropertyAccess` doesn't seem to work well with generics. For example,

```java
class CameraFeature<T> {
  T getValue();
}

class ExposureFeature extends CameraFeature<Exposure> {
  @OverRide
  Exposure getValue() {
    ...
  }
}
```

The `ExposureFeature.getValue` causes the lint warning. I went ahead and suppressed this for all `CameraFeatures`.

I also added `@Nonnull` or `@Nullable` to some private fields that weren't required. This helped deduce whether a value was always nonnull or not.

Part of flutter/flutter#88011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: camera platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants