提交 9d92172d 编写于 作者: L liubb_0516

Remove dbinder's dependency on samgr

Signed-off-by: Nliubb_0516 <liubeibei8@huawei.com>
上级 52e465a7
......@@ -56,7 +56,6 @@ ohos_shared_library("libdbinder") {
external_deps = [
"dsoftbus_standard:softbus_client",
"hiviewdfx_hilog_native:libhilog",
"samgr_standard:samgr_proxy",
]
subsystem_name = "communication"
part_name = "ipc"
......
......@@ -24,6 +24,7 @@
#include <list>
#include <thread>
#include "if_dbinder_service.h"
#include "ipc_object_proxy.h"
#include "ipc_object_stub.h"
#include "dbinder_service_stub.h"
......@@ -101,6 +102,7 @@ public:
public:
static sptr<DBinderService> GetInstance();
bool StartDBinderService();
bool StartDBinderService(std::shared_ptr<IDBinderService> &callbackImpl);
sptr<DBinderServiceStub> MakeRemoteBinder(const std::u16string &serviceName,
const std::string &deviceID, binder_uintptr_t binderObject, uint64_t pid = 0);
bool RegisterRemoteProxy(std::u16string serviceName, sptr<IRemoteObject> binderObject);
......@@ -194,6 +196,8 @@ private:
std::map<IPCObjectProxy *, std::string> busNameObject_;
static constexpr int32_t FIRST_SYS_ABILITY_ID = 0x00000001;
static constexpr int32_t LAST_SYS_ABILITY_ID = 0x00ffffff;
std::shared_ptr<IDBinderService> dbinderCallback_;
};
} // namespace OHOS
#endif // OHOS_IPC_SERVICES_DBINDER_DBINDER_SERVICE_H
/*
* Copyright (C) 2022 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 INTERFACES_RPC_SERVICES_DBINDER_H
#define INTERFACES_RPC_SERVICES_DBINDER_H
#include "iremote_object.h"
namespace OHOS {
class IDBinderService{
public:
virtual sptr<IRemoteObject> GetSystemAbilityFromRemote(int32_t systemAbilityId) = 0;
IDBinderService() = default;
virtual ~IDBinderService() = default;
};
} // namespace OHOS
#endif // INTERFACES_RPC_SERVICES_DBINDER_H
\ No newline at end of file
......@@ -21,14 +21,12 @@
#include <arpa/inet.h>
#include "securec.h"
#include "string_ex.h"
#include "iservice_registry.h"
#include "ipc_skeleton.h"
#include "ipc_thread_skeleton.h"
#include "dbinder_log.h"
#include "dbinder_service_stub.h"
#include "dbinder_remote_listener.h"
#include "if_system_ability_manager.h"
#include "dbinder_error_code.h"
#include "softbus_bus_center.h"
#include "dbinder_sa_death_recipient.h"
......@@ -89,6 +87,22 @@ bool DBinderService::StartDBinderService()
return true;
}
bool DBinderService::StartDBinderService(std::shared_ptr<IDBinderService> &callbackImpl)
{
if (mainThreadCreated_) {
return true;
}
bool result = StartRemoteListener();
if (!result) {
return false;
}
mainThreadCreated_ = true;
dbinderCallback_ = callbackImpl;
return true;
}
bool DBinderService::StartRemoteListener()
{
if (remoteListener_ != nullptr) {
......@@ -378,15 +392,8 @@ sptr<IRemoteObject> DBinderService::FindOrNewProxy(binder_uintptr_t binderObject
DBINDER_LOGE("service is not registered in this device, saId:%{public}d", systemAbilityId);
return nullptr;
}
auto manager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (manager == nullptr) {
DBINDER_LOGE("when new proxy, find samgr fail!");
return nullptr;
}
int digitalName = !serviceName.empty() ? std::atoi(Str16ToStr8(serviceName).c_str()) : systemAbilityId;
proxy = manager->GetSystemAbility(digitalName);
int32_t digitalName = !serviceName.empty() ? std::atoi(Str16ToStr8(serviceName).c_str()) : systemAbilityId;
proxy = dbinderCallback_->GetSystemAbilityFromRemote(digitalName);
if (proxy != nullptr) {
/* When the stub object dies, you need to delete the corresponding busName information */
IPCObjectProxy *saProxy = reinterpret_cast<IPCObjectProxy *>(proxy.GetRefPtr());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册