From 2bc50511221788bf6a5815f92a07d95380e3d8ad Mon Sep 17 00:00:00 2001 From: Michael Bestas Date: Sun, 10 Jan 2016 23:01:05 +0200 Subject: Snap: Fix NPE when parameters.getSupportedVideoSizes() is null * Older devices do not support parameters.getSupportedVideoSizes() * Assume that the device reports valid profiles in media_profiles * Remove dead code Change-Id: Ic3488b6762496bd9498bc6bf8b48b2a2212bad51 --- src/com/android/camera/CameraSettings.java | 124 +++++------------------------ 1 file changed, 22 insertions(+), 102 deletions(-) diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java index fd13ab7d5..e5ce122e1 100644 --- a/src/com/android/camera/CameraSettings.java +++ b/src/com/android/camera/CameraSettings.java @@ -435,7 +435,7 @@ public class CameraSettings { Context context, int cameraId, Parameters parameters) { // When launching the camera app first time, we will set the video quality // to the first one (i.e. highest quality) in the supported list - List supported = getSupportedVideoQualities(cameraId,parameters); + List supported = getSupportedVideoQualities(cameraId, parameters); assert (supported != null) : "No supported video quality is found"; for (String candidate : context.getResources().getStringArray( R.array.pref_video_quality_entryvalues)) { @@ -1025,7 +1025,7 @@ public class CameraSettings { if (videoQuality != null) { filterUnsupportedOptions(group, videoQuality, getSupportedVideoQualities( - mCameraId,mParameters)); + mCameraId, mParameters)); } if (videoEncoder != null) { @@ -1413,114 +1413,34 @@ public class CameraSettings { initialCameraPictureSize(context, parameters); writePreferredCameraId(preferences, currentCameraId); } - private static boolean checkSupportedVideoQuality(Parameters parameters,int width, int height){ - List supported = parameters.getSupportedVideoSizes(); - if (supported == null) { - // video-size not specified in parameter list. just go along with the profile. - return true; - } - int flag = 0; - for (Size size : supported){ - //since we are having two profiles with same height, we are checking with height - if (size.height == 480) { - if (size.height == height && size.width == width) { - flag = 1; - break; - } - } else { - if (size.width == width) { - flag = 1; - break; - } - } - } - if (flag == 1) - return true; - return false; - } - private static ArrayList getSupportedVideoQuality(int cameraId,Parameters parameters) { + public static ArrayList getSupportedVideoQualities(int cameraId, + Parameters parameters) { ArrayList supported = new ArrayList(); - // Check for supported quality - if (ApiHelper.HAS_FINE_RESOLUTION_QUALITY_LEVELS) { - getFineResolutionQuality(supported,cameraId,parameters); + List supportedVideoSizes = parameters.getSupportedVideoSizes(); + List videoSizes; + if (supportedVideoSizes == null) { + // video-size not specified in parameter list, + // assume all profiles in media_profiles are supported. + videoSizes = new ArrayList(); + videoSizes.add("4096x2160"); + videoSizes.add("3840x2160"); + videoSizes.add("1920x1080"); + videoSizes.add("1280x720"); + videoSizes.add("720x480"); + videoSizes.add("640x480"); + videoSizes.add("352x288"); + videoSizes.add("320x240"); + videoSizes.add("176x144"); } else { - supported.add(Integer.toString(CamcorderProfile.QUALITY_HIGH)); - CamcorderProfile high = CamcorderProfile.get( - cameraId, CamcorderProfile.QUALITY_HIGH); - CamcorderProfile low = CamcorderProfile.get( - cameraId, CamcorderProfile.QUALITY_LOW); - if (high.videoFrameHeight * high.videoFrameWidth > - low.videoFrameHeight * low.videoFrameWidth) { - supported.add(Integer.toString(CamcorderProfile.QUALITY_LOW)); - } - } - - return supported; - } - - @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) - private static void getFineResolutionQuality(ArrayList supported, - int cameraId,Parameters parameters) { - - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_4KDCI)) { - if (checkSupportedVideoQuality(parameters,4096,2160)) { - supported.add(Integer.toString(CamcorderProfile.QUALITY_4KDCI)); - } + videoSizes = sizeListToStringList(supportedVideoSizes); } - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_2160P)) { - if (checkSupportedVideoQuality(parameters,3840,2160)) { - supported.add(Integer.toString(CamcorderProfile.QUALITY_2160P)); - } - } - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P)) { - if (checkSupportedVideoQuality(parameters,1920,1080)){ - supported.add(Integer.toString(CamcorderProfile.QUALITY_1080P)); - } - } - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) { - if (checkSupportedVideoQuality(parameters,1280,720)){ - supported.add(Integer.toString(CamcorderProfile.QUALITY_720P)); - } - } - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) { - if (checkSupportedVideoQuality(parameters,720,480)){ - supported.add(Integer.toString(CamcorderProfile.QUALITY_480P)); - } - } - - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_VGA)) { - if (checkSupportedVideoQuality(parameters,640,480)){ - supported.add(Integer.toString(CamcorderProfile.QUALITY_VGA)); - } - } - - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_CIF)) { - if (checkSupportedVideoQuality(parameters,352,288)){ - supported.add(Integer.toString(CamcorderProfile.QUALITY_CIF)); - } - } - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_QVGA)) { - if (checkSupportedVideoQuality(parameters,320,240)){ - supported.add(Integer.toString(CamcorderProfile.QUALITY_QVGA)); - } - } - if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_QCIF)) { - if (checkSupportedVideoQuality(parameters,176,144)){ - supported.add(Integer.toString(CamcorderProfile.QUALITY_QCIF)); - } - } - } - - public static ArrayList getSupportedVideoQualities(int cameraId,Parameters parameters) { - ArrayList supported = new ArrayList(); - List temp = sizeListToStringList(parameters.getSupportedVideoSizes()); - for (String videoSize : temp) { + for (String videoSize : videoSizes) { if (VIDEO_QUALITY_TABLE.containsKey(videoSize)) { int profile = VIDEO_QUALITY_TABLE.get(videoSize); if (CamcorderProfile.hasProfile(cameraId, profile)) { - supported.add(videoSize); + supported.add(videoSize); } } } -- cgit v1.2.3