Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bdcf9572 authored by Matt Buckley's avatar Matt Buckley
Browse files

Update PowerHAL wrapper support checking behavior

- Updates support checks to check status for UNKNOWN_TRANSACTION
- Adds PowerHintSessionWrapper class to check support on session methods
- Ensures that wrapper methods check the HAL version number for support
- Adds macros to cache returned wrapper call support status

Bug: 324255931
Test: atest libpowermanager_test
Test: atest libsurfaceflinger_unittest:PowerAdvisorTest
Change-Id: I624d8dc817aa187b816ccd4902ed0c60169821f8
parent a6499549
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -24,16 +24,17 @@
#include <nativehelper/JNIHelp.h>
#include <nativehelper/ScopedPrimitiveArray.h>
#include <powermanager/PowerHalController.h>
#include <powermanager/PowerHintSessionWrapper.h>
#include <utils/Log.h>

#include <unordered_map>

#include "jni.h"

using aidl::android::hardware::power::IPowerHintSession;
using aidl::android::hardware::power::SessionHint;
using aidl::android::hardware::power::SessionMode;
using aidl::android::hardware::power::WorkDuration;
using android::power::PowerHintSessionWrapper;

using android::base::StringPrintf;

@@ -49,7 +50,7 @@ static struct {
} gWorkDurationInfo;

static power::PowerHalController gPowerHalController;
static std::unordered_map<jlong, std::shared_ptr<IPowerHintSession>> gSessionMap;
static std::unordered_map<jlong, std::shared_ptr<PowerHintSessionWrapper>> gSessionMap;
static std::mutex gSessionMapLock;

static int64_t getHintSessionPreferredRate() {
@@ -76,45 +77,45 @@ static jlong createHintSession(JNIEnv* env, int32_t tgid, int32_t uid,
}

static void pauseHintSession(JNIEnv* env, int64_t session_ptr) {
    auto appSession = reinterpret_cast<IPowerHintSession*>(session_ptr);
    auto appSession = reinterpret_cast<PowerHintSessionWrapper*>(session_ptr);
    appSession->pause();
}

static void resumeHintSession(JNIEnv* env, int64_t session_ptr) {
    auto appSession = reinterpret_cast<IPowerHintSession*>(session_ptr);
    auto appSession = reinterpret_cast<PowerHintSessionWrapper*>(session_ptr);
    appSession->resume();
}

static void closeHintSession(JNIEnv* env, int64_t session_ptr) {
    auto appSession = reinterpret_cast<IPowerHintSession*>(session_ptr);
    auto appSession = reinterpret_cast<PowerHintSessionWrapper*>(session_ptr);
    appSession->close();
    std::unique_lock<std::mutex> sessionLock(gSessionMapLock);
    gSessionMap.erase(session_ptr);
}

static void updateTargetWorkDuration(int64_t session_ptr, int64_t targetDurationNanos) {
    auto appSession = reinterpret_cast<IPowerHintSession*>(session_ptr);
    auto appSession = reinterpret_cast<PowerHintSessionWrapper*>(session_ptr);
    appSession->updateTargetWorkDuration(targetDurationNanos);
}

static void reportActualWorkDuration(int64_t session_ptr,
                                     const std::vector<WorkDuration>& actualDurations) {
    auto appSession = reinterpret_cast<IPowerHintSession*>(session_ptr);
    auto appSession = reinterpret_cast<PowerHintSessionWrapper*>(session_ptr);
    appSession->reportActualWorkDuration(actualDurations);
}

static void sendHint(int64_t session_ptr, SessionHint hint) {
    auto appSession = reinterpret_cast<IPowerHintSession*>(session_ptr);
    auto appSession = reinterpret_cast<PowerHintSessionWrapper*>(session_ptr);
    appSession->sendHint(hint);
}

static void setThreads(int64_t session_ptr, const std::vector<int32_t>& threadIds) {
    auto appSession = reinterpret_cast<IPowerHintSession*>(session_ptr);
    auto appSession = reinterpret_cast<PowerHintSessionWrapper*>(session_ptr);
    appSession->setThreads(threadIds);
}

static void setMode(int64_t session_ptr, SessionMode mode, bool enabled) {
    auto appSession = reinterpret_cast<IPowerHintSession*>(session_ptr);
    auto appSession = reinterpret_cast<PowerHintSessionWrapper*>(session_ptr);
    appSession->setMode(mode, enabled);
}