0
0
mirror of https://git.code.sf.net/p/opencamera/code.git synced 2024-09-20 03:52:26 +02:00

New testTakePhotoVendorExtensions.

This commit is contained in:
Mark Harman 2024-04-13 10:50:08 +01:00
parent 0760ed9c24
commit 5406c08c1f
2 changed files with 127 additions and 9 deletions

View File

@ -14,6 +14,7 @@ import android.annotation.TargetApi;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.hardware.camera2.CameraExtensionCharacteristics;
import android.media.CamcorderProfile; import android.media.CamcorderProfile;
import android.os.Build; import android.os.Build;
import android.os.Looper; import android.os.Looper;
@ -41,6 +42,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
interface PhotoTests {} interface PhotoTests {}
@ -171,13 +173,15 @@ public class InstrumentedTest {
} }
} }
private void updateForSettings(MainActivity activity) { private void updateForSettings() {
Log.d(TAG, "updateForSettings"); Log.d(TAG, "updateForSettings");
assertEquals(Looper.getMainLooper().getThread(), Thread.currentThread()); // check on UI thread mActivityRule.getScenario().onActivity(activity -> {
// updateForSettings has code that must run on UI thread assertEquals(Looper.getMainLooper().getThread(), Thread.currentThread()); // check on UI thread
activity.initLocation(); // initLocation now called via MainActivity.setWindowFlagsForCamera() rather than updateForSettings() // updateForSettings has code that must run on UI thread
activity.getApplicationInterface().getDrawPreview().updateSettings(); activity.initLocation(); // initLocation now called via MainActivity.setWindowFlagsForCamera() rather than updateForSettings()
activity.updateForSettings(true); activity.getApplicationInterface().getDrawPreview().updateSettings();
activity.updateForSettings(true);
});
waitUntilCameraOpened(); // may need to wait if camera is reopened, e.g., when changing scene mode - see testSceneMode() waitUntilCameraOpened(); // may need to wait if camera is reopened, e.g., when changing scene mode - see testSceneMode()
// but we also need to wait for the delay if instead we've stopped and restarted the preview, the latter now only happens after dim_effect_time_c // but we also need to wait for the delay if instead we've stopped and restarted the preview, the latter now only happens after dim_effect_time_c
@ -6294,8 +6298,8 @@ public class InstrumentedTest {
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
editor.putString(PreferenceKeys.RemoveDeviceExifPreferenceKey, "preference_remove_device_exif_on"); editor.putString(PreferenceKeys.RemoveDeviceExifPreferenceKey, "preference_remove_device_exif_on");
editor.apply(); editor.apply();
updateForSettings(activity);
}); });
updateForSettings();
subTestTakePhoto(false, false, true, true, false, false, false, false); subTestTakePhoto(false, false, true, true, false, false, false, false);
@ -6325,8 +6329,8 @@ public class InstrumentedTest {
editor.putString(PreferenceKeys.RemoveDeviceExifPreferenceKey, "preference_remove_device_exif_on"); editor.putString(PreferenceKeys.RemoveDeviceExifPreferenceKey, "preference_remove_device_exif_on");
editor.putBoolean(PreferenceKeys.AutoStabilisePreferenceKey, true); editor.putBoolean(PreferenceKeys.AutoStabilisePreferenceKey, true);
editor.apply(); editor.apply();
updateForSettings(activity);
}); });
updateForSettings();
subTestTakePhoto(false, false, true, true, false, false, false, false); subTestTakePhoto(false, false, true, true, false, false, false, false);
@ -6354,8 +6358,8 @@ public class InstrumentedTest {
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
editor.putString(PreferenceKeys.RemoveDeviceExifPreferenceKey, "preference_remove_device_exif_keep_datetime"); editor.putString(PreferenceKeys.RemoveDeviceExifPreferenceKey, "preference_remove_device_exif_keep_datetime");
editor.apply(); editor.apply();
updateForSettings(activity);
}); });
updateForSettings();
subTestTakePhoto(false, false, true, true, false, false, false, false); subTestTakePhoto(false, false, true, true, false, false, false, false);
@ -6370,6 +6374,114 @@ public class InstrumentedTest {
}); });
} }
@Category(PhotoTests.class)
@Test
public void testTakePhotoVendorExtensions() throws InterruptedException {
Log.d(TAG, "testTakePhotoVendorExtensions");
setToDefault();
List<String> supported_extension_modes = new ArrayList<>();
mActivityRule.getScenario().onActivity(activity -> {
if( activity.supportsCameraExtension(CameraExtensionCharacteristics.EXTENSION_AUTOMATIC) )
supported_extension_modes.add("preference_photo_mode_x_auto");
if( activity.supportsCameraExtension(CameraExtensionCharacteristics.EXTENSION_HDR) )
supported_extension_modes.add("preference_photo_mode_x_hdr");
if( activity.supportsCameraExtension(CameraExtensionCharacteristics.EXTENSION_NIGHT) )
supported_extension_modes.add("preference_photo_mode_x_night");
if( activity.supportsCameraExtension(CameraExtensionCharacteristics.EXTENSION_BOKEH) )
supported_extension_modes.add("preference_photo_mode_x_bokeh");
if( activity.supportsCameraExtension(CameraExtensionCharacteristics.EXTENSION_BEAUTY) )
supported_extension_modes.add("preference_photo_mode_x_beauty");
});
if( supported_extension_modes.size() == 0 ) {
Log.d(TAG, "test requires camera extensions");
return;
}
boolean check_exif = true;
boolean is_samsung = Build.MANUFACTURER.toLowerCase(Locale.US).contains("samsung");
if( is_samsung && Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU ) {
// Samsung Galaxy S10e Android 12 doesn't store various exif tags with vendor extensions
// unclear if this is Samsung specific or Android version specific
check_exif = false;
}
for(String photo_mode : supported_extension_modes) {
mActivityRule.getScenario().onActivity(activity -> {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(activity);
SharedPreferences.Editor editor = settings.edit();
editor.putString(PreferenceKeys.PhotoModePreferenceKey, photo_mode);
editor.apply();
});
updateForSettings();
subTestTakePhoto(false, false, false, false, false, false, false, false);
if( check_exif ) {
mActivityRule.getScenario().onActivity(activity -> {
try {
TestUtils.testExif(activity, activity.test_last_saved_image, activity.test_last_saved_imageuri, true, true, false);
}
catch(IOException e) {
e.printStackTrace();
fail();
}
});
}
}
mActivityRule.getScenario().onActivity(activity -> {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(activity);
SharedPreferences.Editor editor = settings.edit();
editor.putString(PreferenceKeys.PhotoModePreferenceKey, "preference_photo_mode_std");
editor.apply();
});
updateForSettings();
if( getActivityValue(activity -> activity.getPreview().getCameraControllerManager().getNumberOfCameras()) > 1 ) {
Log.d(TAG, "test front camera");
mActivityRule.getScenario().onActivity(activity -> {
Log.d(TAG, "switch camera");
View switchCameraButton = activity.findViewById(net.sourceforge.opencamera.R.id.switch_camera);
clickView(switchCameraButton);
});
waitUntilCameraOpened();
for(String photo_mode : supported_extension_modes) {
mActivityRule.getScenario().onActivity(activity -> {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(activity);
SharedPreferences.Editor editor = settings.edit();
editor.putString(PreferenceKeys.PhotoModePreferenceKey, photo_mode);
editor.apply();
});
updateForSettings();
subTestTakePhoto(false, false, false, false, false, false, false, false);
if( check_exif ) {
mActivityRule.getScenario().onActivity(activity -> {
try {
TestUtils.testExif(activity, activity.test_last_saved_image, activity.test_last_saved_imageuri, true, true, false);
}
catch(IOException e) {
e.printStackTrace();
fail();
}
});
}
}
mActivityRule.getScenario().onActivity(activity -> {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(activity);
SharedPreferences.Editor editor = settings.edit();
editor.putString(PreferenceKeys.PhotoModePreferenceKey, "preference_photo_mode_std");
editor.apply();
});
updateForSettings();
}
}
private int getNFiles() { private int getNFiles() {
// count initial files in folder // count initial files in folder
String [] files = getActivityValue(activity -> TestUtils.filesInSaveFolder(activity)); String [] files = getActivityValue(activity -> TestUtils.filesInSaveFolder(activity));
@ -6575,6 +6687,7 @@ public class InstrumentedTest {
setToDefault(); setToDefault();
if( !getActivityValue(activity -> activity.getPreview().usingCamera2API()) ) { if( !getActivityValue(activity -> activity.getPreview().usingCamera2API()) ) {
Log.d(TAG, "test requires camera2 api");
return; return;
} }

View File

@ -12,6 +12,7 @@ import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.hardware.camera2.CameraExtensionCharacteristics;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
@ -1132,6 +1133,7 @@ public class TestUtils {
boolean is_expo = activity.supportsExpoBracketing() && sharedPreferences.getString(PreferenceKeys.PhotoModePreferenceKey, "preference_photo_mode_std").equals("preference_photo_mode_expo_bracketing"); boolean is_expo = activity.supportsExpoBracketing() && sharedPreferences.getString(PreferenceKeys.PhotoModePreferenceKey, "preference_photo_mode_std").equals("preference_photo_mode_expo_bracketing");
boolean is_focus_bracketing = activity.supportsFocusBracketing() && sharedPreferences.getString(PreferenceKeys.PhotoModePreferenceKey, "preference_photo_mode_std").equals("preference_photo_mode_focus_bracketing"); boolean is_focus_bracketing = activity.supportsFocusBracketing() && sharedPreferences.getString(PreferenceKeys.PhotoModePreferenceKey, "preference_photo_mode_std").equals("preference_photo_mode_focus_bracketing");
boolean is_fast_burst = activity.supportsFastBurst() && sharedPreferences.getString(PreferenceKeys.PhotoModePreferenceKey, "preference_photo_mode_std").equals("preference_photo_mode_fast_burst"); boolean is_fast_burst = activity.supportsFastBurst() && sharedPreferences.getString(PreferenceKeys.PhotoModePreferenceKey, "preference_photo_mode_std").equals("preference_photo_mode_fast_burst");
boolean is_x_night = activity.supportsCameraExtension(CameraExtensionCharacteristics.EXTENSION_NIGHT) && sharedPreferences.getString(PreferenceKeys.PhotoModePreferenceKey, "preference_photo_mode_std").equals("preference_photo_mode_x_night");
String n_expo_images_s = sharedPreferences.getString(PreferenceKeys.ExpoBracketingNImagesPreferenceKey, "3"); String n_expo_images_s = sharedPreferences.getString(PreferenceKeys.ExpoBracketingNImagesPreferenceKey, "3");
int n_expo_images = Integer.parseInt(n_expo_images_s); int n_expo_images = Integer.parseInt(n_expo_images_s);
String n_focus_bracketing_images_s = sharedPreferences.getString(PreferenceKeys.FocusBracketingNImagesPreferenceKey, "3"); String n_focus_bracketing_images_s = sharedPreferences.getString(PreferenceKeys.FocusBracketingNImagesPreferenceKey, "3");
@ -1168,6 +1170,9 @@ public class TestUtils {
//suffix = "_" + (n_fast_burst_images); // when burst numbering starts from _1 //suffix = "_" + (n_fast_burst_images); // when burst numbering starts from _1
max_time_s = 4; // takes longer to save 20 images! max_time_s = 4; // takes longer to save 20 images!
} }
else if( is_x_night ) {
suffix = "_Night";
}
if( is_raw ) { if( is_raw ) {
max_time_s += 6; // extra time needed for Nexus 6 at least max_time_s += 6; // extra time needed for Nexus 6 at least