diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index a2124ae27128f8252eb9e7dc5350e57997f2b544..c4aaf136a9d54653ce7bcfccf36b143764097f0b 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, @@ -66,6 +67,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 4057b15df10f484f160893426c41ab789a4ce0f3..1eae90b77a36fd6173b815fa94fd9b90b1f41664 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/lite", "${utils_path}/include/ipc/lite", "${utils_path}/include/permission/lite", "${innerkits_path}/native_cpp/include", @@ -251,6 +252,7 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc", "${common_path}/include/ipc/model", "${utils_path}/include", + "${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 e8d0d95ad7cf7938b62951855ba20d76eed7e316..3088141e1130a27a5e9df2afec4c6c79ef75f7e3 100755 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -18,6 +18,7 @@ #include "dm_adapter_manager.h" #include "dm_anonymous.h" #include "dm_constants.h" +#include "dm_distributed_hardware_load.h" #include "dm_log.h" namespace OHOS { @@ -128,6 +129,7 @@ void DmDeviceStateManager::PostDeviceOffline(const std::string &pkgName, const D void DmDeviceStateManager::OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &info) { + DmDistributedHardwareLoad::GetInstance().LoadDistributedHardwareFwk(); 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 c8c9d1b7c935a7e3dc3a28bff8c7fc0c1cfaf81f..6a67f2ad89ba23147a1a59514c449ca99622a466 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_distributed_hardware_load.cpp", "src/ipc/lite/ipc_cmd_register.cpp", "src/permission/lite/permission_manager.cpp", ] @@ -116,6 +118,7 @@ if (defined(ohos_lite)) { config("devicemanagerutils_config") { include_dirs = [ "include", + "include/fwkload/standard", "include/ipc/standard", "${common_path}/include", "${common_path}/include/ipc", @@ -134,7 +137,10 @@ if (defined(ohos_lite)) { "src/ipc/standard/ipc_cmd_register.cpp", ] if (support_jsapi) { - sources += [ "src/permission/standard/permission_manager.cpp" ] + sources += [ + "src/fwkload/standard/dm_distributed_hardware_load.cpp", + "src/permission/standard/permission_manager.cpp", + ] } public_configs = [ ":devicemanagerutils_config" ] diff --git a/utils/include/fwkload/lite/dm_distributed_hardware_load.h b/utils/include/fwkload/lite/dm_distributed_hardware_load.h new file mode 100644 index 0000000000000000000000000000000000000000..bcfa6732e1885d82342c4ce7144626b0225d5fea --- /dev/null +++ b/utils/include/fwkload/lite/dm_distributed_hardware_load.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_DISTRIBUTEED_HARDWARE_LOAD_H +#define OHOS_DM_DISTRIBUTEED_HARDWARE_LOAD_H +#include +#include "single_instance.h" +namespace OHOS { +namespace DistributedHardware { +class DmDistributedHardwareLoad { + DECLARE_SINGLE_INSTANCE(DmDistributedHardwareLoad); +public: + void LoadDistributedHardwareFwk(void); + void InitDistributedHardwareLoadCount(void); + uint32_t GetDistributedHardwareLoadCount(void); +private: + uint32_t distributedHardwareLoadCount_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_PERMISSION_MANAGER_H diff --git a/utils/include/fwkload/standard/dm_distributed_hardware_load.h b/utils/include/fwkload/standard/dm_distributed_hardware_load.h new file mode 100644 index 0000000000000000000000000000000000000000..ca3aed65905c26c918725cc8d2a8030d92dd4a44 --- /dev/null +++ b/utils/include/fwkload/standard/dm_distributed_hardware_load.h @@ -0,0 +1,43 @@ +/* + * 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_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" +#include "system_ability_definition.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; +}; + +class DmDistributedHardwareLoad { + DECLARE_SINGLE_INSTANCE(DmDistributedHardwareLoad); +public: + void LoadDistributedHardwareFwk(void); + void InitDistributedHardwareLoadCount(void); + uint32_t GetDistributedHardwareLoadCount(void); +private: + uint32_t distributedHardwareLoadCount_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_PERMISSION_MANAGER_H diff --git a/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp b/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1662a20d5496edf47fb07ce463ca0935963afae5 --- /dev/null +++ b/utils/src/fwkload/lite/dm_distributed_hardware_load.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 "dm_constants.h" +#include "dm_distributed_hardware_load.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(DmDistributedHardwareLoad); +void DmDistributedHardwareLoad::LoadDistributedHardwareFwk(void) +{ + return; +} +void DmDistributedHardwareLoad::InitDistributedHardwareLoadCount(void) +{ + return; +} +uint32_t DmDistributedHardwareLoad::GetDistributedHardwareLoadCount(void) +{ + return 0; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp b/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5a9e019d0bde06f19e619910e560fc0c35a81261 --- /dev/null +++ b/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp @@ -0,0 +1,71 @@ +/* + * 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_constants.h" +#include "dm_log.h" +#include "dm_distributed_hardware_load.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(DmDistributedHardwareLoad); +void DmDistributedHardwareLoad::LoadDistributedHardwareFwk(void) +{ + LOGI("enter DmDistributedHardwareLoad::LoadDistributedHardwareFwk"); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + LOGE("failed to get system ability mgr."); + } + distributedHardwareLoadCount_++; + 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; +} +void DmDistributedHardwareLoad::InitDistributedHardwareLoadCount(void) +{ + distributedHardwareLoadCount_ = 0; +} +uint32_t DmDistributedHardwareLoad::GetDistributedHardwareLoadCount() +{ + 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