Add lock guards to performance hint NDK

Test: atest PerformanceHintNativeTest
Bug: 343817997
Change-Id: Ic48949252be3122e2e13cfa5979f8831aea72a93
diff --git a/native/android/thermal.cpp b/native/android/thermal.cpp
index b43f2f16..f7a3537 100644
--- a/native/android/thermal.cpp
+++ b/native/android/thermal.cpp
@@ -99,21 +99,21 @@
       : mThermalSvc(std::move(service)), mServiceListener(nullptr) {}
 
 AThermalManager::~AThermalManager() {
-    std::unique_lock<std::mutex> listenerLock(mListenerMutex);
-
-    mListeners.clear();
-    if (mServiceListener != nullptr) {
-        bool success = false;
-        mThermalSvc->unregisterThermalStatusListener(mServiceListener, &success);
-        mServiceListener = nullptr;
+    {
+        std::scoped_lock<std::mutex> listenerLock(mListenerMutex);
+        mListeners.clear();
+        if (mServiceListener != nullptr) {
+            bool success = false;
+            mThermalSvc->unregisterThermalStatusListener(mServiceListener, &success);
+            mServiceListener = nullptr;
+        }
     }
-    listenerLock.unlock();
-    std::unique_lock<std::mutex> lock(mThresholdsMutex);
+    std::scoped_lock<std::mutex> lock(mThresholdsMutex);
     delete[] mThresholds;
 }
 
 status_t AThermalManager::notifyStateChange(int32_t status) {
-    std::unique_lock<std::mutex> lock(mListenerMutex);
+    std::scoped_lock<std::mutex> lock(mListenerMutex);
     AThermalStatus thermalStatus = static_cast<AThermalStatus>(status);
 
     for (auto listener : mListeners) {
@@ -123,7 +123,7 @@
 }
 
 status_t AThermalManager::addListener(AThermal_StatusCallback callback, void *data) {
-    std::unique_lock<std::mutex> lock(mListenerMutex);
+    std::scoped_lock<std::mutex> lock(mListenerMutex);
 
     if (callback == nullptr) {
         // Callback can not be nullptr
@@ -157,7 +157,7 @@
 }
 
 status_t AThermalManager::removeListener(AThermal_StatusCallback callback, void *data) {
-    std::unique_lock<std::mutex> lock(mListenerMutex);
+    std::scoped_lock<std::mutex> lock(mListenerMutex);
 
     auto it = std::remove_if(mListeners.begin(),
                              mListeners.end(),
@@ -216,7 +216,7 @@
 
 status_t AThermalManager::getThermalHeadroomThresholds(const AThermalHeadroomThreshold **result,
                                                        size_t *size) {
-    std::unique_lock<std::mutex> lock(mThresholdsMutex);
+    std::scoped_lock<std::mutex> lock(mThresholdsMutex);
     if (mThresholds == nullptr) {
         auto thresholds = std::make_unique<std::vector<float>>();
         binder::Status ret = mThermalSvc->getThermalHeadroomThresholds(thresholds.get());