diff --git a/interfaces/innerkits/libdbinder/BUILD.gn b/interfaces/innerkits/libdbinder/BUILD.gn old mode 100755 new mode 100644 index ad4ce246f54667f86b388dca68c7a6faa4037722..24bec754a20da9195ad94fba97008aa66dc34131 --- a/interfaces/innerkits/libdbinder/BUILD.gn +++ b/interfaces/innerkits/libdbinder/BUILD.gn @@ -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" diff --git a/interfaces/innerkits/libdbinder/include/dbinder_service.h b/interfaces/innerkits/libdbinder/include/dbinder_service.h old mode 100755 new mode 100644 index b23e5f47cfcdaa8da1f4946af7725d148d53d448..763f092e491bd297acde9f7d25949e5591f52cf3 --- a/interfaces/innerkits/libdbinder/include/dbinder_service.h +++ b/interfaces/innerkits/libdbinder/include/dbinder_service.h @@ -24,9 +24,10 @@ #include #include +#include "dbinder_service_stub.h" #include "ipc_object_proxy.h" #include "ipc_object_stub.h" -#include "dbinder_service_stub.h" +#include "rpc_system_ability_callback.h" namespace OHOS { class DBinderRemoteListener; @@ -100,7 +101,7 @@ public: virtual ~DBinderService(); public: static sptr GetInstance(); - bool StartDBinderService(); + bool StartDBinderService(std::shared_ptr &callbackImpl); sptr MakeRemoteBinder(const std::u16string &serviceName, const std::string &deviceID, binder_uintptr_t binderObject, uint64_t pid = 0); bool RegisterRemoteProxy(std::u16string serviceName, sptr binderObject); @@ -194,6 +195,8 @@ private: std::map busNameObject_; static constexpr int32_t FIRST_SYS_ABILITY_ID = 0x00000001; static constexpr int32_t LAST_SYS_ABILITY_ID = 0x00ffffff; + + std::shared_ptr dbinderCallback_; }; } // namespace OHOS #endif // OHOS_IPC_SERVICES_DBINDER_DBINDER_SERVICE_H diff --git a/interfaces/innerkits/libdbinder/include/rpc_system_ability_callback.h b/interfaces/innerkits/libdbinder/include/rpc_system_ability_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..cb93579ca5865bdd60a8b1f51740d47debcb9fff --- /dev/null +++ b/interfaces/innerkits/libdbinder/include/rpc_system_ability_callback.h @@ -0,0 +1,29 @@ +/* + * 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_CALLBACK_H +#define INTERFACES_RPC_SERVICES_CALLBACK_H + +#include "iremote_object.h" + +namespace OHOS { +class RpcSystemAbilityCallback { +public: + virtual sptr GetSystemAbilityFromRemote(int32_t systemAbilityId) = 0; + RpcSystemAbilityCallback() = default; + virtual ~RpcSystemAbilityCallback() = default; +}; +} // namespace OHOS +#endif // INTERFACES_RPC_SERVICES_CALLBACK_H \ No newline at end of file diff --git a/services/dbinder/dbinder_service/src/dbinder_service.cpp b/services/dbinder/dbinder_service/src/dbinder_service.cpp old mode 100755 new mode 100644 index 657d1638cfcc4c54f266811a2c9c68820c36aade..790402be8dc366ee5ab6cb5de3920d8fc56bb5bf --- a/services/dbinder/dbinder_service/src/dbinder_service.cpp +++ b/services/dbinder/dbinder_service/src/dbinder_service.cpp @@ -21,14 +21,12 @@ #include #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" @@ -58,6 +56,7 @@ DBinderService::~DBinderService() noticeProxy_.clear(); deathRecipients_.clear(); busNameObject_.clear(); + dbinderCallback_ = nullptr; DBINDER_LOGI("dbinder service died"); } @@ -74,7 +73,7 @@ std::string DBinderService::GetLocalDeviceID() return networkId; } -bool DBinderService::StartDBinderService() +bool DBinderService::StartDBinderService(std::shared_ptr &callbackImpl) { if (mainThreadCreated_) { return true; @@ -85,6 +84,7 @@ bool DBinderService::StartDBinderService() return false; } mainThreadCreated_ = true; + dbinderCallback_ = callbackImpl; return true; } @@ -372,21 +372,18 @@ sptr DBinderService::FindOrNewProxy(binder_uintptr_t binderObject DBINDER_LOGI("already have proxy"); return proxy; } + if (dbinderCallback_ == nullptr) { + DBINDER_LOGE("samgr not initialized get remote sa callback"); + return nullptr; + } /* proxy is null, attempt to get a new proxy */ std::u16string serviceName = GetRegisterService(binderObject); if (serviceName.empty() && !CheckSystemAbilityId(systemAbilityId)) { 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(proxy.GetRefPtr());