From 69761529240118ac3f49406a516089070549cd15 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 11 Oct 2021 11:12:57 -0700 Subject: [PATCH 01/45] Identified deprecated usages and added initial fixes --- packages/camera/camera/android/build.gradle | 2 +- .../io/flutter/plugins/camera/Camera.java | 8 +- .../resolution/ResolutionFeature.java | 181 +++++++++++++----- .../camera/media/MediaRecorderBuilder.java | 46 +++-- .../io/flutter/plugins/camera/CameraTest.java | 13 +- .../resolution/ResolutionFeatureTest.java | 181 ++++++++++-------- .../DeviceOrientationManagerTest.java | 5 +- .../media/MediaRecorderBuilderTest.java | 66 +++++-- 8 files changed, 328 insertions(+), 174 deletions(-) diff --git a/packages/camera/camera/android/build.gradle b/packages/camera/camera/android/build.gradle index 25285ad33205..387bf4efd657 100644 --- a/packages/camera/camera/android/build.gradle +++ b/packages/camera/camera/android/build.gradle @@ -27,7 +27,7 @@ project.getTasks().withType(JavaCompile){ apply plugin: 'com.android.library' android { - compileSdkVersion 29 + compileSdkVersion 31 defaultConfig { minSdkVersion 21 diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java index 75ced531b08a..44b67cfd6cbc 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java @@ -20,6 +20,7 @@ import android.hardware.camera2.params.OutputConfiguration; import android.hardware.camera2.params.SessionConfiguration; import android.media.CamcorderProfile; +import android.media.EncoderProfiles; import android.media.Image; import android.media.ImageReader; import android.media.MediaRecorder; @@ -200,7 +201,7 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException { .getLockedCaptureOrientation(); mediaRecorder = - new MediaRecorderBuilder(getRecordingProfile(), outputFilePath) + new MediaRecorderBuilder(getRecordingProfile(), applicationContext, outputFilePath) .setEnableAudio(enableAudio) .setMediaOrientation( lockedOrientation == null @@ -919,8 +920,9 @@ public float getMinZoomLevel() { } /** Shortcut to get current recording profile. */ - CamcorderProfile getRecordingProfile() { - return cameraFeatures.getResolution().getRecordingProfile(); + EncoderProfiles getRecordingProfile() { + // return cameraFeatures.getResolution().getRecordingProfile(); + return cameraFeatures.getResolution().getRecordingProfile_v31(); } /** Shortut to get deviceOrientationListener. */ diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java index 67763dde9be4..9ca2c4a9a774 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java @@ -4,12 +4,15 @@ package io.flutter.plugins.camera.features.resolution; +import android.os.Build; import android.hardware.camera2.CaptureRequest; import android.media.CamcorderProfile; +import android.media.EncoderProfiles; import android.util.Size; import androidx.annotation.VisibleForTesting; import io.flutter.plugins.camera.CameraProperties; import io.flutter.plugins.camera.features.CameraFeature; +import java.util.List; /** * Controls the resolutions configuration on the {@link android.hardware.camera2} API. @@ -22,6 +25,7 @@ public class ResolutionFeature extends CameraFeature { private Size captureSize; private Size previewSize; private CamcorderProfile recordingProfile; + private EncoderProfiles recordingProfile_v31; private ResolutionPreset currentSetting; private int cameraId; @@ -42,6 +46,7 @@ public ResolutionFeature( this.cameraId = -1; return; } + System.out.println("CAMERA_ID_" + this.cameraId); configureResolution(resolutionPreset, cameraId); } @@ -55,6 +60,10 @@ public CamcorderProfile getRecordingProfile() { return this.recordingProfile; } + public EncoderProfiles getRecordingProfile_v31() { + return this.recordingProfile_v31; + } + /** * Gets the optimal preview size based on the configured resolution. * @@ -80,6 +89,7 @@ public String getDebugName() { @Override public ResolutionPreset getValue() { + System.out.println(currentSetting); return currentSetting; } @@ -104,10 +114,26 @@ static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) { if (preset.ordinal() > ResolutionPreset.high.ordinal()) { preset = ResolutionPreset.high; } + // if (Build.VERSION.SDK_INT >= 31) { + EncoderProfiles profile = getBestAvailableCamcorderProfileForResolutionPreset_v31(cameraId, preset); + List videoProfiles = profile.getVideoProfiles(); + + try { + EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); + } + catch (IndexOutOfBoundsException e) { + System.out.println("No video profiles found."); + return null; + } + + return new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); - CamcorderProfile profile = - getBestAvailableCamcorderProfileForResolutionPreset(cameraId, preset); - return new Size(profile.videoFrameWidth, profile.videoFrameHeight); + // } + // else { + // CamcorderProfile profile = + // getBestAvailableCamcorderProfileForResolutionPreset(cameraId, preset); + // return new Size(profile.videoFrameWidth, profile.videoFrameHeight); + // } } /** @@ -121,56 +147,119 @@ static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) { * @return The best possible {@link android.media.CamcorderProfile} that matches the supplied * {@link ResolutionPreset}. */ - public static CamcorderProfile getBestAvailableCamcorderProfileForResolutionPreset( - int cameraId, ResolutionPreset preset) { - if (cameraId < 0) { - throw new AssertionError( - "getBestAvailableCamcorderProfileForResolutionPreset can only be used with valid (>=0) camera identifiers."); - } +// public static CamcorderProfile getBestAvailableCamcorderProfileForResolutionPreset( +// int cameraId, ResolutionPreset preset) { +// if (cameraId < 0) { +// throw new AssertionError( +// "getBestAvailableCamcorderProfileForResolutionPreset can only be used with valid (>=0) camera identifiers."); +// } - switch (preset) { - // All of these cases deliberately fall through to get the best available profile. - case max: - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_HIGH)) { - return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH); - } - case ultraHigh: - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_2160P)) { - return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_2160P); - } - case veryHigh: - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P)) { - return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_1080P); - } - case high: - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) { - return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P); - } - case medium: - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) { - return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P); - } - case low: - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_QVGA)) { - return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_QVGA); - } - default: - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW)) { - return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW); - } else { - throw new IllegalArgumentException( - "No capture session available for current capture session."); - } - } +// switch (preset) { +// // All of these cases deliberately fall through to get the best available profile. +// case max: +// if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_HIGH)) { +// return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH); +// } +// case ultraHigh: +// if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_2160P)) { +// return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_2160P); +// } +// case veryHigh: +// if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P)) { +// return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_1080P); +// } +// case high: +// if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) { +// return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P); +// } +// case medium: +// if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) { +// return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P); +// } +// case low: +// if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_QVGA)) { +// return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_QVGA); +// } +// default: +// if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW)) { +// return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW); +// } else { +// throw new IllegalArgumentException( +// "No capture session available for current capture session."); +// } +// } +// } + + public static EncoderProfiles getBestAvailableCamcorderProfileForResolutionPreset_v31( + int cameraId, ResolutionPreset preset) { + if (cameraId < 0) { + throw new AssertionError( + "getBestAvailableCamcorderProfileForResolutionPreset can only be used with valid (>=0) camera identifiers."); + } + + String cameraIdString = Integer.toString(cameraId); + + switch (preset) { + // All of these cases deliberately fall through to get the best available profile. + case max: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_HIGH)) { + return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_HIGH); + } + case ultraHigh: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_2160P)) { + return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_2160P); + } + case veryHigh: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P)) { + return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_1080P); + } + case high: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) { + return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_720P); + } + case medium: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) { + return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_480P); + } + case low: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_QVGA)) { + return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_QVGA); + } + default: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW)) { + return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_LOW); + } else { + throw new IllegalArgumentException( + "No capture session available for current capture session."); + } } +} private void configureResolution(ResolutionPreset resolutionPreset, int cameraId) { if (!checkIsSupported()) { return; } - recordingProfile = - getBestAvailableCamcorderProfileForResolutionPreset(cameraId, resolutionPreset); - captureSize = new Size(recordingProfile.videoFrameWidth, recordingProfile.videoFrameHeight); + + // if (Build.VERSION.SDK_INT >= 31) { + recordingProfile_v31 = + getBestAvailableCamcorderProfileForResolutionPreset_v31(cameraId, resolutionPreset); + List videoProfiles = recordingProfile_v31.getVideoProfiles(); + System.out.println("VIDEO_PROFILES_ " + recordingProfile_v31); + + try { + EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); + captureSize = new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); + } + catch (IndexOutOfBoundsException e) { + System.out.println("No video profiles found."); + } + // } + // else { + // recordingProfile = + // getBestAvailableCamcorderProfileForResolutionPreset(cameraId, resolutionPreset); + // captureSize = new Size(recordingProfile.videoFrameWidth, recordingProfile.videoFrameHeight); + // } + previewSize = computeBestPreviewSize(cameraId, resolutionPreset); } } diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java index a78c2b47b7ad..ea623e2c0af0 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java @@ -5,34 +5,39 @@ package io.flutter.plugins.camera.media; import android.media.CamcorderProfile; +import android.media.EncoderProfiles; +import android.content.Context; import android.media.MediaRecorder; import androidx.annotation.NonNull; import java.io.IOException; public class MediaRecorderBuilder { static class MediaRecorderFactory { - MediaRecorder makeMediaRecorder() { - return new MediaRecorder(); + MediaRecorder makeMediaRecorder(Context applicationContext) { + return new MediaRecorder(applicationContext); } } private final String outputFilePath; - private final CamcorderProfile recordingProfile; + private final EncoderProfiles recordingProfile; private final MediaRecorderFactory recorderFactory; + private final Context applicationContext; private boolean enableAudio; private int mediaOrientation; public MediaRecorderBuilder( - @NonNull CamcorderProfile recordingProfile, @NonNull String outputFilePath) { - this(recordingProfile, outputFilePath, new MediaRecorderFactory()); + @NonNull EncoderProfiles recordingProfile, @NonNull Context applicationContext, @NonNull String outputFilePath) { + this(recordingProfile, applicationContext, outputFilePath, new MediaRecorderFactory()); } MediaRecorderBuilder( - @NonNull CamcorderProfile recordingProfile, + @NonNull EncoderProfiles recordingProfile, + @NonNull Context applicationContext, @NonNull String outputFilePath, MediaRecorderFactory helper) { this.outputFilePath = outputFilePath; + this.applicationContext = applicationContext; this.recordingProfile = recordingProfile; this.recorderFactory = helper; } @@ -48,22 +53,33 @@ public MediaRecorderBuilder setMediaOrientation(int orientation) { } public MediaRecorder build() throws IOException { - MediaRecorder mediaRecorder = recorderFactory.makeMediaRecorder(); + MediaRecorder mediaRecorder = recorderFactory.makeMediaRecorder(applicationContext); + + EncoderProfiles.VideoProfile videoProfile = recordingProfile.getVideoProfiles().get(0); + EncoderProfiles.AudioProfile audioProfile = recordingProfile.getAudioProfiles().get(0); // There's a fixed order that mediaRecorder expects. Only change these functions accordingly. // You can find the specifics here: https://developer.android.com/reference/android/media/MediaRecorder. if (enableAudio) mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); - mediaRecorder.setOutputFormat(recordingProfile.fileFormat); + // mediaRecorder.setOutputFormat(recordingProfile.fileFormat); + mediaRecorder.setOutputFormat(recordingProfile.getRecommendedFileFormat()); if (enableAudio) { - mediaRecorder.setAudioEncoder(recordingProfile.audioCodec); - mediaRecorder.setAudioEncodingBitRate(recordingProfile.audioBitRate); - mediaRecorder.setAudioSamplingRate(recordingProfile.audioSampleRate); + // mediaRecorder.setAudioEncoder(recordingProfile.audioCodec); + mediaRecorder.setAudioEncoder(audioProfile.getCodec()); + // mediaRecorder.setAudioEncodingBitRate(recordingProfile.audioBitRate); + mediaRecorder.setAudioEncodingBitRate(audioProfile.getBitrate()); + // mediaRecorder.setAudioSamplingRate(recordingProfile.audioSampleRate); + mediaRecorder.setAudioSamplingRate(audioProfile.getSampleRate()); } - mediaRecorder.setVideoEncoder(recordingProfile.videoCodec); - mediaRecorder.setVideoEncodingBitRate(recordingProfile.videoBitRate); - mediaRecorder.setVideoFrameRate(recordingProfile.videoFrameRate); - mediaRecorder.setVideoSize(recordingProfile.videoFrameWidth, recordingProfile.videoFrameHeight); + // mediaRecorder.setVideoEncoder(recordingProfile.videoCodec); + mediaRecorder.setVideoEncoder(videoProfile.getCodec()); + // mediaRecorder.setVideoEncodingBitRate(recordingProfile.videoBitRate); + mediaRecorder.setVideoEncodingBitRate(videoProfile.getBitrate()); + // mediaRecorder.setVideoFrameRate(recordingProfile.videoFrameRate); + mediaRecorder.setVideoFrameRate(videoProfile.getFrameRate()); + // mediaRecorder.setVideoSize(recordingProfile.videoFrameWidth, recordingProfile.videoFrameHeight); + mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); mediaRecorder.setOutputFile(outputFilePath); mediaRecorder.setOrientationHint(this.mediaOrientation); diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java index 9d973195435e..4ca6dd7059ae 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java @@ -23,6 +23,7 @@ import android.hardware.camera2.CameraMetadata; import android.hardware.camera2.CaptureRequest; import android.media.CamcorderProfile; +import android.media.EncoderProfiles; import android.media.MediaRecorder; import android.os.Build; import android.os.Handler; @@ -253,14 +254,18 @@ public void getMinZoomLevel() { public void getRecordingProfile() { ResolutionFeature mockResolutionFeature = mockCameraFeatureFactory.createResolutionFeature(mockCameraProperties, null, null); - CamcorderProfile mockCamcorderProfile = mock(CamcorderProfile.class); + // CamcorderProfile mockCamcorderProfile = mock(CamcorderProfile.class); + EncoderProfiles mockRecordingProfile = mock(EncoderProfiles.class); - when(mockResolutionFeature.getRecordingProfile()).thenReturn(mockCamcorderProfile); + // when(mockResolutionFeature.getRecordingProfile()).thenReturn(mockCamcorderProfile); + when(mockResolutionFeature.getRecordingProfile_v31()).thenReturn(mockRecordingProfile); - CamcorderProfile actualRecordingProfile = camera.getRecordingProfile(); + // CamcorderProfile actualRecordingProfile = camera.getRecordingProfile(); + EncoderProfiles actualRecordingProfile = camera.getRecordingProfile(); verify(mockResolutionFeature, times(1)).getRecordingProfile(); - assertEquals(mockCamcorderProfile, actualRecordingProfile); + // assertEquals(mockCamcorderProfile, actualRecordingProfile); + assertEquals(mockRecordingProfile, actualRecordingProfile); } @Test diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java index e09223dfabe9..dd0e02a62b9f 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java @@ -10,6 +10,7 @@ import static org.mockito.Mockito.mockStatic; import android.media.CamcorderProfile; +import android.media.EncoderProfiles; import io.flutter.plugins.camera.CameraProperties; import org.junit.After; import org.junit.Before; @@ -19,57 +20,53 @@ public class ResolutionFeatureTest { private static final String cameraName = "1"; private CamcorderProfile mockProfileLow; + private EncoderProfiles mockProfileLow_v31; private MockedStatic mockedStaticProfile; @Before public void before() { mockedStaticProfile = mockStatic(CamcorderProfile.class); mockProfileLow = mock(CamcorderProfile.class); + mockProfileLow_v31 = mock(EncoderProfiles.class); CamcorderProfile mockProfile = mock(CamcorderProfile.class); - - mockedStaticProfile - .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)) - .thenReturn(true); - mockedStaticProfile - .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_2160P)) - .thenReturn(true); - mockedStaticProfile - .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_1080P)) - .thenReturn(true); - mockedStaticProfile - .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_720P)) - .thenReturn(true); - mockedStaticProfile - .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_480P)) - .thenReturn(true); - mockedStaticProfile - .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_QVGA)) - .thenReturn(true); - mockedStaticProfile - .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW)) - .thenReturn(true); - - mockedStaticProfile - .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_HIGH)) - .thenReturn(mockProfile); - mockedStaticProfile - .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_2160P)) - .thenReturn(mockProfile); - mockedStaticProfile - .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_1080P)) - .thenReturn(mockProfile); - mockedStaticProfile - .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)) - .thenReturn(mockProfile); - mockedStaticProfile - .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)) - .thenReturn(mockProfile); - mockedStaticProfile - .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)) - .thenReturn(mockProfile); - mockedStaticProfile - .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_LOW)) - .thenReturn(mockProfileLow); + EncoderProfiles mockProfile_v31 = mock(EncoderProfiles.class); + EncoderProfiles.VideoProfile mockVideoProfile = mock(EncoderProfiles.VideoProfile.class); + + mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)).thenReturn(true); + mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_2160P)).thenReturn(true); + mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_1080P)).thenReturn(true); + mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_720P)).thenReturn(true); + mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_480P)).thenReturn(true); + mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_QVGA)).thenReturn(true); + mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW)).thenReturn(true); + + // if (Build.VERSION.SDK_INT >= 31) { + mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_HIGH)) + .thenReturn(mockProfile_v31); + mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_2160P)) + .thenReturn(mockProfile_v31); + mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_1080P)) + .thenReturn(mockProfile_v31); + mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)) + .thenReturn(mockProfile_v31); + mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_480P)) + .thenReturn(mockProfile_v31); + mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_QVGA)) + .thenReturn(mockProfile_v31); + mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_LOW)) + .thenReturn(mockProfileLow_v31); + + when(mockProfile_v31.getVideoProfiles()).thenReturn(mockVideoProfile); + + // } else { + // mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_HIGH)).thenReturn(mockProfile); + // mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_2160P)).thenReturn(mockProfile); + // mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_1080P)).thenReturn(mockProfile); + // mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)).thenReturn(mockProfile); + // mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)).thenReturn(mockProfile); + // mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)).thenReturn(mockProfile); + // mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_LOW)).thenReturn(mockProfileLow); + // } } @After @@ -81,8 +78,7 @@ public void after() { @Test public void getDebugName_shouldReturnTheNameOfTheFeature() { CameraProperties mockCameraProperties = mock(CameraProperties.class); - ResolutionFeature resolutionFeature = - new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); + ResolutionFeature resolutionFeature = new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); assertEquals("ResolutionFeature", resolutionFeature.getDebugName()); } @@ -90,8 +86,7 @@ public void getDebugName_shouldReturnTheNameOfTheFeature() { @Test public void getValue_shouldReturnInitialValueWhenNotSet() { CameraProperties mockCameraProperties = mock(CameraProperties.class); - ResolutionFeature resolutionFeature = - new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); + ResolutionFeature resolutionFeature = new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); assertEquals(ResolutionPreset.max, resolutionFeature.getValue()); } @@ -99,8 +94,7 @@ public void getValue_shouldReturnInitialValueWhenNotSet() { @Test public void getValue_shouldEchoSetValue() { CameraProperties mockCameraProperties = mock(CameraProperties.class); - ResolutionFeature resolutionFeature = - new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); + ResolutionFeature resolutionFeature = new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); resolutionFeature.setValue(ResolutionPreset.high); @@ -110,81 +104,100 @@ public void getValue_shouldEchoSetValue() { @Test public void checkIsSupport_returnsTrue() { CameraProperties mockCameraProperties = mock(CameraProperties.class); - ResolutionFeature resolutionFeature = - new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); + ResolutionFeature resolutionFeature = new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); assertTrue(resolutionFeature.checkIsSupported()); } @Test public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThrough() { - mockedStaticProfile - .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)) - .thenReturn(false); - mockedStaticProfile - .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_2160P)) - .thenReturn(false); - mockedStaticProfile - .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_1080P)) - .thenReturn(false); - mockedStaticProfile - .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_720P)) - .thenReturn(false); - mockedStaticProfile - .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_480P)) - .thenReturn(false); - mockedStaticProfile - .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_QVGA)) - .thenReturn(false); - mockedStaticProfile - .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW)) - .thenReturn(true); - - assertEquals( - mockProfileLow, - ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset( - 1, ResolutionPreset.max)); + mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)).thenReturn(false); + mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_2160P)).thenReturn(false); + mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_1080P)).thenReturn(false); + mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_720P)).thenReturn(false); + mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_480P)).thenReturn(false); + mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_QVGA)).thenReturn(false); + mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW)).thenReturn(true); + + // if (Build.VERSION.SDK_INT >= 31) { + assertEquals(mockProfileLow_v31, + ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset_v31(1, ResolutionPreset.max)); + // } else { + // assertEquals(mockProfileLow, + // ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset(1, ResolutionPreset.max)); + // } } @Test public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetMax() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.max); - mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); + // if (Build.VERSION.SDK_INT >= 31) { + mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); + + // } else { + // mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); + + // } } @Test public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetUltraHigh() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.ultraHigh); - mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); + // if (Build.VERSION.SDK_INT >= 31) { + mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); + // } else { + // mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); + // } } @Test public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetVeryHigh() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.veryHigh); - mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); + // if (Build.VERSION.SDK_INT >= 31) { + mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); + + // } else { + // mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); + + // } } @Test public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetHigh() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.high); - mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); + // if (Build.VERSION.SDK_INT >= 31) { + mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); + // } else { + // mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); + + // } } @Test public void computeBestPreviewSize_shouldUse480PWhenResolutionPresetMedium() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.medium); - mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)); + // if (Build.VERSION.SDK_INT >= 31) { + mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_480P)); + // } else { + // mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)); + + // } } @Test public void computeBestPreviewSize_shouldUseQVGAWhenResolutionPresetLow() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.low); - mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)); + // if (Build.VERSION.SDK_INT >= 31) { + mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_QVGA)); + // } else { + // mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)); + + // } } } diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java index 58f17cb758bf..0a922be5a0e6 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java @@ -30,6 +30,7 @@ public class DeviceOrientationManagerTest { private Activity mockActivity; + private Context mockContext; private DartMessenger mockDartMessenger; private WindowManager mockWindowManager; private Display mockDisplay; @@ -38,12 +39,14 @@ public class DeviceOrientationManagerTest { @Before public void before() { mockActivity = mock(Activity.class); + mockContext = mock(Context.class); mockDartMessenger = mock(DartMessenger.class); mockDisplay = mock(Display.class); mockWindowManager = mock(WindowManager.class); when(mockActivity.getSystemService(Context.WINDOW_SERVICE)).thenReturn(mockWindowManager); - when(mockWindowManager.getDefaultDisplay()).thenReturn(mockDisplay); + // when(mockWindowManager.getDefaultDisplay()).thenReturn(mockDisplay); + when(mockContext.getDisplay()).thenReturn(mockDisplay); deviceOrientationManager = DeviceOrientationManager.create(mockActivity, mockDartMessenger, false, 0); diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java index 5425409c2f3a..b5dc84d87f1d 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java @@ -7,7 +7,9 @@ import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.*; +import android.content.Context; import android.media.CamcorderProfile; +import android.media.EncoderProfiles; import android.media.MediaRecorder; import java.io.IOException; import java.lang.reflect.Constructor; @@ -17,38 +19,49 @@ public class MediaRecorderBuilderTest { @Test public void ctor_test() { + Context mockApplicationContext = mock(Context.class); MediaRecorderBuilder builder = - new MediaRecorderBuilder(CamcorderProfile.get(CamcorderProfile.QUALITY_1080P), ""); + new MediaRecorderBuilder(CamcorderProfile.getAll("0",CamcorderProfile.QUALITY_1080P), mockApplicationContext, ""); assertNotNull(builder); } @Test public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOException { - CamcorderProfile recorderProfile = getEmptyCamcorderProfile(); + // CamcorderProfile recorderProfile = getEmptyCamcorderProfile(); + EncoderProfiles recorderProfile = mock(EncoderProfiles.class); + Context mockApplicationContext = mock(Context.class); MediaRecorderBuilder.MediaRecorderFactory mockFactory = mock(MediaRecorderBuilder.MediaRecorderFactory.class); MediaRecorder mockMediaRecorder = mock(MediaRecorder.class); String outputFilePath = "mock_video_file_path"; int mediaOrientation = 1; MediaRecorderBuilder builder = - new MediaRecorderBuilder(recorderProfile, outputFilePath, mockFactory) + new MediaRecorderBuilder(recorderProfile, mockApplicationContext, outputFilePath, mockFactory) .setEnableAudio(false) .setMediaOrientation(mediaOrientation); - when(mockFactory.makeMediaRecorder()).thenReturn(mockMediaRecorder); + when(mockFactory.makeMediaRecorder(mockApplicationContext)).thenReturn(mockMediaRecorder); MediaRecorder recorder = builder.build(); + EncoderProfiles.VideoProfile videoProfile = recorderProfile.getVideoProfiles().get(0); + InOrder inOrder = inOrder(recorder); inOrder.verify(recorder).setVideoSource(MediaRecorder.VideoSource.SURFACE); - inOrder.verify(recorder).setOutputFormat(recorderProfile.fileFormat); - inOrder.verify(recorder).setVideoEncoder(recorderProfile.videoCodec); - inOrder.verify(recorder).setVideoEncodingBitRate(recorderProfile.videoBitRate); - inOrder.verify(recorder).setVideoFrameRate(recorderProfile.videoFrameRate); + // inOrder.verify(recorder).setOutputFormat(recorderProfile.fileFormat); + inOrder.verify(recorder).setOutputFormat(recorderProfile.getRecommendedFileFormat()); + // inOrder.verify(recorder).setVideoEncoder(recorderProfile.videoCodec); + inOrder.verify(recorder).setVideoEncoder(videoProfile.getCodec()); + // inOrder.verify(recorder).setVideoEncodingBitRate(recorderProfile.videoBitRate); + inOrder.verify(recorder).setVideoEncodingBitRate(videoProfile.getBitrate()); + // inOrder.verify(recorder).setVideoFrameRate(recorderProfile.videoFrameRate); + inOrder.verify(recorder).setVideoFrameRate(videoProfile.getFrameRate()); + inOrder .verify(recorder) - .setVideoSize(recorderProfile.videoFrameWidth, recorderProfile.videoFrameHeight); + .setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); + // .setVideoSize(recorderProfile.videoFrameWidth, recorderProfile.videoFrameHeight); inOrder.verify(recorder).setOutputFile(outputFilePath); inOrder.verify(recorder).setOrientationHint(mediaOrientation); inOrder.verify(recorder).prepare(); @@ -56,34 +69,47 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOEx @Test public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOException { - CamcorderProfile recorderProfile = getEmptyCamcorderProfile(); + // CamcorderProfile recorderProfile = getEmptyCamcorderProfile(); + EncoderProfiles recorderProfile = mock(EncoderProfiles.class); + Context mockApplicationContext = mock(Context.class); MediaRecorderBuilder.MediaRecorderFactory mockFactory = mock(MediaRecorderBuilder.MediaRecorderFactory.class); MediaRecorder mockMediaRecorder = mock(MediaRecorder.class); String outputFilePath = "mock_video_file_path"; int mediaOrientation = 1; MediaRecorderBuilder builder = - new MediaRecorderBuilder(recorderProfile, outputFilePath, mockFactory) + new MediaRecorderBuilder(recorderProfile, mockApplicationContext, outputFilePath, mockFactory) .setEnableAudio(true) .setMediaOrientation(mediaOrientation); - when(mockFactory.makeMediaRecorder()).thenReturn(mockMediaRecorder); + when(mockFactory.makeMediaRecorder(mockApplicationContext)).thenReturn(mockMediaRecorder); MediaRecorder recorder = builder.build(); + EncoderProfiles.VideoProfile videoProfile = recorderProfile.getVideoProfiles().get(0); + EncoderProfiles.AudioProfile audioProfile = recorderProfile.getAudioProfiles().get(0); + InOrder inOrder = inOrder(recorder); inOrder.verify(recorder).setAudioSource(MediaRecorder.AudioSource.MIC); inOrder.verify(recorder).setVideoSource(MediaRecorder.VideoSource.SURFACE); - inOrder.verify(recorder).setOutputFormat(recorderProfile.fileFormat); - inOrder.verify(recorder).setAudioEncoder(recorderProfile.audioCodec); - inOrder.verify(recorder).setAudioEncodingBitRate(recorderProfile.audioBitRate); - inOrder.verify(recorder).setAudioSamplingRate(recorderProfile.audioSampleRate); - inOrder.verify(recorder).setVideoEncoder(recorderProfile.videoCodec); - inOrder.verify(recorder).setVideoEncodingBitRate(recorderProfile.videoBitRate); - inOrder.verify(recorder).setVideoFrameRate(recorderProfile.videoFrameRate); + // inOrder.verify(recorder).setOutputFormat(recorderProfile.fileFormat); + inOrder.verify(recorder).setOutputFormat(recorderProfile.getRecommendedFileFormat()); + // inOrder.verify(recorder).setAudioEncoder(recorderProfile.audioCodec); + inOrder.verify(recorder).setAudioEncoder(audioProfile.getCodec()); + // inOrder.verify(recorder).setAudioEncodingBitRate(recorderProfile.audioBitRate); + inOrder.verify(recorder).setAudioEncodingBitRate(audioProfile.getBitrate()); + // inOrder.verify(recorder).setAudioSamplingRate(recorderProfile.audioSampleRate); + inOrder.verify(recorder).setAudioSamplingRate(audioProfile.getSampleRate()); + // inOrder.verify(recorder).setVideoEncoder(recorderProfile.videoCodec); + inOrder.verify(recorder).setVideoEncoder(videoProfile.getCodec()); + // inOrder.verify(recorder).setVideoEncodingBitRate(recorderProfile.videoBitRate); + inOrder.verify(recorder).setVideoEncodingBitRate(videoProfile.getBitrate()); + // inOrder.verify(recorder).setVideoFrameRate(recorderProfile.videoFrameRate); + inOrder.verify(recorder).setVideoFrameRate(videoProfile.getFrameRate()); inOrder .verify(recorder) - .setVideoSize(recorderProfile.videoFrameWidth, recorderProfile.videoFrameHeight); + .setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); + // .setVideoSize(recorderProfile.videoFrameWidth, recorderProfile.videoFrameHeight); inOrder.verify(recorder).setOutputFile(outputFilePath); inOrder.verify(recorder).setOrientationHint(mediaOrientation); inOrder.verify(recorder).prepare(); From 49722e4bd31c49a4b5ceae75e2b1ee400681dc68 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 11 Oct 2021 11:32:28 -0700 Subject: [PATCH 02/45] Fix resolution feature tests --- .../camera/features/resolution/ResolutionFeature.java | 10 +++++----- .../features/resolution/ResolutionFeatureTest.java | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java index 9ca2c4a9a774..70f86899bca5 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java @@ -46,7 +46,7 @@ public ResolutionFeature( this.cameraId = -1; return; } - System.out.println("CAMERA_ID_" + this.cameraId); + // System.out.println("CAMERA_ID_" + this.cameraId); configureResolution(resolutionPreset, cameraId); } @@ -89,7 +89,7 @@ public String getDebugName() { @Override public ResolutionPreset getValue() { - System.out.println(currentSetting); + // System.out.println(currentSetting); return currentSetting; } @@ -120,13 +120,13 @@ static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) { try { EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); + return new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); } catch (IndexOutOfBoundsException e) { System.out.println("No video profiles found."); return null; } - - return new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); + // } // else { @@ -244,7 +244,7 @@ private void configureResolution(ResolutionPreset resolutionPreset, int cameraId recordingProfile_v31 = getBestAvailableCamcorderProfileForResolutionPreset_v31(cameraId, resolutionPreset); List videoProfiles = recordingProfile_v31.getVideoProfiles(); - System.out.println("VIDEO_PROFILES_ " + recordingProfile_v31); + // System.out.println("VIDEO_PROFILES_ " + recordingProfile_v31); try { EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java index dd0e02a62b9f..3db548863ff6 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java @@ -8,10 +8,12 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; import android.media.CamcorderProfile; import android.media.EncoderProfiles; import io.flutter.plugins.camera.CameraProperties; +import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -30,7 +32,7 @@ public void before() { mockProfileLow_v31 = mock(EncoderProfiles.class); CamcorderProfile mockProfile = mock(CamcorderProfile.class); EncoderProfiles mockProfile_v31 = mock(EncoderProfiles.class); - EncoderProfiles.VideoProfile mockVideoProfile = mock(EncoderProfiles.VideoProfile.class); + List mockVideoProfiles = List.of(mock(EncoderProfiles.VideoProfile.class)); mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)).thenReturn(true); mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_2160P)).thenReturn(true); @@ -56,7 +58,7 @@ public void before() { mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_LOW)) .thenReturn(mockProfileLow_v31); - when(mockProfile_v31.getVideoProfiles()).thenReturn(mockVideoProfile); + when(mockProfile_v31.getVideoProfiles()).thenReturn(mockVideoProfiles); // } else { // mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_HIGH)).thenReturn(mockProfile); From f40abe2b3f2bfa72fd3c41824cc7d17e5b203c74 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 11 Oct 2021 12:57:46 -0700 Subject: [PATCH 03/45] fix mediarecorderbuilder test --- .../camera/media/MediaRecorderBuilderTest.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java index b5dc84d87f1d..61a0bc7a334f 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java @@ -13,6 +13,7 @@ import android.media.MediaRecorder; import java.io.IOException; import java.lang.reflect.Constructor; +import java.util.List; import org.junit.Test; import org.mockito.InOrder; @@ -31,6 +32,8 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOEx // CamcorderProfile recorderProfile = getEmptyCamcorderProfile(); EncoderProfiles recorderProfile = mock(EncoderProfiles.class); Context mockApplicationContext = mock(Context.class); + List mockVideoProfiles = List.of(mock(EncoderProfiles.VideoProfile.class)); + List mockAudioProfiles = List.of(mock(EncoderProfiles.AudioProfile.class)); MediaRecorderBuilder.MediaRecorderFactory mockFactory = mock(MediaRecorderBuilder.MediaRecorderFactory.class); MediaRecorder mockMediaRecorder = mock(MediaRecorder.class); @@ -42,10 +45,13 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOEx .setMediaOrientation(mediaOrientation); when(mockFactory.makeMediaRecorder(mockApplicationContext)).thenReturn(mockMediaRecorder); + when(recorderProfile.getVideoProfiles()).thenReturn(mockVideoProfiles); + when(recorderProfile.getAudioProfiles()).thenReturn(mockAudioProfiles); + MediaRecorder recorder = builder.build(); - EncoderProfiles.VideoProfile videoProfile = recorderProfile.getVideoProfiles().get(0); + EncoderProfiles.VideoProfile videoProfile = mockVideoProfiles.get(0); InOrder inOrder = inOrder(recorder); inOrder.verify(recorder).setVideoSource(MediaRecorder.VideoSource.SURFACE); @@ -72,6 +78,8 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOExc // CamcorderProfile recorderProfile = getEmptyCamcorderProfile(); EncoderProfiles recorderProfile = mock(EncoderProfiles.class); Context mockApplicationContext = mock(Context.class); + List mockVideoProfiles = List.of(mock(EncoderProfiles.VideoProfile.class)); + List mockAudioProfiles = List.of(mock(EncoderProfiles.AudioProfile.class)); MediaRecorderBuilder.MediaRecorderFactory mockFactory = mock(MediaRecorderBuilder.MediaRecorderFactory.class); MediaRecorder mockMediaRecorder = mock(MediaRecorder.class); @@ -83,11 +91,13 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOExc .setMediaOrientation(mediaOrientation); when(mockFactory.makeMediaRecorder(mockApplicationContext)).thenReturn(mockMediaRecorder); + when(recorderProfile.getVideoProfiles()).thenReturn(mockVideoProfiles); + when(recorderProfile.getAudioProfiles()).thenReturn(mockAudioProfiles); MediaRecorder recorder = builder.build(); - EncoderProfiles.VideoProfile videoProfile = recorderProfile.getVideoProfiles().get(0); - EncoderProfiles.AudioProfile audioProfile = recorderProfile.getAudioProfiles().get(0); + EncoderProfiles.VideoProfile videoProfile = mockVideoProfiles.get(0); + EncoderProfiles.AudioProfile audioProfile = mockAudioProfiles.get(0); InOrder inOrder = inOrder(recorder); inOrder.verify(recorder).setAudioSource(MediaRecorder.AudioSource.MIC); From 38d2310a65f7cefa9ce155b1598b6489ada8348d Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 11 Oct 2021 14:10:35 -0700 Subject: [PATCH 04/45] suppress device orientation/unrelated errors --- .../sensororientation/DeviceOrientationManagerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java index 0a922be5a0e6..a2cb5e18b2e9 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java @@ -36,6 +36,7 @@ public class DeviceOrientationManagerTest { private Display mockDisplay; private DeviceOrientationManager deviceOrientationManager; + @SuppressWarnings("deprecation") @Before public void before() { mockActivity = mock(Activity.class); @@ -45,8 +46,7 @@ public void before() { mockWindowManager = mock(WindowManager.class); when(mockActivity.getSystemService(Context.WINDOW_SERVICE)).thenReturn(mockWindowManager); - // when(mockWindowManager.getDefaultDisplay()).thenReturn(mockDisplay); - when(mockContext.getDisplay()).thenReturn(mockDisplay); + when(mockWindowManager.getDefaultDisplay()).thenReturn(mockDisplay); deviceOrientationManager = DeviceOrientationManager.create(mockActivity, mockDartMessenger, false, 0); From 09a2685544df4b60fef457df1c4d7ceffd2979ab Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 11 Oct 2021 14:16:46 -0700 Subject: [PATCH 05/45] fix camera test --- .../src/test/java/io/flutter/plugins/camera/CameraTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java index 4ca6dd7059ae..376d360dd399 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java @@ -263,7 +263,8 @@ public void getRecordingProfile() { // CamcorderProfile actualRecordingProfile = camera.getRecordingProfile(); EncoderProfiles actualRecordingProfile = camera.getRecordingProfile(); - verify(mockResolutionFeature, times(1)).getRecordingProfile(); + // verify(mockResolutionFeature, times(1)).getRecordingProfile(); + verify(mockResolutionFeature, times(1)).getRecordingProfile_v31(); // assertEquals(mockCamcorderProfile, actualRecordingProfile); assertEquals(mockRecordingProfile, actualRecordingProfile); } From accaed09d005c0f39fd087dd53fbd0488e39b501 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Tue, 12 Oct 2021 11:34:22 -0700 Subject: [PATCH 06/45] update android sdk versions in related build files --- packages/camera/camera/android/build.gradle | 1 + packages/camera/camera/example/android/app/build.gradle | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/camera/camera/android/build.gradle b/packages/camera/camera/android/build.gradle index 387bf4efd657..a8d5ab63c024 100644 --- a/packages/camera/camera/android/build.gradle +++ b/packages/camera/camera/android/build.gradle @@ -30,6 +30,7 @@ android { compileSdkVersion 31 defaultConfig { + targetSdkVersion 31 minSdkVersion 21 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/packages/camera/camera/example/android/app/build.gradle b/packages/camera/camera/example/android/app/build.gradle index 7d0e281b74e8..476d65373723 100644 --- a/packages/camera/camera/example/android/app/build.gradle +++ b/packages/camera/camera/example/android/app/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 29 + compileSdkVersion 31 lintOptions { disable 'InvalidPackage' From a0441d9d1531d951c931df4bd3f9b3c9ce039858 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Tue, 12 Oct 2021 15:46:31 -0700 Subject: [PATCH 07/45] add build checks for resolutionfeature: --- packages/camera/camera/android/build.gradle | 2 +- .../resolution/ResolutionFeature.java | 120 +++++++++--------- .../resolution/ResolutionFeatureTest.java | 87 +++++++------ 3 files changed, 109 insertions(+), 100 deletions(-) diff --git a/packages/camera/camera/android/build.gradle b/packages/camera/camera/android/build.gradle index a8d5ab63c024..ce2d38a85d89 100644 --- a/packages/camera/camera/android/build.gradle +++ b/packages/camera/camera/android/build.gradle @@ -30,7 +30,7 @@ android { compileSdkVersion 31 defaultConfig { - targetSdkVersion 31 + // targetSdkVersion 31 minSdkVersion 21 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java index 70f86899bca5..ae3f65403d5c 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java @@ -46,7 +46,6 @@ public ResolutionFeature( this.cameraId = -1; return; } - // System.out.println("CAMERA_ID_" + this.cameraId); configureResolution(resolutionPreset, cameraId); } @@ -89,7 +88,6 @@ public String getDebugName() { @Override public ResolutionPreset getValue() { - // System.out.println(currentSetting); return currentSetting; } @@ -109,12 +107,13 @@ public void updateBuilder(CaptureRequest.Builder requestBuilder) { // No-op: when setting a resolution there is no need to update the request builder. } + @SuppressWarnings("deprecation") @VisibleForTesting static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) { if (preset.ordinal() > ResolutionPreset.high.ordinal()) { preset = ResolutionPreset.high; } - // if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= 31) { EncoderProfiles profile = getBestAvailableCamcorderProfileForResolutionPreset_v31(cameraId, preset); List videoProfiles = profile.getVideoProfiles(); @@ -126,14 +125,12 @@ static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) { System.out.println("No video profiles found."); return null; } - - - // } - // else { - // CamcorderProfile profile = - // getBestAvailableCamcorderProfileForResolutionPreset(cameraId, preset); - // return new Size(profile.videoFrameWidth, profile.videoFrameHeight); - // } + } + else { + CamcorderProfile profile = + getBestAvailableCamcorderProfileForResolutionPreset(cameraId, preset); + return new Size(profile.videoFrameWidth, profile.videoFrameHeight); + } } /** @@ -147,48 +144,49 @@ static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) { * @return The best possible {@link android.media.CamcorderProfile} that matches the supplied * {@link ResolutionPreset}. */ -// public static CamcorderProfile getBestAvailableCamcorderProfileForResolutionPreset( -// int cameraId, ResolutionPreset preset) { -// if (cameraId < 0) { -// throw new AssertionError( -// "getBestAvailableCamcorderProfileForResolutionPreset can only be used with valid (>=0) camera identifiers."); -// } + @SuppressWarnings("deprecation") + public static CamcorderProfile getBestAvailableCamcorderProfileForResolutionPreset( + int cameraId, ResolutionPreset preset) { + if (cameraId < 0) { + throw new AssertionError( + "getBestAvailableCamcorderProfileForResolutionPreset can only be used with valid (>=0) camera identifiers."); + } -// switch (preset) { -// // All of these cases deliberately fall through to get the best available profile. -// case max: -// if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_HIGH)) { -// return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH); -// } -// case ultraHigh: -// if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_2160P)) { -// return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_2160P); -// } -// case veryHigh: -// if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P)) { -// return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_1080P); -// } -// case high: -// if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) { -// return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P); -// } -// case medium: -// if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) { -// return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P); -// } -// case low: -// if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_QVGA)) { -// return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_QVGA); -// } -// default: -// if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW)) { -// return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW); -// } else { -// throw new IllegalArgumentException( -// "No capture session available for current capture session."); -// } -// } -// } + switch (preset) { + // All of these cases deliberately fall through to get the best available profile. + case max: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_HIGH)) { + return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH); + } + case ultraHigh: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_2160P)) { + return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_2160P); + } + case veryHigh: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P)) { + return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_1080P); + } + case high: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) { + return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P); + } + case medium: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) { + return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P); + } + case low: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_QVGA)) { + return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_QVGA); + } + default: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW)) { + return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW); + } else { + throw new IllegalArgumentException( + "No capture session available for current capture session."); + } + } + } public static EncoderProfiles getBestAvailableCamcorderProfileForResolutionPreset_v31( int cameraId, ResolutionPreset preset) { @@ -235,16 +233,17 @@ public static EncoderProfiles getBestAvailableCamcorderProfileForResolutionPrese } } + @SuppressWarnings("deprecation") private void configureResolution(ResolutionPreset resolutionPreset, int cameraId) { if (!checkIsSupported()) { return; } - // if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= 31) { + System.out.println("31"); recordingProfile_v31 = getBestAvailableCamcorderProfileForResolutionPreset_v31(cameraId, resolutionPreset); List videoProfiles = recordingProfile_v31.getVideoProfiles(); - // System.out.println("VIDEO_PROFILES_ " + recordingProfile_v31); try { EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); @@ -253,12 +252,13 @@ private void configureResolution(ResolutionPreset resolutionPreset, int cameraId catch (IndexOutOfBoundsException e) { System.out.println("No video profiles found."); } - // } - // else { - // recordingProfile = - // getBestAvailableCamcorderProfileForResolutionPreset(cameraId, resolutionPreset); - // captureSize = new Size(recordingProfile.videoFrameWidth, recordingProfile.videoFrameHeight); - // } + } + else { + System.out.println("not 31"); + recordingProfile = + getBestAvailableCamcorderProfileForResolutionPreset(cameraId, resolutionPreset); + captureSize = new Size(recordingProfile.videoFrameWidth, recordingProfile.videoFrameHeight); + } previewSize = computeBestPreviewSize(cameraId, resolutionPreset); } diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java index 3db548863ff6..5c70c41081cc 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java @@ -12,6 +12,7 @@ import android.media.CamcorderProfile; import android.media.EncoderProfiles; +import android.os.Build; import io.flutter.plugins.camera.CameraProperties; import java.util.List; import org.junit.After; @@ -26,6 +27,7 @@ public class ResolutionFeatureTest { private MockedStatic mockedStaticProfile; @Before + @SuppressWarnings("deprecation") public void before() { mockedStaticProfile = mockStatic(CamcorderProfile.class); mockProfileLow = mock(CamcorderProfile.class); @@ -42,7 +44,7 @@ public void before() { mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_QVGA)).thenReturn(true); mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW)).thenReturn(true); - // if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= 31) { mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_HIGH)) .thenReturn(mockProfile_v31); mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_2160P)) @@ -60,15 +62,15 @@ public void before() { when(mockProfile_v31.getVideoProfiles()).thenReturn(mockVideoProfiles); - // } else { - // mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_HIGH)).thenReturn(mockProfile); - // mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_2160P)).thenReturn(mockProfile); - // mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_1080P)).thenReturn(mockProfile); - // mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)).thenReturn(mockProfile); - // mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)).thenReturn(mockProfile); - // mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)).thenReturn(mockProfile); - // mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_LOW)).thenReturn(mockProfileLow); - // } + } else { + mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_HIGH)).thenReturn(mockProfile); + mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_2160P)).thenReturn(mockProfile); + mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_1080P)).thenReturn(mockProfile); + mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)).thenReturn(mockProfile); + mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)).thenReturn(mockProfile); + mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)).thenReturn(mockProfile); + mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_LOW)).thenReturn(mockProfileLow); + } } @After @@ -111,6 +113,7 @@ public void checkIsSupport_returnsTrue() { assertTrue(resolutionFeature.checkIsSupported()); } + @SuppressWarnings("deprecation") @Test public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThrough() { mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)).thenReturn(false); @@ -121,85 +124,91 @@ public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThroug mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_QVGA)).thenReturn(false); mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW)).thenReturn(true); - // if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= 31) { assertEquals(mockProfileLow_v31, ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset_v31(1, ResolutionPreset.max)); - // } else { - // assertEquals(mockProfileLow, - // ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset(1, ResolutionPreset.max)); - // } + } else { + assertEquals(mockProfileLow, + ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset(1, ResolutionPreset.max)); + } } + @SuppressWarnings("deprecation") @Test public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetMax() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.max); - // if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= 31) { mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); - // } else { - // mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); + } else { + mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); - // } + } } + @SuppressWarnings("deprecation") @Test public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetUltraHigh() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.ultraHigh); - // if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= 31) { mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); - // } else { - // mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); - // } + } else { + mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); + } } + @SuppressWarnings("deprecation") @Test public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetVeryHigh() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.veryHigh); - // if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= 31) { mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); - // } else { - // mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); + } else { + mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); - // } + } } + @SuppressWarnings("deprecation") @Test public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetHigh() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.high); - // if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= 31) { mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); - // } else { - // mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); + } else { + mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); - // } + } } + @SuppressWarnings("deprecation") @Test public void computeBestPreviewSize_shouldUse480PWhenResolutionPresetMedium() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.medium); - // if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= 31) { mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_480P)); - // } else { - // mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)); + } else { + mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)); - // } + } } + @SuppressWarnings("deprecation") @Test public void computeBestPreviewSize_shouldUseQVGAWhenResolutionPresetLow() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.low); - // if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= 31) { mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_QVGA)); - // } else { - // mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)); + } else { + mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)); - // } + } } } From 2383bf3cdf8bf87e53f36e49c80c67c5b3ef5dcc Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 13 Oct 2021 10:31:01 -0700 Subject: [PATCH 08/45] adjust mediarecorderbuilder and use robolectric --- packages/camera/camera/android/build.gradle | 2 +- .../io/flutter/plugins/camera/Camera.java | 2 +- .../camera/media/MediaRecorderBuilder.java | 82 +++++++----- .../media/MediaRecorderBuilderTest.java | 119 ++++++++++++++---- .../camera/example/android/gradle.properties | 1 + 5 files changed, 150 insertions(+), 56 deletions(-) diff --git a/packages/camera/camera/android/build.gradle b/packages/camera/camera/android/build.gradle index ce2d38a85d89..8f437547bb54 100644 --- a/packages/camera/camera/android/build.gradle +++ b/packages/camera/camera/android/build.gradle @@ -63,5 +63,5 @@ dependencies { testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-inline:3.12.4' testImplementation 'androidx.test:core:1.3.0' - testImplementation 'org.robolectric:robolectric:4.3' + testImplementation 'org.robolectric:robolectric:4.6.1' } diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java index 44b67cfd6cbc..65bb59011b24 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java @@ -201,7 +201,7 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException { .getLockedCaptureOrientation(); mediaRecorder = - new MediaRecorderBuilder(getRecordingProfile(), applicationContext, outputFilePath) + new MediaRecorderBuilder(getRecordingProfile(), outputFilePath) .setEnableAudio(enableAudio) .setMediaOrientation( lockedOrientation == null diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java index ea623e2c0af0..cf0b9a4b3d3b 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java @@ -6,39 +6,54 @@ import android.media.CamcorderProfile; import android.media.EncoderProfiles; -import android.content.Context; import android.media.MediaRecorder; +import android.os.Build; import androidx.annotation.NonNull; import java.io.IOException; public class MediaRecorderBuilder { + @SuppressWarnings("deprecation") static class MediaRecorderFactory { - MediaRecorder makeMediaRecorder(Context applicationContext) { - return new MediaRecorder(applicationContext); + MediaRecorder makeMediaRecorder() { + return new MediaRecorder(); } } private final String outputFilePath; - private final EncoderProfiles recordingProfile; + private final CamcorderProfile camcorderProfile; + private final EncoderProfiles encoderProfiles; private final MediaRecorderFactory recorderFactory; - private final Context applicationContext; private boolean enableAudio; private int mediaOrientation; public MediaRecorderBuilder( - @NonNull EncoderProfiles recordingProfile, @NonNull Context applicationContext, @NonNull String outputFilePath) { - this(recordingProfile, applicationContext, outputFilePath, new MediaRecorderFactory()); + @NonNull CamcorderProfile camcorderProfile, @NonNull String outputFilePath) { + this(camcorderProfile, outputFilePath, new MediaRecorderFactory()); } + public MediaRecorderBuilder( + @NonNull EncoderProfiles encoderProfiles, @NonNull String outputFilePath) { + this(encoderProfiles, outputFilePath, new MediaRecorderFactory()); +} + MediaRecorderBuilder( - @NonNull EncoderProfiles recordingProfile, - @NonNull Context applicationContext, + @NonNull CamcorderProfile camcorderProfile, + @NonNull String outputFilePath, + MediaRecorderFactory helper) { + this.outputFilePath = outputFilePath; + this.camcorderProfile = camcorderProfile; + this.encoderProfiles = null; + this.recorderFactory = helper; +} + + MediaRecorderBuilder( + @NonNull EncoderProfiles encoderProfiles, @NonNull String outputFilePath, MediaRecorderFactory helper) { this.outputFilePath = outputFilePath; - this.applicationContext = applicationContext; - this.recordingProfile = recordingProfile; + this.encoderProfiles = encoderProfiles; + this.camcorderProfile = null; this.recorderFactory = helper; } @@ -53,33 +68,42 @@ public MediaRecorderBuilder setMediaOrientation(int orientation) { } public MediaRecorder build() throws IOException { - MediaRecorder mediaRecorder = recorderFactory.makeMediaRecorder(applicationContext); - - EncoderProfiles.VideoProfile videoProfile = recordingProfile.getVideoProfiles().get(0); - EncoderProfiles.AudioProfile audioProfile = recordingProfile.getAudioProfiles().get(0); + MediaRecorder mediaRecorder = recorderFactory.makeMediaRecorder(); // There's a fixed order that mediaRecorder expects. Only change these functions accordingly. // You can find the specifics here: https://developer.android.com/reference/android/media/MediaRecorder. if (enableAudio) mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); - // mediaRecorder.setOutputFormat(recordingProfile.fileFormat); - mediaRecorder.setOutputFormat(recordingProfile.getRecommendedFileFormat()); - if (enableAudio) { - // mediaRecorder.setAudioEncoder(recordingProfile.audioCodec); + + if (Build.VERSION.SDK_INT >= 31) { + EncoderProfiles.VideoProfile videoProfile = encoderProfiles.getVideoProfiles().get(0); + EncoderProfiles.AudioProfile audioProfile = encoderProfiles.getAudioProfiles().get(0); + + mediaRecorder.setOutputFormat(encoderProfiles.getRecommendedFileFormat()); + if (enableAudio) { mediaRecorder.setAudioEncoder(audioProfile.getCodec()); - // mediaRecorder.setAudioEncodingBitRate(recordingProfile.audioBitRate); mediaRecorder.setAudioEncodingBitRate(audioProfile.getBitrate()); - // mediaRecorder.setAudioSamplingRate(recordingProfile.audioSampleRate); mediaRecorder.setAudioSamplingRate(audioProfile.getSampleRate()); + } + mediaRecorder.setVideoEncoder(videoProfile.getCodec()); + mediaRecorder.setVideoEncodingBitRate(videoProfile.getBitrate()); + mediaRecorder.setVideoFrameRate(videoProfile.getFrameRate()); + mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); + mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); } - // mediaRecorder.setVideoEncoder(recordingProfile.videoCodec); - mediaRecorder.setVideoEncoder(videoProfile.getCodec()); - // mediaRecorder.setVideoEncodingBitRate(recordingProfile.videoBitRate); - mediaRecorder.setVideoEncodingBitRate(videoProfile.getBitrate()); - // mediaRecorder.setVideoFrameRate(recordingProfile.videoFrameRate); - mediaRecorder.setVideoFrameRate(videoProfile.getFrameRate()); - // mediaRecorder.setVideoSize(recordingProfile.videoFrameWidth, recordingProfile.videoFrameHeight); - mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); + else { + mediaRecorder.setOutputFormat(camcorderProfile.fileFormat); + if (enableAudio) { + mediaRecorder.setAudioEncoder(camcorderProfile.audioCodec); + mediaRecorder.setAudioEncodingBitRate(camcorderProfile.audioBitRate); + mediaRecorder.setAudioSamplingRate(camcorderProfile.audioSampleRate); + } + mediaRecorder.setVideoEncoder(camcorderProfile.videoCodec); + mediaRecorder.setVideoEncodingBitRate(camcorderProfile.videoBitRate); + mediaRecorder.setVideoFrameRate(camcorderProfile.videoFrameRate); + mediaRecorder.setVideoSize(camcorderProfile.videoFrameWidth, camcorderProfile.videoFrameHeight); + } + mediaRecorder.setOutputFile(outputFilePath); mediaRecorder.setOrientationHint(this.mediaOrientation); diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java index 61a0bc7a334f..fde604c626da 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java @@ -7,31 +7,77 @@ import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.*; -import android.content.Context; import android.media.CamcorderProfile; import android.media.EncoderProfiles; import android.media.MediaRecorder; import java.io.IOException; import java.lang.reflect.Constructor; import java.util.List; +import org.junit.runner.RunWith; import org.junit.Test; import org.mockito.InOrder; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; +@RunWith(RobolectricTestRunner.class) public class MediaRecorderBuilderTest { + @Config(maxSdk = 30) + @SuppressWarnings("deprecation") @Test public void ctor_test() { - Context mockApplicationContext = mock(Context.class); MediaRecorderBuilder builder = - new MediaRecorderBuilder(CamcorderProfile.getAll("0",CamcorderProfile.QUALITY_1080P), mockApplicationContext, ""); + new MediaRecorderBuilder(CamcorderProfile.get(CamcorderProfile.QUALITY_1080P), ""); assertNotNull(builder); } + @Config(minSdk = 31) + @Test + public void ctor_test_v31() { + MediaRecorderBuilder builder = + new MediaRecorderBuilder(CamcorderProfile.getAll("0",CamcorderProfile.QUALITY_1080P), ""); + + assertNotNull(builder); + } + + @Config(maxSdk = 30) + @SuppressWarnings("deprecation") @Test public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOException { - // CamcorderProfile recorderProfile = getEmptyCamcorderProfile(); + CamcorderProfile recorderProfile = getEmptyCamcorderProfile(); + MediaRecorderBuilder.MediaRecorderFactory mockFactory = + mock(MediaRecorderBuilder.MediaRecorderFactory.class); + MediaRecorder mockMediaRecorder = mock(MediaRecorder.class); + String outputFilePath = "mock_video_file_path"; + int mediaOrientation = 1; + MediaRecorderBuilder builder = + new MediaRecorderBuilder(recorderProfile, outputFilePath, mockFactory) + .setEnableAudio(false) + .setMediaOrientation(mediaOrientation); + + when(mockFactory.makeMediaRecorder()).thenReturn(mockMediaRecorder); + + MediaRecorder recorder = builder.build(); + + InOrder inOrder = inOrder(recorder); + inOrder.verify(recorder).setVideoSource(MediaRecorder.VideoSource.SURFACE); + inOrder.verify(recorder).setOutputFormat(recorderProfile.fileFormat); + inOrder.verify(recorder).setVideoEncoder(recorderProfile.videoCodec); + inOrder.verify(recorder).setVideoEncodingBitRate(recorderProfile.videoBitRate); + inOrder.verify(recorder).setVideoFrameRate(recorderProfile.videoFrameRate); + inOrder + .verify(recorder) + .setVideoSize(recorderProfile.videoFrameWidth, recorderProfile.videoFrameHeight); + inOrder.verify(recorder).setOutputFile(outputFilePath); + inOrder.verify(recorder).setOrientationHint(mediaOrientation); + inOrder.verify(recorder).prepare(); + } + + @Config(minSdk = 31) + @Test + public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled_v31() throws IOException { EncoderProfiles recorderProfile = mock(EncoderProfiles.class); - Context mockApplicationContext = mock(Context.class); List mockVideoProfiles = List.of(mock(EncoderProfiles.VideoProfile.class)); List mockAudioProfiles = List.of(mock(EncoderProfiles.AudioProfile.class)); MediaRecorderBuilder.MediaRecorderFactory mockFactory = @@ -40,11 +86,11 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOEx String outputFilePath = "mock_video_file_path"; int mediaOrientation = 1; MediaRecorderBuilder builder = - new MediaRecorderBuilder(recorderProfile, mockApplicationContext, outputFilePath, mockFactory) + new MediaRecorderBuilder(recorderProfile, outputFilePath, mockFactory) .setEnableAudio(false) .setMediaOrientation(mediaOrientation); - when(mockFactory.makeMediaRecorder(mockApplicationContext)).thenReturn(mockMediaRecorder); + when(mockFactory.makeMediaRecorder()).thenReturn(mockMediaRecorder); when(recorderProfile.getVideoProfiles()).thenReturn(mockVideoProfiles); when(recorderProfile.getAudioProfiles()).thenReturn(mockAudioProfiles); @@ -55,29 +101,60 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOEx InOrder inOrder = inOrder(recorder); inOrder.verify(recorder).setVideoSource(MediaRecorder.VideoSource.SURFACE); - // inOrder.verify(recorder).setOutputFormat(recorderProfile.fileFormat); inOrder.verify(recorder).setOutputFormat(recorderProfile.getRecommendedFileFormat()); - // inOrder.verify(recorder).setVideoEncoder(recorderProfile.videoCodec); inOrder.verify(recorder).setVideoEncoder(videoProfile.getCodec()); - // inOrder.verify(recorder).setVideoEncodingBitRate(recorderProfile.videoBitRate); inOrder.verify(recorder).setVideoEncodingBitRate(videoProfile.getBitrate()); - // inOrder.verify(recorder).setVideoFrameRate(recorderProfile.videoFrameRate); inOrder.verify(recorder).setVideoFrameRate(videoProfile.getFrameRate()); - inOrder .verify(recorder) .setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); - // .setVideoSize(recorderProfile.videoFrameWidth, recorderProfile.videoFrameHeight); inOrder.verify(recorder).setOutputFile(outputFilePath); inOrder.verify(recorder).setOrientationHint(mediaOrientation); inOrder.verify(recorder).prepare(); } + @Config(maxSdk = 30) + @SuppressWarnings("deprecation") @Test public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOException { - // CamcorderProfile recorderProfile = getEmptyCamcorderProfile(); + CamcorderProfile recorderProfile = getEmptyCamcorderProfile(); + MediaRecorderBuilder.MediaRecorderFactory mockFactory = + mock(MediaRecorderBuilder.MediaRecorderFactory.class); + MediaRecorder mockMediaRecorder = mock(MediaRecorder.class); + String outputFilePath = "mock_video_file_path"; + int mediaOrientation = 1; + MediaRecorderBuilder builder = + new MediaRecorderBuilder(recorderProfile, outputFilePath, mockFactory) + .setEnableAudio(true) + .setMediaOrientation(mediaOrientation); + + when(mockFactory.makeMediaRecorder()).thenReturn(mockMediaRecorder); + + MediaRecorder recorder = builder.build(); + + InOrder inOrder = inOrder(recorder); + inOrder.verify(recorder).setAudioSource(MediaRecorder.AudioSource.MIC); + inOrder.verify(recorder).setVideoSource(MediaRecorder.VideoSource.SURFACE); + inOrder.verify(recorder).setOutputFormat(recorderProfile.fileFormat); + inOrder.verify(recorder).setAudioEncoder(recorderProfile.audioCodec); + inOrder.verify(recorder).setAudioEncodingBitRate(recorderProfile.audioBitRate); + inOrder.verify(recorder).setAudioSamplingRate(recorderProfile.audioSampleRate); + inOrder.verify(recorder).setVideoEncoder(recorderProfile.videoCodec); + inOrder.verify(recorder).setVideoEncodingBitRate(recorderProfile.videoBitRate); + inOrder.verify(recorder).setVideoFrameRate(recorderProfile.videoFrameRate); + inOrder + .verify(recorder) + .setVideoSize(recorderProfile.videoFrameWidth, recorderProfile.videoFrameHeight); + inOrder.verify(recorder).setOutputFile(outputFilePath); + inOrder.verify(recorder).setOrientationHint(mediaOrientation); + inOrder.verify(recorder).prepare(); + } + + @Config(minSdk = 31) + @Test + public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled_v31() throws IOException { + System.out.println(getEmptyCamcorderProfile()); EncoderProfiles recorderProfile = mock(EncoderProfiles.class); - Context mockApplicationContext = mock(Context.class); List mockVideoProfiles = List.of(mock(EncoderProfiles.VideoProfile.class)); List mockAudioProfiles = List.of(mock(EncoderProfiles.AudioProfile.class)); MediaRecorderBuilder.MediaRecorderFactory mockFactory = @@ -86,11 +163,11 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOExc String outputFilePath = "mock_video_file_path"; int mediaOrientation = 1; MediaRecorderBuilder builder = - new MediaRecorderBuilder(recorderProfile, mockApplicationContext, outputFilePath, mockFactory) + new MediaRecorderBuilder(recorderProfile, outputFilePath, mockFactory) .setEnableAudio(true) .setMediaOrientation(mediaOrientation); - when(mockFactory.makeMediaRecorder(mockApplicationContext)).thenReturn(mockMediaRecorder); + when(mockFactory.makeMediaRecorder()).thenReturn(mockMediaRecorder); when(recorderProfile.getVideoProfiles()).thenReturn(mockVideoProfiles); when(recorderProfile.getAudioProfiles()).thenReturn(mockAudioProfiles); @@ -102,24 +179,16 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOExc InOrder inOrder = inOrder(recorder); inOrder.verify(recorder).setAudioSource(MediaRecorder.AudioSource.MIC); inOrder.verify(recorder).setVideoSource(MediaRecorder.VideoSource.SURFACE); - // inOrder.verify(recorder).setOutputFormat(recorderProfile.fileFormat); inOrder.verify(recorder).setOutputFormat(recorderProfile.getRecommendedFileFormat()); - // inOrder.verify(recorder).setAudioEncoder(recorderProfile.audioCodec); inOrder.verify(recorder).setAudioEncoder(audioProfile.getCodec()); - // inOrder.verify(recorder).setAudioEncodingBitRate(recorderProfile.audioBitRate); inOrder.verify(recorder).setAudioEncodingBitRate(audioProfile.getBitrate()); - // inOrder.verify(recorder).setAudioSamplingRate(recorderProfile.audioSampleRate); inOrder.verify(recorder).setAudioSamplingRate(audioProfile.getSampleRate()); - // inOrder.verify(recorder).setVideoEncoder(recorderProfile.videoCodec); inOrder.verify(recorder).setVideoEncoder(videoProfile.getCodec()); - // inOrder.verify(recorder).setVideoEncodingBitRate(recorderProfile.videoBitRate); inOrder.verify(recorder).setVideoEncodingBitRate(videoProfile.getBitrate()); - // inOrder.verify(recorder).setVideoFrameRate(recorderProfile.videoFrameRate); inOrder.verify(recorder).setVideoFrameRate(videoProfile.getFrameRate()); inOrder .verify(recorder) .setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); - // .setVideoSize(recorderProfile.videoFrameWidth, recorderProfile.videoFrameHeight); inOrder.verify(recorder).setOutputFile(outputFilePath); inOrder.verify(recorder).setOrientationHint(mediaOrientation); inOrder.verify(recorder).prepare(); diff --git a/packages/camera/camera/example/android/gradle.properties b/packages/camera/camera/example/android/gradle.properties index a6738207fd15..030ee5d13667 100644 --- a/packages/camera/camera/example/android/gradle.properties +++ b/packages/camera/camera/example/android/gradle.properties @@ -2,3 +2,4 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true android.enableR8=true +android.jetifier.blacklist=bcprov-jdk15on From 09cbfa80d22ed61b1d99d4a6022b21b8451f5735 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 13 Oct 2021 10:45:16 -0700 Subject: [PATCH 09/45] adjust camera and test --- .../io/flutter/plugins/camera/Camera.java | 22 +++++++++++++--- .../io/flutter/plugins/camera/CameraTest.java | 26 ++++++++++++++----- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java index 65bb59011b24..d9386734177a 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java @@ -199,15 +199,27 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException { final PlatformChannel.DeviceOrientation lockedOrientation = ((SensorOrientationFeature) cameraFeatures.getSensorOrientation()) .getLockedCaptureOrientation(); - + + if (Build.VERSION.SDK_INT >= 31) { mediaRecorder = - new MediaRecorderBuilder(getRecordingProfile(), outputFilePath) + new MediaRecorderBuilder(getRecordingProfile_v31(), outputFilePath) .setEnableAudio(enableAudio) .setMediaOrientation( lockedOrientation == null ? getDeviceOrientationManager().getVideoOrientation() : getDeviceOrientationManager().getVideoOrientation(lockedOrientation)) .build(); + } + else { + mediaRecorder = + new MediaRecorderBuilder(getRecordingProfile(), outputFilePath) + .setEnableAudio(enableAudio) + .setMediaOrientation( + lockedOrientation == null + ? getDeviceOrientationManager().getVideoOrientation() + : getDeviceOrientationManager().getVideoOrientation(lockedOrientation)) + .build(); + } } @SuppressLint("MissingPermission") @@ -920,8 +932,10 @@ public float getMinZoomLevel() { } /** Shortcut to get current recording profile. */ - EncoderProfiles getRecordingProfile() { - // return cameraFeatures.getResolution().getRecordingProfile(); + CamcorderProfile getRecordingProfile() { + return cameraFeatures.getResolution().getRecordingProfile(); + } + EncoderProfiles getRecordingProfile_v31() { return cameraFeatures.getResolution().getRecordingProfile_v31(); } diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java index 376d360dd399..ba19168a2ce4 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java @@ -56,6 +56,9 @@ import org.junit.Before; import org.junit.Test; import org.mockito.MockedStatic; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; public class CameraTest { private CameraProperties mockCameraProperties; @@ -250,22 +253,33 @@ public void getMinZoomLevel() { assertEquals(expectedMinZoomLevel, actualMinZoomLevel, 0); } + @Config(maxSdk = 30) @Test public void getRecordingProfile() { ResolutionFeature mockResolutionFeature = mockCameraFeatureFactory.createResolutionFeature(mockCameraProperties, null, null); - // CamcorderProfile mockCamcorderProfile = mock(CamcorderProfile.class); + CamcorderProfile mockCamcorderProfile = mock(CamcorderProfile.class); + + when(mockResolutionFeature.getRecordingProfile()).thenReturn(mockCamcorderProfile); + + CamcorderProfile actualRecordingProfile = camera.getRecordingProfile(); + + verify(mockResolutionFeature, times(1)).getRecordingProfile(); + assertEquals(mockCamcorderProfile, actualRecordingProfile); + } + + @Config(minSdk = 31) + @Test + public void getRecordingProfile_v31() { + ResolutionFeature mockResolutionFeature = + mockCameraFeatureFactory.createResolutionFeature(mockCameraProperties, null, null); EncoderProfiles mockRecordingProfile = mock(EncoderProfiles.class); - // when(mockResolutionFeature.getRecordingProfile()).thenReturn(mockCamcorderProfile); when(mockResolutionFeature.getRecordingProfile_v31()).thenReturn(mockRecordingProfile); - // CamcorderProfile actualRecordingProfile = camera.getRecordingProfile(); - EncoderProfiles actualRecordingProfile = camera.getRecordingProfile(); + EncoderProfiles actualRecordingProfile = camera.getRecordingProfile_v31(); - // verify(mockResolutionFeature, times(1)).getRecordingProfile(); verify(mockResolutionFeature, times(1)).getRecordingProfile_v31(); - // assertEquals(mockCamcorderProfile, actualRecordingProfile); assertEquals(mockRecordingProfile, actualRecordingProfile); } From 252a6feb3eb9f16e4f9dc52c13fdf285079c7f8a Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 13 Oct 2021 10:46:03 -0700 Subject: [PATCH 10/45] format files --- .../io/flutter/plugins/camera/Camera.java | 36 ++-- .../resolution/ResolutionFeature.java | 105 ++++++------ .../camera/media/MediaRecorderBuilder.java | 54 +++--- .../io/flutter/plugins/camera/CameraTest.java | 2 - .../resolution/ResolutionFeatureTest.java | 157 ++++++++++++------ .../media/MediaRecorderBuilderTest.java | 26 ++- 6 files changed, 213 insertions(+), 167 deletions(-) diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java index d9386734177a..1c3e382dd9fb 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java @@ -199,26 +199,25 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException { final PlatformChannel.DeviceOrientation lockedOrientation = ((SensorOrientationFeature) cameraFeatures.getSensorOrientation()) .getLockedCaptureOrientation(); - + if (Build.VERSION.SDK_INT >= 31) { - mediaRecorder = - new MediaRecorderBuilder(getRecordingProfile_v31(), outputFilePath) - .setEnableAudio(enableAudio) - .setMediaOrientation( - lockedOrientation == null - ? getDeviceOrientationManager().getVideoOrientation() - : getDeviceOrientationManager().getVideoOrientation(lockedOrientation)) - .build(); - } - else { mediaRecorder = - new MediaRecorderBuilder(getRecordingProfile(), outputFilePath) - .setEnableAudio(enableAudio) - .setMediaOrientation( - lockedOrientation == null - ? getDeviceOrientationManager().getVideoOrientation() - : getDeviceOrientationManager().getVideoOrientation(lockedOrientation)) - .build(); + new MediaRecorderBuilder(getRecordingProfile_v31(), outputFilePath) + .setEnableAudio(enableAudio) + .setMediaOrientation( + lockedOrientation == null + ? getDeviceOrientationManager().getVideoOrientation() + : getDeviceOrientationManager().getVideoOrientation(lockedOrientation)) + .build(); + } else { + mediaRecorder = + new MediaRecorderBuilder(getRecordingProfile(), outputFilePath) + .setEnableAudio(enableAudio) + .setMediaOrientation( + lockedOrientation == null + ? getDeviceOrientationManager().getVideoOrientation() + : getDeviceOrientationManager().getVideoOrientation(lockedOrientation)) + .build(); } } @@ -935,6 +934,7 @@ public float getMinZoomLevel() { CamcorderProfile getRecordingProfile() { return cameraFeatures.getResolution().getRecordingProfile(); } + EncoderProfiles getRecordingProfile_v31() { return cameraFeatures.getResolution().getRecordingProfile_v31(); } diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java index ae3f65403d5c..6020c10bfd37 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java @@ -4,10 +4,10 @@ package io.flutter.plugins.camera.features.resolution; -import android.os.Build; import android.hardware.camera2.CaptureRequest; import android.media.CamcorderProfile; import android.media.EncoderProfiles; +import android.os.Build; import android.util.Size; import androidx.annotation.VisibleForTesting; import io.flutter.plugins.camera.CameraProperties; @@ -114,21 +114,20 @@ static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) { preset = ResolutionPreset.high; } if (Build.VERSION.SDK_INT >= 31) { - EncoderProfiles profile = getBestAvailableCamcorderProfileForResolutionPreset_v31(cameraId, preset); + EncoderProfiles profile = + getBestAvailableCamcorderProfileForResolutionPreset_v31(cameraId, preset); List videoProfiles = profile.getVideoProfiles(); - + try { EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); return new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); - } - catch (IndexOutOfBoundsException e) { + } catch (IndexOutOfBoundsException e) { System.out.println("No video profiles found."); return null; } - } - else { + } else { CamcorderProfile profile = - getBestAvailableCamcorderProfileForResolutionPreset(cameraId, preset); + getBestAvailableCamcorderProfileForResolutionPreset(cameraId, preset); return new Size(profile.videoFrameWidth, profile.videoFrameHeight); } } @@ -189,49 +188,49 @@ public static CamcorderProfile getBestAvailableCamcorderProfileForResolutionPres } public static EncoderProfiles getBestAvailableCamcorderProfileForResolutionPreset_v31( - int cameraId, ResolutionPreset preset) { - if (cameraId < 0) { - throw new AssertionError( - "getBestAvailableCamcorderProfileForResolutionPreset can only be used with valid (>=0) camera identifiers."); - } + int cameraId, ResolutionPreset preset) { + if (cameraId < 0) { + throw new AssertionError( + "getBestAvailableCamcorderProfileForResolutionPreset can only be used with valid (>=0) camera identifiers."); + } - String cameraIdString = Integer.toString(cameraId); + String cameraIdString = Integer.toString(cameraId); - switch (preset) { - // All of these cases deliberately fall through to get the best available profile. - case max: - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_HIGH)) { - return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_HIGH); - } - case ultraHigh: - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_2160P)) { - return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_2160P); - } - case veryHigh: - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P)) { - return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_1080P); - } - case high: - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) { - return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_720P); - } - case medium: - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) { - return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_480P); - } - case low: - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_QVGA)) { - return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_QVGA); - } - default: - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW)) { - return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_LOW); - } else { - throw new IllegalArgumentException( - "No capture session available for current capture session."); - } + switch (preset) { + // All of these cases deliberately fall through to get the best available profile. + case max: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_HIGH)) { + return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_HIGH); + } + case ultraHigh: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_2160P)) { + return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_2160P); + } + case veryHigh: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P)) { + return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_1080P); + } + case high: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) { + return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_720P); + } + case medium: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) { + return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_480P); + } + case low: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_QVGA)) { + return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_QVGA); + } + default: + if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW)) { + return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_LOW); + } else { + throw new IllegalArgumentException( + "No capture session available for current capture session."); + } + } } -} @SuppressWarnings("deprecation") private void configureResolution(ResolutionPreset resolutionPreset, int cameraId) { @@ -242,18 +241,16 @@ private void configureResolution(ResolutionPreset resolutionPreset, int cameraId if (Build.VERSION.SDK_INT >= 31) { System.out.println("31"); recordingProfile_v31 = - getBestAvailableCamcorderProfileForResolutionPreset_v31(cameraId, resolutionPreset); - List videoProfiles = recordingProfile_v31.getVideoProfiles(); + getBestAvailableCamcorderProfileForResolutionPreset_v31(cameraId, resolutionPreset); + List videoProfiles = recordingProfile_v31.getVideoProfiles(); try { EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); captureSize = new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); - } - catch (IndexOutOfBoundsException e) { + } catch (IndexOutOfBoundsException e) { System.out.println("No video profiles found."); } - } - else { + } else { System.out.println("not 31"); recordingProfile = getBestAvailableCamcorderProfileForResolutionPreset(cameraId, resolutionPreset); diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java index cf0b9a4b3d3b..1ba9b7e1e704 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java @@ -33,19 +33,19 @@ public MediaRecorderBuilder( } public MediaRecorderBuilder( - @NonNull EncoderProfiles encoderProfiles, @NonNull String outputFilePath) { - this(encoderProfiles, outputFilePath, new MediaRecorderFactory()); -} + @NonNull EncoderProfiles encoderProfiles, @NonNull String outputFilePath) { + this(encoderProfiles, outputFilePath, new MediaRecorderFactory()); + } MediaRecorderBuilder( - @NonNull CamcorderProfile camcorderProfile, - @NonNull String outputFilePath, - MediaRecorderFactory helper) { - this.outputFilePath = outputFilePath; - this.camcorderProfile = camcorderProfile; - this.encoderProfiles = null; - this.recorderFactory = helper; -} + @NonNull CamcorderProfile camcorderProfile, + @NonNull String outputFilePath, + MediaRecorderFactory helper) { + this.outputFilePath = outputFilePath; + this.camcorderProfile = camcorderProfile; + this.encoderProfiles = null; + this.recorderFactory = helper; + } MediaRecorderBuilder( @NonNull EncoderProfiles encoderProfiles, @@ -80,28 +80,28 @@ public MediaRecorder build() throws IOException { EncoderProfiles.AudioProfile audioProfile = encoderProfiles.getAudioProfiles().get(0); mediaRecorder.setOutputFormat(encoderProfiles.getRecommendedFileFormat()); - if (enableAudio) { - mediaRecorder.setAudioEncoder(audioProfile.getCodec()); - mediaRecorder.setAudioEncodingBitRate(audioProfile.getBitrate()); - mediaRecorder.setAudioSamplingRate(audioProfile.getSampleRate()); + if (enableAudio) { + mediaRecorder.setAudioEncoder(audioProfile.getCodec()); + mediaRecorder.setAudioEncodingBitRate(audioProfile.getBitrate()); + mediaRecorder.setAudioSamplingRate(audioProfile.getSampleRate()); } mediaRecorder.setVideoEncoder(videoProfile.getCodec()); mediaRecorder.setVideoEncodingBitRate(videoProfile.getBitrate()); mediaRecorder.setVideoFrameRate(videoProfile.getFrameRate()); mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); - } - else { - mediaRecorder.setOutputFormat(camcorderProfile.fileFormat); - if (enableAudio) { - mediaRecorder.setAudioEncoder(camcorderProfile.audioCodec); - mediaRecorder.setAudioEncodingBitRate(camcorderProfile.audioBitRate); - mediaRecorder.setAudioSamplingRate(camcorderProfile.audioSampleRate); - } - mediaRecorder.setVideoEncoder(camcorderProfile.videoCodec); - mediaRecorder.setVideoEncodingBitRate(camcorderProfile.videoBitRate); - mediaRecorder.setVideoFrameRate(camcorderProfile.videoFrameRate); - mediaRecorder.setVideoSize(camcorderProfile.videoFrameWidth, camcorderProfile.videoFrameHeight); + } else { + mediaRecorder.setOutputFormat(camcorderProfile.fileFormat); + if (enableAudio) { + mediaRecorder.setAudioEncoder(camcorderProfile.audioCodec); + mediaRecorder.setAudioEncodingBitRate(camcorderProfile.audioBitRate); + mediaRecorder.setAudioSamplingRate(camcorderProfile.audioSampleRate); + } + mediaRecorder.setVideoEncoder(camcorderProfile.videoCodec); + mediaRecorder.setVideoEncodingBitRate(camcorderProfile.videoBitRate); + mediaRecorder.setVideoFrameRate(camcorderProfile.videoFrameRate); + mediaRecorder.setVideoSize( + camcorderProfile.videoFrameWidth, camcorderProfile.videoFrameHeight); } mediaRecorder.setOutputFile(outputFilePath); diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java index ba19168a2ce4..7103f9bb7dc5 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java @@ -56,8 +56,6 @@ import org.junit.Before; import org.junit.Test; import org.mockito.MockedStatic; -import org.robolectric.Robolectric; -import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; public class CameraTest { diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java index 5c70c41081cc..8dd8bb78b097 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java @@ -34,42 +34,78 @@ public void before() { mockProfileLow_v31 = mock(EncoderProfiles.class); CamcorderProfile mockProfile = mock(CamcorderProfile.class); EncoderProfiles mockProfile_v31 = mock(EncoderProfiles.class); - List mockVideoProfiles = List.of(mock(EncoderProfiles.VideoProfile.class)); - - mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)).thenReturn(true); - mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_2160P)).thenReturn(true); - mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_1080P)).thenReturn(true); - mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_720P)).thenReturn(true); - mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_480P)).thenReturn(true); - mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_QVGA)).thenReturn(true); - mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW)).thenReturn(true); + List mockVideoProfiles = + List.of(mock(EncoderProfiles.VideoProfile.class)); + + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)) + .thenReturn(true); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_2160P)) + .thenReturn(true); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_1080P)) + .thenReturn(true); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_720P)) + .thenReturn(true); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_480P)) + .thenReturn(true); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_QVGA)) + .thenReturn(true); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW)) + .thenReturn(true); if (Build.VERSION.SDK_INT >= 31) { - mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_HIGH)) - .thenReturn(mockProfile_v31); - mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_2160P)) - .thenReturn(mockProfile_v31); - mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_1080P)) - .thenReturn(mockProfile_v31); - mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)) - .thenReturn(mockProfile_v31); - mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_480P)) - .thenReturn(mockProfile_v31); - mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_QVGA)) - .thenReturn(mockProfile_v31); - mockedStaticProfile.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_LOW)) - .thenReturn(mockProfileLow_v31); - - when(mockProfile_v31.getVideoProfiles()).thenReturn(mockVideoProfiles); + mockedStaticProfile + .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_HIGH)) + .thenReturn(mockProfile_v31); + mockedStaticProfile + .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_2160P)) + .thenReturn(mockProfile_v31); + mockedStaticProfile + .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_1080P)) + .thenReturn(mockProfile_v31); + mockedStaticProfile + .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)) + .thenReturn(mockProfile_v31); + mockedStaticProfile + .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_480P)) + .thenReturn(mockProfile_v31); + mockedStaticProfile + .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_QVGA)) + .thenReturn(mockProfile_v31); + mockedStaticProfile + .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_LOW)) + .thenReturn(mockProfileLow_v31); + + when(mockProfile_v31.getVideoProfiles()).thenReturn(mockVideoProfiles); } else { - mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_HIGH)).thenReturn(mockProfile); - mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_2160P)).thenReturn(mockProfile); - mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_1080P)).thenReturn(mockProfile); - mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)).thenReturn(mockProfile); - mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)).thenReturn(mockProfile); - mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)).thenReturn(mockProfile); - mockedStaticProfile.when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_LOW)).thenReturn(mockProfileLow); + mockedStaticProfile + .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_HIGH)) + .thenReturn(mockProfile); + mockedStaticProfile + .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_2160P)) + .thenReturn(mockProfile); + mockedStaticProfile + .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_1080P)) + .thenReturn(mockProfile); + mockedStaticProfile + .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)) + .thenReturn(mockProfile); + mockedStaticProfile + .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)) + .thenReturn(mockProfile); + mockedStaticProfile + .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)) + .thenReturn(mockProfile); + mockedStaticProfile + .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_LOW)) + .thenReturn(mockProfileLow); } } @@ -82,7 +118,8 @@ public void after() { @Test public void getDebugName_shouldReturnTheNameOfTheFeature() { CameraProperties mockCameraProperties = mock(CameraProperties.class); - ResolutionFeature resolutionFeature = new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); + ResolutionFeature resolutionFeature = + new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); assertEquals("ResolutionFeature", resolutionFeature.getDebugName()); } @@ -90,7 +127,8 @@ public void getDebugName_shouldReturnTheNameOfTheFeature() { @Test public void getValue_shouldReturnInitialValueWhenNotSet() { CameraProperties mockCameraProperties = mock(CameraProperties.class); - ResolutionFeature resolutionFeature = new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); + ResolutionFeature resolutionFeature = + new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); assertEquals(ResolutionPreset.max, resolutionFeature.getValue()); } @@ -98,7 +136,8 @@ public void getValue_shouldReturnInitialValueWhenNotSet() { @Test public void getValue_shouldEchoSetValue() { CameraProperties mockCameraProperties = mock(CameraProperties.class); - ResolutionFeature resolutionFeature = new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); + ResolutionFeature resolutionFeature = + new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); resolutionFeature.setValue(ResolutionPreset.high); @@ -108,7 +147,8 @@ public void getValue_shouldEchoSetValue() { @Test public void checkIsSupport_returnsTrue() { CameraProperties mockCameraProperties = mock(CameraProperties.class); - ResolutionFeature resolutionFeature = new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); + ResolutionFeature resolutionFeature = + new ResolutionFeature(mockCameraProperties, ResolutionPreset.max, cameraName); assertTrue(resolutionFeature.checkIsSupported()); } @@ -116,20 +156,38 @@ public void checkIsSupport_returnsTrue() { @SuppressWarnings("deprecation") @Test public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThrough() { - mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)).thenReturn(false); - mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_2160P)).thenReturn(false); - mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_1080P)).thenReturn(false); - mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_720P)).thenReturn(false); - mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_480P)).thenReturn(false); - mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_QVGA)).thenReturn(false); - mockedStaticProfile.when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW)).thenReturn(true); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)) + .thenReturn(false); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_2160P)) + .thenReturn(false); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_1080P)) + .thenReturn(false); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_720P)) + .thenReturn(false); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_480P)) + .thenReturn(false); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_QVGA)) + .thenReturn(false); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW)) + .thenReturn(true); if (Build.VERSION.SDK_INT >= 31) { - assertEquals(mockProfileLow_v31, - ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset_v31(1, ResolutionPreset.max)); + assertEquals( + mockProfileLow_v31, + ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset_v31( + 1, ResolutionPreset.max)); } else { - assertEquals(mockProfileLow, - ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset(1, ResolutionPreset.max)); + assertEquals( + mockProfileLow, + ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset( + 1, ResolutionPreset.max)); } } @@ -143,7 +201,6 @@ public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetMax() { } else { mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); - } } @@ -169,7 +226,6 @@ public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetVeryHigh() { } else { mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); - } } @@ -182,7 +238,6 @@ public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetHigh() { mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); } else { mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); - } } @@ -195,7 +250,6 @@ public void computeBestPreviewSize_shouldUse480PWhenResolutionPresetMedium() { mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_480P)); } else { mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)); - } } @@ -208,7 +262,6 @@ public void computeBestPreviewSize_shouldUseQVGAWhenResolutionPresetLow() { mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_QVGA)); } else { mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)); - } } } diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java index fde604c626da..08800907e2c9 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java @@ -13,10 +13,9 @@ import java.io.IOException; import java.lang.reflect.Constructor; import java.util.List; -import org.junit.runner.RunWith; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.InOrder; -import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; @@ -36,7 +35,7 @@ public void ctor_test() { @Test public void ctor_test_v31() { MediaRecorderBuilder builder = - new MediaRecorderBuilder(CamcorderProfile.getAll("0",CamcorderProfile.QUALITY_1080P), ""); + new MediaRecorderBuilder(CamcorderProfile.getAll("0", CamcorderProfile.QUALITY_1080P), ""); assertNotNull(builder); } @@ -78,8 +77,10 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOEx @Test public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled_v31() throws IOException { EncoderProfiles recorderProfile = mock(EncoderProfiles.class); - List mockVideoProfiles = List.of(mock(EncoderProfiles.VideoProfile.class)); - List mockAudioProfiles = List.of(mock(EncoderProfiles.AudioProfile.class)); + List mockVideoProfiles = + List.of(mock(EncoderProfiles.VideoProfile.class)); + List mockAudioProfiles = + List.of(mock(EncoderProfiles.AudioProfile.class)); MediaRecorderBuilder.MediaRecorderFactory mockFactory = mock(MediaRecorderBuilder.MediaRecorderFactory.class); MediaRecorder mockMediaRecorder = mock(MediaRecorder.class); @@ -94,7 +95,6 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled_v31() throws when(recorderProfile.getVideoProfiles()).thenReturn(mockVideoProfiles); when(recorderProfile.getAudioProfiles()).thenReturn(mockAudioProfiles); - MediaRecorder recorder = builder.build(); EncoderProfiles.VideoProfile videoProfile = mockVideoProfiles.get(0); @@ -105,9 +105,7 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled_v31() throws inOrder.verify(recorder).setVideoEncoder(videoProfile.getCodec()); inOrder.verify(recorder).setVideoEncodingBitRate(videoProfile.getBitrate()); inOrder.verify(recorder).setVideoFrameRate(videoProfile.getFrameRate()); - inOrder - .verify(recorder) - .setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); + inOrder.verify(recorder).setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); inOrder.verify(recorder).setOutputFile(outputFilePath); inOrder.verify(recorder).setOrientationHint(mediaOrientation); inOrder.verify(recorder).prepare(); @@ -155,8 +153,10 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOExc public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled_v31() throws IOException { System.out.println(getEmptyCamcorderProfile()); EncoderProfiles recorderProfile = mock(EncoderProfiles.class); - List mockVideoProfiles = List.of(mock(EncoderProfiles.VideoProfile.class)); - List mockAudioProfiles = List.of(mock(EncoderProfiles.AudioProfile.class)); + List mockVideoProfiles = + List.of(mock(EncoderProfiles.VideoProfile.class)); + List mockAudioProfiles = + List.of(mock(EncoderProfiles.AudioProfile.class)); MediaRecorderBuilder.MediaRecorderFactory mockFactory = mock(MediaRecorderBuilder.MediaRecorderFactory.class); MediaRecorder mockMediaRecorder = mock(MediaRecorder.class); @@ -186,9 +186,7 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled_v31() throws I inOrder.verify(recorder).setVideoEncoder(videoProfile.getCodec()); inOrder.verify(recorder).setVideoEncodingBitRate(videoProfile.getBitrate()); inOrder.verify(recorder).setVideoFrameRate(videoProfile.getFrameRate()); - inOrder - .verify(recorder) - .setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); + inOrder.verify(recorder).setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); inOrder.verify(recorder).setOutputFile(outputFilePath); inOrder.verify(recorder).setOrientationHint(mediaOrientation); inOrder.verify(recorder).prepare(); From f8fd254825e8ee2597c4f2512e98a03c18da4842 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 13 Oct 2021 13:23:48 -0700 Subject: [PATCH 11/45] restore device orientation (unrelated todo) --- packages/camera/camera/android/build.gradle | 1 - .../sensororientation/DeviceOrientationManagerTest.java | 2 -- 2 files changed, 3 deletions(-) diff --git a/packages/camera/camera/android/build.gradle b/packages/camera/camera/android/build.gradle index 8f437547bb54..884c561abe0c 100644 --- a/packages/camera/camera/android/build.gradle +++ b/packages/camera/camera/android/build.gradle @@ -30,7 +30,6 @@ android { compileSdkVersion 31 defaultConfig { - // targetSdkVersion 31 minSdkVersion 21 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java index a2cb5e18b2e9..a1b0d0b4fca8 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java @@ -30,7 +30,6 @@ public class DeviceOrientationManagerTest { private Activity mockActivity; - private Context mockContext; private DartMessenger mockDartMessenger; private WindowManager mockWindowManager; private Display mockDisplay; @@ -40,7 +39,6 @@ public class DeviceOrientationManagerTest { @Before public void before() { mockActivity = mock(Activity.class); - mockContext = mock(Context.class); mockDartMessenger = mock(DartMessenger.class); mockDisplay = mock(Display.class); mockWindowManager = mock(WindowManager.class); From f238289d6f6ad844b97aea3aaea7f647b4e01c50 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 13 Oct 2021 13:50:12 -0700 Subject: [PATCH 12/45] changed error handling --- .../resolution/ResolutionFeature.java | 25 ++++++------------- .../camera/media/MediaRecorderBuilder.java | 2 +- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java index 6020c10bfd37..26b58615e593 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java @@ -109,7 +109,8 @@ public void updateBuilder(CaptureRequest.Builder requestBuilder) { @SuppressWarnings("deprecation") @VisibleForTesting - static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) { + static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) + throws IndexOutOfBoundsException { if (preset.ordinal() > ResolutionPreset.high.ordinal()) { preset = ResolutionPreset.high; } @@ -118,13 +119,8 @@ static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) { getBestAvailableCamcorderProfileForResolutionPreset_v31(cameraId, preset); List videoProfiles = profile.getVideoProfiles(); - try { - EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); - return new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); - } catch (IndexOutOfBoundsException e) { - System.out.println("No video profiles found."); - return null; - } + EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); + return new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); } else { CamcorderProfile profile = getBestAvailableCamcorderProfileForResolutionPreset(cameraId, preset); @@ -233,25 +229,20 @@ public static EncoderProfiles getBestAvailableCamcorderProfileForResolutionPrese } @SuppressWarnings("deprecation") - private void configureResolution(ResolutionPreset resolutionPreset, int cameraId) { + private void configureResolution(ResolutionPreset resolutionPreset, int cameraId) + throws IndexOutOfBoundsException { if (!checkIsSupported()) { return; } if (Build.VERSION.SDK_INT >= 31) { - System.out.println("31"); recordingProfile_v31 = getBestAvailableCamcorderProfileForResolutionPreset_v31(cameraId, resolutionPreset); List videoProfiles = recordingProfile_v31.getVideoProfiles(); - try { - EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); - captureSize = new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); - } catch (IndexOutOfBoundsException e) { - System.out.println("No video profiles found."); - } + EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); + captureSize = new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); } else { - System.out.println("not 31"); recordingProfile = getBestAvailableCamcorderProfileForResolutionPreset(cameraId, resolutionPreset); captureSize = new Size(recordingProfile.videoFrameWidth, recordingProfile.videoFrameHeight); diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java index 1ba9b7e1e704..0aebfee39e0a 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java @@ -67,7 +67,7 @@ public MediaRecorderBuilder setMediaOrientation(int orientation) { return this; } - public MediaRecorder build() throws IOException { + public MediaRecorder build() throws IOException, NullPointerException, IndexOutOfBoundsException { MediaRecorder mediaRecorder = recorderFactory.makeMediaRecorder(); // There's a fixed order that mediaRecorder expects. Only change these functions accordingly. From 8532e97acd734178208010fc1ecb5c7251925a53 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 13 Oct 2021 14:01:21 -0700 Subject: [PATCH 13/45] add error check for media recorder --- .../media/MediaRecorderBuilderTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java index 08800907e2c9..54cc9b504dc8 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java @@ -111,6 +111,25 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled_v31() throws inOrder.verify(recorder).prepare(); } + @Config(minSdk = 31) + @Test(expected = IndexOutOfBoundsException.class) + public void build_shouldThrowExceptionWithoutVideoOrAudioProfiles_v31() throws IOException{ + EncoderProfiles recorderProfile = mock(EncoderProfiles.class); + MediaRecorderBuilder.MediaRecorderFactory mockFactory = + mock(MediaRecorderBuilder.MediaRecorderFactory.class); + MediaRecorder mockMediaRecorder = mock(MediaRecorder.class); + String outputFilePath = "mock_video_file_path"; + int mediaOrientation = 1; + MediaRecorderBuilder builder = + new MediaRecorderBuilder(recorderProfile, outputFilePath, mockFactory) + .setEnableAudio(false) + .setMediaOrientation(mediaOrientation); + + when(mockFactory.makeMediaRecorder()).thenReturn(mockMediaRecorder); + + MediaRecorder recorder = builder.build(); + } + @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test From 724f891ee1e63696b72cc9fad2458b684e152074 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Fri, 15 Oct 2021 09:02:03 -0700 Subject: [PATCH 14/45] add robolectric to resolutionfeature test --- .../resolution/ResolutionFeature.java | 2 +- .../resolution/ResolutionFeatureTest.java | 250 +++++++++++------- 2 files changed, 159 insertions(+), 93 deletions(-) diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java index 26b58615e593..8967c29df966 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java @@ -118,8 +118,8 @@ static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) EncoderProfiles profile = getBestAvailableCamcorderProfileForResolutionPreset_v31(cameraId, preset); List videoProfiles = profile.getVideoProfiles(); - EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); + return new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); } else { CamcorderProfile profile = diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java index 8dd8bb78b097..fb0f2a3cbf15 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java @@ -12,14 +12,17 @@ import android.media.CamcorderProfile; import android.media.EncoderProfiles; -import android.os.Build; import io.flutter.plugins.camera.CameraProperties; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.MockedStatic; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; +@RunWith(RobolectricTestRunner.class) public class ResolutionFeatureTest { private static final String cameraName = "1"; private CamcorderProfile mockProfileLow; @@ -34,8 +37,8 @@ public void before() { mockProfileLow_v31 = mock(EncoderProfiles.class); CamcorderProfile mockProfile = mock(CamcorderProfile.class); EncoderProfiles mockProfile_v31 = mock(EncoderProfiles.class); - List mockVideoProfiles = - List.of(mock(EncoderProfiles.VideoProfile.class)); + EncoderProfiles.VideoProfile mockVideoProfile = mock(EncoderProfiles.VideoProfile.class); + List mockVideoProfilesList = List.of(mockVideoProfile); mockedStaticProfile .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)) @@ -59,54 +62,57 @@ public void before() { .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW)) .thenReturn(true); - if (Build.VERSION.SDK_INT >= 31) { - mockedStaticProfile - .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_HIGH)) - .thenReturn(mockProfile_v31); - mockedStaticProfile - .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_2160P)) - .thenReturn(mockProfile_v31); - mockedStaticProfile - .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_1080P)) - .thenReturn(mockProfile_v31); - mockedStaticProfile - .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)) - .thenReturn(mockProfile_v31); - mockedStaticProfile - .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_480P)) - .thenReturn(mockProfile_v31); - mockedStaticProfile - .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_QVGA)) - .thenReturn(mockProfile_v31); - mockedStaticProfile - .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_LOW)) - .thenReturn(mockProfileLow_v31); - - when(mockProfile_v31.getVideoProfiles()).thenReturn(mockVideoProfiles); - - } else { - mockedStaticProfile - .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_HIGH)) - .thenReturn(mockProfile); - mockedStaticProfile - .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_2160P)) - .thenReturn(mockProfile); - mockedStaticProfile - .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_1080P)) - .thenReturn(mockProfile); - mockedStaticProfile - .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)) - .thenReturn(mockProfile); - mockedStaticProfile - .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)) - .thenReturn(mockProfile); - mockedStaticProfile - .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)) - .thenReturn(mockProfile); - mockedStaticProfile - .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_LOW)) - .thenReturn(mockProfileLow); - } + mockedStaticProfile + .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_HIGH)) + .thenReturn(mockProfile); + mockedStaticProfile + .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_2160P)) + .thenReturn(mockProfile); + mockedStaticProfile + .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_1080P)) + .thenReturn(mockProfile); + mockedStaticProfile + .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)) + .thenReturn(mockProfile); + mockedStaticProfile + .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)) + .thenReturn(mockProfile); + mockedStaticProfile + .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)) + .thenReturn(mockProfile); + mockedStaticProfile + .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_LOW)) + .thenReturn(mockProfileLow); + + when(mockProfile_v31.getVideoProfiles()).thenReturn(mockVideoProfilesList); + when(mockVideoProfile.getHeight()).thenReturn(100); + when(mockVideoProfile.getWidth()).thenReturn(100); + } + + public void before_v31() { + EncoderProfiles mockProfile_v31 = mock(EncoderProfiles.class); + + mockedStaticProfile + .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_HIGH)) + .thenReturn(mockProfile_v31); + mockedStaticProfile + .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_2160P)) + .thenReturn(mockProfile_v31); + mockedStaticProfile + .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_1080P)) + .thenReturn(mockProfile_v31); + mockedStaticProfile + .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)) + .thenReturn(mockProfile_v31); + mockedStaticProfile + .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_480P)) + .thenReturn(mockProfile_v31); + mockedStaticProfile + .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_QVGA)) + .thenReturn(mockProfile_v31); + mockedStaticProfile + .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_LOW)) + .thenReturn(mockProfileLow_v31); } @After @@ -153,6 +159,7 @@ public void checkIsSupport_returnsTrue() { assertTrue(resolutionFeature.checkIsSupported()); } + @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThrough() { @@ -178,90 +185,149 @@ public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThroug .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW)) .thenReturn(true); - if (Build.VERSION.SDK_INT >= 31) { - assertEquals( - mockProfileLow_v31, - ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset_v31( - 1, ResolutionPreset.max)); - } else { - assertEquals( - mockProfileLow, - ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset( - 1, ResolutionPreset.max)); - } + assertEquals( + mockProfileLow, + ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset( + 1, ResolutionPreset.max)); } + @Config(minSdk = 31) + @Test + public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThrough_v31() { + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)) + .thenReturn(false); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_2160P)) + .thenReturn(false); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_1080P)) + .thenReturn(false); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_720P)) + .thenReturn(false); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_480P)) + .thenReturn(false); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_QVGA)) + .thenReturn(false); + mockedStaticProfile + .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW)) + .thenReturn(true); + + assertEquals( + mockProfileLow_v31, + ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset_v31( + 1, ResolutionPreset.max)); + } + + @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetMax() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.max); - if (Build.VERSION.SDK_INT >= 31) { - mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); + mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); + } + + @Config(minSdk = 31) + @Test + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetMax_v31() { + before_v31(); + ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.max); - } else { - mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); - } + mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); } + @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetUltraHigh() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.ultraHigh); - if (Build.VERSION.SDK_INT >= 31) { - mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); - } else { - mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); - } + mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); } + @Config(minSdk = 31) + @Test + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetUltraHigh_v31() { + before_v31(); + ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.ultraHigh); + + mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); + } + + @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetVeryHigh() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.veryHigh); - if (Build.VERSION.SDK_INT >= 31) { - mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); + mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); + } + + @Config(minSdk = 31) + @SuppressWarnings("deprecation") + @Test + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetVeryHigh_v31() { + before_v31(); + ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.veryHigh); - } else { - mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); - } + mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); } + @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetHigh() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.high); - if (Build.VERSION.SDK_INT >= 31) { - mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); - } else { - mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); - } + mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); } + @Config(minSdk = 31) + @Test + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetHigh_v31() { + before_v31(); + ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.high); + + mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); + } + + @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test public void computeBestPreviewSize_shouldUse480PWhenResolutionPresetMedium() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.medium); - if (Build.VERSION.SDK_INT >= 31) { - mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_480P)); - } else { - mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)); - } + mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)); + } + + @Config(minSdk = 31) + @Test + public void computeBestPreviewSize_shouldUse480PWhenResolutionPresetMedium_v31() { + before_v31(); + ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.medium); + + mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_480P)); } + @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test public void computeBestPreviewSize_shouldUseQVGAWhenResolutionPresetLow() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.low); - if (Build.VERSION.SDK_INT >= 31) { - mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_QVGA)); - } else { - mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)); - } + mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)); + } + + @Config(minSdk = 31) + @Test + public void computeBestPreviewSize_shouldUseQVGAWhenResolutionPresetLow_v31() { + before_v31(); + ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.low); + + mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_QVGA)); } } From b77b4fcd5671865e4d30fe83339dcc1b8ad19403 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Fri, 15 Oct 2021 12:54:12 -0700 Subject: [PATCH 15/45] push latest changes to resolve camera test --- .../src/test/java/io/flutter/plugins/camera/CameraTest.java | 3 +++ .../camera/features/resolution/ResolutionFeatureTest.java | 2 +- packages/camera/camera/example/android/gradle.properties | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java index 7103f9bb7dc5..d1880a2d8709 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java @@ -54,10 +54,13 @@ import io.flutter.view.TextureRegistry; import org.junit.After; import org.junit.Before; +import org.junit.runner.RunWith; import org.junit.Test; import org.mockito.MockedStatic; import org.robolectric.annotation.Config; +import org.robolectric.RobolectricTestRunner; +// @RunWith(RobolectricTestRunner.class) public class CameraTest { private CameraProperties mockCameraProperties; private CameraFeatureFactory mockCameraFeatureFactory; diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java index fb0f2a3cbf15..208eca05aedb 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java @@ -84,7 +84,7 @@ public void before() { .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_LOW)) .thenReturn(mockProfileLow); - when(mockProfile_v31.getVideoProfiles()).thenReturn(mockVideoProfilesList); + when(mockProfile_v31.getVideoProfiles()).thenReturn(mockVideoProfilesList); //TODO: move this logic when(mockVideoProfile.getHeight()).thenReturn(100); when(mockVideoProfile.getWidth()).thenReturn(100); } diff --git a/packages/camera/camera/example/android/gradle.properties b/packages/camera/camera/example/android/gradle.properties index 030ee5d13667..d0a2069e4243 100644 --- a/packages/camera/camera/example/android/gradle.properties +++ b/packages/camera/camera/example/android/gradle.properties @@ -3,3 +3,4 @@ android.useAndroidX=true android.enableJetifier=true android.enableR8=true android.jetifier.blacklist=bcprov-jdk15on +android.enableUnitTestBinaryResources=true From d6110ea643b51e81288a7b27324794146d9a790a Mon Sep 17 00:00:00 2001 From: camsim99 Date: Fri, 15 Oct 2021 13:01:55 -0700 Subject: [PATCH 16/45] reformat and reorganize resolution feature test --- .../io/flutter/plugins/camera/CameraTest.java | 2 -- .../resolution/ResolutionFeatureTest.java | 15 +++++++-------- .../camera/media/MediaRecorderBuilderTest.java | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java index d1880a2d8709..2b89d44cf181 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java @@ -54,11 +54,9 @@ import io.flutter.view.TextureRegistry; import org.junit.After; import org.junit.Before; -import org.junit.runner.RunWith; import org.junit.Test; import org.mockito.MockedStatic; import org.robolectric.annotation.Config; -import org.robolectric.RobolectricTestRunner; // @RunWith(RobolectricTestRunner.class) public class CameraTest { diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java index 208eca05aedb..d7d5a8c1cfe7 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java @@ -34,11 +34,7 @@ public class ResolutionFeatureTest { public void before() { mockedStaticProfile = mockStatic(CamcorderProfile.class); mockProfileLow = mock(CamcorderProfile.class); - mockProfileLow_v31 = mock(EncoderProfiles.class); CamcorderProfile mockProfile = mock(CamcorderProfile.class); - EncoderProfiles mockProfile_v31 = mock(EncoderProfiles.class); - EncoderProfiles.VideoProfile mockVideoProfile = mock(EncoderProfiles.VideoProfile.class); - List mockVideoProfilesList = List.of(mockVideoProfile); mockedStaticProfile .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)) @@ -83,14 +79,13 @@ public void before() { mockedStaticProfile .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_LOW)) .thenReturn(mockProfileLow); - - when(mockProfile_v31.getVideoProfiles()).thenReturn(mockVideoProfilesList); //TODO: move this logic - when(mockVideoProfile.getHeight()).thenReturn(100); - when(mockVideoProfile.getWidth()).thenReturn(100); } public void before_v31() { + mockProfileLow_v31 = mock(EncoderProfiles.class); EncoderProfiles mockProfile_v31 = mock(EncoderProfiles.class); + EncoderProfiles.VideoProfile mockVideoProfile = mock(EncoderProfiles.VideoProfile.class); + List mockVideoProfilesList = List.of(mockVideoProfile); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_HIGH)) @@ -113,6 +108,10 @@ public void before_v31() { mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_LOW)) .thenReturn(mockProfileLow_v31); + + when(mockProfile_v31.getVideoProfiles()).thenReturn(mockVideoProfilesList); + when(mockVideoProfile.getHeight()).thenReturn(100); + when(mockVideoProfile.getWidth()).thenReturn(100); } @After diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java index 54cc9b504dc8..f6d9b92a3cb7 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java @@ -113,7 +113,7 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled_v31() throws @Config(minSdk = 31) @Test(expected = IndexOutOfBoundsException.class) - public void build_shouldThrowExceptionWithoutVideoOrAudioProfiles_v31() throws IOException{ + public void build_shouldThrowExceptionWithoutVideoOrAudioProfiles_v31() throws IOException { EncoderProfiles recorderProfile = mock(EncoderProfiles.class); MediaRecorderBuilder.MediaRecorderFactory mockFactory = mock(MediaRecorderBuilder.MediaRecorderFactory.class); From b7f764958b14737aac3c42c3f39bba9681eab25c Mon Sep 17 00:00:00 2001 From: camsim99 Date: Fri, 15 Oct 2021 13:08:27 -0700 Subject: [PATCH 17/45] add missing imports --- .../src/test/java/io/flutter/plugins/camera/CameraTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java index 2b89d44cf181..4e7d58e235a2 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java @@ -54,11 +54,13 @@ import io.flutter.view.TextureRegistry; import org.junit.After; import org.junit.Before; +import org.junit.runner.RunWith; import org.junit.Test; import org.mockito.MockedStatic; import org.robolectric.annotation.Config; +import org.robolectric.RobolectricTestRunner; -// @RunWith(RobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class CameraTest { private CameraProperties mockCameraProperties; private CameraFeatureFactory mockCameraFeatureFactory; From c77ff4e3c238b16e31462501619758fff2545681 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Fri, 15 Oct 2021 17:35:39 -0700 Subject: [PATCH 18/45] correct camera test --- packages/camera/camera/android/build.gradle | 3 +- .../io/flutter/plugins/camera/CameraTest.java | 36 --- .../CameraTest_getRecordingProfileTest.java | 205 ++++++++++++++++++ .../src/test/resources/robolectric.properties | 1 + 4 files changed, 208 insertions(+), 37 deletions(-) create mode 100644 packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest_getRecordingProfileTest.java create mode 100644 packages/camera/camera/android/src/test/resources/robolectric.properties diff --git a/packages/camera/camera/android/build.gradle b/packages/camera/camera/android/build.gradle index 884c561abe0c..d010036f5c8b 100644 --- a/packages/camera/camera/android/build.gradle +++ b/packages/camera/camera/android/build.gradle @@ -30,6 +30,7 @@ android { compileSdkVersion 31 defaultConfig { + targetSdkVersion 31 minSdkVersion 21 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -60,7 +61,7 @@ android { dependencies { compileOnly 'androidx.annotation:annotation:1.1.0' testImplementation 'junit:junit:4.12' - testImplementation 'org.mockito:mockito-inline:3.12.4' + testImplementation 'org.mockito:mockito-inline:4.0.0' testImplementation 'androidx.test:core:1.3.0' testImplementation 'org.robolectric:robolectric:4.6.1' } diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java index 4e7d58e235a2..1ed2e4c11d7b 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest.java @@ -22,8 +22,6 @@ import android.hardware.camera2.CameraCaptureSession; import android.hardware.camera2.CameraMetadata; import android.hardware.camera2.CaptureRequest; -import android.media.CamcorderProfile; -import android.media.EncoderProfiles; import android.media.MediaRecorder; import android.os.Build; import android.os.Handler; @@ -54,13 +52,9 @@ import io.flutter.view.TextureRegistry; import org.junit.After; import org.junit.Before; -import org.junit.runner.RunWith; import org.junit.Test; import org.mockito.MockedStatic; -import org.robolectric.annotation.Config; -import org.robolectric.RobolectricTestRunner; -@RunWith(RobolectricTestRunner.class) public class CameraTest { private CameraProperties mockCameraProperties; private CameraFeatureFactory mockCameraFeatureFactory; @@ -254,36 +248,6 @@ public void getMinZoomLevel() { assertEquals(expectedMinZoomLevel, actualMinZoomLevel, 0); } - @Config(maxSdk = 30) - @Test - public void getRecordingProfile() { - ResolutionFeature mockResolutionFeature = - mockCameraFeatureFactory.createResolutionFeature(mockCameraProperties, null, null); - CamcorderProfile mockCamcorderProfile = mock(CamcorderProfile.class); - - when(mockResolutionFeature.getRecordingProfile()).thenReturn(mockCamcorderProfile); - - CamcorderProfile actualRecordingProfile = camera.getRecordingProfile(); - - verify(mockResolutionFeature, times(1)).getRecordingProfile(); - assertEquals(mockCamcorderProfile, actualRecordingProfile); - } - - @Config(minSdk = 31) - @Test - public void getRecordingProfile_v31() { - ResolutionFeature mockResolutionFeature = - mockCameraFeatureFactory.createResolutionFeature(mockCameraProperties, null, null); - EncoderProfiles mockRecordingProfile = mock(EncoderProfiles.class); - - when(mockResolutionFeature.getRecordingProfile_v31()).thenReturn(mockRecordingProfile); - - EncoderProfiles actualRecordingProfile = camera.getRecordingProfile_v31(); - - verify(mockResolutionFeature, times(1)).getRecordingProfile_v31(); - assertEquals(mockRecordingProfile, actualRecordingProfile); - } - @Test public void setExposureMode_shouldUpdateExposureLockFeature() { ExposureLockFeature mockExposureLockFeature = diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest_getRecordingProfileTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest_getRecordingProfileTest.java new file mode 100644 index 000000000000..ce94e1fbc691 --- /dev/null +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest_getRecordingProfileTest.java @@ -0,0 +1,205 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.camera; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.app.Activity; +import android.hardware.camera2.CameraCaptureSession; +import android.hardware.camera2.CaptureRequest; +import android.media.CamcorderProfile; +import android.media.EncoderProfiles; +import android.os.Handler; +import android.os.HandlerThread; +import androidx.annotation.NonNull; +import io.flutter.plugins.camera.features.CameraFeatureFactory; +import io.flutter.plugins.camera.features.autofocus.AutoFocusFeature; +import io.flutter.plugins.camera.features.exposurelock.ExposureLockFeature; +import io.flutter.plugins.camera.features.exposureoffset.ExposureOffsetFeature; +import io.flutter.plugins.camera.features.exposurepoint.ExposurePointFeature; +import io.flutter.plugins.camera.features.flash.FlashFeature; +import io.flutter.plugins.camera.features.focuspoint.FocusPointFeature; +import io.flutter.plugins.camera.features.fpsrange.FpsRangeFeature; +import io.flutter.plugins.camera.features.noisereduction.NoiseReductionFeature; +import io.flutter.plugins.camera.features.resolution.ResolutionFeature; +import io.flutter.plugins.camera.features.resolution.ResolutionPreset; +import io.flutter.plugins.camera.features.sensororientation.SensorOrientationFeature; +import io.flutter.plugins.camera.features.zoomlevel.ZoomLevelFeature; +import io.flutter.view.TextureRegistry; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockedStatic; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +@RunWith(RobolectricTestRunner.class) +public class CameraTest_getRecordingProfileTest { + + private CameraProperties mockCameraProperties; + private CameraFeatureFactory mockCameraFeatureFactory; + private DartMessenger mockDartMessenger; + private Camera camera; + private CameraCaptureSession mockCaptureSession; + private CaptureRequest.Builder mockPreviewRequestBuilder; + private MockedStatic mockHandlerThreadFactory; + private HandlerThread mockHandlerThread; + private MockedStatic mockHandlerFactory; + private Handler mockHandler; + + @Before + public void before() { + mockCameraProperties = mock(CameraProperties.class); + mockCameraFeatureFactory = new TestCameraFeatureFactory(); + mockDartMessenger = mock(DartMessenger.class); + + final Activity mockActivity = mock(Activity.class); + final TextureRegistry.SurfaceTextureEntry mockFlutterTexture = + mock(TextureRegistry.SurfaceTextureEntry.class); + final ResolutionPreset resolutionPreset = ResolutionPreset.high; + final boolean enableAudio = false; + + camera = + new Camera( + mockActivity, + mockFlutterTexture, + mockCameraFeatureFactory, + mockDartMessenger, + mockCameraProperties, + resolutionPreset, + enableAudio); + } + + @Config(maxSdk = 30) + @Test + public void getRecordingProfile() { + ResolutionFeature mockResolutionFeature = + mockCameraFeatureFactory.createResolutionFeature(mockCameraProperties, null, null); + CamcorderProfile mockCamcorderProfile = mock(CamcorderProfile.class); + + when(mockResolutionFeature.getRecordingProfile()).thenReturn(mockCamcorderProfile); + + CamcorderProfile actualRecordingProfile = camera.getRecordingProfile(); + + verify(mockResolutionFeature, times(1)).getRecordingProfile(); + assertEquals(mockCamcorderProfile, actualRecordingProfile); + } + + @Config(minSdk = 31) + @Test + public void getRecordingProfile_v31() { + ResolutionFeature mockResolutionFeature = + mockCameraFeatureFactory.createResolutionFeature(mockCameraProperties, null, null); + EncoderProfiles mockRecordingProfile = mock(EncoderProfiles.class); + + when(mockResolutionFeature.getRecordingProfile_v31()).thenReturn(mockRecordingProfile); + + EncoderProfiles actualRecordingProfile = camera.getRecordingProfile_v31(); + + verify(mockResolutionFeature, times(1)).getRecordingProfile_v31(); + assertEquals(mockRecordingProfile, actualRecordingProfile); + } + + private static class TestCameraFeatureFactory implements CameraFeatureFactory { + private final AutoFocusFeature mockAutoFocusFeature; + private final ExposureLockFeature mockExposureLockFeature; + private final ExposureOffsetFeature mockExposureOffsetFeature; + private final ExposurePointFeature mockExposurePointFeature; + private final FlashFeature mockFlashFeature; + private final FocusPointFeature mockFocusPointFeature; + private final FpsRangeFeature mockFpsRangeFeature; + private final NoiseReductionFeature mockNoiseReductionFeature; + private final ResolutionFeature mockResolutionFeature; + private final SensorOrientationFeature mockSensorOrientationFeature; + private final ZoomLevelFeature mockZoomLevelFeature; + + public TestCameraFeatureFactory() { + this.mockAutoFocusFeature = mock(AutoFocusFeature.class); + this.mockExposureLockFeature = mock(ExposureLockFeature.class); + this.mockExposureOffsetFeature = mock(ExposureOffsetFeature.class); + this.mockExposurePointFeature = mock(ExposurePointFeature.class); + this.mockFlashFeature = mock(FlashFeature.class); + this.mockFocusPointFeature = mock(FocusPointFeature.class); + this.mockFpsRangeFeature = mock(FpsRangeFeature.class); + this.mockNoiseReductionFeature = mock(NoiseReductionFeature.class); + this.mockResolutionFeature = mock(ResolutionFeature.class); + this.mockSensorOrientationFeature = mock(SensorOrientationFeature.class); + this.mockZoomLevelFeature = mock(ZoomLevelFeature.class); + } + + @Override + public AutoFocusFeature createAutoFocusFeature( + @NonNull CameraProperties cameraProperties, boolean recordingVideo) { + return mockAutoFocusFeature; + } + + @Override + public ExposureLockFeature createExposureLockFeature( + @NonNull CameraProperties cameraProperties) { + return mockExposureLockFeature; + } + + @Override + public ExposureOffsetFeature createExposureOffsetFeature( + @NonNull CameraProperties cameraProperties) { + return mockExposureOffsetFeature; + } + + @Override + public FlashFeature createFlashFeature(@NonNull CameraProperties cameraProperties) { + return mockFlashFeature; + } + + @Override + public ResolutionFeature createResolutionFeature( + @NonNull CameraProperties cameraProperties, + ResolutionPreset initialSetting, + String cameraName) { + return mockResolutionFeature; + } + + @Override + public FocusPointFeature createFocusPointFeature( + @NonNull CameraProperties cameraProperties, + @NonNull SensorOrientationFeature sensorOrienttionFeature) { + return mockFocusPointFeature; + } + + @Override + public FpsRangeFeature createFpsRangeFeature(@NonNull CameraProperties cameraProperties) { + return mockFpsRangeFeature; + } + + @Override + public SensorOrientationFeature createSensorOrientationFeature( + @NonNull CameraProperties cameraProperties, + @NonNull Activity activity, + @NonNull DartMessenger dartMessenger) { + return mockSensorOrientationFeature; + } + + @Override + public ZoomLevelFeature createZoomLevelFeature(@NonNull CameraProperties cameraProperties) { + return mockZoomLevelFeature; + } + + @Override + public ExposurePointFeature createExposurePointFeature( + @NonNull CameraProperties cameraProperties, + @NonNull SensorOrientationFeature sensorOrientationFeature) { + return mockExposurePointFeature; + } + + @Override + public NoiseReductionFeature createNoiseReductionFeature( + @NonNull CameraProperties cameraProperties) { + return mockNoiseReductionFeature; + } + } +} diff --git a/packages/camera/camera/android/src/test/resources/robolectric.properties b/packages/camera/camera/android/src/test/resources/robolectric.properties new file mode 100644 index 000000000000..90fbd74370a7 --- /dev/null +++ b/packages/camera/camera/android/src/test/resources/robolectric.properties @@ -0,0 +1 @@ +sdk=30 \ No newline at end of file From 162309b292c9cae0b6269e4f791ea90af552b542 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 18 Oct 2021 11:00:13 -0700 Subject: [PATCH 19/45] removed print statement --- .../flutter/plugins/camera/media/MediaRecorderBuilderTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java index f6d9b92a3cb7..ec8dec6fbd27 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java @@ -170,7 +170,6 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOExc @Config(minSdk = 31) @Test public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled_v31() throws IOException { - System.out.println(getEmptyCamcorderProfile()); EncoderProfiles recorderProfile = mock(EncoderProfiles.class); List mockVideoProfiles = List.of(mock(EncoderProfiles.VideoProfile.class)); From e74767abc59a2f81f359984d76a240d8b6661c11 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 18 Oct 2021 16:14:12 -0700 Subject: [PATCH 20/45] change names --- .../io/flutter/plugins/camera/Camera.java | 33 ++++++------ .../resolution/ResolutionFeature.java | 22 ++++---- .../CameraTest_getRecordingProfileTest.java | 8 +-- .../resolution/ResolutionFeatureTest.java | 54 +++++++++---------- .../media/MediaRecorderBuilderTest.java | 8 +-- 5 files changed, 61 insertions(+), 64 deletions(-) diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java index 1c3e382dd9fb..4c34dbe0152c 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java @@ -200,25 +200,22 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException { ((SensorOrientationFeature) cameraFeatures.getSensorOrientation()) .getLockedCaptureOrientation(); + MediaRecorderBuilder mediaRecorderBuilder; + if (Build.VERSION.SDK_INT >= 31) { - mediaRecorder = - new MediaRecorderBuilder(getRecordingProfile_v31(), outputFilePath) - .setEnableAudio(enableAudio) - .setMediaOrientation( - lockedOrientation == null - ? getDeviceOrientationManager().getVideoOrientation() - : getDeviceOrientationManager().getVideoOrientation(lockedOrientation)) - .build(); + mediaRecorderBuilder = new MediaRecorderBuilder(getRecordingProfileOn31(), outputFilePath); } else { - mediaRecorder = - new MediaRecorderBuilder(getRecordingProfile(), outputFilePath) - .setEnableAudio(enableAudio) - .setMediaOrientation( - lockedOrientation == null - ? getDeviceOrientationManager().getVideoOrientation() - : getDeviceOrientationManager().getVideoOrientation(lockedOrientation)) - .build(); + mediaRecorderBuilder = new MediaRecorderBuilder(getRecordingProfile(), outputFilePath); } + + mediaRecorder = + mediaRecorderBuilder + .setEnableAudio(enableAudio) + .setMediaOrientation( + lockedOrientation == null + ? getDeviceOrientationManager().getVideoOrientation() + : getDeviceOrientationManager().getVideoOrientation(lockedOrientation)) + .build(); } @SuppressLint("MissingPermission") @@ -935,8 +932,8 @@ CamcorderProfile getRecordingProfile() { return cameraFeatures.getResolution().getRecordingProfile(); } - EncoderProfiles getRecordingProfile_v31() { - return cameraFeatures.getResolution().getRecordingProfile_v31(); + EncoderProfiles getRecordingProfileOn31() { + return cameraFeatures.getResolution().getRecordingProfileOn31(); } /** Shortut to get deviceOrientationListener. */ diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java index 8967c29df966..1662b98f4b3e 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java @@ -25,7 +25,7 @@ public class ResolutionFeature extends CameraFeature { private Size captureSize; private Size previewSize; private CamcorderProfile recordingProfile; - private EncoderProfiles recordingProfile_v31; + private EncoderProfiles recordingProfileOn31; private ResolutionPreset currentSetting; private int cameraId; @@ -59,8 +59,8 @@ public CamcorderProfile getRecordingProfile() { return this.recordingProfile; } - public EncoderProfiles getRecordingProfile_v31() { - return this.recordingProfile_v31; + public EncoderProfiles getRecordingProfileOn31() { + return this.recordingProfileOn31; } /** @@ -116,7 +116,7 @@ static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) } if (Build.VERSION.SDK_INT >= 31) { EncoderProfiles profile = - getBestAvailableCamcorderProfileForResolutionPreset_v31(cameraId, preset); + getBestAvailableCamcorderProfileForResolutionPresetOn31(cameraId, preset); List videoProfiles = profile.getVideoProfiles(); EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); @@ -183,7 +183,7 @@ public static CamcorderProfile getBestAvailableCamcorderProfileForResolutionPres } } - public static EncoderProfiles getBestAvailableCamcorderProfileForResolutionPreset_v31( + public static EncoderProfiles getBestAvailableCamcorderProfileForResolutionPresetOn31( int cameraId, ResolutionPreset preset) { if (cameraId < 0) { throw new AssertionError( @@ -221,10 +221,10 @@ public static EncoderProfiles getBestAvailableCamcorderProfileForResolutionPrese default: if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW)) { return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_LOW); - } else { - throw new IllegalArgumentException( - "No capture session available for current capture session."); } + + throw new IllegalArgumentException( + "No capture session available for current capture session."); } } @@ -236,9 +236,9 @@ private void configureResolution(ResolutionPreset resolutionPreset, int cameraId } if (Build.VERSION.SDK_INT >= 31) { - recordingProfile_v31 = - getBestAvailableCamcorderProfileForResolutionPreset_v31(cameraId, resolutionPreset); - List videoProfiles = recordingProfile_v31.getVideoProfiles(); + recordingProfileOn31 = + getBestAvailableCamcorderProfileForResolutionPresetOn31(cameraId, resolutionPreset); + List videoProfiles = recordingProfileOn31.getVideoProfiles(); EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); captureSize = new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest_getRecordingProfileTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest_getRecordingProfileTest.java index ce94e1fbc691..431124f54b98 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest_getRecordingProfileTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest_getRecordingProfileTest.java @@ -93,16 +93,16 @@ public void getRecordingProfile() { @Config(minSdk = 31) @Test - public void getRecordingProfile_v31() { + public void getRecordingProfileOn31() { ResolutionFeature mockResolutionFeature = mockCameraFeatureFactory.createResolutionFeature(mockCameraProperties, null, null); EncoderProfiles mockRecordingProfile = mock(EncoderProfiles.class); - when(mockResolutionFeature.getRecordingProfile_v31()).thenReturn(mockRecordingProfile); + when(mockResolutionFeature.getRecordingProfileOn31()).thenReturn(mockRecordingProfile); - EncoderProfiles actualRecordingProfile = camera.getRecordingProfile_v31(); + EncoderProfiles actualRecordingProfile = camera.getRecordingProfileOn31(); - verify(mockResolutionFeature, times(1)).getRecordingProfile_v31(); + verify(mockResolutionFeature, times(1)).getRecordingProfileOn31(); assertEquals(mockRecordingProfile, actualRecordingProfile); } diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java index d7d5a8c1cfe7..fc9b908f8ace 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java @@ -26,7 +26,7 @@ public class ResolutionFeatureTest { private static final String cameraName = "1"; private CamcorderProfile mockProfileLow; - private EncoderProfiles mockProfileLow_v31; + private EncoderProfiles mockProfileLowOn31; private MockedStatic mockedStaticProfile; @Before @@ -81,35 +81,35 @@ public void before() { .thenReturn(mockProfileLow); } - public void before_v31() { - mockProfileLow_v31 = mock(EncoderProfiles.class); - EncoderProfiles mockProfile_v31 = mock(EncoderProfiles.class); + public void beforeOn31() { + mockProfileLowOn31 = mock(EncoderProfiles.class); + EncoderProfiles mockProfileOn31 = mock(EncoderProfiles.class); EncoderProfiles.VideoProfile mockVideoProfile = mock(EncoderProfiles.VideoProfile.class); List mockVideoProfilesList = List.of(mockVideoProfile); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_HIGH)) - .thenReturn(mockProfile_v31); + .thenReturn(mockProfileOn31); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_2160P)) - .thenReturn(mockProfile_v31); + .thenReturn(mockProfileOn31); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_1080P)) - .thenReturn(mockProfile_v31); + .thenReturn(mockProfileOn31); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)) - .thenReturn(mockProfile_v31); + .thenReturn(mockProfileOn31); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_480P)) - .thenReturn(mockProfile_v31); + .thenReturn(mockProfileOn31); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_QVGA)) - .thenReturn(mockProfile_v31); + .thenReturn(mockProfileOn31); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_LOW)) - .thenReturn(mockProfileLow_v31); + .thenReturn(mockProfileLowOn31); - when(mockProfile_v31.getVideoProfiles()).thenReturn(mockVideoProfilesList); + when(mockProfileOn31.getVideoProfiles()).thenReturn(mockVideoProfilesList); when(mockVideoProfile.getHeight()).thenReturn(100); when(mockVideoProfile.getWidth()).thenReturn(100); } @@ -192,7 +192,7 @@ public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThroug @Config(minSdk = 31) @Test - public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThrough_v31() { + public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThroughOn31() { mockedStaticProfile .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)) .thenReturn(false); @@ -216,8 +216,8 @@ public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThroug .thenReturn(true); assertEquals( - mockProfileLow_v31, - ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset_v31( + mockProfileLowOn31, + ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPresetOn31( 1, ResolutionPreset.max)); } @@ -232,8 +232,8 @@ public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetMax() { @Config(minSdk = 31) @Test - public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetMax_v31() { - before_v31(); + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetMaxOn31() { + beforeOn31(); ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.max); mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); @@ -250,8 +250,8 @@ public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetUltraHigh() @Config(minSdk = 31) @Test - public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetUltraHigh_v31() { - before_v31(); + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetUltraHighOn31() { + beforeOn31(); ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.ultraHigh); mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); @@ -269,8 +269,8 @@ public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetVeryHigh() { @Config(minSdk = 31) @SuppressWarnings("deprecation") @Test - public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetVeryHigh_v31() { - before_v31(); + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetVeryHighOn31() { + beforeOn31(); ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.veryHigh); mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); @@ -287,8 +287,8 @@ public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetHigh() { @Config(minSdk = 31) @Test - public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetHigh_v31() { - before_v31(); + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetHighOn31() { + beforeOn31(); ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.high); mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); @@ -305,8 +305,8 @@ public void computeBestPreviewSize_shouldUse480PWhenResolutionPresetMedium() { @Config(minSdk = 31) @Test - public void computeBestPreviewSize_shouldUse480PWhenResolutionPresetMedium_v31() { - before_v31(); + public void computeBestPreviewSize_shouldUse480PWhenResolutionPresetMediumOn31() { + beforeOn31(); ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.medium); mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_480P)); @@ -323,8 +323,8 @@ public void computeBestPreviewSize_shouldUseQVGAWhenResolutionPresetLow() { @Config(minSdk = 31) @Test - public void computeBestPreviewSize_shouldUseQVGAWhenResolutionPresetLow_v31() { - before_v31(); + public void computeBestPreviewSize_shouldUseQVGAWhenResolutionPresetLowOn31() { + beforeOn31(); ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.low); mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_QVGA)); diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java index ec8dec6fbd27..5e74ce949f45 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java @@ -33,7 +33,7 @@ public void ctor_test() { @Config(minSdk = 31) @Test - public void ctor_test_v31() { + public void ctor_testOn31() { MediaRecorderBuilder builder = new MediaRecorderBuilder(CamcorderProfile.getAll("0", CamcorderProfile.QUALITY_1080P), ""); @@ -75,7 +75,7 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOEx @Config(minSdk = 31) @Test - public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled_v31() throws IOException { + public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabledOn31() throws IOException { EncoderProfiles recorderProfile = mock(EncoderProfiles.class); List mockVideoProfiles = List.of(mock(EncoderProfiles.VideoProfile.class)); @@ -113,7 +113,7 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled_v31() throws @Config(minSdk = 31) @Test(expected = IndexOutOfBoundsException.class) - public void build_shouldThrowExceptionWithoutVideoOrAudioProfiles_v31() throws IOException { + public void build_shouldThrowExceptionWithoutVideoOrAudioProfilesOn31() throws IOException { EncoderProfiles recorderProfile = mock(EncoderProfiles.class); MediaRecorderBuilder.MediaRecorderFactory mockFactory = mock(MediaRecorderBuilder.MediaRecorderFactory.class); @@ -169,7 +169,7 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOExc @Config(minSdk = 31) @Test - public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled_v31() throws IOException { + public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabledOn31() throws IOException { EncoderProfiles recorderProfile = mock(EncoderProfiles.class); List mockVideoProfiles = List.of(mock(EncoderProfiles.VideoProfile.class)); From 3fd589c107bbc82ba2a5900384e23f63e315f209 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 18 Oct 2021 16:32:39 -0700 Subject: [PATCH 21/45] Document gradle properties --- packages/camera/camera/example/android/gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/camera/camera/example/android/gradle.properties b/packages/camera/camera/example/android/gradle.properties index d0a2069e4243..5429e72885f9 100644 --- a/packages/camera/camera/example/android/gradle.properties +++ b/packages/camera/camera/example/android/gradle.properties @@ -2,5 +2,5 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true android.enableR8=true -android.jetifier.blacklist=bcprov-jdk15on -android.enableUnitTestBinaryResources=true +# To resolve dependencies needed for SDK-specific tests +android.jetifier.blacklist=bcprov From d3547d8467200f5775fef9dfecd11c6d7827ffb3 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 18 Oct 2021 16:46:03 -0700 Subject: [PATCH 22/45] change bcprov jdk version --- packages/camera/camera/example/android/gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/camera/camera/example/android/gradle.properties b/packages/camera/camera/example/android/gradle.properties index 5429e72885f9..73317adb53dc 100644 --- a/packages/camera/camera/example/android/gradle.properties +++ b/packages/camera/camera/example/android/gradle.properties @@ -3,4 +3,4 @@ android.useAndroidX=true android.enableJetifier=true android.enableR8=true # To resolve dependencies needed for SDK-specific tests -android.jetifier.blacklist=bcprov +android.jetifier.blacklist=bcprov-jdk15on:1.68 From c8194fc4bfe5a1559649fd36c64dbede5c02a583 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 18 Oct 2021 17:00:09 -0700 Subject: [PATCH 23/45] modify enablejetifier --- packages/camera/camera/example/android/gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/camera/camera/example/android/gradle.properties b/packages/camera/camera/example/android/gradle.properties index 73317adb53dc..031945904101 100644 --- a/packages/camera/camera/example/android/gradle.properties +++ b/packages/camera/camera/example/android/gradle.properties @@ -1,6 +1,6 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true -android.enableJetifier=true +android.enableJetifier=false android.enableR8=true # To resolve dependencies needed for SDK-specific tests -android.jetifier.blacklist=bcprov-jdk15on:1.68 +android.jetifier.blacklist=bcprov From 84a243a6f327274cf48cbc1cf6b6c06205ffd463 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 18 Oct 2021 17:12:06 -0700 Subject: [PATCH 24/45] removie blacklist option --- packages/camera/camera/example/android/gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/camera/camera/example/android/gradle.properties b/packages/camera/camera/example/android/gradle.properties index 031945904101..340f486e6baa 100644 --- a/packages/camera/camera/example/android/gradle.properties +++ b/packages/camera/camera/example/android/gradle.properties @@ -3,4 +3,4 @@ android.useAndroidX=true android.enableJetifier=false android.enableR8=true # To resolve dependencies needed for SDK-specific tests -android.jetifier.blacklist=bcprov +#android.jetifier.blacklist=bcprov From 95fac07238399ac5f61777db6c0c55e6ffe54d89 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 18 Oct 2021 17:26:16 -0700 Subject: [PATCH 25/45] trying gradle modifications --- packages/camera/camera/android/build.gradle | 2 +- packages/camera/camera/example/android/gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/camera/camera/android/build.gradle b/packages/camera/camera/android/build.gradle index d010036f5c8b..3eacf6eba15d 100644 --- a/packages/camera/camera/android/build.gradle +++ b/packages/camera/camera/android/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:4.2.0' } } diff --git a/packages/camera/camera/example/android/gradle.properties b/packages/camera/camera/example/android/gradle.properties index 340f486e6baa..031945904101 100644 --- a/packages/camera/camera/example/android/gradle.properties +++ b/packages/camera/camera/example/android/gradle.properties @@ -3,4 +3,4 @@ android.useAndroidX=true android.enableJetifier=false android.enableR8=true # To resolve dependencies needed for SDK-specific tests -#android.jetifier.blacklist=bcprov +android.jetifier.blacklist=bcprov From 00a4e0d80f9493ac0dc95cb3dddd5f31f66549d0 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Tue, 19 Oct 2021 09:10:09 -0700 Subject: [PATCH 26/45] upgrade gradle version: --- packages/camera/camera/android/build.gradle | 2 +- packages/camera/camera/example/android/gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/camera/camera/android/build.gradle b/packages/camera/camera/android/build.gradle index 3eacf6eba15d..0f14afa253a8 100644 --- a/packages/camera/camera/android/build.gradle +++ b/packages/camera/camera/android/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.2.0' + classpath 'com.android.tools.build:gradle:7.0.0-alpha03' } } diff --git a/packages/camera/camera/example/android/gradle.properties b/packages/camera/camera/example/android/gradle.properties index 031945904101..5429e72885f9 100644 --- a/packages/camera/camera/example/android/gradle.properties +++ b/packages/camera/camera/example/android/gradle.properties @@ -1,6 +1,6 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true -android.enableJetifier=false +android.enableJetifier=true android.enableR8=true # To resolve dependencies needed for SDK-specific tests android.jetifier.blacklist=bcprov From d59ff1f1999844a602e2f90616adb4175c4fc654 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Tue, 19 Oct 2021 09:25:11 -0700 Subject: [PATCH 27/45] upgrade gradle version and remove deprecations --- packages/camera/camera/android/build.gradle | 2 +- packages/camera/camera/example/android/gradle.properties | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/camera/camera/android/build.gradle b/packages/camera/camera/android/build.gradle index 0f14afa253a8..39dc36a2a597 100644 --- a/packages/camera/camera/android/build.gradle +++ b/packages/camera/camera/android/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:7.0.0-alpha03' + classpath 'com.android.tools.build:gradle:7.0.2' } } diff --git a/packages/camera/camera/example/android/gradle.properties b/packages/camera/camera/example/android/gradle.properties index 5429e72885f9..59714757c5bb 100644 --- a/packages/camera/camera/example/android/gradle.properties +++ b/packages/camera/camera/example/android/gradle.properties @@ -1,6 +1,6 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true -android.enableJetifier=true +android.enableJetifier=false android.enableR8=true # To resolve dependencies needed for SDK-specific tests -android.jetifier.blacklist=bcprov +android.jetifier.ignorelist=bcprov From fb944833d56f6027f51db19fccabbf60a8d6d252 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Tue, 19 Oct 2021 14:33:51 -0700 Subject: [PATCH 28/45] downgrade robolectric version --- packages/camera/camera/android/build.gradle | 2 +- packages/camera/camera/example/android/gradle.properties | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/camera/camera/android/build.gradle b/packages/camera/camera/android/build.gradle index 39dc36a2a597..264f7f8edc7d 100644 --- a/packages/camera/camera/android/build.gradle +++ b/packages/camera/camera/android/build.gradle @@ -63,5 +63,5 @@ dependencies { testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-inline:4.0.0' testImplementation 'androidx.test:core:1.3.0' - testImplementation 'org.robolectric:robolectric:4.6.1' + testImplementation 'org.robolectric:robolectric:4.5' } diff --git a/packages/camera/camera/example/android/gradle.properties b/packages/camera/camera/example/android/gradle.properties index 59714757c5bb..b253d8e5f746 100644 --- a/packages/camera/camera/example/android/gradle.properties +++ b/packages/camera/camera/example/android/gradle.properties @@ -2,5 +2,3 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=false android.enableR8=true -# To resolve dependencies needed for SDK-specific tests -android.jetifier.ignorelist=bcprov From e0f71bcfc8ab91cac7fff89624e6ffc99fb7bf0c Mon Sep 17 00:00:00 2001 From: camsim99 Date: Tue, 19 Oct 2021 14:58:13 -0700 Subject: [PATCH 29/45] remove robolectric req'd docker lines --- .ci/Dockerfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.ci/Dockerfile b/.ci/Dockerfile index a3deb6948d90..60f82eb005ed 100644 --- a/.ci/Dockerfile +++ b/.ci/Dockerfile @@ -5,10 +5,6 @@ FROM cirrusci/flutter:2.2.2 RUN apt-get update -y -# Required by Roboeletric and the Android SDK. -RUN apt-get install -y openjdk-8-jdk -ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 - RUN apt-get install -y --no-install-recommends gnupg # Add repo for gcloud sdk and install it From 92e44c186569aa469d88493e9185cefb61f64e1a Mon Sep 17 00:00:00 2001 From: camsim99 Date: Tue, 19 Oct 2021 17:08:00 -0700 Subject: [PATCH 30/45] fix video_player and target api CI issues --- .../plugins/camera/features/resolution/ResolutionFeature.java | 2 ++ .../video_player/video_player/example/android/app/build.gradle | 2 +- .../android/app/gradle/wrapper/gradle-wrapper.properties | 2 +- packages/video_player/video_player/example/android/build.gradle | 2 +- .../example/android/gradle/wrapper/gradle-wrapper.properties | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java index 1662b98f4b3e..992396ab00a7 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java @@ -4,6 +4,7 @@ package io.flutter.plugins.camera.features.resolution; +import android.annotation.TargetApi; import android.hardware.camera2.CaptureRequest; import android.media.CamcorderProfile; import android.media.EncoderProfiles; @@ -183,6 +184,7 @@ public static CamcorderProfile getBestAvailableCamcorderProfileForResolutionPres } } + @TargetApi(Build.VERSION_CODES.S) public static EncoderProfiles getBestAvailableCamcorderProfileForResolutionPresetOn31( int cameraId, ResolutionPreset preset) { if (cameraId < 0) { diff --git a/packages/video_player/video_player/example/android/app/build.gradle b/packages/video_player/video_player/example/android/app/build.gradle index 0d1d5031ef4f..a1fc1f6b4204 100644 --- a/packages/video_player/video_player/example/android/app/build.gradle +++ b/packages/video_player/video_player/example/android/app/build.gradle @@ -61,6 +61,6 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' - testImplementation 'org.robolectric:robolectric:3.8' + testImplementation 'org.robolectric:robolectric:4.6' testImplementation 'org.mockito:mockito-core:3.5.13' } diff --git a/packages/video_player/video_player/example/android/app/gradle/wrapper/gradle-wrapper.properties b/packages/video_player/video_player/example/android/app/gradle/wrapper/gradle-wrapper.properties index 9a4163a4f5ee..29e413457635 100644 --- a/packages/video_player/video_player/example/android/app/gradle/wrapper/gradle-wrapper.properties +++ b/packages/video_player/video_player/example/android/app/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/packages/video_player/video_player/example/android/build.gradle b/packages/video_player/video_player/example/android/build.gradle index 456d020f6e2c..9971094448c3 100644 --- a/packages/video_player/video_player/example/android/build.gradle +++ b/packages/video_player/video_player/example/android/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:7.0.2' } } diff --git a/packages/video_player/video_player/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/video_player/video_player/example/android/gradle/wrapper/gradle-wrapper.properties index 296b146b7318..b8793d3c0d69 100644 --- a/packages/video_player/video_player/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/packages/video_player/video_player/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip From e54ec6183d29bb8f112f5edf3a28e3cf0560e897 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 20 Oct 2021 09:37:07 -0700 Subject: [PATCH 31/45] modify connectivity gradle verison --- .../connectivity/connectivity/example/android/app/build.gradle | 2 +- .../android/app/gradle/wrapper/gradle-wrapper.properties | 2 +- packages/connectivity/connectivity/example/android/build.gradle | 2 +- .../example/android/gradle/wrapper/gradle-wrapper.properties | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/connectivity/connectivity/example/android/app/build.gradle b/packages/connectivity/connectivity/example/android/app/build.gradle index 64f3d0626bf4..777712c5fc6e 100644 --- a/packages/connectivity/connectivity/example/android/app/build.gradle +++ b/packages/connectivity/connectivity/example/android/app/build.gradle @@ -55,6 +55,6 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' - testImplementation 'org.robolectric:robolectric:3.8' + testImplementation 'org.robolectric:robolectric:4.6' testImplementation 'org.mockito:mockito-core:3.5.13' } diff --git a/packages/connectivity/connectivity/example/android/app/gradle/wrapper/gradle-wrapper.properties b/packages/connectivity/connectivity/example/android/app/gradle/wrapper/gradle-wrapper.properties index 9a4163a4f5ee..29e413457635 100644 --- a/packages/connectivity/connectivity/example/android/app/gradle/wrapper/gradle-wrapper.properties +++ b/packages/connectivity/connectivity/example/android/app/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/packages/connectivity/connectivity/example/android/build.gradle b/packages/connectivity/connectivity/example/android/build.gradle index 456d020f6e2c..9971094448c3 100644 --- a/packages/connectivity/connectivity/example/android/build.gradle +++ b/packages/connectivity/connectivity/example/android/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:7.0.2' } } diff --git a/packages/connectivity/connectivity/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/connectivity/connectivity/example/android/gradle/wrapper/gradle-wrapper.properties index 01a286e96a21..297f2fec363f 100644 --- a/packages/connectivity/connectivity/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/packages/connectivity/connectivity/example/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip From bf9e4f7a59061c10802c8ca0018eafc3bd799e61 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 20 Oct 2021 11:20:05 -0700 Subject: [PATCH 32/45] circumvent android-lint problems for now --- .cirrus.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index ef6b9c1b6d44..ce136ce37587 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -219,11 +219,12 @@ task: - echo "This user does not have permission to run Firebase Test Lab tests." - fi # Upload the full lint results to Cirrus to display in the results UI. - always: - android-lint_artifacts: - path: "**/reports/lint-results-debug.xml" - type: text/xml - format: android-lint + # TODO(camsim99): See https://github.com/flutter/flutter/issues/92201 + # always: + # android-lint_artifacts: + # path: "**/reports/lint-results-debug.xml" + # type: text/xml + # format: android-lint ### Web tasks ### - name: web-platform_tests env: From e10031d953692bc1bd054c720bc5c81c3290a2c2 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 20 Oct 2021 14:46:03 -0700 Subject: [PATCH 33/45] Bump plugin versions and update release notes --- packages/camera/camera/CHANGELOG.md | 6 ++++++ packages/camera/camera/pubspec.yaml | 2 +- packages/connectivity/connectivity/CHANGELOG.md | 1 + packages/connectivity/connectivity/pubspec.yaml | 2 +- packages/video_player/video_player/CHANGELOG.md | 4 ++++ packages/video_player/video_player/pubspec.yaml | 2 +- 6 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/camera/camera/CHANGELOG.md b/packages/camera/camera/CHANGELOG.md index dc83a4fabca2..1a2c5b5a6be6 100644 --- a/packages/camera/camera/CHANGELOG.md +++ b/packages/camera/camera/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.9.4+3 + +* Change compileSdkVersion to 31. +* Remove deprecated `CamcorderProfile`. +* Update gradle version to 7.0.2. + ## 0.9.4+2 * Updated package description; diff --git a/packages/camera/camera/pubspec.yaml b/packages/camera/camera/pubspec.yaml index f68d026b206c..6b4db7cd91ec 100644 --- a/packages/camera/camera/pubspec.yaml +++ b/packages/camera/camera/pubspec.yaml @@ -4,7 +4,7 @@ description: A Flutter plugin for controlling the camera. Supports previewing Dart. repository: https://github.com/flutter/plugins/tree/master/packages/camera/camera issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.9.4+2 +version: 0.9.4+3 environment: sdk: ">=2.14.0 <3.0.0" diff --git a/packages/connectivity/connectivity/CHANGELOG.md b/packages/connectivity/connectivity/CHANGELOG.md index 932565842efd..c8347901499e 100644 --- a/packages/connectivity/connectivity/CHANGELOG.md +++ b/packages/connectivity/connectivity/CHANGELOG.md @@ -3,6 +3,7 @@ * Remove references to the Android V1 embedding. * Updated Android lint settings. * Specify Java 8 for Android build. +* Update gradle version to 7.0.2. ## 3.0.6 diff --git a/packages/connectivity/connectivity/pubspec.yaml b/packages/connectivity/connectivity/pubspec.yaml index 16e179cfa085..4cbfdaef8caf 100644 --- a/packages/connectivity/connectivity/pubspec.yaml +++ b/packages/connectivity/connectivity/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for discovering the state of the network (WiFi & mobile/cellular) connectivity on Android and iOS. repository: https://github.com/flutter/plugins/tree/master/packages/connectivity/connectivity issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+connectivity%22 -version: 3.0.6 +version: 3.0.6+1 environment: sdk: ">=2.12.0 <3.0.0" diff --git a/packages/video_player/video_player/CHANGELOG.md b/packages/video_player/video_player/CHANGELOG.md index 539a5520e5be..f48ecdc7190b 100644 --- a/packages/video_player/video_player/CHANGELOG.md +++ b/packages/video_player/video_player/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.2.5+1 + +* Upgrade gradle version to 7.0.2. + ## 2.2.5 * Support to closed caption WebVTT format added. diff --git a/packages/video_player/video_player/pubspec.yaml b/packages/video_player/video_player/pubspec.yaml index a6ee2d594656..48a48a4f24dd 100644 --- a/packages/video_player/video_player/pubspec.yaml +++ b/packages/video_player/video_player/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter widgets on Android, iOS, and web. repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22 -version: 2.2.5 +version: 2.2.5+1 environment: sdk: ">=2.14.0 <3.0.0" From ef23a8c876fa1808416585100fe0bf6155155ba9 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 20 Oct 2021 14:56:15 -0700 Subject: [PATCH 34/45] Revert mistake versionplugin bump --- packages/connectivity/connectivity/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/connectivity/connectivity/pubspec.yaml b/packages/connectivity/connectivity/pubspec.yaml index 4cbfdaef8caf..16e179cfa085 100644 --- a/packages/connectivity/connectivity/pubspec.yaml +++ b/packages/connectivity/connectivity/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for discovering the state of the network (WiFi & mobile/cellular) connectivity on Android and iOS. repository: https://github.com/flutter/plugins/tree/master/packages/connectivity/connectivity issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+connectivity%22 -version: 3.0.6+1 +version: 3.0.6 environment: sdk: ">=2.12.0 <3.0.0" From 4fff3f33ff860c32e3693bf6b73f23c2a63e1cda Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 20 Oct 2021 16:48:48 -0700 Subject: [PATCH 35/45] Correct video_player version --- packages/video_player/video_player/CHANGELOG.md | 2 +- packages/video_player/video_player/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/video_player/video_player/CHANGELOG.md b/packages/video_player/video_player/CHANGELOG.md index f48ecdc7190b..27fdf6b8d785 100644 --- a/packages/video_player/video_player/CHANGELOG.md +++ b/packages/video_player/video_player/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.2.5+1 +## 2.2.6 * Upgrade gradle version to 7.0.2. diff --git a/packages/video_player/video_player/pubspec.yaml b/packages/video_player/video_player/pubspec.yaml index 48a48a4f24dd..c002ed859f2c 100644 --- a/packages/video_player/video_player/pubspec.yaml +++ b/packages/video_player/video_player/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter widgets on Android, iOS, and web. repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22 -version: 2.2.5+1 +version: 2.2.6 environment: sdk: ">=2.14.0 <3.0.0" From d2d58b337d7265e9b1041ec0c293d3df3ded7c2d Mon Sep 17 00:00:00 2001 From: camsim99 Date: Thu, 21 Oct 2021 10:26:16 -0700 Subject: [PATCH 36/45] Make first round of addressing Stuart's comments --- .ci/Dockerfile | 4 ++++ packages/camera/camera/CHANGELOG.md | 6 +++--- .../sensororientation/DeviceOrientationManagerTest.java | 1 - 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.ci/Dockerfile b/.ci/Dockerfile index 60f82eb005ed..a3deb6948d90 100644 --- a/.ci/Dockerfile +++ b/.ci/Dockerfile @@ -5,6 +5,10 @@ FROM cirrusci/flutter:2.2.2 RUN apt-get update -y +# Required by Roboeletric and the Android SDK. +RUN apt-get install -y openjdk-8-jdk +ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 + RUN apt-get install -y --no-install-recommends gnupg # Add repo for gcloud sdk and install it diff --git a/packages/camera/camera/CHANGELOG.md b/packages/camera/camera/CHANGELOG.md index b840caa8dcca..29750f9cefff 100644 --- a/packages/camera/camera/CHANGELOG.md +++ b/packages/camera/camera/CHANGELOG.md @@ -1,8 +1,8 @@ ## 0.9.4+3 -* Change compileSdkVersion to 31. -* Remove deprecated `CamcorderProfile`. -* Update gradle version to 7.0.2. +* Change Android compileSdkVersion to 31. +* Remove usages of deprecated Android API `CamcorderProfile`. +* Update gradle version to 7.0.2 on Android. * Fix registerTexture and result being called on background thread on iOS. ## 0.9.4+2 diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java index a1b0d0b4fca8..58f17cb758bf 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java @@ -35,7 +35,6 @@ public class DeviceOrientationManagerTest { private Display mockDisplay; private DeviceOrientationManager deviceOrientationManager; - @SuppressWarnings("deprecation") @Before public void before() { mockActivity = mock(Activity.class); From 25550d039119028fb1c8c3c1654e2e20a509480d Mon Sep 17 00:00:00 2001 From: camsim99 Date: Thu, 21 Oct 2021 12:17:48 -0700 Subject: [PATCH 37/45] rename on31, add back android-lint-artifcats --- .cirrus.yml | 11 +++--- .../io/flutter/plugins/camera/Camera.java | 14 +++---- .../resolution/ResolutionFeature.java | 39 ++++++++++--------- .../CameraTest_getRecordingProfileTest.java | 16 ++++---- .../resolution/ResolutionFeatureTest.java | 4 +- 5 files changed, 43 insertions(+), 41 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 628c7f110d85..f223ce93dfd2 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -220,12 +220,11 @@ task: - echo "This user does not have permission to run Firebase Test Lab tests." - fi # Upload the full lint results to Cirrus to display in the results UI. - # TODO(camsim99): See https://github.com/flutter/flutter/issues/92201 - # always: - # android-lint_artifacts: - # path: "**/reports/lint-results-debug.xml" - # type: text/xml - # format: android-lint + always: + android-lint_artifacts: + path: "**/reports/lint-results-debug.xml" + type: text/xml + format: android-lint ### Web tasks ### - name: web-platform_tests env: diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java index 4c34dbe0152c..e31903955b4e 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java @@ -203,9 +203,9 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException { MediaRecorderBuilder mediaRecorderBuilder; if (Build.VERSION.SDK_INT >= 31) { - mediaRecorderBuilder = new MediaRecorderBuilder(getRecordingProfileOn31(), outputFilePath); - } else { mediaRecorderBuilder = new MediaRecorderBuilder(getRecordingProfile(), outputFilePath); + } else { + mediaRecorderBuilder = new MediaRecorderBuilder(getRecordingProfileLegacy(), outputFilePath); } mediaRecorder = @@ -927,13 +927,13 @@ public float getMinZoomLevel() { return cameraFeatures.getZoomLevel().getMinimumZoomLevel(); } - /** Shortcut to get current recording profile. */ - CamcorderProfile getRecordingProfile() { - return cameraFeatures.getResolution().getRecordingProfile(); + /** Shortcut to get current recording profile. Legacy method provides support for SDK < 31. */ + CamcorderProfile getRecordingProfileLegacy() { + return cameraFeatures.getResolution().getRecordingProfileLegacy(); } - EncoderProfiles getRecordingProfileOn31() { - return cameraFeatures.getResolution().getRecordingProfileOn31(); + EncoderProfiles getRecordingProfile() { + return cameraFeatures.getResolution().getRecordingProfile(); } /** Shortut to get deviceOrientationListener. */ diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java index 992396ab00a7..0fc0c1b0bc5d 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java @@ -25,8 +25,8 @@ public class ResolutionFeature extends CameraFeature { private Size captureSize; private Size previewSize; - private CamcorderProfile recordingProfile; - private EncoderProfiles recordingProfileOn31; + private CamcorderProfile recordingProfileLegacy; + private EncoderProfiles recordingProfile; private ResolutionPreset currentSetting; private int cameraId; @@ -56,12 +56,12 @@ public ResolutionFeature( * * @return Resolution information to configure the {@link android.hardware.camera2} API. */ - public CamcorderProfile getRecordingProfile() { - return this.recordingProfile; + public CamcorderProfile getRecordingProfileLegacy() { + return this.recordingProfileLegacy; } - public EncoderProfiles getRecordingProfileOn31() { - return this.recordingProfileOn31; + public EncoderProfiles getRecordingProfile() { + return this.recordingProfile; } /** @@ -117,21 +117,22 @@ static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) } if (Build.VERSION.SDK_INT >= 31) { EncoderProfiles profile = - getBestAvailableCamcorderProfileForResolutionPresetOn31(cameraId, preset); + getBestAvailableCamcorderProfileForResolutionPreset(cameraId, preset); List videoProfiles = profile.getVideoProfiles(); EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); return new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); } else { + @SuppressWarnings("deprecation") CamcorderProfile profile = - getBestAvailableCamcorderProfileForResolutionPreset(cameraId, preset); + getBestAvailableCamcorderProfileForResolutionPresetLegacy(cameraId, preset); return new Size(profile.videoFrameWidth, profile.videoFrameHeight); } } /** * Gets the best possible {@link android.media.CamcorderProfile} for the supplied {@link - * ResolutionPreset}. + * ResolutionPreset}. Supports SDK < 31. * * @param cameraId Camera identifier which indicates the device's camera for which to select a * {@link android.media.CamcorderProfile}. @@ -140,8 +141,7 @@ static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) * @return The best possible {@link android.media.CamcorderProfile} that matches the supplied * {@link ResolutionPreset}. */ - @SuppressWarnings("deprecation") - public static CamcorderProfile getBestAvailableCamcorderProfileForResolutionPreset( + public static CamcorderProfile getBestAvailableCamcorderProfileForResolutionPresetLegacy( int cameraId, ResolutionPreset preset) { if (cameraId < 0) { throw new AssertionError( @@ -185,7 +185,7 @@ public static CamcorderProfile getBestAvailableCamcorderProfileForResolutionPres } @TargetApi(Build.VERSION_CODES.S) - public static EncoderProfiles getBestAvailableCamcorderProfileForResolutionPresetOn31( + public static EncoderProfiles getBestAvailableCamcorderProfileForResolutionPreset( int cameraId, ResolutionPreset preset) { if (cameraId < 0) { throw new AssertionError( @@ -238,16 +238,19 @@ private void configureResolution(ResolutionPreset resolutionPreset, int cameraId } if (Build.VERSION.SDK_INT >= 31) { - recordingProfileOn31 = - getBestAvailableCamcorderProfileForResolutionPresetOn31(cameraId, resolutionPreset); - List videoProfiles = recordingProfileOn31.getVideoProfiles(); + recordingProfile = + getBestAvailableCamcorderProfileForResolutionPreset(cameraId, resolutionPreset); + List videoProfiles = recordingProfile.getVideoProfiles(); EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); captureSize = new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); } else { - recordingProfile = - getBestAvailableCamcorderProfileForResolutionPreset(cameraId, resolutionPreset); - captureSize = new Size(recordingProfile.videoFrameWidth, recordingProfile.videoFrameHeight); + @SuppressWarnings("deprecation") + CamcorderProfile camcorderProfile = + getBestAvailableCamcorderProfileForResolutionPresetLegacy(cameraId, resolutionPreset); + recordingProfileLegacy = camcorderProfile; + captureSize = + new Size(recordingProfileLegacy.videoFrameWidth, recordingProfileLegacy.videoFrameHeight); } previewSize = computeBestPreviewSize(cameraId, resolutionPreset); diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest_getRecordingProfileTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest_getRecordingProfileTest.java index 431124f54b98..04bab14f26ac 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest_getRecordingProfileTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/CameraTest_getRecordingProfileTest.java @@ -78,31 +78,31 @@ public void before() { @Config(maxSdk = 30) @Test - public void getRecordingProfile() { + public void getRecordingProfileLegacy() { ResolutionFeature mockResolutionFeature = mockCameraFeatureFactory.createResolutionFeature(mockCameraProperties, null, null); CamcorderProfile mockCamcorderProfile = mock(CamcorderProfile.class); - when(mockResolutionFeature.getRecordingProfile()).thenReturn(mockCamcorderProfile); + when(mockResolutionFeature.getRecordingProfileLegacy()).thenReturn(mockCamcorderProfile); - CamcorderProfile actualRecordingProfile = camera.getRecordingProfile(); + CamcorderProfile actualRecordingProfile = camera.getRecordingProfileLegacy(); - verify(mockResolutionFeature, times(1)).getRecordingProfile(); + verify(mockResolutionFeature, times(1)).getRecordingProfileLegacy(); assertEquals(mockCamcorderProfile, actualRecordingProfile); } @Config(minSdk = 31) @Test - public void getRecordingProfileOn31() { + public void getRecordingProfile() { ResolutionFeature mockResolutionFeature = mockCameraFeatureFactory.createResolutionFeature(mockCameraProperties, null, null); EncoderProfiles mockRecordingProfile = mock(EncoderProfiles.class); - when(mockResolutionFeature.getRecordingProfileOn31()).thenReturn(mockRecordingProfile); + when(mockResolutionFeature.getRecordingProfile()).thenReturn(mockRecordingProfile); - EncoderProfiles actualRecordingProfile = camera.getRecordingProfileOn31(); + EncoderProfiles actualRecordingProfile = camera.getRecordingProfile(); - verify(mockResolutionFeature, times(1)).getRecordingProfileOn31(); + verify(mockResolutionFeature, times(1)).getRecordingProfile(); assertEquals(mockRecordingProfile, actualRecordingProfile); } diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java index fc9b908f8ace..d1ea66f42faf 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java @@ -186,7 +186,7 @@ public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThroug assertEquals( mockProfileLow, - ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset( + ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPresetLegacy( 1, ResolutionPreset.max)); } @@ -217,7 +217,7 @@ public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThroug assertEquals( mockProfileLowOn31, - ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPresetOn31( + ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset( 1, ResolutionPreset.max)); } From 73040682765318d0483103747f66644b5f5786a2 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 25 Oct 2021 10:18:17 -0700 Subject: [PATCH 38/45] Removed unneeded annotation --- .../plugins/camera/features/resolution/ResolutionFeature.java | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java index 0fc0c1b0bc5d..cb431efe753e 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java @@ -108,7 +108,6 @@ public void updateBuilder(CaptureRequest.Builder requestBuilder) { // No-op: when setting a resolution there is no need to update the request builder. } - @SuppressWarnings("deprecation") @VisibleForTesting static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) throws IndexOutOfBoundsException { From 3f503771b76cc8ddcd45b7bbb361c4669b334841 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 25 Oct 2021 10:24:04 -0700 Subject: [PATCH 39/45] undo changes to other plugins --- .../connectivity/connectivity/example/android/app/build.gradle | 2 +- packages/connectivity/connectivity/example/android/build.gradle | 2 +- .../video_player/video_player/example/android/app/build.gradle | 2 +- .../android/app/gradle/wrapper/gradle-wrapper.properties | 2 +- packages/video_player/video_player/example/android/build.gradle | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/connectivity/connectivity/example/android/app/build.gradle b/packages/connectivity/connectivity/example/android/app/build.gradle index c9740ab1d5da..99e360558af8 100644 --- a/packages/connectivity/connectivity/example/android/app/build.gradle +++ b/packages/connectivity/connectivity/example/android/app/build.gradle @@ -53,7 +53,7 @@ flutter { dependencies { testImplementation 'junit:junit:4.13' - testImplementation 'org.robolectric:robolectric:4.6' + testImplementation 'org.robolectric:robolectric:4.4' testImplementation 'org.mockito:mockito-core:3.5.13' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' diff --git a/packages/connectivity/connectivity/example/android/build.gradle b/packages/connectivity/connectivity/example/android/build.gradle index 9971094448c3..c21bff8e0a2f 100644 --- a/packages/connectivity/connectivity/example/android/build.gradle +++ b/packages/connectivity/connectivity/example/android/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:7.0.2' + classpath 'com.android.tools.build:gradle:7.0.1' } } diff --git a/packages/video_player/video_player/example/android/app/build.gradle b/packages/video_player/video_player/example/android/app/build.gradle index 3b256040a951..5f1f3afa6352 100644 --- a/packages/video_player/video_player/example/android/app/build.gradle +++ b/packages/video_player/video_player/example/android/app/build.gradle @@ -59,7 +59,7 @@ flutter { dependencies { testImplementation 'junit:junit:4.13' - testImplementation 'org.robolectric:robolectric:4.6' + testImplementation 'org.robolectric:robolectric:4.4' testImplementation 'org.mockito:mockito-core:3.5.13' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' diff --git a/packages/video_player/video_player/example/android/app/gradle/wrapper/gradle-wrapper.properties b/packages/video_player/video_player/example/android/app/gradle/wrapper/gradle-wrapper.properties index 29e413457635..9a4163a4f5ee 100644 --- a/packages/video_player/video_player/example/android/app/gradle/wrapper/gradle-wrapper.properties +++ b/packages/video_player/video_player/example/android/app/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/packages/video_player/video_player/example/android/build.gradle b/packages/video_player/video_player/example/android/build.gradle index 9971094448c3..c21bff8e0a2f 100644 --- a/packages/video_player/video_player/example/android/build.gradle +++ b/packages/video_player/video_player/example/android/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:7.0.2' + classpath 'com.android.tools.build:gradle:7.0.1' } } From 5d6a93afc363f81b646aa3d83b9de14a0b5b01bd Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 25 Oct 2021 11:38:21 -0700 Subject: [PATCH 40/45] fix android platform test errors --- .../test/java/io/flutter/plugins/camera/DartMessengerTest.java | 2 +- .../sensororientation/DeviceOrientationManagerTest.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/DartMessengerTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/DartMessengerTest.java index 0a2fc43d03cb..e9084d28744f 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/DartMessengerTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/DartMessengerTest.java @@ -42,7 +42,7 @@ public void send(@NonNull String channel, ByteBuffer message, BinaryReply callba } @Override - public void setMessageHandler(@NonNull String channel, BinaryMessageHandler handler) {} + public void setMessageHandler(@NonNull String channel, BinaryMessageHandler handler, BinaryMessenger.TaskQueue TaskQueue) {} List getMessages() { return new ArrayList<>(sentMessages); diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java index 58f17cb758bf..82449a10188a 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java @@ -36,6 +36,7 @@ public class DeviceOrientationManagerTest { private DeviceOrientationManager deviceOrientationManager; @Before + @SuppressWarnings("deprecation") public void before() { mockActivity = mock(Activity.class); mockDartMessenger = mock(DartMessenger.class); From 1e266e04e6abe60882659e7fefc86c504ff41d77 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 25 Oct 2021 11:41:31 -0700 Subject: [PATCH 41/45] Remove undone changes from change logs --- packages/connectivity/connectivity/CHANGELOG.md | 1 - packages/video_player/video_player/CHANGELOG.md | 3 --- 2 files changed, 4 deletions(-) diff --git a/packages/connectivity/connectivity/CHANGELOG.md b/packages/connectivity/connectivity/CHANGELOG.md index c8347901499e..932565842efd 100644 --- a/packages/connectivity/connectivity/CHANGELOG.md +++ b/packages/connectivity/connectivity/CHANGELOG.md @@ -3,7 +3,6 @@ * Remove references to the Android V1 embedding. * Updated Android lint settings. * Specify Java 8 for Android build. -* Update gradle version to 7.0.2. ## 3.0.6 diff --git a/packages/video_player/video_player/CHANGELOG.md b/packages/video_player/video_player/CHANGELOG.md index 27fdf6b8d785..dd868414b2dd 100644 --- a/packages/video_player/video_player/CHANGELOG.md +++ b/packages/video_player/video_player/CHANGELOG.md @@ -1,6 +1,3 @@ -## 2.2.6 - -* Upgrade gradle version to 7.0.2. ## 2.2.5 From 2cf0c68890cf0d2c59901611ef924e337ffdff26 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 25 Oct 2021 13:03:21 -0700 Subject: [PATCH 42/45] undo changes to dart messenger --- .../test/java/io/flutter/plugins/camera/DartMessengerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/DartMessengerTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/DartMessengerTest.java index e9084d28744f..0a2fc43d03cb 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/DartMessengerTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/DartMessengerTest.java @@ -42,7 +42,7 @@ public void send(@NonNull String channel, ByteBuffer message, BinaryReply callba } @Override - public void setMessageHandler(@NonNull String channel, BinaryMessageHandler handler, BinaryMessenger.TaskQueue TaskQueue) {} + public void setMessageHandler(@NonNull String channel, BinaryMessageHandler handler) {} List getMessages() { return new ArrayList<>(sentMessages); From e745349d5ccbcb3bea917ffa76365010c2ad8ec8 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Thu, 28 Oct 2021 15:17:01 -0700 Subject: [PATCH 43/45] undo accidental changelog modification --- packages/video_player/video_player/CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/video_player/video_player/CHANGELOG.md b/packages/video_player/video_player/CHANGELOG.md index 02d0974a9229..9eb9d24679d0 100644 --- a/packages/video_player/video_player/CHANGELOG.md +++ b/packages/video_player/video_player/CHANGELOG.md @@ -1,4 +1,3 @@ - ## 2.2.6 * Initialize player when size and duration become available on iOS From 979a37fb87d7ee8a6c6a18c818f82d57310f75e3 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Fri, 29 Oct 2021 13:23:36 -0700 Subject: [PATCH 44/45] address nits --- .../resolution/ResolutionFeature.java | 1 - .../resolution/ResolutionFeatureTest.java | 44 +++++++++---------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java index cb431efe753e..afbd7c3758a6 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/resolution/ResolutionFeature.java @@ -229,7 +229,6 @@ public static EncoderProfiles getBestAvailableCamcorderProfileForResolutionPrese } } - @SuppressWarnings("deprecation") private void configureResolution(ResolutionPreset resolutionPreset, int cameraId) throws IndexOutOfBoundsException { if (!checkIsSupported()) { diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java index d1ea66f42faf..70f1e276d7f0 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java @@ -31,7 +31,7 @@ public class ResolutionFeatureTest { @Before @SuppressWarnings("deprecation") - public void before() { + public void beforeLegacy() { mockedStaticProfile = mockStatic(CamcorderProfile.class); mockProfileLow = mock(CamcorderProfile.class); CamcorderProfile mockProfile = mock(CamcorderProfile.class); @@ -81,7 +81,7 @@ public void before() { .thenReturn(mockProfileLow); } - public void beforeOn31() { + public void before() { mockProfileLowOn31 = mock(EncoderProfiles.class); EncoderProfiles mockProfileOn31 = mock(EncoderProfiles.class); EncoderProfiles.VideoProfile mockVideoProfile = mock(EncoderProfiles.VideoProfile.class); @@ -161,7 +161,7 @@ public void checkIsSupport_returnsTrue() { @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test - public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThrough() { + public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThroughLegacy() { mockedStaticProfile .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)) .thenReturn(false); @@ -192,7 +192,7 @@ public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThroug @Config(minSdk = 31) @Test - public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThroughOn31() { + public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThrough() { mockedStaticProfile .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)) .thenReturn(false); @@ -224,7 +224,7 @@ public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThroug @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test - public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetMax() { + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetMaxLegacy() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.max); mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); @@ -232,8 +232,8 @@ public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetMax() { @Config(minSdk = 31) @Test - public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetMaxOn31() { - beforeOn31(); + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetMax() { + before(); ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.max); mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); @@ -242,7 +242,7 @@ public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetMaxOn31() { @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test - public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetUltraHigh() { + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetUltraHighLegacy() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.ultraHigh); mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); @@ -250,8 +250,8 @@ public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetUltraHigh() @Config(minSdk = 31) @Test - public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetUltraHighOn31() { - beforeOn31(); + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetUltraHigh() { + before(); ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.ultraHigh); mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); @@ -260,7 +260,7 @@ public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetUltraHighOn3 @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test - public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetVeryHigh() { + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetVeryHighLegacy() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.veryHigh); mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); @@ -269,8 +269,8 @@ public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetVeryHigh() { @Config(minSdk = 31) @SuppressWarnings("deprecation") @Test - public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetVeryHighOn31() { - beforeOn31(); + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetVeryHigh() { + before(); ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.veryHigh); mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); @@ -279,7 +279,7 @@ public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetVeryHighOn31 @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test - public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetHigh() { + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetHighLegacy() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.high); mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)); @@ -287,8 +287,8 @@ public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetHigh() { @Config(minSdk = 31) @Test - public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetHighOn31() { - beforeOn31(); + public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetHigh() { + before(); ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.high); mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)); @@ -297,7 +297,7 @@ public void computeBestPreviewSize_shouldUse720PWhenResolutionPresetHighOn31() { @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test - public void computeBestPreviewSize_shouldUse480PWhenResolutionPresetMedium() { + public void computeBestPreviewSize_shouldUse480PWhenResolutionPresetMediumLegacy() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.medium); mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)); @@ -305,8 +305,8 @@ public void computeBestPreviewSize_shouldUse480PWhenResolutionPresetMedium() { @Config(minSdk = 31) @Test - public void computeBestPreviewSize_shouldUse480PWhenResolutionPresetMediumOn31() { - beforeOn31(); + public void computeBestPreviewSize_shouldUse480PWhenResolutionPresetMedium() { + before(); ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.medium); mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_480P)); @@ -315,7 +315,7 @@ public void computeBestPreviewSize_shouldUse480PWhenResolutionPresetMediumOn31() @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test - public void computeBestPreviewSize_shouldUseQVGAWhenResolutionPresetLow() { + public void computeBestPreviewSize_shouldUseQVGAWhenResolutionPresetLowLegacy() { ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.low); mockedStaticProfile.verify(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)); @@ -323,8 +323,8 @@ public void computeBestPreviewSize_shouldUseQVGAWhenResolutionPresetLow() { @Config(minSdk = 31) @Test - public void computeBestPreviewSize_shouldUseQVGAWhenResolutionPresetLowOn31() { - beforeOn31(); + public void computeBestPreviewSize_shouldUseQVGAWhenResolutionPresetLow() { + before(); ResolutionFeature.computeBestPreviewSize(1, ResolutionPreset.low); mockedStaticProfile.verify(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_QVGA)); From 11cc4e1acca3025a507e84a574ab0246576efe95 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Fri, 29 Oct 2021 15:22:45 -0700 Subject: [PATCH 45/45] rename on31s --- .../resolution/ResolutionFeatureTest.java | 46 +++++++++---------- .../media/MediaRecorderBuilderTest.java | 14 +++--- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java index 70f1e276d7f0..957b57a66435 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java @@ -25,16 +25,16 @@ @RunWith(RobolectricTestRunner.class) public class ResolutionFeatureTest { private static final String cameraName = "1"; - private CamcorderProfile mockProfileLow; - private EncoderProfiles mockProfileLowOn31; + private CamcorderProfile mockProfileLowLegacy; + private EncoderProfiles mockProfileLow; private MockedStatic mockedStaticProfile; @Before @SuppressWarnings("deprecation") public void beforeLegacy() { mockedStaticProfile = mockStatic(CamcorderProfile.class); - mockProfileLow = mock(CamcorderProfile.class); - CamcorderProfile mockProfile = mock(CamcorderProfile.class); + mockProfileLowLegacy = mock(CamcorderProfile.class); + CamcorderProfile mockProfileLegacy = mock(CamcorderProfile.class); mockedStaticProfile .when(() -> CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_HIGH)) @@ -60,56 +60,56 @@ public void beforeLegacy() { mockedStaticProfile .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_HIGH)) - .thenReturn(mockProfile); + .thenReturn(mockProfileLegacy); mockedStaticProfile .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_2160P)) - .thenReturn(mockProfile); + .thenReturn(mockProfileLegacy); mockedStaticProfile .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_1080P)) - .thenReturn(mockProfile); + .thenReturn(mockProfileLegacy); mockedStaticProfile .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_720P)) - .thenReturn(mockProfile); + .thenReturn(mockProfileLegacy); mockedStaticProfile .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_480P)) - .thenReturn(mockProfile); + .thenReturn(mockProfileLegacy); mockedStaticProfile .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_QVGA)) - .thenReturn(mockProfile); + .thenReturn(mockProfileLegacy); mockedStaticProfile .when(() -> CamcorderProfile.get(1, CamcorderProfile.QUALITY_LOW)) - .thenReturn(mockProfileLow); + .thenReturn(mockProfileLowLegacy); } public void before() { - mockProfileLowOn31 = mock(EncoderProfiles.class); - EncoderProfiles mockProfileOn31 = mock(EncoderProfiles.class); + mockProfileLow = mock(EncoderProfiles.class); + EncoderProfiles mockProfile = mock(EncoderProfiles.class); EncoderProfiles.VideoProfile mockVideoProfile = mock(EncoderProfiles.VideoProfile.class); List mockVideoProfilesList = List.of(mockVideoProfile); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_HIGH)) - .thenReturn(mockProfileOn31); + .thenReturn(mockProfile); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_2160P)) - .thenReturn(mockProfileOn31); + .thenReturn(mockProfile); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_1080P)) - .thenReturn(mockProfileOn31); + .thenReturn(mockProfile); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_720P)) - .thenReturn(mockProfileOn31); + .thenReturn(mockProfile); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_480P)) - .thenReturn(mockProfileOn31); + .thenReturn(mockProfile); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_QVGA)) - .thenReturn(mockProfileOn31); + .thenReturn(mockProfile); mockedStaticProfile .when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_LOW)) - .thenReturn(mockProfileLowOn31); + .thenReturn(mockProfileLow); - when(mockProfileOn31.getVideoProfiles()).thenReturn(mockVideoProfilesList); + when(mockProfile.getVideoProfiles()).thenReturn(mockVideoProfilesList); when(mockVideoProfile.getHeight()).thenReturn(100); when(mockVideoProfile.getWidth()).thenReturn(100); } @@ -185,7 +185,7 @@ public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThroug .thenReturn(true); assertEquals( - mockProfileLow, + mockProfileLowLegacy, ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPresetLegacy( 1, ResolutionPreset.max)); } @@ -216,7 +216,7 @@ public void getBestAvailableCamcorderProfileForResolutionPreset_shouldFallThroug .thenReturn(true); assertEquals( - mockProfileLowOn31, + mockProfileLow, ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset( 1, ResolutionPreset.max)); } diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java index 5e74ce949f45..6cc58ee823d9 100644 --- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java +++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java @@ -24,7 +24,7 @@ public class MediaRecorderBuilderTest { @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test - public void ctor_test() { + public void ctor_testLegacy() { MediaRecorderBuilder builder = new MediaRecorderBuilder(CamcorderProfile.get(CamcorderProfile.QUALITY_1080P), ""); @@ -33,7 +33,7 @@ public void ctor_test() { @Config(minSdk = 31) @Test - public void ctor_testOn31() { + public void ctor_test() { MediaRecorderBuilder builder = new MediaRecorderBuilder(CamcorderProfile.getAll("0", CamcorderProfile.QUALITY_1080P), ""); @@ -43,7 +43,7 @@ public void ctor_testOn31() { @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test - public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOException { + public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabledLegacy() throws IOException { CamcorderProfile recorderProfile = getEmptyCamcorderProfile(); MediaRecorderBuilder.MediaRecorderFactory mockFactory = mock(MediaRecorderBuilder.MediaRecorderFactory.class); @@ -75,7 +75,7 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOEx @Config(minSdk = 31) @Test - public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabledOn31() throws IOException { + public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOException { EncoderProfiles recorderProfile = mock(EncoderProfiles.class); List mockVideoProfiles = List.of(mock(EncoderProfiles.VideoProfile.class)); @@ -113,7 +113,7 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabledOn31() throws @Config(minSdk = 31) @Test(expected = IndexOutOfBoundsException.class) - public void build_shouldThrowExceptionWithoutVideoOrAudioProfilesOn31() throws IOException { + public void build_shouldThrowExceptionWithoutVideoOrAudioProfiles() throws IOException { EncoderProfiles recorderProfile = mock(EncoderProfiles.class); MediaRecorderBuilder.MediaRecorderFactory mockFactory = mock(MediaRecorderBuilder.MediaRecorderFactory.class); @@ -133,7 +133,7 @@ public void build_shouldThrowExceptionWithoutVideoOrAudioProfilesOn31() throws I @Config(maxSdk = 30) @SuppressWarnings("deprecation") @Test - public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOException { + public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabledLegacy() throws IOException { CamcorderProfile recorderProfile = getEmptyCamcorderProfile(); MediaRecorderBuilder.MediaRecorderFactory mockFactory = mock(MediaRecorderBuilder.MediaRecorderFactory.class); @@ -169,7 +169,7 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOExc @Config(minSdk = 31) @Test - public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabledOn31() throws IOException { + public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOException { EncoderProfiles recorderProfile = mock(EncoderProfiles.class); List mockVideoProfiles = List.of(mock(EncoderProfiles.VideoProfile.class));