Home | History | Annotate | Download | only in device
      1 /*
      2  * Copyright (C) 2015 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.device;
     18 
     19 import android.content.Context;
     20 
     21 import com.android.camera.async.HandlerFactory;
     22 import com.android.camera.debug.Logger;
     23 import com.android.camera.device.CameraDeviceKey.ApiType;
     24 import com.android.ex.camera2.portability.CameraAgent.CameraProxy;
     25 import com.android.ex.camera2.portability.CameraAgentFactory.CameraApi;
     26 
     27 import java.util.concurrent.ExecutorService;
     28 
     29 /**
     30  * Provides a set of executable actions that can be used to open or close
     31  * a portability layer camera device object.
     32  */
     33 public class PortabilityCameraActionProvider implements CameraDeviceActionProvider<CameraProxy> {
     34     private final HandlerFactory mHandlerFactory;
     35     private final ExecutorService mBackgroundRunner;
     36     private final Context mAppContext;
     37     private final Logger.Factory mLogFactory;
     38 
     39     public PortabilityCameraActionProvider(HandlerFactory handlerFactory,
     40           ExecutorService backgroundRunner,
     41           Context appContext,
     42           Logger.Factory logFactory) {
     43 
     44         mHandlerFactory = handlerFactory;
     45         mBackgroundRunner = backgroundRunner;
     46         mAppContext = appContext;
     47         mLogFactory = logFactory;
     48     }
     49 
     50     @Override
     51     public SingleDeviceActions<CameraProxy> get(CameraDeviceKey key) {
     52         return new PortabilityCameraActions(key, mAppContext, getApiFromKey(key),
     53               mBackgroundRunner, mHandlerFactory, mLogFactory);
     54     }
     55 
     56     private CameraApi getApiFromKey(CameraDeviceKey key) {
     57         if (key.getApiType() == ApiType.CAMERA_API_PORTABILITY_API2) {
     58             return CameraApi.API_2;
     59         } else if (key.getApiType() == ApiType.CAMERA_API_PORTABILITY_API1) {
     60             return CameraApi.API_1;
     61         }
     62 
     63         return CameraApi.AUTO;
     64     }
     65 }
     66