ADPF: Fix the lock race issue for send hint.

When sending the POWER_EFFICIENCY hint, the existing implementation
runs into lock race which resulted in system hanging issue.

Bug: 379950145
Test: atest VtsHalPowerTargetTest
Flag: NONE powerhal doesn't have a tag yet.
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:6a20206cbb565fe968371a86eadf90ab4addf0e0)
Merged-In: I7803b15b877e0252928387d918b9095fa8cdd03a
Change-Id: I7803b15b877e0252928387d918b9095fa8cdd03a

Signed-off-by: Jis G Jacob <studiokeys@blissroms.org>
diff --git a/power-libperfmgr/aidl/PowerHintSession.cpp b/power-libperfmgr/aidl/PowerHintSession.cpp
index 89b2639..ef9c7f0 100644
--- a/power-libperfmgr/aidl/PowerHintSession.cpp
+++ b/power-libperfmgr/aidl/PowerHintSession.cpp
@@ -599,7 +599,7 @@
                                                                adpfConfig->mStaleTimeFactor / 2.0));
                 break;
             case SessionHint::POWER_EFFICIENCY:
-                setMode(SessionMode::POWER_EFFICIENCY, true);
+                setModeLocked(SessionMode::POWER_EFFICIENCY, true);
                 break;
             case SessionHint::GPU_LOAD_UP:
                 mPSManager->voteSet(mSessionId, AdpfVoteType::GPU_LOAD_UP,
@@ -634,6 +634,12 @@
 ndk::ScopedAStatus PowerHintSession<HintManagerT, PowerSessionManagerT>::setMode(SessionMode mode,
                                                                                  bool enabled) {
     std::scoped_lock lock{mPowerHintSessionLock};
+    return setModeLocked(mode, enabled);
+}
+
+template <class HintManagerT, class PowerSessionManagerT>
+ndk::ScopedAStatus PowerHintSession<HintManagerT, PowerSessionManagerT>::setModeLocked(
+        SessionMode mode, bool enabled) {
     if (mSessionClosed) {
         ALOGE("Error: session is dead");
         return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
diff --git a/power-libperfmgr/aidl/PowerHintSession.h b/power-libperfmgr/aidl/PowerHintSession.h
index 76ed887..c243f71 100644
--- a/power-libperfmgr/aidl/PowerHintSession.h
+++ b/power-libperfmgr/aidl/PowerHintSession.h
@@ -90,6 +90,8 @@
     void resetSessionHeuristicStates() REQUIRES(mPowerHintSessionLock);
     const std::shared_ptr<AdpfConfig> getAdpfProfile() const;
     ProcessTag getProcessTag(int32_t tgid);
+    ndk::ScopedAStatus setModeLocked(SessionMode mode, bool enabled)
+            REQUIRES(mPowerHintSessionLock);
 
     // Data
     PowerSessionManagerT *mPSManager;