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] Fix Java lints in camerax version #3966

Merged
merged 3 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/camera/camera_android_camerax/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.0+2

* Fixes Java lints.

## 0.5.0+1

* Update `README.md` to include known duplicate Kotlin classes issue.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ android {
checkAllWarnings true
warningsAsErrors true
disable 'AndroidGradlePluginVersion', 'GradleDependency', 'InvalidPackage'
baseline file("lint-baseline.xml")
}
}

Expand Down
1,434 changes: 0 additions & 1,434 deletions packages/camera/camera_android_camerax/android/lint-baseline.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.app.Activity;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.LifecycleOwner;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
Expand All @@ -24,12 +25,12 @@ public final class CameraAndroidCameraxPlugin implements FlutterPlugin, Activity
private VideoCaptureHostApiImpl videoCaptureHostApiImpl;
private ImageAnalysisHostApiImpl imageAnalysisHostApiImpl;
private ImageCaptureHostApiImpl imageCaptureHostApiImpl;
public SystemServicesHostApiImpl systemServicesHostApiImpl;
public @Nullable SystemServicesHostApiImpl systemServicesHostApiImpl;

@VisibleForTesting @NonNull
public ProcessCameraProviderHostApiImpl processCameraProviderHostApiImpl;
@VisibleForTesting
public @Nullable ProcessCameraProviderHostApiImpl processCameraProviderHostApiImpl;

@VisibleForTesting @NonNull public LiveDataHostApiImpl liveDataHostApiImpl;
@VisibleForTesting public @Nullable LiveDataHostApiImpl liveDataHostApiImpl;

/**
* Initialize this within the {@code #configureFlutterEngine} of a Flutter activity or fragment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

package io.flutter.plugins.camerax;

import androidx.annotation.NonNull;
import androidx.camera.core.Camera;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraFlutterApi;

public class CameraFlutterApiImpl extends CameraFlutterApi {
private final InstanceManager instanceManager;
private final @NonNull InstanceManager instanceManager;

public CameraFlutterApiImpl(BinaryMessenger binaryMessenger, InstanceManager instanceManager) {
public CameraFlutterApiImpl(
@NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
super(binaryMessenger);
this.instanceManager = instanceManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

package io.flutter.plugins.camerax;

import androidx.annotation.NonNull;
import androidx.camera.core.CameraInfo;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraInfoFlutterApi;

public class CameraInfoFlutterApiImpl extends CameraInfoFlutterApi {
private final InstanceManager instanceManager;
private final @NonNull InstanceManager instanceManager;

public CameraInfoFlutterApiImpl(
BinaryMessenger binaryMessenger, InstanceManager instanceManager) {
@NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
super(binaryMessenger);
this.instanceManager = instanceManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class CameraInfoHostApiImpl implements CameraInfoHostApi {
private final BinaryMessenger binaryMessenger;
private final InstanceManager instanceManager;

@VisibleForTesting public LiveDataFlutterApiWrapper liveDataFlutterApiWrapper;
@VisibleForTesting public @NonNull LiveDataFlutterApiWrapper liveDataFlutterApiWrapper;

public CameraInfoHostApiImpl(
@NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.Manifest.permission;
import android.app.Activity;
import android.content.pm.PackageManager;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
Expand Down Expand Up @@ -99,7 +100,8 @@ static final class CameraRequestPermissionsListener
}

@Override
public boolean onRequestPermissionsResult(int id, String[] permissions, int[] grantResults) {
public boolean onRequestPermissionsResult(
int id, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (alreadyCalled || id != CAMERA_REQUEST_ID) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package io.flutter.plugins.camerax;

import androidx.annotation.NonNull;
import androidx.camera.core.CameraSelector;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraSelectorFlutterApi;
Expand All @@ -12,7 +13,7 @@ public class CameraSelectorFlutterApiImpl extends CameraSelectorFlutterApi {
private final InstanceManager instanceManager;

public CameraSelectorFlutterApiImpl(
BinaryMessenger binaryMessenger, InstanceManager instanceManager) {
@NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
super(binaryMessenger);
this.instanceManager = instanceManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package io.flutter.plugins.camerax;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.camera.core.CameraInfo;
import androidx.camera.core.CameraSelector;
Expand All @@ -18,16 +19,16 @@ public class CameraSelectorHostApiImpl implements CameraSelectorHostApi {
private final BinaryMessenger binaryMessenger;
private final InstanceManager instanceManager;

@VisibleForTesting public CameraXProxy cameraXProxy = new CameraXProxy();
@VisibleForTesting public @NonNull CameraXProxy cameraXProxy = new CameraXProxy();

public CameraSelectorHostApiImpl(
BinaryMessenger binaryMessenger, InstanceManager instanceManager) {
@NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
this.binaryMessenger = binaryMessenger;
this.instanceManager = instanceManager;
}

@Override
public void create(@NonNull Long identifier, Long lensFacing) {
public void create(@NonNull Long identifier, @Nullable Long lensFacing) {
CameraSelector.Builder cameraSelectorBuilder = cameraXProxy.createCameraSelectorBuilder();
if (lensFacing != null) {
cameraSelectorBuilder = cameraSelectorBuilder.requireLensFacing(lensFacing.intValue());
Expand All @@ -36,10 +37,10 @@ public void create(@NonNull Long identifier, Long lensFacing) {
}

@Override
public List<Long> filter(@NonNull Long identifier, @NonNull List<Long> cameraInfoIds) {
public @NonNull List<Long> filter(@NonNull Long identifier, @NonNull List<Long> cameraInfoIds) {
CameraSelector cameraSelector =
(CameraSelector) Objects.requireNonNull(instanceManager.getInstance(identifier));
List<CameraInfo> cameraInfosForFilter = new ArrayList<CameraInfo>();
List<CameraInfo> cameraInfosForFilter = new ArrayList<>();

for (Number cameraInfoAsNumber : cameraInfoIds) {
Long cameraInfoId = cameraInfoAsNumber.longValue();
Expand All @@ -50,7 +51,7 @@ public List<Long> filter(@NonNull Long identifier, @NonNull List<Long> cameraInf
}

List<CameraInfo> filteredCameraInfos = cameraSelector.filter(cameraInfosForFilter);
List<Long> filteredCameraInfosIds = new ArrayList<Long>();
List<Long> filteredCameraInfosIds = new ArrayList<>();

for (CameraInfo cameraInfo : filteredCameraInfos) {
Long filteredCameraInfoId = instanceManager.getIdentifierForStrongReference(cameraInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,35 @@ public class CameraXProxy {
* Converts a {@link ResolutionInfo} instance to a {@link Size} for setting the target resolution
* of {@link UseCase}s.
*/
public static Size sizeFromResolution(@NonNull ResolutionInfo resolutionInfo) {
public static @NonNull Size sizeFromResolution(@NonNull ResolutionInfo resolutionInfo) {
return new Size(resolutionInfo.getWidth().intValue(), resolutionInfo.getHeight().intValue());
}

public CameraSelector.Builder createCameraSelectorBuilder() {
public @NonNull CameraSelector.Builder createCameraSelectorBuilder() {
return new CameraSelector.Builder();
}

/** Creates an instance of {@link CameraPermissionsManager}. */
public CameraPermissionsManager createCameraPermissionsManager() {
public @NonNull CameraPermissionsManager createCameraPermissionsManager() {
return new CameraPermissionsManager();
}

/** Creates an instance of the {@link DeviceOrientationManager}. */
public DeviceOrientationManager createDeviceOrientationManager(
public @NonNull DeviceOrientationManager createDeviceOrientationManager(
@NonNull Activity activity,
@NonNull Boolean isFrontFacing,
@NonNull int sensorOrientation,
int sensorOrientation,
@NonNull DeviceOrientationManager.DeviceOrientationChangeCallback callback) {
return new DeviceOrientationManager(activity, isFrontFacing, sensorOrientation, callback);
}

/** Creates a builder for an instance of the {@link Preview} use case. */
public Preview.Builder createPreviewBuilder() {
public @NonNull Preview.Builder createPreviewBuilder() {
return new Preview.Builder();
}

/** Creates a {@link Surface} instance from the specified {@link SurfaceTexture}. */
public Surface createSurface(@NonNull SurfaceTexture surfaceTexture) {
public @NonNull Surface createSurface(@NonNull SurfaceTexture surfaceTexture) {
return new Surface(surfaceTexture);
}

Expand All @@ -62,7 +62,7 @@ public Surface createSurface(@NonNull SurfaceTexture surfaceTexture) {
* <p>Included in this class to utilize the callback methods it provides, e.g. {@code
* onCameraError(String)}.
*/
public SystemServicesFlutterApiImpl createSystemServicesFlutterApiImpl(
public @NonNull SystemServicesFlutterApiImpl createSystemServicesFlutterApiImpl(
@NonNull BinaryMessenger binaryMessenger) {
return new SystemServicesFlutterApiImpl(binaryMessenger);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.view.Surface;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import io.flutter.embedding.engine.systemchannels.PlatformChannel;
import io.flutter.embedding.engine.systemchannels.PlatformChannel.DeviceOrientation;
Expand Down Expand Up @@ -106,7 +107,7 @@ public int getPhotoOrientation() {
* into degrees.
* @return The device's photo orientation in degrees.
*/
public int getPhotoOrientation(PlatformChannel.DeviceOrientation orientation) {
public int getPhotoOrientation(@Nullable PlatformChannel.DeviceOrientation orientation) {
int angle = 0;
// Fallback to device orientation when the orientation value is null.
if (orientation == null) {
Expand Down Expand Up @@ -163,7 +164,7 @@ public int getVideoOrientation() {
* into degrees.
* @return The device's video orientation in clockwise degrees.
*/
public int getVideoOrientation(PlatformChannel.DeviceOrientation orientation) {
public int getVideoOrientation(@Nullable PlatformChannel.DeviceOrientation orientation) {
int angle = 0;

// Fallback to device orientation when the orientation value is null.
Expand Down Expand Up @@ -194,7 +195,7 @@ public int getVideoOrientation(PlatformChannel.DeviceOrientation orientation) {
}

/** @return the last received UI orientation. */
public PlatformChannel.DeviceOrientation getLastUIOrientation() {
public @Nullable PlatformChannel.DeviceOrientation getLastUIOrientation() {
return this.lastOrientation;
}

Expand Down Expand Up @@ -236,6 +237,8 @@ static void handleOrientationChange(
*
* @return The current user interface orientation.
*/
// Configuration.ORIENTATION_SQUARE is deprecated.
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this no longer is supported or used, could you go ahead and delete that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that then we get a lint about missing coverage in the switch, and if I suppress that instead of deprecation then we won't get notified via lints if new orientation values are added in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh gotcha!

@SuppressWarnings("deprecation")
@VisibleForTesting
PlatformChannel.DeviceOrientation getUIOrientation() {
final int rotation = getDisplay().getRotation();
Expand All @@ -254,6 +257,8 @@ PlatformChannel.DeviceOrientation getUIOrientation() {
} else {
return PlatformChannel.DeviceOrientation.LANDSCAPE_RIGHT;
}
case Configuration.ORIENTATION_SQUARE:
case Configuration.ORIENTATION_UNDEFINED:
default:
return PlatformChannel.DeviceOrientation.PORTRAIT_UP;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ImageCaptureHostApiImpl implements ImageCaptureHostApi {
public static final String TEMPORARY_FILE_NAME = "CAP";
public static final String JPG_FILE_TYPE = ".jpg";

@VisibleForTesting public CameraXProxy cameraXProxy = new CameraXProxy();
@VisibleForTesting public @NonNull CameraXProxy cameraXProxy = new CameraXProxy();

public ImageCaptureHostApiImpl(
@NonNull BinaryMessenger binaryMessenger,
Expand All @@ -42,7 +42,7 @@ public ImageCaptureHostApiImpl(
* Sets the context that the {@link ImageCapture} will use to find a location to save a captured
* image.
*/
public void setContext(Context context) {
public void setContext(@NonNull Context context) {
this.context = context;
}

Expand Down Expand Up @@ -101,7 +101,7 @@ public void takePicture(

/** Creates a callback used when saving a captured image. */
@VisibleForTesting
public ImageCapture.OnImageSavedCallback createOnImageSavedCallback(
public @NonNull ImageCapture.OnImageSavedCallback createOnImageSavedCallback(
@NonNull File file, @NonNull GeneratedCameraXLibrary.Result<String> result) {
return new ImageCapture.OnImageSavedCallback() {
@Override
Expand Down
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public interface FinalizationListener {
* @return a new `InstanceManager`.
*/
@NonNull
public static InstanceManager create(FinalizationListener finalizationListener) {
public static InstanceManager create(@NonNull FinalizationListener finalizationListener) {
return new InstanceManager(finalizationListener);
}

Expand Down Expand Up @@ -109,7 +109,7 @@ public <T> T remove(long identifier) {
* `null` if the manager doesn't contain the value.
*/
@Nullable
public Long getIdentifierForStrongReference(Object instance) {
public Long getIdentifierForStrongReference(@NonNull Object instance) {
logWarningIfFinalizationListenerHasStopped();

final Long identifier = identifiers.get(instance);
Expand All @@ -130,7 +130,7 @@ public Long getIdentifierForStrongReference(Object instance) {
* @param identifier the identifier to be paired with instance. This value must be >= 0 and
* unique.
*/
public void addDartCreatedInstance(Object instance, long identifier) {
public void addDartCreatedInstance(@NonNull Object instance, long identifier) {
logWarningIfFinalizationListenerHasStopped();
addInstance(instance, identifier);
}
Expand All @@ -141,7 +141,7 @@ public void addDartCreatedInstance(Object instance, long identifier) {
* @param instance the instance to be stored. This must be unique to all other added instances.
* @return the unique identifier (>= 0) stored with instance.
*/
public long addHostCreatedInstance(Object instance) {
public long addHostCreatedInstance(@NonNull Object instance) {
logWarningIfFinalizationListenerHasStopped();

if (containsInstance(instance)) {
Expand Down Expand Up @@ -178,7 +178,7 @@ public <T> T getInstance(long identifier) {
* @param instance the instance whose presence in this manager is to be tested.
* @return whether this manager contains the given `instance`.
*/
public boolean containsInstance(Object instance) {
public boolean containsInstance(@NonNull Object instance) {
logWarningIfFinalizationListenerHasStopped();
return identifiers.containsKey(instance);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class JavaObjectHostApiImpl implements JavaObjectHostApi {
*
* @param instanceManager maintains instances stored to communicate with Dart objects
*/
public JavaObjectHostApiImpl(InstanceManager instanceManager) {
public JavaObjectHostApiImpl(@NonNull InstanceManager instanceManager) {
this.instanceManager = instanceManager;
}

Expand Down
Loading