From f47a508d497fbca3487a360e50f6e115ee2efbd7 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 26 Apr 2022 09:49:25 +0800 Subject: [PATCH 1/8] =?UTF-8?q?DM=E4=B8=8A=E7=BA=BF=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=8B=89=E8=B5=B7SA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- common/include/dm_constants.h | 1 + services/devicemanagerservice/BUILD.gn | 1 + .../src/devicestate/dm_device_state_manager.cpp | 7 +++++++ utils/BUILD.gn | 7 ++++++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index a2124ae27..db66982b9 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -66,6 +66,7 @@ enum { ERR_DM_INPUT_PARA_INVALID, ERR_DM_SUBSCRIBE_DP_EVENTS, ERR_DM_UNSUBSCRIBE_DP_EVENTS, + ERR_DM_LOAD_FWK_SA_FAIL, DM_IPC_FAILED = 2000, DM_IPC_TRANSACTION_FAILED, DM_IPC_FLATTEN_OBJECT, diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn index 4057b15df..e2114fd52 100755 --- a/services/devicemanagerservice/BUILD.gn +++ b/services/devicemanagerservice/BUILD.gn @@ -251,6 +251,7 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc", "${common_path}/include/ipc/model", "${utils_path}/include", + "${utils_path}/include/fwkload", "${utils_path}/include/permission/standard", "//base/security/deviceauth/interfaces/innerkits", "//third_party/json/include", diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index e8d0d95ad..02af9fed7 100755 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -19,6 +19,7 @@ #include "dm_anonymous.h" #include "dm_constants.h" #include "dm_log.h" +#include "dm_loadfwk.h" namespace OHOS { namespace DistributedHardware { @@ -128,6 +129,12 @@ void DmDeviceStateManager::PostDeviceOffline(const std::string &pkgName, const D void DmDeviceStateManager::OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &info) { + std::shared_ptr dmLoadFwkPtr = std::make_shared(); + int32_t ret = dmLoadFwkPtr->LoadFwk(); + if (ret != DM_OK) { + LOGE("load fwk sa failed"); + return; + } LOGI("OnDeviceOnline function is called back with pkgName: %s", pkgName.c_str()); RegisterOffLineTimer(info); RegisterProfileListener(pkgName, info); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index c8c9d1b7c..371aa15f2 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -116,6 +116,7 @@ if (defined(ohos_lite)) { config("devicemanagerutils_config") { include_dirs = [ "include", + "include/fwkload", "include/ipc/standard", "${common_path}/include", "${common_path}/include/ipc", @@ -134,7 +135,11 @@ if (defined(ohos_lite)) { "src/ipc/standard/ipc_cmd_register.cpp", ] if (support_jsapi) { - sources += [ "src/permission/standard/permission_manager.cpp" ] + sources += [ + "src/fwkload/distributed_hardware_load_callback.cpp", + "src/fwkload/dm_loadfwk.cpp", + "src/permission/standard/permission_manager.cpp", + ] } public_configs = [ ":devicemanagerutils_config" ] -- Gitee From 5be836511140e96b9891f877752eba032aeb5652 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 26 Apr 2022 10:17:45 +0800 Subject: [PATCH 2/8] =?UTF-8?q?DM=E4=B8=8A=E7=BA=BF=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=8B=89=E8=B5=B7=E5=88=86=E5=B8=83=E5=BC=8F=E6=A1=86=E6=9E=B6?= =?UTF-8?q?SA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../distributed_hardware_load_callback.h | 29 +++++++++++ utils/include/fwkload/dm_loadfwk.h | 29 +++++++++++ .../distributed_hardware_load_callback.cpp | 35 +++++++++++++ utils/src/fwkload/dm_loadfwk.cpp | 52 +++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 utils/include/fwkload/distributed_hardware_load_callback.h create mode 100644 utils/include/fwkload/dm_loadfwk.h create mode 100644 utils/src/fwkload/distributed_hardware_load_callback.cpp create mode 100644 utils/src/fwkload/dm_loadfwk.cpp diff --git a/utils/include/fwkload/distributed_hardware_load_callback.h b/utils/include/fwkload/distributed_hardware_load_callback.h new file mode 100644 index 000000000..8ee6832c5 --- /dev/null +++ b/utils/include/fwkload/distributed_hardware_load_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 OHOS_DISTRIBUTED_HARDWARE_LOAD_CALLBACK_H +#define OHOS_DISTRIBUTED_HARDWARE_LOAD_CALLBACK_H + +#include "system_ability_load_callback_stub.h" + +namespace OHOS { +namespace DistributedHardware { +class DistributedHardwareLoadCallback : public SystemAbilityLoadCallbackStub { +public: + void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr& remoteObject) override; + void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; +}; +} +} +#endif \ No newline at end of file diff --git a/utils/include/fwkload/dm_loadfwk.h b/utils/include/fwkload/dm_loadfwk.h new file mode 100644 index 000000000..798ec91c4 --- /dev/null +++ b/utils/include/fwkload/dm_loadfwk.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 OHOS_DM_LOAD_FWK_H +#define OHOS_DM_LOAD_FWK_H + +#include "distributed_hardware_load_callback.h" + +namespace OHOS { +namespace DistributedHardware { +class DmLoadFwk { +public: + int32_t LoadFwk(void); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_PERMISSION_MANAGER_H diff --git a/utils/src/fwkload/distributed_hardware_load_callback.cpp b/utils/src/fwkload/distributed_hardware_load_callback.cpp new file mode 100644 index 000000000..63dfc5aed --- /dev/null +++ b/utils/src/fwkload/distributed_hardware_load_callback.cpp @@ -0,0 +1,35 @@ + /* + * 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 "distributed_hardware_load_callback.h" +#include "dm_log.h" +namespace OHOS { +namespace DistributedHardware { +void DistributedHardwareLoadCallback::OnLoadSystemAbilitySuccess( + int32_t systemAbilityId, const sptr &remoteObject) +{ + LOGI("load fwk SA success, systemAbilityId:%d, remoteObject result:%s", + systemAbilityId, (remoteObject != nullptr) ? "true":"false"); + if (remoteObject == nullptr) { + LOGE("remoteObject is nullptr"); + return; + } +} + +void DistributedHardwareLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) +{ + LOGE("load fwk SA failed, systemAbilityId:%d", systemAbilityId); +} +} +} \ No newline at end of file diff --git a/utils/src/fwkload/dm_loadfwk.cpp b/utils/src/fwkload/dm_loadfwk.cpp new file mode 100644 index 000000000..f87e1302c --- /dev/null +++ b/utils/src/fwkload/dm_loadfwk.cpp @@ -0,0 +1,52 @@ +/* + * 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 "dm_loadfwk.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" +#include "dm_constants.h" +#include "dm_log.h" + +namespace OHOS { +namespace DistributedHardware { +int32_t DmLoadFwk::LoadFwk(void) +{ + LOGI("enter DmLoadFwk::LoadFwk"); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + LOGE("failed to get system ability mgr."); + return DM_SERVICE_NOT_READY; + } + const uint32_t nLoadCount = 3; + int32_t ret = DM_OK; + sptr loadCallback = new DistributedHardwareLoadCallback(); + for (size_t i = 0; i < nLoadCount; i++) + { + ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_SA_ID, loadCallback); + if (ret == DM_OK) { + break; + } + } + if (ret != DM_OK) { + LOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d, nLoadCount:%d", + DISTRIBUTED_HARDWARE_SA_ID, ret, nLoadCount); + return ERR_DM_LOAD_FWK_SA_FAIL; + } + LOGI("leave DmLoadFwk::LoadFwk"); + return DM_OK; +} +} // namespace DistributedHardware +} // namespace OHOS -- Gitee From 137e174f001faf1a259f948bc9950afb7b01aef1 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 26 Apr 2022 10:41:06 +0800 Subject: [PATCH 3/8] =?UTF-8?q?DM=E4=B8=8A=E7=BA=BF=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=8B=89=E8=B5=B7=E5=88=86=E5=B8=83=E5=BC=8F=E6=A1=86=E6=9E=B6?= =?UTF-8?q?SA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- services/devicemanagerservice/BUILD.gn | 1 + utils/src/fwkload/distributed_hardware_load_callback.cpp | 2 +- utils/src/fwkload/dm_loadfwk.cpp | 5 ++--- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn index e2114fd52..b192b2500 100755 --- a/services/devicemanagerservice/BUILD.gn +++ b/services/devicemanagerservice/BUILD.gn @@ -149,6 +149,7 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc", "${common_path}/include/ipc/model", "${utils_path}/include", + "${utils_path}/include/fwkload", "${utils_path}/include/ipc/lite", "${utils_path}/include/permission/lite", "${innerkits_path}/native_cpp/include", diff --git a/utils/src/fwkload/distributed_hardware_load_callback.cpp b/utils/src/fwkload/distributed_hardware_load_callback.cpp index 63dfc5aed..3f6a85796 100644 --- a/utils/src/fwkload/distributed_hardware_load_callback.cpp +++ b/utils/src/fwkload/distributed_hardware_load_callback.cpp @@ -1,4 +1,4 @@ - /* +/* * 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. diff --git a/utils/src/fwkload/dm_loadfwk.cpp b/utils/src/fwkload/dm_loadfwk.cpp index f87e1302c..c98640824 100644 --- a/utils/src/fwkload/dm_loadfwk.cpp +++ b/utils/src/fwkload/dm_loadfwk.cpp @@ -33,8 +33,7 @@ int32_t DmLoadFwk::LoadFwk(void) const uint32_t nLoadCount = 3; int32_t ret = DM_OK; sptr loadCallback = new DistributedHardwareLoadCallback(); - for (size_t i = 0; i < nLoadCount; i++) - { + for (size_t i = 0; i < nLoadCount; i++) { ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_SA_ID, loadCallback); if (ret == DM_OK) { break; @@ -42,7 +41,7 @@ int32_t DmLoadFwk::LoadFwk(void) } if (ret != DM_OK) { LOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d, nLoadCount:%d", - DISTRIBUTED_HARDWARE_SA_ID, ret, nLoadCount); + DISTRIBUTED_HARDWARE_SA_ID, ret, nLoadCount); return ERR_DM_LOAD_FWK_SA_FAIL; } LOGI("leave DmLoadFwk::LoadFwk"); -- Gitee From 2aa0e6b1363253d2440c0a6c7e8c8cd3f3f81511 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 26 Apr 2022 17:01:16 +0800 Subject: [PATCH 4/8] =?UTF-8?q?DM=E4=B8=8A=E7=BA=BF=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=8B=89=E8=B5=B7=E5=88=86=E5=B8=83=E5=BC=8F=E6=A1=86=E6=9E=B6?= =?UTF-8?q?SA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- services/devicemanagerservice/BUILD.gn | 4 +-- .../devicestate/dm_device_state_manager.cpp | 5 ++- utils/BUILD.gn | 8 +++-- utils/include/fwkload/{ => lite}/dm_loadfwk.h | 7 ++-- .../distributed_hardware_load_callback.h | 3 ++ utils/include/fwkload/standard/dm_loadfwk.h | 33 +++++++++++++++++++ utils/src/fwkload/lite/dm_loadfwk.cpp | 32 ++++++++++++++++++ .../distributed_hardware_load_callback.cpp | 12 ++++++- .../src/fwkload/{ => standard}/dm_loadfwk.cpp | 24 ++++++++------ 9 files changed, 106 insertions(+), 22 deletions(-) rename utils/include/fwkload/{ => lite}/dm_loadfwk.h (87%) rename utils/include/fwkload/{ => standard}/distributed_hardware_load_callback.h (90%) create mode 100644 utils/include/fwkload/standard/dm_loadfwk.h create mode 100644 utils/src/fwkload/lite/dm_loadfwk.cpp rename utils/src/fwkload/{ => standard}/distributed_hardware_load_callback.cpp (76%) rename utils/src/fwkload/{ => standard}/dm_loadfwk.cpp (75%) diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn index b192b2500..1eae90b77 100755 --- a/services/devicemanagerservice/BUILD.gn +++ b/services/devicemanagerservice/BUILD.gn @@ -149,7 +149,7 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc", "${common_path}/include/ipc/model", "${utils_path}/include", - "${utils_path}/include/fwkload", + "${utils_path}/include/fwkload/lite", "${utils_path}/include/ipc/lite", "${utils_path}/include/permission/lite", "${innerkits_path}/native_cpp/include", @@ -252,7 +252,7 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc", "${common_path}/include/ipc/model", "${utils_path}/include", - "${utils_path}/include/fwkload", + "${utils_path}/include/fwkload/standard", "${utils_path}/include/permission/standard", "//base/security/deviceauth/interfaces/innerkits", "//third_party/json/include", diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index 02af9fed7..caf61f931 100755 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -129,9 +129,7 @@ void DmDeviceStateManager::PostDeviceOffline(const std::string &pkgName, const D void DmDeviceStateManager::OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &info) { - std::shared_ptr dmLoadFwkPtr = std::make_shared(); - int32_t ret = dmLoadFwkPtr->LoadFwk(); - if (ret != DM_OK) { + if (DmLoadFwk::GetInstance().LoadFwk() != DM_OK) { LOGE("load fwk sa failed"); return; } @@ -166,6 +164,7 @@ void DmDeviceStateManager::OnDeviceOnline(const std::string &pkgName, const DmDe void DmDeviceStateManager::OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &info) { + DmLoadFwk::GetInstance().ResetLoadCallback(); LOGI("OnDeviceOnline function is called with pkgName: %s", pkgName.c_str()); StartOffLineTimer(info); UnRegisterProfileListener(pkgName, info); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 371aa15f2..8261381e3 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -69,6 +69,7 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc", "${common_path}/include/ipc/model", "include", + "include/fwkload/lite", "include/ipc/lite", "include/permission/lite", ] @@ -92,6 +93,7 @@ if (defined(ohos_lite)) { "src/dm_anonymous.cpp", "src/dm_log.cpp", "src/dm_random.cpp", + "src/fwkload/lite/dm_loadfwk.cpp", "src/ipc/lite/ipc_cmd_register.cpp", "src/permission/lite/permission_manager.cpp", ] @@ -116,7 +118,7 @@ if (defined(ohos_lite)) { config("devicemanagerutils_config") { include_dirs = [ "include", - "include/fwkload", + "include/fwkload/standard", "include/ipc/standard", "${common_path}/include", "${common_path}/include/ipc", @@ -136,8 +138,8 @@ if (defined(ohos_lite)) { ] if (support_jsapi) { sources += [ - "src/fwkload/distributed_hardware_load_callback.cpp", - "src/fwkload/dm_loadfwk.cpp", + "src/fwkload/standard/distributed_hardware_load_callback.cpp", + "src/fwkload/standard/dm_loadfwk.cpp", "src/permission/standard/permission_manager.cpp", ] } diff --git a/utils/include/fwkload/dm_loadfwk.h b/utils/include/fwkload/lite/dm_loadfwk.h similarity index 87% rename from utils/include/fwkload/dm_loadfwk.h rename to utils/include/fwkload/lite/dm_loadfwk.h index 798ec91c4..15d61e6e2 100644 --- a/utils/include/fwkload/dm_loadfwk.h +++ b/utils/include/fwkload/lite/dm_loadfwk.h @@ -15,14 +15,15 @@ #ifndef OHOS_DM_LOAD_FWK_H #define OHOS_DM_LOAD_FWK_H - -#include "distributed_hardware_load_callback.h" - +#include +#include "single_instance.h" namespace OHOS { namespace DistributedHardware { class DmLoadFwk { + DECLARE_SINGLE_INSTANCE(DmLoadFwk); public: int32_t LoadFwk(void); + void ResetLoadCallback(void); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/include/fwkload/distributed_hardware_load_callback.h b/utils/include/fwkload/standard/distributed_hardware_load_callback.h similarity index 90% rename from utils/include/fwkload/distributed_hardware_load_callback.h rename to utils/include/fwkload/standard/distributed_hardware_load_callback.h index 8ee6832c5..6628453c2 100644 --- a/utils/include/fwkload/distributed_hardware_load_callback.h +++ b/utils/include/fwkload/standard/distributed_hardware_load_callback.h @@ -21,8 +21,11 @@ namespace OHOS { namespace DistributedHardware { class DistributedHardwareLoadCallback : public SystemAbilityLoadCallbackStub { public: + explicit DistributedHardwareLoadCallback(const uint32_t &nLoadCount); void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr& remoteObject) override; void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; +private: + uint32_t nLoadCount_; }; } } diff --git a/utils/include/fwkload/standard/dm_loadfwk.h b/utils/include/fwkload/standard/dm_loadfwk.h new file mode 100644 index 000000000..65a6fbc74 --- /dev/null +++ b/utils/include/fwkload/standard/dm_loadfwk.h @@ -0,0 +1,33 @@ +/* + * 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 OHOS_DM_LOAD_FWK_H +#define OHOS_DM_LOAD_FWK_H +#include "distributed_hardware_load_callback.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +class DmLoadFwk { + DECLARE_SINGLE_INSTANCE(DmLoadFwk); +public: + int32_t LoadFwk(void); + void ResetLoadCallback(void); +private: + sptr loadCallback_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_PERMISSION_MANAGER_H diff --git a/utils/src/fwkload/lite/dm_loadfwk.cpp b/utils/src/fwkload/lite/dm_loadfwk.cpp new file mode 100644 index 000000000..2e90fa778 --- /dev/null +++ b/utils/src/fwkload/lite/dm_loadfwk.cpp @@ -0,0 +1,32 @@ +/* + * 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 "dm_loadfwk.h" +#include "dm_constants.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(DmLoadFwk); + +int32_t DmLoadFwk::LoadFwk(void) +{ + return DM_OK; +} +void DmLoadFwk::ResetLoadCallback(void) +{ + return; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/utils/src/fwkload/distributed_hardware_load_callback.cpp b/utils/src/fwkload/standard/distributed_hardware_load_callback.cpp similarity index 76% rename from utils/src/fwkload/distributed_hardware_load_callback.cpp rename to utils/src/fwkload/standard/distributed_hardware_load_callback.cpp index 3f6a85796..701ab9796 100644 --- a/utils/src/fwkload/distributed_hardware_load_callback.cpp +++ b/utils/src/fwkload/standard/distributed_hardware_load_callback.cpp @@ -14,13 +14,17 @@ */ #include "distributed_hardware_load_callback.h" #include "dm_log.h" +#include "dm_loadfwk.h" namespace OHOS { namespace DistributedHardware { +DistributedHardwareLoadCallback::DistributedHardwareLoadCallback( + const uint32_t &nLoadCount) : nLoadCount_(nLoadCount) {} + void DistributedHardwareLoadCallback::OnLoadSystemAbilitySuccess( int32_t systemAbilityId, const sptr &remoteObject) { LOGI("load fwk SA success, systemAbilityId:%d, remoteObject result:%s", - systemAbilityId, (remoteObject != nullptr) ? "true":"false"); + systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); if (remoteObject == nullptr) { LOGE("remoteObject is nullptr"); return; @@ -30,6 +34,12 @@ void DistributedHardwareLoadCallback::OnLoadSystemAbilitySuccess( void DistributedHardwareLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) { LOGE("load fwk SA failed, systemAbilityId:%d", systemAbilityId); + uint32_t minLoadValue = 1; + if (nLoadCount_ > minLoadValue) { + DmLoadFwk::GetInstance().LoadFwk(); + nLoadCount_--; + } + return; } } } \ No newline at end of file diff --git a/utils/src/fwkload/dm_loadfwk.cpp b/utils/src/fwkload/standard/dm_loadfwk.cpp similarity index 75% rename from utils/src/fwkload/dm_loadfwk.cpp rename to utils/src/fwkload/standard/dm_loadfwk.cpp index c98640824..bec7b7e66 100644 --- a/utils/src/fwkload/dm_loadfwk.cpp +++ b/utils/src/fwkload/standard/dm_loadfwk.cpp @@ -22,6 +22,8 @@ namespace OHOS { namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(DmLoadFwk); + int32_t DmLoadFwk::LoadFwk(void) { LOGI("enter DmLoadFwk::LoadFwk"); @@ -30,22 +32,24 @@ int32_t DmLoadFwk::LoadFwk(void) LOGE("failed to get system ability mgr."); return DM_SERVICE_NOT_READY; } - const uint32_t nLoadCount = 3; - int32_t ret = DM_OK; - sptr loadCallback = new DistributedHardwareLoadCallback(); - for (size_t i = 0; i < nLoadCount; i++) { - ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_SA_ID, loadCallback); - if (ret == DM_OK) { - break; - } + if (nullptr == loadCallback_) { + const uint32_t nLoadCount = 3; + loadCallback_ = new DistributedHardwareLoadCallback(nLoadCount); } + int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_SA_ID, loadCallback_); if (ret != DM_OK) { - LOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d, nLoadCount:%d", - DISTRIBUTED_HARDWARE_SA_ID, ret, nLoadCount); + LOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d", + DISTRIBUTED_HARDWARE_SA_ID, ret); return ERR_DM_LOAD_FWK_SA_FAIL; } LOGI("leave DmLoadFwk::LoadFwk"); return DM_OK; } +void DmLoadFwk::ResetLoadCallback(void) +{ + if (nullptr != loadCallback_) { + loadCallback_ = nullptr; + } +} } // namespace DistributedHardware } // namespace OHOS -- Gitee From 322da8df77e9f488ae347750dcf300a79a6348b8 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 26 Apr 2022 17:09:08 +0800 Subject: [PATCH 5/8] =?UTF-8?q?DM=E4=B8=8A=E7=BA=BF=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=8B=89=E8=B5=B7=E5=88=86=E5=B8=83=E5=BC=8F=E6=A1=86=E6=9E=B6?= =?UTF-8?q?SA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- utils/src/fwkload/standard/dm_loadfwk.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/src/fwkload/standard/dm_loadfwk.cpp b/utils/src/fwkload/standard/dm_loadfwk.cpp index bec7b7e66..9ff20ff02 100644 --- a/utils/src/fwkload/standard/dm_loadfwk.cpp +++ b/utils/src/fwkload/standard/dm_loadfwk.cpp @@ -32,7 +32,7 @@ int32_t DmLoadFwk::LoadFwk(void) LOGE("failed to get system ability mgr."); return DM_SERVICE_NOT_READY; } - if (nullptr == loadCallback_) { + if (loadCallback_ == nullptr) { const uint32_t nLoadCount = 3; loadCallback_ = new DistributedHardwareLoadCallback(nLoadCount); } @@ -47,7 +47,7 @@ int32_t DmLoadFwk::LoadFwk(void) } void DmLoadFwk::ResetLoadCallback(void) { - if (nullptr != loadCallback_) { + if (loadCallback_ != nullptr) { loadCallback_ = nullptr; } } -- Gitee From b4e7ce1acb0347bb68b196febd31b734f37015b5 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Wed, 27 Apr 2022 17:49:50 +0800 Subject: [PATCH 6/8] =?UTF-8?q?DM=E4=B8=8A=E7=BA=BF=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=8B=89=E8=B5=B7=E5=88=86=E5=B8=83=E5=BC=8F=E6=A1=86=E6=9E=B6?= =?UTF-8?q?SA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../devicestate/dm_device_state_manager.cpp | 9 +-- utils/BUILD.gn | 5 +- ...adfwk.h => dm_distributed_hardware_load.h} | 15 +++-- ...lback.h => dm_distributed_hardware_load.h} | 25 ++++++--- utils/include/fwkload/standard/dm_loadfwk.h | 33 ----------- ...k.cpp => dm_distributed_hardware_load.cpp} | 15 +++-- .../distributed_hardware_load_callback.cpp | 45 --------------- ...k.cpp => dm_distributed_hardware_load.cpp} | 55 ++++++++++++------- 8 files changed, 76 insertions(+), 126 deletions(-) rename utils/include/fwkload/lite/{dm_loadfwk.h => dm_distributed_hardware_load.h} (68%) rename utils/include/fwkload/standard/{distributed_hardware_load_callback.h => dm_distributed_hardware_load.h} (60%) delete mode 100644 utils/include/fwkload/standard/dm_loadfwk.h rename utils/src/fwkload/lite/{dm_loadfwk.cpp => dm_distributed_hardware_load.cpp} (68%) delete mode 100644 utils/src/fwkload/standard/distributed_hardware_load_callback.cpp rename utils/src/fwkload/standard/{dm_loadfwk.cpp => dm_distributed_hardware_load.cpp} (45%) diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index caf61f931..2ba741e77 100755 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -18,8 +18,8 @@ #include "dm_adapter_manager.h" #include "dm_anonymous.h" #include "dm_constants.h" +#include "dm_distributed_hardware_load.h" #include "dm_log.h" -#include "dm_loadfwk.h" namespace OHOS { namespace DistributedHardware { @@ -129,10 +129,8 @@ void DmDeviceStateManager::PostDeviceOffline(const std::string &pkgName, const D void DmDeviceStateManager::OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &info) { - if (DmLoadFwk::GetInstance().LoadFwk() != DM_OK) { - LOGE("load fwk sa failed"); - return; - } + DmDistributedHhardwareLoad::GetInstance().InitDistributedHardwareLoadCount(); + DmDistributedHhardwareLoad::GetInstance().LoadDistributedHardwareFwk(); LOGI("OnDeviceOnline function is called back with pkgName: %s", pkgName.c_str()); RegisterOffLineTimer(info); RegisterProfileListener(pkgName, info); @@ -164,7 +162,6 @@ void DmDeviceStateManager::OnDeviceOnline(const std::string &pkgName, const DmDe void DmDeviceStateManager::OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &info) { - DmLoadFwk::GetInstance().ResetLoadCallback(); LOGI("OnDeviceOnline function is called with pkgName: %s", pkgName.c_str()); StartOffLineTimer(info); UnRegisterProfileListener(pkgName, info); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 8261381e3..6a67f2ad8 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -93,7 +93,7 @@ if (defined(ohos_lite)) { "src/dm_anonymous.cpp", "src/dm_log.cpp", "src/dm_random.cpp", - "src/fwkload/lite/dm_loadfwk.cpp", + "src/fwkload/lite/dm_distributed_hardware_load.cpp", "src/ipc/lite/ipc_cmd_register.cpp", "src/permission/lite/permission_manager.cpp", ] @@ -138,8 +138,7 @@ if (defined(ohos_lite)) { ] if (support_jsapi) { sources += [ - "src/fwkload/standard/distributed_hardware_load_callback.cpp", - "src/fwkload/standard/dm_loadfwk.cpp", + "src/fwkload/standard/dm_distributed_hardware_load.cpp", "src/permission/standard/permission_manager.cpp", ] } diff --git a/utils/include/fwkload/lite/dm_loadfwk.h b/utils/include/fwkload/lite/dm_distributed_hardware_load.h similarity index 68% rename from utils/include/fwkload/lite/dm_loadfwk.h rename to utils/include/fwkload/lite/dm_distributed_hardware_load.h index 15d61e6e2..94a1f1cd1 100644 --- a/utils/include/fwkload/lite/dm_loadfwk.h +++ b/utils/include/fwkload/lite/dm_distributed_hardware_load.h @@ -13,17 +13,20 @@ * limitations under the License. */ -#ifndef OHOS_DM_LOAD_FWK_H -#define OHOS_DM_LOAD_FWK_H +#ifndef OHOS_DM_DISTRIBUTEED_HARDWARE_LOAD_FWK_H +#define OHOS_DM_DISTRIBUTEED_HARDWARE_LOAD_FWK_H #include #include "single_instance.h" namespace OHOS { namespace DistributedHardware { -class DmLoadFwk { - DECLARE_SINGLE_INSTANCE(DmLoadFwk); +class DmDistributedHhardwareLoad { + DECLARE_SINGLE_INSTANCE(DmDistributedHhardwareLoad); public: - int32_t LoadFwk(void); - void ResetLoadCallback(void); + void LoadDistributedHardwareFwk(void); + void InitDistributedHardwareLoadCount(void); + uint32_t getDistributedHardwareLoadCount(void); +private: + uint32_t nLoadCount_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/include/fwkload/standard/distributed_hardware_load_callback.h b/utils/include/fwkload/standard/dm_distributed_hardware_load.h similarity index 60% rename from utils/include/fwkload/standard/distributed_hardware_load_callback.h rename to utils/include/fwkload/standard/dm_distributed_hardware_load.h index 6628453c2..d89774391 100644 --- a/utils/include/fwkload/standard/distributed_hardware_load_callback.h +++ b/utils/include/fwkload/standard/dm_distributed_hardware_load.h @@ -4,7 +4,7 @@ * 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 + * 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, @@ -12,21 +12,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef OHOS_DISTRIBUTED_HARDWARE_LOAD_CALLBACK_H -#define OHOS_DISTRIBUTED_HARDWARE_LOAD_CALLBACK_H +#ifndef OHOS_DM_DISTRIBUTEED_HARDWARE_LOAD_FWK_H +#define OHOS_DM_DISTRIBUTEED_HARDWARE_LOAD_FWK_H +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "single_instance.h" +#include "system_ability_definition.h" #include "system_ability_load_callback_stub.h" namespace OHOS { namespace DistributedHardware { class DistributedHardwareLoadCallback : public SystemAbilityLoadCallbackStub { public: - explicit DistributedHardwareLoadCallback(const uint32_t &nLoadCount); void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr& remoteObject) override; void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; +}; + +class DmDistributedHhardwareLoad { + DECLARE_SINGLE_INSTANCE(DmDistributedHhardwareLoad); +public: + void LoadDistributedHardwareFwk(void); + void InitDistributedHardwareLoadCount(void); + uint32_t getDistributedHardwareLoadCount(void); private: uint32_t nLoadCount_; }; -} -} -#endif \ No newline at end of file +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_PERMISSION_MANAGER_H diff --git a/utils/include/fwkload/standard/dm_loadfwk.h b/utils/include/fwkload/standard/dm_loadfwk.h deleted file mode 100644 index 65a6fbc74..000000000 --- a/utils/include/fwkload/standard/dm_loadfwk.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 OHOS_DM_LOAD_FWK_H -#define OHOS_DM_LOAD_FWK_H -#include "distributed_hardware_load_callback.h" -#include "single_instance.h" - -namespace OHOS { -namespace DistributedHardware { -class DmLoadFwk { - DECLARE_SINGLE_INSTANCE(DmLoadFwk); -public: - int32_t LoadFwk(void); - void ResetLoadCallback(void); -private: - sptr loadCallback_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DM_PERMISSION_MANAGER_H diff --git a/utils/src/fwkload/lite/dm_loadfwk.cpp b/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp similarity index 68% rename from utils/src/fwkload/lite/dm_loadfwk.cpp rename to utils/src/fwkload/lite/dm_distributed_hardware_load.cpp index 2e90fa778..21e1e2686 100644 --- a/utils/src/fwkload/lite/dm_loadfwk.cpp +++ b/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp @@ -13,20 +13,23 @@ * limitations under the License. */ -#include "dm_loadfwk.h" #include "dm_constants.h" +#include "dm_distributed_hardware_load.h" namespace OHOS { namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(DmLoadFwk); - -int32_t DmLoadFwk::LoadFwk(void) +IMPLEMENT_SINGLE_INSTANCE(DmDistributedHhardwareLoad); +void DmDistributedHhardwareLoad::LoadDistributedHardwareFwk(void) { - return DM_OK; + return; } -void DmLoadFwk::ResetLoadCallback(void) +void DmDistributedHhardwareLoad::InitDistributedHardwareLoadCount(void) { return; } +uint32_t DmDistributedHhardwareLoad::getDistributedHardwareLoadCount(void) +{ + return 0; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/src/fwkload/standard/distributed_hardware_load_callback.cpp b/utils/src/fwkload/standard/distributed_hardware_load_callback.cpp deleted file mode 100644 index 701ab9796..000000000 --- a/utils/src/fwkload/standard/distributed_hardware_load_callback.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 "distributed_hardware_load_callback.h" -#include "dm_log.h" -#include "dm_loadfwk.h" -namespace OHOS { -namespace DistributedHardware { -DistributedHardwareLoadCallback::DistributedHardwareLoadCallback( - const uint32_t &nLoadCount) : nLoadCount_(nLoadCount) {} - -void DistributedHardwareLoadCallback::OnLoadSystemAbilitySuccess( - int32_t systemAbilityId, const sptr &remoteObject) -{ - LOGI("load fwk SA success, systemAbilityId:%d, remoteObject result:%s", - systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); - if (remoteObject == nullptr) { - LOGE("remoteObject is nullptr"); - return; - } -} - -void DistributedHardwareLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - LOGE("load fwk SA failed, systemAbilityId:%d", systemAbilityId); - uint32_t minLoadValue = 1; - if (nLoadCount_ > minLoadValue) { - DmLoadFwk::GetInstance().LoadFwk(); - nLoadCount_--; - } - return; -} -} -} \ No newline at end of file diff --git a/utils/src/fwkload/standard/dm_loadfwk.cpp b/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp similarity index 45% rename from utils/src/fwkload/standard/dm_loadfwk.cpp rename to utils/src/fwkload/standard/dm_distributed_hardware_load.cpp index 9ff20ff02..f13eed489 100644 --- a/utils/src/fwkload/standard/dm_loadfwk.cpp +++ b/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp @@ -13,43 +13,58 @@ * limitations under the License. */ -#include "dm_loadfwk.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" #include "dm_constants.h" +#include "dm_distributed_hardware_load.h" #include "dm_log.h" namespace OHOS { namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(DmLoadFwk); -int32_t DmLoadFwk::LoadFwk(void) +void DistributedHardwareLoadCallback::OnLoadSystemAbilitySuccess( + int32_t systemAbilityId, const sptr &remoteObject) { - LOGI("enter DmLoadFwk::LoadFwk"); + LOGI("DmDistributedHhardware Load SA success, systemAbilityId:%d, remoteObject result:%s", + systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); + if (remoteObject == nullptr) { + LOGE("remoteObject is nullptr"); + return; + } +} + +void DistributedHardwareLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) +{ + LOGE("DmDistributedHhardware Load SA failed, systemAbilityId:%d", systemAbilityId); + uint32_t maxLoadValue = 3; + if (DmDistributedHhardwareLoad::GetInstance().getDistributedHardwareLoadCount() < maxLoadValue) { + DmDistributedHhardwareLoad::GetInstance().LoadDistributedHardwareFwk(); + } + return; +} + +IMPLEMENT_SINGLE_INSTANCE(DmDistributedHhardwareLoad); +void DmDistributedHhardwareLoad::LoadDistributedHardwareFwk(void) +{ + LOGI("enter DmDistributedHhardwareLoad::LoadDistributedHardwareFwk"); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { LOGE("failed to get system ability mgr."); - return DM_SERVICE_NOT_READY; - } - if (loadCallback_ == nullptr) { - const uint32_t nLoadCount = 3; - loadCallback_ = new DistributedHardwareLoadCallback(nLoadCount); } - int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_SA_ID, loadCallback_); + nLoadCount_++; + sptr distributedHardwareLoadCallback_ = new DistributedHardwareLoadCallback(); + int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_SA_ID, distributedHardwareLoadCallback_); if (ret != DM_OK) { LOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d", DISTRIBUTED_HARDWARE_SA_ID, ret); - return ERR_DM_LOAD_FWK_SA_FAIL; } - LOGI("leave DmLoadFwk::LoadFwk"); - return DM_OK; + return; } -void DmLoadFwk::ResetLoadCallback(void) +void DmDistributedHhardwareLoad::InitDistributedHardwareLoadCount(void) { - if (loadCallback_ != nullptr) { - loadCallback_ = nullptr; - } + nLoadCount_ = 0; +} +uint32_t DmDistributedHhardwareLoad::getDistributedHardwareLoadCount() +{ + return nLoadCount_; } } // namespace DistributedHardware } // namespace OHOS -- Gitee From b0870bc61fa5e3492d49a96814fc5b57a35b1204 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Thu, 28 Apr 2022 09:09:15 +0800 Subject: [PATCH 7/8] =?UTF-8?q?DM=E4=B8=8A=E7=BA=BF=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=8B=89=E8=B5=B7=E5=88=86=E5=B8=83=E5=BC=8F=E6=A1=86=E6=9E=B6?= =?UTF-8?q?SA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../devicestate/dm_device_state_manager.cpp | 4 ++-- .../lite/dm_distributed_hardware_load.h | 8 ++++---- .../standard/dm_distributed_hardware_load.h | 8 ++++---- .../lite/dm_distributed_hardware_load.cpp | 8 ++++---- .../standard/dm_distributed_hardware_load.cpp | 18 ++++++++---------- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index 2ba741e77..ab10937cd 100755 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -129,8 +129,8 @@ void DmDeviceStateManager::PostDeviceOffline(const std::string &pkgName, const D void DmDeviceStateManager::OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &info) { - DmDistributedHhardwareLoad::GetInstance().InitDistributedHardwareLoadCount(); - DmDistributedHhardwareLoad::GetInstance().LoadDistributedHardwareFwk(); + DmDistributedHardwareLoad::GetInstance().InitDistributedHardwareLoadCount(); + DmDistributedHardwareLoad::GetInstance().LoadDistributedHardwareFwk(); LOGI("OnDeviceOnline function is called back with pkgName: %s", pkgName.c_str()); RegisterOffLineTimer(info); RegisterProfileListener(pkgName, info); diff --git a/utils/include/fwkload/lite/dm_distributed_hardware_load.h b/utils/include/fwkload/lite/dm_distributed_hardware_load.h index 94a1f1cd1..7a2d54c23 100644 --- a/utils/include/fwkload/lite/dm_distributed_hardware_load.h +++ b/utils/include/fwkload/lite/dm_distributed_hardware_load.h @@ -13,14 +13,14 @@ * limitations under the License. */ -#ifndef OHOS_DM_DISTRIBUTEED_HARDWARE_LOAD_FWK_H -#define OHOS_DM_DISTRIBUTEED_HARDWARE_LOAD_FWK_H +#ifndef OHOS_DM_DISTRIBUTEED_HARDWARE_LOAD_H +#define OHOS_DM_DISTRIBUTEED_HARDWARE_LOAD_H #include #include "single_instance.h" namespace OHOS { namespace DistributedHardware { -class DmDistributedHhardwareLoad { - DECLARE_SINGLE_INSTANCE(DmDistributedHhardwareLoad); +class DmDistributedHardwareLoad { + DECLARE_SINGLE_INSTANCE(DmDistributedHardwareLoad); public: void LoadDistributedHardwareFwk(void); void InitDistributedHardwareLoadCount(void); diff --git a/utils/include/fwkload/standard/dm_distributed_hardware_load.h b/utils/include/fwkload/standard/dm_distributed_hardware_load.h index d89774391..3f47ffd0d 100644 --- a/utils/include/fwkload/standard/dm_distributed_hardware_load.h +++ b/utils/include/fwkload/standard/dm_distributed_hardware_load.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_DM_DISTRIBUTEED_HARDWARE_LOAD_FWK_H -#define OHOS_DM_DISTRIBUTEED_HARDWARE_LOAD_FWK_H +#ifndef OHOS_DM_DISTRIBUTEED_HARDWARE_LOAD_H +#define OHOS_DM_DISTRIBUTEED_HARDWARE_LOAD_H #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "single_instance.h" @@ -29,8 +29,8 @@ public: void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; }; -class DmDistributedHhardwareLoad { - DECLARE_SINGLE_INSTANCE(DmDistributedHhardwareLoad); +class DmDistributedHardwareLoad { + DECLARE_SINGLE_INSTANCE(DmDistributedHardwareLoad); public: void LoadDistributedHardwareFwk(void); void InitDistributedHardwareLoadCount(void); diff --git a/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp b/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp index 21e1e2686..bdc2a89da 100644 --- a/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp +++ b/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp @@ -18,16 +18,16 @@ namespace OHOS { namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(DmDistributedHhardwareLoad); -void DmDistributedHhardwareLoad::LoadDistributedHardwareFwk(void) +IMPLEMENT_SINGLE_INSTANCE(DmDistributedHardwareLoad); +void DmDistributedHardwareLoad::LoadDistributedHardwareFwk(void) { return; } -void DmDistributedHhardwareLoad::InitDistributedHardwareLoadCount(void) +void DmDistributedHardwareLoad::InitDistributedHardwareLoadCount(void) { return; } -uint32_t DmDistributedHhardwareLoad::getDistributedHardwareLoadCount(void) +uint32_t DmDistributedHardwareLoad::getDistributedHardwareLoadCount(void) { return 0; } diff --git a/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp b/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp index f13eed489..c349c7ded 100644 --- a/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp +++ b/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp @@ -14,12 +14,11 @@ */ #include "dm_constants.h" -#include "dm_distributed_hardware_load.h" #include "dm_log.h" +#include "dm_distributed_hardware_load.h" namespace OHOS { namespace DistributedHardware { - void DistributedHardwareLoadCallback::OnLoadSystemAbilitySuccess( int32_t systemAbilityId, const sptr &remoteObject) { @@ -30,21 +29,20 @@ void DistributedHardwareLoadCallback::OnLoadSystemAbilitySuccess( return; } } - void DistributedHardwareLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) { LOGE("DmDistributedHhardware Load SA failed, systemAbilityId:%d", systemAbilityId); uint32_t maxLoadValue = 3; - if (DmDistributedHhardwareLoad::GetInstance().getDistributedHardwareLoadCount() < maxLoadValue) { - DmDistributedHhardwareLoad::GetInstance().LoadDistributedHardwareFwk(); + if (DmDistributedHardwareLoad::GetInstance().getDistributedHardwareLoadCount() < maxLoadValue) { + DmDistributedHardwareLoad::GetInstance().LoadDistributedHardwareFwk(); } return; } -IMPLEMENT_SINGLE_INSTANCE(DmDistributedHhardwareLoad); -void DmDistributedHhardwareLoad::LoadDistributedHardwareFwk(void) +IMPLEMENT_SINGLE_INSTANCE(DmDistributedHardwareLoad); +void DmDistributedHardwareLoad::LoadDistributedHardwareFwk(void) { - LOGI("enter DmDistributedHhardwareLoad::LoadDistributedHardwareFwk"); + LOGI("enter DmDistributedHardwareLoad::LoadDistributedHardwareFwk"); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { LOGE("failed to get system ability mgr."); @@ -58,11 +56,11 @@ void DmDistributedHhardwareLoad::LoadDistributedHardwareFwk(void) } return; } -void DmDistributedHhardwareLoad::InitDistributedHardwareLoadCount(void) +void DmDistributedHardwareLoad::InitDistributedHardwareLoadCount(void) { nLoadCount_ = 0; } -uint32_t DmDistributedHhardwareLoad::getDistributedHardwareLoadCount() +uint32_t DmDistributedHardwareLoad::getDistributedHardwareLoadCount() { return nLoadCount_; } -- Gitee From f647f495723dc20d19ec7054879711504c1e1e63 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Thu, 28 Apr 2022 11:10:39 +0800 Subject: [PATCH 8/8] =?UTF-8?q?DM=E4=B8=8A=E7=BA=BF=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=8B=89=E8=B5=B7=E5=88=86=E5=B8=83=E5=BC=8F=E6=A1=86=E6=9E=B6?= =?UTF-8?q?SA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- common/include/dm_constants.h | 1 + .../devicestate/dm_device_state_manager.cpp | 1 - .../lite/dm_distributed_hardware_load.h | 4 +- .../standard/dm_distributed_hardware_load.h | 4 +- .../lite/dm_distributed_hardware_load.cpp | 2 +- .../standard/dm_distributed_hardware_load.cpp | 51 ++++++++++--------- 6 files changed, 33 insertions(+), 30 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index db66982b9..c4aaf136a 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -41,6 +41,7 @@ const int32_t MIN_PIN_CODE = 100000; const int32_t MAX_PIN_CODE = 999999; const int32_t DISCOVER_STATUS_LEN = 20; const int32_t COMMON_CALLBACK_MAX_SIZE = 200; +const uint32_t MAX_LOAD_VAVLUE = 3; enum { DM_OK = 0, diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index ab10937cd..3088141e1 100755 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -129,7 +129,6 @@ void DmDeviceStateManager::PostDeviceOffline(const std::string &pkgName, const D void DmDeviceStateManager::OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &info) { - DmDistributedHardwareLoad::GetInstance().InitDistributedHardwareLoadCount(); DmDistributedHardwareLoad::GetInstance().LoadDistributedHardwareFwk(); LOGI("OnDeviceOnline function is called back with pkgName: %s", pkgName.c_str()); RegisterOffLineTimer(info); diff --git a/utils/include/fwkload/lite/dm_distributed_hardware_load.h b/utils/include/fwkload/lite/dm_distributed_hardware_load.h index 7a2d54c23..bcfa6732e 100644 --- a/utils/include/fwkload/lite/dm_distributed_hardware_load.h +++ b/utils/include/fwkload/lite/dm_distributed_hardware_load.h @@ -24,9 +24,9 @@ class DmDistributedHardwareLoad { public: void LoadDistributedHardwareFwk(void); void InitDistributedHardwareLoadCount(void); - uint32_t getDistributedHardwareLoadCount(void); + uint32_t GetDistributedHardwareLoadCount(void); private: - uint32_t nLoadCount_; + uint32_t distributedHardwareLoadCount_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/include/fwkload/standard/dm_distributed_hardware_load.h b/utils/include/fwkload/standard/dm_distributed_hardware_load.h index 3f47ffd0d..ca3aed659 100644 --- a/utils/include/fwkload/standard/dm_distributed_hardware_load.h +++ b/utils/include/fwkload/standard/dm_distributed_hardware_load.h @@ -34,9 +34,9 @@ class DmDistributedHardwareLoad { public: void LoadDistributedHardwareFwk(void); void InitDistributedHardwareLoadCount(void); - uint32_t getDistributedHardwareLoadCount(void); + uint32_t GetDistributedHardwareLoadCount(void); private: - uint32_t nLoadCount_; + uint32_t distributedHardwareLoadCount_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp b/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp index bdc2a89da..1662a20d5 100644 --- a/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp +++ b/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp @@ -27,7 +27,7 @@ void DmDistributedHardwareLoad::InitDistributedHardwareLoadCount(void) { return; } -uint32_t DmDistributedHardwareLoad::getDistributedHardwareLoadCount(void) +uint32_t DmDistributedHardwareLoad::GetDistributedHardwareLoadCount(void) { return 0; } diff --git a/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp b/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp index c349c7ded..5a9e019d0 100644 --- a/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp +++ b/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp @@ -19,26 +19,6 @@ namespace OHOS { namespace DistributedHardware { -void DistributedHardwareLoadCallback::OnLoadSystemAbilitySuccess( - int32_t systemAbilityId, const sptr &remoteObject) -{ - LOGI("DmDistributedHhardware Load SA success, systemAbilityId:%d, remoteObject result:%s", - systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); - if (remoteObject == nullptr) { - LOGE("remoteObject is nullptr"); - return; - } -} -void DistributedHardwareLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - LOGE("DmDistributedHhardware Load SA failed, systemAbilityId:%d", systemAbilityId); - uint32_t maxLoadValue = 3; - if (DmDistributedHardwareLoad::GetInstance().getDistributedHardwareLoadCount() < maxLoadValue) { - DmDistributedHardwareLoad::GetInstance().LoadDistributedHardwareFwk(); - } - return; -} - IMPLEMENT_SINGLE_INSTANCE(DmDistributedHardwareLoad); void DmDistributedHardwareLoad::LoadDistributedHardwareFwk(void) { @@ -47,7 +27,7 @@ void DmDistributedHardwareLoad::LoadDistributedHardwareFwk(void) if (samgr == nullptr) { LOGE("failed to get system ability mgr."); } - nLoadCount_++; + distributedHardwareLoadCount_++; sptr distributedHardwareLoadCallback_ = new DistributedHardwareLoadCallback(); int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_SA_ID, distributedHardwareLoadCallback_); if (ret != DM_OK) { @@ -58,11 +38,34 @@ void DmDistributedHardwareLoad::LoadDistributedHardwareFwk(void) } void DmDistributedHardwareLoad::InitDistributedHardwareLoadCount(void) { - nLoadCount_ = 0; + distributedHardwareLoadCount_ = 0; } -uint32_t DmDistributedHardwareLoad::getDistributedHardwareLoadCount() +uint32_t DmDistributedHardwareLoad::GetDistributedHardwareLoadCount() { - return nLoadCount_; + return distributedHardwareLoadCount_; +} + +void DistributedHardwareLoadCallback::OnLoadSystemAbilitySuccess( + int32_t systemAbilityId, const sptr &remoteObject) +{ + LOGI("DmDistributedHhardware Load SA success, systemAbilityId:%d, remoteObject result:%s", + systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); + if (remoteObject == nullptr) { + LOGE("remoteObject is nullptr"); + return; + } + DmDistributedHardwareLoad::GetInstance().InitDistributedHardwareLoadCount(); +} +void DistributedHardwareLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) +{ + LOGE("DmDistributedHhardware Load SA failed, systemAbilityId:%d", systemAbilityId); + + if (DmDistributedHardwareLoad::GetInstance().GetDistributedHardwareLoadCount() < MAX_LOAD_VAVLUE) { + DmDistributedHardwareLoad::GetInstance().LoadDistributedHardwareFwk(); + } else { + DmDistributedHardwareLoad::GetInstance().InitDistributedHardwareLoadCount(); + } + return; } } // namespace DistributedHardware } // namespace OHOS -- Gitee