Bug 1966310 - Use weak android symbol instead of dlopen/dlsym for AndroidPerformanceHintManager..cpp r=geckoview-reviewers,m_kato

Differential Revision: https://phabricator.services.mozilla.com/D249225
This commit is contained in:
serge-sans-paille
2025-05-16 07:04:52 +00:00
committed by sguelton@mozilla.com
parent 5c575caf38
commit 801ade11ce

View File

@@ -10,26 +10,18 @@
#include "AndroidBuild.h"
#include <dlfcn.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include <android/performance_hint.h>
typedef struct APerformanceHintManager APerformanceHintManager;
typedef struct APerformanceHintSession APerformanceHintSession;
namespace mozilla {
namespace hal_impl {
#define LOAD_FN(api, lib, name) \
do { \
api->m##name = reinterpret_cast<Fn##name>(dlsym(handle, #name)); \
if (!api->m##name) { \
HAL_ERR("Failed to load %s", #name); \
return nullptr; \
} \
} while (false)
class PerformanceHintManagerApi final {
public:
static PerformanceHintManagerApi* Get() {
@@ -73,20 +65,21 @@ class PerformanceHintManagerApi final {
return nullptr;
}
void* const handle = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL);
if (!handle) {
HAL_ERR("Failed to open libandroid.so");
return nullptr;
}
if (__builtin_available(android 33, *)) {
auto api = WrapUnique(new PerformanceHintManagerApi());
LOAD_FN(api, handle, APerformanceHint_getManager);
LOAD_FN(api, handle, APerformanceHint_createSession);
LOAD_FN(api, handle, APerformanceHint_updateTargetWorkDuration);
LOAD_FN(api, handle, APerformanceHint_reportActualWorkDuration);
LOAD_FN(api, handle, APerformanceHint_closeSession);
api->mAPerformanceHint_getManager = ::APerformanceHint_getManager;
api->mAPerformanceHint_createSession = ::APerformanceHint_createSession;
api->mAPerformanceHint_updateTargetWorkDuration =
::APerformanceHint_updateTargetWorkDuration;
api->mAPerformanceHint_reportActualWorkDuration =
::APerformanceHint_reportActualWorkDuration;
api->mAPerformanceHint_closeSession = ::APerformanceHint_closeSession;
return api;
} else {
HAL_ERR("Failed to load PerformanceHintManager symbols");
return nullptr;
}
}
using FnAPerformanceHint_getManager = APerformanceHintManager* (*)();