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 17 package com.android.camera.hardware; 18 19 import com.android.camera.app.CameraProvider; 20 import com.android.camera.one.OneCamera; 21 import com.android.camera.one.config.OneCameraFeatureConfig; 22 import com.android.camera.util.GcamHelper; 23 import com.android.ex.camera2.portability.CameraCapabilities; 24 25 /** 26 * HardwareSpecImpl is the default implementation of 27 * {@link com.android.camera.hardware.HardwareSpec} for 28 * a camera device opened using the {@link android.hardware.Camera} 29 * api. 30 */ 31 public class HardwareSpecImpl implements HardwareSpec { 32 33 private final boolean mIsFrontCameraSupported; 34 private final boolean mIsHdrSupported; 35 private final boolean mIsHdrPlusSupported; 36 private final boolean mIsFlashSupported; 37 38 /** 39 * Compute the supported values for all 40 * {@link com.android.camera.hardware.HardwareSpec} methods 41 */ HardwareSpecImpl(CameraProvider provider, CameraCapabilities capabilities, OneCameraFeatureConfig featureConfig, boolean isFrontCamera)42 public HardwareSpecImpl(CameraProvider provider, CameraCapabilities capabilities, 43 OneCameraFeatureConfig featureConfig, boolean isFrontCamera) { 44 // Cache whether front camera is supported. 45 mIsFrontCameraSupported = (provider.getFirstFrontCameraId() != -1); 46 47 // Cache whether hdr is supported. 48 mIsHdrSupported = capabilities.supports(CameraCapabilities.SceneMode.HDR); 49 50 // Cache whether hdr plus is supported. 51 OneCamera.Facing cameraFacing = 52 isFrontCamera ? OneCamera.Facing.FRONT : OneCamera.Facing.BACK; 53 mIsHdrPlusSupported = featureConfig.getHdrPlusSupportLevel(cameraFacing) != 54 OneCameraFeatureConfig.HdrPlusSupportLevel.NONE; 55 56 // Cache whether flash is supported. 57 mIsFlashSupported = isFlashSupported(capabilities); 58 } 59 60 @Override isFrontCameraSupported()61 public boolean isFrontCameraSupported() { 62 return mIsFrontCameraSupported; 63 } 64 65 @Override isHdrSupported()66 public boolean isHdrSupported() { 67 return mIsHdrSupported; 68 } 69 70 @Override isHdrPlusSupported()71 public boolean isHdrPlusSupported() { 72 return mIsHdrPlusSupported; 73 } 74 75 @Override isFlashSupported()76 public boolean isFlashSupported() { 77 return mIsFlashSupported; 78 } 79 80 /** 81 * Returns whether flash is supported and flash has more than 82 * one possible value. 83 */ isFlashSupported(CameraCapabilities capabilities)84 private boolean isFlashSupported(CameraCapabilities capabilities) { 85 return (capabilities.supports(CameraCapabilities.FlashMode.AUTO) || capabilities.supports 86 (CameraCapabilities.FlashMode.ON)); 87 } 88 } 89