Skip to content

Commit c40f189

Browse files
[camera_android] Fix camera android deprecation warning for CamcorderProfile.get() (#3273)
[camera_android] Fix camera android deprecation warning for CamcorderProfile.get()
1 parent 789e3a7 commit c40f189

File tree

14 files changed

+218
-178
lines changed

14 files changed

+218
-178
lines changed

packages/camera/camera_android/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
## NEXT
1+
## 0.10.4+2
22

33
* Aligns Dart and Flutter SDK constraints.
44
* Updates compileSdkVersion to 33.
5+
* Fixes false positive for CamcorderProfile deprecation warning
6+
that was already fixed.
7+
* Changes the severity of `javac` warnings so that they are treated as errors and fixes the violations.
58

69
## 0.10.4+1
710

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

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import io.flutter.plugins.camera.features.resolution.ResolutionFeature;
5858
import io.flutter.plugins.camera.features.resolution.ResolutionPreset;
5959
import io.flutter.plugins.camera.features.sensororientation.DeviceOrientationManager;
60-
import io.flutter.plugins.camera.features.sensororientation.SensorOrientationFeature;
6160
import io.flutter.plugins.camera.features.zoomlevel.ZoomLevelFeature;
6261
import io.flutter.plugins.camera.media.MediaRecorderBuilder;
6362
import io.flutter.plugins.camera.types.CameraCaptureProperties;
@@ -79,24 +78,6 @@ interface ErrorCallback {
7978
void onError(String errorCode, String errorMessage);
8079
}
8180

82-
/** A mockable wrapper for CameraDevice calls. */
83-
interface CameraDeviceWrapper {
84-
@NonNull
85-
CaptureRequest.Builder createCaptureRequest(int templateType) throws CameraAccessException;
86-
87-
@TargetApi(VERSION_CODES.P)
88-
void createCaptureSession(SessionConfiguration config) throws CameraAccessException;
89-
90-
@TargetApi(VERSION_CODES.LOLLIPOP)
91-
void createCaptureSession(
92-
@NonNull List<Surface> outputs,
93-
@NonNull CameraCaptureSession.StateCallback callback,
94-
@Nullable Handler handler)
95-
throws CameraAccessException;
96-
97-
void close();
98-
}
99-
10081
class Camera
10182
implements CameraCaptureCallback.CameraCaptureStateListener,
10283
ImageReader.OnImageAvailableListener {
@@ -239,7 +220,7 @@ public void onPrecapture() {
239220
* @param requestBuilder request builder to update.
240221
*/
241222
private void updateBuilderSettings(CaptureRequest.Builder requestBuilder) {
242-
for (CameraFeature feature : cameraFeatures.getAllFeatures()) {
223+
for (CameraFeature<?> feature : cameraFeatures.getAllFeatures()) {
243224
Log.d(TAG, "Updating builder with feature: " + feature.getDebugName());
244225
feature.updateBuilder(requestBuilder);
245226
}
@@ -253,8 +234,7 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException {
253234
}
254235

255236
final PlatformChannel.DeviceOrientation lockedOrientation =
256-
((SensorOrientationFeature) cameraFeatures.getSensorOrientation())
257-
.getLockedCaptureOrientation();
237+
cameraFeatures.getSensorOrientation().getLockedCaptureOrientation();
258238

259239
MediaRecorderBuilder mediaRecorderBuilder;
260240

@@ -637,8 +617,7 @@ private void takePictureAfterPrecapture() {
637617

638618
// Orientation.
639619
final PlatformChannel.DeviceOrientation lockedOrientation =
640-
((SensorOrientationFeature) cameraFeatures.getSensorOrientation())
641-
.getLockedCaptureOrientation();
620+
cameraFeatures.getSensorOrientation().getLockedCaptureOrientation();
642621
stillBuilder.set(
643622
CaptureRequest.JPEG_ORIENTATION,
644623
lockedOrientation == null
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.camera;
6+
7+
import android.annotation.TargetApi;
8+
import android.hardware.camera2.CameraAccessException;
9+
import android.hardware.camera2.CameraCaptureSession;
10+
import android.hardware.camera2.CaptureRequest;
11+
import android.hardware.camera2.params.SessionConfiguration;
12+
import android.os.Build;
13+
import android.os.Handler;
14+
import android.view.Surface;
15+
import androidx.annotation.NonNull;
16+
import androidx.annotation.Nullable;
17+
import java.util.List;
18+
19+
/** A mockable wrapper for CameraDevice calls. */
20+
interface CameraDeviceWrapper {
21+
@NonNull
22+
CaptureRequest.Builder createCaptureRequest(int templateType) throws CameraAccessException;
23+
24+
@TargetApi(Build.VERSION_CODES.P)
25+
void createCaptureSession(SessionConfiguration config) throws CameraAccessException;
26+
27+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
28+
void createCaptureSession(
29+
@NonNull List<Surface> outputs,
30+
@NonNull CameraCaptureSession.StateCallback callback,
31+
@Nullable Handler handler)
32+
throws CameraAccessException;
33+
34+
void close();
35+
}

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

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
package io.flutter.plugins.camera;
66

77
import android.graphics.Rect;
8-
import android.hardware.camera2.CameraAccessException;
9-
import android.hardware.camera2.CameraCharacteristics;
10-
import android.hardware.camera2.CameraManager;
118
import android.os.Build.VERSION_CODES;
129
import android.util.Range;
13-
import android.util.Rational;
1410
import android.util.Size;
1511
import androidx.annotation.RequiresApi;
1612

@@ -260,127 +256,3 @@ public interface CameraProperties {
260256
*/
261257
int[] getAvailableNoiseReductionModes();
262258
}
263-
264-
/**
265-
* Implementation of the @see CameraProperties interface using the @see
266-
* android.hardware.camera2.CameraCharacteristics class to access the different characteristics.
267-
*/
268-
class CameraPropertiesImpl implements CameraProperties {
269-
private final CameraCharacteristics cameraCharacteristics;
270-
private final String cameraName;
271-
272-
public CameraPropertiesImpl(String cameraName, CameraManager cameraManager)
273-
throws CameraAccessException {
274-
this.cameraName = cameraName;
275-
this.cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraName);
276-
}
277-
278-
@Override
279-
public String getCameraName() {
280-
return cameraName;
281-
}
282-
283-
@Override
284-
public Range<Integer>[] getControlAutoExposureAvailableTargetFpsRanges() {
285-
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
286-
}
287-
288-
@Override
289-
public Range<Integer> getControlAutoExposureCompensationRange() {
290-
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
291-
}
292-
293-
@Override
294-
public double getControlAutoExposureCompensationStep() {
295-
Rational rational =
296-
cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP);
297-
298-
return rational == null ? 0.0 : rational.doubleValue();
299-
}
300-
301-
@Override
302-
public int[] getControlAutoFocusAvailableModes() {
303-
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES);
304-
}
305-
306-
@Override
307-
public Integer getControlMaxRegionsAutoExposure() {
308-
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AE);
309-
}
310-
311-
@Override
312-
public Integer getControlMaxRegionsAutoFocus() {
313-
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF);
314-
}
315-
316-
@RequiresApi(api = VERSION_CODES.P)
317-
@Override
318-
public int[] getDistortionCorrectionAvailableModes() {
319-
return cameraCharacteristics.get(CameraCharacteristics.DISTORTION_CORRECTION_AVAILABLE_MODES);
320-
}
321-
322-
@Override
323-
public Boolean getFlashInfoAvailable() {
324-
return cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
325-
}
326-
327-
@Override
328-
public int getLensFacing() {
329-
return cameraCharacteristics.get(CameraCharacteristics.LENS_FACING);
330-
}
331-
332-
@Override
333-
public Float getLensInfoMinimumFocusDistance() {
334-
return cameraCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);
335-
}
336-
337-
@Override
338-
public Float getScalerAvailableMaxDigitalZoom() {
339-
return cameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
340-
}
341-
342-
@RequiresApi(api = VERSION_CODES.R)
343-
@Override
344-
public Float getScalerMaxZoomRatio() {
345-
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE).getUpper();
346-
}
347-
348-
@RequiresApi(api = VERSION_CODES.R)
349-
@Override
350-
public Float getScalerMinZoomRatio() {
351-
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE).getLower();
352-
}
353-
354-
@Override
355-
public Rect getSensorInfoActiveArraySize() {
356-
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
357-
}
358-
359-
@Override
360-
public Size getSensorInfoPixelArraySize() {
361-
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE);
362-
}
363-
364-
@RequiresApi(api = VERSION_CODES.M)
365-
@Override
366-
public Rect getSensorInfoPreCorrectionActiveArraySize() {
367-
return cameraCharacteristics.get(
368-
CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
369-
}
370-
371-
@Override
372-
public int getSensorOrientation() {
373-
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
374-
}
375-
376-
@Override
377-
public int getHardwareLevel() {
378-
return cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
379-
}
380-
381-
@Override
382-
public int[] getAvailableNoiseReductionModes() {
383-
return cameraCharacteristics.get(
384-
CameraCharacteristics.NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES);
385-
}
386-
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.camera;
6+
7+
import android.graphics.Rect;
8+
import android.hardware.camera2.CameraAccessException;
9+
import android.hardware.camera2.CameraCharacteristics;
10+
import android.hardware.camera2.CameraManager;
11+
import android.os.Build.VERSION_CODES;
12+
import android.util.Range;
13+
import android.util.Rational;
14+
import android.util.Size;
15+
import androidx.annotation.RequiresApi;
16+
17+
/**
18+
* Implementation of the @see CameraProperties interface using the @see
19+
* android.hardware.camera2.CameraCharacteristics class to access the different characteristics.
20+
*/
21+
public class CameraPropertiesImpl implements CameraProperties {
22+
private final CameraCharacteristics cameraCharacteristics;
23+
private final String cameraName;
24+
25+
public CameraPropertiesImpl(String cameraName, CameraManager cameraManager)
26+
throws CameraAccessException {
27+
this.cameraName = cameraName;
28+
this.cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraName);
29+
}
30+
31+
@Override
32+
public String getCameraName() {
33+
return cameraName;
34+
}
35+
36+
@Override
37+
public Range<Integer>[] getControlAutoExposureAvailableTargetFpsRanges() {
38+
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
39+
}
40+
41+
@Override
42+
public Range<Integer> getControlAutoExposureCompensationRange() {
43+
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
44+
}
45+
46+
@Override
47+
public double getControlAutoExposureCompensationStep() {
48+
Rational rational =
49+
cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP);
50+
51+
return rational == null ? 0.0 : rational.doubleValue();
52+
}
53+
54+
@Override
55+
public int[] getControlAutoFocusAvailableModes() {
56+
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES);
57+
}
58+
59+
@Override
60+
public Integer getControlMaxRegionsAutoExposure() {
61+
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AE);
62+
}
63+
64+
@Override
65+
public Integer getControlMaxRegionsAutoFocus() {
66+
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF);
67+
}
68+
69+
@RequiresApi(api = VERSION_CODES.P)
70+
@Override
71+
public int[] getDistortionCorrectionAvailableModes() {
72+
return cameraCharacteristics.get(CameraCharacteristics.DISTORTION_CORRECTION_AVAILABLE_MODES);
73+
}
74+
75+
@Override
76+
public Boolean getFlashInfoAvailable() {
77+
return cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
78+
}
79+
80+
@Override
81+
public int getLensFacing() {
82+
return cameraCharacteristics.get(CameraCharacteristics.LENS_FACING);
83+
}
84+
85+
@Override
86+
public Float getLensInfoMinimumFocusDistance() {
87+
return cameraCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);
88+
}
89+
90+
@Override
91+
public Float getScalerAvailableMaxDigitalZoom() {
92+
return cameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
93+
}
94+
95+
@RequiresApi(api = VERSION_CODES.R)
96+
@Override
97+
public Float getScalerMaxZoomRatio() {
98+
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE).getUpper();
99+
}
100+
101+
@RequiresApi(api = VERSION_CODES.R)
102+
@Override
103+
public Float getScalerMinZoomRatio() {
104+
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE).getLower();
105+
}
106+
107+
@Override
108+
public Rect getSensorInfoActiveArraySize() {
109+
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
110+
}
111+
112+
@Override
113+
public Size getSensorInfoPixelArraySize() {
114+
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE);
115+
}
116+
117+
@RequiresApi(api = VERSION_CODES.M)
118+
@Override
119+
public Rect getSensorInfoPreCorrectionActiveArraySize() {
120+
return cameraCharacteristics.get(
121+
CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
122+
}
123+
124+
@Override
125+
public int getSensorOrientation() {
126+
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
127+
}
128+
129+
@Override
130+
public int getHardwareLevel() {
131+
return cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
132+
}
133+
134+
@Override
135+
public int[] getAvailableNoiseReductionModes() {
136+
return cameraCharacteristics.get(
137+
CameraCharacteristics.NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES);
138+
}
139+
}

0 commit comments

Comments
 (0)