diff --git a/ipc/native/src/core/dbinder/include/dbinder_softbus_client.h b/ipc/native/src/core/dbinder/include/dbinder_softbus_client.h index f63351127a6df62692c38428503d4791f8b13608..4d69e3ff75a38c75cc49ada52573bdc278b6689e 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_softbus_client.h +++ b/ipc/native/src/core/dbinder/include/dbinder_softbus_client.h @@ -75,7 +75,9 @@ private: ShutdownFunc shutdownFunc_ = nullptr; std::mutex loadSoMutex_; + std::mutex permissionMutex_; std::atomic exitFlag_ = false; + std::atomic sessionRefCount_ = 0; bool isLoaded_ = false; void *soHandle_ = nullptr; }; diff --git a/ipc/native/src/core/dbinder/source/dbinder_softbus_client.cpp b/ipc/native/src/core/dbinder/source/dbinder_softbus_client.cpp index 1911756e669ba21760e915f48bbdcc126f345a65..66b29f176363f8cedcafedb149ead9745101f737 100644 --- a/ipc/native/src/core/dbinder/source/dbinder_softbus_client.cpp +++ b/ipc/native/src/core/dbinder/source/dbinder_softbus_client.cpp @@ -16,7 +16,7 @@ #include "dbinder_softbus_client.h" #include - +#include "ipc_types.h" #include "check_instance_exit.h" #include "ipc_debug.h" #include "log_tags.h" @@ -68,8 +68,11 @@ bool DBinderSoftbusClient::OpenSoftbusClientSo() int32_t DBinderSoftbusClient::DBinderGrantPermission(int32_t uid, int32_t pid, const std::string &socketName) { + std::lock_guard lockGuard(permissionMutex_); CHECK_INSTANCE_EXIT_WITH_RETVAL(exitFlag_, SOFTBUS_CLIENT_INSTANCE_EXIT); if (grantPermissionFunc_ != nullptr) { + sessionRefCount_++; + ZLOGI(LOG_LABEL, "refCount + 1 socketName:%{public}s", socketName.c_str()); return grantPermissionFunc_(uid, pid, socketName.c_str()); } @@ -82,14 +85,21 @@ int32_t DBinderSoftbusClient::DBinderGrantPermission(int32_t uid, int32_t pid, c ZLOGE(LOG_LABEL, "dlsym DBinderGrantPermission fail, err msg:%{public}s", dlerror()); return SOFTBUS_CLIENT_DLSYM_FAILED; } - + sessionRefCount_++; + ZLOGI(LOG_LABEL, "refCount + 1 socketName:%{public}s", socketName.c_str()); return grantPermissionFunc_(uid, pid, socketName.c_str()); } int32_t DBinderSoftbusClient::DBinderRemovePermission(const std::string &socketName) { + std::lock_guard lockGuard(permissionMutex_); CHECK_INSTANCE_EXIT_WITH_RETVAL(exitFlag_, SOFTBUS_CLIENT_INSTANCE_EXIT); if (removePermissionFunc_ != nullptr) { + if (sessionRefCount_ != 0) { + ZLOGI(LOG_LABEL, "refCount not 0 socketName:%{public}s", socketName.c_str()); + sessionRefCount_--; + return ERR_NONE; + } return removePermissionFunc_(socketName.c_str()); } @@ -102,7 +112,11 @@ int32_t DBinderSoftbusClient::DBinderRemovePermission(const std::string &socketN ZLOGE(LOG_LABEL, "dlsym DBinderRemovePermission fail, err msg:%{public}s", dlerror()); return SOFTBUS_CLIENT_DLSYM_FAILED; } - + if (sessionRefCount_ != 0) { + ZLOGI(LOG_LABEL, "refCount not 0 socketName:%{public}s", socketName.c_str()); + sessionRefCount_--; + return ERR_NONE; + } return removePermissionFunc_(socketName.c_str()); }