1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.camera.one.v1; 18 19import android.graphics.Rect; 20import android.hardware.Camera; 21 22import com.android.camera.one.OneCamera; 23import com.android.camera.one.OneCamera.Facing; 24import com.android.camera.one.OneCameraCharacteristics; 25import com.android.camera.ui.focus.LensRangeCalculator; 26import com.android.camera.ui.motion.LinearScale; 27import com.android.camera.util.ApiHelper; 28import com.android.camera.util.Size; 29 30import java.util.ArrayList; 31import java.util.List; 32 33/** 34 * Describes a OneCamera device which is on top of camera1 API. 35 */ 36public class OneCameraCharacteristicsImpl implements OneCameraCharacteristics { 37 private final Camera.CameraInfo mCameraInfo; 38 private final Camera.Parameters mCameraParameters; 39 40 /** The supported picture sizes. */ 41 private final ArrayList<Size> mSupportedPictureSizes = new ArrayList<Size>(); 42 43 /** The supported preview sizes. */ 44 private final ArrayList<Size> mSupportedPreviewSizes = new ArrayList<Size>(); 45 46 public OneCameraCharacteristicsImpl( 47 Camera.CameraInfo cameraInfo, Camera.Parameters cameraParameters) { 48 mCameraInfo = cameraInfo; 49 mCameraParameters = cameraParameters; 50 51 List<Camera.Size> supportedPictureSizes = cameraParameters.getSupportedPictureSizes(); 52 if (supportedPictureSizes != null) { 53 for (Camera.Size pictureSize : supportedPictureSizes) { 54 mSupportedPictureSizes.add(new Size(pictureSize)); 55 } 56 } 57 58 List<Camera.Size> supportedPreviewSizes = cameraParameters.getSupportedPreviewSizes(); 59 if (supportedPreviewSizes != null) { 60 for (Camera.Size previewSize : supportedPreviewSizes) { 61 mSupportedPreviewSizes.add(new Size(previewSize)); 62 } 63 } 64 } 65 66 @Override 67 public List<Size> getSupportedPictureSizes(int imageFormat) { 68 return mSupportedPictureSizes; 69 } 70 71 @Override 72 public List<Size> getSupportedPreviewSizes() { 73 return mSupportedPreviewSizes; 74 } 75 76 @Override 77 public int getSensorOrientation() { 78 return mCameraInfo.orientation; 79 } 80 81 @Override 82 public OneCamera.Facing getCameraDirection() { 83 int direction = mCameraInfo.facing; 84 if (direction == Camera.CameraInfo.CAMERA_FACING_BACK) { 85 return OneCamera.Facing.BACK; 86 } else { 87 return OneCamera.Facing.FRONT; 88 } 89 } 90 91 @Override 92 public Rect getSensorInfoActiveArraySize() { 93 throw new RuntimeException("Not implemented yet."); 94 } 95 96 @Override 97 public float getAvailableMaxDigitalZoom() { 98 throw new RuntimeException("Not implemented yet."); 99 } 100 101 @Override 102 public boolean isFlashSupported() { 103 return (mCameraParameters.getFlashMode() != null); 104 } 105 106 @Override 107 public boolean isHdrSceneSupported() { 108 return mCameraParameters.getSupportedSceneModes().contains( 109 Camera.Parameters.SCENE_MODE_HDR); 110 } 111 112 @Override 113 public SupportedHardwareLevel getSupportedHardwareLevel() { 114 throw new RuntimeException("Not implemented yet."); 115 } 116 117 @Override 118 public List<FaceDetectMode> getSupportedFaceDetectModes() { 119 List<FaceDetectMode> oneModes = new ArrayList<>(1); 120 oneModes.add(FaceDetectMode.NONE); 121 return oneModes; 122 } 123 124 @Override 125 public LinearScale getLensFocusRange() { 126 // Diopter range is not supported on legacy camera devices. 127 return LensRangeCalculator.getNoOp(); 128 } 129 130 @Override 131 public List<Float> getAvailableFocalLengths() { 132 List<Float> list = new ArrayList<>(1); 133 list.add(mCameraParameters.getFocalLength()); 134 return list; 135 } 136 137 @Override 138 public boolean isExposureCompensationSupported() { 139 // Turn off exposure compensation for Nexus 6 on L (API level 21) 140 // because the bug in framework b/19219128. 141 if (ApiHelper.IS_NEXUS_6 && ApiHelper.isLollipop()) { 142 return false; 143 } 144 return mCameraParameters.getMinExposureCompensation() != 0 || 145 mCameraParameters.getMaxExposureCompensation() != 0; 146 } 147 148 @Override 149 public int getMinExposureCompensation() { 150 if (!isExposureCompensationSupported()) { 151 return -1; 152 } 153 return mCameraParameters.getMinExposureCompensation(); 154 } 155 156 @Override 157 public int getMaxExposureCompensation() { 158 if (!isExposureCompensationSupported()) { 159 return -1; 160 } 161 return mCameraParameters.getMaxExposureCompensation(); 162 } 163 164 @Override 165 public float getExposureCompensationStep() { 166 if (!isExposureCompensationSupported()) { 167 return -1.0f; 168 } 169 return mCameraParameters.getExposureCompensationStep(); 170 } 171 172 @Override 173 public boolean isAutoFocusSupported() { 174 // Custom AF is only supported on the back camera for legacy devices. 175 return getCameraDirection() == Facing.BACK; 176 } 177 178 @Override 179 public boolean isAutoExposureSupported() { 180 // Custom AE is only supported on the back camera for legacy devices. 181 return getCameraDirection() == Facing.BACK; 182 } 183} 184