diff --git a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp index cd3355714a24f1ded9fcd869614380ddcbebf189..55534d76bf17544f4daac0d45689b3efe5246775 100644 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp +++ b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp @@ -59,18 +59,24 @@ std::vector DCameraHandler::Query() DHLOGE("DCameraHandler::Query no camera device"); return itemList; } + std::map>> camMap; for (auto& info : cameraList) { if (info->GetConnectionType() != OHOS_CAMERA_CONNECTION_TYPE_BUILTIN) { DHLOGI("DCameraHandler::Query connection type: %d", info->GetConnectionType()); continue; } - if ((info->GetPosition() == OHOS_CAMERA_POSITION_OTHER) || - (info->GetPosition() == OHOS_CAMERA_POSITION_FRONT) || - (info->GetPosition() == OHOS_CAMERA_POSITION_BACK && - info->GetCameraType() == OHOS_CAMERA_TYPE_LOGICAL)) { - DHItem item = CreateDHItem(info); - itemList.emplace_back(item); + DHLOGI("DCameraHandler::Query get %s, position: %d, type: %d", GetAnonyString(info->GetID()).c_str(), + info->GetPosition(), info->GetCameraType()); + camMap[info->GetPosition()].emplace_back(info); + } + + for (auto iter = camMap.begin(); iter != camMap.end(); iter++) { + if(iter->second.size() == 0) { + continue; } + DHLOGI("DCameraHandler::Query CreateDHItem %s", GetAnonyString(iter->second.at(0)->GetID()).c_str()); + DHItem item = CreateDHItem(iter->second.at(0)); + itemList.emplace_back(item); } DHLOGI("DCameraHandler::Query success, get %d items", itemList.size()); return itemList; @@ -113,18 +119,23 @@ std::vector DCameraHandler::GetCameras() DHLOGE("DCameraHandler::GetCameras no camera device"); return cameras; } + std::map>> camMap; for (auto& info : cameraList) { if (info->GetConnectionType() != OHOS_CAMERA_CONNECTION_TYPE_BUILTIN) { DHLOGI("DCameraHandler::GetCameras connection type: %d", info->GetConnectionType()); continue; } - if ((info->GetPosition() == OHOS_CAMERA_POSITION_OTHER) || - (info->GetPosition() == OHOS_CAMERA_POSITION_FRONT) || - (info->GetPosition() == OHOS_CAMERA_POSITION_BACK && - info->GetCameraType() == OHOS_CAMERA_TYPE_LOGICAL)) { - std::string dhId = CAMERA_ID_PREFIX + info->GetID(); - cameras.emplace_back(dhId); + DHLOGI("DCameraHandler::GetCameras get %s, position: %d, type: %d", GetAnonyString(info->GetID()).c_str(), + info->GetPosition(), info->GetCameraType()); + camMap[info->GetPosition()].emplace_back(info); + } + + for (auto iter = camMap.begin(); iter != camMap.end(); iter++) { + if(iter->second.size() == 0) { + continue; } + std::string dhId = CAMERA_ID_PREFIX + iter->second.at(0)->GetID(); + cameras.emplace_back(dhId); } DHLOGI("DCameraHandler::GetCameras success, get %d items", cameras.size()); return cameras;