camera: update CameraModule

1. Add more accessor methods to CameraModule to prevent exposing
raw module pointer
2. Use KeyedVector to replace array

Bug: 19897963

Change-Id: I111cc093f09f5fb3c4b13693d5d0687e1f441058
diff --git a/services/camera/libcameraservice/common/CameraModule.cpp b/services/camera/libcameraservice/common/CameraModule.cpp
index 5f767ad..50cece4 100644
--- a/services/camera/libcameraservice/common/CameraModule.cpp
+++ b/services/camera/libcameraservice/common/CameraModule.cpp
@@ -54,14 +54,12 @@
     }
 
     mModule = module;
-    for (int i = 0; i < MAX_CAMERAS_PER_MODULE; i++) {
-        mCameraInfoCached[i] = false;
-    }
+    mCameraInfoMap.setCapacity(getNumberOfCameras());
 }
 
 int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) {
     Mutex::Autolock lock(mCameraInfoLock);
-    if (cameraId < 0 || cameraId >= MAX_CAMERAS_PER_MODULE) {
+    if (cameraId < 0) {
         ALOGE("%s: Invalid camera ID %d", __FUNCTION__, cameraId);
         return -EINVAL;
     }
@@ -72,21 +70,27 @@
         return mModule->get_camera_info(cameraId, info);
     }
 
-    camera_info &wrappedInfo = mCameraInfo[cameraId];
-    if (!mCameraInfoCached[cameraId]) {
+    ssize_t index = mCameraInfoMap.indexOfKey(cameraId);
+    if (index == NAME_NOT_FOUND) {
+        // Get camera info from raw module and cache it
+        CameraInfo cameraInfo;
         camera_info rawInfo;
         int ret = mModule->get_camera_info(cameraId, &rawInfo);
         if (ret != 0) {
             return ret;
         }
-        CameraMetadata &m = mCameraCharacteristics[cameraId];
+        CameraMetadata &m = cameraInfo.cameraCharacteristics;
         m = rawInfo.static_camera_characteristics;
         deriveCameraCharacteristicsKeys(rawInfo.device_version, m);
-        wrappedInfo = rawInfo;
-        wrappedInfo.static_camera_characteristics = m.getAndLock();
-        mCameraInfoCached[cameraId] = true;
+        cameraInfo.cameraInfo = rawInfo;
+        cameraInfo.cameraInfo.static_camera_characteristics = m.getAndLock();
+        mCameraInfoMap.add(cameraId, cameraInfo);
+        index = mCameraInfoMap.indexOfKey(cameraId);
     }
-    *info = wrappedInfo;
+
+    assert(index != NAME_NOT_FOUND);
+    // return the cached camera info
+    *info = mCameraInfoMap[index].cameraInfo;
     return 0;
 }
 
@@ -99,10 +103,6 @@
     return mModule->open_legacy(&mModule->common, id, halVersion, device);
 }
 
-const hw_module_t* CameraModule::getRawModule() {
-    return &mModule->common;
-}
-
 int CameraModule::getNumberOfCameras() {
     return mModule->get_number_of_cameras();
 }
@@ -125,7 +125,6 @@
     return mModule->set_torch_mode(camera_id, enable);
 }
 
-
 status_t CameraModule::filterOpenErrorCode(status_t err) {
     switch(err) {
         case NO_ERROR:
@@ -139,6 +138,25 @@
     return -ENODEV;
 }
 
+uint16_t CameraModule::getModuleApiVersion() {
+    return mModule->common.module_api_version;
+}
+
+const char* CameraModule::getModuleName() {
+    return mModule->common.name;
+}
+
+uint16_t CameraModule::getHalApiVersion() {
+    return mModule->common.hal_api_version;
+}
+
+const char* CameraModule::getModuleAuthor() {
+    return mModule->common.author;
+}
+
+void* CameraModule::getDso() {
+    return mModule->common.dso;
+}
 
 }; // namespace android