Skip to content

Commit ae4f17d

Browse files
authored
[camerax] Ensure DeviceOrientationManager stops on dispose (flutter#9141)
This ensures DeviceOrientationManager is released on dispose. Prevents leaked IntentReceiver on close. Fixes: flutter/flutter#166529 ## Pre-Review Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] page, which explains my responsibilities. - [X] I read and followed the [relevant style guides] and ran [the auto-formatter]. - [X] I signed the [CLA]. - [X] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]` - [X] I [linked to at least one issue that this PR fixes] in the description above. - [X] I updated `pubspec.yaml` with an appropriate new version according to the [pub versioning philosophy], or I have commented below to indicate which [version change exemption] this PR falls under[^1]. - [X] I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style], or I have commented below to indicate which [CHANGELOG exemption] this PR falls under[^1]. - [X] I updated/added any relevant documentation (doc comments with `///`). - [X] I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1]. - [X] All existing and new tests are passing.
1 parent 3ee5f0a commit ae4f17d

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

packages/camera/camera_android_camerax/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.15+1
2+
3+
* Ensures DeviceOrientationManager is stopped on dispose.
4+
15
## 0.6.15
26

37
* Updates internal API wrapper to use ProxyApis.

packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ class AndroidCameraCameraX extends CameraPlatform {
493493
await liveCameraState?.removeObservers();
494494
await processCameraProvider?.unbindAll();
495495
await imageAnalysis?.clearAnalyzer();
496+
await deviceOrientationManager.stopListeningForDeviceOrientationChange();
496497
}
497498

498499
/// The camera has been initialized.

packages/camera/camera_android_camerax/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera_android_camerax
22
description: Android implementation of the camera plugin using the CameraX library.
33
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
5-
version: 0.6.15
5+
version: 0.6.15+1
66

77
environment:
88
sdk: ^3.6.0

packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,7 +2205,30 @@ void main() {
22052205
test(
22062206
'dispose releases Flutter surface texture, removes camera state observers, and unbinds all use cases',
22072207
() async {
2208+
bool stoppedListeningForDeviceOrientationChange = false;
22082209
final AndroidCameraCameraX camera = AndroidCameraCameraX();
2210+
camera.proxy = CameraXProxy(
2211+
newDeviceOrientationManager: ({
2212+
required void Function(DeviceOrientationManager, String)
2213+
onDeviceOrientationChanged,
2214+
// ignore: non_constant_identifier_names
2215+
BinaryMessenger? pigeon_binaryMessenger,
2216+
// ignore: non_constant_identifier_names
2217+
PigeonInstanceManager? pigeon_instanceManager,
2218+
}) {
2219+
final MockDeviceOrientationManager mockDeviceOrientationManager =
2220+
MockDeviceOrientationManager();
2221+
when(
2222+
mockDeviceOrientationManager
2223+
.stopListeningForDeviceOrientationChange(),
2224+
).thenAnswer((
2225+
_,
2226+
) async {
2227+
stoppedListeningForDeviceOrientationChange = true;
2228+
});
2229+
return mockDeviceOrientationManager;
2230+
},
2231+
);
22092232

22102233
camera.preview = MockPreview();
22112234
camera.processCameraProvider = MockProcessCameraProvider();
@@ -2218,6 +2241,7 @@ void main() {
22182241
verify(camera.liveCameraState!.removeObservers());
22192242
verify(camera.processCameraProvider!.unbindAll());
22202243
verify(camera.imageAnalysis!.clearAnalyzer());
2244+
expect(stoppedListeningForDeviceOrientationChange, isTrue);
22212245
},
22222246
);
22232247

0 commit comments

Comments
 (0)