diff --git a/android/build.gradle b/android/build.gradle index 8dea6a00e6..fbcc9e7afa 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -53,9 +53,9 @@ subprojects { } } ext { - compileSdkVersion=28 + compileSdkVersion=29 minSdkVersion=14 - targetSdkVersion=28 + targetSdkVersion=29 supportLibVersion="28.0.0" fastjsonLibVersion="1.1.70.android" //Default value for disableCov is false diff --git a/weex_core/Source/third_party/IPC/ashmem.c b/weex_core/Source/third_party/IPC/ashmem.c index 3c976edb56..d8755a6c76 100644 --- a/weex_core/Source/third_party/IPC/ashmem.c +++ b/weex_core/Source/third_party/IPC/ashmem.c @@ -16,11 +16,6 @@ * specific language governing permissions and limitations * under the License. */ -/* - * Implementation of the user-space ashmem API for devices, which have our - * ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version, - * used by the simulator. - */ #include #include @@ -31,9 +26,45 @@ #include "ashmem.h" #include +#include +#include +#include +#include #define ASHMEM_DEVICE "/dev/ashmem" +static int system_property_get_int(const char* name) { + int result = 0; + char value[PROP_VALUE_MAX] = {}; + if (__system_property_get(name, value) >= 1) + result = atoi(value); + return result; +} + +static int device_api_level() { + static int s_api_level = -1; + if (s_api_level < 0) + s_api_level = system_property_get_int("ro.build.version.sdk"); + return s_api_level; +} + +typedef int(*ASharedMemory_createFunc)(const char *, size_t); +typedef size_t(*ASharedMemory_getSizeFunc)(int fd); +typedef int(*ASharedMemory_setProtFunc)(int fd, int prot); + +// Function pointers to shared memory functions. +typedef struct { + ASharedMemory_createFunc create; + ASharedMemory_getSizeFunc getSize; + ASharedMemory_setProtFunc setProt; +} ASharedMemoryFuncs; + +static ASharedMemoryFuncs s_ashmem_funcs = { + NULL, NULL, NULL +}; +static pthread_once_t s_ashmem_funcs_once = PTHREAD_ONCE_INIT; + + /* * ashmem_create_region - creates a new ashmem region and returns the file * descriptor, or <0 on error @@ -41,7 +72,7 @@ * `name' is an optional label to give the region (visible in /proc/pid/maps) * `size' is the size of the region, in page-aligned bytes */ -int ashmem_create_region(const char* name, size_t size) +static int ashmem_dev_create_region(const char* name, size_t size) { int fd, ret; @@ -69,34 +100,56 @@ int ashmem_create_region(const char* name, size_t size) return ret; } -int ashmem_set_prot_region(int fd, int prot) +static int ashmem_dev_set_prot_region(int fd, int prot) { return ioctl(fd, ASHMEM_SET_PROT_MASK, prot); } -int ashmem_pin_region(int fd, size_t offset, size_t len) +static size_t ashmem_dev_get_size_region(int fd) { - struct ashmem_pin pin = { offset, len }; - return ioctl(fd, ASHMEM_PIN, &pin); + return (size_t)ioctl(fd, ASHMEM_GET_SIZE, NULL); } -int ashmem_unpin_region(int fd, size_t offset, size_t len) -{ - struct ashmem_pin pin = { offset, len }; - return ioctl(fd, ASHMEM_UNPIN, &pin); +static void ashmem_init_funcs() { + ASharedMemoryFuncs* funcs = &s_ashmem_funcs; + // ANDROID_API_Q + if (device_api_level() >= 29) { + void * lib = dlopen("libandroid.so", RTLD_NOW); + funcs->create = + (ASharedMemory_createFunc)dlsym(lib, "ASharedMemory_create"); + funcs->getSize = + (ASharedMemory_getSizeFunc)dlsym(lib, "ASharedMemory_getSize"); + funcs->setProt = + (ASharedMemory_setProtFunc)dlsym(lib, "ASharedMemory_setProt"); + } + + if(funcs->create == NULL) { + funcs->create = &ashmem_dev_create_region; + } + if(funcs->getSize == NULL) { + funcs->getSize = &ashmem_dev_get_size_region; + } + if(funcs->setProt == NULL) { + funcs->setProt = &ashmem_dev_set_prot_region; + } } -int ashmem_get_size_region(int fd) -{ - return ioctl(fd, ASHMEM_GET_SIZE, NULL); +static const ASharedMemoryFuncs* ashmem_get_funcs() { + pthread_once(&s_ashmem_funcs_once, ashmem_init_funcs); + return &s_ashmem_funcs; } -int ashmem_purge_all(void) +int ashmem_create_region(const char *name, size_t size) + { + return ashmem_get_funcs()->create(name, size); +} + +int ashmem_set_prot_region(int fd, int prot) { - const int fd = open(ASHMEM_DEVICE, O_RDWR); - if (fd < 0) - return fd; - const int ret = ioctl(fd, ASHMEM_PURGE_ALL_CACHES, 0); - close(fd); - return ret; + return ashmem_get_funcs()->setProt(fd, prot); } + +int ashmem_get_size_region(int fd) +{ + return (int)ashmem_get_funcs()->getSize(fd); +} \ No newline at end of file diff --git a/weex_core/Source/third_party/IPC/ashmem.h b/weex_core/Source/third_party/IPC/ashmem.h index cec94f1d92..20718e673f 100644 --- a/weex_core/Source/third_party/IPC/ashmem.h +++ b/weex_core/Source/third_party/IPC/ashmem.h @@ -33,10 +33,7 @@ extern "C" { int ashmem_create_region(const char* name, size_t size); int ashmem_set_prot_region(int fd, int prot); -int ashmem_pin_region(int fd, size_t offset, size_t len); -int ashmem_unpin_region(int fd, size_t offset, size_t len); int ashmem_get_size_region(int fd); -int ashmem_purge_all(void); #ifdef __cplusplus }