diff --git a/packages/camera/camera_android/CHANGELOG.md b/packages/camera/camera_android/CHANGELOG.md index 8bfdd7f0b1f..c853b8a4b1b 100644 --- a/packages/camera/camera_android/CHANGELOG.md +++ b/packages/camera/camera_android/CHANGELOG.md @@ -1,6 +1,7 @@ ## NEXT * Fixes unawaited_futures violations. +* Removes duplicate line in `MediaRecorderBuilder.java`. ## 0.10.8+2 diff --git a/packages/camera/camera_android/android/build.gradle b/packages/camera/camera_android/android/build.gradle index ef8d9e29767..24a736e0e90 100644 --- a/packages/camera/camera_android/android/build.gradle +++ b/packages/camera/camera_android/android/build.gradle @@ -51,6 +51,7 @@ android { unitTests.includeAndroidResources = true unitTests.returnDefaultValues = true unitTests.all { + jvmArgs "-Xmx1g" testLogging { events "passed", "skipped", "failed", "standardOut", "standardError" outputs.upToDateWhen {false} @@ -65,5 +66,5 @@ dependencies { testImplementation 'junit:junit:4.13.2' testImplementation 'org.mockito:mockito-inline:5.0.0' testImplementation 'androidx.test:core:1.4.0' - testImplementation 'org.robolectric:robolectric:4.5' + testImplementation 'org.robolectric:robolectric:4.10.3' } diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java index f55552edf89..966019bb143 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java @@ -92,7 +92,6 @@ public MediaRecorder build() throws IOException, NullPointerException, IndexOutO mediaRecorder.setVideoEncodingBitRate(videoProfile.getBitrate()); mediaRecorder.setVideoFrameRate(videoProfile.getFrameRate()); mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); - mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); } else if (camcorderProfile != null) { mediaRecorder.setOutputFormat(camcorderProfile.fileFormat); if (enableAudio) { diff --git a/packages/camera/camera_android/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java b/packages/camera/camera_android/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java index dbc352d697a..fe4dcd795fe 100644 --- a/packages/camera/camera_android/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java +++ b/packages/camera/camera_android/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java @@ -91,8 +91,9 @@ public void beforeLegacy() { public void before() { mockProfileLow = mock(EncoderProfiles.class); EncoderProfiles mockProfile = mock(EncoderProfiles.class); - EncoderProfiles.VideoProfile mockVideoProfile = mock(EncoderProfiles.VideoProfile.class); - List mockVideoProfilesList = List.of(mockVideoProfile); + List mockVideoProfilesList = + new ArrayList(); + mockVideoProfilesList.add(null); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_HIGH)) @@ -117,8 +118,6 @@ public void before() { .thenReturn(mockProfileLow); when(mockProfile.getVideoProfiles()).thenReturn(mockVideoProfilesList); - when(mockVideoProfile.getHeight()).thenReturn(100); - when(mockVideoProfile.getWidth()).thenReturn(100); } @After @@ -386,7 +385,7 @@ public void computeBestPreviewSize_shouldUseLegacyBehaviorWhenEncoderProfilesNul @Config(minSdk = 31) @Test public void resolutionFeatureShouldUseLegacyBehaviorWhenEncoderProfilesNull() { - beforeLegacy(); + before(); try (MockedStatic mockedResolutionFeature = mockStatic(ResolutionFeature.class)) { mockedResolutionFeature diff --git a/packages/camera/camera_android/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java b/packages/camera/camera_android/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java index 6cc58ee823d..f37de01f5e7 100644 --- a/packages/camera/camera_android/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java +++ b/packages/camera/camera_android/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java @@ -78,9 +78,9 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabledLegacy() throw public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOException { EncoderProfiles recorderProfile = mock(EncoderProfiles.class); List mockVideoProfiles = - List.of(mock(EncoderProfiles.VideoProfile.class)); + List.of(getEmptyEncoderProfilesVideoProfile()); List mockAudioProfiles = - List.of(mock(EncoderProfiles.AudioProfile.class)); + List.of(getEmptyEncoderProfilesAudioProfile()); MediaRecorderBuilder.MediaRecorderFactory mockFactory = mock(MediaRecorderBuilder.MediaRecorderFactory.class); MediaRecorder mockMediaRecorder = mock(MediaRecorder.class); @@ -172,9 +172,9 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabledLegacy() throws public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOException { EncoderProfiles recorderProfile = mock(EncoderProfiles.class); List mockVideoProfiles = - List.of(mock(EncoderProfiles.VideoProfile.class)); + List.of(getEmptyEncoderProfilesVideoProfile()); List mockAudioProfiles = - List.of(mock(EncoderProfiles.AudioProfile.class)); + List.of(getEmptyEncoderProfilesAudioProfile()); MediaRecorderBuilder.MediaRecorderFactory mockFactory = mock(MediaRecorderBuilder.MediaRecorderFactory.class); MediaRecorder mockMediaRecorder = mock(MediaRecorder.class); @@ -224,4 +224,32 @@ private CamcorderProfile getEmptyCamcorderProfile() { return null; } + + private EncoderProfiles.VideoProfile getEmptyEncoderProfilesVideoProfile() { + try { + Constructor constructor = + EncoderProfiles.VideoProfile.class.getDeclaredConstructor( + int.class, int.class, int.class, int.class, int.class, int.class); + + constructor.setAccessible(true); + return constructor.newInstance(0, 0, 0, 0, 0, 0); + } catch (Exception ignored) { + } + + return null; + } + + private EncoderProfiles.AudioProfile getEmptyEncoderProfilesAudioProfile() { + try { + Constructor constructor = + EncoderProfiles.AudioProfile.class.getDeclaredConstructor( + int.class, int.class, int.class, int.class, int.class); + + constructor.setAccessible(true); + return constructor.newInstance(0, 0, 0, 0, 0); + } catch (Exception ignored) { + } + + return null; + } }