Skip to content

Commit 2f78047

Browse files
authored
Bump Camera Example Plugin Apps Targetsdk Versions (#8193)
Bumped targetsdk versions of example app plugins for `camera`, `camera_android`, and `camera_android_camerax`. Deleted `Capture specific image resolutions` integration. The Android CameraX team confirmed the result coming from the CameraX side is correct and works as they expect. This means the supported output sizes cannot fulfill our test case assumptions. For 'camera_android_camerax', we use the automatic selection described [here](https://developer.android.com/media/camera/camerax/configuration#resolution), and it willl automatically choose, so we can't control the outcome. Even if we specify, the resolution is not gauranteed. `camera` would have the same behavior as `camera_android_camerax` because `camera`'s android implementation defaults to `camera_android_camerax` behavior. For `camera_android` we cannot choose the aspect ratio [here](https://developer.android.com/reference/android/media/CamcorderProfile#getAll%28java.lang.String,%20int%29). If there's an unsupported size, it "falls through" to the next smallest size, which means we cannot choose the final resolution. Example high quality aspect ratio [here](https://developer.android.com/reference/android/media/CamcorderProfile#QUALITY_HIGH), and logic for final resolution [here](https://github.com/flutter/packages/blob/a02deb49c1f6bcb8bb895dd67fbf36ac2c9738bd/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java#L172). Fixes flutter/flutter#154682
1 parent cb9ab42 commit 2f78047

File tree

9 files changed

+6
-145
lines changed

9 files changed

+6
-145
lines changed

packages/camera/camera/example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ android {
3232
defaultConfig {
3333
applicationId "io.flutter.plugins.cameraexample"
3434
minSdkVersion flutter.minSdkVersion
35-
targetSdkVersion 28
35+
targetSdkVersion flutter.targetSdkVersion
3636
versionCode flutterVersionCode.toInteger()
3737
versionName flutterVersionName
3838
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

packages/camera/camera/example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<activity
88
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
99
android:hardwareAccelerated="true"
10+
android:exported="true"
1011
android:launchMode="singleTop"
1112
android:name="io.flutter.embedding.android.FlutterActivity"
1213
android:theme="@style/LaunchTheme"

packages/camera/camera/example/integration_test/camera_test.dart

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -53,49 +53,6 @@ void main() {
5353
actual.longestSide == expectedSize.longestSide;
5454
}
5555

56-
// This tests that the capture is no bigger than the preset, since we have
57-
// automatic code to fall back to smaller sizes when we need to. Returns
58-
// whether the image is exactly the desired resolution.
59-
Future<bool> testCaptureImageResolution(
60-
CameraController controller, ResolutionPreset preset) async {
61-
final Size expectedSize = presetExpectedSizes[preset]!;
62-
63-
// Take Picture
64-
final XFile file = await controller.takePicture();
65-
66-
// Load picture
67-
final File fileImage = File(file.path);
68-
final Image image = await decodeImageFromList(fileImage.readAsBytesSync());
69-
70-
// Verify image dimensions are as expected
71-
expect(image, isNotNull);
72-
return assertExpectedDimensions(
73-
expectedSize, Size(image.height.toDouble(), image.width.toDouble()));
74-
}
75-
76-
testWidgets('Capture specific image resolutions',
77-
(WidgetTester tester) async {
78-
final List<CameraDescription> cameras = await availableCameras();
79-
if (cameras.isEmpty) {
80-
return;
81-
}
82-
for (final CameraDescription cameraDescription in cameras) {
83-
bool previousPresetExactlySupported = true;
84-
for (final MapEntry<ResolutionPreset, Size> preset
85-
in presetExpectedSizes.entries) {
86-
final CameraController controller =
87-
CameraController(cameraDescription, preset.key);
88-
await controller.initialize();
89-
final bool presetExactlySupported =
90-
await testCaptureImageResolution(controller, preset.key);
91-
assert(!(!previousPresetExactlySupported && presetExactlySupported),
92-
'The camera took higher resolution pictures at a lower resolution.');
93-
previousPresetExactlySupported = presetExactlySupported;
94-
await controller.dispose();
95-
}
96-
}
97-
});
98-
9956
// This tests that the capture is no bigger than the preset, since we have
10057
// automatic code to fall back to smaller sizes when we need to. Returns
10158
// whether the image is exactly the desired resolution.

packages/camera/camera_android/example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ android {
3232
defaultConfig {
3333
applicationId "io.flutter.plugins.cameraexample"
3434
minSdkVersion flutter.minSdkVersion
35-
targetSdkVersion 28
35+
targetSdkVersion flutter.targetSdkVersion
3636
versionCode flutterVersionCode.toInteger()
3737
versionName flutterVersionName
3838
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

packages/camera/camera_android/example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<activity
88
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
99
android:hardwareAccelerated="true"
10+
android:exported="true"
1011
android:launchMode="singleTop"
1112
android:name="io.flutter.embedding.android.FlutterActivity"
1213
android:theme="@style/LaunchTheme"

packages/camera/camera_android/example/integration_test/camera_test.dart

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
// found in the LICENSE file.
44

55
import 'dart:io';
6-
import 'dart:ui';
76

87
import 'package:camera_android/camera_android.dart';
98
import 'package:camera_example/camera_controller.dart';
109
import 'package:camera_platform_interface/camera_platform_interface.dart';
11-
import 'package:flutter/painting.dart';
1210
import 'package:flutter/services.dart';
1311
import 'package:flutter_test/flutter_test.dart';
1412
import 'package:integration_test/integration_test.dart';
@@ -50,50 +48,6 @@ void main() {
5048
actual.longestSide == expectedSize.longestSide;
5149
}
5250

53-
// This tests that the capture is no bigger than the preset, since we have
54-
// automatic code to fall back to smaller sizes when we need to. Returns
55-
// whether the image is exactly the desired resolution.
56-
Future<bool> testCaptureImageResolution(
57-
CameraController controller, ResolutionPreset preset) async {
58-
final Size expectedSize = presetExpectedSizes[preset]!;
59-
60-
// Take Picture
61-
final XFile file = await controller.takePicture();
62-
63-
// Load picture
64-
final File fileImage = File(file.path);
65-
final Image image = await decodeImageFromList(fileImage.readAsBytesSync());
66-
67-
// Verify image dimensions are as expected
68-
expect(image, isNotNull);
69-
return assertExpectedDimensions(
70-
expectedSize, Size(image.height.toDouble(), image.width.toDouble()));
71-
}
72-
73-
testWidgets('Capture specific image resolutions',
74-
(WidgetTester tester) async {
75-
final List<CameraDescription> cameras =
76-
await CameraPlatform.instance.availableCameras();
77-
if (cameras.isEmpty) {
78-
return;
79-
}
80-
for (final CameraDescription cameraDescription in cameras) {
81-
bool previousPresetExactlySupported = true;
82-
for (final MapEntry<ResolutionPreset, Size> preset
83-
in presetExpectedSizes.entries) {
84-
final CameraController controller = CameraController(cameraDescription,
85-
mediaSettings: MediaSettings(resolutionPreset: preset.key));
86-
await controller.initialize();
87-
final bool presetExactlySupported =
88-
await testCaptureImageResolution(controller, preset.key);
89-
assert(!(!previousPresetExactlySupported && presetExactlySupported),
90-
'The camera took higher resolution pictures at a lower resolution.');
91-
previousPresetExactlySupported = presetExactlySupported;
92-
await controller.dispose();
93-
}
94-
}
95-
});
96-
9751
// This tests that the capture is no bigger than the preset, since we have
9852
// automatic code to fall back to smaller sizes when we need to. Returns
9953
// whether the image is exactly the desired resolution.

packages/camera/camera_android_camerax/example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ android {
3838
defaultConfig {
3939
applicationId "io.flutter.plugins.cameraxexample"
4040
minSdkVersion flutter.minSdkVersion
41-
targetSdkVersion 30
41+
targetSdkVersion flutter.targetSdkVersion
4242
versionCode flutterVersionCode.toInteger()
4343
versionName flutterVersionName
4444
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

packages/camera/camera_android_camerax/example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
android:icon="@mipmap/ic_launcher">
77
<activity
88
android:name=".MainActivity"
9-
android:exported="true"
109
android:launchMode="singleTop"
1110
android:theme="@style/LaunchTheme"
1211
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
1312
android:hardwareAccelerated="true"
13+
android:exported="true"
1414
android:windowSoftInputMode="adjustResize">
1515
<!-- Specifies an Android theme to apply to this Activity as soon as
1616
the Android process has started. This theme is visible to the user

packages/camera/camera_android_camerax/example/integration_test/integration_test.dart

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'package:camera_android_camerax/camera_android_camerax.dart';
1010
import 'package:camera_android_camerax_example/camera_controller.dart';
1111
import 'package:camera_android_camerax_example/camera_image.dart';
1212
import 'package:camera_platform_interface/camera_platform_interface.dart';
13-
import 'package:flutter/painting.dart';
1413
import 'package:flutter_test/flutter_test.dart';
1514
import 'package:integration_test/integration_test.dart';
1615
import 'package:video_player/video_player.dart';
@@ -46,26 +45,6 @@ void main() {
4645
actual.longestSide == expectedSize.longestSide;
4746
}
4847

49-
// This tests that the capture is no bigger than the preset, since we have
50-
// automatic code to fall back to smaller sizes when we need to. Returns
51-
// whether the image is exactly the desired resolution.
52-
Future<bool> testCaptureImageResolution(
53-
CameraController controller, ResolutionPreset preset) async {
54-
final Size expectedSize = presetExpectedSizes[preset]!;
55-
56-
// Take Picture
57-
final XFile file = await controller.takePicture();
58-
59-
// Load picture
60-
final File fileImage = File(file.path);
61-
final Image image = await decodeImageFromList(fileImage.readAsBytesSync());
62-
63-
// Verify image dimensions are as expected
64-
expect(image, isNotNull);
65-
return assertExpectedDimensions(
66-
expectedSize, Size(image.height.toDouble(), image.width.toDouble()));
67-
}
68-
6948
testWidgets('availableCameras only supports valid back or front cameras',
7049
(WidgetTester tester) async {
7150
final List<CameraDescription> availableCameras =
@@ -78,37 +57,6 @@ void main() {
7857
}
7958
});
8059

81-
testWidgets('Capture specific image resolutions',
82-
(WidgetTester tester) async {
83-
final List<CameraDescription> cameras =
84-
await CameraPlatform.instance.availableCameras();
85-
if (cameras.isEmpty) {
86-
return;
87-
}
88-
for (final CameraDescription cameraDescription in cameras) {
89-
bool previousPresetExactlySupported = true;
90-
for (final MapEntry<ResolutionPreset, Size> preset
91-
in presetExpectedSizes.entries) {
92-
final CameraController controller = CameraController(
93-
cameraDescription,
94-
mediaSettings: MediaSettings(resolutionPreset: preset.key),
95-
);
96-
await controller.initialize();
97-
final bool presetExactlySupported =
98-
await testCaptureImageResolution(controller, preset.key);
99-
// Ensures that if a lower resolution was used for previous (lower)
100-
// resolution preset, then the current (higher) preset also is adjusted,
101-
// as it demands a higher resolution.
102-
expect(
103-
previousPresetExactlySupported || !presetExactlySupported, isTrue,
104-
reason:
105-
'The camera took higher resolution pictures at a lower resolution.');
106-
previousPresetExactlySupported = presetExactlySupported;
107-
await controller.dispose();
108-
}
109-
}
110-
});
111-
11260
testWidgets('Preview takes expected resolution from preset',
11361
(WidgetTester tester) async {
11462
final List<CameraDescription> cameras =

0 commit comments

Comments
 (0)