diff --git a/hal/android/AndroidPerformanceHintManager.cpp b/hal/android/AndroidPerformanceHintManager.cpp index a9507a82724b..743ee602feb5 100644 --- a/hal/android/AndroidPerformanceHintManager.cpp +++ b/hal/android/AndroidPerformanceHintManager.cpp @@ -10,26 +10,18 @@ #include "AndroidBuild.h" -#include #include #include #include +#include + 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(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"); + if (__builtin_available(android 33, *)) { + auto api = WrapUnique(new PerformanceHintManagerApi()); + 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; } - - 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); - - return api; } using FnAPerformanceHint_getManager = APerformanceHintManager* (*)();