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