Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit c0cba54

Browse files
juliocbcottaMichael Klimushyn
authored andcommitted
[Camera] Fixes NullPointerException (#2057)
This PR fixes a possible NullPointerException when the device has only front-facing cameras. There are two versions of CamcorderProfile.get, the one currently in use will return null in case there is no back-facing camera. The second version uses the cameraId to avoid returning null. More: https://developer.android.com/reference/android/media/CamcorderProfile.html#get(int,%20int)
1 parent 4eeb744 commit c0cba54

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

packages/camera/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.4+2
2+
3+
* Fix Android NullPointerException on devices with only front-facing camera.
4+
15
## 0.5.4+1
26

37
* Fix Android pause and resume video crash when executing in APIs below 24.

packages/camera/android/src/main/java/io/flutter/plugins/camera/CameraUtils.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,31 @@ static CamcorderProfile getBestAvailableCamcorderProfileForResolutionPreset(
7777
// All of these cases deliberately fall through to get the best available profile.
7878
case max:
7979
if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_HIGH)) {
80-
return CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
80+
return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
8181
}
8282
case ultraHigh:
8383
if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_2160P)) {
84-
return CamcorderProfile.get(CamcorderProfile.QUALITY_2160P);
84+
return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_2160P);
8585
}
8686
case veryHigh:
8787
if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P)) {
88-
return CamcorderProfile.get(CamcorderProfile.QUALITY_1080P);
88+
return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_1080P);
8989
}
9090
case high:
9191
if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) {
92-
return CamcorderProfile.get(CamcorderProfile.QUALITY_720P);
92+
return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P);
9393
}
9494
case medium:
9595
if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) {
96-
return CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
96+
return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P);
9797
}
9898
case low:
9999
if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_QVGA)) {
100-
return CamcorderProfile.get(CamcorderProfile.QUALITY_QVGA);
100+
return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_QVGA);
101101
}
102102
default:
103-
if (CamcorderProfile.hasProfile(
104-
Integer.parseInt(cameraName), CamcorderProfile.QUALITY_LOW)) {
105-
return CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
103+
if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW)) {
104+
return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
106105
} else {
107106
throw new IllegalArgumentException(
108107
"No capture session available for current capture session.");

packages/camera/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera
22
description: A Flutter plugin for getting information about and controlling the
33
camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video,
44
and streaming image buffers to dart.
5-
version: 0.5.4+1
5+
version: 0.5.4+2
66

77
authors:
88
- Flutter Team <[email protected]>

0 commit comments

Comments
 (0)