From 8af506e885caa5feef8c6a8438c6eb507d54dd6b Mon Sep 17 00:00:00 2001 From: chen Date: Tue, 11 Jan 2022 14:58:57 +0800 Subject: [PATCH] fixed 28c2cca from https://gitee.com/hdcck/distributedschedule_samgr/pulls/46 update callback Signed-off-by: chen Change-Id: Iec53f9ccd5b6238d0f921937c66b33b0d5361979 --- services/samgr/native/BUILD.gn | 1 + .../native/include/dbinder_callback_imp.h | 30 +++++++++++++++++++ .../native/include/system_ability_manager.h | 3 ++ .../native/source/dbinder_callback_imp.cpp | 24 +++++++++++++++ .../native/source/system_ability_manager.cpp | 27 +++++++++++++++-- 5 files changed, 83 insertions(+), 2 deletions(-) mode change 100644 => 100755 services/samgr/native/BUILD.gn create mode 100755 services/samgr/native/include/dbinder_callback_imp.h create mode 100755 services/samgr/native/source/dbinder_callback_imp.cpp diff --git a/services/samgr/native/BUILD.gn b/services/samgr/native/BUILD.gn old mode 100644 new mode 100755 index bc7fa7c1..9a7d83ca --- a/services/samgr/native/BUILD.gn +++ b/services/samgr/native/BUILD.gn @@ -56,6 +56,7 @@ ohos_executable("samgr") { install_enable = true sources = [ "//foundation/distributedschedule/samgr/services/samgr/native/source/ability_death_recipient.cpp", + "//foundation/distributedschedule/samgr/services/samgr/native/source/dbinder_callback_imp.cpp", "//foundation/distributedschedule/samgr/services/samgr/native/source/main.cpp", "//foundation/distributedschedule/samgr/services/samgr/native/source/system_ability_load_callback_proxy.cpp", "//foundation/distributedschedule/samgr/services/samgr/native/source/system_ability_manager.cpp", diff --git a/services/samgr/native/include/dbinder_callback_imp.h b/services/samgr/native/include/dbinder_callback_imp.h new file mode 100755 index 00000000..7b6d68e4 --- /dev/null +++ b/services/samgr/native/include/dbinder_callback_imp.h @@ -0,0 +1,30 @@ +/* + * 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 SERVICES_SAMGR_NATIVE_INCLUDE_DBINDER_CALLBACK_IMP_H_ +#define SERVICES_SAMGR_NATIVE_INCLUDE_DBINDER_CALLBACK_IMP_H_ + +#include "if_dbinder_service.h" + +namespace OHOS { +class DbinderCallbackImp : public IDBinderService { +public: + sptr GetSystemAbilityFromRemote(int32_t systemAbilityId) override; + DbinderCallbackImp() = default; + ~DbinderCallbackImp() override = default; +}; +} // namespace OHOS + +#endif // !defined(SERVICES_SAMGR_NATIVE_INCLUDE_ABILITY_DEATH_RECIPIENT_H_) diff --git a/services/samgr/native/include/system_ability_manager.h b/services/samgr/native/include/system_ability_manager.h index d87d2ca7..d8a19930 100755 --- a/services/samgr/native/include/system_ability_manager.h +++ b/services/samgr/native/include/system_ability_manager.h @@ -24,6 +24,7 @@ #include #include "event_handler.h" +#include "dbinder_callback_imp.h" #include "dbinder_service.h" #include "dbinder_service_stub.h" #include "sa_profiles.h" @@ -90,6 +91,7 @@ public: int32_t LoadSystemAbility(int32_t systemAbilityId, const sptr& callback) override; void OnAbilityCallbackDied(const sptr& remoteObject); + sptr GetSystemAbilityFromRemote(int32_t systemAbilityId); private: enum class AbilityState { INIT, @@ -148,6 +150,7 @@ private: sptr abilityStatusDeath_; sptr abilityCallbackDeath_; sptr dBinderService_; + std::shared_ptr dBinderCallbackImp_; bool isDbinderStart_ = false; // must hold abilityMapLock_ never access other locks diff --git a/services/samgr/native/source/dbinder_callback_imp.cpp b/services/samgr/native/source/dbinder_callback_imp.cpp new file mode 100755 index 00000000..ba377651 --- /dev/null +++ b/services/samgr/native/source/dbinder_callback_imp.cpp @@ -0,0 +1,24 @@ +/* + * 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. + */ + +#include "dbinder_callback_imp.h" +#include "system_ability_manager.h" + +namespace OHOS { +sptr DbinderCallbackImp::GetSystemAbilityFromRemote(int32_t systemAbilityId) +{ + return SystemAbilityManager::GetInstance()->GetSystemAbilityFromRemote(systemAbilityId); +} +} \ No newline at end of file diff --git a/services/samgr/native/source/system_ability_manager.cpp b/services/samgr/native/source/system_ability_manager.cpp index fb900c9c..7e9d8a91 100755 --- a/services/samgr/native/source/system_ability_manager.cpp +++ b/services/samgr/native/source/system_ability_manager.cpp @@ -64,6 +64,7 @@ void SystemAbilityManager::Init() systemProcessDeath_ = sptr(new SystemProcessDeathRecipient()); abilityStatusDeath_ = sptr(new AbilityStatusDeathRecipient()); abilityCallbackDeath_ = sptr(new AbilityCallbackDeathRecipient()); + dBinderCallbackImp_ = make_shared(); if (workHandler_ == nullptr) { auto runner = AppExecFwk::EventRunner::Create("workHandler"); workHandler_ = make_shared(runner); @@ -139,6 +140,28 @@ sptr SystemAbilityManager::GetSystemAbility(int32_t systemAbility return CheckSystemAbility(systemAbilityId, deviceId); } +sptr SystemAbilityManager::GetSystemAbilityFromRemote(int32_t systemAbilityId) +{ + HILOGD("%{public}s called, systemAbilityId = %{public}d", __func__, systemAbilityId); + if (!CheckInputSysAbilityId(systemAbilityId)) { + HILOGW("GetSystemAbilityFromRemote invalid!"); + return nullptr; + } + + shared_lock readLock(abilityMapLock_); + auto iter = abilityMap_.find(systemAbilityId); + if (iter == abilityMap_.end()) { + HILOGI("GetSystemAbilityFromRemote not found service : %{public}d.", systemAbilityId); + return nullptr; + } + if (!(iter->second.isDistributed)) { + HILOGW("GetSystemAbilityFromRemote service : %{public}d not distributed", systemAbilityId); + return nullptr; + } + HILOGI("GetSystemAbilityFromRemote found service : %{public}d.", systemAbilityId); + return iter->second.remoteObj; +} + sptr SystemAbilityManager::CheckSystemAbility(int32_t systemAbilityId) { HILOGD("%{public}s called, systemAbilityId = %{public}d", __func__, systemAbilityId); @@ -596,8 +619,8 @@ int32_t SystemAbilityManager::AddSystemAbility(int32_t systemAbilityId, const sp HILOGD("AddSystemAbility RegisterRemoteProxy, serviceId is %{public}d", systemAbilityId); } if (systemAbilityId == SOFTBUS_SERVER_SA_ID && !isDbinderStart_) { - if (dBinderService_ != nullptr) { - bool ret = dBinderService_->StartDBinderService(); + if (dBinderService_ != nullptr && dBinderCallbackImp_ != nullptr) { + bool ret = dBinderService_->StartDBinderService(dBinderCallbackImp_); HILOGI("start result is %{public}s", ret ? "succeed" : "fail"); isDbinderStart_ = true; } -- Gitee