Add support for Android 11 RefBase ABI (#29)
Implements a compatibility layer to allow the binary to run on Android 11 (API 30) and older, which lack the `incStrongRequireStrong` symbol in their `libutils.so`. This is achieved by creating a runtime wrapper that checks the device's SDK version. - On Android 12 (API 31) and newer, it dynamically loads and calls the `incStrongRequireStrong` function using `dlsym`. - On older versions, it safely falls back to the universally available `incStrong` method. This resolves the fatal `dlopen` error "cannot locate symbol" when injecting the library into processes on older Android versions. See AOSP change https://android-review.googlesource.com/c/platform/system/core/+/1660499
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#ifndef ANDROID_STRONG_POINTER_H
|
||||
#define ANDROID_STRONG_POINTER_H
|
||||
|
||||
#include "refbase_compat.h"
|
||||
#include <functional>
|
||||
#include <type_traits> // for common_type.
|
||||
|
||||
@@ -212,7 +213,7 @@ sp<T> sp<T>::make(Args&&... args) {
|
||||
template <typename T>
|
||||
sp<T> sp<T>::fromExisting(T* other) {
|
||||
if (other) {
|
||||
other->incStrongRequireStrong(other);
|
||||
incStrongFromExisting(other, other);
|
||||
sp<T> result;
|
||||
result.m_ptr = other;
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user