Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[camera_android] Fix Android lint warnings #3716

Merged
merged 7 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/camera/camera_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 0 additions & 1 deletion packages/camera/camera_android/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ android {
checkAllWarnings true
warningsAsErrors true
disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency'
baseline file("lint-baseline.xml")
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
3,106 changes: 0 additions & 3,106 deletions packages/camera/camera_android/android/lint-baseline.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;
}

Expand All @@ -171,7 +171,6 @@ public void createCaptureSession(SessionConfiguration config) throws CameraAcces
cameraDevice.createCaptureSession(config);
}

@TargetApi(VERSION_CODES.LOLLIPOP)
@SuppressWarnings("deprecation")
@Override
public void createCaptureSession(
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -489,7 +492,6 @@ private void createCaptureSessionWithSessionConfig(
callback));
}

@TargetApi(VERSION_CODES.LOLLIPOP)
@SuppressWarnings("deprecation")
private void createCaptureSession(
List<Surface> surfaces, CameraCaptureSession.StateCallback callback)
Expand All @@ -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");

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1234,7 +1236,7 @@ private void setImageStreamImageAvailableListener(final EventChannel.EventSink i
backgroundHandler);
}

private void closeCaptureSession() {
void closeCaptureSession() {
if (captureSession != null) {
Log.i(TAG, "closeCaptureSession");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -97,11 +97,6 @@ private void maybeStartListening(
BinaryMessenger messenger,
PermissionsRegistry permissionsRegistry,
TextureRegistry textureRegistry) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

min version is 21 already

// 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);
Expand Down
Copy link
Contributor Author

@bparrishMines bparrishMines Apr 14, 2023

Choose a reason for hiding this comment

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -18,6 +20,7 @@ public interface CameraProperties {
*
* @return String The name of the camera device.
*/
@NonNull
String getCameraName();

/**
Expand All @@ -30,6 +33,7 @@ public interface CameraProperties {
* @return android.util.Range<Integer>[] List of frame rate ranges supported by this camera
* device.
*/
@NonNull
Range<Integer>[] getControlAutoExposureAvailableTargetFpsRanges();

/**
Expand All @@ -43,6 +47,7 @@ public interface CameraProperties {
* @return android.util.Range<Integer> Maximum and minimum exposure compensation supported by this
* camera device.
*/
@NonNull
Range<Integer> getControlAutoExposureCompensationRange();

/**
Expand All @@ -64,6 +69,7 @@ public interface CameraProperties {
*
* @return int[] List of auto-focus modes supported by this camera device.
*/
@NonNull
int[] getControlAutoFocusAvailableModes();

/**
Expand All @@ -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();

/**
Expand All @@ -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();

/**
Expand All @@ -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();

/**
Expand All @@ -107,6 +116,7 @@ public interface CameraProperties {
*
* @return Boolean Whether this camera device has a flash unit.
*/
@NonNull
Boolean getFlashInfoAvailable();

/**
Expand Down Expand Up @@ -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();

/**
Expand All @@ -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();

/**
Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

/**
Expand All @@ -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();

/**
Expand All @@ -209,6 +225,7 @@ public interface CameraProperties {
* to the application of any geometric distortion correction.
*/
@RequiresApi(api = VERSION_CODES.M)
@NonNull
Rect getSensorInfoPreCorrectionActiveArraySize();

/**
Expand Down Expand Up @@ -254,5 +271,6 @@ public interface CameraProperties {
*
* @return int[] List of noise reduction modes that are supported by this camera device.
*/
@NonNull
int[] getAvailableNoiseReductionModes();
}
Loading