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

Handle Android camera permissions error code #5938

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion packages/camera/camera_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.2.1

* Handles Android camera permissions error code that indicates a request being made while another was in progress.
* Ignores unnecessary import warnings in preparation for [upcoming Flutter changes](https://github.com/flutter/flutter/pull/104231).
* Ignores missing return warnings in preparation for [upcoming analysis changes](https://github.com/flutter/flutter/issues/105750).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class MethodChannelCamera extends CameraPlatform {

final Map<int, MethodChannel> _channels = <int, MethodChannel>{};

/// Error code used to detect multiple requests for camera permissions on Android.
static const String cameraPermissionsRequestOngoingErrorCode =
'CameraPermissionsRequestOngoing';

/// The controller we need to broadcast the different events coming
/// from handleMethodCall, specific to camera events.
///
Expand Down Expand Up @@ -101,6 +105,10 @@ class MethodChannelCamera extends CameraPlatform {

return reply!['cameraId']! as int;
} on PlatformException catch (e) {
if (e.code == cameraPermissionsRequestOngoingErrorCode) {
throw StateError(e.message!);
}

throw CameraException(e.code, e.message);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera_
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.2.0
version: 2.2.1

environment:
sdk: '>=2.12.0 <3.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,37 +56,31 @@ void main() {
});

test(
'Should throw CameraException when create throws a PlatformException',
'Should throw StateError when create is called while camera permissions request ongoing',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a duplicate test (see test right below), so I just modified this one.

() {
// Arrange
MethodChannelMock(
channelName: 'plugins.flutter.io/camera',
methods: <String, dynamic>{
'create': PlatformException(
code: 'TESTING_ERROR_CODE',
code: 'CameraPermissionsRequestOngoing',
message: 'Mock error message used during testing.',
)
});
final MethodChannelCamera camera = MethodChannelCamera();

// Act
expect(
() => camera.createCamera(
const CameraDescription(
name: 'Test',
lensDirection: CameraLensDirection.back,
sensorOrientation: 0,
),
ResolutionPreset.high,
),
throwsA(
isA<CameraException>()
.having(
(CameraException e) => e.code, 'code', 'TESTING_ERROR_CODE')
.having((CameraException e) => e.description, 'description',
'Mock error message used during testing.'),
),
);
() => camera.createCamera(
const CameraDescription(
name: 'Test',
lensDirection: CameraLensDirection.back,
sensorOrientation: 0,
),
ResolutionPreset.high,
),
throwsStateError,
reason: 'Mock error message used during testing.');
});

test(
Expand Down