HardwareSpecImpl.java revision b1641f5df0cf839b54385ea4d2e43521620fc237
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.hardware; 18 19import android.hardware.Camera; 20 21import com.android.camera.util.CameraUtil; 22import com.android.camera.util.GcamHelper; 23 24import java.util.List; 25 26/** 27 * HardwareSpecImpl is the default implementation of 28 * {@link com.android.camera.hardware.HardwareSpec} for 29 * a camera device opened using the {@link android.hardware.Camera} 30 * api. 31 */ 32public class HardwareSpecImpl implements HardwareSpec { 33 34 private final boolean mIsFrontCameraSupported; 35 private final boolean mIsHdrSupported; 36 private final boolean mIsHdrPlusSupported; 37 private final boolean mIsFlashSupported; 38 39 /** 40 * Compute the supported values for all 41 * {@link com.android.camera.hardware.HardwareSpec} methods 42 * based on {@link android.hardware.Camera.Parameters}. 43 */ 44 public HardwareSpecImpl(Camera.Parameters parameters) { 45 // Cache whether front camera is supported. 46 mIsFrontCameraSupported = (Camera.getNumberOfCameras() > 1); 47 48 // Cache whether hdr is supported. 49 mIsHdrSupported = CameraUtil.isCameraHdrSupported(parameters); 50 51 // Cache whether hdr plus is supported. 52 mIsHdrPlusSupported = GcamHelper.hasGcamCapture(); 53 54 // Cache whether flash is supported. 55 mIsFlashSupported = isFlashSupported(parameters); 56 } 57 58 @Override 59 public boolean isFrontCameraSupported() { 60 return mIsFrontCameraSupported; 61 } 62 63 @Override 64 public boolean isHdrSupported() { 65 return mIsHdrSupported; 66 } 67 68 @Override 69 public boolean isHdrPlusSupported() { 70 return mIsHdrPlusSupported; 71 } 72 73 @Override 74 public boolean isFlashSupported() { 75 return mIsFlashSupported; 76 } 77 78 /** 79 * Returns whether flash is supported and flash has more than 80 * one possible value. 81 */ 82 private boolean isFlashSupported(Camera.Parameters parameters) { 83 List<String> supportedFlashModes = parameters.getSupportedFlashModes(); 84 return !(supportedFlashModes == null || (supportedFlashModes.size() == 1)); 85 } 86}