!512 DM设备上线时动态拉起分布式框架SA

Merge pull request !512 from wuqi/master
This commit is contained in:
openharmony_ci
2022-04-29 03:03:09 +00:00
committed by Gitee
8 changed files with 195 additions and 1 deletions
+2
View File
@@ -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,
+2
View File
@@ -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",
@@ -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 {
@@ -126,6 +127,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);
+7 -1
View File
@@ -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" ]
@@ -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 <cstdint>
#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
@@ -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<IRemoteObject>& 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
@@ -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
@@ -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<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgr == nullptr) {
LOGE("failed to get system ability mgr.");
}
distributedHardwareLoadCount_++;
sptr<DistributedHardwareLoadCallback> 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<IRemoteObject> &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