!787 dms适配dp最新修改

Merge pull request !787 from hunili/master
This commit is contained in:
openharmony_ci 2024-01-24 12:26:13 +00:00 committed by Gitee
commit 3158d0462e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 29 additions and 100 deletions

View File

@ -20,7 +20,12 @@ namespace OHOS {
namespace DistributedSchedule {
namespace Constants {
constexpr const char* DMS_NAME = "dmsfwk";
constexpr const char* DMS_VERSION = "4.0.0";
constexpr const char* DMS_VERSION = "4.1.0";
constexpr const char* DMS_SERVICE_ID = "dmsfwk_svr_id";
constexpr const char* DMS_CHAR_ID = "dmsInfo";
constexpr const char* PACKAGE_NAMES = "packageNames";
constexpr const char* VERSIONS = "versions";
constexpr const char* DMS_SERVICE_TYPE = "appInfo";
} // Constants
} // DistributedSchedule
} // OHOS

View File

@ -28,6 +28,7 @@ config("distributed_sched_config") {
"${communication_path}/dsoftbus/dsoftbus_enhance/interfaces/kits/broadcast",
"${communication_path}/dsoftbus/interfaces/kits/common",
"${dms_path}/interfaces/kits/napi/include",
"${dms_path}/interfaces/innerkits/common/include",
"include/distributedWant",
"//third_party/cJSON",
]

View File

@ -25,7 +25,6 @@
#include "event_handler.h"
#include "iremote_object.h"
#include "single_instance.h"
#include "sync_completed_callback_stub.h"
namespace OHOS {
namespace DistributedSchedule {
@ -63,6 +62,13 @@ public:
*/
std::string GetUuidByNetworkId(const std::string& networkId);
/**
* get udid by networkId
*
* @param networkId
*/
std::string GetUdidByNetworkId(const std::string& networkId);
/**
* get networkId by uuid
*
@ -84,13 +90,6 @@ 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();
@ -108,9 +107,6 @@ 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

View File

@ -78,7 +78,6 @@ void DnetworkAdapter::DmsDeviceStateCallback::OnDeviceOnline(const DmDeviceInfo&
HILOGE("OnNodeOnline post task failed");
return;
}
DtbschedmgrDeviceInfoStorage::GetInstance().SyncDmsVersionInfoToRemote(networkId);
}
void DnetworkAdapter::DmsDeviceStateCallback::OnDeviceOffline(const DmDeviceInfo& deviceInfo)

View File

@ -16,6 +16,7 @@
#include "dms_version_manager.h"
#include "distributed_device_profile_client.h"
#include "dms_constant.h"
#include "dtbschedmgr_device_info_storage.h"
#include "dtbschedmgr_log.h"
#include "nlohmann/json.hpp"
@ -23,14 +24,11 @@
namespace OHOS {
namespace DistributedSchedule {
using namespace Constants;
namespace {
const std::string TAG = "DmsVersionManager";
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";
const std::string DMS_NAME = "dmsfwk";
const int32_t DMS_VERSION_LENGTH = 3;
const int32_t DMS_MAJOR_VERSION_INDEX = 0;
const int32_t DMS_MINOR_VERSION_INDEX = 1;
@ -81,7 +79,7 @@ int32_t DmsVersionManager::GetAppInfoFromDP(const std::string& deviceId, std::st
{
DistributedDeviceProfile::CharacteristicProfile profile;
std::string udid = "";
udid = DtbschedmgrDeviceInfoStorage::GetInstance().GetUuidByNetworkId(deviceId);
udid = DtbschedmgrDeviceInfoStorage::GetInstance().GetUdidByNetworkId(deviceId);
int32_t result = DistributedDeviceProfile::DistributedDeviceProfileClient::GetInstance().GetCharacteristicProfile(
udid, DMS_SERVICE_ID, DMS_CHAR_ID, profile);
if (result != ERR_OK) {

View File

@ -19,13 +19,11 @@
#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;
@ -33,18 +31,11 @@ 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.1.0";
const std::string DMS_NAMES = "dmsfwk";
constexpr const char *PACKAGE_NAMES = "packageNames";
constexpr const char *VERSIONS = "versions";
}
IMPLEMENT_SINGLE_INSTANCE(DtbschedmgrDeviceInfoStorage);
@ -198,52 +189,6 @@ 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);
@ -326,6 +271,16 @@ std::string DtbschedmgrDeviceInfoStorage::GetUuidByNetworkId(const std::string&
return uuid;
}
std::string DtbschedmgrDeviceInfoStorage::GetUdidByNetworkId(const std::string& networkId)
{
if (networkId.empty()) {
HILOGW("GetUdidByNetworkId networkId empty!");
return "";
}
std::string udid = DnetworkAdapter::GetInstance()->GetUdidByNetworkId(networkId);
return udid;
}
std::string DtbschedmgrDeviceInfoStorage::GetNetworkIdByUuid(const std::string& uuid)
{
if (uuid.empty()) {
@ -401,17 +356,6 @@ 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");

View File

@ -416,19 +416,5 @@ HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetLocalDeviceUdidTest_001, TestSize.
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