mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 22:39:58 +00:00
Merge branch 'master' of gitee.com:openharmony/ability_dmsfwk into 0924
Signed-off-by: ql <qianli16@huawei.com>
This commit is contained in:
commit
079ab024f3
@ -38,6 +38,7 @@
|
||||
"bundle_framework",
|
||||
"c_utils",
|
||||
"device_auth",
|
||||
"device_info_manager",
|
||||
"distributeddatamgr",
|
||||
"dsoftbus",
|
||||
"eventhandler",
|
||||
@ -100,8 +101,10 @@
|
||||
}
|
||||
],
|
||||
"test": [
|
||||
"//foundation/ability/dmsfwk/services/base:unittest",
|
||||
"//foundation/ability/dmsfwk/services/dtbschedmgr:unittest",
|
||||
"//foundation/ability/dmsfwk/services/dtbabilitymgr:unittest"
|
||||
"//foundation/ability/dmsfwk/services/dtbabilitymgr:unittest",
|
||||
"//foundation/ability/dmsfwk/test/fuzztest/continuationmanager_fuzzer:fuzztest"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -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/",
|
||||
|
@ -16,7 +16,7 @@ import("//build/ohos.gni")
|
||||
config("continuationmanager_napi_public_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"include/",
|
||||
"//foundation/ability/dmsfwk/interfaces/kits/napi/include",
|
||||
"//foundation/ability/dmsfwk/services/base/include",
|
||||
]
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "napi_error_code.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
@ -34,7 +35,22 @@ constexpr int32_t ARG_COUNT_ONE = 1;
|
||||
constexpr int32_t ARG_COUNT_TWO = 2;
|
||||
constexpr int32_t ARG_COUNT_THREE = 3;
|
||||
constexpr uint32_t MAX_JSPROCOUNT = 1000000;
|
||||
constexpr int32_t ARG_COUNT_FOUR = 4;
|
||||
constexpr int32_t PARAMETER_CHECK_FAILED = 401;
|
||||
}
|
||||
static const std::map<int32_t, int32_t> DMS_ERROR_CODE_MAP = {
|
||||
{ ERR_OK, ERR_OK },
|
||||
{ ERR_NULL_OBJECT, SYSTEM_WORK_ABNORMALLY },
|
||||
{ ERR_FLATTEN_OBJECT, SYSTEM_WORK_ABNORMALLY },
|
||||
{ CONNECT_ABILITY_FAILED, SYSTEM_WORK_ABNORMALLY },
|
||||
{ INVALID_CONTINUATION_MODE, INVALID_INPUT_PARAMETER },
|
||||
{ UNKNOWN_CALLBACK_TYPE, INVALID_INPUT_PARAMETER },
|
||||
{ INVALID_CONNECT_STATUS, INVALID_INPUT_PARAMETER },
|
||||
{ CALLBACK_HAS_NOT_REGISTERED, CALLBACK_TOKEN_UNREGISTERED },
|
||||
{ TOKEN_HAS_NOT_REGISTERED, CALLBACK_TOKEN_UNREGISTERED },
|
||||
{ REGISTER_EXCEED_MAX_TIMES, REGISTER_EXCEED_MAX_TIMES },
|
||||
{ CALLBACK_HAS_REGISTERED, REPEATED_REGISTRATION },
|
||||
};
|
||||
|
||||
void JsContinuationManager::Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
@ -94,6 +110,30 @@ NativeValue *JsContinuationManager::InitContinuationModeObject(NativeEngine *eng
|
||||
return (me != nullptr) ? me->OnInitContinuationModeObject(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::RegisterContinuation(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsContinuationManager* me = CheckParamsAndGetThis<JsContinuationManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnRegisterContinuation(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::UnregisterContinuation(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsContinuationManager* me = CheckParamsAndGetThis<JsContinuationManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnUnregisterContinuation(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::UpdateContinuationState(NativeEngine* engine, NativeCallbackInfo *info)
|
||||
{
|
||||
JsContinuationManager *me = CheckParamsAndGetThis<JsContinuationManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnUpdateContinuationState(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::StartContinuationDeviceManager(NativeEngine* engine, NativeCallbackInfo *info)
|
||||
{
|
||||
JsContinuationManager *me = CheckParamsAndGetThis<JsContinuationManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnStartContinuationDeviceManager(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::OnRegister(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOGD("called.");
|
||||
@ -132,6 +172,51 @@ NativeValue* JsContinuationManager::OnRegister(NativeEngine &engine, NativeCallb
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::OnRegisterContinuation(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOGD("called.");
|
||||
decltype(info.argc) unwrapArgc = 0;
|
||||
std::shared_ptr<ContinuationExtraParams> continuationExtraParams;
|
||||
std::string errInfo = [this, &engine, &info, &continuationExtraParams, &unwrapArgc]() -> std::string {
|
||||
if (info.argc > ARG_COUNT_TWO) {
|
||||
return "Parameter error. The type of \"number of parameters\" must be less than 3";
|
||||
}
|
||||
if (info.argc > 0 && info.argv[0]->TypeOf() == NATIVE_OBJECT) {
|
||||
HILOGI("register options is used.");
|
||||
continuationExtraParams = std::make_shared<ContinuationExtraParams>();
|
||||
if (!UnWrapContinuationExtraParams(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[0]), continuationExtraParams)) {
|
||||
return "Parameter error. The type of \"options\" must be ContinuationExtraParams";
|
||||
}
|
||||
unwrapArgc++;
|
||||
}
|
||||
return std::string();
|
||||
} ();
|
||||
if (!errInfo.empty()) {
|
||||
HILOGE("%{public}s", errInfo.c_str());
|
||||
napi_throw_error(reinterpret_cast<napi_env>(&engine),
|
||||
std::to_string(PARAMETER_CHECK_FAILED).c_str(), errInfo.c_str());
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[this, continuationExtraParams, unwrapArgc](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
int32_t token = -1;
|
||||
int32_t ret = (unwrapArgc == 0) ? DistributedAbilityManagerClient::GetInstance().Register(nullptr, token) :
|
||||
DistributedAbilityManagerClient::GetInstance().Register(continuationExtraParams, token);
|
||||
if (ret == ERR_OK) {
|
||||
task.Resolve(engine, engine.CreateNumber(token));
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, ErrorCodeReturn(ret), "RegisterContinuation failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= unwrapArgc) ? nullptr : info.argv[unwrapArgc];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule("JsContinuationManager::OnRegisterContinuation",
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::OnUnregister(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOGD("called.");
|
||||
@ -166,50 +251,102 @@ NativeValue* JsContinuationManager::OnUnregister(NativeEngine &engine, NativeCal
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::OnUnregisterContinuation(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOGD("called.");
|
||||
int32_t token = -1;
|
||||
std::string errInfo = [this, &engine, &info, &token]() -> std::string {
|
||||
if (info.argc == 0 || info.argc > ARG_COUNT_TWO) {
|
||||
return "Parameter error. The type of \"number of parameters\" must be greater than 0 and less than 3";
|
||||
}
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], token)) {
|
||||
return "Parameter error. The type of \"token\" must be number";
|
||||
}
|
||||
return std::string();
|
||||
} ();
|
||||
if (!errInfo.empty()) {
|
||||
HILOGE("%{public}s", errInfo.c_str());
|
||||
napi_throw_error(reinterpret_cast<napi_env>(&engine),
|
||||
std::to_string(PARAMETER_CHECK_FAILED).c_str(), errInfo.c_str());
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[this, token](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
int32_t ret = DistributedAbilityManagerClient::GetInstance().Unregister(token);
|
||||
if (ret == ERR_OK) {
|
||||
task.Resolve(engine, engine.CreateNull());
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, ErrorCodeReturn(ret), "UnregisterContinuation failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc == ARG_COUNT_ONE) ? nullptr : info.argv[ARG_COUNT_ONE];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule("JsContinuationManager::OnUnregisterContinuation",
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string JsContinuationManager::OnRegisterDeviceSelectionCallbackParameterCheck(NativeEngine &engine,
|
||||
NativeCallbackInfo &info, std::string &cbType, int32_t &token, NativeValue** jsListenerObj)
|
||||
{
|
||||
if (info.argc != ARG_COUNT_THREE) {
|
||||
return "Parameter error. The type of \"number of parameters\" must be 3";
|
||||
}
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
return "Parameter error. The type of \"type\" must be " +
|
||||
std::string(EVENT_CONNECT) + " or " + std::string(EVENT_DISCONNECT);;
|
||||
}
|
||||
if (!ConvertFromJsValue(engine, info.argv[ARG_COUNT_ONE], token)) {
|
||||
return "Parameter error. The type of \"token\" must be number";
|
||||
}
|
||||
*jsListenerObj = info.argv[ARG_COUNT_TWO];
|
||||
if (!IsCallbackValid(*jsListenerObj)) {
|
||||
return "Parameter error. The type of \"callback\" must be Callback<Array<ContinuationResult>>";
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::OnRegisterDeviceSelectionCallback(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOGD("called.");
|
||||
if (info.argc != ARG_COUNT_THREE) {
|
||||
HILOGE("Params not match");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::string cbType;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
HILOGE("Parse cbType failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
int32_t token = -1;
|
||||
if (!ConvertFromJsValue(engine, info.argv[ARG_COUNT_ONE], token)) {
|
||||
HILOGE("Parse token failed");
|
||||
return engine.CreateUndefined();
|
||||
int32_t errCode = PARAMETER_CHECK_FAILED;
|
||||
NativeValue* jsListenerObj = nullptr;
|
||||
std::string errInfo = OnRegisterDeviceSelectionCallbackParameterCheck(engine, info, cbType, token, &jsListenerObj);
|
||||
if (errInfo.empty()) {
|
||||
errInfo = [this, &engine, &info, &cbType, &token, &jsListenerObj, &errCode]() -> std::string {
|
||||
std::lock_guard<std::mutex> jsCbMapLock(jsCbMapMutex_);
|
||||
if (IsCallbackRegistered(token, cbType)) {
|
||||
errCode = CALLBACK_TOKEN_UNREGISTERED;
|
||||
return "UnregisterDeviceSelectionCallback Callback is not registered";
|
||||
}
|
||||
std::unique_ptr<NativeReference> callbackRef;
|
||||
callbackRef.reset(engine.CreateReference(jsListenerObj, 1));
|
||||
sptr<JsDeviceSelectionListener> deviceSelectionListener = new JsDeviceSelectionListener(&engine);
|
||||
if (deviceSelectionListener == nullptr) {
|
||||
errCode = SYSTEM_WORK_ABNORMALLY;
|
||||
return "deviceSelectionListener is nullptr";
|
||||
}
|
||||
int32_t ret = DistributedAbilityManagerClient::GetInstance().RegisterDeviceSelectionCallback(
|
||||
token, cbType, deviceSelectionListener);
|
||||
if (ret == ERR_OK) {
|
||||
deviceSelectionListener->AddCallback(cbType, jsListenerObj);
|
||||
CallbackPair callbackPair = std::make_pair(std::move(callbackRef), deviceSelectionListener);
|
||||
jsCbMap_[token][cbType] = std::move(callbackPair); // move assignment
|
||||
HILOGI("RegisterDeviceSelectionListener success");
|
||||
} else {
|
||||
deviceSelectionListener = nullptr;
|
||||
errCode = SYSTEM_WORK_ABNORMALLY;
|
||||
return "RegisterDeviceSelectionListener failed";
|
||||
}
|
||||
return std::string();
|
||||
}();
|
||||
}
|
||||
NativeValue* jsListenerObj = info.argv[ARG_COUNT_TWO];
|
||||
if (!IsCallbackValid(jsListenerObj)) {
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> jsCbMapLock(jsCbMapMutex_);
|
||||
if (IsCallbackRegistered(token, cbType)) {
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::unique_ptr<NativeReference> callbackRef;
|
||||
callbackRef.reset(engine.CreateReference(jsListenerObj, 1));
|
||||
sptr<JsDeviceSelectionListener> deviceSelectionListener = new JsDeviceSelectionListener(&engine);
|
||||
if (deviceSelectionListener == nullptr) {
|
||||
HILOGE("deviceSelectionListener is nullptr");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
int32_t ret = DistributedAbilityManagerClient::GetInstance().RegisterDeviceSelectionCallback(
|
||||
token, cbType, deviceSelectionListener);
|
||||
if (ret == ERR_OK) {
|
||||
deviceSelectionListener->AddCallback(cbType, jsListenerObj);
|
||||
CallbackPair callbackPair = std::make_pair(std::move(callbackRef), deviceSelectionListener);
|
||||
jsCbMap_[token][cbType] = std::move(callbackPair); // move assignment
|
||||
HILOGI("RegisterDeviceSelectionListener success");
|
||||
} else {
|
||||
deviceSelectionListener = nullptr;
|
||||
HILOGE("RegisterDeviceSelectionListener failed");
|
||||
}
|
||||
if (!errInfo.empty()) {
|
||||
HILOGE("%{public}s", errInfo.c_str());
|
||||
napi_throw_error(reinterpret_cast<napi_env>(&engine), std::to_string(errCode).c_str(), errInfo.c_str());
|
||||
}
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
@ -217,42 +354,48 @@ NativeValue* JsContinuationManager::OnRegisterDeviceSelectionCallback(NativeEngi
|
||||
NativeValue* JsContinuationManager::OnUnregisterDeviceSelectionCallback(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOGD("called.");
|
||||
if (info.argc != ARG_COUNT_TWO) {
|
||||
HILOGE("Params not match");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::string cbType;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
HILOGE("Parse cbType failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (cbType != EVENT_CONNECT && cbType != EVENT_DISCONNECT) {
|
||||
HILOGE("type: %{public}s not support!", cbType.c_str());
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
int32_t token = -1;
|
||||
if (!ConvertFromJsValue(engine, info.argv[ARG_COUNT_ONE], token)) {
|
||||
HILOGE("Parse token failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> jsCbMapLock(jsCbMapMutex_);
|
||||
if (!IsCallbackRegistered(token, cbType)) {
|
||||
return engine.CreateUndefined();
|
||||
int32_t errCode = PARAMETER_CHECK_FAILED;
|
||||
std::string errInfo = [this, &engine, &info, &cbType, &token, &errCode]() -> std::string {
|
||||
if (info.argc != ARG_COUNT_TWO) {
|
||||
return "Parameter error. The type of \"number of parameters\" must be 2";
|
||||
}
|
||||
CallbackPair& callbackPair = jsCbMap_[token][cbType];
|
||||
auto& listener = callbackPair.second;
|
||||
int32_t ret = DistributedAbilityManagerClient::GetInstance().UnregisterDeviceSelectionCallback(token, cbType);
|
||||
if (ret == ERR_OK) {
|
||||
listener->RemoveCallback(cbType);
|
||||
jsCbMap_[token].erase(cbType);
|
||||
if (jsCbMap_[token].empty()) {
|
||||
jsCbMap_.erase(token);
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
return "Parameter error. The type of \"type\" must be string";
|
||||
}
|
||||
if (cbType != EVENT_CONNECT && cbType != EVENT_DISCONNECT) {
|
||||
return "Parameter error. The type of \"type\" must be " +
|
||||
std::string(EVENT_CONNECT) + " or " + std::string(EVENT_DISCONNECT);
|
||||
}
|
||||
if (!ConvertFromJsValue(engine, info.argv[ARG_COUNT_ONE], token)) {
|
||||
return "Parameter error. The type of \"token\" must be string";
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> jsCbMapLock(jsCbMapMutex_);
|
||||
if (!IsCallbackRegistered(token, cbType)) {
|
||||
errCode = REPEATED_REGISTRATION;
|
||||
return "UnregisterDeviceSelectionCallback Callback is not registered";
|
||||
}
|
||||
errCode = DistributedAbilityManagerClient::GetInstance().UnregisterDeviceSelectionCallback(token, cbType);
|
||||
if (errCode == ERR_OK) {
|
||||
CallbackPair& callbackPair = jsCbMap_[token][cbType];
|
||||
callbackPair.second->RemoveCallback(cbType);
|
||||
jsCbMap_[token].erase(cbType);
|
||||
if (jsCbMap_[token].empty()) {
|
||||
jsCbMap_.erase(token);
|
||||
}
|
||||
HILOGI("UnregisterDeviceSelectionCallback success");
|
||||
} else {
|
||||
errCode = SYSTEM_WORK_ABNORMALLY;
|
||||
return "UnregisterDeviceSelectionCallback failed";
|
||||
}
|
||||
HILOGI("UnregisterDeviceSelectionCallback success");
|
||||
} else {
|
||||
HILOGE("UnregisterDeviceSelectionCallback failed");
|
||||
}
|
||||
return std::string();
|
||||
} ();
|
||||
if (!errInfo.empty()) {
|
||||
HILOGE("%{public}s", errInfo.c_str());
|
||||
napi_throw_error(reinterpret_cast<napi_env>(&engine), std::to_string(errCode).c_str(), errInfo.c_str());
|
||||
}
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
@ -302,6 +445,52 @@ NativeValue *JsContinuationManager::OnUpdateConnectStatus(NativeEngine &engine,
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::OnUpdateContinuationState(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOGD("called.");
|
||||
int32_t token = -1;
|
||||
std::string deviceId;
|
||||
DeviceConnectStatus deviceConnectStatus;
|
||||
std::string errInfo = [this, &engine, &info, &token, &deviceId, &deviceConnectStatus, &errInfo]() -> std::string {
|
||||
if (info.argc != ARG_COUNT_THREE && info.argc != ARG_COUNT_FOUR) {
|
||||
return "Parameter error. The type of \"number of parameters\" must be 3 or 4";
|
||||
}
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], token)) {
|
||||
return "Parameter error. The type of \"token\" must be number";
|
||||
}
|
||||
if (!ConvertFromJsValue(engine, info.argv[ARG_COUNT_ONE], deviceId)) {
|
||||
return "Parameter error. The type of \"deviceId\" must be string";
|
||||
}
|
||||
deviceConnectStatus = DeviceConnectStatus::IDLE;
|
||||
if (!ConvertFromJsValue(engine, info.argv[ARG_COUNT_TWO], deviceConnectStatus)) {
|
||||
return "Parameter error. The type of \"status\" must be DeviceConnectState";
|
||||
}
|
||||
return std::string();
|
||||
} ();
|
||||
if (!errInfo.empty()) {
|
||||
HILOGE("%{public}s", errInfo.c_str());
|
||||
napi_throw_error(reinterpret_cast<napi_env>(&engine),
|
||||
std::to_string(PARAMETER_CHECK_FAILED).c_str(), errInfo.c_str());
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[this, token, deviceId, deviceConnectStatus](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
int32_t ret = DistributedAbilityManagerClient::GetInstance().UpdateConnectStatus(
|
||||
token, deviceId, deviceConnectStatus);
|
||||
if (ret == ERR_OK) {
|
||||
task.Resolve(engine, engine.CreateNull());
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, ErrorCodeReturn(ret), "UpdateContinuationState failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc == ARG_COUNT_THREE) ? nullptr : info.argv[ARG_COUNT_THREE];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule("JsContinuationManager::OnUpdateContinuationState",
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue *JsContinuationManager::OnStartDeviceManager(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOGD("called.");
|
||||
@ -349,6 +538,55 @@ NativeValue *JsContinuationManager::OnStartDeviceManager(NativeEngine &engine, N
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::OnStartContinuationDeviceManager(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOGD("called.");
|
||||
int32_t token = -1;
|
||||
decltype(info.argc) unwrapArgc = ARG_COUNT_ONE;
|
||||
std::shared_ptr<ContinuationExtraParams> continuationExtraParams;
|
||||
std::string errInfo = [this, &engine, &info, &token, & unwrapArgc, &continuationExtraParams]() -> std::string {
|
||||
if (info.argc < ARG_COUNT_ONE || info.argc > ARG_COUNT_THREE) {
|
||||
return "Parameter error. The type of \"number of parameters\" must be greater than 1 and less than 4";
|
||||
}
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], token)) {
|
||||
return "Parameter error. The type of \"token\" must be number";
|
||||
}
|
||||
continuationExtraParams = std::make_shared<ContinuationExtraParams>();
|
||||
if (info.argc > ARG_COUNT_ONE && info.argv[ARG_COUNT_ONE]->TypeOf() == NATIVE_OBJECT) {
|
||||
HILOGI("StartContinuationDeviceManager options is used.");
|
||||
if (!UnWrapContinuationExtraParams(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[ARG_COUNT_ONE]), continuationExtraParams)) {
|
||||
return "Parameter error. The type of \"options\" must be ContinuationExtraParams";
|
||||
}
|
||||
unwrapArgc++;
|
||||
}
|
||||
return std::string();
|
||||
} ();
|
||||
if (!errInfo.empty()) {
|
||||
HILOGE("%{public}s", errInfo.c_str());
|
||||
napi_throw_error(reinterpret_cast<napi_env>(&engine),
|
||||
std::to_string(PARAMETER_CHECK_FAILED).c_str(), errInfo.c_str());
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[this, token, continuationExtraParams, unwrapArgc](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
int32_t ret = (unwrapArgc == ARG_COUNT_ONE) ?
|
||||
DistributedAbilityManagerClient::GetInstance().StartDeviceManager(token) :
|
||||
DistributedAbilityManagerClient::GetInstance().StartDeviceManager(token, continuationExtraParams);
|
||||
if (ret == ERR_OK) {
|
||||
task.Resolve(engine, engine.CreateNull());
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, ErrorCodeReturn(ret), "StartContinuationDeviceManager failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= unwrapArgc) ? nullptr : info.argv[unwrapArgc];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule("JsContinuationManager::OnStartContinuationDeviceManager",
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue *JsContinuationManager::OnInitDeviceConnectStateObject(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
napi_value object;
|
||||
@ -459,7 +697,7 @@ bool JsContinuationManager::UnWrapContinuationExtraParams(const napi_env& env, c
|
||||
}
|
||||
|
||||
bool JsContinuationManager::UnwrapJsonByPropertyName(const napi_env& env, const napi_value& param,
|
||||
const std::string& field, nlohmann::json& jsonObject)
|
||||
const std::string& field, nlohmann::json& jsonObj)
|
||||
{
|
||||
HILOGD("called.");
|
||||
if (!IsTypeForNapiValue(env, param, napi_object)) {
|
||||
@ -478,7 +716,7 @@ bool JsContinuationManager::UnwrapJsonByPropertyName(const napi_env& env, const
|
||||
uint32_t jsProCount = 0;
|
||||
napi_get_property_names(env, jsonField, &jsProNameList);
|
||||
napi_get_array_length(env, jsProNameList, &jsProCount);
|
||||
if (!PraseJson(env, jsonField, jsProNameList, jsProCount, jsonObject)) {
|
||||
if (!PraseJson(env, jsonField, jsProNameList, jsProCount, jsonObj)) {
|
||||
HILOGE("PraseJson failed.");
|
||||
return false;
|
||||
}
|
||||
@ -486,7 +724,7 @@ bool JsContinuationManager::UnwrapJsonByPropertyName(const napi_env& env, const
|
||||
}
|
||||
|
||||
bool JsContinuationManager::PraseJson(const napi_env& env, const napi_value& jsonField,
|
||||
const napi_value& jsProNameList, uint32_t jsProCount, nlohmann::json& jsonObject)
|
||||
const napi_value& jsProNameList, uint32_t jsProCount, nlohmann::json& jsonObj)
|
||||
{
|
||||
napi_value jsProName = nullptr;
|
||||
napi_value jsProValue = nullptr;
|
||||
@ -504,14 +742,14 @@ bool JsContinuationManager::PraseJson(const napi_env& env, const napi_value& jso
|
||||
case napi_string: {
|
||||
std::string elementValue = UnwrapStringFromJS(env, jsProValue);
|
||||
HILOGI("Property name=%{public}s, string, value=%{public}s", strProName.c_str(), elementValue.c_str());
|
||||
jsonObject[strProName] = elementValue;
|
||||
jsonObj[strProName] = elementValue;
|
||||
break;
|
||||
}
|
||||
case napi_boolean: {
|
||||
bool elementValue = false;
|
||||
napi_get_value_bool(env, jsProValue, &elementValue);
|
||||
HILOGI("Property name=%{public}s, boolean, value=%{public}d.", strProName.c_str(), elementValue);
|
||||
jsonObject[strProName] = elementValue;
|
||||
jsonObj[strProName] = elementValue;
|
||||
break;
|
||||
}
|
||||
case napi_number: {
|
||||
@ -520,7 +758,7 @@ bool JsContinuationManager::PraseJson(const napi_env& env, const napi_value& jso
|
||||
HILOGE("Property name=%{public}s, Property int32_t parse error", strProName.c_str());
|
||||
} else {
|
||||
HILOGI("Property name=%{public}s, number, value=%{public}d.", strProName.c_str(), elementValue);
|
||||
jsonObject[strProName] = elementValue;
|
||||
jsonObj[strProName] = elementValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -533,6 +771,12 @@ bool JsContinuationManager::PraseJson(const napi_env& env, const napi_value& jso
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t JsContinuationManager::ErrorCodeReturn(int32_t code)
|
||||
{
|
||||
return DMS_ERROR_CODE_MAP.find(code) !=
|
||||
DMS_ERROR_CODE_MAP.end() ? DMS_ERROR_CODE_MAP.at(code) : SYSTEM_WORK_ABNORMALLY;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
{
|
||||
HILOGD("called.");
|
||||
@ -559,6 +803,14 @@ NativeValue* JsContinuationManagerInit(NativeEngine* engine, NativeValue* export
|
||||
BindNativeFunction(*engine, *object, "startDeviceManager", moduleName, JsContinuationManager::StartDeviceManager);
|
||||
BindNativeProperty(*object, "DeviceConnectState", JsContinuationManager::InitDeviceConnectStateObject);
|
||||
BindNativeProperty(*object, "ContinuationMode", JsContinuationManager::InitContinuationModeObject);
|
||||
BindNativeFunction(*engine, *object, "registerContinuation", moduleName,
|
||||
JsContinuationManager::RegisterContinuation);
|
||||
BindNativeFunction(*engine, *object, "unregisterContinuation", moduleName,
|
||||
JsContinuationManager::UnregisterContinuation);
|
||||
BindNativeFunction(*engine, *object, "updateContinuationState", moduleName,
|
||||
JsContinuationManager::UpdateContinuationState);
|
||||
BindNativeFunction(*engine, *object, "startContinuationDeviceManager", moduleName,
|
||||
JsContinuationManager::StartContinuationDeviceManager);
|
||||
|
||||
return engine->CreateUndefined();
|
||||
}
|
||||
|
@ -41,6 +41,10 @@ public:
|
||||
static NativeValue* StartDeviceManager(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* InitDeviceConnectStateObject(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* InitContinuationModeObject(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* RegisterContinuation(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* UnregisterContinuation(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* UpdateContinuationState(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* StartContinuationDeviceManager(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
|
||||
private:
|
||||
using CallbackPair = std::pair<std::unique_ptr<NativeReference>, sptr<JsDeviceSelectionListener>>;
|
||||
@ -52,17 +56,23 @@ private:
|
||||
NativeValue* OnStartDeviceManager(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue* OnInitDeviceConnectStateObject(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue* OnInitContinuationModeObject(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
napi_status SetEnumItem(const napi_env& env, napi_value object, const char* name, int32_t value);
|
||||
static napi_status SetEnumItem(const napi_env& env, napi_value object, const char* name, int32_t value);
|
||||
NativeValue* OnRegisterContinuation(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue* OnUnregisterContinuation(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue* OnUpdateContinuationState(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue* OnStartContinuationDeviceManager(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
|
||||
bool IsCallbackValid(NativeValue* listenerObj);
|
||||
static bool IsCallbackValid(NativeValue* listenerObj);
|
||||
bool IsCallbackRegistered(int32_t token, const std::string& cbType);
|
||||
bool UnWrapContinuationExtraParams(const napi_env& env, const napi_value& options,
|
||||
std::shared_ptr<ContinuationExtraParams>& continuationExtraParams);
|
||||
bool UnwrapJsonByPropertyName(const napi_env& env, const napi_value& param,
|
||||
const std::string& fieldStr, nlohmann::json& jsonObj);
|
||||
bool PraseJson(const napi_env& env, const napi_value& jsonField, const napi_value& jsProNameList,
|
||||
const std::string& field, nlohmann::json& jsonObj);
|
||||
static bool PraseJson(const napi_env& env, const napi_value& jsonField, const napi_value& jsProNameList,
|
||||
uint32_t jsProCount, nlohmann::json& jsonObj);
|
||||
|
||||
int32_t ErrorCodeReturn(int32_t code);
|
||||
std::string OnRegisterDeviceSelectionCallbackParameterCheck(NativeEngine &engine,
|
||||
NativeCallbackInfo &info, std::string &cbType, int32_t &token, NativeValue** jsListenerObj);
|
||||
std::mutex jsCbMapMutex_;
|
||||
std::map<int32_t, std::map<std::string, CallbackPair>> jsCbMap_;
|
||||
};
|
||||
|
49
interfaces/kits/napi/include/napi_error_code.h
Normal file
49
interfaces/kits/napi/include/napi_error_code.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 SERVICES_DTBSCHEDMGR_NAPI_ERROR_CODE_H_
|
||||
#define SERVICES_DTBSCHEDMGR_NAPI_ERROR_CODE_H_
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
enum {
|
||||
/**
|
||||
* Result(16300503) for failed to get the missioninfo of the specified missionId.
|
||||
*/
|
||||
NO_MISSION_INFO_FOR_MISSION_ID = 16300503,
|
||||
/**
|
||||
* Result(16600001) for the system ability work abnormally.
|
||||
*/
|
||||
SYSTEM_WORK_ABNORMALLY = 16600001,
|
||||
/**
|
||||
* Result(16600002) for invalid input parameter.
|
||||
*/
|
||||
INVALID_INPUT_PARAMETER = 16600002,
|
||||
/**
|
||||
* Result(16600003) for token or callback not registered.
|
||||
*/
|
||||
CALLBACK_TOKEN_UNREGISTERED = 16600003,
|
||||
/**
|
||||
* Result(16600004) for token register max times.
|
||||
*/
|
||||
OVER_MAX_REGISTERED_TIMES = 16600004,
|
||||
/**
|
||||
* Result(16600005) for token has been registered.
|
||||
*/
|
||||
REPEATED_REGISTRATION = 16600005,
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // SERVICES_DTBSCHEDMGR_NAPI_ERROR_CODE_H_
|
@ -35,6 +35,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 = [
|
||||
@ -44,6 +45,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",
|
||||
|
52
services/base/include/dms_version_manager.h
Normal file
52
services/base/include/dms_version_manager.h
Normal 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& appInfoJsonData);
|
||||
static int32_t ParseAppInfo(const std::string& appInfoJsonData, 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
|
@ -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,
|
||||
/*
|
||||
* Result(29360219) for background permission check failed.
|
||||
*/
|
||||
|
177
services/base/src/dms_version_manager.cpp
Normal file
177
services/base/src/dms_version_manager.cpp
Normal file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* 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 appInfoJsonData;
|
||||
int32_t result = GetAppInfoFromDP(deviceId, appInfoJsonData);
|
||||
if (result != ERR_OK) {
|
||||
HILOGI("get app info failed, result: %{public}d!", result);
|
||||
return result;
|
||||
}
|
||||
std::string packageNamesData;
|
||||
std::string versionsData;
|
||||
result = ParseAppInfo(appInfoJsonData, packageNamesData, versionsData);
|
||||
if (result != ERR_OK) {
|
||||
HILOGI("parse app info failed");
|
||||
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& appInfoJsonData)
|
||||
{
|
||||
DeviceProfile::ServiceCharacteristicProfile profile;
|
||||
int32_t result = IN_PROCESS_CALL(
|
||||
DeviceProfile::DistributedDeviceProfileClient::GetInstance().GetDeviceProfile(deviceId,
|
||||
DMS_SERVICE_ID, profile)
|
||||
);
|
||||
if (result != ERR_OK) {
|
||||
return result;
|
||||
}
|
||||
appInfoJsonData = profile.GetCharacteristicProfileJson();
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t DmsVersionManager::ParseAppInfo(const std::string& appInfoJsonData, std::string& packageNamesData,
|
||||
std::string& versionsData)
|
||||
{
|
||||
if (appInfoJsonData.empty()) {
|
||||
return DMS_VERSION_EMPTY;
|
||||
}
|
||||
nlohmann::json appInfoJson = nlohmann::json::parse(appInfoJsonData.c_str(), nullptr, false);
|
||||
if (appInfoJson.find(PACKAGE_NAMES) == appInfoJson.end() || !appInfoJson.at(PACKAGE_NAMES).is_string()) {
|
||||
return DMS_VERSION_EMPTY;
|
||||
}
|
||||
appInfoJson.at(PACKAGE_NAMES).get_to(packageNamesData);
|
||||
|
||||
if (appInfoJson.find(VERSIONS) == appInfoJson.end() || !appInfoJson.at(VERSIONS).is_string()) {
|
||||
return DMS_VERSION_EMPTY;
|
||||
}
|
||||
appInfoJson.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 = static_cast<uint32_t>(majorVersionNum);
|
||||
|
||||
int32_t minorVersionNum = -1;
|
||||
if (!OHOS::StrToInt(versionNumList[DMS_MINOR_VERSION_INDEX], minorVersionNum) || minorVersionNum < 0) {
|
||||
return false;
|
||||
}
|
||||
dmsVersion.minorVersionNum = static_cast<uint32_t>(minorVersionNum);
|
||||
|
||||
int32_t featureVersionNum = -1;
|
||||
if (!OHOS::StrToInt(versionNumList[DMS_FEATURE_VERSION_INDEX], featureVersionNum) || featureVersionNum < 0) {
|
||||
return false;
|
||||
}
|
||||
dmsVersion.featureVersionNum = static_cast<uint32_t>(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
|
@ -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:
|
||||
|
@ -118,7 +118,7 @@ ohos_shared_library("distributedschedsvr") {
|
||||
}
|
||||
|
||||
if (dmsfwk_report_memmgr_plugins) {
|
||||
external_deps += [ "plugins/memmgr:memmgrclient" ]
|
||||
external_deps += [ "memmgr_plugin:memmgrclient" ]
|
||||
}
|
||||
|
||||
install_images = [ system_base_dir ]
|
||||
|
@ -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,
|
||||
|
@ -100,7 +100,6 @@ private:
|
||||
bool DeleteInnerLocked(const std::string& uuid, int32_t missionId);
|
||||
bool FuzzyDeleteInnerLocked(const std::string& networkId);
|
||||
bool QueryInnerLocked(const std::string& uuid, int32_t missionId, DistributedKv::Value& value) const;
|
||||
bool InitHandler();
|
||||
static void GenerateKey(const std::string& uuid, int32_t missionId, DistributedKv::Key& key);
|
||||
static void GenerateValue(const uint8_t* byteStream, size_t len, DistributedKv::Value& value);
|
||||
|
||||
|
@ -90,7 +90,7 @@ public:
|
||||
int32_t StartSyncMissionsFromRemote(const CallerInfo& callerInfo, std::vector<DstbMissionInfo>& missionInfos);
|
||||
int32_t StopSyncRemoteMissions(const std::string& dstDevId, bool offline, bool exit = false);
|
||||
void StopSyncMissionsFromRemote(const std::string& deviceId);
|
||||
bool needSyncDevice(const std::string& deviceId);
|
||||
bool NeedSyncDevice(const std::string& deviceId);
|
||||
|
||||
void NotifySnapshotChanged(const std::string& networkId, int32_t missionId);
|
||||
void OnRemoteDied(const wptr<IRemoteObject>& remote);
|
||||
|
@ -127,7 +127,7 @@ bool BundleManagerInternal::QueryExtensionAbilityInfo(const AAFwk::Want& want,
|
||||
std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos;
|
||||
bundleMgr->QueryExtensionAbilityInfos(want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT
|
||||
| AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_PERMISSION, ids[0], extensionInfos);
|
||||
if (extensionInfos.size() <= 0) {
|
||||
if (extensionInfos.empty()) {
|
||||
HILOGE("QueryExtensionAbilityInfo failed.");
|
||||
return false;
|
||||
}
|
||||
|
@ -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"
|
||||
@ -318,6 +319,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);
|
||||
@ -332,12 +338,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");
|
||||
@ -363,6 +364,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)
|
||||
{
|
||||
|
@ -52,12 +52,11 @@ bool DistributedDataStorage::Init()
|
||||
if (kvStoreDeathRecipient_ == nullptr) {
|
||||
kvStoreDeathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new KvStoreDeathRecipient());
|
||||
}
|
||||
bool ret = InitHandler();
|
||||
if (!ret) {
|
||||
HILOGE("InitHandler failed!");
|
||||
return false;
|
||||
if (dmsDataStorageHandler_ == nullptr) {
|
||||
shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("dmsDataStorageHandler");
|
||||
dmsDataStorageHandler_ = make_shared<AppExecFwk::EventHandler>(runner);
|
||||
}
|
||||
ret = InitKvDataService();
|
||||
int32_t ret = InitKvDataService();
|
||||
if (!ret) {
|
||||
HILOGE("InitKvDataService failed!");
|
||||
return false;
|
||||
@ -175,19 +174,6 @@ void DistributedDataStorage::SubscribeDistributedDataStorage()
|
||||
}
|
||||
}
|
||||
|
||||
bool DistributedDataStorage::InitHandler()
|
||||
{
|
||||
if (dmsDataStorageHandler_ == nullptr) {
|
||||
shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("dmsDataStorageHandler");
|
||||
dmsDataStorageHandler_ = make_shared<AppExecFwk::EventHandler>(runner);
|
||||
}
|
||||
if (dmsDataStorageHandler_ == nullptr) {
|
||||
HILOGW("dmsDataStorageHandler_ is null!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DistributedDataStorage::NotifyRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
HILOGD("begin.");
|
||||
|
@ -540,7 +540,7 @@ void DistributedSchedMissionManager::StopSyncMissionsFromRemote(const std::strin
|
||||
}
|
||||
}
|
||||
|
||||
bool DistributedSchedMissionManager::needSyncDevice(const std::string& deviceId)
|
||||
bool DistributedSchedMissionManager::NeedSyncDevice(const std::string& deviceId)
|
||||
{
|
||||
std::lock_guard<std::mutex> autoLock(remoteSyncDeviceLock_);
|
||||
if (remoteSyncDeviceSet_.count(deviceId) == 0) {
|
||||
|
@ -60,7 +60,7 @@ if (dmsfwk_report_memmgr) {
|
||||
}
|
||||
|
||||
if (dmsfwk_report_memmgr_plugins) {
|
||||
dsched_external_deps += [ "plugins/memmgr:memmgrclient" ]
|
||||
dsched_external_deps += [ "memmgr_plugin:memmgrclient" ]
|
||||
}
|
||||
|
||||
if (dmsfwk_standard_form_share) {
|
||||
@ -192,6 +192,7 @@ ohos_unittest("dschedcontinuetest") {
|
||||
|
||||
sources = [
|
||||
"unittest/distributed_sched_continuation_test.cpp",
|
||||
"unittest/dms_version_manager_test.cpp",
|
||||
"unittest/mock_distributed_sched.cpp",
|
||||
]
|
||||
sources += dtbschedmgr_sources
|
||||
|
@ -321,6 +321,46 @@ HWTEST_F(DSchedContinuationTest, ContinueLocalMission_002, TestSize.Level1)
|
||||
DTEST_LOG << "DSchedContinuationTest ContinueLocalMission_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ContinueLocalMission_003
|
||||
* @tc.desc: input invalid params.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, ContinueLocalMission_003, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest ContinueLocalMission_003 start" << std::endl;
|
||||
string deviceId = "123456";
|
||||
int32_t missionId = -1;
|
||||
auto callback = GetDSchedService();
|
||||
WantParams wantParams;
|
||||
DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
|
||||
int32_t ret = DistributedSchedService::GetInstance().ContinueLocalMission(
|
||||
deviceId, missionId, callback, wantParams);
|
||||
EXPECT_NE(ret, ERR_OK);
|
||||
DTEST_LOG << "DSchedContinuationTest ContinueLocalMission_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ContinueLocalMission_004
|
||||
* @tc.desc: input invalid params.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, ContinueLocalMission_004, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest ContinueLocalMission_004 start" << std::endl;
|
||||
string deviceId;
|
||||
int32_t missionId = -1;
|
||||
auto callback = GetDSchedService();
|
||||
WantParams wantParams;
|
||||
DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
|
||||
int32_t ret = DistributedSchedService::GetInstance().ContinueLocalMission(
|
||||
deviceId, missionId, callback, wantParams);
|
||||
EXPECT_NE(ret, ERR_OK);
|
||||
DTEST_LOG << "DSchedContinuationTest ContinueLocalMission_004 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ContinueRemoteMission_001
|
||||
* @tc.desc: input invalid params.
|
||||
|
540
services/dtbschedmgr/test/unittest/dms_version_manager_test.cpp
Normal file
540
services/dtbschedmgr/test/unittest/dms_version_manager_test.cpp
Normal file
@ -0,0 +1,540 @@
|
||||
/*
|
||||
* 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_test.h"
|
||||
|
||||
#define private public
|
||||
#include "dms_version_manager.h"
|
||||
#undef private
|
||||
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "test_log.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
|
||||
}
|
||||
|
||||
void DmsVersionManagerTest::SetUpTestCase()
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest::SetUpTestCase" << std::endl;
|
||||
}
|
||||
|
||||
void DmsVersionManagerTest::TearDownTestCase()
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest::TearDownTestCase" << std::endl;
|
||||
}
|
||||
|
||||
void DmsVersionManagerTest::TearDown()
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest::TearDown" << std::endl;
|
||||
}
|
||||
|
||||
void DmsVersionManagerTest::SetUp()
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest::SetUp" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CompareDmsVersionTest_001
|
||||
* @tc.desc: test dmsVersion lower than thresholdDmsVersion
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, CompareDmsVersionTest_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest CompareDmsVersionTest_001 begin" << std::endl;
|
||||
DmsVersion thresholdDmsVersion = {3, 2, 1};
|
||||
DmsVersion dmsVersion = {2, 2, 1};
|
||||
bool result = DmsVersionManager::CompareDmsVersion(dmsVersion, thresholdDmsVersion);
|
||||
EXPECT_EQ(result, true);
|
||||
DTEST_LOG << "DmsVersionManagerTest CompareDmsVersionTest_001 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CompareDmsVersionTest_002
|
||||
* @tc.desc: test dmsVersion lower than thresholdDmsVersion
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, CompareDmsVersionTest_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest CompareDmsVersionTest_002 begin" << std::endl;
|
||||
DmsVersion thresholdDmsVersion = {3, 2, 1};
|
||||
DmsVersion dmsVersion = {3, 1, 1};
|
||||
bool result = DmsVersionManager::CompareDmsVersion(dmsVersion, thresholdDmsVersion);
|
||||
EXPECT_EQ(result, true);
|
||||
DTEST_LOG << "DmsVersionManagerTest CompareDmsVersionTest_002 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CompareDmsVersionTest_003
|
||||
* @tc.desc: test dmsVersion lower than thresholdDmsVersion
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, CompareDmsVersionTest_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest CompareDmsVersionTest_003 begin" << std::endl;
|
||||
DmsVersion thresholdDmsVersion = {3, 2, 1};
|
||||
DmsVersion dmsVersion = {3, 2, 0};
|
||||
bool result = DmsVersionManager::CompareDmsVersion(dmsVersion, thresholdDmsVersion);
|
||||
EXPECT_EQ(result, true);
|
||||
DTEST_LOG << "DmsVersionManagerTest CompareDmsVersionTest_003 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CompareDmsVersionTest_004
|
||||
* @tc.desc: test dmsVersion higher than thresholdDmsVersion
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, CompareDmsVersionTest_004, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest CompareDmsVersionTest_004 begin" << std::endl;
|
||||
DmsVersion thresholdDmsVersion = {3, 2, 1};
|
||||
DmsVersion dmsVersion = {3, 2, 2};
|
||||
bool result = DmsVersionManager::CompareDmsVersion(dmsVersion, thresholdDmsVersion);
|
||||
EXPECT_EQ(result, false);
|
||||
DTEST_LOG << "DmsVersionManagerTest CompareDmsVersionTest_004 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ParseDmsVersionTest_001
|
||||
* @tc.desc: test call ParseDmsVersion with empty dmsVersionData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_001 begin" << std::endl;
|
||||
std::string dmsVersionData;
|
||||
DmsVersion dmsVersion;
|
||||
bool result = DmsVersionManager::ParseDmsVersion(dmsVersionData, dmsVersion);
|
||||
EXPECT_EQ(result, false);
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_001 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ParseDmsVersionTest_002
|
||||
* @tc.desc: test call ParseDmsVersion with invaild dmsVersionData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_002 begin" << std::endl;
|
||||
std::string dmsVersionData = "invaild.2.1";
|
||||
DmsVersion dmsVersion;
|
||||
bool result = DmsVersionManager::ParseDmsVersion(dmsVersionData, dmsVersion);
|
||||
EXPECT_EQ(result, false);
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_002 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ParseDmsVersionTest_003
|
||||
* @tc.desc: test call ParseDmsVersion with invaild dmsVersionData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_003 begin" << std::endl;
|
||||
std::string dmsVersionData = "-2.2.1";
|
||||
DmsVersion dmsVersion;
|
||||
bool result = DmsVersionManager::ParseDmsVersion(dmsVersionData, dmsVersion);
|
||||
EXPECT_EQ(result, false);
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_003 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ParseDmsVersionTest_004
|
||||
* @tc.desc: test call ParseDmsVersion with invaild dmsVersionData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_004, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_004 begin" << std::endl;
|
||||
std::string dmsVersionData = "3.invaild.1";
|
||||
DmsVersion dmsVersion;
|
||||
bool result = DmsVersionManager::ParseDmsVersion(dmsVersionData, dmsVersion);
|
||||
EXPECT_EQ(result, false);
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_004 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ParseDmsVersionTest_005
|
||||
* @tc.desc: test call ParseDmsVersion with invaild dmsVersionData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_005, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_005 begin" << std::endl;
|
||||
std::string dmsVersionData = "3.-2.1";
|
||||
DmsVersion dmsVersion;
|
||||
bool result = DmsVersionManager::ParseDmsVersion(dmsVersionData, dmsVersion);
|
||||
EXPECT_EQ(result, false);
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_005 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ParseDmsVersionTest_006
|
||||
* @tc.desc: test call ParseDmsVersion with invaild dmsVersionData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_006, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_006 begin" << std::endl;
|
||||
std::string dmsVersionData = "3.2.invaild";
|
||||
DmsVersion dmsVersion;
|
||||
bool result = DmsVersionManager::ParseDmsVersion(dmsVersionData, dmsVersion);
|
||||
EXPECT_EQ(result, false);
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_006 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ParseDmsVersionTest_007
|
||||
* @tc.desc: test call ParseDmsVersion with invaild dmsVersionData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_007, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_007 begin" << std::endl;
|
||||
std::string dmsVersionData = "3.2.-1";
|
||||
DmsVersion dmsVersion;
|
||||
bool result = DmsVersionManager::ParseDmsVersion(dmsVersionData, dmsVersion);
|
||||
EXPECT_EQ(result, false);
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_007 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ParseDmsVersionTest_008
|
||||
* @tc.desc: test call ParseDmsVersion
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_008, TestSize.Level2)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_008 begin" << std::endl;
|
||||
std::string dmsVersionData = "3.2.1";
|
||||
DmsVersion dmsVersion;
|
||||
bool result = DmsVersionManager::ParseDmsVersion(dmsVersionData, dmsVersion);
|
||||
EXPECT_EQ(result, true);
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_008 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetDmsVersionDataFromAppInfo_001
|
||||
* @tc.desc: test call GetDmsVersionDataFromAppInfo with empty data
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, GetDmsVersionDataFromAppInfo_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest GetDmsVersionDataFromAppInfo_001 begin" << std::endl;
|
||||
std::string packageNamesData;
|
||||
std::string versionsData;
|
||||
std::string dmsVersionData;
|
||||
int32_t result = DmsVersionManager::GetDmsVersionDataFromAppInfo(packageNamesData,
|
||||
versionsData, dmsVersionData);
|
||||
EXPECT_EQ(result, DMS_VERSION_EMPTY);
|
||||
DTEST_LOG << "DmsVersionManagerTest GetDmsVersionDataFromAppInfo_001 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetDmsVersionDataFromAppInfo_002
|
||||
* @tc.desc: test call GetDmsVersionDataFromAppInfo with empty versionsData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, GetDmsVersionDataFromAppInfo_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest GetDmsVersionDataFromAppInfo_002 begin" << std::endl;
|
||||
std::string packageNamesData = "mockData";
|
||||
std::string versionsData;
|
||||
std::string dmsVersionData;
|
||||
int32_t result = DmsVersionManager::GetDmsVersionDataFromAppInfo(packageNamesData,
|
||||
versionsData, dmsVersionData);
|
||||
EXPECT_EQ(result, DMS_VERSION_EMPTY);
|
||||
DTEST_LOG << "DmsVersionManagerTest GetDmsVersionDataFromAppInfo_002 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetDmsVersionDataFromAppInfo_003
|
||||
* @tc.desc: test call GetDmsVersionDataFromAppInfo with invaild data
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, GetDmsVersionDataFromAppInfo_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest GetDmsVersionDataFromAppInfo_003 begin" << std::endl;
|
||||
std::string packageNamesData = "a,b,c";
|
||||
std::string versionsData = "1.1,2.2";
|
||||
std::string dmsVersionData;
|
||||
int32_t result = DmsVersionManager::GetDmsVersionDataFromAppInfo(packageNamesData,
|
||||
versionsData, dmsVersionData);
|
||||
EXPECT_EQ(result, DMS_VERSION_PARSE_EXCEPTION);
|
||||
DTEST_LOG << "DmsVersionManagerTest GetDmsVersionDataFromAppInfo_003 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetDmsVersionDataFromAppInfo_004
|
||||
* @tc.desc: test call GetDmsVersionDataFromAppInfo with invaild data
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, GetDmsVersionDataFromAppInfo_004, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest GetDmsVersionDataFromAppInfo_004 begin" << std::endl;
|
||||
std::string packageNamesData = "a,b,c";
|
||||
std::string versionsData = "1.1,2.2,3.3";
|
||||
std::string dmsVersionData;
|
||||
int32_t result = DmsVersionManager::GetDmsVersionDataFromAppInfo(packageNamesData,
|
||||
versionsData, dmsVersionData);
|
||||
EXPECT_EQ(result, DMS_VERSION_EMPTY);
|
||||
DTEST_LOG << "DmsVersionManagerTest GetDmsVersionDataFromAppInfo_004 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetDmsVersionDataFromAppInfo_005
|
||||
* @tc.desc: test call GetDmsVersionDataFromAppInfo
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, GetDmsVersionDataFromAppInfo_005, TestSize.Level2)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest GetDmsVersionDataFromAppInfo_005 begin" << std::endl;
|
||||
std::string packageNamesData = "a,b,dmsfwk";
|
||||
std::string versionsData = "1.1,2.2,3.3";
|
||||
std::string dmsVersionData;
|
||||
int32_t result = DmsVersionManager::GetDmsVersionDataFromAppInfo(packageNamesData,
|
||||
versionsData, dmsVersionData);
|
||||
EXPECT_EQ(result, ERR_OK);
|
||||
DTEST_LOG << "DmsVersionManagerTest GetDmsVersionDataFromAppInfo_005 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAppInfoFromDP_001
|
||||
* @tc.desc: test call GetAppInfoFromDP with invaild device id
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, GetAppInfoFromDP_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest GetAppInfoFromDP_001 begin" << std::endl;
|
||||
std::string deviceId = "1";
|
||||
std::string appInfoJson;
|
||||
int32_t result = DmsVersionManager::GetAppInfoFromDP(deviceId, appInfoJson);
|
||||
EXPECT_NE(result, ERR_OK);
|
||||
DTEST_LOG << "DmsVersionManagerTest GetAppInfoFromDP_001 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAppInfoFromDP_002
|
||||
* @tc.desc: test call GetAppInfoFromDP with local device id
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, GetAppInfoFromDP_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest GetAppInfoFromDP_002 begin" << std::endl;
|
||||
std::string deviceId;
|
||||
std::string appInfoJson;
|
||||
int32_t result = DmsVersionManager::GetAppInfoFromDP(deviceId, appInfoJson);
|
||||
EXPECT_EQ(result, ERR_OK);
|
||||
DTEST_LOG << "DmsVersionManagerTest GetAppInfoFromDP_002 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ParseAppInfo_001
|
||||
* @tc.desc: test call ParseAppInfo with appInfoJsonDatadata is empty
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseAppInfo_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseAppInfo_001 begin" << std::endl;
|
||||
std::string appInfoJsonData;
|
||||
std::string packageNamesData;
|
||||
std::string versionsData;
|
||||
int32_t result = DmsVersionManager::ParseAppInfo(appInfoJsonData,
|
||||
packageNamesData, versionsData);
|
||||
EXPECT_EQ(result, DMS_VERSION_EMPTY);
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseAppInfo_001 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ParseAppInfo_002
|
||||
* @tc.desc: test call ParseAppInfo with packageNamesData is empty
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseAppInfo_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseAppInfo_002 begin" << std::endl;
|
||||
std::string appInfoJsonData = "{\"versions\":\"3.2.0\"}";
|
||||
std::string packageNamesData;
|
||||
std::string versionsData;
|
||||
int32_t result = DmsVersionManager::ParseAppInfo(appInfoJsonData,
|
||||
packageNamesData, versionsData);
|
||||
EXPECT_EQ(result, DMS_VERSION_EMPTY);
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseAppInfo_002 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ParseAppInfo_003
|
||||
* @tc.desc: test call ParseAppInfo with invaild packageNamesData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseAppInfo_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseAppInfo_003 begin" << std::endl;
|
||||
std::string appInfoJsonData = "{\"packageNames\":1,\"versions\":\"3.2.0\"}";
|
||||
std::string packageNamesData;
|
||||
std::string versionsData;
|
||||
int32_t result = DmsVersionManager::ParseAppInfo(appInfoJsonData,
|
||||
packageNamesData, versionsData);
|
||||
EXPECT_EQ(result, DMS_VERSION_EMPTY);
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseAppInfo_003 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ParseAppInfo_004
|
||||
* @tc.desc: test call ParseAppInfo with versionsData is empty
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseAppInfo_004, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseAppInfo_004 begin" << std::endl;
|
||||
std::string appInfoJsonData = "{\"packageNames\":\"dmsfwk\"}";
|
||||
std::string packageNamesData;
|
||||
std::string versionsData;
|
||||
int32_t result = DmsVersionManager::ParseAppInfo(appInfoJsonData,
|
||||
packageNamesData, versionsData);
|
||||
EXPECT_EQ(result, DMS_VERSION_EMPTY);
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseAppInfo_004 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ParseAppInfo_005
|
||||
* @tc.desc: test call ParseAppInfo with invaild versionsData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseAppInfo_005, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseAppInfo_005 begin" << std::endl;
|
||||
std::string appInfoJsonData = "{\"packageNames\":\"dmsfwk\",\"versions\":1}";
|
||||
std::string packageNamesData;
|
||||
std::string versionsData;
|
||||
int32_t result = DmsVersionManager::ParseAppInfo(appInfoJsonData,
|
||||
packageNamesData, versionsData);
|
||||
EXPECT_EQ(result, DMS_VERSION_EMPTY);
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseAppInfo_005 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ParseAppInfo_006
|
||||
* @tc.desc: test call ParseAppInfo
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseAppInfo_006, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseAppInfo_006 begin" << std::endl;
|
||||
std::string appInfoJsonData = "{\"packageNames\":\"dmsfwk\",\"versions\":\"3.2.0\"}";
|
||||
std::string packageNamesData;
|
||||
std::string versionsData;
|
||||
int32_t result = DmsVersionManager::ParseAppInfo(appInfoJsonData,
|
||||
packageNamesData, versionsData);
|
||||
EXPECT_EQ(result, ERR_OK);
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseAppInfo_006 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetRemoteDmsVersion_001
|
||||
* @tc.desc: test call GetRemoteDmsVersion with invaild deviceId
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, GetRemoteDmsVersion_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest GetRemoteDmsVersion_001 begin" << std::endl;
|
||||
std::string deviceId = "0";
|
||||
DmsVersion dmsVersion;
|
||||
int32_t result = DmsVersionManager::GetRemoteDmsVersion(deviceId, dmsVersion);
|
||||
EXPECT_NE(result, ERR_OK);
|
||||
DTEST_LOG << "DmsVersionManagerTest GetRemoteDmsVersion_001 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetRemoteDmsVersion_002
|
||||
* @tc.desc: test call GetRemoteDmsVersion with local deviceId
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, GetRemoteDmsVersion_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest GetRemoteDmsVersion_002 begin" << std::endl;
|
||||
std::string deviceId;
|
||||
DmsVersion dmsVersion;
|
||||
int32_t result = DmsVersionManager::GetRemoteDmsVersion(deviceId, dmsVersion);
|
||||
EXPECT_EQ(result, ERR_OK);
|
||||
DTEST_LOG << "DmsVersionManagerTest GetRemoteDmsVersion_002 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsRemoteDmsVersionLower_001
|
||||
* @tc.desc: test call IsRemoteDmsVersionLower with invaild deviceId
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, IsRemoteDmsVersionLower_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest IsRemoteDmsVersionLower_001 begin" << std::endl;
|
||||
std::string deviceId = "0";
|
||||
DmsVersion thresholdDmsVersion = {3, 2, 0};
|
||||
bool result = DmsVersionManager::IsRemoteDmsVersionLower(deviceId, thresholdDmsVersion);
|
||||
EXPECT_EQ(result, true);
|
||||
DTEST_LOG << "DmsVersionManagerTest IsRemoteDmsVersionLower_001 end ret:" << result << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsRemoteDmsVersionLower_002
|
||||
* @tc.desc: test call IsRemoteDmsVersionLower with local deviceId
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, IsRemoteDmsVersionLower_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest IsRemoteDmsVersionLower_002 begin" << std::endl;
|
||||
std::string deviceId;
|
||||
DmsVersion thresholdDmsVersion = {3, 2, 0};
|
||||
bool result = DmsVersionManager::IsRemoteDmsVersionLower(deviceId, thresholdDmsVersion);
|
||||
EXPECT_EQ(result, false);
|
||||
DTEST_LOG << "DmsVersionManagerTest IsRemoteDmsVersionLower_002 end ret:" << result << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 DMS_VERSION_MANAGER_TEST_H
|
||||
#define DMS_VERSION_MANAGER_TEST_H
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DmsVersionManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // DMS_VERSION_MANAGER_TEST_H
|
@ -365,7 +365,7 @@ HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions014, TestSize.Level3)
|
||||
HWTEST_F(DMSMissionManagerTest, testNeedSyncDevice001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "testCleanMissionResources001 begin" << std::endl;
|
||||
bool ret = DistributedSchedMissionManager::GetInstance().needSyncDevice(DEVICE_ID);
|
||||
bool ret = DistributedSchedMissionManager::GetInstance().NeedSyncDevice(DEVICE_ID);
|
||||
EXPECT_EQ(false, ret);
|
||||
DTEST_LOG << "testNeedSyncDevice001 end" << std::endl;
|
||||
}
|
||||
|
@ -64,14 +64,6 @@ public:
|
||||
{
|
||||
return ERR_OK;
|
||||
};
|
||||
ErrCode AddFormInfo(FormInfo &formInfo) override
|
||||
{
|
||||
return ERR_OK;
|
||||
};
|
||||
ErrCode RemoveFormInfo(const std::string &moduleName, const std::string &formName) override
|
||||
{
|
||||
return ERR_OK;
|
||||
};
|
||||
ErrCode RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId) override
|
||||
{
|
||||
@ -114,22 +106,6 @@ public:
|
||||
{
|
||||
return ERR_OK;
|
||||
};
|
||||
int32_t BatchAddFormRecords(const Want &want) override
|
||||
{
|
||||
return ERR_OK;
|
||||
};
|
||||
int32_t ClearFormRecords() override
|
||||
{
|
||||
return ERR_OK;
|
||||
};
|
||||
int32_t DistributedDataAddForm(const Want &want) override
|
||||
{
|
||||
return ERR_OK;
|
||||
};
|
||||
int32_t DistributedDataDeleteForm(const std::string &formId) override
|
||||
{
|
||||
return ERR_OK;
|
||||
};
|
||||
int32_t DeleteInvalidForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
|
||||
int32_t &numFormsDeleted) override
|
||||
{
|
||||
@ -163,10 +139,6 @@ public:
|
||||
{
|
||||
return ERR_OK;
|
||||
};
|
||||
int32_t UpdateRouterAction(const int64_t formId, std::string &action) override
|
||||
{
|
||||
return ERR_OK;
|
||||
};
|
||||
int32_t ShareForm(const int64_t formId, const std::string &deviceId,
|
||||
const sptr<IRemoteObject> &callerToken, const int64_t requestCode) override
|
||||
{
|
||||
|
85
test/fuzztest/continuationmanager_fuzzer/BUILD.gn
Normal file
85
test/fuzztest/continuationmanager_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,85 @@
|
||||
# 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.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
module_output_path = "dmsfwk/continuationmanager"
|
||||
distributed_service = "//foundation/ability/dmsfwk/services"
|
||||
|
||||
config("continuationmanager_fuzz_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"${distributed_service}/dtbabilitymgr/include/",
|
||||
"//foundation/ability/dmsfwk/interfaces/innerkits/continuation_manager/include/",
|
||||
]
|
||||
}
|
||||
|
||||
dtbabilitymgr_sources = [
|
||||
"${distributed_service}/dtbabilitymgr/src/continuation_manager/app_device_callback_stub.cpp",
|
||||
"${distributed_service}/dtbabilitymgr/src/continuation_manager/connect_status_info.cpp",
|
||||
"${distributed_service}/dtbabilitymgr/src/continuation_manager/continuation_extra_params.cpp",
|
||||
"${distributed_service}/dtbabilitymgr/src/continuation_manager/continuation_result.cpp",
|
||||
"${distributed_service}/dtbabilitymgr/src/continuation_manager/device_selection_notifier_proxy.cpp",
|
||||
"${distributed_service}/dtbabilitymgr/src/continuation_manager/device_selection_notifier_stub.cpp",
|
||||
"${distributed_service}/dtbabilitymgr/src/continuation_manager/notifier_death_recipient.cpp",
|
||||
"${distributed_service}/dtbabilitymgr/src/continuation_manager/notifier_info.cpp",
|
||||
"${distributed_service}/dtbabilitymgr/src/distributed_ability_manager_dumper.cpp",
|
||||
"${distributed_service}/dtbabilitymgr/src/distributed_ability_manager_service.cpp",
|
||||
"${distributed_service}/dtbabilitymgr/src/distributed_ability_manager_stub.cpp",
|
||||
]
|
||||
|
||||
dtbabilitymgr_external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"c_utils:utils",
|
||||
"device_manager:devicemanagersdk",
|
||||
"eventhandler:libeventhandler",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("ContinuationManagerFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file =
|
||||
"//foundation/ability/dmsfwk/test/fuzztest/continuationmanager_fuzzer"
|
||||
|
||||
configs = [
|
||||
":continuationmanager_fuzz_config",
|
||||
"${distributed_service}/dtbschedmgr/test/resource:coverage_flags",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
|
||||
sources = [ "continuationmanager_fuzzer.cpp" ]
|
||||
sources += dtbabilitymgr_sources
|
||||
|
||||
deps = [ "//foundation/ability/dmsfwk/services/base:dmsbaseinner" ]
|
||||
|
||||
external_deps = dtbabilitymgr_external_deps
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = [ ":ContinuationManagerFuzzTest" ]
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 "continuationmanager_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "distributed_ability_manager_interface.h"
|
||||
#include "distributed_ability_manager_stub.h"
|
||||
#include "distributed_ability_manager_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
constexpr int32_t DISTRIBUTED_SCHED_SA_ID = 1401;
|
||||
constexpr size_t THRESHOLD = 10;
|
||||
constexpr uint8_t MAX_CALL_TRANSACTION = 64;
|
||||
constexpr int32_t OFFSET = 4;
|
||||
const std::u16string DMS_INTERFACE_TOKEN = u"OHOS.DistributedSchedule.IDistributedAbilityManager";
|
||||
}
|
||||
|
||||
uint32_t Convert2Uint32(const uint8_t* ptr)
|
||||
{
|
||||
if (ptr == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | (ptr[3]); // this is a general method of converting in fuzz
|
||||
}
|
||||
|
||||
void FuzzUnregister(const uint8_t* rawData, size_t size)
|
||||
{
|
||||
uint32_t code = Convert2Uint32(rawData);
|
||||
rawData = rawData + OFFSET;
|
||||
size = size - OFFSET;
|
||||
MessageParcel data;
|
||||
data.WriteInterfaceToken(DMS_INTERFACE_TOKEN);
|
||||
data.WriteBuffer(rawData, size);
|
||||
data.RewindRead(0);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
std::shared_ptr<DistributedAbilityManagerService> dtbAbilityMgr(
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true));
|
||||
dtbAbilityMgr->OnRemoteRequest(code % MAX_CALL_TRANSACTION, data, reply, option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
if (size < OHOS::DistributedSchedule::THRESHOLD) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
OHOS::DistributedSchedule::FuzzUnregister(data, size);
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_ABILITY_MANAGER_FUZZTEST_CONTINUATION_MANAGER_FUZZER_H
|
||||
#define OHOS_DISTRIBUTED_ABILITY_MANAGER_FUZZTEST_CONTINUATION_MANAGER_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "continuationmanager_fuzzer"
|
||||
|
||||
#endif
|
16
test/fuzztest/continuationmanager_fuzzer/corpus/init
Normal file
16
test/fuzztest/continuationmanager_fuzzer/corpus/init
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
FUZZ
|
25
test/fuzztest/continuationmanager_fuzzer/project.xml
Normal file
25
test/fuzztest/continuationmanager_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
Loading…
Reference in New Issue
Block a user