Skip to content

[camera_android] Fix camera android deprecation warning for CamcorderProfile.get() #3273

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f584b49
Recreating PR 7062 from flutter/plugins
navaronbracke Feb 23, 2023
ad16b36
Merge branch 'main' into fix_camera_android_deprecation
navaronbracke Mar 3, 2023
a03ebbe
enable javac options for camera_android example
navaronbracke Mar 3, 2023
d109aab
fix redundant casts
navaronbracke Mar 3, 2023
f720424
move CameraPropertiesImpl to its own file; make CameraPropertiesImpl …
navaronbracke Mar 3, 2023
caf0c38
specify Object as type parameter for features map
navaronbracke Mar 3, 2023
fcee0e0
format
navaronbracke Mar 3, 2023
fce7935
use a wildcard instead of Object as type parameter
navaronbracke Mar 4, 2023
95c3ce6
fix version
navaronbracke Mar 4, 2023
6d779be
fix a missing break
navaronbracke Mar 4, 2023
1c2d40b
suppress fallthrough in getBestAvailableCamcorderProfileForResolution…
navaronbracke Mar 4, 2023
a9fd29a
Suppress fallthrough warning in getBestAvailableCamcorderProfileForRe…
navaronbracke Mar 4, 2023
f2bc33d
fix FpsRangeFeatureTest raw types warning
navaronbracke Mar 4, 2023
eae0d34
fix raw types for Range in CameraPropertiesImplTest
navaronbracke Mar 4, 2023
ff1c9bd
use float literal in CameraPropertiesImplTest
navaronbracke Mar 4, 2023
9e735a6
move CameraDeviceWrapper to its own file
navaronbracke Mar 4, 2023
e89cb7b
suppress warnings for unused try block variables
navaronbracke Mar 4, 2023
cd1ffa4
format
navaronbracke Mar 4, 2023
b306ed8
Add missing license header to CameraDeviceWrapper
navaronbracke Mar 4, 2023
0c6c156
feedback
navaronbracke Mar 6, 2023
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: 4 additions & 1 deletion packages/camera/camera_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## NEXT
## 0.10.4+2

* Updates compileSdkVersion to 33.
* Fixes false positive for CamcorderProfile deprecation warning
that was already fixed.
* Changes the severity of `javac` warnings so that they are treated as errors and fixes the violations.

## 0.10.4+1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import io.flutter.plugins.camera.features.resolution.ResolutionFeature;
import io.flutter.plugins.camera.features.resolution.ResolutionPreset;
import io.flutter.plugins.camera.features.sensororientation.DeviceOrientationManager;
import io.flutter.plugins.camera.features.sensororientation.SensorOrientationFeature;
import io.flutter.plugins.camera.features.zoomlevel.ZoomLevelFeature;
import io.flutter.plugins.camera.media.MediaRecorderBuilder;
import io.flutter.plugins.camera.types.CameraCaptureProperties;
Expand All @@ -79,24 +78,6 @@ interface ErrorCallback {
void onError(String errorCode, String errorMessage);
}

/** A mockable wrapper for CameraDevice calls. */
interface CameraDeviceWrapper {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to move this interface to its own file because of a warning.

@NonNull
CaptureRequest.Builder createCaptureRequest(int templateType) throws CameraAccessException;

@TargetApi(VERSION_CODES.P)
void createCaptureSession(SessionConfiguration config) throws CameraAccessException;

@TargetApi(VERSION_CODES.LOLLIPOP)
void createCaptureSession(
@NonNull List<Surface> outputs,
@NonNull CameraCaptureSession.StateCallback callback,
@Nullable Handler handler)
throws CameraAccessException;

void close();
}

class Camera
implements CameraCaptureCallback.CameraCaptureStateListener,
ImageReader.OnImageAvailableListener {
Expand Down Expand Up @@ -239,7 +220,7 @@ public void onPrecapture() {
* @param requestBuilder request builder to update.
*/
private void updateBuilderSettings(CaptureRequest.Builder requestBuilder) {
for (CameraFeature feature : cameraFeatures.getAllFeatures()) {
for (CameraFeature<?> feature : cameraFeatures.getAllFeatures()) {
Log.d(TAG, "Updating builder with feature: " + feature.getDebugName());
feature.updateBuilder(requestBuilder);
}
Expand All @@ -253,8 +234,7 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException {
}

final PlatformChannel.DeviceOrientation lockedOrientation =
((SensorOrientationFeature) cameraFeatures.getSensorOrientation())
.getLockedCaptureOrientation();
cameraFeatures.getSensorOrientation().getLockedCaptureOrientation();

MediaRecorderBuilder mediaRecorderBuilder;

Expand Down Expand Up @@ -637,8 +617,7 @@ private void takePictureAfterPrecapture() {

// Orientation.
final PlatformChannel.DeviceOrientation lockedOrientation =
((SensorOrientationFeature) cameraFeatures.getSensorOrientation())
.getLockedCaptureOrientation();
cameraFeatures.getSensorOrientation().getLockedCaptureOrientation();
stillBuilder.set(
CaptureRequest.JPEG_ORIENTATION,
lockedOrientation == null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.camera;

import android.annotation.TargetApi;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.params.SessionConfiguration;
import android.os.Build;
import android.os.Handler;
import android.view.Surface;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.List;

/** A mockable wrapper for CameraDevice calls. */
interface CameraDeviceWrapper {
@NonNull
CaptureRequest.Builder createCaptureRequest(int templateType) throws CameraAccessException;

@TargetApi(Build.VERSION_CODES.P)
void createCaptureSession(SessionConfiguration config) throws CameraAccessException;

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void createCaptureSession(
@NonNull List<Surface> outputs,
@NonNull CameraCaptureSession.StateCallback callback,
@Nullable Handler handler)
throws CameraAccessException;

void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
package io.flutter.plugins.camera;

import android.graphics.Rect;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager;
import android.os.Build.VERSION_CODES;
import android.util.Range;
import android.util.Rational;
import android.util.Size;
import androidx.annotation.RequiresApi;

Expand Down Expand Up @@ -260,127 +256,3 @@ public interface CameraProperties {
*/
int[] getAvailableNoiseReductionModes();
}

/**
* Implementation of the @see CameraProperties interface using the @see
* android.hardware.camera2.CameraCharacteristics class to access the different characteristics.
*/
class CameraPropertiesImpl implements CameraProperties {
private final CameraCharacteristics cameraCharacteristics;
private final String cameraName;

public CameraPropertiesImpl(String cameraName, CameraManager cameraManager)
throws CameraAccessException {
this.cameraName = cameraName;
this.cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraName);
}

@Override
public String getCameraName() {
return cameraName;
}

@Override
public Range<Integer>[] getControlAutoExposureAvailableTargetFpsRanges() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
}

@Override
public Range<Integer> getControlAutoExposureCompensationRange() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
}

@Override
public double getControlAutoExposureCompensationStep() {
Rational rational =
cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP);

return rational == null ? 0.0 : rational.doubleValue();
}

@Override
public int[] getControlAutoFocusAvailableModes() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES);
}

@Override
public Integer getControlMaxRegionsAutoExposure() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AE);
}

@Override
public Integer getControlMaxRegionsAutoFocus() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF);
}

@RequiresApi(api = VERSION_CODES.P)
@Override
public int[] getDistortionCorrectionAvailableModes() {
return cameraCharacteristics.get(CameraCharacteristics.DISTORTION_CORRECTION_AVAILABLE_MODES);
}

@Override
public Boolean getFlashInfoAvailable() {
return cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
}

@Override
public int getLensFacing() {
return cameraCharacteristics.get(CameraCharacteristics.LENS_FACING);
}

@Override
public Float getLensInfoMinimumFocusDistance() {
return cameraCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);
}

@Override
public Float getScalerAvailableMaxDigitalZoom() {
return cameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
}

@RequiresApi(api = VERSION_CODES.R)
@Override
public Float getScalerMaxZoomRatio() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE).getUpper();
}

@RequiresApi(api = VERSION_CODES.R)
@Override
public Float getScalerMinZoomRatio() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE).getLower();
}

@Override
public Rect getSensorInfoActiveArraySize() {
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
}

@Override
public Size getSensorInfoPixelArraySize() {
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE);
}

@RequiresApi(api = VERSION_CODES.M)
@Override
public Rect getSensorInfoPreCorrectionActiveArraySize() {
return cameraCharacteristics.get(
CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
}

@Override
public int getSensorOrientation() {
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
}

@Override
public int getHardwareLevel() {
return cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
}

@Override
public int[] getAvailableNoiseReductionModes() {
return cameraCharacteristics.get(
CameraCharacteristics.NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.camera;

import android.graphics.Rect;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager;
import android.os.Build.VERSION_CODES;
import android.util.Range;
import android.util.Rational;
import android.util.Size;
import androidx.annotation.RequiresApi;

/**
* Implementation of the @see CameraProperties interface using the @see
* android.hardware.camera2.CameraCharacteristics class to access the different characteristics.
*/
public class CameraPropertiesImpl implements CameraProperties {
Copy link
Contributor Author

@navaronbracke navaronbracke Mar 3, 2023

Choose a reason for hiding this comment

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

@camsim99 The javac warnings indicated that this class should have only been used from its own file.
Since it has one usage, I moved it to its own file and made it public to resolve that warning.

private final CameraCharacteristics cameraCharacteristics;
private final String cameraName;

public CameraPropertiesImpl(String cameraName, CameraManager cameraManager)
throws CameraAccessException {
this.cameraName = cameraName;
this.cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraName);
}

@Override
public String getCameraName() {
return cameraName;
}

@Override
public Range<Integer>[] getControlAutoExposureAvailableTargetFpsRanges() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
}

@Override
public Range<Integer> getControlAutoExposureCompensationRange() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
}

@Override
public double getControlAutoExposureCompensationStep() {
Rational rational =
cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP);

return rational == null ? 0.0 : rational.doubleValue();
}

@Override
public int[] getControlAutoFocusAvailableModes() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES);
}

@Override
public Integer getControlMaxRegionsAutoExposure() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AE);
}

@Override
public Integer getControlMaxRegionsAutoFocus() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF);
}

@RequiresApi(api = VERSION_CODES.P)
@Override
public int[] getDistortionCorrectionAvailableModes() {
return cameraCharacteristics.get(CameraCharacteristics.DISTORTION_CORRECTION_AVAILABLE_MODES);
}

@Override
public Boolean getFlashInfoAvailable() {
return cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
}

@Override
public int getLensFacing() {
return cameraCharacteristics.get(CameraCharacteristics.LENS_FACING);
}

@Override
public Float getLensInfoMinimumFocusDistance() {
return cameraCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);
}

@Override
public Float getScalerAvailableMaxDigitalZoom() {
return cameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
}

@RequiresApi(api = VERSION_CODES.R)
@Override
public Float getScalerMaxZoomRatio() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE).getUpper();
}

@RequiresApi(api = VERSION_CODES.R)
@Override
public Float getScalerMinZoomRatio() {
return cameraCharacteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE).getLower();
}

@Override
public Rect getSensorInfoActiveArraySize() {
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
}

@Override
public Size getSensorInfoPixelArraySize() {
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE);
}

@RequiresApi(api = VERSION_CODES.M)
@Override
public Rect getSensorInfoPreCorrectionActiveArraySize() {
return cameraCharacteristics.get(
CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
}

@Override
public int getSensorOrientation() {
return cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
}

@Override
public int getHardwareLevel() {
return cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
}

@Override
public int[] getAvailableNoiseReductionModes() {
return cameraCharacteristics.get(
CameraCharacteristics.NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES);
}
}
Loading