Skip to content

Commit 9989606

Browse files
[camera_android] Fix Android lint warnings (#3716)
Removes the lint-baseline.xml file, and fixes all issues. The `KotlinPropertyAccess` doesn't seem to work well with generics. For example, ```java class CameraFeature<T> { T getValue(); } class ExposureFeature extends CameraFeature<Exposure> { @OverRide Exposure getValue() { ... } } ``` The `ExposureFeature.getValue` causes the lint warning. I went ahead and suppressed this for all `CameraFeatures`. I also added `@Nonnull` or `@Nullable` to some private fields that weren't required. This helped deduce whether a value was always nonnull or not. Part of flutter/flutter#88011
1 parent 6e71978 commit 9989606

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+391
-3276
lines changed

packages/camera/camera_android/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
## 0.10.6
2+
3+
* Fixes Java warnings.
4+
15
## 0.10.5
26

37
* Allows camera to be switched while video recording.
8+
49
## 0.10.4+3
510

611
* Clarifies explanation of endorsement in README.

packages/camera/camera_android/android/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ android {
3838
checkAllWarnings true
3939
warningsAsErrors true
4040
disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency'
41-
baseline file("lint-baseline.xml")
4241
}
4342
compileOptions {
4443
sourceCompatibility JavaVersion.VERSION_1_8

packages/camera/camera_android/android/lint-baseline.xml

Lines changed: 0 additions & 3106 deletions
This file was deleted.

packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/Camera.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class Camera
9696
* Holds all of the camera features/settings and will be used to update the request builder when
9797
* one changes.
9898
*/
99-
private CameraFeatures cameraFeatures;
99+
CameraFeatures cameraFeatures;
100100

101101
private String imageFormatGroup;
102102

@@ -116,28 +116,28 @@ class Camera
116116
private final ResolutionPreset resolutionPreset;
117117
private final boolean enableAudio;
118118
private final Context applicationContext;
119-
private final DartMessenger dartMessenger;
119+
final DartMessenger dartMessenger;
120120
private CameraProperties cameraProperties;
121121
private final CameraFeatureFactory cameraFeatureFactory;
122122
private final Activity activity;
123123
/** A {@link CameraCaptureSession.CaptureCallback} that handles events related to JPEG capture. */
124124
private final CameraCaptureCallback cameraCaptureCallback;
125125
/** A {@link Handler} for running tasks in the background. */
126-
private Handler backgroundHandler;
126+
Handler backgroundHandler;
127127

128128
/** An additional thread for running tasks that shouldn't block the UI. */
129129
private HandlerThread backgroundHandlerThread;
130130

131-
private CameraDeviceWrapper cameraDevice;
132-
private CameraCaptureSession captureSession;
131+
CameraDeviceWrapper cameraDevice;
132+
CameraCaptureSession captureSession;
133133
private ImageReader pictureImageReader;
134-
private ImageReader imageStreamReader;
134+
ImageReader imageStreamReader;
135135
/** {@link CaptureRequest.Builder} for the camera preview */
136-
private CaptureRequest.Builder previewRequestBuilder;
136+
CaptureRequest.Builder previewRequestBuilder;
137137

138138
private MediaRecorder mediaRecorder;
139139
/** True when recording video. */
140-
private boolean recordingVideo;
140+
boolean recordingVideo;
141141
/** True when the preview is paused. */
142142
private boolean pausedPreview;
143143

@@ -148,13 +148,13 @@ class Camera
148148
/** Holds the last known capture properties */
149149
private CameraCaptureProperties captureProps;
150150

151-
private MethodChannel.Result flutterResult;
151+
MethodChannel.Result flutterResult;
152152

153153
/** A CameraDeviceWrapper implementation that forwards calls to a CameraDevice. */
154154
private class DefaultCameraDeviceWrapper implements CameraDeviceWrapper {
155155
private final CameraDevice cameraDevice;
156156

157-
private DefaultCameraDeviceWrapper(CameraDevice cameraDevice) {
157+
DefaultCameraDeviceWrapper(CameraDevice cameraDevice) {
158158
this.cameraDevice = cameraDevice;
159159
}
160160

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

174-
@TargetApi(VERSION_CODES.LOLLIPOP)
175174
@SuppressWarnings("deprecation")
176175
@Override
177176
public void createCaptureSession(
@@ -235,9 +234,11 @@ public void onPrecapture() {
235234
*
236235
* @param requestBuilder request builder to update.
237236
*/
238-
private void updateBuilderSettings(CaptureRequest.Builder requestBuilder) {
237+
void updateBuilderSettings(CaptureRequest.Builder requestBuilder) {
239238
for (CameraFeature<?> feature : cameraFeatures.getAllFeatures()) {
240-
Log.d(TAG, "Updating builder with feature: " + feature.getDebugName());
239+
if (BuildConfig.DEBUG) {
240+
Log.d(TAG, "Updating builder with feature: " + feature.getDebugName());
241+
}
241242
feature.updateBuilder(requestBuilder);
242243
}
243244
}
@@ -331,7 +332,9 @@ public void onOpened(@NonNull CameraDevice device) {
331332
cameraFeatures.getFocusPoint().checkIsSupported());
332333

333334
} catch (Exception e) {
334-
Log.i(TAG, "open | onOpened error: " + e.getMessage());
335+
if (BuildConfig.DEBUG) {
336+
Log.i(TAG, "open | onOpened error: " + e.getMessage());
337+
}
335338
dartMessenger.sendCameraErrorEvent(e.getMessage());
336339
close();
337340
}
@@ -489,7 +492,6 @@ private void createCaptureSessionWithSessionConfig(
489492
callback));
490493
}
491494

492-
@TargetApi(VERSION_CODES.LOLLIPOP)
493495
@SuppressWarnings("deprecation")
494496
private void createCaptureSession(
495497
List<Surface> surfaces, CameraCaptureSession.StateCallback callback)
@@ -498,7 +500,7 @@ private void createCaptureSession(
498500
}
499501

500502
// Send a repeating request to refresh capture session.
501-
private void refreshPreviewCaptureSession(
503+
void refreshPreviewCaptureSession(
502504
@Nullable Runnable onSuccessCallback, @NonNull ErrorCallback onErrorCallback) {
503505
Log.i(TAG, "refreshPreviewCaptureSession");
504506

@@ -722,7 +724,7 @@ private void lockAutoFocus() {
722724
}
723725

724726
/** Cancel and reset auto focus state and refresh the preview session. */
725-
private void unlockAutoFocus() {
727+
void unlockAutoFocus() {
726728
Log.i(TAG, "unlockAutoFocus");
727729
if (captureSession == null) {
728730
Log.i(TAG, "[unlockAutoFocus] captureSession null, returning");
@@ -1194,7 +1196,7 @@ public void onCancel(Object o) {
11941196
});
11951197
}
11961198

1197-
private void setImageStreamImageAvailableListener(final EventChannel.EventSink imageStreamSink) {
1199+
void setImageStreamImageAvailableListener(final EventChannel.EventSink imageStreamSink) {
11981200
imageStreamReader.setOnImageAvailableListener(
11991201
reader -> {
12001202
Image img = reader.acquireNextImage();
@@ -1234,7 +1236,7 @@ private void setImageStreamImageAvailableListener(final EventChannel.EventSink i
12341236
backgroundHandler);
12351237
}
12361238

1237-
private void closeCaptureSession() {
1239+
void closeCaptureSession() {
12381240
if (captureSession != null) {
12391241
Log.i(TAG, "closeCaptureSession");
12401242

packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraPlugin.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package io.flutter.plugins.camera;
66

77
import android.app.Activity;
8-
import android.os.Build;
98
import androidx.annotation.NonNull;
109
import androidx.annotation.Nullable;
1110
import io.flutter.embedding.engine.plugins.FlutterPlugin;
@@ -45,7 +44,8 @@ public CameraPlugin() {}
4544
* won't react to changes in activity or context, unlike {@link CameraPlugin}.
4645
*/
4746
@SuppressWarnings("deprecation")
48-
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
47+
public static void registerWith(
48+
@NonNull io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
4949
CameraPlugin plugin = new CameraPlugin();
5050
plugin.maybeStartListening(
5151
registrar.activity(),
@@ -97,11 +97,6 @@ private void maybeStartListening(
9797
BinaryMessenger messenger,
9898
PermissionsRegistry permissionsRegistry,
9999
TextureRegistry textureRegistry) {
100-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
101-
// If the sdk is less than 21 (min sdk for Camera2) we don't register the plugin.
102-
return;
103-
}
104-
105100
methodCallHandler =
106101
new MethodCallHandlerImpl(
107102
activity, messenger, new CameraPermissions(), permissionsRegistry, textureRegistry);

packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraProperties.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import android.os.Build.VERSION_CODES;
99
import android.util.Range;
1010
import android.util.Size;
11+
import androidx.annotation.NonNull;
12+
import androidx.annotation.Nullable;
1113
import androidx.annotation.RequiresApi;
1214

1315
/** An interface allowing access to the different characteristics of the device's camera. */
@@ -18,6 +20,7 @@ public interface CameraProperties {
1820
*
1921
* @return String The name of the camera device.
2022
*/
23+
@NonNull
2124
String getCameraName();
2225

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

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

4853
/**
@@ -64,6 +69,7 @@ public interface CameraProperties {
6469
*
6570
* @return int[] List of auto-focus modes supported by this camera device.
6671
*/
72+
@NonNull
6773
int[] getControlAutoFocusAvailableModes();
6874

6975
/**
@@ -75,6 +81,7 @@ public interface CameraProperties {
7581
* @return Integer Maximum number of metering regions that can be used by the auto-exposure
7682
* routine.
7783
*/
84+
@NonNull
7885
Integer getControlMaxRegionsAutoExposure();
7986

8087
/**
@@ -85,6 +92,7 @@ public interface CameraProperties {
8592
*
8693
* @return Integer Maximum number of metering regions that can be used by the auto-focus routine.
8794
*/
95+
@NonNull
8896
Integer getControlMaxRegionsAutoFocus();
8997

9098
/**
@@ -97,6 +105,7 @@ public interface CameraProperties {
97105
* @return int[] List of distortion correction modes supported by this camera device.
98106
*/
99107
@RequiresApi(api = VERSION_CODES.P)
108+
@Nullable
100109
int[] getDistortionCorrectionAvailableModes();
101110

102111
/**
@@ -107,6 +116,7 @@ public interface CameraProperties {
107116
*
108117
* @return Boolean Whether this camera device has a flash unit.
109118
*/
119+
@NonNull
110120
Boolean getFlashInfoAvailable();
111121

112122
/**
@@ -136,6 +146,7 @@ public interface CameraProperties {
136146
* @return Float Shortest distance from front most surface of the lens that can be brought into
137147
* sharp focus.
138148
*/
149+
@Nullable
139150
Float getLensInfoMinimumFocusDistance();
140151

141152
/**
@@ -148,6 +159,7 @@ public interface CameraProperties {
148159
* @return Float Maximum ratio between both active area width and crop region width, and active
149160
* area height and crop region height.
150161
*/
162+
@NonNull
151163
Float getScalerAvailableMaxDigitalZoom();
152164

153165
/**
@@ -159,6 +171,7 @@ public interface CameraProperties {
159171
*
160172
* @return Float Minimum ratio between the default zoom ratio and the minimum possible zoom.
161173
*/
174+
@Nullable
162175
@RequiresApi(api = VERSION_CODES.R)
163176
Float getScalerMinZoomRatio();
164177

@@ -171,6 +184,7 @@ public interface CameraProperties {
171184
*
172185
* @return Float Maximum ratio between the default zoom ratio and the maximum possible zoom.
173186
*/
187+
@Nullable
174188
@RequiresApi(api = VERSION_CODES.R)
175189
Float getScalerMaxZoomRatio();
176190

@@ -184,6 +198,7 @@ public interface CameraProperties {
184198
* @return android.graphics.Rect area of the image sensor which corresponds to active pixels after
185199
* any geometric distortion correction has been applied.
186200
*/
201+
@NonNull
187202
Rect getSensorInfoActiveArraySize();
188203

189204
/**
@@ -195,6 +210,7 @@ public interface CameraProperties {
195210
* @return android.util.Size Dimensions of the full pixel array, possibly including black
196211
* calibration pixels.
197212
*/
213+
@NonNull
198214
Size getSensorInfoPixelArraySize();
199215

200216
/**
@@ -209,6 +225,7 @@ public interface CameraProperties {
209225
* to the application of any geometric distortion correction.
210226
*/
211227
@RequiresApi(api = VERSION_CODES.M)
228+
@NonNull
212229
Rect getSensorInfoPreCorrectionActiveArraySize();
213230

214231
/**
@@ -254,5 +271,6 @@ public interface CameraProperties {
254271
*
255272
* @return int[] List of noise reduction modes that are supported by this camera device.
256273
*/
274+
@NonNull
257275
int[] getAvailableNoiseReductionModes();
258276
}

0 commit comments

Comments
 (0)