mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 06:20:07 +00:00
commit
ce3892f5e6
@ -65,7 +65,9 @@
|
||||
"samgr",
|
||||
"ffrt"
|
||||
],
|
||||
"third_party": []
|
||||
"third_party": [
|
||||
"cJSON"
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
"group_type": {
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2021-2024 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
|
||||
@ -29,6 +29,7 @@ config("distributed_sched_config") {
|
||||
"${communication_path}/dsoftbus/interfaces/kits/common",
|
||||
"${dms_path}/interfaces/kits/napi/include",
|
||||
"include/distributedWant",
|
||||
"//third_party/cJSON",
|
||||
]
|
||||
defines = []
|
||||
if (dmsfwk_mission_manager) {
|
||||
@ -111,6 +112,8 @@ ohos_shared_library("distributedschedsvr") {
|
||||
"//foundation/ability/dmsfwk/services/dtbschedmgr/test/resource:coverage_flags",
|
||||
]
|
||||
|
||||
deps = [ "//third_party/cJSON:cjson" ]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:want",
|
||||
@ -123,7 +126,8 @@ ohos_shared_library("distributedschedsvr") {
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"device_auth:deviceauth_sdk",
|
||||
"device_info_manager:distributed_device_profile_client",
|
||||
"device_info_manager:distributed_device_profile_common",
|
||||
"device_info_manager:distributed_device_profile_sdk",
|
||||
"device_manager:devicemanagersdk",
|
||||
"device_security_level:dslm_sdk",
|
||||
"distributed_bundle_framework:dbms_fwk",
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2024 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
|
||||
@ -16,6 +16,7 @@
|
||||
#ifndef OHOS_DISTRIBUTED_DTBSCHEDMGR_DEVICE_INFO_INTERFACE_H
|
||||
#define OHOS_DISTRIBUTED_DTBSCHEDMGR_DEVICE_INFO_INTERFACE_H
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include "adapter/dnetwork_adapter.h"
|
||||
@ -24,6 +25,7 @@
|
||||
#include "event_handler.h"
|
||||
#include "iremote_object.h"
|
||||
#include "single_instance.h"
|
||||
#include "sync_completed_callback_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
@ -41,6 +43,7 @@ public:
|
||||
bool Init();
|
||||
void Stop();
|
||||
bool GetLocalDeviceId(std::string& networkId);
|
||||
bool GetLocalUdid(std::string& udid);
|
||||
void DeviceOnlineNotify(const std::shared_ptr<DmsDeviceInfo> devInfo);
|
||||
void DeviceOfflineNotify(const std::string& networkId);
|
||||
void OnDeviceInfoChanged(const std::string& networkId);
|
||||
@ -81,12 +84,20 @@ public:
|
||||
*/
|
||||
void UpdateDeviceInfoStorage(const std::vector<DistributedHardware::DmDeviceInfo>& dmDeviceInfoList);
|
||||
|
||||
/**
|
||||
* Sync dms version info to remote
|
||||
*
|
||||
* @param remoteNetworkId
|
||||
*/
|
||||
int32_t SyncDmsVersionInfoToRemote(const std::string& remoteNetworkId);
|
||||
|
||||
private:
|
||||
bool InitNetworkIdManager(std::shared_ptr<DnetworkAdapter> dnetworkAdapter);
|
||||
bool ConnectSoftbus();
|
||||
void ClearAllDevices();
|
||||
bool WaitForDnetworkReady();
|
||||
bool GetLocalDeviceFromDnet(std::string& networkId);
|
||||
bool GetLocalDeviceUdid(std::string& udid);
|
||||
void RegisterUuidNetworkIdMap(const std::string& networkId);
|
||||
void UnregisterUuidNetworkIdMap(const std::string& networkId);
|
||||
std::mutex deviceLock_;
|
||||
@ -97,6 +108,9 @@ private:
|
||||
std::mutex uuidNetworkIdLock_;
|
||||
std::shared_ptr<AppExecFwk::EventHandler> initHandler_;
|
||||
std::shared_ptr<AppExecFwk::EventHandler> networkIdMgrHandler_;
|
||||
class SyncCallback : public OHOS::DistributedDeviceProfile::SyncCompletedCallbackStub {
|
||||
void OnSyncCompleted(const std::map<std::string, OHOS::DistributedDeviceProfile::SyncStatus> &syncResults);
|
||||
};
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2024 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
|
||||
@ -66,7 +66,8 @@ void DnetworkAdapter::DeviceInitCallBack::OnRemoteDied()
|
||||
|
||||
void DnetworkAdapter::DmsDeviceStateCallback::OnDeviceOnline(const DmDeviceInfo& deviceInfo)
|
||||
{
|
||||
HILOGI("OnNodeOnline netwokId = %{public}s", AnonymizeNetworkId(deviceInfo.networkId).c_str());
|
||||
std::string networkId = deviceInfo.networkId;
|
||||
HILOGI("OnNodeOnline netwokId = %{public}s", AnonymizeNetworkId(networkId).c_str());
|
||||
auto onlineNotifyTask = [deviceInfo]() {
|
||||
std::lock_guard<std::mutex> autoLock(listenerSetMutex_);
|
||||
for (auto& listener : listenerSet_) {
|
||||
@ -77,6 +78,7 @@ void DnetworkAdapter::DmsDeviceStateCallback::OnDeviceOnline(const DmDeviceInfo&
|
||||
HILOGE("OnNodeOnline post task failed");
|
||||
return;
|
||||
}
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().SyncDmsVersionInfoToRemote(networkId);
|
||||
}
|
||||
|
||||
void DnetworkAdapter::DmsDeviceStateCallback::OnDeviceOffline(const DmDeviceInfo& deviceInfo)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2024 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
|
||||
@ -16,14 +16,17 @@
|
||||
#include "dms_version_manager.h"
|
||||
|
||||
#include "distributed_device_profile_client.h"
|
||||
#include "dtbschedmgr_device_info_storage.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "string_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "DmsVersionManager";
|
||||
const std::string DMS_SERVICE_ID = "appInfo";
|
||||
const std::string DMS_SERVICE_ID = "dmsfwk_svr_id";
|
||||
const std::string DMS_CHAR_ID = "dmsInfo";
|
||||
const std::string DMS_SERVICE_TYPE = "appInfo";
|
||||
const std::string PACKAGE_NAMES = "packageNames";
|
||||
const std::string VERSIONS = "versions";
|
||||
@ -76,13 +79,15 @@ int32_t DmsVersionManager::GetRemoteDmsVersion(const std::string& deviceId, DmsV
|
||||
|
||||
int32_t DmsVersionManager::GetAppInfoFromDP(const std::string& deviceId, std::string& appInfoJsonData)
|
||||
{
|
||||
DeviceProfile::ServiceCharacteristicProfile profile;
|
||||
int32_t result = DeviceProfile::DistributedDeviceProfileClient::GetInstance().GetDeviceProfile(deviceId,
|
||||
DMS_SERVICE_ID, profile);
|
||||
DistributedDeviceProfile::CharacteristicProfile profile;
|
||||
std::string udid = "";
|
||||
udid = DtbschedmgrDeviceInfoStorage::GetInstance().GetUuidByNetworkId(deviceId);
|
||||
int32_t result = DistributedDeviceProfile::DistributedDeviceProfileClient::GetInstance().GetCharacteristicProfile(
|
||||
udid, DMS_SERVICE_ID, DMS_CHAR_ID, profile);
|
||||
if (result != ERR_OK) {
|
||||
return result;
|
||||
}
|
||||
appInfoJsonData = profile.GetCharacteristicProfileJson();
|
||||
appInfoJsonData = profile.GetCharacteristicValue();
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2024 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
|
||||
@ -19,11 +19,13 @@
|
||||
#include <thread>
|
||||
|
||||
#include "distributed_device_node_listener.h"
|
||||
#include "distributed_device_profile_client.h"
|
||||
#include "distributed_sched_service.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "ipc_object_proxy.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "cJSON.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
using namespace std;
|
||||
@ -31,11 +33,18 @@ namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
using namespace std::chrono_literals;
|
||||
using namespace DistributedHardware;
|
||||
using namespace DistributedDeviceProfile;
|
||||
|
||||
namespace {
|
||||
constexpr int32_t RETRY_TIMES = 30;
|
||||
constexpr int32_t CONNECT_SOFTBUS_RETRY_TIMES = 60;
|
||||
const std::string TAG = "DtbschedmgrDeviceInfoStorage";
|
||||
const std::string DMS_SERVICE_ID = "dmsfwk_svr_id";
|
||||
const std::string DMS_CHAR_ID = "dmsInfo";
|
||||
const std::string DMS_VERSION = "4.0.0";
|
||||
const std::string DMS_NAMES = "dmsfwk";
|
||||
constexpr const char *PACKAGE_NAMES = "packageNames";
|
||||
constexpr const char *VERSIONS = "versions";
|
||||
}
|
||||
|
||||
IMPLEMENT_SINGLE_INSTANCE(DtbschedmgrDeviceInfoStorage);
|
||||
@ -189,11 +198,62 @@ void DtbschedmgrDeviceInfoStorage::UpdateDeviceInfoStorage(
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DtbschedmgrDeviceInfoStorage::SyncDmsVersionInfoToRemote(const std::string& remoteNetworkId)
|
||||
{
|
||||
std::string localUdid = "";
|
||||
GetLocalUdid(localUdid);
|
||||
if (localUdid.empty()) {
|
||||
HILOGE("getlocaludid failed, localUdid is empty");
|
||||
}
|
||||
DistributedDeviceProfile::ServiceProfile serviceProfile;
|
||||
serviceProfile.SetDeviceId(localUdid);
|
||||
serviceProfile.SetServiceName(DMS_SERVICE_ID);
|
||||
serviceProfile.SetServiceType(DMS_SERVICE_ID);
|
||||
DistributedDeviceProfile::DistributedDeviceProfileClient::GetInstance().PutServiceProfile(serviceProfile);
|
||||
|
||||
DistributedDeviceProfile::CharacteristicProfile characteristicProfile;
|
||||
characteristicProfile.SetDeviceId(localUdid);
|
||||
characteristicProfile.SetServiceName(DMS_SERVICE_ID);
|
||||
characteristicProfile.SetCharacteristicKey(DMS_CHAR_ID);
|
||||
cJSON *jObject = cJSON_CreateObject();
|
||||
if (jObject == nullptr) {
|
||||
HILOGE("Failed to create cJSON object.");
|
||||
return ERR_NULL_OBJECT;
|
||||
}
|
||||
cJSON_AddStringToObject(jObject, PACKAGE_NAMES, DMS_NAMES.c_str());
|
||||
cJSON_AddStringToObject(jObject, VERSIONS, DMS_VERSION.c_str());
|
||||
char *jsonData = cJSON_PrintUnformatted(jObject);
|
||||
if (jsonData == nullptr) {
|
||||
HILOGE("Failed to create JSON data.");
|
||||
cJSON_Delete(jObject);
|
||||
return ERR_NULL_OBJECT;
|
||||
}
|
||||
std::string dmsInfo(jsonData);
|
||||
cJSON_Delete(jObject);
|
||||
cJSON_free(jsonData);
|
||||
characteristicProfile.SetCharacteristicValue(dmsInfo);
|
||||
DistributedDeviceProfile::DistributedDeviceProfileClient::GetInstance().
|
||||
PutCharacteristicProfile(characteristicProfile);
|
||||
|
||||
SyncOptions syncOptions;
|
||||
syncOptions.AddDevice(remoteNetworkId);
|
||||
syncOptions.SetSyncMode(SyncMode::PUSH_PULL);
|
||||
sptr<ISyncCompletedCallback> syncCallback = new(std::nothrow) SyncCallback;
|
||||
int32_t syncRes = DistributedDeviceProfileClient::GetInstance().SyncDeviceProfile(syncOptions, syncCallback);
|
||||
HILOGI("SyncDeviceProfile result: %{public}d", syncRes);
|
||||
return syncRes;
|
||||
}
|
||||
|
||||
bool DtbschedmgrDeviceInfoStorage::GetLocalDeviceId(std::string& networkId)
|
||||
{
|
||||
return GetLocalDeviceFromDnet(networkId);
|
||||
}
|
||||
|
||||
bool DtbschedmgrDeviceInfoStorage::GetLocalUdid(std::string& udid)
|
||||
{
|
||||
return GetLocalDeviceUdid(udid);
|
||||
}
|
||||
|
||||
bool DtbschedmgrDeviceInfoStorage::GetLocalDeviceFromDnet(std::string& networkId)
|
||||
{
|
||||
auto dnetworkAdapter = DnetworkAdapter::GetInstance();
|
||||
@ -212,6 +272,23 @@ bool DtbschedmgrDeviceInfoStorage::GetLocalDeviceFromDnet(std::string& networkId
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DtbschedmgrDeviceInfoStorage::GetLocalDeviceUdid(std::string& udid)
|
||||
{
|
||||
auto dnetworkAdapter = DnetworkAdapter::GetInstance();
|
||||
if (dnetworkAdapter == nullptr) {
|
||||
HILOGE("GetLocalDeviceFromDnet dnetworkAdapter null");
|
||||
return false;
|
||||
}
|
||||
DmDeviceInfo dmDeviceInfo;
|
||||
if (!dnetworkAdapter->GetLocalBasicInfo(dmDeviceInfo)) {
|
||||
HILOGE("GetLocalBasicInfo error");
|
||||
return false;
|
||||
}
|
||||
udid = GetUuidByNetworkId(dmDeviceInfo.networkId);
|
||||
HILOGI("GetLocalDeviceUdid = %{public}s", DnetworkAdapter::AnonymizeNetworkId(udid).c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
void DtbschedmgrDeviceInfoStorage::ClearAllDevices()
|
||||
{
|
||||
lock_guard<mutex> autoLock(deviceLock_);
|
||||
@ -324,6 +401,17 @@ void DtbschedmgrDeviceInfoStorage::OnDeviceInfoChanged(const std::string& device
|
||||
HILOGI("OnDeviceInfoChanged called");
|
||||
}
|
||||
|
||||
void DtbschedmgrDeviceInfoStorage::SyncCallback::OnSyncCompleted(const std::map<std::string,
|
||||
OHOS::DistributedDeviceProfile::SyncStatus> &syncResults)
|
||||
{
|
||||
for (const auto &item : syncResults) {
|
||||
std::string networkId = item.first;
|
||||
int32_t syncResult = item.second;
|
||||
HILOGI("networkId: %{public}s, SyncStatus: %{public}d",
|
||||
DnetworkAdapter::AnonymizeNetworkId(networkId).c_str(), syncResult);
|
||||
}
|
||||
}
|
||||
|
||||
void DnetServiceDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
HILOGI("OnRemoteDied dnetwork service died");
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2021-2024 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
|
||||
@ -47,7 +47,8 @@ dsched_external_deps = [
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"device_auth:deviceauth_sdk",
|
||||
"device_info_manager:distributed_device_profile_client",
|
||||
"device_info_manager:distributed_device_profile_common",
|
||||
"device_info_manager:distributed_device_profile_sdk",
|
||||
"device_manager:devicemanagersdk",
|
||||
"device_security_level:dslm_sdk",
|
||||
"distributed_bundle_framework:dbms_fwk",
|
||||
@ -536,6 +537,7 @@ ohos_unittest("dmsbasetest") {
|
||||
":test_config",
|
||||
"./resource:coverage_flags",
|
||||
]
|
||||
deps = [ "//third_party/cJSON:cjson" ]
|
||||
configs += dsched_configs
|
||||
if (is_standard_system) {
|
||||
external_deps = dsched_external_deps
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2024 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
|
||||
@ -399,5 +399,36 @@ HWTEST_F(DtbschedmgrDeviceInfoStorageTest, UpdateDeviceInfoStorageTest_002, Test
|
||||
EXPECT_EQ(!dmDeviceInfoList.empty(), true);
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest UpdateDeviceInfoStorageTest_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetLocalDeviceUdidTest_001
|
||||
* @tc.desc: test GetLocalDeviceUdid
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetLocalDeviceUdidTest_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetLocalDeviceUdidTest_001 start" << std::endl;
|
||||
std::string udid = "";
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalUdid(udid);
|
||||
EXPECT_EQ(udid.empty(), true);
|
||||
DistributedSchedUtil::MockPermission();
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalUdid(udid);
|
||||
EXPECT_EQ(!udid.empty(), true);
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetLocalDeviceUdidTest_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SyncDmsVersionInfoToRemoteTest_001
|
||||
* @tc.desc: test SyncDmsVersionInfoToRemote
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DtbschedmgrDeviceInfoStorageTest, SyncDmsVersionInfoToRemoteTest_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest SyncDmsVersionInfoToRemoteTest_001 start" << std::endl;
|
||||
std::string remoteNetworkId = "test";
|
||||
int32_t result = DtbschedmgrDeviceInfoStorage::GetInstance().SyncDmsVersionInfoToRemote(remoteNetworkId);
|
||||
EXPECT_TRUE(result != DistributedDeviceProfile::DP_SUCCESS);
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest SyncDmsVersionInfoToRemoteTest_001 end" << std::endl;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user