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..4127d6f269f3d7ba756c8614fbf2a1aee4e3f9e6 --- a/interfaces/innerkits/libdbinder/include/dbinder_service.h +++ b/interfaces/innerkits/libdbinder/include/dbinder_service.h @@ -24,6 +24,7 @@ #include #include +#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 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 +196,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/if_dbinder_service.h b/interfaces/innerkits/libdbinder/include/if_dbinder_service.h new file mode 100644 index 0000000000000000000000000000000000000000..c6708cde7a96653d3081a466885f4c4bcf2ec1d3 --- /dev/null +++ b/interfaces/innerkits/libdbinder/include/if_dbinder_service.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_DBINDER_H +#define INTERFACES_RPC_SERVICES_DBINDER_H + +#include "iremote_object.h" + +namespace OHOS { +class IDBinderService{ +public: + virtual sptr GetSystemAbilityFromRemote(int32_t systemAbilityId) = 0; + IDBinderService() = default; + virtual ~IDBinderService() = default; +}; +} // namespace OHOS +#endif // INTERFACES_RPC_SERVICES_DBINDER_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..9c9ff2dec2889e5922503e9ca38a73c4afbedeab --- 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" @@ -89,6 +87,22 @@ bool DBinderService::StartDBinderService() return true; } +bool DBinderService::StartDBinderService(std::shared_ptr &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 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(proxy.GetRefPtr());