ipc_core解耦dsoftbus,动态加载softbus_client

Signed-off-by: luodonghui <luodonghui@huawei.com>
Change-Id: Ic4f21de9b4fddabe3ba1fe3fb0c02e30909fb0f9
This commit is contained in:
luodonghui 2024-01-11 22:35:06 +08:00
parent 0fe088339c
commit a789457fee
38 changed files with 482 additions and 144 deletions

View File

@ -42,9 +42,20 @@ config("ipc_util_config") {
}
}
config("dsoftbus_header_deps_config") {
include_dirs = [
"//foundation/communication/dsoftbus/interfaces/kits/bus_center",
"//foundation/communication/dsoftbus/interfaces/kits/common",
"//foundation/communication/dsoftbus/interfaces/kits/discovery",
"//foundation/communication/dsoftbus/interfaces/kits/transport",
"//foundation/communication/dsoftbus/sdk/transmission/session/cpp/include",
]
}
group("ipc_components") {
if (os_level == "standard") {
deps = [
"$IPC_CORE_ROOT/src/core:dbinder_softbus_adaptor",
"$IPC_CORE_ROOT/src/core:ipc_common",
"$SUBSYSTEM_DIR/interfaces/innerkits/ipc_core:ipc_core",
"$SUBSYSTEM_DIR/interfaces/innerkits/ipc_single:ipc_single",

View File

@ -46,6 +46,7 @@ ohos_shared_library("ipc_core") {
"$IPC_CORE_ROOT/src/core/source/databus_session_callback.cpp",
"$IPC_CORE_ROOT/src/core/source/dbinder_callback_stub.cpp",
"$IPC_CORE_ROOT/src/core/source/dbinder_session_object.cpp",
"$IPC_CORE_ROOT/src/core/source/dbinder_softbus_client.cpp",
"$IPC_CORE_ROOT/src/core/source/ipc_file_descriptor.cpp",
"$IPC_CORE_ROOT/src/core/source/ipc_object_proxy.cpp",
"$IPC_CORE_ROOT/src/core/source/ipc_object_stub.cpp",
@ -60,7 +61,6 @@ ohos_shared_library("ipc_core") {
"$IPC_CORE_ROOT/src/core/source/message_parcel.cpp",
"$IPC_CORE_ROOT/src/core/source/peer_holder.cpp",
"$IPC_CORE_ROOT/src/core/source/stub_refcount_object.cpp",
"$IPC_CORE_ROOT/src/mock/source/binder_connector.cpp",
"$IPC_CORE_ROOT/src/mock/source/binder_debug.cpp",
"$IPC_CORE_ROOT/src/mock/source/binder_invoker.cpp",
"$IPC_CORE_ROOT/src/mock/source/dbinder_databus_invoker.cpp",
@ -73,7 +73,10 @@ ohos_shared_library("ipc_core") {
"$SUBSYSTEM_DIR:ipc_util_config",
":libipc_core_private_config",
]
public_configs = [ "$SUBSYSTEM_DIR:ipc_util_config" ]
public_configs = [
"$SUBSYSTEM_DIR:ipc_util_config",
"$SUBSYSTEM_DIR:dsoftbus_header_deps_config",
]
all_dependent_configs = [ ":ipc_all_deps_config" ]
@ -82,7 +85,6 @@ ohos_shared_library("ipc_core") {
external_deps = [
"access_token:libaccesstoken_sdk",
"c_utils:utils",
"dsoftbus:softbus_client",
"ffrt:libffrt",
"hilog:libhilog",
"hisysevent:libhisysevent",

View File

@ -45,7 +45,6 @@
OHOS::IPCProcessSkeleton*;
OHOS::DBinderDatabusInvoker*;
OHOS::BufferObject*;
OHOS::BinderConnector*;
OHOS::DatabusSessionCallback*;
OHOS::DBinderCallbackStub*;
OHOS::StubRefCountObject*;
@ -53,6 +52,7 @@
OHOS::IPCWorkThread*;
OHOS::DBinderSessionObject*;
OHOS::CommAuthInfo*;
OHOS::DBinderSoftbusClient*;
"vtable for OHOS::BinderInvoker";
"vtable for OHOS::DatabusSessionCallback";
"virtual thunk to OHOS::IPCObjectStub::~IPCObjectStub()";

View File

@ -50,7 +50,6 @@ ohos_shared_library("ipc_single") {
"$IPC_CORE_ROOT/src/core/source/message_option.cpp",
"$IPC_CORE_ROOT/src/core/source/message_parcel.cpp",
"$IPC_CORE_ROOT/src/core/source/peer_holder.cpp",
"$IPC_CORE_ROOT/src/mock/source/binder_connector.cpp",
"$IPC_CORE_ROOT/src/mock/source/binder_debug.cpp",
"$IPC_CORE_ROOT/src/mock/source/binder_invoker.cpp",
"$IPC_CORE_ROOT/src/mock/source/hitrace_invoker.cpp",

View File

@ -52,12 +52,14 @@ ohos_shared_library("libdbinder") {
"$DBINDER_ROOT/dbinder_service/src/dbinder_service_stub.cpp",
"$DBINDER_ROOT/dbinder_service/src/socket/dbinder_remote_listener.cpp",
]
public_configs = [ ":libdbinder_config" ]
public_configs = [
":libdbinder_config",
"$SUBSYSTEM_DIR:dsoftbus_header_deps_config",
]
configs = [ ":libdbinder_private_config" ]
deps = [ "$SUBSYSTEM_DIR/interfaces/innerkits/ipc_core:ipc_core" ]
external_deps = [
"c_utils:utils",
"dsoftbus:softbus_client",
"ffrt:libffrt",
"hilog:libhilog",
"hisysevent:libhisysevent",

View File

@ -12,8 +12,10 @@
# limitations under the License.
import("//build/ohos.gni")
import("../../../../config.gni")
SUBSYSTEM_DIR = "//foundation/communication/ipc"
IPC_CORE_ROOT = "$SUBSYSTEM_DIR/ipc/native"
config("libipc_common_private_config") {
cflags_cc = [ "-O2" ]
@ -27,7 +29,14 @@ ohos_shared_library("ipc_common") {
"$SUBSYSTEM_DIR/utils/include",
"include",
]
sources = [ "source/process_skeleton.cpp" ]
if (ipc_feature_actv_binder_enabled) {
include_dirs += [ "//third_party/json/single_include" ]
}
sources = [
"$IPC_CORE_ROOT/src/mock/source/binder_connector.cpp",
"source/process_skeleton.cpp",
]
configs = [
"$SUBSYSTEM_DIR:ipc_util_config",
@ -53,3 +62,19 @@ ohos_shared_library("ipc_common") {
subsystem_name = "communication"
part_name = "ipc"
}
ohos_shared_library("dbinder_softbus_adaptor") {
sanitize = {
integer_overflow = true
}
include_dirs = [ "$IPC_CORE_ROOT/src/core/include" ]
sources = [ "$IPC_CORE_ROOT/src/core/source/dbinder_softbus_adaptor.cpp" ]
external_deps = [ "dsoftbus:softbus_client" ]
innerapi_tags = [ "platformsdk_indirect" ]
install_images = [
system_base_dir,
updater_base_dir,
]
subsystem_name = "communication"
part_name = "ipc"
}

View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_IPC_CHECK_INSTANCE_EXIT_H
#define OHOS_IPC_CHECK_INSTANCE_EXIT_H
#define CHECK_INSTANCE_EXIT(flag) \
if (flag) { \
ZLOGW(LOG_LABEL, "instance is exiting"); \
return; \
}
#define CHECK_INSTANCE_EXIT_WITH_RETVAL(flag, retVal) \
if (flag) { \
ZLOGW(LOG_LABEL, "instance is exiting"); \
return retVal; \
}
#endif // OHOS_IPC_CHECK_INSTANCE_EXIT_H

View File

@ -0,0 +1,28 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_IPC_DBINDER_SOFTBUS_ADAPTOR_H
#define OHOS_IPC_DBINDER_SOFTBUS_ADAPTOR_H
#include <memory>
#include <string>
#include "ISessionService.h"
using Communication::SoftBus::ISessionService;
std::shared_ptr<ISessionService> GetSessionService() asm("GetSessionService");
std::string GetLocalDeviceId(const char *pkgName) asm("GetLocalDeviceId");
#endif // OHOS_IPC_DBINDER_SOFTBUS_ADAPTOR_H

View File

@ -0,0 +1,53 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_IPC_DBINDER_SOFTBUS_CLIENT_H
#define OHOS_IPC_DBINDER_SOFTBUS_CLIENT_H
#include <memory>
#include <mutex>
#include <string>
#include "ISessionService.h"
#include "nocopyable.h"
using Communication::SoftBus::ISessionService;
namespace OHOS {
class DBinderSoftbusClient {
public:
static DBinderSoftbusClient &GetInstance();
std::shared_ptr<ISessionService> GetSessionService();
std::string GetLocalDeviceId(const std::string &pkgName);
private:
DISALLOW_COPY_AND_MOVE(DBinderSoftbusClient);
DBinderSoftbusClient();
~DBinderSoftbusClient();
bool LoadSoftbusAdaptor();
private:
using GetSessionServiceFunc = std::shared_ptr<ISessionService>(*)();
using GetLocalDeviceIdFunc = std::string(*)(const char*);
GetSessionServiceFunc sessionServiceFunc_ = nullptr;
GetLocalDeviceIdFunc localDeviceIdFunc_ = nullptr;
std::atomic<bool> exitFlag_;
std::mutex loadSoMutex_;
std::shared_ptr<ISessionService> sessionManager_;
bool isLoaded_;
void *soHandle_;
};
} // namespace OHOS
#endif // OHOS_IPC_DBINDER_SOFTBUS_CLIENT_H

View File

@ -32,12 +32,7 @@
#include "comm_auth_info.h"
#include "dbinder_callback_stub.h"
#include "dbinder_session_object.h"
#include "ISessionService.h"
#include "Session.h"
#include "stub_refcount_object.h"
using Communication::SoftBus::ISessionService;
using Communication::SoftBus::Session;
#endif
namespace OHOS {

View File

@ -22,18 +22,6 @@
#include "iremote_object.h"
#define CHECK_INSTANCE_EXIT(flag) \
if (flag) { \
ZLOGW(LOG_LABEL, "instance is exiting"); \
return; \
}
#define CHECK_INSTANCE_EXIT_WITH_RETVAL(flag, retVal) \
if (flag) { \
ZLOGW(LOG_LABEL, "instance is exiting"); \
return retVal; \
}
namespace OHOS {
class ProcessSkeleton {
public:

View File

@ -15,13 +15,13 @@
#include "dbinder_session_object.h"
#include "dbinder_softbus_client.h"
#include "ipc_process_skeleton.h"
#include "ISessionService.h"
#include "ipc_debug.h"
#include "log_tags.h"
namespace OHOS {
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_RPC_SESSION_OBJ, "dbinder_session_object" };
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_RPC_SESSION_OBJ, "DBinderSessionObject" };
DBinderSessionObject::DBinderSessionObject(std::shared_ptr<Session> session, const std::string &serviceName,
const std::string &serverDeviceId, uint64_t stubIndex, IPCObjectProxy *proxy, uint32_t tokenId)
@ -37,8 +37,14 @@ DBinderSessionObject::~DBinderSessionObject()
void DBinderSessionObject::CloseDatabusSession()
{
std::shared_ptr<ISessionService> manager = ISessionService::GetInstance();
if (session_ != nullptr && manager != nullptr) {
auto &client = DBinderSoftbusClient::GetInstance();
auto manager = client.GetSessionService();
if (manager == nullptr) {
ZLOGE(LOG_LABEL, "GetSessionService fail");
return;
}
if (session_ != nullptr) {
ZLOGI(LOG_LABEL, "close softbus session, deviceId:%{public}s channelId:%{public}" PRId64,
IPCProcessSkeleton::ConvertToSecureString(session_->GetPeerDeviceId()).c_str(), session_->GetChannelId());
(void)manager->CloseSession(session_);

View File

@ -0,0 +1,34 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "dbinder_softbus_adaptor.h"
#include "softbus_bus_center.h"
std::shared_ptr<ISessionService> GetSessionService()
{
return ISessionService::GetInstance();
}
std::string GetLocalDeviceId(const char *pkgName)
{
if (pkgName == nullptr) {
return "";
}
NodeBasicInfo info;
if (GetLocalNodeDeviceInfo(pkgName, &info) != 0) {
return "";
}
return std::string(info.networkId);
}

View File

@ -0,0 +1,126 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "dbinder_softbus_client.h"
#include <cerrno>
#include <dlfcn.h>
#include "check_instance_exit.h"
#include "ipc_debug.h"
#include "ipc_process_skeleton.h"
#include "log_tags.h"
namespace OHOS {
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_RPC_DBINDER_SOFTBUS_CLIENT,
"DBinderSoftbusClient" };
#ifdef __aarch64__
static constexpr const char *SOFTBUS_ADAPTOR_PATH = "/system/lib64/platformsdk/";
#else
static constexpr const char *SOFTBUS_ADAPTOR_PATH = "/system/lib/platformsdk/";
#endif
static constexpr const char *SOFTBUS_ADAPTOR_NAME = "libdbinder_softbus_adaptor.z.so";
DBinderSoftbusClient &DBinderSoftbusClient::GetInstance()
{
static DBinderSoftbusClient instance;
return instance;
}
DBinderSoftbusClient::DBinderSoftbusClient() : exitFlag_(false), isLoaded_(false), soHandle_(nullptr)
{
}
DBinderSoftbusClient::~DBinderSoftbusClient()
{
exitFlag_ = true;
ZLOGI(LOG_LABEL, "destroy");
}
bool DBinderSoftbusClient::LoadSoftbusAdaptor()
{
CHECK_INSTANCE_EXIT_WITH_RETVAL(exitFlag_, false);
std::lock_guard<std::mutex> lockGuard(loadSoMutex_);
if (isLoaded_ && soHandle_ != nullptr) {
return true;
}
std::string path = std::string(SOFTBUS_ADAPTOR_PATH) + std::string(SOFTBUS_ADAPTOR_NAME);
soHandle_ = dlopen(path.c_str(), RTLD_NOW | RTLD_NODELETE);
if (soHandle_ == nullptr) {
ZLOGE(LOG_LABEL, "dlopen %{public}s failed, err:%{public}s", path.c_str(), dlerror());
return false;
}
isLoaded_ = true;
ZLOGI(LOG_LABEL, "dlopen %{public}s success", SOFTBUS_ADAPTOR_NAME);
return true;
}
std::shared_ptr<ISessionService> DBinderSoftbusClient::GetSessionService()
{
CHECK_INSTANCE_EXIT_WITH_RETVAL(exitFlag_, nullptr);
if (sessionManager_ != nullptr) {
return sessionManager_;
}
if (sessionServiceFunc_ != nullptr) {
sessionManager_ = sessionServiceFunc_();
return sessionManager_;
}
if (!LoadSoftbusAdaptor()) {
return nullptr;
}
sessionServiceFunc_ = (GetSessionServiceFunc)dlsym(soHandle_, "GetSessionService");
if (sessionServiceFunc_ == nullptr) {
ZLOGE(LOG_LABEL, "GetSessionServiceFunc fail, err:%{public}s", dlerror());
return nullptr;
}
sessionManager_ = sessionServiceFunc_();
if (sessionManager_ == nullptr) {
ZLOGE(LOG_LABEL, "GetSessionService fail");
return nullptr;
}
ZLOGD(LOG_LABEL, "success");
return sessionManager_;
}
std::string DBinderSoftbusClient::GetLocalDeviceId(const std::string &pkgName)
{
CHECK_INSTANCE_EXIT_WITH_RETVAL(exitFlag_, "");
if (localDeviceIdFunc_ != nullptr) {
return localDeviceIdFunc_(pkgName.c_str());
}
if (!LoadSoftbusAdaptor()) {
ZLOGE(LOG_LABEL, "LoadSoftbusAdaptor fail");
return "";
}
localDeviceIdFunc_ = (GetLocalDeviceIdFunc)dlsym(soHandle_, "GetLocalDeviceId");
if (localDeviceIdFunc_ == nullptr) {
ZLOGE(LOG_LABEL, "GetLocalDeviceIdFunc fail, err:%{public}s", dlerror());
return "";
}
std::string deviceId = localDeviceIdFunc_(pkgName.c_str());
if (deviceId.empty()) {
ZLOGE(LOG_LABEL, "failed, deviceId is empty");
return "";
}
ZLOGD(LOG_LABEL, "GetLocalDeviceId succ, deviceId:%{public}s",
IPCProcessSkeleton::ConvertToSecureString(deviceId).c_str());
return deviceId;
}
} // namespace OHOS

View File

@ -42,7 +42,7 @@
#ifndef CONFIG_IPC_SINGLE
#include "dbinder_databus_invoker.h"
#include "dbinder_error_code.h"
#include "ISessionService.h"
#include "dbinder_softbus_client.h"
#endif
namespace OHOS {
@ -612,18 +612,18 @@ int IPCObjectStub::GetPidUid(MessageParcel &data, MessageParcel &reply)
std::string IPCObjectStub::CreateSessionName(int uid, int pid)
{
std::shared_ptr<ISessionService> softbusManager = ISessionService::GetInstance();
if (softbusManager == nullptr) {
ZLOGE(LABEL, "fail to get softbus service");
auto &client = DBinderSoftbusClient::GetInstance();
auto manager = client.GetSessionService();
if (manager == nullptr) {
ZLOGE(LABEL, "GetSessionService fail");
return "";
}
}
std::string sessionName = "DBinder" + std::to_string(uid) + std::string("_") + std::to_string(pid);
if (softbusManager->GrantPermission(uid, pid, sessionName) != ERR_NONE) {
if (manager->GrantPermission(uid, pid, sessionName) != ERR_NONE) {
ZLOGE(LABEL, "fail to Grant Permission softbus name");
return "";
}
return sessionName;
}

View File

@ -20,6 +20,7 @@
#include <sys/epoll.h>
#include <unistd.h>
#include "check_instance_exit.h"
#include "ipc_debug.h"
#include "ipc_thread_skeleton.h"
#include "ipc_types.h"
@ -30,7 +31,7 @@
#ifndef CONFIG_IPC_SINGLE
#include "databus_session_callback.h"
#include "softbus_bus_center.h"
#include "dbinder_softbus_client.h"
#endif
namespace OHOS {
@ -161,11 +162,14 @@ IPCProcessSkeleton::~IPCProcessSkeleton()
#ifndef CONFIG_IPC_SINGLE
ClearDataResource();
std::shared_ptr<ISessionService> manager = ISessionService::GetInstance();
if (manager != nullptr) {
std::string pkgName = std::string(DBINDER_SERVER_PKG_NAME) + "_" + std::to_string(getpid());
(void)manager->RemoveSessionServer(pkgName, sessionName_);
auto &client = DBinderSoftbusClient::GetInstance();
auto manager = client.GetSessionService();
if (manager == nullptr) {
ZLOGE(LOG_LABEL, "GetSessionService fail");
return;
}
std::string pkgName = std::string(DBINDER_SERVER_PKG_NAME) + "_" + std::to_string(getpid());
(void)manager->RemoveSessionServer(pkgName, sessionName_);
#endif
}
@ -473,13 +477,8 @@ std::string IPCProcessSkeleton::GetLocalDeviceID()
std::lock_guard<std::mutex> lockGuard(databusProcMutex_);
std::string pkgName = std::string(DBINDER_SERVER_PKG_NAME) + "_" + std::to_string(getpid());
NodeBasicInfo nodeBasicInfo;
if (GetLocalNodeDeviceInfo(pkgName.c_str(), &nodeBasicInfo) != 0) {
ZLOGE(LOG_LABEL, "Get local node device info failed");
return "";
}
std::string networkId(nodeBasicInfo.networkId);
return networkId;
auto &client = DBinderSoftbusClient::GetInstance();
return client.GetLocalDeviceId(pkgName);
}
bool IPCProcessSkeleton::IsHandleMadeByUser(uint32_t handle)
@ -1185,9 +1184,10 @@ bool IPCProcessSkeleton::CreateSoftbusServer(const std::string &name)
return false;
}
std::shared_ptr<ISessionService> manager = ISessionService::GetInstance();
auto &client = DBinderSoftbusClient::GetInstance();
auto manager = client.GetSessionService();
if (manager == nullptr) {
ZLOGE(LOG_LABEL, "fail to get softbus manager");
ZLOGE(LOG_LABEL, "GetSessionService fail");
return false;
}
@ -1199,7 +1199,8 @@ bool IPCProcessSkeleton::CreateSoftbusServer(const std::string &name)
std::string pkgName = std::string(DBINDER_SERVER_PKG_NAME) + "_" + std::to_string(getpid());
int ret = manager->CreateSessionServer(pkgName, name, callback);
if (ret != 0) {
ZLOGE(LOG_LABEL, "CreateSessionServer fail, sessionName:%{public}s maybe created already", name.c_str());
ZLOGE(LOG_LABEL, "CreateSessionServer fail:%{public}d, sessionName:%{public}s maybe created already",
ret, name.c_str());
}
if (name != sessionName_) {

View File

@ -15,6 +15,7 @@
#include "process_skeleton.h"
#include "check_instance_exit.h"
#include "log_tags.h"
#include "ipc_debug.h"
#include "string_ex.h"

View File

@ -24,10 +24,6 @@
#endif
namespace OHOS {
#ifdef CONFIG_IPC_SINGLE
namespace IPC_SINGLE {
#endif
#ifdef CONFIG_ACTV_BINDER
typedef void (*ActvBinderJoinThreadFunc)(bool initiative);
typedef void (*ActvBinderSetHandlerInfoFunc)(uint32_t id);
@ -109,8 +105,5 @@ private:
ActvBinderConnector actvBinder_;
#endif
};
#ifdef CONFIG_IPC_SINGLE
} // namespace IPC_SINGLE
#endif
} // namespace OHOS
#endif // OHOS_IPC_BINDER_CONNECTOR_H

View File

@ -45,9 +45,6 @@
#endif
namespace OHOS {
#ifdef CONFIG_IPC_SINGLE
namespace IPC_SINGLE {
#endif
static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC_BINDER_CONNECT, "BinderConnector" };
std::mutex BinderConnector::skeletonMutex;
constexpr int SZ_1_M = 1048576;
@ -565,7 +562,4 @@ BinderConnector *BinderConnector::GetInstance()
return instance_;
}
#ifdef CONFIG_IPC_SINGLE
} // namespace IPC_SINGLE
#endif
} // namespace OHOS

View File

@ -26,6 +26,7 @@
#include "ipc_debug.h"
#include "log_tags.h"
#include "databus_session_callback.h"
#include "dbinder_softbus_client.h"
namespace OHOS {
using namespace OHOS::HiviewDFX;
@ -525,17 +526,19 @@ bool DBinderDatabusInvoker::UpdateClientSession(std::shared_ptr<DBinderSessionOb
return false;
}
std::shared_ptr<ISessionService> manager = ISessionService::GetInstance();
if (manager == nullptr) {
ZLOGE(LOG_LABEL, "fail to get softbus manager");
return false;
}
std::string sessionName = current->GetDatabusName();
if (sessionName.empty()) {
ZLOGE(LOG_LABEL, "fail to get session name");
return false;
}
auto &client = DBinderSoftbusClient::GetInstance();
auto manager = client.GetSessionService();
if (manager == nullptr) {
ZLOGE(LOG_LABEL, "GetSessionService fail");
return false;
}
std::shared_ptr<Session> session = manager->OpenSession(sessionName, sessionObject->GetServiceName(),
sessionObject->GetDeviceId(), std::string(""), Session::TYPE_BYTES);
if (session == nullptr) {
@ -549,7 +552,6 @@ bool DBinderDatabusInvoker::UpdateClientSession(std::shared_ptr<DBinderSessionOb
"channelId:%{public}" PRId64, sessionName.c_str(), sessionObject->GetServiceName().c_str(),
IPCProcessSkeleton::ConvertToSecureString(sessionObject->GetDeviceId()).c_str(),
session->GetChannelId());
return true;
}

View File

@ -22,7 +22,7 @@
#include "napi_rpc_error.h"
namespace OHOS {
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC_NAPI, "napi_ashmem" };
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC_NAPI, "NAPIAshmem" };
static constexpr int MMAP_PROT_MAX = NAPIAshmem::PROT_EXEC | NAPIAshmem::PROT_READ | NAPIAshmem::PROT_WRITE;
constexpr size_t BYTE_SIZE_32 = 4;

View File

@ -36,7 +36,7 @@ static const size_t ARGV_INDEX_1 = 1;
static const size_t ARGV_LENGTH_1 = 1;
static const size_t ARGV_LENGTH_2 = 2;
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC_NAPI, "napi_messageParcel" };
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC_NAPI, "NAPI_MessageParcel" };
#define CHECK_WRITE_CAPACITY(env, lenToWrite, napiParcel) \
do { \

View File

@ -33,7 +33,7 @@
#include "napi_process_skeleton.h"
namespace OHOS {
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC_NAPI, "napi_remoteObject" };
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC_NAPI, "NAPIRemoteObject" };
static const size_t ARGV_INDEX_0 = 0;
static const size_t ARGV_INDEX_1 = 1;

View File

@ -21,7 +21,7 @@
#include "log_tags.h"
namespace OHOS {
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC_NAPI, "napi_remoteObject_holder" };
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC_NAPI, "NAPIRemoteObjectHolder" };
static void OnEnvCleanUp(void *data)
{

View File

@ -24,7 +24,7 @@
#include "native_engine/native_value.h"
namespace OHOS {
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC_NAPI, "NapiRemoteProxyHolder" };
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC_NAPI, "NAPIRemoteProxyHolder" };
NAPIDeathRecipient::NAPIDeathRecipient(napi_env env, napi_value jsDeathRecipient)
{

View File

@ -18,7 +18,7 @@
#include "log_tags.h"
namespace OHOS {
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC_NAPI, "napi_rpc_error" };
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC_NAPI, "NapiError" };
std::map<int, errorInfo> NapiError::napiErrMap_ {
{CHECK_PARAM_ERROR, errorInfo{401, "check param error"}},

View File

@ -49,6 +49,7 @@ ohos_unittest("IPCNativeUnitTest") {
configs = [
"$SUBSYSTEM_DIR:ipc_util_config",
"$IPC_TEST_ROOT:ipc_test_config",
"$SUBSYSTEM_DIR:dsoftbus_header_deps_config",
]
deps = [
@ -85,6 +86,7 @@ ohos_unittest("IPCFileDescOpsTest") {
configs = [
"$SUBSYSTEM_DIR:ipc_util_config",
"$IPC_TEST_ROOT:ipc_test_config",
"$SUBSYSTEM_DIR:dsoftbus_header_deps_config",
]
deps = [
@ -112,9 +114,11 @@ ohos_unittest("BinderConnectorTest") {
configs = [
"$SUBSYSTEM_DIR:ipc_util_config",
"$IPC_TEST_ROOT:ipc_test_config",
"$SUBSYSTEM_DIR:dsoftbus_header_deps_config",
]
deps = [
"$IPC_CORE_ROOT/src/core:ipc_common",
"$IPC_TEST_ROOT/auxiliary/native:TestAssistance",
"//third_party/googletest:gtest_main",
]
@ -142,9 +146,11 @@ ohos_unittest("BinderInvokerUnitTest") {
configs = [
"$SUBSYSTEM_DIR:ipc_util_config",
"$IPC_TEST_ROOT:ipc_test_config",
"$SUBSYSTEM_DIR:dsoftbus_header_deps_config",
]
deps = [
"$IPC_CORE_ROOT/src/core:ipc_common",
"$IPC_TEST_ROOT/auxiliary/native:TestAssistance",
"//third_party/googletest:gtest_main",
]
@ -170,6 +176,7 @@ ohos_unittest("IPCHiTraceUnitTest") {
configs = [
"$SUBSYSTEM_DIR:ipc_util_config",
"$IPC_TEST_ROOT:ipc_test_config",
"$SUBSYSTEM_DIR:dsoftbus_header_deps_config",
]
deps = [
@ -229,6 +236,7 @@ ohos_unittest("IPCMockUnitTest") {
configs = [
"$SUBSYSTEM_DIR:ipc_util_config",
"$IPC_TEST_ROOT:ipc_test_config",
"$SUBSYSTEM_DIR:dsoftbus_header_deps_config",
]
deps = [
@ -263,6 +271,7 @@ ohos_unittest("InvokerFactoryTest") {
configs = [
"$SUBSYSTEM_DIR:ipc_util_config",
"$IPC_TEST_ROOT:ipc_test_config",
"$SUBSYSTEM_DIR:dsoftbus_header_deps_config",
]
deps = [
@ -298,6 +307,7 @@ ohos_unittest("RPCFeatureUnitTest") {
configs = [
"$SUBSYSTEM_DIR:ipc_util_config",
"$IPC_TEST_ROOT:ipc_test_config",
"$SUBSYSTEM_DIR:dsoftbus_header_deps_config",
]
deps = [
@ -356,6 +366,8 @@ ohos_unittest("IPCSoDlcloseTest") {
sources = [ "ipc_so_dlclose_unittest.cpp" ]
configs = [ "$SUBSYSTEM_DIR:dsoftbus_header_deps_config" ]
deps = [
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",

View File

@ -21,12 +21,10 @@
#include <mutex>
#include "dbinder_service.h"
#include "ISessionService.h"
#include "Session.h"
#include "ISessionListener.h"
using Communication::SoftBus::ISessionListener;
using Communication::SoftBus::ISessionService;
using Communication::SoftBus::Session;
namespace OHOS {
@ -69,7 +67,6 @@ private:
std::mutex resourceMutex_;
std::mutex serverSessionMutex_;
std::mutex deviceMutex_;
std::shared_ptr<ISessionService> softbusManager_;
sptr<DBinderService> dBinderService_;
std::map<std::string, std::shared_ptr<Session>> clientSessionMap_;
std::map<std::string, std::shared_ptr<Session>> serverSessionMap_;

View File

@ -23,6 +23,7 @@
#include "dbinder_log.h"
#include "dbinder_service_stub.h"
#include "dbinder_softbus_client.h"
#include "dbinder_remote_listener.h"
#include "dbinder_error_code.h"
#include "dbinder_sa_death_recipient.h"
@ -32,7 +33,7 @@
namespace OHOS {
using namespace Communication;
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_RPC_DBINDER_SER, "DbinderService" };
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_RPC_DBINDER_SER, "DBinderService" };
sptr<DBinderService> DBinderService::instance_ = nullptr;
bool DBinderService::mainThreadCreated_ = false;
@ -67,13 +68,8 @@ DBinderService::~DBinderService()
std::string DBinderService::GetLocalDeviceID()
{
std::string pkgName = "DBinderService";
NodeBasicInfo nodeBasicInfo;
if (GetLocalNodeDeviceInfo(pkgName.c_str(), &nodeBasicInfo) != 0) {
DBINDER_LOGE(LOG_LABEL, "Get local node device info failed");
return "";
}
std::string networkId(nodeBasicInfo.networkId);
return networkId;
auto &client = DBinderSoftbusClient::GetInstance();
return client.GetLocalDeviceId(pkgName);
}
bool DBinderService::StartDBinderService(std::shared_ptr<RpcSystemAbilityCallback> &callbackImpl)
@ -598,18 +594,18 @@ std::string DBinderService::GetDatabusNameByProxy(IPCObjectProxy *proxy)
std::string DBinderService::CreateDatabusName(int uid, int pid)
{
std::shared_ptr<ISessionService> softbusManager = ISessionService::GetInstance();
if (softbusManager == nullptr) {
DBINDER_LOGE(LOG_LABEL, "fail to get softbus service");
auto &client = DBinderSoftbusClient::GetInstance();
auto manager = client.GetSessionService();
if (manager == nullptr) {
DBINDER_LOGE(LOG_LABEL, "GetSessionService fail");
return "";
}
std::string sessionName = "DBinder" + std::to_string(uid) + std::string("_") + std::to_string(pid);
if (softbusManager->GrantPermission(uid, pid, sessionName) != ERR_NONE) {
if (manager->GrantPermission(uid, pid, sessionName) != ERR_NONE) {
DBINDER_LOGE(LOG_LABEL, "fail to Grant Permission softbus name");
return "";
}
return sessionName;
}

View File

@ -25,7 +25,7 @@
namespace OHOS {
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_RPC_DBINDER_SER_STUB,
"DbinderServiceStub" };
"DBinderServiceStub" };
DBinderServiceStub::DBinderServiceStub(const std::string &service, const std::string &device, binder_uintptr_t object)
: IPCObjectStub(Str8ToStr16(DBinderService::ConvertToSecureDeviceID(device) + service)),

View File

@ -19,10 +19,11 @@
#include "ipc_types.h"
#include "dbinder_log.h"
#include "dbinder_error_code.h"
#include "dbinder_softbus_client.h"
namespace OHOS {
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_RPC_REMOTE_LISTENER,
"DbinderRemoteListener" };
"DBinderRemoteListener" };
DBinderRemoteListener::DBinderRemoteListener(const sptr<DBinderService> &dBinderService)
: dBinderService_(dBinderService)
@ -38,21 +39,23 @@ DBinderRemoteListener::~DBinderRemoteListener()
bool DBinderRemoteListener::StartListener(std::shared_ptr<DBinderRemoteListener> &listener)
{
std::lock_guard<std::mutex> lockGuard(resourceMutex_);
softbusManager_ = ISessionService::GetInstance();
if (softbusManager_ == nullptr) {
DBINDER_LOGE(LOG_LABEL, "fail to get softbus service");
auto &client = DBinderSoftbusClient::GetInstance();
auto manager = client.GetSessionService();
if (manager == nullptr) {
DBINDER_LOGE(LOG_LABEL, "GetSessionService fail");
return false;
}
int pid = static_cast<int>(getpid());
int uid = static_cast<int>(getuid());
if (softbusManager_->GrantPermission(uid, pid, OWN_SESSION_NAME) != ERR_NONE) {
if (manager->GrantPermission(uid, pid, OWN_SESSION_NAME) != ERR_NONE) {
DBINDER_LOGE(LOG_LABEL, "fail to Grant Permission softbus name:%{public}s", OWN_SESSION_NAME.c_str());
return false;
}
int ret = softbusManager_->CreateSessionServer(OWN_SESSION_NAME, PEER_SESSION_NAME, listener);
int ret = manager->CreateSessionServer(OWN_SESSION_NAME, PEER_SESSION_NAME, listener);
if (ret != 0) {
DBINDER_LOGE(LOG_LABEL, "fail to create softbus server with ret:%{public}d", ret);
DBINDER_LOGE(LOG_LABEL, "CreateSessionServer fail, ret:%{public}d", ret);
return false;
}
return true;
@ -61,23 +64,25 @@ bool DBinderRemoteListener::StartListener(std::shared_ptr<DBinderRemoteListener>
bool DBinderRemoteListener::StopListener()
{
std::lock_guard<std::mutex> lockGuard(resourceMutex_);
if (softbusManager_ == nullptr) {
DBINDER_LOGE(LOG_LABEL, "softbus manager is null");
auto &client = DBinderSoftbusClient::GetInstance();
auto manager = client.GetSessionService();
if (manager == nullptr) {
DBINDER_LOGE(LOG_LABEL, "GetSessionService fail");
return false;
}
for (auto it = clientSessionMap_.begin(); it != clientSessionMap_.end(); it++) {
std::shared_ptr<Session> session = it->second;
if (session != nullptr) {
softbusManager_->CloseSession(session);
manager->CloseSession(session);
}
}
clientSessionMap_.clear();
int ret = softbusManager_->RemoveSessionServer(OWN_SESSION_NAME, PEER_SESSION_NAME);
int ret = manager->RemoveSessionServer(OWN_SESSION_NAME, PEER_SESSION_NAME);
if (ret != 0) {
DBINDER_LOGE(LOG_LABEL, "fail to remove softbus server");
return false;
}
softbusManager_ = nullptr;
return true;
}
@ -163,13 +168,16 @@ bool DBinderRemoteListener::SendDataReply(const std::string &deviceId, const str
bool DBinderRemoteListener::CloseDatabusSession(const std::string &deviceId)
{
std::lock_guard<std::mutex> lockGuard(resourceMutex_);
if (softbusManager_ == nullptr) {
DBINDER_LOGE(LOG_LABEL, "softbus manager is null");
auto &client = DBinderSoftbusClient::GetInstance();
auto manager = client.GetSessionService();
if (manager == nullptr) {
DBINDER_LOGE(LOG_LABEL, "GetSessionService fail");
return false;
}
auto it = clientSessionMap_.find(deviceId);
if (it != clientSessionMap_.end()) {
bool result = softbusManager_->CloseSession(it->second) == 0;
bool result = manager->CloseSession(it->second) == 0;
clientSessionMap_.erase(deviceId);
DBINDER_LOGI(LOG_LABEL, "device:%{public}s offline, close session result:%{public}d",
DBinderService::ConvertToSecureDeviceID(deviceId).c_str(), result);
@ -183,16 +191,19 @@ bool DBinderRemoteListener::CloseDatabusSession(const std::string &deviceId)
std::shared_ptr<Session> DBinderRemoteListener::OpenSoftbusSession(const std::string &peerDeviceId)
{
std::lock_guard<std::mutex> lockGuard(resourceMutex_);
if (softbusManager_ == nullptr) {
DBINDER_LOGE(LOG_LABEL, "softbus manager is null");
auto &client = DBinderSoftbusClient::GetInstance();
auto manager = client.GetSessionService();
if (manager == nullptr) {
DBINDER_LOGE(LOG_LABEL, "GetSessionService fail");
return nullptr;
}
auto it = clientSessionMap_.find(peerDeviceId);
if (it != clientSessionMap_.end()) {
return it->second;
}
std::shared_ptr<Session> session = softbusManager_->OpenSession(OWN_SESSION_NAME, PEER_SESSION_NAME,
std::shared_ptr<Session> session = manager->OpenSession(OWN_SESSION_NAME, PEER_SESSION_NAME,
peerDeviceId, std::string(""), Session::TYPE_BYTES);
if (session == nullptr) {
DBINDER_LOGE(LOG_LABEL, "open session for dbinder service failed, device:%{public}s",

View File

@ -86,7 +86,6 @@ ohos_distributedtest("DbinderTestAgent") {
external_deps = [
"c_utils:utils",
"dsoftbus:softbus_client",
"hilog:libhilog",
"samgr:samgr_proxy",
]

View File

@ -34,7 +34,6 @@ ohos_moduletest("RPCCLIENTTEST") {
external_deps = [
"c_utils:utils",
"dsoftbus:softbus_client",
"ipc:ipc_core",
"samgr:samgr_proxy",
]
@ -55,7 +54,6 @@ ohos_moduletest("RPCSERVERTEST") {
external_deps = [
"c_utils:utils",
"dsoftbus:softbus_client",
"ipc:ipc_core",
"samgr:samgr_proxy",
]

View File

@ -26,6 +26,7 @@ ohos_unittest("RPCDbinderTest") {
"//foundation/communication/dsoftbus/sdk/transmission/session/cpp/src",
"$SUBSYSTEM_DIR/interfaces/innerkits/ipc_core/include",
"$IPC_CORE_ROOT/c/rpc/include",
"$IPC_CORE_ROOT/test/unittest/common",
]
sources = [
@ -35,16 +36,16 @@ ohos_unittest("RPCDbinderTest") {
"dbinder_service_unittest.cpp",
]
configs = []
configs = [ "$SUBSYSTEM_DIR:dsoftbus_header_deps_config" ]
deps = [
"$SUBSYSTEM_DIR/interfaces/innerkits/ipc_core:ipc_core",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"c_utils:utils",
"dsoftbus:softbus_client",
"hilog:libhilog",
"ipc:libdbinder",
]

View File

@ -17,7 +17,6 @@
#include "gtest/gtest.h"
#include "rpc_log.h"
#include "log_tags.h"
#include "session_impl.h"
#define private public
#include "dbinder_death_recipient.h"
#undef private
@ -26,7 +25,6 @@ using namespace testing::ext;
using namespace OHOS;
using namespace OHOS::HiviewDFX;
using Communication::SoftBus::Session;
using Communication::SoftBus::SessionImpl;
class DbinderDeathRecipientUnitTest : public testing::Test {
public:

View File

@ -13,11 +13,13 @@
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "dbinder_service.h"
#include "gtest/gtest.h"
#include "rpc_log.h"
#include "log_tags.h"
#include "session_impl.h"
#include "mock_session_impl.h"
#define private public
#include "dbinder_remote_listener.h"
#undef private
@ -25,8 +27,9 @@
using namespace testing::ext;
using namespace OHOS;
using namespace OHOS::HiviewDFX;
using Communication::SoftBus::Session;
using Communication::SoftBus::SessionImpl;
const std::string TEST_SESSION_NAME = "DBinderService";
const std::string TEST_DEVICE_ID = "123";
class DBinderRemoteListenerUnitTest : public testing::Test {
public:
@ -48,24 +51,44 @@ void DBinderRemoteListenerUnitTest::TearDownTestCase() {}
HWTEST_F(DBinderRemoteListenerUnitTest, onsessionopened_001, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
std::shared_ptr<Session> session = std::make_shared<SessionImpl>();
std::shared_ptr<MockSessionImpl> session = std::make_shared<MockSessionImpl>();
EXPECT_CALL(*session, GetChannelId())
.WillRepeatedly(testing::Return(1));
std::string deviceId = "DeviceId";
EXPECT_CALL(*session, GetPeerSessionName())
.WillRepeatedly(testing::ReturnRef(deviceId));
EXPECT_CALL(*session, GetPeerDeviceId())
.WillRepeatedly(testing::ReturnRef(TEST_DEVICE_ID));
EXPECT_CALL(*session, IsServerSide())
.WillRepeatedly(testing::Return(false));
EXPECT_EQ(dBinderRemoteListener_.OnSessionOpened(session), -DBINDER_SERVICE_WRONG_SESSION);
}
HWTEST_F(DBinderRemoteListenerUnitTest, onsessionopened_002, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
std::shared_ptr<Session> session = std::make_shared<SessionImpl>();
const std::string name = "DBinderService";
session->SetPeerSessionName(name);
std::shared_ptr<MockSessionImpl> session = std::make_shared<MockSessionImpl>();
EXPECT_CALL(*session, GetChannelId())
.WillRepeatedly(testing::Return(1));
EXPECT_CALL(*session, GetPeerSessionName())
.WillRepeatedly(testing::ReturnRef(TEST_SESSION_NAME));
EXPECT_CALL(*session, GetPeerDeviceId())
.WillRepeatedly(testing::ReturnRef(TEST_DEVICE_ID));
EXPECT_CALL(*session, IsServerSide())
.WillRepeatedly(testing::Return(false));
EXPECT_EQ(dBinderRemoteListener_.OnSessionOpened(session), 0);
}
HWTEST_F(DBinderRemoteListenerUnitTest, onsessionclosed_001, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
std::shared_ptr<Session> session = std::make_shared<SessionImpl>();
session->SetIsServer(true);
std::shared_ptr<MockSessionImpl> session = std::make_shared<MockSessionImpl>();
EXPECT_CALL(*session, GetChannelId())
.WillRepeatedly(testing::Return(1));
EXPECT_CALL(*session, GetPeerDeviceId())
.WillRepeatedly(testing::ReturnRef(TEST_DEVICE_ID));
EXPECT_CALL(*session, IsServerSide())
.WillRepeatedly(testing::Return(true));
dBinderRemoteListener_.OnSessionClosed(session);
EXPECT_EQ(session->IsServerSide(), true);
}
@ -73,8 +96,13 @@ HWTEST_F(DBinderRemoteListenerUnitTest, onsessionclosed_001, TestSize.Level1)
HWTEST_F(DBinderRemoteListenerUnitTest, onsessionclosed_002, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
std::shared_ptr<Session> session = std::make_shared<SessionImpl>();
session->SetIsServer(false);
std::shared_ptr<MockSessionImpl> session = std::make_shared<MockSessionImpl>();
EXPECT_CALL(*session, GetChannelId())
.WillRepeatedly(testing::Return(1));
EXPECT_CALL(*session, GetPeerDeviceId())
.WillRepeatedly(testing::ReturnRef(TEST_DEVICE_ID));
EXPECT_CALL(*session, IsServerSide())
.WillRepeatedly(testing::Return(false));
dBinderRemoteListener_.OnSessionClosed(session);
EXPECT_EQ(session->IsServerSide(), false);
}
@ -82,7 +110,13 @@ HWTEST_F(DBinderRemoteListenerUnitTest, onsessionclosed_002, TestSize.Level1)
HWTEST_F(DBinderRemoteListenerUnitTest, onbytesreceived_001, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
std::shared_ptr<Session> session = std::make_shared<SessionImpl>();
std::shared_ptr<MockSessionImpl> session = std::make_shared<MockSessionImpl>();
EXPECT_CALL(*session, GetChannelId())
.WillRepeatedly(testing::Return(1));
EXPECT_CALL(*session, GetPeerSessionName())
.WillRepeatedly(testing::ReturnRef(TEST_SESSION_NAME));
EXPECT_CALL(*session, GetPeerDeviceId())
.WillRepeatedly(testing::ReturnRef(TEST_DEVICE_ID));
const char* data = nullptr;
auto len = sizeof(struct DHandleEntryTxRx);
dBinderRemoteListener_.OnBytesReceived(session, data, len);
@ -92,7 +126,13 @@ HWTEST_F(DBinderRemoteListenerUnitTest, onbytesreceived_001, TestSize.Level1)
HWTEST_F(DBinderRemoteListenerUnitTest, onbytesreceived_002, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
std::shared_ptr<Session> session = std::make_shared<SessionImpl>();
std::shared_ptr<MockSessionImpl> session = std::make_shared<MockSessionImpl>();
EXPECT_CALL(*session, GetChannelId())
.WillRepeatedly(testing::Return(1));
EXPECT_CALL(*session, GetPeerSessionName())
.WillRepeatedly(testing::ReturnRef(TEST_SESSION_NAME));
EXPECT_CALL(*session, GetPeerDeviceId())
.WillRepeatedly(testing::ReturnRef(TEST_DEVICE_ID));
const char *data = "testdatas";
ssize_t len = 0;
dBinderRemoteListener_.OnBytesReceived(session, data, len);
@ -152,14 +192,12 @@ HWTEST_F(DBinderRemoteListenerUnitTest, startlistener_002, TestSize.Level1)
HWTEST_F(DBinderRemoteListenerUnitTest, StopListener_001, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
dBinderRemoteListener_.softbusManager_ = nullptr;
EXPECT_EQ(dBinderRemoteListener_.StopListener(), false);
}
HWTEST_F(DBinderRemoteListenerUnitTest, StopListener_002, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
dBinderRemoteListener_.softbusManager_ = ISessionService::GetInstance();
EXPECT_EQ(dBinderRemoteListener_.StopListener(), false);
}
@ -174,7 +212,6 @@ HWTEST_F(DBinderRemoteListenerUnitTest, closedatabussession_002, TestSize.Level1
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
const std::string deviceId = "123";
dBinderRemoteListener_.softbusManager_ = ISessionService::GetInstance();
EXPECT_EQ(dBinderRemoteListener_.CloseDatabusSession(deviceId), false);
}
@ -218,7 +255,6 @@ HWTEST_F(DBinderRemoteListenerUnitTest, OpenSoftbusSession_001, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
const std::string peerDeviceId = "12345";
dBinderRemoteListener_.softbusManager_ = ISessionService::GetInstance();
EXPECT_EQ(dBinderRemoteListener_.OpenSoftbusSession(peerDeviceId), nullptr);
}
@ -226,7 +262,6 @@ HWTEST_F(DBinderRemoteListenerUnitTest, OpenSoftbusSession_002, TestSize.Level1)
{
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
const std::string peerDeviceId = "";
dBinderRemoteListener_.softbusManager_ = ISessionService::GetInstance();
EXPECT_EQ(dBinderRemoteListener_.OpenSoftbusSession(peerDeviceId), nullptr);
}
@ -242,6 +277,5 @@ HWTEST_F(DBinderRemoteListenerUnitTest, GetPeerSession_002, TestSize.Level1)
DBinderRemoteListener dBinderRemoteListener_(DBinderService::GetInstance());
const std::string peerDeviceId = "12345";
EXPECT_EQ(dBinderRemoteListener_.OpenSoftbusSession(peerDeviceId), nullptr);
dBinderRemoteListener_.softbusManager_ = ISessionService::GetInstance();
dBinderRemoteListener_.OpenSoftbusSession(peerDeviceId);
}

View File

@ -24,13 +24,11 @@
#include "rpc_log.h"
#include "log_tags.h"
#include "string_ex.h"
#include "session_impl.h"
#include "mock_session_impl.h"
using namespace testing::ext;
using namespace OHOS;
using namespace OHOS::HiviewDFX;
using Communication::SoftBus::Session;
using Communication::SoftBus::SessionImpl;
class DBinderServiceUnitTest : public testing::Test {
public:
@ -1047,8 +1045,10 @@ HWTEST_F(DBinderServiceUnitTest, FindDBinderStub001, TestSize.Level1)
HWTEST_F(DBinderServiceUnitTest, ProcessOnSessionClosedTest002, TestSize.Level1)
{
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
std::shared_ptr<Session> session = std::make_shared<SessionImpl>();
session->SetPeerDeviceId("networkId");
std::shared_ptr<MockSessionImpl> session = std::make_shared<MockSessionImpl>();
std::string deviceId = "networkId";
EXPECT_CALL(*session, GetPeerDeviceId())
.WillRepeatedly(testing::ReturnRef(deviceId));
std::shared_ptr<OHOS::ThreadLockInfo> threadLockInfo = std::make_shared<OHOS::ThreadLockInfo>();
uint32_t seqNumber = 10;
dBinderService->AttachThreadLockInfo(seqNumber, "networkId", threadLockInfo);

View File

@ -40,5 +40,6 @@ const unsigned int LOG_ID_RPC_DBINDER_SER_STUB = LOG_ID_IPC_BASE | 0x13;
const unsigned int LOG_ID_RPC_DBINDER_INVOKER = LOG_ID_IPC_BASE | 0x14;
const unsigned int LOG_ID_RPC_REMOTE_LISTENER = LOG_ID_IPC_BASE | 0x15;
const unsigned int LOG_ID_RPC_DBINDER_CB_STUB = LOG_ID_IPC_BASE | 0x16;
const unsigned int LOG_ID_RPC_DBINDER_SOFTBUS_CLIENT = LOG_ID_IPC_BASE | 0x17;
} // namespace OHOS
#endif // OHOS_COMMUNICATION_LOG_TAGS_H