diff --git a/packages/camera/camera_android/CHANGELOG.md b/packages/camera/camera_android/CHANGELOG.md index c4c772bfd608..89514a155755 100644 --- a/packages/camera/camera_android/CHANGELOG.md +++ b/packages/camera/camera_android/CHANGELOG.md @@ -1,6 +1,11 @@ +## 0.10.6 + +* Fixes Java warnings. + ## 0.10.5 * Allows camera to be switched while video recording. + ## 0.10.4+3 * Clarifies explanation of endorsement in README. diff --git a/packages/camera/camera_android/android/build.gradle b/packages/camera/camera_android/android/build.gradle index 8e2775a0e263..d93d06aaf4d3 100644 --- a/packages/camera/camera_android/android/build.gradle +++ b/packages/camera/camera_android/android/build.gradle @@ -38,7 +38,6 @@ android { checkAllWarnings true warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' - baseline file("lint-baseline.xml") } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 diff --git a/packages/camera/camera_android/android/lint-baseline.xml b/packages/camera/camera_android/android/lint-baseline.xml deleted file mode 100644 index b0fc2e758dff..000000000000 --- a/packages/camera/camera_android/android/lint-baseline.xml +++ /dev/null @@ -1,3106 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/Camera.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/Camera.java index 500407009c5a..954458f5d5eb 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/Camera.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/Camera.java @@ -96,7 +96,7 @@ class Camera * Holds all of the camera features/settings and will be used to update the request builder when * one changes. */ - private CameraFeatures cameraFeatures; + CameraFeatures cameraFeatures; private String imageFormatGroup; @@ -116,28 +116,28 @@ class Camera private final ResolutionPreset resolutionPreset; private final boolean enableAudio; private final Context applicationContext; - private final DartMessenger dartMessenger; + final DartMessenger dartMessenger; private CameraProperties cameraProperties; private final CameraFeatureFactory cameraFeatureFactory; private final Activity activity; /** A {@link CameraCaptureSession.CaptureCallback} that handles events related to JPEG capture. */ private final CameraCaptureCallback cameraCaptureCallback; /** A {@link Handler} for running tasks in the background. */ - private Handler backgroundHandler; + Handler backgroundHandler; /** An additional thread for running tasks that shouldn't block the UI. */ private HandlerThread backgroundHandlerThread; - private CameraDeviceWrapper cameraDevice; - private CameraCaptureSession captureSession; + CameraDeviceWrapper cameraDevice; + CameraCaptureSession captureSession; private ImageReader pictureImageReader; - private ImageReader imageStreamReader; + ImageReader imageStreamReader; /** {@link CaptureRequest.Builder} for the camera preview */ - private CaptureRequest.Builder previewRequestBuilder; + CaptureRequest.Builder previewRequestBuilder; private MediaRecorder mediaRecorder; /** True when recording video. */ - private boolean recordingVideo; + boolean recordingVideo; /** True when the preview is paused. */ private boolean pausedPreview; @@ -148,13 +148,13 @@ class Camera /** Holds the last known capture properties */ private CameraCaptureProperties captureProps; - private MethodChannel.Result flutterResult; + MethodChannel.Result flutterResult; /** A CameraDeviceWrapper implementation that forwards calls to a CameraDevice. */ private class DefaultCameraDeviceWrapper implements CameraDeviceWrapper { private final CameraDevice cameraDevice; - private DefaultCameraDeviceWrapper(CameraDevice cameraDevice) { + DefaultCameraDeviceWrapper(CameraDevice cameraDevice) { this.cameraDevice = cameraDevice; } @@ -171,7 +171,6 @@ public void createCaptureSession(SessionConfiguration config) throws CameraAcces cameraDevice.createCaptureSession(config); } - @TargetApi(VERSION_CODES.LOLLIPOP) @SuppressWarnings("deprecation") @Override public void createCaptureSession( @@ -235,9 +234,11 @@ public void onPrecapture() { * * @param requestBuilder request builder to update. */ - private void updateBuilderSettings(CaptureRequest.Builder requestBuilder) { + void updateBuilderSettings(CaptureRequest.Builder requestBuilder) { for (CameraFeature feature : cameraFeatures.getAllFeatures()) { - Log.d(TAG, "Updating builder with feature: " + feature.getDebugName()); + if (BuildConfig.DEBUG) { + Log.d(TAG, "Updating builder with feature: " + feature.getDebugName()); + } feature.updateBuilder(requestBuilder); } } @@ -331,7 +332,9 @@ public void onOpened(@NonNull CameraDevice device) { cameraFeatures.getFocusPoint().checkIsSupported()); } catch (Exception e) { - Log.i(TAG, "open | onOpened error: " + e.getMessage()); + if (BuildConfig.DEBUG) { + Log.i(TAG, "open | onOpened error: " + e.getMessage()); + } dartMessenger.sendCameraErrorEvent(e.getMessage()); close(); } @@ -489,7 +492,6 @@ private void createCaptureSessionWithSessionConfig( callback)); } - @TargetApi(VERSION_CODES.LOLLIPOP) @SuppressWarnings("deprecation") private void createCaptureSession( List surfaces, CameraCaptureSession.StateCallback callback) @@ -498,7 +500,7 @@ private void createCaptureSession( } // Send a repeating request to refresh capture session. - private void refreshPreviewCaptureSession( + void refreshPreviewCaptureSession( @Nullable Runnable onSuccessCallback, @NonNull ErrorCallback onErrorCallback) { Log.i(TAG, "refreshPreviewCaptureSession"); @@ -722,7 +724,7 @@ private void lockAutoFocus() { } /** Cancel and reset auto focus state and refresh the preview session. */ - private void unlockAutoFocus() { + void unlockAutoFocus() { Log.i(TAG, "unlockAutoFocus"); if (captureSession == null) { Log.i(TAG, "[unlockAutoFocus] captureSession null, returning"); @@ -1194,7 +1196,7 @@ public void onCancel(Object o) { }); } - private void setImageStreamImageAvailableListener(final EventChannel.EventSink imageStreamSink) { + void setImageStreamImageAvailableListener(final EventChannel.EventSink imageStreamSink) { imageStreamReader.setOnImageAvailableListener( reader -> { Image img = reader.acquireNextImage(); @@ -1234,7 +1236,7 @@ private void setImageStreamImageAvailableListener(final EventChannel.EventSink i backgroundHandler); } - private void closeCaptureSession() { + void closeCaptureSession() { if (captureSession != null) { Log.i(TAG, "closeCaptureSession"); diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraPlugin.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraPlugin.java index 067ed0295e2e..308d4283aa27 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraPlugin.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraPlugin.java @@ -5,7 +5,6 @@ package io.flutter.plugins.camera; import android.app.Activity; -import android.os.Build; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import io.flutter.embedding.engine.plugins.FlutterPlugin; @@ -45,7 +44,8 @@ public CameraPlugin() {} * won't react to changes in activity or context, unlike {@link CameraPlugin}. */ @SuppressWarnings("deprecation") - public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) { + public static void registerWith( + @NonNull io.flutter.plugin.common.PluginRegistry.Registrar registrar) { CameraPlugin plugin = new CameraPlugin(); plugin.maybeStartListening( registrar.activity(), @@ -97,11 +97,6 @@ private void maybeStartListening( BinaryMessenger messenger, PermissionsRegistry permissionsRegistry, TextureRegistry textureRegistry) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - // If the sdk is less than 21 (min sdk for Camera2) we don't register the plugin. - return; - } - methodCallHandler = new MethodCallHandlerImpl( activity, messenger, new CameraPermissions(), permissionsRegistry, textureRegistry); diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraProperties.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraProperties.java index 7e061a24aabc..2c3eda880deb 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraProperties.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraProperties.java @@ -8,6 +8,8 @@ import android.os.Build.VERSION_CODES; import android.util.Range; import android.util.Size; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; /** An interface allowing access to the different characteristics of the device's camera. */ @@ -18,6 +20,7 @@ public interface CameraProperties { * * @return String The name of the camera device. */ + @NonNull String getCameraName(); /** @@ -30,6 +33,7 @@ public interface CameraProperties { * @return android.util.Range[] List of frame rate ranges supported by this camera * device. */ + @NonNull Range[] getControlAutoExposureAvailableTargetFpsRanges(); /** @@ -43,6 +47,7 @@ public interface CameraProperties { * @return android.util.Range Maximum and minimum exposure compensation supported by this * camera device. */ + @NonNull Range getControlAutoExposureCompensationRange(); /** @@ -64,6 +69,7 @@ public interface CameraProperties { * * @return int[] List of auto-focus modes supported by this camera device. */ + @NonNull int[] getControlAutoFocusAvailableModes(); /** @@ -75,6 +81,7 @@ public interface CameraProperties { * @return Integer Maximum number of metering regions that can be used by the auto-exposure * routine. */ + @NonNull Integer getControlMaxRegionsAutoExposure(); /** @@ -85,6 +92,7 @@ public interface CameraProperties { * * @return Integer Maximum number of metering regions that can be used by the auto-focus routine. */ + @NonNull Integer getControlMaxRegionsAutoFocus(); /** @@ -97,6 +105,7 @@ public interface CameraProperties { * @return int[] List of distortion correction modes supported by this camera device. */ @RequiresApi(api = VERSION_CODES.P) + @Nullable int[] getDistortionCorrectionAvailableModes(); /** @@ -107,6 +116,7 @@ public interface CameraProperties { * * @return Boolean Whether this camera device has a flash unit. */ + @NonNull Boolean getFlashInfoAvailable(); /** @@ -136,6 +146,7 @@ public interface CameraProperties { * @return Float Shortest distance from front most surface of the lens that can be brought into * sharp focus. */ + @Nullable Float getLensInfoMinimumFocusDistance(); /** @@ -148,6 +159,7 @@ public interface CameraProperties { * @return Float Maximum ratio between both active area width and crop region width, and active * area height and crop region height. */ + @NonNull Float getScalerAvailableMaxDigitalZoom(); /** @@ -159,6 +171,7 @@ public interface CameraProperties { * * @return Float Minimum ratio between the default zoom ratio and the minimum possible zoom. */ + @Nullable @RequiresApi(api = VERSION_CODES.R) Float getScalerMinZoomRatio(); @@ -171,6 +184,7 @@ public interface CameraProperties { * * @return Float Maximum ratio between the default zoom ratio and the maximum possible zoom. */ + @Nullable @RequiresApi(api = VERSION_CODES.R) Float getScalerMaxZoomRatio(); @@ -184,6 +198,7 @@ public interface CameraProperties { * @return android.graphics.Rect area of the image sensor which corresponds to active pixels after * any geometric distortion correction has been applied. */ + @NonNull Rect getSensorInfoActiveArraySize(); /** @@ -195,6 +210,7 @@ public interface CameraProperties { * @return android.util.Size Dimensions of the full pixel array, possibly including black * calibration pixels. */ + @NonNull Size getSensorInfoPixelArraySize(); /** @@ -209,6 +225,7 @@ public interface CameraProperties { * to the application of any geometric distortion correction. */ @RequiresApi(api = VERSION_CODES.M) + @NonNull Rect getSensorInfoPreCorrectionActiveArraySize(); /** @@ -254,5 +271,6 @@ public interface CameraProperties { * * @return int[] List of noise reduction modes that are supported by this camera device. */ + @NonNull int[] getAvailableNoiseReductionModes(); } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraPropertiesImpl.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraPropertiesImpl.java index 66bb2901b629..dc8e9b736f2c 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraPropertiesImpl.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraPropertiesImpl.java @@ -12,6 +12,8 @@ import android.util.Range; import android.util.Rational; import android.util.Size; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; /** @@ -22,22 +24,25 @@ public class CameraPropertiesImpl implements CameraProperties { private final CameraCharacteristics cameraCharacteristics; private final String cameraName; - public CameraPropertiesImpl(String cameraName, CameraManager cameraManager) + public CameraPropertiesImpl(@NonNull String cameraName, @NonNull CameraManager cameraManager) throws CameraAccessException { this.cameraName = cameraName; this.cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraName); } + @NonNull @Override public String getCameraName() { return cameraName; } + @NonNull @Override public Range[] getControlAutoExposureAvailableTargetFpsRanges() { return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES); } + @NonNull @Override public Range getControlAutoExposureCompensationRange() { return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE); @@ -51,27 +56,32 @@ public double getControlAutoExposureCompensationStep() { return rational == null ? 0.0 : rational.doubleValue(); } + @NonNull @Override public int[] getControlAutoFocusAvailableModes() { return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES); } + @NonNull @Override public Integer getControlMaxRegionsAutoExposure() { return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AE); } + @NonNull @Override public Integer getControlMaxRegionsAutoFocus() { return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF); } @RequiresApi(api = VERSION_CODES.P) + @Nullable @Override public int[] getDistortionCorrectionAvailableModes() { return cameraCharacteristics.get(CameraCharacteristics.DISTORTION_CORRECTION_AVAILABLE_MODES); } + @NonNull @Override public Boolean getFlashInfoAvailable() { return cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); @@ -82,39 +92,56 @@ public int getLensFacing() { return cameraCharacteristics.get(CameraCharacteristics.LENS_FACING); } + @Nullable @Override public Float getLensInfoMinimumFocusDistance() { return cameraCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE); } + @NonNull @Override public Float getScalerAvailableMaxDigitalZoom() { return cameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM); } @RequiresApi(api = VERSION_CODES.R) + @Nullable @Override public Float getScalerMaxZoomRatio() { - return cameraCharacteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE).getUpper(); + final Range range = + cameraCharacteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE); + if (range != null) { + return range.getUpper(); + } + return null; } @RequiresApi(api = VERSION_CODES.R) + @Nullable @Override public Float getScalerMinZoomRatio() { - return cameraCharacteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE).getLower(); + final Range range = + cameraCharacteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE); + if (range != null) { + return range.getLower(); + } + return null; } + @NonNull @Override public Rect getSensorInfoActiveArraySize() { return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE); } + @NonNull @Override public Size getSensorInfoPixelArraySize() { return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE); } @RequiresApi(api = VERSION_CODES.M) + @NonNull @Override public Rect getSensorInfoPreCorrectionActiveArraySize() { return cameraCharacteristics.get( @@ -131,6 +158,7 @@ public int getHardwareLevel() { return cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL); } + @NonNull @Override public int[] getAvailableNoiseReductionModes() { return cameraCharacteristics.get( diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraRegionUtils.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraRegionUtils.java index 951a2797d68f..55ca63caed4e 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraRegionUtils.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraRegionUtils.java @@ -29,6 +29,7 @@ public final class CameraRegionUtils { * @param requestBuilder - The request builder for the current capture request. * @return The boundaries for the current camera device. */ + @NonNull public static Size getCameraBoundaries( @NonNull CameraProperties cameraProperties, @NonNull CaptureRequest.Builder requestBuilder) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P @@ -69,6 +70,7 @@ && supportsDistortionCorrection(cameraProperties)) { * @return The dimensions of the metering rectangle based on the supplied coordinates and * boundaries. */ + @NonNull public static MeteringRectangle convertPointToMeteringRectangle( @NonNull Size boundaries, double x, diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraUtils.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraUtils.java index 11b6eeaa5b50..d98984cbf2f5 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraUtils.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraUtils.java @@ -10,6 +10,7 @@ import android.hardware.camera2.CameraCharacteristics; import android.hardware.camera2.CameraManager; import android.hardware.camera2.CameraMetadata; +import androidx.annotation.NonNull; import io.flutter.embedding.engine.systemchannels.PlatformChannel; import java.util.ArrayList; import java.util.HashMap; @@ -91,7 +92,8 @@ static PlatformChannel.DeviceOrientation deserializeDeviceOrientation(String ori * @return A map of all the available cameras, with their name as their key. * @throws CameraAccessException when the camera could not be accessed. */ - public static List> getAvailableCameras(Activity activity) + @NonNull + public static List> getAvailableCameras(@NonNull Activity activity) throws CameraAccessException { CameraManager cameraManager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); String[] cameraNames = cameraManager.getCameraIdList(); diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/DartMessenger.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/DartMessenger.java index e15078e66afc..e2b2ef80820d 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/DartMessenger.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/DartMessenger.java @@ -19,14 +19,14 @@ /** Utility class that facilitates communication to the Flutter client */ public class DartMessenger { @NonNull private final Handler handler; - @Nullable private MethodChannel cameraChannel; - @Nullable private MethodChannel deviceChannel; + @Nullable MethodChannel cameraChannel; + @Nullable MethodChannel deviceChannel; /** Specifies the different device related message types. */ enum DeviceEventType { /** Indicates the device's orientation has changed. */ ORIENTATION_CHANGED("orientation_changed"); - private final String method; + final String method; DeviceEventType(String method) { this.method = method; @@ -42,7 +42,7 @@ enum CameraEventType { /** Indicates that the camera is initialized. */ INITIALIZED("initialized"); - private final String method; + final String method; /** * Converts the supplied method name to the matching {@link CameraEventType}. @@ -75,8 +75,8 @@ enum CameraEventType { * * @param orientation specifies the new orientation of the device. */ - public void sendDeviceOrientationChangeEvent(PlatformChannel.DeviceOrientation orientation) { - assert (orientation != null); + public void sendDeviceOrientationChangeEvent( + @NonNull PlatformChannel.DeviceOrientation orientation) { this.send( DeviceEventType.ORIENTATION_CHANGED, new HashMap() { @@ -171,13 +171,7 @@ private void send(DeviceEventType eventType, Map args) { return; } - handler.post( - new Runnable() { - @Override - public void run() { - deviceChannel.invokeMethod(eventType.method, args); - } - }); + handler.post(() -> deviceChannel.invokeMethod(eventType.method, args)); } /** @@ -185,7 +179,7 @@ public void run() { * * @param payload The payload to send. */ - public void finish(MethodChannel.Result result, Object payload) { + public void finish(@NonNull MethodChannel.Result result, @Nullable Object payload) { handler.post(() -> result.success(payload)); } @@ -197,8 +191,8 @@ public void finish(MethodChannel.Result result, Object payload) { * @param errorDetails error details. */ public void error( - MethodChannel.Result result, - String errorCode, + @NonNull MethodChannel.Result result, + @NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails) { handler.post(() -> result.error(errorCode, errorMessage, errorDetails)); diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/ImageSaver.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/ImageSaver.java index 821c9a50c13f..e9d266b75883 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/ImageSaver.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/ImageSaver.java @@ -74,7 +74,7 @@ public interface Callback { * * @param absolutePath - The absolute path of the file that was saved. */ - void onComplete(String absolutePath); + void onComplete(@NonNull String absolutePath); /** * Called when an error is encountered while saving the image file. @@ -82,7 +82,7 @@ public interface Callback { * @param errorCode - The error code. * @param errorMessage - The human readable error message. */ - void onError(String errorCode, String errorMessage); + void onError(@NonNull String errorCode, @NonNull String errorMessage); } /** Factory class that assists in creating a {@link FileOutputStream} instance. */ diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/VideoRenderer.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/VideoRenderer.java index 62a70640961d..baa4157688e1 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/VideoRenderer.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/VideoRenderer.java @@ -21,6 +21,7 @@ import android.os.HandlerThread; import android.util.Log; import android.view.Surface; +import androidx.annotation.NonNull; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -40,7 +41,7 @@ */ public class VideoRenderer { - private static String TAG = "VideoRenderer"; + static String TAG = "VideoRenderer"; private static final String vertexShaderCode = " precision highp float;\n" @@ -91,15 +92,15 @@ public class VideoRenderer { EGLSurface surface; private Thread thread; private final Surface outputSurface; - private SurfaceTexture inputSurfaceTexture; + SurfaceTexture inputSurfaceTexture; private Surface inputSurface; private HandlerThread surfaceTextureFrameAvailableHandler; - private final Object surfaceTextureAvailableFrameLock = new Object(); - private Boolean surfaceTextureFrameAvailable = false; + final Object surfaceTextureAvailableFrameLock = new Object(); + Boolean surfaceTextureFrameAvailable = false; - private final int recordingWidth; - private final int recordingHeight; + final int recordingWidth; + final int recordingHeight; private int rotation = 0; private final Object lock = new Object(); @@ -107,6 +108,7 @@ public class VideoRenderer { private final Thread.UncaughtExceptionHandler uncaughtExceptionHandler; /** Gets surface for input. Blocks until surface is ready. */ + @NonNull public Surface getInputSurface() throws InterruptedException { synchronized (lock) { while (inputSurface == null) { @@ -117,10 +119,10 @@ public Surface getInputSurface() throws InterruptedException { } public VideoRenderer( - Surface outputSurface, + @NonNull Surface outputSurface, int recordingWidth, int recordingHeight, - Thread.UncaughtExceptionHandler uncaughtExceptionHandler) { + @NonNull Thread.UncaughtExceptionHandler uncaughtExceptionHandler) { this.outputSurface = outputSurface; this.recordingHeight = recordingHeight; this.recordingWidth = recordingWidth; @@ -146,7 +148,7 @@ private void cleanupOpenGL() { } /** Configures openGL. Must be called in same thread as draw is called. */ - private void configureOpenGL() { + void configureOpenGL() { synchronized (lock) { display = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY); if (display == EGL14.EGL_NO_DISPLAY) @@ -164,16 +166,29 @@ private void configureOpenGL() { throw new RuntimeException( "cannot configure OpenGL. missing EGL_ANDROID_presentation_time"); - int[] attribList = - new int[] { - EGL14.EGL_RED_SIZE, 8, - EGL14.EGL_GREEN_SIZE, 8, - EGL14.EGL_BLUE_SIZE, 8, - EGL14.EGL_ALPHA_SIZE, 8, - EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT, - EGLExt.EGL_RECORDABLE_ANDROID, 1, - EGL14.EGL_NONE - }; + int[] attribList; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + attribList = + new int[] { + EGL14.EGL_RED_SIZE, 8, + EGL14.EGL_GREEN_SIZE, 8, + EGL14.EGL_BLUE_SIZE, 8, + EGL14.EGL_ALPHA_SIZE, 8, + EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT, + EGLExt.EGL_RECORDABLE_ANDROID, 1, + EGL14.EGL_NONE + }; + } else { + attribList = + new int[] { + EGL14.EGL_RED_SIZE, 8, + EGL14.EGL_GREEN_SIZE, 8, + EGL14.EGL_BLUE_SIZE, 8, + EGL14.EGL_ALPHA_SIZE, 8, + EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT, + EGL14.EGL_NONE + }; + } EGLConfig[] configs = new EGLConfig[1]; int[] numConfigs = new int[1]; @@ -307,6 +322,7 @@ public int getTexId() { return textureHandles[0]; } + @NonNull public float[] moveMatrix() { float[] m = new float[16]; Matrix.setIdentityM(m, 0); @@ -331,7 +347,7 @@ private void deleteShader(int shader) { GLES20.glDeleteShader(shader); } - public void draw(int viewportWidth, int viewportHeight, float[] texMatrix) { + public void draw(int viewportWidth, int viewportHeight, @NonNull float[] texMatrix) { GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); GLES20.glClearColor(0f, 0f, 0f, 0f); diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeature.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeature.java index 92cfd548cd06..f9e571e51147 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeature.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeature.java @@ -25,6 +25,7 @@ protected CameraFeature(@NonNull CameraProperties cameraProperties) { } /** Debug name for this feature. */ + @NonNull public abstract String getDebugName(); /** @@ -56,5 +57,5 @@ protected CameraFeature(@NonNull CameraProperties cameraProperties) { * @param requestBuilder A {@see android.hardware.camera2.CaptureRequest.Builder} instance used to * configure the settings and outputs needed to capture a single image from the camera device. */ - public abstract void updateBuilder(CaptureRequest.Builder requestBuilder); + public abstract void updateBuilder(@NonNull CaptureRequest.Builder requestBuilder); } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeatureFactory.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeatureFactory.java index b91f9a1c03f7..573bf7b5bf45 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeatureFactory.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeatureFactory.java @@ -35,6 +35,7 @@ public interface CameraFeatureFactory { * @param recordingVideo indicates if the camera is currently recording. * @return newly created instance of the AutoFocusFeature class. */ + @NonNull AutoFocusFeature createAutoFocusFeature( @NonNull CameraProperties cameraProperties, boolean recordingVideo); @@ -45,6 +46,7 @@ AutoFocusFeature createAutoFocusFeature( * cameras features. * @return newly created instance of the ExposureLockFeature class. */ + @NonNull ExposureLockFeature createExposureLockFeature(@NonNull CameraProperties cameraProperties); /** @@ -54,6 +56,7 @@ AutoFocusFeature createAutoFocusFeature( * cameras features. * @return newly created instance of the ExposureOffsetFeature class. */ + @NonNull ExposureOffsetFeature createExposureOffsetFeature(@NonNull CameraProperties cameraProperties); /** @@ -63,6 +66,7 @@ AutoFocusFeature createAutoFocusFeature( * cameras features. * @return newly created instance of the FlashFeature class. */ + @NonNull FlashFeature createFlashFeature(@NonNull CameraProperties cameraProperties); /** @@ -74,10 +78,11 @@ AutoFocusFeature createAutoFocusFeature( * @param cameraName the name of the camera which can be used to identify the camera device. * @return newly created instance of the ResolutionFeature class. */ + @NonNull ResolutionFeature createResolutionFeature( @NonNull CameraProperties cameraProperties, - ResolutionPreset initialSetting, - String cameraName); + @NonNull ResolutionPreset initialSetting, + @NonNull String cameraName); /** * Creates a new instance of the focus point feature. @@ -88,6 +93,7 @@ ResolutionFeature createResolutionFeature( * information about the sensor and device orientation. * @return newly created instance of the FocusPointFeature class. */ + @NonNull FocusPointFeature createFocusPointFeature( @NonNull CameraProperties cameraProperties, @NonNull SensorOrientationFeature sensorOrientationFeature); @@ -99,6 +105,7 @@ FocusPointFeature createFocusPointFeature( * cameras features. * @return newly created instance of the FpsRangeFeature class. */ + @NonNull FpsRangeFeature createFpsRangeFeature(@NonNull CameraProperties cameraProperties); /** @@ -111,6 +118,7 @@ FocusPointFeature createFocusPointFeature( * Dart. * @return newly created instance of the SensorOrientationFeature class. */ + @NonNull SensorOrientationFeature createSensorOrientationFeature( @NonNull CameraProperties cameraProperties, @NonNull Activity activity, @@ -123,6 +131,7 @@ SensorOrientationFeature createSensorOrientationFeature( * cameras features. * @return newly created instance of the ZoomLevelFeature class. */ + @NonNull ZoomLevelFeature createZoomLevelFeature(@NonNull CameraProperties cameraProperties); /** @@ -134,6 +143,7 @@ SensorOrientationFeature createSensorOrientationFeature( * information about the sensor and device orientation. * @return newly created instance of the ExposurePointFeature class. */ + @NonNull ExposurePointFeature createExposurePointFeature( @NonNull CameraProperties cameraProperties, @NonNull SensorOrientationFeature sensorOrientationFeature); @@ -145,5 +155,6 @@ ExposurePointFeature createExposurePointFeature( * cameras features. * @return newly created instance of the NoiseReductionFeature class. */ + @NonNull NoiseReductionFeature createNoiseReductionFeature(@NonNull CameraProperties cameraProperties); } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeatureFactoryImpl.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeatureFactoryImpl.java index 95a8c06caa0a..a15a0dca4017 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeatureFactoryImpl.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeatureFactoryImpl.java @@ -27,37 +27,42 @@ * android.hardware.camera2.CaptureRequest}. */ public class CameraFeatureFactoryImpl implements CameraFeatureFactory { - + @NonNull @Override public AutoFocusFeature createAutoFocusFeature( @NonNull CameraProperties cameraProperties, boolean recordingVideo) { return new AutoFocusFeature(cameraProperties, recordingVideo); } + @NonNull @Override public ExposureLockFeature createExposureLockFeature(@NonNull CameraProperties cameraProperties) { return new ExposureLockFeature(cameraProperties); } + @NonNull @Override public ExposureOffsetFeature createExposureOffsetFeature( @NonNull CameraProperties cameraProperties) { return new ExposureOffsetFeature(cameraProperties); } + @NonNull @Override public FlashFeature createFlashFeature(@NonNull CameraProperties cameraProperties) { return new FlashFeature(cameraProperties); } + @NonNull @Override public ResolutionFeature createResolutionFeature( @NonNull CameraProperties cameraProperties, - ResolutionPreset initialSetting, - String cameraName) { + @NonNull ResolutionPreset initialSetting, + @NonNull String cameraName) { return new ResolutionFeature(cameraProperties, initialSetting, cameraName); } + @NonNull @Override public FocusPointFeature createFocusPointFeature( @NonNull CameraProperties cameraProperties, @@ -65,11 +70,13 @@ public FocusPointFeature createFocusPointFeature( return new FocusPointFeature(cameraProperties, sensorOrientationFeature); } + @NonNull @Override public FpsRangeFeature createFpsRangeFeature(@NonNull CameraProperties cameraProperties) { return new FpsRangeFeature(cameraProperties); } + @NonNull @Override public SensorOrientationFeature createSensorOrientationFeature( @NonNull CameraProperties cameraProperties, @@ -78,11 +85,13 @@ public SensorOrientationFeature createSensorOrientationFeature( return new SensorOrientationFeature(cameraProperties, activity, dartMessenger); } + @NonNull @Override public ZoomLevelFeature createZoomLevelFeature(@NonNull CameraProperties cameraProperties) { return new ZoomLevelFeature(cameraProperties); } + @NonNull @Override public ExposurePointFeature createExposurePointFeature( @NonNull CameraProperties cameraProperties, @@ -90,6 +99,7 @@ public ExposurePointFeature createExposurePointFeature( return new ExposurePointFeature(cameraProperties, sensorOrientationFeature); } + @NonNull @Override public NoiseReductionFeature createNoiseReductionFeature( @NonNull CameraProperties cameraProperties) { diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeatures.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeatures.java index c7ed9bb205df..6c8c1f17a2f2 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeatures.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/CameraFeatures.java @@ -5,6 +5,7 @@ package io.flutter.plugins.camera.features; import android.app.Activity; +import androidx.annotation.NonNull; import io.flutter.plugins.camera.CameraProperties; import io.flutter.plugins.camera.DartMessenger; import io.flutter.plugins.camera.features.autofocus.AutoFocusFeature; @@ -22,6 +23,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.Objects; /** * These are all of our available features in the camera. Used in the Camera to access all features @@ -41,12 +43,13 @@ public class CameraFeatures { private static final String SENSOR_ORIENTATION = "SENSOR_ORIENTATION"; private static final String ZOOM_LEVEL = "ZOOM_LEVEL"; + @NonNull public static CameraFeatures init( - CameraFeatureFactory cameraFeatureFactory, - CameraProperties cameraProperties, - Activity activity, - DartMessenger dartMessenger, - ResolutionPreset resolutionPreset) { + @NonNull CameraFeatureFactory cameraFeatureFactory, + @NonNull CameraProperties cameraProperties, + @NonNull Activity activity, + @NonNull DartMessenger dartMessenger, + @NonNull ResolutionPreset resolutionPreset) { CameraFeatures cameraFeatures = new CameraFeatures(); cameraFeatures.setAutoFocus( cameraFeatureFactory.createAutoFocusFeature(cameraProperties, false)); @@ -74,13 +77,14 @@ public static CameraFeatures init( return cameraFeatures; } - private Map> featureMap = new HashMap<>(); + private final Map> featureMap = new HashMap<>(); /** * Gets a collection of all features that have been set. * * @return A collection of all features that have been set. */ + @NonNull public Collection> getAllFeatures() { return this.featureMap.values(); } @@ -90,6 +94,7 @@ public Collection> getAllFeatures() { * * @return the auto focus feature. */ + @NonNull public AutoFocusFeature getAutoFocus() { return (AutoFocusFeature) featureMap.get(AUTO_FOCUS); } @@ -99,7 +104,7 @@ public AutoFocusFeature getAutoFocus() { * * @param autoFocus the {@link AutoFocusFeature} instance to set. */ - public void setAutoFocus(AutoFocusFeature autoFocus) { + public void setAutoFocus(@NonNull AutoFocusFeature autoFocus) { this.featureMap.put(AUTO_FOCUS, autoFocus); } @@ -108,6 +113,7 @@ public void setAutoFocus(AutoFocusFeature autoFocus) { * * @return the exposure lock feature. */ + @NonNull public ExposureLockFeature getExposureLock() { return (ExposureLockFeature) featureMap.get(EXPOSURE_LOCK); } @@ -117,7 +123,7 @@ public ExposureLockFeature getExposureLock() { * * @param exposureLock the {@link ExposureLockFeature} instance to set. */ - public void setExposureLock(ExposureLockFeature exposureLock) { + public void setExposureLock(@NonNull ExposureLockFeature exposureLock) { this.featureMap.put(EXPOSURE_LOCK, exposureLock); } @@ -126,8 +132,9 @@ public void setExposureLock(ExposureLockFeature exposureLock) { * * @return the exposure offset feature. */ + @NonNull public ExposureOffsetFeature getExposureOffset() { - return (ExposureOffsetFeature) featureMap.get(EXPOSURE_OFFSET); + return (ExposureOffsetFeature) Objects.requireNonNull(featureMap.get(EXPOSURE_OFFSET)); } /** @@ -135,7 +142,7 @@ public ExposureOffsetFeature getExposureOffset() { * * @param exposureOffset the {@link ExposureOffsetFeature} instance to set. */ - public void setExposureOffset(ExposureOffsetFeature exposureOffset) { + public void setExposureOffset(@NonNull ExposureOffsetFeature exposureOffset) { this.featureMap.put(EXPOSURE_OFFSET, exposureOffset); } @@ -144,8 +151,9 @@ public void setExposureOffset(ExposureOffsetFeature exposureOffset) { * * @return the exposure point feature. */ + @NonNull public ExposurePointFeature getExposurePoint() { - return (ExposurePointFeature) featureMap.get(EXPOSURE_POINT); + return (ExposurePointFeature) Objects.requireNonNull(featureMap.get(EXPOSURE_POINT)); } /** @@ -153,7 +161,7 @@ public ExposurePointFeature getExposurePoint() { * * @param exposurePoint the {@link ExposurePointFeature} instance to set. */ - public void setExposurePoint(ExposurePointFeature exposurePoint) { + public void setExposurePoint(@NonNull ExposurePointFeature exposurePoint) { this.featureMap.put(EXPOSURE_POINT, exposurePoint); } @@ -162,8 +170,9 @@ public void setExposurePoint(ExposurePointFeature exposurePoint) { * * @return the flash feature. */ + @NonNull public FlashFeature getFlash() { - return (FlashFeature) featureMap.get(FLASH); + return (FlashFeature) Objects.requireNonNull(featureMap.get(FLASH)); } /** @@ -171,7 +180,7 @@ public FlashFeature getFlash() { * * @param flash the {@link FlashFeature} instance to set. */ - public void setFlash(FlashFeature flash) { + public void setFlash(@NonNull FlashFeature flash) { this.featureMap.put(FLASH, flash); } @@ -180,8 +189,9 @@ public void setFlash(FlashFeature flash) { * * @return the focus point feature. */ + @NonNull public FocusPointFeature getFocusPoint() { - return (FocusPointFeature) featureMap.get(FOCUS_POINT); + return (FocusPointFeature) Objects.requireNonNull(featureMap.get(FOCUS_POINT)); } /** @@ -189,7 +199,7 @@ public FocusPointFeature getFocusPoint() { * * @param focusPoint the {@link FocusPointFeature} instance to set. */ - public void setFocusPoint(FocusPointFeature focusPoint) { + public void setFocusPoint(@NonNull FocusPointFeature focusPoint) { this.featureMap.put(FOCUS_POINT, focusPoint); } @@ -198,8 +208,9 @@ public void setFocusPoint(FocusPointFeature focusPoint) { * * @return the fps range feature. */ + @NonNull public FpsRangeFeature getFpsRange() { - return (FpsRangeFeature) featureMap.get(FPS_RANGE); + return (FpsRangeFeature) Objects.requireNonNull(featureMap.get(FPS_RANGE)); } /** @@ -207,7 +218,7 @@ public FpsRangeFeature getFpsRange() { * * @param fpsRange the {@link FpsRangeFeature} instance to set. */ - public void setFpsRange(FpsRangeFeature fpsRange) { + public void setFpsRange(@NonNull FpsRangeFeature fpsRange) { this.featureMap.put(FPS_RANGE, fpsRange); } @@ -216,8 +227,9 @@ public void setFpsRange(FpsRangeFeature fpsRange) { * * @return the noise reduction feature. */ + @NonNull public NoiseReductionFeature getNoiseReduction() { - return (NoiseReductionFeature) featureMap.get(NOISE_REDUCTION); + return (NoiseReductionFeature) Objects.requireNonNull(featureMap.get(NOISE_REDUCTION)); } /** @@ -225,7 +237,7 @@ public NoiseReductionFeature getNoiseReduction() { * * @param noiseReduction the {@link NoiseReductionFeature} instance to set. */ - public void setNoiseReduction(NoiseReductionFeature noiseReduction) { + public void setNoiseReduction(@NonNull NoiseReductionFeature noiseReduction) { this.featureMap.put(NOISE_REDUCTION, noiseReduction); } @@ -234,8 +246,9 @@ public void setNoiseReduction(NoiseReductionFeature noiseReduction) { * * @return the resolution feature. */ + @NonNull public ResolutionFeature getResolution() { - return (ResolutionFeature) featureMap.get(RESOLUTION); + return (ResolutionFeature) Objects.requireNonNull(featureMap.get(RESOLUTION)); } /** @@ -243,7 +256,7 @@ public ResolutionFeature getResolution() { * * @param resolution the {@link ResolutionFeature} instance to set. */ - public void setResolution(ResolutionFeature resolution) { + public void setResolution(@NonNull ResolutionFeature resolution) { this.featureMap.put(RESOLUTION, resolution); } @@ -252,8 +265,9 @@ public void setResolution(ResolutionFeature resolution) { * * @return the sensor orientation feature. */ + @NonNull public SensorOrientationFeature getSensorOrientation() { - return (SensorOrientationFeature) featureMap.get(SENSOR_ORIENTATION); + return (SensorOrientationFeature) Objects.requireNonNull(featureMap.get(SENSOR_ORIENTATION)); } /** @@ -261,7 +275,7 @@ public SensorOrientationFeature getSensorOrientation() { * * @param sensorOrientation the {@link SensorOrientationFeature} instance to set. */ - public void setSensorOrientation(SensorOrientationFeature sensorOrientation) { + public void setSensorOrientation(@NonNull SensorOrientationFeature sensorOrientation) { this.featureMap.put(SENSOR_ORIENTATION, sensorOrientation); } @@ -270,8 +284,9 @@ public void setSensorOrientation(SensorOrientationFeature sensorOrientation) { * * @return the zoom level feature. */ + @NonNull public ZoomLevelFeature getZoomLevel() { - return (ZoomLevelFeature) featureMap.get(ZOOM_LEVEL); + return (ZoomLevelFeature) Objects.requireNonNull(featureMap.get(ZOOM_LEVEL)); } /** @@ -279,7 +294,7 @@ public ZoomLevelFeature getZoomLevel() { * * @param zoomLevel the {@link ZoomLevelFeature} instance to set. */ - public void setZoomLevel(ZoomLevelFeature zoomLevel) { + public void setZoomLevel(@NonNull ZoomLevelFeature zoomLevel) { this.featureMap.put(ZOOM_LEVEL, zoomLevel); } } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/Point.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/Point.java index b6b64f92d987..c953614c6470 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/Point.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/Point.java @@ -4,12 +4,14 @@ package io.flutter.plugins.camera.features; +import androidx.annotation.Nullable; + /** Represents a point on an x/y axis. */ public class Point { public final Double x; public final Double y; - public Point(Double x, Double y) { + public Point(@Nullable Double x, @Nullable Double y) { this.x = x; this.y = y; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/autofocus/AutoFocusFeature.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/autofocus/AutoFocusFeature.java index 818e4e9b6425..81370898ae1f 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/autofocus/AutoFocusFeature.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/autofocus/AutoFocusFeature.java @@ -4,14 +4,16 @@ package io.flutter.plugins.camera.features.autofocus; +import android.annotation.SuppressLint; import android.hardware.camera2.CameraCharacteristics; import android.hardware.camera2.CaptureRequest; +import androidx.annotation.NonNull; import io.flutter.plugins.camera.CameraProperties; import io.flutter.plugins.camera.features.CameraFeature; /** Controls the auto focus configuration on the {@see anddroid.hardware.camera2} API. */ public class AutoFocusFeature extends CameraFeature { - private FocusMode currentSetting = FocusMode.auto; + @NonNull private FocusMode currentSetting = FocusMode.auto; // When switching recording modes this feature is re-created with the appropriate setting here. private final boolean recordingVideo; @@ -22,23 +24,26 @@ public class AutoFocusFeature extends CameraFeature { * @param cameraProperties Collection of the characteristics for the current camera device. * @param recordingVideo Indicates whether the camera is currently recording video. */ - public AutoFocusFeature(CameraProperties cameraProperties, boolean recordingVideo) { + public AutoFocusFeature(@NonNull CameraProperties cameraProperties, boolean recordingVideo) { super(cameraProperties); this.recordingVideo = recordingVideo; } + @NonNull @Override public String getDebugName() { return "AutoFocusFeature"; } + @NonNull + @SuppressLint("KotlinPropertyAccess") @Override public FocusMode getValue() { return currentSetting; } @Override - public void setValue(FocusMode value) { + public void setValue(@NonNull FocusMode value) { this.currentSetting = value; } @@ -58,7 +63,7 @@ public boolean checkIsSupported() { } @Override - public void updateBuilder(CaptureRequest.Builder requestBuilder) { + public void updateBuilder(@NonNull CaptureRequest.Builder requestBuilder) { if (!checkIsSupported()) { return; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/autofocus/FocusMode.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/autofocus/FocusMode.java index 56331b4fab8c..d032a9076845 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/autofocus/FocusMode.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/autofocus/FocusMode.java @@ -4,6 +4,9 @@ package io.flutter.plugins.camera.features.autofocus; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + // Mirrors focus_mode.dart public enum FocusMode { auto("auto"), @@ -15,7 +18,8 @@ public enum FocusMode { this.strValue = strValue; } - public static FocusMode getValueForString(String modeStr) { + @Nullable + public static FocusMode getValueForString(@NonNull String modeStr) { for (FocusMode value : values()) { if (value.strValue.equals(modeStr)) { return value; diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposurelock/ExposureLockFeature.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposurelock/ExposureLockFeature.java index df08cd9a3c77..32f01a2053dc 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposurelock/ExposureLockFeature.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposurelock/ExposureLockFeature.java @@ -4,36 +4,40 @@ package io.flutter.plugins.camera.features.exposurelock; +import android.annotation.SuppressLint; import android.hardware.camera2.CaptureRequest; +import androidx.annotation.NonNull; import io.flutter.plugins.camera.CameraProperties; import io.flutter.plugins.camera.features.CameraFeature; /** Controls whether or not the exposure mode is currently locked or automatically metering. */ public class ExposureLockFeature extends CameraFeature { - - private ExposureMode currentSetting = ExposureMode.auto; + @NonNull private ExposureMode currentSetting = ExposureMode.auto; /** * Creates a new instance of the {@see ExposureLockFeature}. * * @param cameraProperties Collection of the characteristics for the current camera device. */ - public ExposureLockFeature(CameraProperties cameraProperties) { + public ExposureLockFeature(@NonNull CameraProperties cameraProperties) { super(cameraProperties); } + @NonNull @Override public String getDebugName() { return "ExposureLockFeature"; } + @SuppressLint("KotlinPropertyAccess") + @NonNull @Override public ExposureMode getValue() { return currentSetting; } @Override - public void setValue(ExposureMode value) { + public void setValue(@NonNull ExposureMode value) { this.currentSetting = value; } @@ -44,7 +48,7 @@ public boolean checkIsSupported() { } @Override - public void updateBuilder(CaptureRequest.Builder requestBuilder) { + public void updateBuilder(@NonNull CaptureRequest.Builder requestBuilder) { if (!checkIsSupported()) { return; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposurelock/ExposureMode.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposurelock/ExposureMode.java index 2971fb23727a..8febc1af66fe 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposurelock/ExposureMode.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposurelock/ExposureMode.java @@ -4,6 +4,9 @@ package io.flutter.plugins.camera.features.exposurelock; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + // Mirrors exposure_mode.dart public enum ExposureMode { auto("auto"), @@ -24,7 +27,8 @@ public enum ExposureMode { * @param modeStr String value to convert into an {@see ExposureMode} enum value. * @return Matching {@see ExposureMode} enum value, or null if no match is found. */ - public static ExposureMode getValueForString(String modeStr) { + @Nullable + public static ExposureMode getValueForString(@NonNull String modeStr) { for (ExposureMode value : values()) { if (value.strValue.equals(modeStr)) { return value; diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposureoffset/ExposureOffsetFeature.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposureoffset/ExposureOffsetFeature.java index d5a9fcd4a38a..d083a57dd7ed 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposureoffset/ExposureOffsetFeature.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposureoffset/ExposureOffsetFeature.java @@ -4,6 +4,7 @@ package io.flutter.plugins.camera.features.exposureoffset; +import android.annotation.SuppressLint; import android.hardware.camera2.CaptureRequest; import android.util.Range; import androidx.annotation.NonNull; @@ -12,7 +13,6 @@ /** Controls the exposure offset making the resulting image brighter or darker. */ public class ExposureOffsetFeature extends CameraFeature { - private double currentSetting = 0; /** @@ -20,15 +20,18 @@ public class ExposureOffsetFeature extends CameraFeature { * * @param cameraProperties Collection of the characteristics for the current camera device. */ - public ExposureOffsetFeature(CameraProperties cameraProperties) { + public ExposureOffsetFeature(@NonNull CameraProperties cameraProperties) { super(cameraProperties); } + @NonNull @Override public String getDebugName() { return "ExposureOffsetFeature"; } + @SuppressLint("KotlinPropertyAccess") + @NonNull @Override public Double getValue() { return currentSetting; @@ -47,7 +50,7 @@ public boolean checkIsSupported() { } @Override - public void updateBuilder(CaptureRequest.Builder requestBuilder) { + public void updateBuilder(@NonNull CaptureRequest.Builder requestBuilder) { if (!checkIsSupported()) { return; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposurepoint/ExposurePointFeature.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposurepoint/ExposurePointFeature.java index 336e756e9ed8..40f28eadc040 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposurepoint/ExposurePointFeature.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/exposurepoint/ExposurePointFeature.java @@ -4,10 +4,12 @@ package io.flutter.plugins.camera.features.exposurepoint; +import android.annotation.SuppressLint; import android.hardware.camera2.CaptureRequest; import android.hardware.camera2.params.MeteringRectangle; import android.util.Size; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import io.flutter.embedding.engine.systemchannels.PlatformChannel; import io.flutter.plugins.camera.CameraProperties; import io.flutter.plugins.camera.CameraRegionUtils; @@ -19,9 +21,9 @@ public class ExposurePointFeature extends CameraFeature { private Size cameraBoundaries; - private Point exposurePoint; + @Nullable private Point exposurePoint; private MeteringRectangle exposureRectangle; - private final SensorOrientationFeature sensorOrientationFeature; + @NonNull private final SensorOrientationFeature sensorOrientationFeature; /** * Creates a new instance of the {@link ExposurePointFeature}. @@ -29,7 +31,8 @@ public class ExposurePointFeature extends CameraFeature { * @param cameraProperties Collection of the characteristics for the current camera device. */ public ExposurePointFeature( - CameraProperties cameraProperties, SensorOrientationFeature sensorOrientationFeature) { + @NonNull CameraProperties cameraProperties, + @NonNull SensorOrientationFeature sensorOrientationFeature) { super(cameraProperties); this.sensorOrientationFeature = sensorOrientationFeature; } @@ -44,18 +47,21 @@ public void setCameraBoundaries(@NonNull Size cameraBoundaries) { this.buildExposureRectangle(); } + @NonNull @Override public String getDebugName() { return "ExposurePointFeature"; } + @SuppressLint("KotlinPropertyAccess") + @Nullable @Override public Point getValue() { return exposurePoint; } @Override - public void setValue(Point value) { + public void setValue(@Nullable Point value) { this.exposurePoint = (value == null || value.x == null || value.y == null) ? null : value; this.buildExposureRectangle(); } @@ -68,7 +74,7 @@ public boolean checkIsSupported() { } @Override - public void updateBuilder(CaptureRequest.Builder requestBuilder) { + public void updateBuilder(@NonNull CaptureRequest.Builder requestBuilder) { if (!checkIsSupported()) { return; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/flash/FlashFeature.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/flash/FlashFeature.java index 054c81f5183b..2de97cb790bd 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/flash/FlashFeature.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/flash/FlashFeature.java @@ -4,35 +4,40 @@ package io.flutter.plugins.camera.features.flash; +import android.annotation.SuppressLint; import android.hardware.camera2.CaptureRequest; +import androidx.annotation.NonNull; import io.flutter.plugins.camera.CameraProperties; import io.flutter.plugins.camera.features.CameraFeature; /** Controls the flash configuration on the {@link android.hardware.camera2} API. */ public class FlashFeature extends CameraFeature { - private FlashMode currentSetting = FlashMode.auto; + @NonNull private FlashMode currentSetting = FlashMode.auto; /** * Creates a new instance of the {@link FlashFeature}. * * @param cameraProperties Collection of characteristics for the current camera device. */ - public FlashFeature(CameraProperties cameraProperties) { + public FlashFeature(@NonNull CameraProperties cameraProperties) { super(cameraProperties); } + @NonNull @Override public String getDebugName() { return "FlashFeature"; } + @SuppressLint("KotlinPropertyAccess") + @NonNull @Override public FlashMode getValue() { return currentSetting; } @Override - public void setValue(FlashMode value) { + public void setValue(@NonNull FlashMode value) { this.currentSetting = value; } @@ -43,7 +48,7 @@ public boolean checkIsSupported() { } @Override - public void updateBuilder(CaptureRequest.Builder requestBuilder) { + public void updateBuilder(@NonNull CaptureRequest.Builder requestBuilder) { if (!checkIsSupported()) { return; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/flash/FlashMode.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/flash/FlashMode.java index 788c768e0b3c..cb4dbae440f4 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/flash/FlashMode.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/flash/FlashMode.java @@ -4,6 +4,9 @@ package io.flutter.plugins.camera.features.flash; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + // Mirrors flash_mode.dart public enum FlashMode { off("off"), @@ -26,7 +29,8 @@ public enum FlashMode { * @param modeStr String value to convert into an {@see FlashMode} enum value. * @return Matching {@see FlashMode} enum value, or null if no match is found. */ - public static FlashMode getValueForString(String modeStr) { + @Nullable + public static FlashMode getValueForString(@NonNull String modeStr) { for (FlashMode value : values()) { if (value.strValue.equals(modeStr)) return value; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/focuspoint/FocusPointFeature.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/focuspoint/FocusPointFeature.java index a3a0172d3c37..f63bab8dc200 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/focuspoint/FocusPointFeature.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/focuspoint/FocusPointFeature.java @@ -4,10 +4,12 @@ package io.flutter.plugins.camera.features.focuspoint; +import android.annotation.SuppressLint; import android.hardware.camera2.CaptureRequest; import android.hardware.camera2.params.MeteringRectangle; import android.util.Size; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import io.flutter.embedding.engine.systemchannels.PlatformChannel; import io.flutter.plugins.camera.CameraProperties; import io.flutter.plugins.camera.CameraRegionUtils; @@ -19,9 +21,9 @@ public class FocusPointFeature extends CameraFeature { private Size cameraBoundaries; - private Point focusPoint; + @Nullable private Point focusPoint; private MeteringRectangle focusRectangle; - private final SensorOrientationFeature sensorOrientationFeature; + @NonNull private final SensorOrientationFeature sensorOrientationFeature; /** * Creates a new instance of the {@link FocusPointFeature}. @@ -29,7 +31,8 @@ public class FocusPointFeature extends CameraFeature { * @param cameraProperties Collection of the characteristics for the current camera device. */ public FocusPointFeature( - CameraProperties cameraProperties, SensorOrientationFeature sensorOrientationFeature) { + @NonNull CameraProperties cameraProperties, + @NonNull SensorOrientationFeature sensorOrientationFeature) { super(cameraProperties); this.sensorOrientationFeature = sensorOrientationFeature; } @@ -44,18 +47,21 @@ public void setCameraBoundaries(@NonNull Size cameraBoundaries) { this.buildFocusRectangle(); } + @NonNull @Override public String getDebugName() { return "FocusPointFeature"; } + @SuppressLint("KotlinPropertyAccess") + @Nullable @Override public Point getValue() { return focusPoint; } @Override - public void setValue(Point value) { + public void setValue(@Nullable Point value) { this.focusPoint = value == null || value.x == null || value.y == null ? null : value; this.buildFocusRectangle(); } @@ -68,7 +74,7 @@ public boolean checkIsSupported() { } @Override - public void updateBuilder(CaptureRequest.Builder requestBuilder) { + public void updateBuilder(@NonNull CaptureRequest.Builder requestBuilder) { if (!checkIsSupported()) { return; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/fpsrange/FpsRangeFeature.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/fpsrange/FpsRangeFeature.java index 500f2aa28dc2..1f3104bbf4cf 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/fpsrange/FpsRangeFeature.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/fpsrange/FpsRangeFeature.java @@ -4,9 +4,12 @@ package io.flutter.plugins.camera.features.fpsrange; +import android.annotation.SuppressLint; import android.hardware.camera2.CaptureRequest; import android.os.Build; import android.util.Range; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import io.flutter.plugins.camera.CameraProperties; import io.flutter.plugins.camera.features.CameraFeature; @@ -16,14 +19,14 @@ */ public class FpsRangeFeature extends CameraFeature> { private static final Range MAX_PIXEL4A_RANGE = new Range<>(30, 30); - private Range currentSetting; + @Nullable private Range currentSetting; /** * Creates a new instance of the {@link FpsRangeFeature}. * * @param cameraProperties Collection of characteristics for the current camera device. */ - public FpsRangeFeature(CameraProperties cameraProperties) { + public FpsRangeFeature(@NonNull CameraProperties cameraProperties) { super(cameraProperties); if (isPixel4A()) { @@ -55,18 +58,21 @@ private boolean isPixel4A() { return Build.BRAND.equals("google") && Build.MODEL.equals("Pixel 4a"); } + @NonNull @Override public String getDebugName() { return "FpsRangeFeature"; } + @SuppressLint("KotlinPropertyAccess") + @Nullable @Override public Range getValue() { return currentSetting; } @Override - public void setValue(Range value) { + public void setValue(@NonNull Range value) { this.currentSetting = value; } @@ -77,7 +83,7 @@ public boolean checkIsSupported() { } @Override - public void updateBuilder(CaptureRequest.Builder requestBuilder) { + public void updateBuilder(@NonNull CaptureRequest.Builder requestBuilder) { if (!checkIsSupported()) { return; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/noisereduction/NoiseReductionFeature.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/noisereduction/NoiseReductionFeature.java index 408575b375e6..d98328dcce4c 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/noisereduction/NoiseReductionFeature.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/noisereduction/NoiseReductionFeature.java @@ -4,10 +4,13 @@ package io.flutter.plugins.camera.features.noisereduction; +import android.annotation.SuppressLint; import android.hardware.camera2.CaptureRequest; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.util.Log; +import androidx.annotation.NonNull; +import io.flutter.BuildConfig; import io.flutter.plugins.camera.CameraProperties; import io.flutter.plugins.camera.features.CameraFeature; import java.util.HashMap; @@ -18,7 +21,7 @@ * https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES */ public class NoiseReductionFeature extends CameraFeature { - private NoiseReductionMode currentSetting = NoiseReductionMode.fast; + @NonNull private NoiseReductionMode currentSetting = NoiseReductionMode.fast; private final HashMap NOISE_REDUCTION_MODES = new HashMap<>(); @@ -27,7 +30,7 @@ public class NoiseReductionFeature extends CameraFeature { * * @param cameraProperties Collection of the characteristics for the current camera device. */ - public NoiseReductionFeature(CameraProperties cameraProperties) { + public NoiseReductionFeature(@NonNull CameraProperties cameraProperties) { super(cameraProperties); NOISE_REDUCTION_MODES.put(NoiseReductionMode.off, CaptureRequest.NOISE_REDUCTION_MODE_OFF); NOISE_REDUCTION_MODES.put(NoiseReductionMode.fast, CaptureRequest.NOISE_REDUCTION_MODE_FAST); @@ -41,18 +44,21 @@ public NoiseReductionFeature(CameraProperties cameraProperties) { } } + @NonNull @Override public String getDebugName() { return "NoiseReductionFeature"; } + @SuppressLint("KotlinPropertyAccess") + @NonNull @Override public NoiseReductionMode getValue() { return currentSetting; } @Override - public void setValue(NoiseReductionMode value) { + public void setValue(@NonNull NoiseReductionMode value) { this.currentSetting = value; } @@ -77,12 +83,14 @@ public boolean checkIsSupported() { } @Override - public void updateBuilder(CaptureRequest.Builder requestBuilder) { + public void updateBuilder(@NonNull CaptureRequest.Builder requestBuilder) { if (!checkIsSupported()) { return; } - Log.i("Camera", "updateNoiseReduction | currentSetting: " + currentSetting); + if (BuildConfig.DEBUG) { + Log.i("Camera", "updateNoiseReduction | currentSetting: " + currentSetting); + } // Always use fast mode. requestBuilder.set( diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/noisereduction/NoiseReductionMode.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/noisereduction/NoiseReductionMode.java index 425a458e2a2b..257b8b9d8335 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/noisereduction/NoiseReductionMode.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/noisereduction/NoiseReductionMode.java @@ -4,6 +4,9 @@ package io.flutter.plugins.camera.features.noisereduction; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + /** Only supports fast mode for now. */ public enum NoiseReductionMode { off("off"), @@ -27,7 +30,8 @@ public enum NoiseReductionMode { * @param modeStr String value to convert into an {@see NoiseReductionMode} enum value. * @return Matching {@see NoiseReductionMode} enum value, or null if no match is found. */ - public static NoiseReductionMode getValueForString(String modeStr) { + @Nullable + public static NoiseReductionMode getValueForString(@NonNull String modeStr) { for (NoiseReductionMode value : values()) { if (value.strValue.equals(modeStr)) return value; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java index a80c340f89fa..4cba44816639 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java @@ -4,12 +4,15 @@ package io.flutter.plugins.camera.features.resolution; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.hardware.camera2.CaptureRequest; import android.media.CamcorderProfile; import android.media.EncoderProfiles; import android.os.Build; import android.util.Size; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import io.flutter.plugins.camera.CameraProperties; import io.flutter.plugins.camera.features.CameraFeature; @@ -23,11 +26,11 @@ * required to configure the resolution using the {@link android.hardware.camera2} API. */ public class ResolutionFeature extends CameraFeature { - private Size captureSize; - private Size previewSize; + @Nullable private Size captureSize; + @Nullable private Size previewSize; private CamcorderProfile recordingProfileLegacy; private EncoderProfiles recordingProfile; - private ResolutionPreset currentSetting; + @NonNull private ResolutionPreset currentSetting; private int cameraId; /** @@ -38,7 +41,9 @@ public class ResolutionFeature extends CameraFeature { * @param cameraName Camera identifier of the camera for which to configure the resolution. */ public ResolutionFeature( - CameraProperties cameraProperties, ResolutionPreset resolutionPreset, String cameraName) { + @NonNull CameraProperties cameraProperties, + @NonNull ResolutionPreset resolutionPreset, + @NonNull String cameraName) { super(cameraProperties); this.currentSetting = resolutionPreset; try { @@ -56,10 +61,12 @@ public ResolutionFeature( * * @return Resolution information to configure the {@link android.hardware.camera2} API. */ + @Nullable public CamcorderProfile getRecordingProfileLegacy() { return this.recordingProfileLegacy; } + @Nullable public EncoderProfiles getRecordingProfile() { return this.recordingProfile; } @@ -69,6 +76,7 @@ public EncoderProfiles getRecordingProfile() { * * @return The optimal preview size. */ + @Nullable public Size getPreviewSize() { return this.previewSize; } @@ -78,22 +86,26 @@ public Size getPreviewSize() { * * @return The optimal capture size. */ + @Nullable public Size getCaptureSize() { return this.captureSize; } + @NonNull @Override public String getDebugName() { return "ResolutionFeature"; } + @SuppressLint("KotlinPropertyAccess") + @NonNull @Override public ResolutionPreset getValue() { return currentSetting; } @Override - public void setValue(ResolutionPreset value) { + public void setValue(@NonNull ResolutionPreset value) { this.currentSetting = value; configureResolution(currentSetting, cameraId); } @@ -104,7 +116,7 @@ public boolean checkIsSupported() { } @Override - public void updateBuilder(CaptureRequest.Builder requestBuilder) { + public void updateBuilder(@NonNull CaptureRequest.Builder requestBuilder) { // No-op: when setting a resolution there is no need to update the request builder. } @@ -146,8 +158,9 @@ static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) @TargetApi(Build.VERSION_CODES.R) // All of these cases deliberately fall through to get the best available profile. @SuppressWarnings({"fallthrough", "deprecation"}) + @NonNull public static CamcorderProfile getBestAvailableCamcorderProfileForResolutionPresetLegacy( - int cameraId, ResolutionPreset preset) { + int cameraId, @NonNull ResolutionPreset preset) { if (cameraId < 0) { throw new AssertionError( "getBestAvailableCamcorderProfileForResolutionPreset can only be used with valid (>=0) camera identifiers."); @@ -197,8 +210,9 @@ public static CamcorderProfile getBestAvailableCamcorderProfileForResolutionPres @TargetApi(Build.VERSION_CODES.S) // All of these cases deliberately fall through to get the best available profile. @SuppressWarnings("fallthrough") + @NonNull public static EncoderProfiles getBestAvailableCamcorderProfileForResolutionPreset( - int cameraId, ResolutionPreset preset) { + int cameraId, @NonNull ResolutionPreset preset) { if (cameraId < 0) { throw new AssertionError( "getBestAvailableCamcorderProfileForResolutionPreset can only be used with valid (>=0) camera identifiers."); diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManager.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManager.java index ec6fa13dbd1d..fd670715825c 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManager.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManager.java @@ -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; @@ -35,6 +36,7 @@ public class DeviceOrientationManager { private BroadcastReceiver broadcastReceiver; /** Factory method to create a device orientation manager. */ + @NonNull public static DeviceOrientationManager create( @NonNull Activity activity, @NonNull DartMessenger messenger, @@ -112,7 +114,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) { @@ -169,7 +171,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. @@ -200,6 +202,7 @@ public int getVideoOrientation(PlatformChannel.DeviceOrientation orientation) { } /** @return the last received UI orientation. */ + @Nullable public PlatformChannel.DeviceOrientation getLastUIOrientation() { return this.lastOrientation; } @@ -242,6 +245,8 @@ static void handleOrientationChange( * * @return The current user interface orientation. */ + // Configuration.ORIENTATION_SQUARE is deprecated. + @SuppressWarnings("deprecation") @VisibleForTesting PlatformChannel.DeviceOrientation getUIOrientation() { final int rotation = getDisplay().getRotation(); @@ -260,6 +265,8 @@ PlatformChannel.DeviceOrientation getUIOrientation() { } else { return PlatformChannel.DeviceOrientation.LANDSCAPE_RIGHT; } + case Configuration.ORIENTATION_SQUARE: + case Configuration.ORIENTATION_UNDEFINED: default: return PlatformChannel.DeviceOrientation.PORTRAIT_UP; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/sensororientation/SensorOrientationFeature.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/sensororientation/SensorOrientationFeature.java index 9e316f741805..5f2516d594d9 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/sensororientation/SensorOrientationFeature.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/sensororientation/SensorOrientationFeature.java @@ -4,10 +4,12 @@ package io.flutter.plugins.camera.features.sensororientation; +import android.annotation.SuppressLint; import android.app.Activity; import android.hardware.camera2.CameraMetadata; import android.hardware.camera2.CaptureRequest; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import io.flutter.embedding.engine.systemchannels.PlatformChannel; import io.flutter.plugins.camera.CameraProperties; import io.flutter.plugins.camera.DartMessenger; @@ -16,9 +18,9 @@ /** Provides access to the sensor orientation of the camera devices. */ public class SensorOrientationFeature extends CameraFeature { - private Integer currentSetting = 0; - private final DeviceOrientationManager deviceOrientationListener; - private PlatformChannel.DeviceOrientation lockedCaptureOrientation; + @NonNull private Integer currentSetting = 0; + @NonNull private final DeviceOrientationManager deviceOrientationListener; + @Nullable private PlatformChannel.DeviceOrientation lockedCaptureOrientation; /** * Creates a new instance of the {@link ResolutionFeature}. @@ -42,18 +44,21 @@ public SensorOrientationFeature( deviceOrientationListener.start(); } + @NonNull @Override public String getDebugName() { return "SensorOrientationFeature"; } + @SuppressLint("KotlinPropertyAccess") + @NonNull @Override public Integer getValue() { return currentSetting; } @Override - public void setValue(Integer value) { + public void setValue(@NonNull Integer value) { this.currentSetting = value; } @@ -63,7 +68,7 @@ public boolean checkIsSupported() { } @Override - public void updateBuilder(CaptureRequest.Builder requestBuilder) { + public void updateBuilder(@NonNull CaptureRequest.Builder requestBuilder) { // Noop: when setting the sensor orientation there is no need to update the request builder. } @@ -72,6 +77,7 @@ public void updateBuilder(CaptureRequest.Builder requestBuilder) { * * @return The instance of the {@link DeviceOrientationManager}. */ + @NonNull public DeviceOrientationManager getDeviceOrientationManager() { return this.deviceOrientationListener; } @@ -82,7 +88,7 @@ public DeviceOrientationManager getDeviceOrientationManager() { * * @param orientation The orientation in which to lock the capture orientation. */ - public void lockCaptureOrientation(PlatformChannel.DeviceOrientation orientation) { + public void lockCaptureOrientation(@NonNull PlatformChannel.DeviceOrientation orientation) { this.lockedCaptureOrientation = orientation; } @@ -99,6 +105,7 @@ public void unlockCaptureOrientation() { * * @return The configured locked capture orientation. */ + @Nullable public PlatformChannel.DeviceOrientation getLockedCaptureOrientation() { return this.lockedCaptureOrientation; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/zoomlevel/ZoomLevelFeature.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/zoomlevel/ZoomLevelFeature.java index 2ac70822eb77..dda06845da2f 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/zoomlevel/ZoomLevelFeature.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/zoomlevel/ZoomLevelFeature.java @@ -4,9 +4,11 @@ package io.flutter.plugins.camera.features.zoomlevel; +import android.annotation.SuppressLint; import android.graphics.Rect; import android.hardware.camera2.CaptureRequest; import android.os.Build; +import androidx.annotation.NonNull; import io.flutter.plugins.camera.CameraProperties; import io.flutter.plugins.camera.features.CameraFeature; @@ -15,16 +17,16 @@ public class ZoomLevelFeature extends CameraFeature { private static final Float DEFAULT_ZOOM_LEVEL = 1.0f; private final boolean hasSupport; private final Rect sensorArraySize; - private Float currentSetting = DEFAULT_ZOOM_LEVEL; + @NonNull private Float currentSetting = DEFAULT_ZOOM_LEVEL; private Float minimumZoomLevel = currentSetting; - private Float maximumZoomLevel; + private final Float maximumZoomLevel; /** * Creates a new instance of the {@link ZoomLevelFeature}. * * @param cameraProperties Collection of characteristics for the current camera device. */ - public ZoomLevelFeature(CameraProperties cameraProperties) { + public ZoomLevelFeature(@NonNull CameraProperties cameraProperties) { super(cameraProperties); sensorArraySize = cameraProperties.getSensorInfoActiveArraySize(); @@ -50,18 +52,21 @@ public ZoomLevelFeature(CameraProperties cameraProperties) { hasSupport = (Float.compare(maximumZoomLevel, minimumZoomLevel) > 0); } + @NonNull @Override public String getDebugName() { return "ZoomLevelFeature"; } + @SuppressLint("KotlinPropertyAccess") + @NonNull @Override public Float getValue() { return currentSetting; } @Override - public void setValue(Float value) { + public void setValue(@NonNull Float value) { currentSetting = value; } @@ -71,7 +76,7 @@ public boolean checkIsSupported() { } @Override - public void updateBuilder(CaptureRequest.Builder requestBuilder) { + public void updateBuilder(@NonNull CaptureRequest.Builder requestBuilder) { if (!checkIsSupported()) { return; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java index 1f9f6200bb99..f55552edf898 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java @@ -57,16 +57,19 @@ public MediaRecorderBuilder( this.recorderFactory = helper; } + @NonNull public MediaRecorderBuilder setEnableAudio(boolean enableAudio) { this.enableAudio = enableAudio; return this; } + @NonNull public MediaRecorderBuilder setMediaOrientation(int orientation) { this.mediaOrientation = orientation; return this; } + @NonNull public MediaRecorder build() throws IOException, NullPointerException, IndexOutOfBoundsException { MediaRecorder mediaRecorder = recorderFactory.makeMediaRecorder(); @@ -90,7 +93,7 @@ public MediaRecorder build() throws IOException, NullPointerException, IndexOutO mediaRecorder.setVideoFrameRate(videoProfile.getFrameRate()); mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); - } else { + } else if (camcorderProfile != null) { mediaRecorder.setOutputFormat(camcorderProfile.fileFormat); if (enableAudio) { mediaRecorder.setAudioEncoder(camcorderProfile.audioCodec); diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/CameraCaptureProperties.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/CameraCaptureProperties.java index 68177f4ecfd6..c35483c81655 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/CameraCaptureProperties.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/CameraCaptureProperties.java @@ -4,6 +4,9 @@ package io.flutter.plugins.camera.types; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + public class CameraCaptureProperties { private Float lastLensAperture; @@ -15,6 +18,7 @@ public class CameraCaptureProperties { * * @return the last known lens aperture. (As f-stop value) */ + @Nullable public Float getLastLensAperture() { return lastLensAperture; } @@ -24,7 +28,7 @@ public Float getLastLensAperture() { * * @param lastLensAperture - The last known lens aperture to set. (As f-stop value) */ - public void setLastLensAperture(Float lastLensAperture) { + public void setLastLensAperture(@NonNull Float lastLensAperture) { this.lastLensAperture = lastLensAperture; } @@ -33,6 +37,7 @@ public void setLastLensAperture(Float lastLensAperture) { * * @return the last known sensor exposure time in nanoseconds. */ + @Nullable public Long getLastSensorExposureTime() { return lastSensorExposureTime; } @@ -42,7 +47,7 @@ public Long getLastSensorExposureTime() { * * @param lastSensorExposureTime - The last known sensor exposure time to set, in nanoseconds. */ - public void setLastSensorExposureTime(Long lastSensorExposureTime) { + public void setLastSensorExposureTime(@NonNull Long lastSensorExposureTime) { this.lastSensorExposureTime = lastSensorExposureTime; } @@ -51,6 +56,7 @@ public void setLastSensorExposureTime(Long lastSensorExposureTime) { * * @return the last known sensor sensitivity in ISO arithmetic units. */ + @Nullable public Integer getLastSensorSensitivity() { return lastSensorSensitivity; } @@ -61,7 +67,7 @@ public Integer getLastSensorSensitivity() { * @param lastSensorSensitivity - The last known sensor sensitivity to set, in ISO arithmetic * units. */ - public void setLastSensorSensitivity(Integer lastSensorSensitivity) { + public void setLastSensorSensitivity(@NonNull Integer lastSensorSensitivity) { this.lastSensorSensitivity = lastSensorSensitivity; } } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/CaptureTimeoutsWrapper.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/CaptureTimeoutsWrapper.java index ad59bd09c754..2d5d2b7b7efe 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/CaptureTimeoutsWrapper.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/CaptureTimeoutsWrapper.java @@ -4,6 +4,8 @@ package io.flutter.plugins.camera.types; +import androidx.annotation.NonNull; + /** * Wrapper class that provides a container for all {@link Timeout} instances that are required for * the capture flow. @@ -24,6 +26,8 @@ public CaptureTimeoutsWrapper( long preCaptureFocusingTimeoutMs, long preCaptureMeteringTimeoutMs) { this.preCaptureFocusingTimeoutMs = preCaptureFocusingTimeoutMs; this.preCaptureMeteringTimeoutMs = preCaptureMeteringTimeoutMs; + this.preCaptureFocusing = Timeout.create(preCaptureFocusingTimeoutMs); + this.preCaptureMetering = Timeout.create(preCaptureMeteringTimeoutMs); } /** Reset all timeouts to the current timestamp. */ @@ -37,6 +41,7 @@ public void reset() { * * @return - The timeout object */ + @NonNull public Timeout getPreCaptureFocusing() { return preCaptureFocusing; } @@ -46,6 +51,7 @@ public Timeout getPreCaptureFocusing() { * * @return - The timeout object */ + @NonNull public Timeout getPreCaptureMetering() { return preCaptureMetering; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/ExposureMode.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/ExposureMode.java index 0bd23945e3f7..1942808657bd 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/ExposureMode.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/ExposureMode.java @@ -4,6 +4,9 @@ package io.flutter.plugins.camera.types; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + // Mirrors exposure_mode.dart public enum ExposureMode { auto("auto"), @@ -15,7 +18,8 @@ public enum ExposureMode { this.strValue = strValue; } - public static ExposureMode getValueForString(String modeStr) { + @Nullable + public static ExposureMode getValueForString(@NonNull String modeStr) { for (ExposureMode value : values()) { if (value.strValue.equals(modeStr)) return value; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/FlashMode.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/FlashMode.java index d7b661380098..28c990bfb6ff 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/FlashMode.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/FlashMode.java @@ -4,6 +4,9 @@ package io.flutter.plugins.camera.types; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + // Mirrors flash_mode.dart public enum FlashMode { off("off"), @@ -17,7 +20,8 @@ public enum FlashMode { this.strValue = strValue; } - public static FlashMode getValueForString(String modeStr) { + @Nullable + public static FlashMode getValueForString(@NonNull String modeStr) { for (FlashMode value : values()) { if (value.strValue.equals(modeStr)) return value; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/FocusMode.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/FocusMode.java index c879593d4f21..ad7afebdada2 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/FocusMode.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/FocusMode.java @@ -4,6 +4,9 @@ package io.flutter.plugins.camera.types; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + // Mirrors focus_mode.dart public enum FocusMode { auto("auto"), @@ -15,7 +18,8 @@ public enum FocusMode { this.strValue = strValue; } - public static FocusMode getValueForString(String modeStr) { + @Nullable + public static FocusMode getValueForString(@NonNull String modeStr) { for (FocusMode value : values()) { if (value.strValue.equals(modeStr)) return value; } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/Timeout.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/Timeout.java index 67e05499d47a..c89bb2191f38 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/Timeout.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/types/Timeout.java @@ -5,6 +5,7 @@ package io.flutter.plugins.camera.types; import android.os.SystemClock; +import androidx.annotation.NonNull; /** * This is a simple class for managing a timeout. In the camera we generally keep two timeouts: one @@ -30,6 +31,7 @@ public class Timeout { * @param timeoutMs timeout to use. * @return returns a new Timeout. */ + @NonNull public static Timeout create(long timeoutMs) { return new Timeout(timeoutMs); } diff --git a/packages/camera/camera_android/pubspec.yaml b/packages/camera/camera_android/pubspec.yaml index aff401efcde7..4e05a55f4d23 100644 --- a/packages/camera/camera_android/pubspec.yaml +++ b/packages/camera/camera_android/pubspec.yaml @@ -2,7 +2,7 @@ name: camera_android description: Android implementation of the camera plugin. repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.10.5 +version: 0.10.6 environment: sdk: ">=2.17.0 <4.0.0"