| 178 | } |
| 179 | |
| 180 | size_t ASharedMemory_getSize(int fd) { |
| 181 | size_t size = 0; |
| 182 | #ifndef MMKV_OHOS |
| 183 | if (g_android_api >= __ANDROID_API_O__) { |
| 184 | static auto handle = loadLibrary(); |
| 185 | static AShmem_getSize_t funcPtr = |
| 186 | (handle != nullptr) ? reinterpret_cast<AShmem_getSize_t>(dlsym(handle, "ASharedMemory_getSize")) : nullptr; |
| 187 | if (funcPtr) { |
| 188 | size = funcPtr(fd); |
| 189 | if (size == 0) { |
| 190 | MMKVError("fail to ASharedMemory_getSize:%d, %s", fd, strerror(errno)); |
| 191 | } |
| 192 | } else { |
| 193 | MMKVWarning("fail to locate ASharedMemory_create() from loading libandroid.so"); |
| 194 | } |
| 195 | } |
| 196 | #endif |
| 197 | if (size == 0) { |
| 198 | int tmp = ioctl(fd, ASHMEM_GET_SIZE, nullptr); |
| 199 | if (tmp < 0) { |
| 200 | MMKVError("fail to get ashmem size:%d, %s", fd, strerror(errno)); |
| 201 | } else { |
| 202 | size = static_cast<size_t>(tmp); |
| 203 | } |
| 204 | } |
| 205 | return size; |
| 206 | } |
| 207 | |
| 208 | string ASharedMemory_getName(int fd) { |
| 209 | // Android Q doesn't have ASharedMemory_getName() |
no test coverage detected