Camera: fix FlashLightTest

Fix issues related Treble HAL1 path.

Test: FlashLightTest pass on Angler HAL1/module 1.0
Bug: 35674539
Change-Id: I6bd749464c0e6e437a4743d2d66a0a5f54cdba38
diff --git a/services/camera/libcameraservice/common/CameraProviderManager.cpp b/services/camera/libcameraservice/common/CameraProviderManager.cpp
index 562e6c9..bbeeca6 100644
--- a/services/camera/libcameraservice/common/CameraProviderManager.cpp
+++ b/services/camera/libcameraservice/common/CameraProviderManager.cpp
@@ -22,7 +22,6 @@
 
 #include <chrono>
 #include <inttypes.h>
-#include <set>
 #include <hidl/ServiceManagement.h>
 
 namespace android {
@@ -96,8 +95,21 @@
     std::lock_guard<std::mutex> lock(mInterfaceMutex);
     std::vector<std::string> deviceIds;
     for (auto& provider : mProviders) {
-        for (auto& deviceInfo : provider->mDevices) {
-            deviceIds.push_back(deviceInfo->mId);
+        for (auto& id : provider->mUniqueCameraIds) {
+            deviceIds.push_back(id);
+        }
+    }
+    return deviceIds;
+}
+
+std::vector<std::string> CameraProviderManager::getStandardCameraDeviceIds() const {
+    std::lock_guard<std::mutex> lock(mInterfaceMutex);
+    std::vector<std::string> deviceIds;
+    for (auto& provider : mProviders) {
+        if (kStandardProviderTypes.find(provider->getType()) != std::string::npos) {
+            for (auto& id : provider->mUniqueCameraIds) {
+                deviceIds.push_back(id);
+            }
         }
     }
     return deviceIds;
@@ -182,6 +194,23 @@
     return OK;
 }
 
+bool CameraProviderManager::supportSetTorchMode(const std::string &id) {
+    std::lock_guard<std::mutex> lock(mInterfaceMutex);
+    bool support = false;
+    for (auto& provider : mProviders) {
+        auto deviceInfo = findDeviceInfoLocked(id);
+        if (deviceInfo != nullptr) {
+            provider->mInterface->isSetTorchModeSupported(
+                [&support](auto status, bool supported) {
+                    if (status == Status::OK) {
+                        support = supported;
+                    }
+                });
+        }
+    }
+    return support;
+}
+
 status_t CameraProviderManager::setTorchMode(const std::string &id, bool enabled) {
     std::lock_guard<std::mutex> lock(mInterfaceMutex);
 
@@ -472,11 +501,10 @@
         }
     }
 
-    std::set<std::string> uniqueCameraIds;
     for (auto& device : mDevices) {
-        uniqueCameraIds.insert(device->mId);
+        mUniqueCameraIds.insert(device->mId);
     }
-    mUniqueDeviceCount = uniqueCameraIds.size();
+    mUniqueDeviceCount = mUniqueCameraIds.size();
 
     ALOGI("Camera provider %s ready with %zu camera devices",
             mProviderName.c_str(), mDevices.size());
diff --git a/services/camera/libcameraservice/common/CameraProviderManager.h b/services/camera/libcameraservice/common/CameraProviderManager.h
index 04b9597..a388db5 100644
--- a/services/camera/libcameraservice/common/CameraProviderManager.h
+++ b/services/camera/libcameraservice/common/CameraProviderManager.h
@@ -18,6 +18,7 @@
 #define ANDROID_SERVERS_CAMERA_CAMERAPROVIDER_H
 
 #include <vector>
+#include <set>
 #include <string>
 #include <mutex>
 
@@ -133,6 +134,8 @@
 
     std::vector<std::string> getCameraDeviceIds() const;
 
+    std::vector<std::string> getStandardCameraDeviceIds() const;
+
     /**
      * Return true if a device with a given ID and major version exists
      */
@@ -170,8 +173,14 @@
             hardware::hidl_version *v);
 
     /**
+     * Check if a given camera device support setTorchMode API.
+     */
+    bool supportSetTorchMode(const std::string &id);
+
+    /**
      * Turn on or off the flashlight on a given camera device.
-     * May fail if the device is in active use, or if the device doesn't exist, etc.
+     * May fail if the device does not support this API, is in active use, or if the device
+     * doesn't exist, etc.
      */
     status_t setTorchMode(const std::string &id, bool enabled);
 
@@ -292,6 +301,7 @@
             static status_t setTorchMode(InterfaceT& interface, bool enabled);
         };
         std::vector<std::unique_ptr<DeviceInfo>> mDevices;
+        std::set<std::string> mUniqueCameraIds;
         int mUniqueDeviceCount;
 
         // HALv1-specific camera fields, including the actual device interface