解决迁移兼容性问题

Signed-off-by: wangyang2022 <wangyang412@huawei.com>
Change-Id: I39a19a7a964c99fac201acad0f6b5534eca12502
This commit is contained in:
wangyang2022 2022-09-24 10:34:53 +08:00
parent e747c5a65b
commit ae941de86d
9 changed files with 248 additions and 6 deletions

View File

@ -38,6 +38,7 @@
"bundle_framework",
"c_utils",
"device_auth",
"device_info_manager",
"distributeddatamgr",
"dsoftbus",
"eventhandler",

View File

@ -17,6 +17,7 @@ config("common_public_config") {
visibility = [ ":*" ]
include_dirs = [
"include/",
"//foundation/ability/dmsfwk/interfaces/innerkits/continuation_manager/include/",
"//foundation/ability/dmsfwk/services/base/include",
"//foundation/ability/dmsfwk/services/dtbabilitymgr/include/",
"//foundation/ability/dmsfwk/utils/native/include/",

View File

@ -30,6 +30,7 @@ ohos_shared_library("dmsbaseinner") {
"src/dfx/dms_hisysevent_report.cpp",
"src/dfx/dms_hitrace_chain.cpp",
"src/distributed_device_node_listener.cpp",
"src/dms_version_manager.cpp",
"src/dtbschedmgr_device_info_storage.cpp",
]
public_configs = [
@ -39,6 +40,7 @@ ohos_shared_library("dmsbaseinner") {
external_deps = [
"c_utils:utils",
"device_info_manager:distributed_device_profile_client",
"device_manager:devicemanagersdk",
"dsoftbus:softbus_client",
"eventhandler:libeventhandler",

View File

@ -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.
*/
#ifndef OHOS_DMS_VERSION_MANAGER_H
#define OHOS_DMS_VERSION_MANAGER_H
#include <string>
#include "ipc_skeleton.h"
namespace OHOS {
namespace DistributedSchedule {
#define IN_PROCESS_CALL(theCall) \
([&]() { \
std::string identity = IPCSkeleton::ResetCallingIdentity(); \
auto retVal = theCall; \
IPCSkeleton::SetCallingIdentity(identity); \
return retVal; \
}())
struct DmsVersion {
uint32_t majorVersionNum = 0;
uint32_t minorVersionNum = 0;
uint32_t featureVersionNum = 0;
};
class DmsVersionManager {
public:
static bool IsRemoteDmsVersionLower(const std::string& remoteDeviceId, const DmsVersion& thresholdDmsVersion);
private:
static int32_t GetRemoteDmsVersion(const std::string& deviceId, DmsVersion& dmsVersion);
static int32_t GetAppInfoFromDP(const std::string& deviceId, std::string& packageNamesData,
std::string& versionsData);
static int32_t GetDmsVersionDataFromAppInfo(const std::string& packageNamesData, const std::string& versionsData,
std::string& dmsVersionData);
static bool ParseDmsVersion(const std::string& dmsVersionData, DmsVersion& dmsVersion);
static bool CompareDmsVersion(const DmsVersion& dmsVersion, const DmsVersion& thresholdDmsVersion);
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DMS_VERSION_MANAGER_H

View File

@ -405,6 +405,14 @@ enum {
* Result(29360216) for invalid continuation mode.
*/
INVALID_CONTINUATION_MODE = 29360216,
/**
* Result(29360217) for dms version is empty.
*/
DMS_VERSION_EMPTY = 29360217,
/**
* Result(29360218) for DistributedSched Service parse dms version error.
*/
DMS_VERSION_PARSE_EXCEPTION = 29360218,
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -0,0 +1,162 @@
/*
* 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 "dms_version_manager.h"
#include "distributed_device_profile_client.h"
#include "dtbschedmgr_log.h"
#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_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;
const int32_t DMS_FEATURE_VERSION_INDEX = 2;
}
bool DmsVersionManager::IsRemoteDmsVersionLower(const std::string& remoteDeviceId,
const DmsVersion& thresholdDmsVersion)
{
DmsVersion dmsVersion;
int32_t result = GetRemoteDmsVersion(remoteDeviceId, dmsVersion);
if (result != ERR_OK) {
return true;
}
return CompareDmsVersion(dmsVersion, thresholdDmsVersion);
}
int32_t DmsVersionManager::GetRemoteDmsVersion(const std::string& deviceId, DmsVersion& dmsVersion)
{
std::string packageNamesData;
std::string versionsData;
int32_t result = GetAppInfoFromDP(deviceId, packageNamesData, versionsData);
if (result != ERR_OK) {
HILOGI("get app info failed, result: %{public}d!", result);
return result;
}
std::string dmsVersionData;
result = GetDmsVersionDataFromAppInfo(packageNamesData, versionsData, dmsVersionData);
if (result != ERR_OK) {
HILOGW("get dms version data failed, result: %{public}d!", result);
return result;
}
if (!ParseDmsVersion(dmsVersionData, dmsVersion)) {
HILOGE("parse dms version failed");
return DMS_VERSION_PARSE_EXCEPTION;
}
return ERR_OK;
}
int32_t DmsVersionManager::GetAppInfoFromDP(const std::string& deviceId, std::string& packageNamesData,
std::string& versionsData)
{
DeviceProfile::ServiceCharacteristicProfile profile;
int32_t result = IN_PROCESS_CALL(
DeviceProfile::DistributedDeviceProfileClient::GetInstance().GetDeviceProfile(deviceId,
DMS_SERVICE_ID, profile)
);
if (result != ERR_OK) {
return result;
}
std::string jsonData = profile.GetCharacteristicProfileJson();
if (jsonData.empty()) {
return DMS_VERSION_EMPTY;
}
nlohmann::json dpJson = nlohmann::json::parse(jsonData.c_str(), nullptr, false);
if (dpJson.find(PACKAGE_NAMES) != dpJson.end() && dpJson.at(PACKAGE_NAMES).is_string()) {
dpJson.at(PACKAGE_NAMES).get_to(packageNamesData);
}
if (dpJson.find(VERSIONS) != dpJson.end() && dpJson.at(VERSIONS).is_string()) {
dpJson.at(VERSIONS).get_to(versionsData);
}
return ERR_OK;
}
int32_t DmsVersionManager::GetDmsVersionDataFromAppInfo(const std::string& packageNamesData,
const std::string& versionsData, std::string& dmsVersionData)
{
if (packageNamesData.empty() || versionsData.empty()) {
return DMS_VERSION_EMPTY;
}
std::vector<std::string> packageNameList;
std::vector<std::string> versionsList;
SplitStr(packageNamesData, ",", packageNameList);
SplitStr(versionsData, ",", versionsList);
if (packageNameList.size() != versionsList.size()) {
return DMS_VERSION_PARSE_EXCEPTION;
}
for (std::size_t i = 0; i < packageNameList.size(); i++) {
if (packageNameList[i] == DMS_NAME) {
dmsVersionData = versionsList[i];
return ERR_OK;
}
}
return DMS_VERSION_EMPTY;
}
bool DmsVersionManager::ParseDmsVersion(const std::string& dmsVersionData, DmsVersion& dmsVersion)
{
std::vector<std::string> versionNumList;
SplitStr(dmsVersionData, ".", versionNumList);
if (versionNumList.size() != DMS_VERSION_LENGTH) {
return false;
}
int32_t majorVersionNum = -1;
if (!OHOS::StrToInt(versionNumList[DMS_MAJOR_VERSION_INDEX], majorVersionNum) || majorVersionNum < 0) {
return false;
}
dmsVersion.majorVersionNum = majorVersionNum;
int32_t minorVersionNum = -1;
if (!OHOS::StrToInt(versionNumList[DMS_MINOR_VERSION_INDEX], minorVersionNum) || minorVersionNum < 0) {
return false;
}
dmsVersion.minorVersionNum = minorVersionNum;
int32_t featureVersionNum = -1;
if (!OHOS::StrToInt(versionNumList[DMS_FEATURE_VERSION_INDEX], featureVersionNum) || featureVersionNum < 0) {
return false;
}
dmsVersion.featureVersionNum = featureVersionNum;
return true;
}
bool DmsVersionManager::CompareDmsVersion(const DmsVersion& dmsVersion, const DmsVersion& thresholdDmsVersion)
{
if (dmsVersion.majorVersionNum < thresholdDmsVersion.majorVersionNum) {
return true;
}
if (dmsVersion.majorVersionNum == thresholdDmsVersion.majorVersionNum &&
dmsVersion.minorVersionNum < thresholdDmsVersion.minorVersionNum) {
return true;
}
if (dmsVersion.majorVersionNum == thresholdDmsVersion.majorVersionNum &&
dmsVersion.minorVersionNum == thresholdDmsVersion.minorVersionNum &&
dmsVersion.featureVersionNum < thresholdDmsVersion.featureVersionNum) {
return true;
}
return false;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -26,6 +26,9 @@ namespace DistributedSchedule {
namespace {
constexpr int32_t VALUE_NULL = -1; // no object in parcel
constexpr int32_t VALUE_OBJECT = 1; // object exist in parcel
constexpr const char* DMS_NAME = "dmsfwk";
constexpr const char* DMS_VERSION = "3.2.0";
}
class IDistributedAbilityManager : public OHOS::IRemoteBroker {
public:

View File

@ -176,6 +176,8 @@ private:
int32_t SetWantForContinuation(AAFwk::Want& newWant, int32_t missionId);
int32_t ContinueLocalMission(const std::string& dstDeviceId, int32_t missionId,
const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams);
int32_t ContinueAbilityWithTimeout(const std::string& dstDeviceId, int32_t missionId,
const sptr<IRemoteObject>& callback, uint32_t remoteBundleVersion = 0);
int32_t ContinueRemoteMission(const std::string& srcDeviceId, const std::string& dstDeviceId, int32_t missionId,
const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams);
int32_t TryStartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,

View File

@ -32,6 +32,7 @@
#include "dms_callback_task.h"
#include "dms_free_install_callback.h"
#include "dms_token_callback.h"
#include "dms_version_manager.h"
#include "dtbschedmgr_device_info_storage.h"
#include "dtbschedmgr_log.h"
#include "element_name.h"
@ -319,6 +320,11 @@ int32_t DistributedSchedService::ContinueLocalMission(const std::string& dstDevi
HILOGE("ContinueLocalMission already in progress!");
return INVALID_PARAMETERS_ERR;
}
DmsVersion thresholdDmsVersion = {3, 2, 0};
if (DmsVersionManager::IsRemoteDmsVersionLower(dstDeviceId, thresholdDmsVersion)) {
HILOGI("remote dms is low version");
return ContinueAbilityWithTimeout(dstDeviceId, missionId, callback);
}
MissionInfo missionInfo;
int32_t result = AbilityManagerClient::GetInstance()->GetMissionInfo("", missionId, missionInfo);
@ -333,12 +339,7 @@ int32_t DistributedSchedService::ContinueLocalMission(const std::string& dstDevi
result = BundleManagerInternal::CheckRemoteBundleInfoForContinuation(dstDeviceId,
bundleName, remoteBundleInfo);
if (result == ERR_OK) {
dschedContinuation_->PushCallback(missionId, callback, dstDeviceId, false);
SetContinuationTimeout(missionId, CONTINUATION_TIMEOUT);
uint32_t remoteBundleVersion = remoteBundleInfo.versionCode;
result = AbilityManagerClient::GetInstance()->ContinueAbility(dstDeviceId, missionId, remoteBundleVersion);
HILOGI("result: %{public}d!", result);
return result;
return ContinueAbilityWithTimeout(dstDeviceId, missionId, callback, remoteBundleInfo.versionCode);
}
if (result == CONTINUE_REMOTE_UNINSTALLED_UNSUPPORT_FREEINSTALL) {
HILOGE("remote not installed and app not support free install");
@ -364,6 +365,16 @@ int32_t DistributedSchedService::ContinueLocalMission(const std::string& dstDevi
return ERR_OK;
}
int32_t DistributedSchedService::ContinueAbilityWithTimeout(const std::string& dstDeviceId, int32_t missionId,
const sptr<IRemoteObject>& callback, uint32_t remoteBundleVersion)
{
dschedContinuation_->PushCallback(missionId, callback, dstDeviceId, false);
SetContinuationTimeout(missionId, CONTINUATION_TIMEOUT);
int32_t result = AbilityManagerClient::GetInstance()->ContinueAbility(dstDeviceId, missionId, remoteBundleVersion);
HILOGI("result: %{public}d!", result);
return result;
}
int32_t DistributedSchedService::ContinueRemoteMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
int32_t missionId, const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams)
{