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 java.util.Objects;
     20 
     21 import javax.annotation.concurrent.ThreadSafe;
     22 
     23 /**
     24  * Internal representation of a single camera device for a given API. Only one
     25  * device key may be active at any given time and other devices must be closed
     26  * before opening a new one.
     27  *
     28  * A single instance is considered equal if both API and provided cameraIds
     29  * match and the device key is suitable for use in hash maps. All values are
     30  * immutable.
     31  */
     32 @ThreadSafe
     33 final class CameraDeviceKey {
     34     /**
     35      * Unified set of supported types.
     36      */
     37     public enum ApiType {
     38         CAMERA_API1,
     39         CAMERA_API2,
     40         CAMERA_API_PORTABILITY_AUTO,
     41         CAMERA_API_PORTABILITY_API1,
     42         CAMERA_API_PORTABILITY_API2
     43     }
     44 
     45     private final ApiType mApiType;
     46     private final CameraId mCameraId;
     47 
     48     /**
     49      * @return the api type for this instances.
     50      */
     51     public ApiType getApiType() {
     52         return mApiType;
     53     }
     54 
     55     /**
     56      * @return the typed cameraId for this instances.
     57      */
     58     public CameraId getCameraId() {
     59         return mCameraId;
     60     }
     61 
     62     /**
     63      * Create a camera device key with an explicit API version.
     64      */
     65     public CameraDeviceKey(ApiType apiType, CameraId cameraId) {
     66         mApiType = apiType;
     67         mCameraId = cameraId;
     68     }
     69 
     70     @Override
     71     public String toString() {
     72         return "CameraDeviceKey{" +
     73               "mApiType: " + mApiType +
     74               ", mCameraId: " + mCameraId + "}";
     75     }
     76 
     77     @Override
     78     public boolean equals(Object o) {
     79         if (this == o) {
     80             return true;
     81         }
     82         if (o == null || getClass() != o.getClass()) {
     83             return false;
     84         }
     85 
     86         CameraDeviceKey other = (CameraDeviceKey) o;
     87 
     88         if (mApiType != other.mApiType) {
     89             return false;
     90         }
     91         if (!mCameraId.equals(other.mCameraId)) {
     92             return false;
     93         }
     94 
     95         return true;
     96     }
     97 
     98     @Override
     99     public int hashCode() {
    100         return Objects.hash(mApiType, mCameraId);
    101     }
    102 }
    103