mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-23 15:20:34 +00:00
Merge branch 'master' of https://gitee.com/openharmony/ability_ability_runtime
Signed-off-by: dy_study <dingyao5@huawei.com>
This commit is contained in:
commit
4d6fa23c3f
@ -231,7 +231,7 @@ static void ParseFormInfoIntoNapi(napi_env env, const FormInfo &formInfo, napi_v
|
||||
napi_set_named_property(env, result, "isStatic", isStatic);
|
||||
|
||||
// window
|
||||
napi_value formWindowObject = nullptr;
|
||||
napi_value formWindowObject;
|
||||
napi_create_object(env, &formWindowObject);
|
||||
napi_value autoDesignWidth;
|
||||
napi_get_boolean(env, formInfo.window.autoDesignWidth, &autoDesignWidth);
|
||||
|
@ -282,13 +282,14 @@ static ErrCode UnwrapFormInfo(napi_env env, napi_value value, FormInfo &formInfo
|
||||
UnwrapBooleanByPropertyName(env, jsWindowValue, "autoDesignWidth", formInfo.window.autoDesignWidth);
|
||||
}
|
||||
|
||||
auto colorMode = (int32_t) FormsColorMode::AUTO_MODE;
|
||||
auto colorMode = static_cast<int32_t>(FormsColorMode::AUTO_MODE);
|
||||
UnwrapInt32ByPropertyName(env, value, "colorMode", colorMode);
|
||||
if (colorMode < (int32_t) FormsColorMode::AUTO_MODE || colorMode > (int32_t) FormsColorMode::LIGHT_MODE) {
|
||||
if (colorMode < static_cast<int32_t>(FormsColorMode::AUTO_MODE) ||
|
||||
colorMode > static_cast<int32_t>(FormsColorMode::LIGHT_MODE)) {
|
||||
HILOG_ERROR("%{public}s called. Invalid form color mode: %{public}d.", __func__, colorMode);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
formInfo.colorMode = (FormsColorMode) colorMode;
|
||||
formInfo.colorMode = static_cast<FormsColorMode>(colorMode);
|
||||
|
||||
UnwrapFormInfoCustomData(env, value, formInfo.customizeDatas);
|
||||
return FormInfoCheck(formInfo);
|
||||
@ -722,9 +723,9 @@ static void InnerRequestPublishForm(napi_env env, AsyncRequestPublishFormCallbac
|
||||
}
|
||||
|
||||
ErrCode errCode = FormMgr::GetInstance().RequestPublishForm(asyncCallbackInfo->want,
|
||||
asyncCallbackInfo->withFormBindingData, asyncCallbackInfo->formProviderData);
|
||||
asyncCallbackInfo->withFormBindingData, asyncCallbackInfo->formProviderData, asyncCallbackInfo->formId);
|
||||
if (errCode != ERR_OK) {
|
||||
HILOG_ERROR("Failed to AddFormInfo, error code is %{public}d.", errCode);
|
||||
HILOG_ERROR("Failed to RequestPublishForm, error code is %{public}d.", errCode);
|
||||
}
|
||||
asyncCallbackInfo->result = errCode;
|
||||
HILOG_DEBUG("%{public}s, end", __func__);
|
||||
@ -742,15 +743,15 @@ static ErrCode RequestPublishFormParse(napi_env env, napi_value *argv,
|
||||
if (asyncCallbackInfo->withFormBindingData) {
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
napi_typeof(env, argv[1], &valueType);
|
||||
if (valueType == napi_object) {
|
||||
auto formProviderData = std::make_unique<OHOS::AppExecFwk::FormProviderData>();
|
||||
std::string formDataStr = GetStringByProp(env, argv[1], "data");
|
||||
formProviderData->SetDataString(formDataStr);
|
||||
formProviderData->ParseImagesData();
|
||||
asyncCallbackInfo->formProviderData = std::move(formProviderData);
|
||||
} else {
|
||||
if (valueType != napi_object) {
|
||||
HILOG_ERROR("%{public}s, wrong type for argv[1].", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
auto formProviderData = std::make_unique<FormProviderData>();
|
||||
std::string formDataStr = GetStringByProp(env, argv[1], "data");
|
||||
formProviderData->SetDataString(formDataStr);
|
||||
formProviderData->ParseImagesData();
|
||||
asyncCallbackInfo->formProviderData = std::move(formProviderData);
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
@ -759,28 +760,34 @@ static ErrCode RequestPublishFormParse(napi_env env, napi_value *argv,
|
||||
static napi_value RequestPublishFormCallback(napi_env env, napi_value *argv, bool withFormBindingData)
|
||||
{
|
||||
HILOG_INFO("%{public}s, asyncCallback.", __func__);
|
||||
auto *asyncCallbackInfo = new AsyncRequestPublishFormCallbackInfo {
|
||||
.env = env,
|
||||
.ability = GetGlobalAbility(env),
|
||||
.withFormBindingData = withFormBindingData,
|
||||
};
|
||||
|
||||
int32_t callbackIdx = 1;
|
||||
if (withFormBindingData) {
|
||||
callbackIdx++;
|
||||
}
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
NAPI_CALL(env, napi_typeof(env, argv[callbackIdx], &valueType));
|
||||
if (valueType != napi_function) {
|
||||
HILOG_ERROR("The arguments[1] type of requestPublishForm is incorrect, expected type is function.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto *asyncCallbackInfo = new (std::nothrow) AsyncRequestPublishFormCallbackInfo {
|
||||
.env = env,
|
||||
.ability = GetGlobalAbility(env),
|
||||
.withFormBindingData = withFormBindingData,
|
||||
};
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
HILOG_ERROR("asyncCallbackInfo == nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ErrCode errCode = RequestPublishFormParse(env, argv, asyncCallbackInfo);
|
||||
if (errCode != ERR_OK) {
|
||||
delete asyncCallbackInfo;
|
||||
return RetErrMsg(InitErrMsg(env, errCode, CALLBACK_FLG, argv[callbackIdx]));
|
||||
}
|
||||
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
NAPI_CALL(env, napi_typeof(env, argv[callbackIdx], &valueType));
|
||||
NAPI_ASSERT(env, valueType == napi_function,
|
||||
"The arguments[1] type of requestPublishForm is incorrect, expected type is function.");
|
||||
napi_create_reference(env, argv[1], REF_COUNT, &asyncCallbackInfo->callback);
|
||||
napi_create_reference(env, argv[callbackIdx], REF_COUNT, &asyncCallbackInfo->callback);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName);
|
||||
@ -801,6 +808,12 @@ static napi_value RequestPublishFormCallback(napi_env env, napi_value *argv, boo
|
||||
napi_value callback;
|
||||
napi_value callbackValues[ARGS_SIZE_TWO] = {nullptr, nullptr};
|
||||
InnerCreateCallbackRetMsg(env, asyncCallbackInfo->result, callbackValues);
|
||||
if (asyncCallbackInfo->result == ERR_OK) {
|
||||
std::string strFormId = std::to_string(asyncCallbackInfo->formId);
|
||||
napi_value formId;
|
||||
napi_create_string_utf8(env, strFormId.c_str(), strFormId.length(), &formId);
|
||||
callbackValues[1] = formId;
|
||||
}
|
||||
|
||||
napi_get_reference_value(env, asyncCallbackInfo->callback, &callback);
|
||||
napi_value callResult;
|
||||
@ -824,12 +837,16 @@ static napi_value RequestPublishFormPromise(napi_env env, napi_value *argv, bool
|
||||
napi_value promise;
|
||||
NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
|
||||
|
||||
auto *asyncCallbackInfo = new AsyncRequestPublishFormCallbackInfo {
|
||||
auto *asyncCallbackInfo = new (std::nothrow) AsyncRequestPublishFormCallbackInfo {
|
||||
.env = env,
|
||||
.ability = GetGlobalAbility(env),
|
||||
.deferred = deferred,
|
||||
.withFormBindingData = withFormBindingData,
|
||||
};
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
HILOG_ERROR("asyncCallbackInfo == nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ErrCode errCode = RequestPublishFormParse(env, argv, asyncCallbackInfo);
|
||||
if (errCode != ERR_OK) {
|
||||
@ -850,12 +867,15 @@ static napi_value RequestPublishFormPromise(napi_env env, napi_value *argv, bool
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
HILOG_INFO("%{public}s, promise complete", __func__);
|
||||
auto *asyncCallbackInfo = (AsyncAddFormInfoCallbackInfo *) data;
|
||||
auto *asyncCallbackInfo = (AsyncRequestPublishFormCallbackInfo *) data;
|
||||
napi_value result;
|
||||
InnerCreatePromiseRetMsg(env, asyncCallbackInfo->result, &result);
|
||||
|
||||
if (asyncCallbackInfo->result == ERR_OK) {
|
||||
std::string strFormId = std::to_string(asyncCallbackInfo->formId);
|
||||
napi_create_string_utf8(env, strFormId.c_str(), strFormId.length(), &result);
|
||||
napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result);
|
||||
} else {
|
||||
InnerCreatePromiseRetMsg(env, asyncCallbackInfo->result, &result);
|
||||
napi_reject_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result);
|
||||
}
|
||||
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
@ -1028,7 +1048,7 @@ napi_value NAPI_AddFormInfo(napi_env env, napi_callback_info info)
|
||||
return RetErrMsg(InitErrMsg(env, ERR_APPEXECFWK_FORM_INVALID_PARAM, callbackType, argv[1]));
|
||||
}
|
||||
|
||||
auto *asyncCallbackInfo = new AsyncAddFormInfoCallbackInfo {
|
||||
auto *asyncCallbackInfo = new (std::nothrow) AsyncAddFormInfoCallbackInfo {
|
||||
.env = env,
|
||||
.ability = GetGlobalAbility(env),
|
||||
.asyncWork = nullptr,
|
||||
@ -1037,6 +1057,10 @@ napi_value NAPI_AddFormInfo(napi_env env, napi_callback_info info)
|
||||
.formInfo = {},
|
||||
.result = ERR_OK,
|
||||
};
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
HILOG_ERROR("asyncCallbackInfo == nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ErrCode errCode = UnwrapFormInfo(env, argv[0], asyncCallbackInfo->formInfo);
|
||||
if (errCode != ERR_OK) {
|
||||
@ -1069,7 +1093,7 @@ static void InnerRemoveFormInfo(napi_env env, AsyncRemoveFormInfoCallbackInfo *c
|
||||
|
||||
ErrCode errCode = FormMgr::GetInstance().RemoveFormInfo(asyncCallbackInfo->moduleName, asyncCallbackInfo->formName);
|
||||
if (errCode != ERR_OK) {
|
||||
HILOG_ERROR("Failed to AddFormInfo, error code is %{public}d.", errCode);
|
||||
HILOG_ERROR("Failed to RemoveFormInfo, error code is %{public}d.", errCode);
|
||||
}
|
||||
asyncCallbackInfo->result = errCode;
|
||||
HILOG_DEBUG("%{public}s, end", __func__);
|
||||
@ -1218,12 +1242,16 @@ napi_value NAPI_RemoveFormInfo(napi_env env, napi_callback_info info)
|
||||
return RetErrMsg(InitErrMsg(env, errCode, callbackType, argv[ARGS_SIZE_TWO]));
|
||||
}
|
||||
|
||||
auto *asyncCallbackInfo = new AsyncRemoveFormInfoCallbackInfo {
|
||||
auto *asyncCallbackInfo = new (std::nothrow) AsyncRemoveFormInfoCallbackInfo {
|
||||
.env = env,
|
||||
.ability = GetGlobalAbility(env),
|
||||
.moduleName = moduleName,
|
||||
.formName = formName,
|
||||
};
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
HILOG_ERROR("asyncCallbackInfo == nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (argc == ARGS_SIZE_THREE) {
|
||||
// Check the value type of the arguments
|
||||
|
@ -56,6 +56,7 @@ struct AsyncRequestPublishFormCallbackInfo {
|
||||
bool withFormBindingData = false;
|
||||
std::unique_ptr<OHOS::AppExecFwk::FormProviderData> formProviderData = nullptr;
|
||||
int32_t result = OHOS::ERR_OK;
|
||||
int64_t formId = 0;
|
||||
};
|
||||
|
||||
struct AsyncAddFormInfoCallbackInfo {
|
||||
|
@ -298,6 +298,11 @@ void InnerCreatePromiseRetMsg(napi_env env, int32_t code, napi_value* result)
|
||||
napi_value RetErrMsg(AsyncErrMsgCallbackInfo* asyncCallbackInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
HILOG_ERROR("asyncCallback == nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_env env = asyncCallbackInfo->env;
|
||||
napi_value value = asyncCallbackInfo->callbackValue;
|
||||
|
||||
@ -372,7 +377,7 @@ napi_value RetErrMsg(AsyncErrMsgCallbackInfo* asyncCallbackInfo)
|
||||
|
||||
AsyncErrMsgCallbackInfo *InitErrMsg(napi_env env, int32_t code, int32_t type, napi_value callbackValue)
|
||||
{
|
||||
auto *asyncErrorInfo = new AsyncErrMsgCallbackInfo {
|
||||
auto *asyncErrorInfo = new (std::nothrow) AsyncErrMsgCallbackInfo {
|
||||
.env = env,
|
||||
.asyncWork = nullptr,
|
||||
.deferred = nullptr,
|
||||
|
@ -26,6 +26,8 @@ namespace Constants {
|
||||
const std::string PARAM_FORM_IDENTITY_KEY = "ohos.extra.param.key.form_identity";
|
||||
const std::string PARAM_FORM_CALLING_IDENTITY_KEY = "ohos.extra.param.key.form_calling_identity";
|
||||
const std::string PARAM_MODULE_NAME_KEY = "ohos.extra.param.key.module_name";
|
||||
const std::string PARAM_BUNDLE_NAME_KEY = "ohos.extra.param.key.bundle_name";
|
||||
const std::string PARAM_ABILITY_NAME_KEY = "ohos.extra.param.key.ability_name";
|
||||
const std::string PARAM_FORM_NAME_KEY = "ohos.extra.param.key.form_name";
|
||||
const std::string PARAM_FORM_DIMENSION_KEY = "ohos.extra.param.key.form_dimension";
|
||||
const std::string PARAM_MESSAGE_KEY = "ohos.extra.param.key.message";
|
||||
@ -51,6 +53,7 @@ namespace Constants {
|
||||
const std::string ABS_CODE_PATH = "/data/app/el1/bundle/public";
|
||||
const std::string LOCAL_CODE_PATH = "/data/storage/el1/bundle";
|
||||
const std::string LOCAL_BUNDLES = "/data/bundles";
|
||||
const std::string FORM_PUBLISH_ACTION = "action.form.publish";
|
||||
const int TYPE_RESET_LIMIT = 1;
|
||||
const int TYPE_STATIC_UPDATE = 2;
|
||||
const int TYPE_DYNAMIC_UPDATE = 3;
|
||||
|
@ -105,10 +105,11 @@ public:
|
||||
* @param want The want of the form to publish.
|
||||
* @param withFormBindingData Indicates whether the formBindingData is carried with.
|
||||
* @param formBindingData Indicates the form data.
|
||||
* @param formId Return the form id to be published.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual ErrCode RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData) = 0;
|
||||
std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId) = 0;
|
||||
|
||||
/**
|
||||
* @brief Lifecycle update.
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
* @param formInfo Indicates the form info to be added.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual ErrCode AddFormInfo(FormInfo &formInfo) override;
|
||||
ErrCode AddFormInfo(FormInfo &formInfo) override;
|
||||
|
||||
/**
|
||||
* @brief Remove the specified form info.
|
||||
@ -91,7 +91,7 @@ public:
|
||||
* @param formName Indicates the form name of the dynamic form info to be removed.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual ErrCode RemoveFormInfo(const std::string &moduleName, const std::string &formName) override;
|
||||
ErrCode RemoveFormInfo(const std::string &moduleName, const std::string &formName) override;
|
||||
|
||||
/**
|
||||
* @brief Request to publish a form to the form host.
|
||||
@ -99,10 +99,11 @@ public:
|
||||
* @param want The want of the form to publish.
|
||||
* @param withFormBindingData Indicates whether the formBindingData is carried with.
|
||||
* @param formBindingData Indicates the form data.
|
||||
* @param formId Return the form id to be published.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual ErrCode RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData) override;
|
||||
ErrCode RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId) override;
|
||||
|
||||
/**
|
||||
* @brief Lifecycle update.
|
||||
|
@ -213,12 +213,6 @@ int FormMgrProxy::SetNextRefreshTime(const int64_t formId, const int64_t nextTim
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add the form info.
|
||||
*
|
||||
* @param formInfo Indicates the form info to be added.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FormMgrProxy::AddFormInfo(FormInfo &formInfo)
|
||||
{
|
||||
MessageParcel data;
|
||||
@ -246,13 +240,6 @@ ErrCode FormMgrProxy::AddFormInfo(FormInfo &formInfo)
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Remove the specified form info.
|
||||
*
|
||||
* @param moduleName Indicates the module name of the dynamic form info to be removed.
|
||||
* @param formName Indicates the form name of the dynamic form info to be removed.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FormMgrProxy::RemoveFormInfo(const std::string &moduleName, const std::string &formName)
|
||||
{
|
||||
MessageParcel data;
|
||||
@ -284,16 +271,8 @@ ErrCode FormMgrProxy::RemoveFormInfo(const std::string &moduleName, const std::s
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request to publish a form to the form host.
|
||||
*
|
||||
* @param want The want of the form to publish.
|
||||
* @param withFormBindingData Indicates whether the formBindingData is carried with.
|
||||
* @param formBindingData Indicates the form data.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FormMgrProxy::RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData)
|
||||
std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
@ -327,7 +306,11 @@ ErrCode FormMgrProxy::RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
|
||||
return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
|
||||
}
|
||||
return reply.ReadInt32();
|
||||
ErrCode errCode = reply.ReadInt32();
|
||||
if (errCode == ERR_OK) {
|
||||
formId = reply.ReadInt64();
|
||||
}
|
||||
return errCode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -280,8 +280,12 @@ ErrCode FormMgrStub::HandleRequestPublishForm(MessageParcel &data, MessageParcel
|
||||
formProviderData.reset(data.ReadParcelable<FormProviderData>());
|
||||
}
|
||||
|
||||
ErrCode result = RequestPublishForm(*want, withFormBindingData, formProviderData);
|
||||
int64_t formId = 0;
|
||||
ErrCode result = RequestPublishForm(*want, withFormBindingData, formProviderData, formId);
|
||||
reply.WriteInt32(result);
|
||||
if (result == ERR_OK) {
|
||||
reply.WriteInt64(formId);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
|
@ -214,10 +214,11 @@ public:
|
||||
* @param want The want of the form to publish.
|
||||
* @param withFormBindingData Indicates whether the formBindingData is carried with.
|
||||
* @param formBindingData Indicates the form data.
|
||||
* @param formId Return the form id to be published.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData);
|
||||
std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId);
|
||||
|
||||
/**
|
||||
* @brief Lifecycle Update.
|
||||
|
@ -299,12 +299,6 @@ int FormMgr::SetNextRefreshTime(const int64_t formId, const int64_t nextTime)
|
||||
return remoteProxy_->SetNextRefreshTime(formId, nextTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add the form info.
|
||||
*
|
||||
* @param formInfo Indicates the form info to be added.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FormMgr::AddFormInfo(FormInfo &formInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
@ -316,13 +310,6 @@ ErrCode FormMgr::AddFormInfo(FormInfo &formInfo)
|
||||
return remoteProxy_->AddFormInfo(formInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Remove the specified form info.
|
||||
*
|
||||
* @param moduleName Indicates the module name of the dynamic form info to be removed.
|
||||
* @param formName Indicates the form name of the dynamic form info to be removed.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FormMgr::RemoveFormInfo(const std::string &moduleName, const std::string &formName)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
@ -334,16 +321,8 @@ ErrCode FormMgr::RemoveFormInfo(const std::string &moduleName, const std::string
|
||||
return remoteProxy_->RemoveFormInfo(moduleName, formName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request to publish a form to the form host.
|
||||
*
|
||||
* @param want The want of the form to publish.
|
||||
* @param withFormBindingData Indicates whether the formBindingData is carried with.
|
||||
* @param formBindingData Indicates the form data.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FormMgr::RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData)
|
||||
std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
ErrCode errCode = Connect();
|
||||
@ -351,7 +330,7 @@ ErrCode FormMgr::RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
|
||||
return errCode;
|
||||
}
|
||||
return remoteProxy_->RequestPublishForm(want, withFormBindingData, formBindingData);
|
||||
return remoteProxy_->RequestPublishForm(want, withFormBindingData, formBindingData, formId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,6 +35,8 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
using Want = AAFwk::Want;
|
||||
|
||||
/**
|
||||
* @class FormDataMgr
|
||||
* form data manager.
|
||||
@ -407,7 +409,7 @@ public:
|
||||
* @param want The want of onAcquireFormState.
|
||||
* @return Returns true if this function is successfully called; returns false otherwise.
|
||||
*/
|
||||
ErrCode AcquireFormStateBack(AppExecFwk::FormState state, const std::string &provider, const AAFwk::Want &want);
|
||||
ErrCode AcquireFormStateBack(AppExecFwk::FormState state, const std::string &provider, const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Notify the form is visible or not.
|
||||
@ -426,6 +428,41 @@ public:
|
||||
* @return Returns true if this function is successfully called; returns false otherwise.
|
||||
*/
|
||||
ErrCode SetRecordVisible(int64_t matchedFormId, bool isVisible);
|
||||
|
||||
/**
|
||||
* @brief add request publish form info.
|
||||
* @param formId The form id of the form to publish.
|
||||
* @param want The want of the form to publish.
|
||||
* @param formProviderData The form data.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode AddRequestPublishFormInfo(int64_t formId, const Want &want,
|
||||
std::unique_ptr<FormProviderData> &formProviderData);
|
||||
|
||||
/**
|
||||
* @brief remove request publish form info.
|
||||
* @param formId The form id of the form to publish.
|
||||
* @return Returns true if this function is successfully called; returns false otherwise.
|
||||
*/
|
||||
ErrCode RemoveRequestPublishFormInfo(int64_t formId);
|
||||
|
||||
/**
|
||||
* @brief check whether request publish form info.
|
||||
* @param formId The form id of the form to publish.
|
||||
* @return Returns true if this function is successfully called; returns false otherwise.
|
||||
*/
|
||||
bool IsRequestPublishForm(int64_t formId);
|
||||
|
||||
/**
|
||||
* @brief get request publish form info.
|
||||
* @param formId The form id of the form to publish.
|
||||
* @param want The want of the form to publish.
|
||||
* @param formProviderData The form data.
|
||||
* @return Returns true if this function is successfully called; returns false otherwise.
|
||||
*/
|
||||
ErrCode GetRequestPublishFormInfo(int64_t formId, Want &want,
|
||||
std::unique_ptr<FormProviderData> &formProviderData);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Create form record.
|
||||
@ -503,10 +540,13 @@ private:
|
||||
mutable std::mutex formHostRecordMutex_;
|
||||
mutable std::mutex formTempMutex_;
|
||||
mutable std::mutex formStateRecordMutex_;
|
||||
mutable std::mutex formRequestPublishFormsMutex_;
|
||||
std::map<int64_t, FormRecord> formRecords_;
|
||||
std::vector<FormHostRecord> clientRecords_;
|
||||
std::vector<int64_t> tempForms_;
|
||||
std::map<std::string, FormHostRecord> formStateRecord_;
|
||||
using FormRequestPublishFormInfo = std::pair<Want, std::unique_ptr<FormProviderData>>;
|
||||
std::map<int64_t, FormRequestPublishFormInfo> formRequestPublishForms_;
|
||||
int64_t udidHash_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
|
@ -169,10 +169,11 @@ public:
|
||||
* @param want The want of the form to publish.
|
||||
* @param withFormBindingData Indicates whether the formBindingData is carried with.
|
||||
* @param formBindingData Indicates the form data.
|
||||
* @param formId Return the form id to be published.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData);
|
||||
std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId);
|
||||
|
||||
/**
|
||||
* @brief enable update form.
|
||||
@ -530,6 +531,39 @@ private:
|
||||
*/
|
||||
ErrCode AddFormTimer(const FormRecord &formRecord);
|
||||
|
||||
/**
|
||||
* @brief check the publish form.
|
||||
* @param want The want of the form to publish.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode CheckPublishForm(Want &want);
|
||||
|
||||
/**
|
||||
* @brief Post request publish form to host.
|
||||
* @param want The want of the form to publish.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode RequestPublishFormToHost(Want &want);
|
||||
|
||||
/**
|
||||
* @brief check the argv of AddRequestPublishForm.
|
||||
* @param want The want of the form to add.
|
||||
* @param formProviderWant The want of the form to publish from provider.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode CheckAddRequestPublishForm(const Want &want, const Want &formProviderWant);
|
||||
|
||||
/**
|
||||
* @brief add request publish form.
|
||||
* @param formId The Id of the forms to add.
|
||||
* @param want The want of the form to add.
|
||||
* @param callerToken Caller ability token.
|
||||
* @param formJsInfo Return form info to form host.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode AddRequestPublishForm(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken,
|
||||
FormJsInfo &formJsInfo);
|
||||
|
||||
/**
|
||||
* @brief get bundleName.
|
||||
* @param bundleName for output.
|
||||
|
@ -119,10 +119,11 @@ public:
|
||||
* @param want The want of the form to publish.
|
||||
* @param withFormBindingData Indicates whether the formBindingData is carried with.
|
||||
* @param formBindingData Indicates the form data.
|
||||
* @param formId Return the form id to be published.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData) override;
|
||||
std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId) override;
|
||||
|
||||
/**
|
||||
* @brief lifecycle update.
|
||||
|
@ -1222,7 +1222,7 @@ bool FormDataMgr::CreateFormStateRecord(std::string &provider, const FormItemInf
|
||||
* @return Returns true if this function is successfully called; returns false otherwise.
|
||||
*/
|
||||
ErrCode FormDataMgr::AcquireFormStateBack(AppExecFwk::FormState state, const std::string &provider,
|
||||
const AAFwk::Want &want)
|
||||
const Want &want)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(formStateRecordMutex_);
|
||||
auto iter = formStateRecord_.find(provider);
|
||||
@ -1490,5 +1490,55 @@ int32_t FormDataMgr::ClearHostDataByInvalidForms(int32_t callingUid, std::map<in
|
||||
HILOG_INFO("DeleteInvalidForms host done");
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode FormDataMgr::AddRequestPublishFormInfo(int64_t formId, const Want &want,
|
||||
std::unique_ptr<FormProviderData> &formProviderData)
|
||||
{
|
||||
HILOG_INFO("add request publish form info, formId: %{public}" PRId64 "", formId);
|
||||
std::lock_guard<std::mutex> lock(formRequestPublishFormsMutex_);
|
||||
|
||||
auto insertResult = formRequestPublishForms_.insert(
|
||||
std::make_pair(formId, std::make_pair(want, std::move(formProviderData))));
|
||||
if (!insertResult.second) {
|
||||
HILOG_ERROR("Failed to emplace requestPublishFormInfo");
|
||||
return ERR_APPEXECFWK_FORM_COMMON_CODE;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode FormDataMgr::RemoveRequestPublishFormInfo(int64_t formId)
|
||||
{
|
||||
HILOG_INFO("remove request publish form info, formId: %{public}" PRId64 "", formId);
|
||||
std::lock_guard<std::mutex> lock(formRequestPublishFormsMutex_);
|
||||
formRequestPublishForms_.erase(formId);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
bool FormDataMgr::IsRequestPublishForm(int64_t formId)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(formRequestPublishFormsMutex_);
|
||||
auto result = formRequestPublishForms_.find(formId);
|
||||
if (result == formRequestPublishForms_.end()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ErrCode FormDataMgr::GetRequestPublishFormInfo(int64_t formId, Want &want,
|
||||
std::unique_ptr<FormProviderData> &formProviderData)
|
||||
{
|
||||
HILOG_INFO("get request publish form info, formId: %{public}" PRId64 "", formId);
|
||||
std::lock_guard<std::mutex> lock(formRequestPublishFormsMutex_);
|
||||
auto result = formRequestPublishForms_.find(formId);
|
||||
if (result == formRequestPublishForms_.end()) {
|
||||
HILOG_INFO("request publish form id not found, formId: %{public}" PRId64 "", formId);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_FORM_ID;
|
||||
}
|
||||
|
||||
want = result->second.first;
|
||||
formProviderData = std::move(result->second.second);
|
||||
formRequestPublishForms_.erase(result);
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -77,6 +77,10 @@ int FormMgrAdapter::AddForm(const int64_t formId, const Want &want,
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (formId > 0 && FormDataMgr::GetInstance().IsRequestPublishForm(formId)) {
|
||||
return AddRequestPublishForm(formId, want, callerToken, formInfo);
|
||||
}
|
||||
|
||||
// check form count limit
|
||||
bool tempFormFlag = want.GetBoolParam(Constants::PARAM_FORM_TEMPORARY_KEY, false);
|
||||
int callingUid = IPCSkeleton::GetCallingUid();
|
||||
@ -1293,12 +1297,6 @@ int FormMgrAdapter::SetNextRefreshTime(const int64_t formId, const int64_t nextT
|
||||
return SetNextRefreshtTimeLocked(matchedFormId, nextTime, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add the form info.
|
||||
*
|
||||
* @param formInfo Indicates the form info to be added.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FormMgrAdapter::AddFormInfo(FormInfo &formInfo)
|
||||
{
|
||||
std::string bundleName;
|
||||
@ -1320,13 +1318,6 @@ ErrCode FormMgrAdapter::AddFormInfo(FormInfo &formInfo)
|
||||
return FormInfoMgr::GetInstance().AddDynamicFormInfo(formInfo, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Remove the specified form info.
|
||||
*
|
||||
* @param moduleName Indicates the module name of the dynamic form info to be removed.
|
||||
* @param formName Indicates the form name of the dynamic form info to be removed.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FormMgrAdapter::RemoveFormInfo(const std::string &moduleName, const std::string &formName)
|
||||
{
|
||||
std::string bundleName;
|
||||
@ -1340,20 +1331,268 @@ ErrCode FormMgrAdapter::RemoveFormInfo(const std::string &moduleName, const std:
|
||||
return FormInfoMgr::GetInstance().RemoveDynamicFormInfo(bundleName, moduleName, formName, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request to publish a form to the form host.
|
||||
*
|
||||
* @param want The want of the form to publish.
|
||||
* @param withFormBindingData Indicates whether the formBindingData is carried with.
|
||||
* @param formBindingData Indicates the form data.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FormMgrAdapter::RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData)
|
||||
ErrCode FormMgrAdapter::CheckPublishForm(Want &want)
|
||||
{
|
||||
std::string bundleName;
|
||||
if (!GetBundleName(bundleName)) {
|
||||
return ERR_APPEXECFWK_FORM_GET_BUNDLE_FAILED;
|
||||
}
|
||||
sptr<IBundleMgr> iBundleMgr = FormBmsHelper::GetInstance().GetBundleMgr();
|
||||
if (iBundleMgr == nullptr) {
|
||||
HILOG_ERROR("%{public}s fail, failed to get IBundleMgr.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_GET_BMS_FAILED;
|
||||
}
|
||||
if (!CheckIsSystemAppByBundleName(iBundleMgr, bundleName)) {
|
||||
HILOG_ERROR("Only system app can request publish form.");
|
||||
return ERR_APPEXECFWK_FORM_PERMISSION_DENY;
|
||||
}
|
||||
|
||||
if (bundleName != want.GetElement().GetBundleName()) {
|
||||
HILOG_WARN("The bundleName in want does not match the bundleName of current calling user.");
|
||||
want.SetBundle(bundleName);
|
||||
}
|
||||
|
||||
std::string moduleName = want.GetStringParam(Constants::PARAM_MODULE_NAME_KEY);
|
||||
if (moduleName.empty()) {
|
||||
HILOG_ERROR("%{public}s error, moduleName is empty.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
bool isTemporary = want.GetBoolParam(AppExecFwk::Constants::PARAM_FORM_TEMPORARY_KEY, false);
|
||||
if (isTemporary) {
|
||||
HILOG_WARN("The published form should not be temp.");
|
||||
want.SetParam(AppExecFwk::Constants::PARAM_FORM_TEMPORARY_KEY, false);
|
||||
}
|
||||
|
||||
std::string abilityName = want.GetElement().GetAbilityName();
|
||||
std::string formName = want.GetStringParam(AppExecFwk::Constants::PARAM_FORM_NAME_KEY);
|
||||
std::vector<FormInfo> formInfos {};
|
||||
ErrCode errCode = FormInfoMgr::GetInstance().GetFormsInfoByModule(bundleName, moduleName, formInfos);
|
||||
if (errCode != ERR_OK) {
|
||||
HILOG_ERROR("%{public}s error, failed to get forms info.", __func__);
|
||||
return errCode;
|
||||
}
|
||||
for (auto &formInfo: formInfos) {
|
||||
int32_t dimensionId = want.GetIntParam(Constants::PARAM_FORM_DIMENSION_KEY, 0);
|
||||
if ((formInfo.abilityName == abilityName) && (formInfo.name == formName) &&
|
||||
(IsDimensionValid(formInfo, dimensionId))) {
|
||||
want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, dimensionId);
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
HILOG_ERROR("failed to find match form info.");
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ErrCode FormMgrAdapter::RequestPublishFormToHost(Want &want)
|
||||
{
|
||||
sptr<IBundleMgr> iBundleMgr = FormBmsHelper::GetInstance().GetBundleMgr();
|
||||
/* Query the highest priority ability or extension ability for publishing form */
|
||||
Want wantAction;
|
||||
wantAction.SetAction(Constants::FORM_PUBLISH_ACTION);
|
||||
AppExecFwk::AbilityInfo abilityInfo;
|
||||
AppExecFwk::ExtensionAbilityInfo extensionAbilityInfo;
|
||||
int callingUid = IPCSkeleton::GetCallingUid();
|
||||
int32_t userId = GetCurrentUserId(callingUid);
|
||||
if (!IN_PROCESS_CALL(iBundleMgr->ImplicitQueryInfoByPriority(wantAction,
|
||||
AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, userId, abilityInfo, extensionAbilityInfo))) {
|
||||
HILOG_ERROR("Failed to ImplicitQueryInfoByPriority for publishing form");
|
||||
return ERR_APPEXECFWK_FORM_GET_HOST_FAILED;
|
||||
}
|
||||
|
||||
if (abilityInfo.name.empty() && extensionAbilityInfo.name.empty()) {
|
||||
HILOG_ERROR("Query highest priority ability failed, no form host ability found.");
|
||||
return ERR_APPEXECFWK_FORM_GET_HOST_FAILED;
|
||||
}
|
||||
|
||||
Want wantToHost;
|
||||
ElementName elementName = want.GetElement();
|
||||
wantToHost.SetParam(Constants::PARAM_BUNDLE_NAME_KEY, elementName.GetBundleName());
|
||||
wantToHost.SetParam(Constants::PARAM_ABILITY_NAME_KEY, elementName.GetAbilityName());
|
||||
std::string strFormId = want.GetStringParam(Constants::PARAM_FORM_IDENTITY_KEY);
|
||||
wantToHost.SetParam(Constants::PARAM_FORM_IDENTITY_KEY, strFormId);
|
||||
std::string formName = want.GetStringParam(Constants::PARAM_FORM_NAME_KEY);
|
||||
wantToHost.SetParam(Constants::PARAM_FORM_NAME_KEY, formName);
|
||||
std::string moduleName = want.GetStringParam(Constants::PARAM_MODULE_NAME_KEY);
|
||||
wantToHost.SetParam(Constants::PARAM_MODULE_NAME_KEY, moduleName);
|
||||
int32_t dimensionId = want.GetIntParam(Constants::PARAM_FORM_DIMENSION_KEY, 0);
|
||||
wantToHost.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, dimensionId);
|
||||
bool tempFormFlag = want.GetBoolParam(Constants::PARAM_FORM_TEMPORARY_KEY, false);
|
||||
wantToHost.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, tempFormFlag);
|
||||
|
||||
if (!abilityInfo.name.empty()) {
|
||||
/* highest priority ability */
|
||||
HILOG_INFO("Start the highest priority ability. bundleName: %{public}s, ability:%{public}s",
|
||||
abilityInfo.bundleName.c_str(), abilityInfo.name.c_str());
|
||||
wantToHost.SetElementName(abilityInfo.bundleName, abilityInfo.name);
|
||||
} else {
|
||||
/* highest priority extension ability */
|
||||
HILOG_INFO("Start the highest priority extension ability. bundleName: %{public}s, ability:%{public}s",
|
||||
extensionAbilityInfo.bundleName.c_str(), extensionAbilityInfo.name.c_str());
|
||||
wantToHost.SetElementName(extensionAbilityInfo.bundleName, extensionAbilityInfo.name);
|
||||
}
|
||||
|
||||
return FormAmsHelper::GetInstance().GetAbilityManager()->StartAbility(wantToHost, userId, DEFAULT_INVAL_VALUE);
|
||||
}
|
||||
|
||||
ErrCode FormMgrAdapter::RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
ErrCode errCode = CheckPublishForm(want);
|
||||
if (errCode != ERR_OK) {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
// generate formId
|
||||
formId = FormDataMgr::GetInstance().GenerateFormId();
|
||||
if (formId < 0) {
|
||||
HILOG_ERROR("%{public}s fail, generateFormId no invalid formId", __func__);
|
||||
return ERR_APPEXECFWK_FORM_COMMON_CODE;
|
||||
}
|
||||
HILOG_DEBUG("formId:%{public}" PRId64 "", formId);
|
||||
std::string strFormId = std::to_string(formId);
|
||||
want.SetParam(Constants::PARAM_FORM_IDENTITY_KEY, strFormId);
|
||||
|
||||
if (withFormBindingData) {
|
||||
errCode = FormDataMgr::GetInstance().AddRequestPublishFormInfo(formId, want, formBindingData);
|
||||
} else {
|
||||
std::unique_ptr<FormProviderData> noFormBindingData = nullptr;
|
||||
errCode = FormDataMgr::GetInstance().AddRequestPublishFormInfo(formId, want, noFormBindingData);
|
||||
}
|
||||
if (errCode != ERR_OK) {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
errCode = RequestPublishFormToHost(want);
|
||||
if (errCode != ERR_OK) {
|
||||
FormDataMgr::GetInstance().RemoveRequestPublishFormInfo(formId);
|
||||
}
|
||||
return errCode;
|
||||
}
|
||||
|
||||
ErrCode FormMgrAdapter::CheckAddRequestPublishForm(const Want &want, const Want &formProviderWant)
|
||||
{
|
||||
std::string bundleName = want.GetElement().GetBundleName();
|
||||
std::string bundleNameProvider = formProviderWant.GetElement().GetBundleName();
|
||||
if (bundleNameProvider != bundleName) {
|
||||
HILOG_ERROR("The bundleName is not match.");
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
std::string moduleName = want.GetStringParam(Constants::PARAM_MODULE_NAME_KEY);
|
||||
std::string moduleNameProvider = formProviderWant.GetStringParam(Constants::PARAM_MODULE_NAME_KEY);
|
||||
if (moduleNameProvider != moduleName) {
|
||||
HILOG_ERROR("The moduleName is not match.");
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
std::string abilityName = want.GetElement().GetAbilityName();
|
||||
std::string abilityNameProvider = formProviderWant.GetElement().GetAbilityName();
|
||||
if (abilityNameProvider != abilityName) {
|
||||
HILOG_ERROR("The abilityName is not match.");
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
std::string formName = want.GetStringParam(Constants::PARAM_FORM_NAME_KEY);
|
||||
std::string formNameProvider = formProviderWant.GetStringParam(Constants::PARAM_FORM_NAME_KEY);
|
||||
if (formNameProvider != formName) {
|
||||
HILOG_ERROR("The formName is not match.");
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
int32_t dimensionId = want.GetIntParam(Constants::PARAM_FORM_DIMENSION_KEY, 0);
|
||||
int32_t dimensionIdProvider = formProviderWant.GetIntParam(Constants::PARAM_FORM_DIMENSION_KEY, 0);
|
||||
if (dimensionIdProvider != dimensionId) {
|
||||
HILOG_ERROR("The dimensionId is not match.");
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
bool isTemporary = want.GetBoolParam(Constants::PARAM_FORM_TEMPORARY_KEY, false);
|
||||
bool isTemporaryProvider = formProviderWant.GetBoolParam(Constants::PARAM_FORM_TEMPORARY_KEY, false);
|
||||
if (isTemporaryProvider != isTemporary) {
|
||||
HILOG_ERROR("The temporary is not match.");
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
int32_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
ErrCode errCode = 0;
|
||||
if (isTemporary) {
|
||||
errCode = FormDataMgr::GetInstance().CheckTempEnoughForm();
|
||||
} else {
|
||||
int32_t currentUserId = GetCurrentUserId(callingUid);
|
||||
errCode = FormDataMgr::GetInstance().CheckEnoughForm(callingUid, currentUserId);
|
||||
}
|
||||
if (errCode != ERR_OK) {
|
||||
HILOG_ERROR("%{public}s fail, too much forms in system", __func__);
|
||||
return errCode;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode FormMgrAdapter::AddRequestPublishForm(const int64_t formId, const Want &want,
|
||||
const sptr<IRemoteObject> &callerToken, FormJsInfo &formJsInfo)
|
||||
{
|
||||
HILOG_INFO("Add request publish form.");
|
||||
Want formProviderWant;
|
||||
std::unique_ptr<FormProviderData> formProviderData = nullptr;
|
||||
ErrCode errCode = FormDataMgr::GetInstance().GetRequestPublishFormInfo(formId, formProviderWant, formProviderData);
|
||||
if (errCode != ERR_OK) {
|
||||
HILOG_ERROR("Failed to get request publish form");
|
||||
return errCode;
|
||||
}
|
||||
|
||||
errCode = CheckAddRequestPublishForm(want, formProviderWant);
|
||||
if (errCode != ERR_OK) {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
FormItemInfo formItemInfo;
|
||||
errCode = GetFormConfigInfo(want, formItemInfo);
|
||||
formItemInfo.SetFormId(formId);
|
||||
formItemInfo.SetDeviceId(want.GetElement().GetDeviceID());
|
||||
if (errCode != ERR_OK) {
|
||||
HILOG_ERROR("%{public}s fail, get form config info failed.", __func__);
|
||||
return errCode;
|
||||
}
|
||||
if (!formItemInfo.IsValidItem()) {
|
||||
HILOG_ERROR("%{public}s fail, input param itemInfo is invalid", __func__);
|
||||
return ERR_APPEXECFWK_FORM_GET_INFO_FAILED;
|
||||
}
|
||||
|
||||
int32_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
if (!FormDataMgr::GetInstance().AllotFormHostRecord(formItemInfo, callerToken, formId, callingUid)) {
|
||||
HILOG_ERROR("%{public}s fail, AllotFormHostRecord failed when no matched formRecord", __func__);
|
||||
return ERR_APPEXECFWK_FORM_COMMON_CODE;
|
||||
}
|
||||
|
||||
// get current userId
|
||||
int32_t currentUserId = GetCurrentUserId(callingUid);
|
||||
// allot form record
|
||||
FormRecord formRecord = FormDataMgr::GetInstance().AllotFormRecord(formItemInfo, callingUid, currentUserId);
|
||||
|
||||
// create form info for js
|
||||
FormDataMgr::GetInstance().CreateFormInfo(formId, formRecord, formJsInfo);
|
||||
if (formProviderData != nullptr) {
|
||||
formJsInfo.formData = formProviderData->GetDataString();
|
||||
formJsInfo.formProviderData = *formProviderData;
|
||||
if (formJsInfo.formData.size() <= Constants::MAX_FORM_DATA_SIZE) {
|
||||
HILOG_INFO("%{public}s, updateJsForm, data is less than 1k, cache data.", __func__);
|
||||
FormCacheMgr::GetInstance().AddData(formId, formJsInfo.formData, formProviderData->GetImageDataMap());
|
||||
}
|
||||
}
|
||||
// storage info
|
||||
if (!formItemInfo.IsTemporaryForm()) {
|
||||
if (ErrCode errorCode = FormDbCache::GetInstance().UpdateDBRecord(formId, formRecord); errorCode != ERR_OK) {
|
||||
HILOG_ERROR("%{public}s fail, UpdateDBRecord failed", __func__);
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
|
||||
// start update timer
|
||||
return AddFormTimer(formRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get bundleName.
|
||||
* @param bundleName for output.
|
||||
|
@ -215,12 +215,6 @@ int FormMgrService::SetNextRefreshTime(const int64_t formId, const int64_t nextT
|
||||
return FormMgrAdapter::GetInstance().SetNextRefreshTime(formId, nextTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add the form info.
|
||||
*
|
||||
* @param formInfo Indicates the form info to be added.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FormMgrService::AddFormInfo(FormInfo &formInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
@ -228,13 +222,6 @@ ErrCode FormMgrService::AddFormInfo(FormInfo &formInfo)
|
||||
return FormMgrAdapter::GetInstance().AddFormInfo(formInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Remove the specified form info.
|
||||
*
|
||||
* @param moduleName Indicates the module name of the dynamic form info to be removed.
|
||||
* @param formName Indicates the form name of the dynamic form info to be removed.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FormMgrService::RemoveFormInfo(const std::string &moduleName, const std::string &formName)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
@ -242,20 +229,12 @@ ErrCode FormMgrService::RemoveFormInfo(const std::string &moduleName, const std:
|
||||
return FormMgrAdapter::GetInstance().RemoveFormInfo(moduleName, formName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request to publish a form to the form host.
|
||||
*
|
||||
* @param want The want of the form to publish.
|
||||
* @param withFormBindingData Indicates whether the formBindingData is carried with.
|
||||
* @param formBindingData Indicates the form data.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FormMgrService::RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData)
|
||||
std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
|
||||
return FormMgrAdapter::GetInstance().RequestPublishForm(want, withFormBindingData, formBindingData);
|
||||
return FormMgrAdapter::GetInstance().RequestPublishForm(want, withFormBindingData, formBindingData, formId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,9 +141,15 @@ HWTEST_F(FmsFormMgrCastTempFormTest, CastTempForm_001, TestSize.Level0)
|
||||
std::vector<FormDBInfo> formDBInfos;
|
||||
FormDbCache::GetInstance().GetAllFormInfo(formDBInfos);
|
||||
EXPECT_EQ(originDbInfoSize + dataCnt, formDBInfos.size());
|
||||
FormDBInfo dbInfo {formDBInfos[0]};
|
||||
EXPECT_EQ(formId, dbInfo.formId);
|
||||
EXPECT_EQ(userUidCnt, dbInfo.formUserUids.size());
|
||||
bool formExist = false;
|
||||
for (size_t i = 0; i < formDBInfos.size(); i++) {
|
||||
if (formId == formDBInfos[i].formId) {
|
||||
EXPECT_EQ(userUidCnt, formDBInfos[i].formUserUids.size());
|
||||
formExist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
EXPECT_TRUE(formExist);
|
||||
// host is added
|
||||
FormHostRecord hostRecord;
|
||||
ret = FormDataMgr::GetInstance().GetFormHostRecord(formId, hostRecord);
|
||||
|
@ -44,7 +44,10 @@ ohos_shared_library("ability_context_native") {
|
||||
"src/local_call_record.cpp",
|
||||
]
|
||||
|
||||
deps = [ "${kits_path}/appkit:app_context" ]
|
||||
deps = [
|
||||
"${kits_path}/appkit:app_context",
|
||||
"${kits_path}/appkit:app_context_utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:configuration",
|
||||
|
@ -137,6 +137,7 @@ ohos_shared_library("abilitykit_native") {
|
||||
"${kits_path}/appkit/native/app/src/sys_mgr_client.cpp",
|
||||
"${services_path}/abilitymgr/src/ability_start_setting.cpp",
|
||||
"${services_path}/abilitymgr/src/launch_param.cpp",
|
||||
"${services_path}/common/src/event_report.cpp",
|
||||
"src/ability.cpp",
|
||||
"src/ability_context.cpp",
|
||||
"src/ability_handler.cpp",
|
||||
@ -201,6 +202,7 @@ ohos_shared_library("abilitykit_native") {
|
||||
":static_subscriber_ipc",
|
||||
"${innerkits_path}/dataobs_manager:dataobs_manager",
|
||||
"${kits_path}/appkit:app_context",
|
||||
"${kits_path}/appkit:app_context_utils",
|
||||
"${kits_path}/appkit:appkit_delegator",
|
||||
]
|
||||
|
||||
@ -220,6 +222,7 @@ ohos_shared_library("abilitykit_native") {
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"dataability:native_dataability",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"hitrace_native:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
"ipc_js:rpc",
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "context/context.h"
|
||||
#include "context/application_context.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "event_report.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
@ -84,7 +85,8 @@ void JsAbility::Init(const std::shared_ptr<AbilityInfo> &abilityInfo,
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto &engine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
jsAbilityObj_ = jsRuntime_.LoadModule(moduleName, srcPath);
|
||||
jsAbilityObj_ =
|
||||
jsRuntime_.LoadModule(moduleName, srcPath, abilityInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE);
|
||||
|
||||
NativeObject *obj = ConvertNativeValueTo<NativeObject>(jsAbilityObj_->Get());
|
||||
if (obj == nullptr) {
|
||||
@ -291,6 +293,10 @@ void JsAbility::OnForeground(const Want &want)
|
||||
applicationContext->DispatchOnAbilityForeground(jsAbilityObj_);
|
||||
}
|
||||
HILOG_INFO("OnForeground end, ability is %{public}s.", GetAbilityName().c_str());
|
||||
AAFWK::EventInfo eventInfo;
|
||||
eventInfo.abilityName = GetAbilityName();
|
||||
AAFWK::EventReport::SendAbilityEvent(AAFWK::ABILITY_ONFOREGROUND,
|
||||
HiSysEventType::BEHAVIOR, eventInfo);
|
||||
}
|
||||
|
||||
void JsAbility::OnBackground()
|
||||
@ -310,6 +316,10 @@ void JsAbility::OnBackground()
|
||||
if (applicationContext != nullptr) {
|
||||
applicationContext->DispatchOnAbilityBackground(jsAbilityObj_);
|
||||
}
|
||||
AAFWK::EventInfo eventInfo;
|
||||
eventInfo.abilityName = GetAbilityName();
|
||||
AAFWK::EventReport::SendAbilityEvent(AAFWK::ABILITY_ONBACKGROUND,
|
||||
HiSysEventType::BEHAVIOR, eventInfo);
|
||||
}
|
||||
|
||||
std::unique_ptr<NativeReference> JsAbility::CreateAppWindowStage()
|
||||
|
@ -65,7 +65,7 @@ void JsFormExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto& engine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath);
|
||||
jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath, abilityInfo_->compileMode == CompileMode::ES_MODULE);
|
||||
if (jsObj_ == nullptr) {
|
||||
HILOG_ERROR("Failed to get jsObj_");
|
||||
return;
|
||||
|
@ -62,7 +62,7 @@ void JsServiceExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto& engine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath);
|
||||
jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath, abilityInfo_->compileMode == CompileMode::ES_MODULE);
|
||||
if (jsObj_ == nullptr) {
|
||||
HILOG_ERROR("Failed to get jsObj_");
|
||||
return;
|
||||
|
@ -64,7 +64,7 @@ void JsStaticSubscriberExtension::Init(const std::shared_ptr<AbilityLocalRecord>
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto& engine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath);
|
||||
jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath, abilityInfo_->compileMode == CompileMode::ES_MODULE);
|
||||
if (jsObj_ == nullptr) {
|
||||
HILOG_ERROR("Failed to get jsObj_");
|
||||
return;
|
||||
|
@ -392,6 +392,7 @@ ohos_unittest("data_ability_helper_test") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"dataability:native_dataability",
|
||||
@ -733,6 +734,7 @@ ohos_unittest("data_ability_impl_file_secondpart_test") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:configuration",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
@ -785,6 +787,7 @@ ohos_unittest("data_ability_impl_file_test") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:configuration",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
|
@ -96,6 +96,7 @@ ohos_shared_library("appkit_native") {
|
||||
"native/app/src/ability_record_mgr.cpp",
|
||||
"native/app/src/app_context.cpp",
|
||||
"native/app/src/app_loader.cpp",
|
||||
"native/app/src/application_data_manager.cpp",
|
||||
"native/app/src/application_env.cpp",
|
||||
"native/app/src/application_env_impl.cpp",
|
||||
"native/app/src/application_impl.cpp",
|
||||
@ -114,6 +115,7 @@ ohos_shared_library("appkit_native") {
|
||||
deps = [
|
||||
":appkit_delegator",
|
||||
"${aafwk_path}/frameworks/kits/appkit:app_context",
|
||||
"${aafwk_path}/frameworks/kits/appkit:app_context_utils",
|
||||
"${innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
]
|
||||
|
||||
@ -173,18 +175,74 @@ ohos_shared_library("app_context") {
|
||||
"native/ability_runtime/context/ability_lifecycle_callback.cpp",
|
||||
"native/ability_runtime/context/application_context.cpp",
|
||||
"native/ability_runtime/context/context_impl.cpp",
|
||||
"native/ability_runtime/context/js_application_context_utils.cpp",
|
||||
"native/ability_runtime/context/js_context_utils.cpp",
|
||||
"native/ability_runtime/context/js_hap_module_info_utils.cpp",
|
||||
"native/ability_runtime/context/js_resource_manager_utils.cpp",
|
||||
"native/app/src/sys_mgr_client.cpp",
|
||||
]
|
||||
cflags = []
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
deps = [ "//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility" ]
|
||||
|
||||
public_deps =
|
||||
[ "${global_path}/resource_management/frameworks/resmgr:global_resmgr" ]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:configuration",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:app_manager",
|
||||
"ability_runtime:runtime",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"eventhandler:libeventhandler",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
"samgr_standard:samgr_proxy",
|
||||
"utils_base:utils",
|
||||
]
|
||||
|
||||
if (os_account_part_enabled) {
|
||||
cflags_cc += [ "-DOS_ACCOUNT_PART_ENABLED" ]
|
||||
external_deps += [ "os_account:os_account_innerkits" ]
|
||||
public_deps += [ "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits" ]
|
||||
}
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
deps += [
|
||||
"${multimodalinput_path}/frameworks/proxy:libmmi-client",
|
||||
"//third_party/icu/icu4c:shared_icuuc",
|
||||
]
|
||||
public_deps += [ "${global_path}/i18n/frameworks/intl:intl_util" ]
|
||||
}
|
||||
part_name = "ability_runtime"
|
||||
}
|
||||
|
||||
# build so
|
||||
ohos_shared_library("app_context_utils") {
|
||||
cflags_cc = []
|
||||
include_dirs = [
|
||||
"native/ability_runtime/context",
|
||||
"native/app/include",
|
||||
]
|
||||
|
||||
configs = [ ":appkit_config" ]
|
||||
|
||||
public_configs = [ ":appkit_public_config" ]
|
||||
|
||||
sources = [
|
||||
"native/ability_runtime/context/js_application_context_utils.cpp",
|
||||
"native/ability_runtime/context/js_context_utils.cpp",
|
||||
"native/ability_runtime/context/js_hap_module_info_utils.cpp",
|
||||
"native/ability_runtime/context/js_resource_manager_utils.cpp",
|
||||
]
|
||||
cflags = []
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
deps = [
|
||||
# "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native",
|
||||
"${aafwk_path}/frameworks/kits/appkit:app_context",
|
||||
"//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility",
|
||||
]
|
||||
|
||||
|
@ -43,7 +43,8 @@ std::shared_ptr<AbilityStage> JsAbilityStage::Create(
|
||||
}
|
||||
std::string moduleName(hapModuleInfo.moduleName);
|
||||
moduleName.append("::").append("AbilityStage");
|
||||
auto moduleObj = jsRuntime.LoadModule(moduleName, srcPath);
|
||||
auto moduleObj =
|
||||
jsRuntime.LoadModule(moduleName, srcPath, hapModuleInfo.compileMode == AppExecFwk::CompileMode::ES_MODULE);
|
||||
return std::make_shared<JsAbilityStage>(jsRuntime, std::move(moduleObj));
|
||||
}
|
||||
|
||||
@ -55,7 +56,8 @@ std::shared_ptr<AbilityStage> JsAbilityStage::Create(
|
||||
srcPath.append(".abc");
|
||||
std::string moduleName(hapModuleInfo.moduleName);
|
||||
moduleName.append("::").append("AbilityStage");
|
||||
moduleObj = jsRuntime.LoadModule(moduleName, srcPath);
|
||||
moduleObj =
|
||||
jsRuntime.LoadModule(moduleName, srcPath, hapModuleInfo.compileMode == AppExecFwk::CompileMode::ES_MODULE);
|
||||
HILOG_INFO("JsAbilityStage srcPath is %{public}s", srcPath.c_str());
|
||||
}
|
||||
return std::make_shared<JsAbilityStage>(jsRuntime, std::move(moduleObj));
|
||||
|
@ -273,7 +273,7 @@ private:
|
||||
std::shared_ptr<Global::Resource::ResourceManager> resourceManager_ = nullptr;
|
||||
std::shared_ptr<AppExecFwk::HapModuleInfo> hapModuleInfo_ = nullptr;
|
||||
std::shared_ptr<AppExecFwk::Configuration> config_ = nullptr;
|
||||
std::string currArea_ = CONTEXT_ELS[EL_DEFAULT];
|
||||
std::string currArea_ = "el2";
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
@ -391,10 +391,16 @@ NativeValue *JsApplicationContextUtils::OnUnregisterAbilityLifecycleCallback(
|
||||
task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "applicationContext is nullptr"));
|
||||
return;
|
||||
}
|
||||
callback->UnRegister(callbackId);
|
||||
if (callback->IsEmpty()) {
|
||||
applicationContext->UnregisterAbilityLifecycleCallback(callback);
|
||||
|
||||
if (callback != nullptr) {
|
||||
callback->UnRegister(callbackId);
|
||||
if (callback->IsEmpty()) {
|
||||
applicationContext->UnregisterAbilityLifecycleCallback(callback);
|
||||
}
|
||||
} else {
|
||||
HILOG_INFO("nothing is registered.");
|
||||
}
|
||||
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
};
|
||||
NativeValue *lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE];
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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_APPEXECFWK_APP_DATA_MANAGER_H
|
||||
#define OHOS_APPEXECFWK_APP_DATA_MANAGER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ierror_observer.h"
|
||||
#include "singleton.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class ApplicationDataManager : public std::enable_shared_from_this<ApplicationDataManager> {
|
||||
DECLARE_DELAYED_SINGLETON(ApplicationDataManager)
|
||||
public:
|
||||
void AddErrorObserver(const std::shared_ptr<IErrorObserver> &observer);
|
||||
void NotifyUnhandledException(const std::string &errMsg);
|
||||
|
||||
private:
|
||||
std::weak_ptr<IErrorObserver> errorObserver_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_APPEXECFWK_APP_DATA_MANAGER_H
|
@ -672,7 +672,7 @@ private:
|
||||
std::shared_ptr<EventRunner> mainEventRunner_;
|
||||
std::shared_ptr<HapModuleInfo> hapModuleInfoLocal_ = nullptr;
|
||||
bool isCreateBySystemApp_ = false;
|
||||
std::string currArea_ = CONTEXT_ELS[EL_DEFAULT];
|
||||
std::string currArea_ = "el2";
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 "application_data_manager.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
ApplicationDataManager::ApplicationDataManager() {}
|
||||
|
||||
ApplicationDataManager::~ApplicationDataManager() {}
|
||||
|
||||
void ApplicationDataManager::AddErrorObserver(const std::shared_ptr<IErrorObserver> &observer)
|
||||
{
|
||||
HILOG_DEBUG("Add error observer come.");
|
||||
errorObserver_ = observer;
|
||||
}
|
||||
|
||||
void ApplicationDataManager::NotifyUnhandledException(const std::string &errMsg)
|
||||
{
|
||||
HILOG_DEBUG("Notify error observer come.");
|
||||
std::shared_ptr<IErrorObserver> observer = errorObserver_.lock();
|
||||
if (observer) {
|
||||
observer->OnUnhandledException(errMsg);
|
||||
}
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include <new>
|
||||
#include <regex>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ability_constants.h"
|
||||
#include "ability_delegator.h"
|
||||
@ -24,6 +25,7 @@
|
||||
#include "ability_loader.h"
|
||||
#include "ability_thread.h"
|
||||
#include "app_loader.h"
|
||||
#include "application_data_manager.h"
|
||||
#include "application_env_impl.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "configuration_convertor.h"
|
||||
@ -876,6 +878,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
if (isStageBased) {
|
||||
// Create runtime
|
||||
AbilityRuntime::Runtime::Options options;
|
||||
options.bundleName = appInfo.bundleName;
|
||||
options.codePath = LOCAL_CODE_PATH;
|
||||
options.eventRunner = mainHandler_->GetEventRunner();
|
||||
options.loadAce = true;
|
||||
@ -904,6 +907,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
std::string errorName = GetNativeStrFromJsTaggedObj(obj, "name");
|
||||
std::string errorStack = GetNativeStrFromJsTaggedObj(obj, "stack");
|
||||
std::string summary = "Error message:" + errorMsg + "\nStacktrace:\n" + errorStack;
|
||||
DelayedSingleton<ApplicationDataManager>::GetInstance()->NotifyUnhandledException(summary);
|
||||
time_t timet;
|
||||
struct tm localUTC;
|
||||
struct timeval gtime;
|
||||
|
@ -106,6 +106,7 @@ ohos_unittest("application_test") {
|
||||
"${aafwk_path}/frameworks/kits/appkit/native/app/src/app_loader.cpp",
|
||||
"../app/src/ohos_application.cpp",
|
||||
"unittest/ability_stage_test.cpp",
|
||||
"unittest/application_data_manager_test.cpp",
|
||||
"unittest/application_test.cpp",
|
||||
"unittest/context_impl_test.cpp",
|
||||
]
|
||||
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include "application_data_manager.h"
|
||||
#include "ierror_observer.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class ApplicationDataManagerTest : public testing::Test {
|
||||
public:
|
||||
ApplicationDataManagerTest()
|
||||
{}
|
||||
~ApplicationDataManagerTest()
|
||||
{}
|
||||
std::shared_ptr<ApplicationDataManager> appDataManagerTest_ = nullptr;
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
static bool Flag;
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
class MyObserver : public IErrorObserver {
|
||||
void OnUnhandledException(std::string errMsg) override;
|
||||
};
|
||||
|
||||
bool ApplicationDataManagerTest::Flag = false;
|
||||
|
||||
void ApplicationDataManagerTest::SetUpTestCase(void)
|
||||
{}
|
||||
|
||||
void ApplicationDataManagerTest::TearDownTestCase(void)
|
||||
{}
|
||||
|
||||
void ApplicationDataManagerTest::SetUp(void)
|
||||
{
|
||||
appDataManagerTest_ = DelayedSingleton<AppExecFwk::ApplicationDataManager>::GetInstance();
|
||||
}
|
||||
|
||||
void ApplicationDataManagerTest::TearDown(void)
|
||||
{}
|
||||
|
||||
void MyObserver::OnUnhandledException(std::string errMsg)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "OnUnhandledException come, errMsg is" << errMsg;
|
||||
ApplicationDataManagerTest::Flag = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: ApplicationDataManager_AddErrorObservers_001
|
||||
* @tc.name: RegisterAbilityLifecycleCallbacks
|
||||
* @tc.desc: Test whether registerabilitylifecyclecallbacks and are called normally.
|
||||
*/
|
||||
HWTEST_F(ApplicationDataManagerTest, ApplicationDataManager_AddErrorObservers_001, Function | MediumTest | Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ApplicationDataManager_AddErrorObservers_001 start";
|
||||
|
||||
EXPECT_NE(appDataManagerTest_, nullptr);
|
||||
std::shared_ptr<MyObserver> observer = std::make_shared<MyObserver>();
|
||||
if (appDataManagerTest_ != nullptr) {
|
||||
appDataManagerTest_->AddErrorObserver(observer);
|
||||
appDataManagerTest_->NotifyUnhandledException("test");
|
||||
EXPECT_EQ(true, ApplicationDataManagerTest::Flag);
|
||||
}
|
||||
GTEST_LOG_(INFO) << "ApplicationDataManager_AddErrorObservers_001 end";
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -47,6 +47,357 @@ constexpr char ARK_DEBUGGER_LIB_PATH[] = "/system/lib64/libark_debugger.z.so";
|
||||
constexpr char ARK_DEBUGGER_LIB_PATH[] = "/system/lib/libark_debugger.z.so";
|
||||
#endif
|
||||
|
||||
constexpr char DEFAULT_BUNDLE_INSTALL_PATH[] = "/data/storage/el1/bundle/";
|
||||
constexpr char BUNDLES_INSTALL_PATH[] = "/data/bundles/";
|
||||
|
||||
constexpr char PREFIX_BUNDLE[] = "@bundle:";
|
||||
constexpr char PREFIX_MODULE[] = "@module:";
|
||||
constexpr char PREFIX_LOCAL[] = "@local:";
|
||||
|
||||
constexpr char NPM_PATH_SEGMENT[] = "node_modules";
|
||||
|
||||
constexpr char NPM_ENTRY_FILE[] = "index.abc";
|
||||
constexpr char NPM_ENTRY_LINK[] = "entry.txt";
|
||||
|
||||
constexpr char EXT_NAME_ABC[] = ".abc";
|
||||
constexpr char EXT_NAME_ETS[] = ".ets";
|
||||
constexpr char EXT_NAME_TS[] = ".ts";
|
||||
constexpr char EXT_NAME_JS[] = ".js";
|
||||
|
||||
constexpr size_t NPM_LEVEL_START = 0;
|
||||
constexpr size_t NPM_LEVEL_END = 1;
|
||||
|
||||
inline bool StringEndWith(const std::string& str, const char* endStr, size_t endStrLen)
|
||||
{
|
||||
size_t len = str.length();
|
||||
return ((len >= endStrLen) && (str.compare(len - endStrLen, endStrLen, endStr) == 0));
|
||||
}
|
||||
|
||||
inline bool StringStartWith(const std::string& str, const char* startStr, size_t startStrLen)
|
||||
{
|
||||
return ((str.length() >= startStrLen) && (str.compare(0, startStrLen, startStr) == 0));
|
||||
}
|
||||
|
||||
void SplitString(const std::string& str, std::vector<std::string>& out, size_t pos = 0, const char* seps = "\\/")
|
||||
{
|
||||
if (str.empty() || pos >= str.length()) {
|
||||
return;
|
||||
}
|
||||
|
||||
size_t startPos = pos;
|
||||
size_t endPos = 0;
|
||||
while ((endPos = str.find_first_of(seps, startPos)) != std::string::npos) {
|
||||
if (endPos > startPos) {
|
||||
out.emplace_back(str.substr(startPos, endPos - startPos));
|
||||
}
|
||||
startPos = endPos + 1;
|
||||
}
|
||||
|
||||
if (startPos < str.length()) {
|
||||
out.emplace_back(str.substr(startPos));
|
||||
}
|
||||
}
|
||||
|
||||
std::string JoinString(const std::vector<std::string>& strs, char sep, size_t startIndex = 0)
|
||||
{
|
||||
std::string out;
|
||||
for (size_t index = startIndex; index < strs.size(); ++index) {
|
||||
if (!strs[index].empty()) {
|
||||
out.append(strs[index]) += sep;
|
||||
}
|
||||
}
|
||||
if (!out.empty()) {
|
||||
out.pop_back();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
inline std::string StripString(const std::string& str, const char* charSet = " \t\n\r")
|
||||
{
|
||||
size_t startPos = str.find_first_not_of(charSet);
|
||||
if (startPos == std::string::npos) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
return str.substr(startPos, str.find_last_not_of(charSet) - startPos + 1);
|
||||
}
|
||||
|
||||
class JsModuleSearcher {
|
||||
public:
|
||||
JsModuleSearcher(const JsModuleSearcher&) = default;
|
||||
JsModuleSearcher(JsModuleSearcher&&) = default;
|
||||
JsModuleSearcher& operator=(const JsModuleSearcher&) = default;
|
||||
JsModuleSearcher& operator=(JsModuleSearcher&&) = default;
|
||||
|
||||
explicit JsModuleSearcher(const std::string& bundleName) : bundleName_(bundleName) {}
|
||||
|
||||
std::string operator()(const std::string& curJsModulePath, const std::string& newJsModuleUri) const
|
||||
{
|
||||
HILOG_INFO("Search JS module (%{public}s, %{public}s) begin",
|
||||
curJsModulePath.c_str(), newJsModuleUri.c_str());
|
||||
|
||||
std::string newJsModulePath;
|
||||
|
||||
if (curJsModulePath.empty() || newJsModuleUri.empty()) {
|
||||
return newJsModulePath;
|
||||
}
|
||||
|
||||
switch (newJsModuleUri[0]) {
|
||||
case '.': {
|
||||
newJsModulePath = MakeNewJsModulePath(curJsModulePath, newJsModuleUri);
|
||||
break;
|
||||
}
|
||||
case '@': {
|
||||
newJsModulePath = ParseOhmUri(curJsModulePath, newJsModuleUri);
|
||||
if (newJsModulePath.empty()) {
|
||||
newJsModulePath = FindNpmPackage(curJsModulePath, newJsModuleUri);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
newJsModulePath = FindNpmPackage(curJsModulePath, newJsModuleUri);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FixExtName(newJsModulePath);
|
||||
|
||||
HILOG_INFO("Search JS module (%{public}s, %{public}s) => %{public}s end",
|
||||
curJsModulePath.c_str(), newJsModuleUri.c_str(), newJsModulePath.c_str());
|
||||
|
||||
return newJsModulePath;
|
||||
}
|
||||
|
||||
private:
|
||||
static void FixExtName(std::string& path)
|
||||
{
|
||||
if (path.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (StringEndWith(path, EXT_NAME_ABC, sizeof(EXT_NAME_ABC) - 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (StringEndWith(path, EXT_NAME_ETS, sizeof(EXT_NAME_ETS) - 1)) {
|
||||
path.erase(path.length() - (sizeof(EXT_NAME_ETS) - 1), sizeof(EXT_NAME_ETS) - 1);
|
||||
} else if (StringEndWith(path, EXT_NAME_TS, sizeof(EXT_NAME_TS) - 1)) {
|
||||
path.erase(path.length() - (sizeof(EXT_NAME_TS) - 1), sizeof(EXT_NAME_TS) - 1);
|
||||
} else if (StringEndWith(path, EXT_NAME_JS, sizeof(EXT_NAME_JS) - 1)) {
|
||||
path.erase(path.length() - (sizeof(EXT_NAME_JS) - 1), sizeof(EXT_NAME_JS) - 1);
|
||||
}
|
||||
|
||||
path.append(EXT_NAME_ABC);
|
||||
}
|
||||
|
||||
static std::string GetInstallPath(const std::string& curJsModulePath, bool module = true)
|
||||
{
|
||||
size_t pos = std::string::npos;
|
||||
if (StringStartWith(curJsModulePath, DEFAULT_BUNDLE_INSTALL_PATH, sizeof(DEFAULT_BUNDLE_INSTALL_PATH) - 1)) {
|
||||
pos = sizeof(DEFAULT_BUNDLE_INSTALL_PATH) - 1 - 1;
|
||||
} else {
|
||||
if (!StringStartWith(curJsModulePath, BUNDLES_INSTALL_PATH, sizeof(BUNDLES_INSTALL_PATH) - 1)) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
pos = curJsModulePath.find('/', sizeof(BUNDLES_INSTALL_PATH) - 1);
|
||||
if (pos == std::string::npos) {
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
if (module) {
|
||||
pos = curJsModulePath.find('/', pos + 1);
|
||||
if (pos == std::string::npos) {
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
return curJsModulePath.substr(0, pos + 1);
|
||||
}
|
||||
|
||||
static std::string MakeNewJsModulePath(const std::string& curJsModulePath, const std::string& newJsModuleUri)
|
||||
{
|
||||
std::string moduleInstallPath = GetInstallPath(curJsModulePath, true);
|
||||
if (moduleInstallPath.empty()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::vector<std::string> pathVector;
|
||||
SplitString(curJsModulePath, pathVector, moduleInstallPath.length());
|
||||
|
||||
if (pathVector.empty()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
// Remove file name, reserve only dir name
|
||||
pathVector.pop_back();
|
||||
|
||||
std::vector<std::string> relativePathVector;
|
||||
SplitString(newJsModuleUri, relativePathVector);
|
||||
|
||||
for (auto& value : relativePathVector) {
|
||||
if (value == ".") {
|
||||
continue;
|
||||
} else if (value == "..") {
|
||||
if (pathVector.empty()) {
|
||||
return std::string();
|
||||
}
|
||||
pathVector.pop_back();
|
||||
} else {
|
||||
pathVector.emplace_back(std::move(value));
|
||||
}
|
||||
}
|
||||
|
||||
return moduleInstallPath + JoinString(pathVector, '/');
|
||||
}
|
||||
|
||||
static std::string FindNpmPackageInPath(const std::string& npmPath)
|
||||
{
|
||||
std::string fileName = npmPath + "/" + NPM_ENTRY_FILE;
|
||||
|
||||
char path[PATH_MAX];
|
||||
if (realpath(fileName.c_str(), path) != nullptr) {
|
||||
return path;
|
||||
}
|
||||
|
||||
fileName = npmPath + "/" + NPM_ENTRY_LINK;
|
||||
if (realpath(fileName.c_str(), path) == nullptr) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::ifstream stream(path, std::ios::ate);
|
||||
if (!stream.is_open()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
size_t fileLen = stream.tellg();
|
||||
if (fileLen >= sizeof(path)) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
stream.seekg(0);
|
||||
stream.read(path, fileLen);
|
||||
path[fileLen] = '\0';
|
||||
return npmPath + '/' + StripString(path);
|
||||
}
|
||||
|
||||
static std::string FindNpmPackageInTopLevel(const std::string& moduleInstallPath, const std::string& npmPackage,
|
||||
size_t start = NPM_LEVEL_START)
|
||||
{
|
||||
for (size_t level = start; level <= NPM_LEVEL_END; ++level) {
|
||||
std::string path = moduleInstallPath + NPM_PATH_SEGMENT + '/' + std::to_string(level) + '/' + npmPackage;
|
||||
path = FindNpmPackageInPath(path);
|
||||
if (!path.empty()) {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
static std::string FindNpmPackage(const std::string& curJsModulePath, const std::string& npmPackage)
|
||||
{
|
||||
std::string moduleInstallPath = GetInstallPath(curJsModulePath);
|
||||
if (moduleInstallPath.empty()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::vector<std::string> pathVector;
|
||||
SplitString(curJsModulePath, pathVector, moduleInstallPath.length());
|
||||
if (pathVector.empty()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (pathVector[0] != NPM_PATH_SEGMENT) {
|
||||
return FindNpmPackageInTopLevel(moduleInstallPath, npmPackage);
|
||||
}
|
||||
|
||||
// Remove file name, reserve only dir name
|
||||
pathVector.pop_back();
|
||||
|
||||
// Find npm package until reach top level npm path such as 'node_modules/0',
|
||||
// so there must be 2 element in vector
|
||||
while (pathVector.size() > 2) {
|
||||
std::string path =
|
||||
moduleInstallPath + JoinString(pathVector, '/') + '/' + NPM_PATH_SEGMENT + '/' + npmPackage;
|
||||
path = FindNpmPackageInPath(path);
|
||||
if (!path.empty()) {
|
||||
return path;
|
||||
}
|
||||
|
||||
pathVector.pop_back();
|
||||
}
|
||||
|
||||
char* p = nullptr;
|
||||
size_t index = std::strtoul(pathVector.back().c_str(), &p, 10);
|
||||
if (p == nullptr || *p != '\0') {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
return FindNpmPackageInTopLevel(moduleInstallPath, npmPackage, index);
|
||||
}
|
||||
|
||||
std::string ParseOhmUri(const std::string& curJsModulePath, const std::string& newJsModuleUri) const
|
||||
{
|
||||
std::string moduleInstallPath;
|
||||
std::vector<std::string> pathVector;
|
||||
size_t index = 0;
|
||||
|
||||
if (StringStartWith(newJsModuleUri, PREFIX_BUNDLE, sizeof(PREFIX_BUNDLE) - 1)) {
|
||||
SplitString(newJsModuleUri, pathVector, sizeof(PREFIX_BUNDLE) - 1);
|
||||
|
||||
// Uri should have atleast 3 segments
|
||||
if (pathVector.size() < 3) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
const auto& bundleName = pathVector[index++];
|
||||
if (bundleName == bundleName_) {
|
||||
moduleInstallPath = DEFAULT_BUNDLE_INSTALL_PATH;
|
||||
} else {
|
||||
moduleInstallPath = BUNDLES_INSTALL_PATH;
|
||||
moduleInstallPath.append(bundleName).append("/");
|
||||
}
|
||||
moduleInstallPath.append(pathVector[index++]).append("/");
|
||||
} else if (StringStartWith(newJsModuleUri, PREFIX_MODULE, sizeof(PREFIX_MODULE) - 1)) {
|
||||
SplitString(newJsModuleUri, pathVector, sizeof(PREFIX_MODULE) - 1);
|
||||
|
||||
// Uri should have atleast 2 segments
|
||||
if (pathVector.size() < 2) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
moduleInstallPath = GetInstallPath(curJsModulePath, false);
|
||||
if (moduleInstallPath.empty()) {
|
||||
return std::string();
|
||||
}
|
||||
moduleInstallPath.append(pathVector[index++]).append("/");
|
||||
} else if (StringStartWith(newJsModuleUri, PREFIX_LOCAL, sizeof(PREFIX_LOCAL) - 1)) {
|
||||
SplitString(newJsModuleUri, pathVector, sizeof(PREFIX_LOCAL) - 1);
|
||||
|
||||
if (pathVector.empty()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
moduleInstallPath = GetInstallPath(curJsModulePath);
|
||||
if (moduleInstallPath.empty()) {
|
||||
return std::string();
|
||||
}
|
||||
} else {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (pathVector[index] != NPM_PATH_SEGMENT) {
|
||||
return moduleInstallPath + JoinString(pathVector, '/', index);
|
||||
}
|
||||
|
||||
return FindNpmPackageInTopLevel(moduleInstallPath, JoinString(pathVector, '/', index + 1));
|
||||
}
|
||||
|
||||
std::string bundleName_;
|
||||
};
|
||||
|
||||
class ArkJsRuntime : public JsRuntime {
|
||||
public:
|
||||
ArkJsRuntime()
|
||||
@ -78,6 +429,23 @@ public:
|
||||
return vm_ != nullptr ? panda::JSNApi::Execute(vm_, path.c_str(), PANDA_MAIN_FUNCTION) : false;
|
||||
}
|
||||
|
||||
NativeValue* LoadJsModule(const std::string& path) override
|
||||
{
|
||||
if (!RunScript(path)) {
|
||||
HILOG_ERROR("Failed to run script: %{public}s", path.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
panda::Local<panda::ObjectRef> exportObj = panda::JSNApi::GetExportObject(vm_, path, "default");
|
||||
if (exportObj->IsNull()) {
|
||||
HILOG_ERROR("Get export object failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ArkNativeEngine::ArkValueToNativeValue(
|
||||
static_cast<ArkNativeEngine*>(nativeEngine_.get()), exportObj);
|
||||
}
|
||||
|
||||
private:
|
||||
static int32_t PrintVmLog(int32_t id, int32_t level, const char* tag, const char* fmt, const char* message)
|
||||
{
|
||||
@ -104,6 +472,8 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
panda::JSNApi::SetHostResolvePathTracker(vm_, JsModuleSearcher(options.bundleName));
|
||||
|
||||
nativeEngine_ = std::make_unique<ArkNativeEngine>(vm_, static_cast<JsRuntime*>(this));
|
||||
return JsRuntime::Initialize(options);
|
||||
}
|
||||
@ -443,9 +813,37 @@ void JsRuntime::Deinitialize()
|
||||
nativeEngine_.reset();
|
||||
}
|
||||
|
||||
std::unique_ptr<NativeReference> JsRuntime::LoadModule(const std::string& moduleName, const std::string& modulePath)
|
||||
NativeValue* JsRuntime::LoadJsBundle(const std::string& path)
|
||||
{
|
||||
HILOG_INFO("JsRuntime::LoadModule(%{public}s, %{public}s)", moduleName.c_str(), modulePath.c_str());
|
||||
NativeObject* globalObj = ConvertNativeValueTo<NativeObject>(nativeEngine_->GetGlobal());
|
||||
NativeValue* exports = nativeEngine_->CreateObject();
|
||||
globalObj->SetProperty("exports", exports);
|
||||
|
||||
if (!RunScript(path)) {
|
||||
HILOG_ERROR("Failed to run script: %{public}s", path.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeObject* exportsObj = ConvertNativeValueTo<NativeObject>(globalObj->GetProperty("exports"));
|
||||
if (exportsObj == nullptr) {
|
||||
HILOG_ERROR("Failed to get exports objcect: %{public}s", path.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue* exportObj = exportsObj->GetProperty("default");
|
||||
if (exportObj == nullptr) {
|
||||
HILOG_ERROR("Failed to get default objcect: %{public}s", path.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return exportObj;
|
||||
}
|
||||
|
||||
std::unique_ptr<NativeReference> JsRuntime::LoadModule(
|
||||
const std::string& moduleName, const std::string& modulePath, bool esmodule)
|
||||
{
|
||||
HILOG_INFO("JsRuntime::LoadModule(%{public}s, %{public}s, %{public}s)", moduleName.c_str(), modulePath.c_str(),
|
||||
esmodule ? "true" : "false");
|
||||
|
||||
HandleScope handleScope(*this);
|
||||
|
||||
@ -461,24 +859,8 @@ std::unique_ptr<NativeReference> JsRuntime::LoadModule(const std::string& module
|
||||
return std::unique_ptr<NativeReference>();
|
||||
}
|
||||
|
||||
NativeObject* globalObj = ConvertNativeValueTo<NativeObject>(nativeEngine_->GetGlobal());
|
||||
NativeValue* exports = nativeEngine_->CreateObject();
|
||||
globalObj->SetProperty("exports", exports);
|
||||
|
||||
if (!RunScript(fileName)) {
|
||||
HILOG_ERROR("Failed to run script: %{public}s", fileName.c_str());
|
||||
return std::unique_ptr<NativeReference>();
|
||||
}
|
||||
|
||||
NativeObject* exportsObj = ConvertNativeValueTo<NativeObject>(globalObj->GetProperty("exports"));
|
||||
if (exportsObj == nullptr) {
|
||||
HILOG_ERROR("Failed to get exports objcect: %{public}s", modulePath.c_str());
|
||||
return std::unique_ptr<NativeReference>();
|
||||
}
|
||||
|
||||
classValue = exportsObj->GetProperty("default");
|
||||
classValue = esmodule ? LoadJsModule(fileName) : LoadJsBundle(fileName);
|
||||
if (classValue == nullptr) {
|
||||
HILOG_ERROR("Failed to get default objcect: %{public}s", modulePath.c_str());
|
||||
return std::unique_ptr<NativeReference>();
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,7 @@ ohos_shared_library("wantagent_innerkits") {
|
||||
deps = [ "${kits_path}/appkit:app_context" ]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:want",
|
||||
"ability_runtime:ability_manager",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
|
@ -16,7 +16,7 @@ import("//build/ohos.gni")
|
||||
config("idl_config") {
|
||||
include_dirs = [
|
||||
"./",
|
||||
"//utils/native/base/include/",
|
||||
"//third_party/bounds_checking_function/include/",
|
||||
]
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ ohos_executable("idl") {
|
||||
|
||||
configs = [ ":idl_config" ]
|
||||
|
||||
deps = [ "//utils/native/base:utilsecurec" ]
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_static" ]
|
||||
|
||||
part_name = "idl"
|
||||
subsystem_name = "aafwk"
|
||||
|
@ -19,7 +19,7 @@ config("idl_module_test_config") {
|
||||
include_dirs = [
|
||||
"../../common",
|
||||
"${IDL_DIR}/",
|
||||
"//utils/native/base/include/",
|
||||
"//third_party/bounds_checking_function/include/",
|
||||
]
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ ohos_moduletest("ts_code_emitter_test") {
|
||||
configs = [ ":idl_module_test_config" ]
|
||||
sources = [ "ts_code_emitter_test.cpp" ]
|
||||
sources += common_sources
|
||||
deps = [ "//utils/native/base:utilsecurec" ]
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_static" ]
|
||||
}
|
||||
|
||||
group("moduletest") {
|
||||
|
@ -19,7 +19,7 @@ config("idl_unittest_test_config") {
|
||||
include_dirs = [
|
||||
"../../common/",
|
||||
"${IDL_DIR}/",
|
||||
"//utils/native/base/include/",
|
||||
"//third_party/bounds_checking_function/include/",
|
||||
]
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ ohos_unittest("ts_code_emitter_interface_test") {
|
||||
configs = [ ":idl_unittest_test_config" ]
|
||||
sources = [ "ts_code_emitter_interface_test.cpp" ]
|
||||
sources += common_sources
|
||||
deps = [ "//utils/native/base:utilsecurec" ]
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_static" ]
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
|
@ -20,7 +20,7 @@ config("idl_unittest_test_config") {
|
||||
"../../common",
|
||||
"${IDL_DIR}/",
|
||||
"${IDL_DIR}/codegen/",
|
||||
"//utils/native/base/include/",
|
||||
"//third_party/bounds_checking_function/include/",
|
||||
]
|
||||
}
|
||||
|
||||
@ -87,9 +87,9 @@ ohos_unittest("ts_code_emitter_proxy_test") {
|
||||
sources += idl_common_sources
|
||||
|
||||
deps = [
|
||||
"//third_party/bounds_checking_function:libsec_static",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utilsecurec",
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ config("idl_unittest_test_config") {
|
||||
include_dirs = [
|
||||
"../../common",
|
||||
"${IDL_DIR}/",
|
||||
"//utils/native/base/include/",
|
||||
"//third_party/bounds_checking_function/include/",
|
||||
]
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ ohos_unittest("ts_code_emitter_stub_test") {
|
||||
configs = [ ":idl_unittest_test_config" ]
|
||||
sources = [ "ts_code_emitter_stub_test.cpp" ]
|
||||
sources += common_sources
|
||||
deps = [ "//utils/native/base:utilsecurec" ]
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_static" ]
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
|
@ -264,92 +264,92 @@ enum NativeFreeInstallError {
|
||||
/**
|
||||
* FA search failed.
|
||||
*/
|
||||
FA_FREE_INSTALL_QUERY_ERROR = 0x800001,
|
||||
FA_FREE_INSTALL_QUERY_ERROR = -1,
|
||||
|
||||
/**
|
||||
* HAG query timeout.
|
||||
*/
|
||||
HAG_QUERY_TIMEOUT = 0x800002,
|
||||
HAG_QUERY_TIMEOUT = -4,
|
||||
|
||||
/**
|
||||
* FA Network unavailable.
|
||||
*/
|
||||
FA_NETWORK_UNAVAILABLE = 0x800003,
|
||||
FA_NETWORK_UNAVAILABLE = -2,
|
||||
|
||||
/**
|
||||
* FA internal system error.
|
||||
*/
|
||||
FA_FREE_INSTALL_SERVICE_ERROR = 0x600001,
|
||||
FA_FREE_INSTALL_SERVICE_ERROR = 0x820101,
|
||||
|
||||
/**
|
||||
* FA distribution center crash.
|
||||
*/
|
||||
FA_CRASH = 0x600002,
|
||||
FA_CRASH = 0x820102,
|
||||
|
||||
/**
|
||||
* FA distribution center processing timeout(30s).
|
||||
*/
|
||||
FA_TIMEOUT = 0x600003,
|
||||
FA_TIMEOUT = 0x820103,
|
||||
|
||||
/**
|
||||
* BMS unknown exception.
|
||||
*/
|
||||
UNKNOWN_EXCEPTION = 0x600004,
|
||||
UNKNOWN_EXCEPTION = 0x820104,
|
||||
|
||||
/**
|
||||
* It is not supported to pull up PA across applications on the same device
|
||||
*/
|
||||
NOT_SUPPORT_PA_ON_SAME_DEVICE = 0x800004,
|
||||
NOT_SUPPORT_PA_ON_SAME_DEVICE = -11,
|
||||
|
||||
/**
|
||||
* FA internal system error.
|
||||
*/
|
||||
FA_INTERNET_ERROR = 0x800005,
|
||||
FA_INTERNET_ERROR = -3,
|
||||
|
||||
/**
|
||||
* The user confirms to jump to the application market upgrade.
|
||||
*/
|
||||
JUMP_TO_THE_APPLICATION_MARKET_UPGRADE = 0x800006,
|
||||
JUMP_TO_THE_APPLICATION_MARKET_UPGRADE = -8,
|
||||
|
||||
/**
|
||||
* User gives up.
|
||||
*/
|
||||
USER_GIVES_UP = 0x800007,
|
||||
USER_GIVES_UP = -7,
|
||||
|
||||
/**
|
||||
* Installation error in free installation.
|
||||
*/
|
||||
INSTALLATION_ERROR_IN_FREE_INSTALL = 0x800008,
|
||||
INSTALLATION_ERROR_IN_FREE_INSTALL = -5,
|
||||
|
||||
/**
|
||||
* HAP package download timed out.
|
||||
*/
|
||||
HAP_PACKAGE_DOWNLOAD_TIMED_OUT = 0x800009,
|
||||
HAP_PACKAGE_DOWNLOAD_TIMED_OUT = -9,
|
||||
|
||||
/**
|
||||
* There are concurrent tasks, waiting for retry.
|
||||
*/
|
||||
CONCURRENT_TASKS_WAITING_FOR_RETRY = 0x800010,
|
||||
CONCURRENT_TASKS_WAITING_FOR_RETRY = -6,
|
||||
|
||||
/**
|
||||
* FA package does not support free installation.
|
||||
*/
|
||||
FA_PACKAGE_DOES_NOT_SUPPORT_FREE_INSTALL = 0x800011,
|
||||
FA_PACKAGE_DOES_NOT_SUPPORT_FREE_INSTALL = -10,
|
||||
|
||||
/**
|
||||
* The app is not allowed to pull this FA.
|
||||
*/
|
||||
NOT_ALLOWED_TO_PULL_THIS_FA = 0x800012,
|
||||
NOT_ALLOWED_TO_PULL_THIS_FA = -901,
|
||||
|
||||
/**
|
||||
* Not support cross-device free install PA
|
||||
*/
|
||||
NOT_SUPPORT_CROSS_DEVICE_FREE_INSTALL_PA = 0x80013,
|
||||
NOT_SUPPORT_CROSS_DEVICE_FREE_INSTALL_PA = -12,
|
||||
|
||||
/**
|
||||
* Free install timeout
|
||||
*/
|
||||
FREE_INSTALL_TIMEOUT = 0x710003,
|
||||
FREE_INSTALL_TIMEOUT = 29360300,
|
||||
|
||||
/**
|
||||
* Not top ability
|
||||
@ -361,11 +361,6 @@ enum NativeFreeInstallError {
|
||||
*/
|
||||
TARGET_BUNDLE_NOT_EXIST = 0x500002,
|
||||
|
||||
/**
|
||||
* FA Network unavailable in free install.
|
||||
*/
|
||||
FA_FREE_INSTALL_INTERNET_ERROR = 0x800013,
|
||||
|
||||
/**
|
||||
* Permission denied.
|
||||
*/
|
||||
@ -390,6 +385,26 @@ enum NativeFreeInstallError {
|
||||
* Remote service's device is offline.
|
||||
*/
|
||||
DEVICE_OFFLINE_ERR = 29360142,
|
||||
|
||||
/**
|
||||
* Result(29360175) for account access permission check failed.
|
||||
*/
|
||||
DMS_ACCOUNT_ACCESS_PERMISSION_DENIED = 29360175,
|
||||
|
||||
/**
|
||||
* Result(29360131) for remote invalid parameters.
|
||||
*/
|
||||
INVALID_REMOTE_PARAMETERS_ERR = 29360131,
|
||||
|
||||
/*
|
||||
* Result(29360205) for continue freeinstall failed.
|
||||
*/
|
||||
CONTINUE_FREE_INSTALL_FAILED = 29360205,
|
||||
|
||||
/**
|
||||
* Undefine error code.
|
||||
*/
|
||||
UNDEFINE_ERROR_CODE = 3,
|
||||
};
|
||||
|
||||
static const std::map<NativeFreeInstallError, int> FIErrorToAppMaps = {
|
||||
@ -413,13 +428,15 @@ static const std::map<NativeFreeInstallError, int> FIErrorToAppMaps = {
|
||||
{NOT_SUPPORT_CROSS_DEVICE_FREE_INSTALL_PA, 7},
|
||||
{DMS_PERMISSION_DENIED, 8},
|
||||
{DMS_COMPONENT_ACCESS_PERMISSION_DENIED, 8},
|
||||
{DMS_ACCOUNT_ACCESS_PERMISSION_DENIED, 8},
|
||||
{INVALID_PARAMETERS_ERR, 9},
|
||||
{INVALID_REMOTE_PARAMETERS_ERR, 9},
|
||||
{REMOTE_DEVICE_NOT_COMPATIBLE, 10},
|
||||
{DEVICE_OFFLINE_ERR, 11},
|
||||
{FREE_INSTALL_TIMEOUT, 12},
|
||||
{NOT_TOP_ABILITY, 13},
|
||||
{TARGET_BUNDLE_NOT_EXIST, 14},
|
||||
{FA_FREE_INSTALL_INTERNET_ERROR, 15}
|
||||
{CONTINUE_FREE_INSTALL_FAILED, 15},
|
||||
};
|
||||
|
||||
static const std::map<NativeFreeInstallError, std::string> FIErrorStrs = {
|
||||
@ -503,10 +520,18 @@ static const std::map<NativeFreeInstallError, std::string> FIErrorStrs = {
|
||||
DMS_COMPONENT_ACCESS_PERMISSION_DENIED,
|
||||
"Component access permission denied."
|
||||
},
|
||||
{
|
||||
DMS_ACCOUNT_ACCESS_PERMISSION_DENIED,
|
||||
"Component access permission denied."
|
||||
},
|
||||
{
|
||||
INVALID_PARAMETERS_ERR,
|
||||
"Invalid parameters."
|
||||
},
|
||||
{
|
||||
INVALID_REMOTE_PARAMETERS_ERR,
|
||||
"Invalid parameters."
|
||||
},
|
||||
{
|
||||
REMOTE_DEVICE_NOT_COMPATIBLE,
|
||||
"Remote DMS is not compatible."
|
||||
@ -517,7 +542,7 @@ static const std::map<NativeFreeInstallError, std::string> FIErrorStrs = {
|
||||
},
|
||||
{
|
||||
FREE_INSTALL_TIMEOUT,
|
||||
"free install timeout."
|
||||
"Free install timeout."
|
||||
},
|
||||
{
|
||||
NOT_TOP_ABILITY,
|
||||
@ -528,8 +553,8 @@ static const std::map<NativeFreeInstallError, std::string> FIErrorStrs = {
|
||||
"Target bundle name is not exist in targetBundleList."
|
||||
},
|
||||
{
|
||||
FA_FREE_INSTALL_INTERNET_ERROR,
|
||||
"Network unavailable."
|
||||
CONTINUE_FREE_INSTALL_FAILED,
|
||||
"Error continue freeinstall failed."
|
||||
},
|
||||
};
|
||||
} // namespace AAFwk
|
||||
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* 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_AAFWK_SYSTEM_ABILITY_TOKEN_CALLBACK_PROXY_H
|
||||
#define OHOS_AAFWK_SYSTEM_ABILITY_TOKEN_CALLBACK_PROXY_H
|
||||
|
||||
#include "system_ability_token_callback.h"
|
||||
#include "iremote_proxy.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
class SystemAbilityTokenCallbackProxy : public IRemoteProxy<ISystemAbilityTokenCallback> {
|
||||
public:
|
||||
explicit SystemAbilityTokenCallbackProxy(const sptr<IRemoteObject> &impl)
|
||||
: IRemoteProxy<ISystemAbilityTokenCallback>(impl)
|
||||
{}
|
||||
virtual ~SystemAbilityTokenCallbackProxy() {}
|
||||
|
||||
/**
|
||||
* @brief When the remote device send result back to system ability, AbilityMs notify the listener.
|
||||
*
|
||||
* @param want, want of caller.
|
||||
* @param callerUid, uid of caller.
|
||||
* @param deviceId, requestCode of caller.
|
||||
* @param deviceId, accessToken of caller .
|
||||
* @param deviceId, resultCode of caller.
|
||||
*/
|
||||
virtual int32_t SendResult(OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode,
|
||||
uint32_t accessToken, int32_t resultCode) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<SystemAbilityTokenCallbackProxy> delegator_;
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_AAFWK_SYSTEM_ABILITY_TOKEN_CALLBACK_PROXY_H
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 ABILITY_RUNTIME_APP_MANAGER_IERROR_ONSERVER_H
|
||||
#define ABILITY_RUNTIME_APP_MANAGER_IERROR_ONSERVER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class IErrorObserver {
|
||||
public:
|
||||
IErrorObserver() = default;
|
||||
virtual ~IErrorObserver() = default;
|
||||
/**
|
||||
* Will be called when the js runtime throws an exception which doesn't caught by user.
|
||||
*
|
||||
* @param errMsg the message and error stacktrace about the exception.
|
||||
*/
|
||||
virtual void OnUnhandledException(std::string errMsg) = 0;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // ABILITY_RUNTIME_APP_MANAGER_IERROR_ONSERVER_H
|
@ -49,7 +49,8 @@ public:
|
||||
return Language::JS;
|
||||
}
|
||||
|
||||
std::unique_ptr<NativeReference> LoadModule(const std::string& moduleName, const std::string& modulePath);
|
||||
std::unique_ptr<NativeReference> LoadModule(
|
||||
const std::string& moduleName, const std::string& modulePath, bool esmodule = false);
|
||||
std::unique_ptr<NativeReference> LoadSystemModule(
|
||||
const std::string& moduleName, NativeValue* const* argv = nullptr, size_t argc = 0);
|
||||
void PostTask(const TimerTask& task, const std::string& name, int64_t delayTime);
|
||||
@ -59,8 +60,8 @@ public:
|
||||
void DumpHeapSnapshot(bool isPrivate) override;
|
||||
std::string BuildNativeAndJsBackStackTrace() override;
|
||||
|
||||
virtual bool RunScript(const std::string& path);
|
||||
virtual bool RunSandboxScript(const std::string& path);
|
||||
bool RunSandboxScript(const std::string& path);
|
||||
virtual bool RunScript(const std::string& path) = 0;
|
||||
|
||||
protected:
|
||||
JsRuntime() = default;
|
||||
@ -68,6 +69,9 @@ protected:
|
||||
virtual bool Initialize(const Options& options);
|
||||
void Deinitialize();
|
||||
|
||||
virtual NativeValue* LoadJsBundle(const std::string& path);
|
||||
virtual NativeValue* LoadJsModule(const std::string& path) = 0;
|
||||
|
||||
bool isArkEngine_ = false;
|
||||
bool debugMode_ = false;
|
||||
std::unique_ptr<NativeEngine> nativeEngine_;
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
|
||||
struct Options {
|
||||
Language lang = Language::JS;
|
||||
std::string bundleName;
|
||||
std::string codePath;
|
||||
std::string packagePath;
|
||||
std::shared_ptr<AppExecFwk::EventRunner> eventRunner;
|
||||
|
@ -28,6 +28,7 @@ group("napi_packages") {
|
||||
"${aafwk_napi_path}/app/app_manager:appmanager_napi",
|
||||
"${aafwk_napi_path}/app/application_context:applicationcontext_napi",
|
||||
"${aafwk_napi_path}/app/context:context_napi",
|
||||
"${aafwk_napi_path}/app/error_manager:errormanager_napi",
|
||||
"${aafwk_napi_path}/app/test_runner:testrunner_napi",
|
||||
"${aafwk_napi_path}/callee:callee_napi",
|
||||
"${aafwk_napi_path}/caller:caller_napi",
|
||||
|
@ -34,6 +34,7 @@ ohos_shared_library("abilitydelegatorregistry") {
|
||||
deps = [
|
||||
"${aafwk_path}/interfaces/kits/napi/aafwk/inner/napi_common:napi_common",
|
||||
"${kits_path}/appkit:app_context",
|
||||
"${kits_path}/appkit:app_context_utils",
|
||||
"${kits_path}/appkit:appkit_delegator",
|
||||
]
|
||||
|
||||
|
48
interfaces/kits/napi/aafwk/app/error_manager/BUILD.gn
Normal file
48
interfaces/kits/napi/aafwk/app/error_manager/BUILD.gn
Normal file
@ -0,0 +1,48 @@
|
||||
# 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/ability/ability_runtime/aafwk.gni")
|
||||
|
||||
ohos_shared_library("errormanager_napi") {
|
||||
include_dirs = []
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
include_dirs += [ "./" ]
|
||||
}
|
||||
|
||||
sources = [
|
||||
"error_manager_module.cpp",
|
||||
"js_error_manager.cpp",
|
||||
"js_error_observer.cpp",
|
||||
]
|
||||
|
||||
configs = [ "${aafwk_path}/services/common:common_config" ]
|
||||
|
||||
deps = [ "${aafwk_path}/frameworks/kits/appkit:appkit_native" ]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:app_manager",
|
||||
"ability_runtime:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"napi:ace_napi",
|
||||
"utils_base:utils",
|
||||
]
|
||||
|
||||
relative_install_dir = "module/application"
|
||||
|
||||
subsystem_name = "aafwk"
|
||||
part_name = "ability_runtime"
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 "js_error_manager.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
extern "C" __attribute__((constructor)) void NAPI_application_ErrorManager_AutoRegister()
|
||||
{
|
||||
auto moduleManager = NativeModuleManager::GetInstance();
|
||||
NativeModule newModuleInfo = {
|
||||
.name = "application.ErrorManager",
|
||||
.fileName = "application/errormanager_napi.so/error_manager.js",
|
||||
.registerCallback = OHOS::AbilityRuntime::JsErrorManagerInit,
|
||||
};
|
||||
|
||||
moduleManager->Register(&newModuleInfo);
|
||||
}
|
@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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 "js_error_manager.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "application_data_manager.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_error_observer.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi/native_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr int32_t INDEX_ZERO = 0;
|
||||
constexpr int32_t INDEX_ONE = 1;
|
||||
constexpr int32_t ERROR_CODE = -1;
|
||||
constexpr int32_t INVALID_PARAM = -2;
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
|
||||
class JsErrorManager final {
|
||||
public:
|
||||
JsErrorManager() {}
|
||||
~JsErrorManager() = default;
|
||||
|
||||
static void Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
HILOG_INFO("JsErrorManager Finalizer is called");
|
||||
std::unique_ptr<JsErrorManager>(static_cast<JsErrorManager*>(data));
|
||||
}
|
||||
|
||||
static NativeValue* RegisterErrorObserver(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsErrorManager* me = CheckParamsAndGetThis<JsErrorManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnRegisterErrorObserver(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* UnregisterErrorObserver(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsErrorManager* me = CheckParamsAndGetThis<JsErrorManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnUnregisterErrorObserver(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
NativeValue* OnRegisterErrorObserver(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("Register errorObserver is called.");
|
||||
// only support one
|
||||
if (info.argc != ARGC_ONE) {
|
||||
HILOG_ERROR("The param is invalid, observers need.");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
int32_t observerId = serialNumber_;
|
||||
if (serialNumber_ < INT32_MAX) {
|
||||
serialNumber_++;
|
||||
} else {
|
||||
serialNumber_ = 0;
|
||||
}
|
||||
|
||||
if (observer_ == nullptr) {
|
||||
// create observer
|
||||
observer_ = std::make_shared<JsErrorObserver>(engine);
|
||||
DelayedSingleton<AppExecFwk::ApplicationDataManager>::GetInstance()->AddErrorObserver(observer_);
|
||||
}
|
||||
observer_->AddJsObserverObject(observerId, info.argv[0]);
|
||||
return engine.CreateNumber(observerId);
|
||||
}
|
||||
|
||||
NativeValue* OnUnregisterErrorObserver(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
int32_t observerId = -1;
|
||||
// only support one or two params
|
||||
if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) {
|
||||
HILOG_ERROR("unregister errorObserver error, not enough params.");
|
||||
} else {
|
||||
napi_get_value_int32(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[INDEX_ZERO]), &observerId);
|
||||
HILOG_INFO("unregister errorObserver called, observer:%{public}d", observerId);
|
||||
}
|
||||
|
||||
std::weak_ptr<JsErrorObserver> observerWptr(observer_);
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[observerWptr, observerId](
|
||||
NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
HILOG_INFO("Unregister errorObserver called.");
|
||||
if (observerId == -1) {
|
||||
task.Reject(engine, CreateJsError(engine, INVALID_PARAM, "param is invalid!"));
|
||||
return;
|
||||
}
|
||||
auto observer = observerWptr.lock();
|
||||
if (observer && observer->RemoveJsObserverObject(observerId)) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, ERROR_CODE, "observer is not exist!"));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t serialNumber_ = 0;
|
||||
std::shared_ptr<JsErrorObserver> observer_;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
NativeValue* JsErrorManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
{
|
||||
HILOG_INFO("Js error manager Init.");
|
||||
if (engine == nullptr || exportObj == nullptr) {
|
||||
HILOG_INFO("engine or exportObj null");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(exportObj);
|
||||
if (object == nullptr) {
|
||||
HILOG_INFO("object is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<JsErrorManager> jsErrorManager = std::make_unique<JsErrorManager>();
|
||||
object->SetNativePointer(jsErrorManager.release(), JsErrorManager::Finalizer, nullptr);
|
||||
|
||||
HILOG_INFO("JsErrorManager BindNativeFunction called");
|
||||
BindNativeFunction(*engine, *object, "registerErrorObserver", JsErrorManager::RegisterErrorObserver);
|
||||
BindNativeFunction(*engine, *object, "unregisterErrorObserver", JsErrorManager::UnregisterErrorObserver);
|
||||
return engine->CreateUndefined();
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 "ierror_observer.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_JS_ERROR_MANAGER_H
|
||||
#define OHOS_ABILITY_RUNTIME_JS_ERROR_MANAGER_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
NativeValue* JsErrorManagerInit(NativeEngine* engine, NativeValue* exportObj);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_JS_ERROR_MANAGER_H
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 "js_error_observer.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi/native_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
JsErrorObserver::JsErrorObserver(NativeEngine& engine) : engine_(engine) {}
|
||||
|
||||
JsErrorObserver::~JsErrorObserver() = default;
|
||||
|
||||
void JsErrorObserver::OnUnhandledException(std::string errMsg)
|
||||
{
|
||||
HILOG_DEBUG("OnUnhandledException come.");
|
||||
std::weak_ptr<JsErrorObserver> thisWeakPtr(shared_from_this());
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback>
|
||||
([thisWeakPtr, errMsg](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
std::shared_ptr<JsErrorObserver> jsObserver = thisWeakPtr.lock();
|
||||
if (jsObserver) {
|
||||
jsObserver->HandleOnUnhandledException(errMsg);
|
||||
}
|
||||
});
|
||||
NativeReference* callback = nullptr;
|
||||
std::unique_ptr<AsyncTask::ExecuteCallback> execute = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine_, std::make_unique<AsyncTask>(callback, std::move(execute), std::move(complete)));
|
||||
}
|
||||
|
||||
void JsErrorObserver::HandleOnUnhandledException(const std::string &errMsg)
|
||||
{
|
||||
HILOG_DEBUG("HandleOnUnhandledException come.");
|
||||
auto tmpMap = jsObserverObjectMap_;
|
||||
for (auto &item : tmpMap) {
|
||||
NativeValue* value = (item.second)->Get();
|
||||
NativeValue* argv[] = { CreateJsValue(engine_, errMsg) };
|
||||
CallJsFunction(value, "onUnhandledException", argv, ARGC_ONE);
|
||||
}
|
||||
}
|
||||
|
||||
void JsErrorObserver::CallJsFunction(NativeValue* value, const char* methodName, NativeValue* const* argv, size_t argc)
|
||||
{
|
||||
HILOG_INFO("CallJsFunction begin, method:%{public}s", methodName);
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get object");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue* method = obj->GetProperty(methodName);
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Failed to get method");
|
||||
return;
|
||||
}
|
||||
engine_.CallFunction(value, method, argv, argc);
|
||||
}
|
||||
|
||||
void JsErrorObserver::AddJsObserverObject(int32_t observerId, NativeValue* jsObserverObject)
|
||||
{
|
||||
jsObserverObjectMap_.emplace(
|
||||
observerId, std::shared_ptr<NativeReference>(engine_.CreateReference(jsObserverObject, 1)));
|
||||
}
|
||||
|
||||
bool JsErrorObserver::RemoveJsObserverObject(int32_t observerId)
|
||||
{
|
||||
return jsObserverObjectMap_.erase(observerId) == 1;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 <map>
|
||||
|
||||
#include "ierror_observer.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_JS_ERROR_OBSERVER_H
|
||||
#define OHOS_ABILITY_RUNTIME_JS_ERROR_OBSERVER_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class JsErrorObserver : public AppExecFwk::IErrorObserver,
|
||||
public std::enable_shared_from_this<JsErrorObserver> {
|
||||
public:
|
||||
explicit JsErrorObserver(NativeEngine& engine);
|
||||
~JsErrorObserver();
|
||||
void OnUnhandledException(std::string errMsg) override;
|
||||
void AddJsObserverObject(int32_t observerId, NativeValue* jsObserverObject);
|
||||
bool RemoveJsObserverObject(int32_t observerId);
|
||||
|
||||
private:
|
||||
void CallJsFunction(NativeValue* value, const char* methodName, NativeValue* const* argv, size_t argc);
|
||||
void HandleOnUnhandledException(const std::string &errMsg);
|
||||
|
||||
private:
|
||||
NativeEngine& engine_;
|
||||
std::map<int32_t, std::shared_ptr<NativeReference>> jsObserverObjectMap_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_JS_ERROR_OBSERVER_H
|
@ -70,7 +70,6 @@ abilityms_files = [
|
||||
"src/remote_mission_listener_stub.cpp",
|
||||
"src/mission_list_manager.cpp",
|
||||
"src/mission_list.cpp",
|
||||
"src/system_ability_token_callback_proxy.cpp",
|
||||
|
||||
#multi user
|
||||
"src/user_controller.cpp",
|
||||
|
@ -558,6 +558,8 @@ public:
|
||||
int requestCode,
|
||||
int callerUid = DEFAULT_INVAL_VALUE,
|
||||
int32_t userId = DEFAULT_INVAL_VALUE);
|
||||
|
||||
int IsStartFreeInstall(const Want &want, const sptr<IRemoteObject> &callerToken, int requestCode, int32_t userId);
|
||||
|
||||
int CheckPermission(const std::string &bundleName, const std::string &permission);
|
||||
|
||||
|
@ -595,13 +595,6 @@ public:
|
||||
*/
|
||||
void AddCallerRecord(const sptr<IRemoteObject> &callerToken, int requestCode, std::string srcAbilityId = "");
|
||||
|
||||
/**
|
||||
* add system ability caller record
|
||||
*
|
||||
*/
|
||||
void AddSystemAbilityCallerRecord(const sptr<IRemoteObject> &callerToken, int requestCode,
|
||||
std::string srcAbilityId);
|
||||
|
||||
/**
|
||||
* get caller record to list.
|
||||
*
|
||||
@ -786,6 +779,15 @@ private:
|
||||
void GrantUriPermission(const Want &want);
|
||||
int GetCurrentAccountId();
|
||||
|
||||
/**
|
||||
* add system ability caller record
|
||||
*
|
||||
*/
|
||||
void AddSystemAbilityCallerRecord(const sptr<IRemoteObject> &callerToken, int requestCode,
|
||||
std::string srcAbilityId);
|
||||
|
||||
bool IsSystemAbilityCall(const sptr<IRemoteObject> &callerToken);
|
||||
|
||||
static int64_t abilityRecordId;
|
||||
int recordId_ = 0; // record id
|
||||
AppExecFwk::AbilityInfo abilityInfo_ = {}; // the ability info get from BMS
|
||||
|
@ -93,6 +93,18 @@ public:
|
||||
int IsConnectFreeInstall(const Want &want, int32_t userId, const sptr<IRemoteObject> &callerToken,
|
||||
std::string& localDeviceId);
|
||||
|
||||
/**
|
||||
* Check if the connect request is free install.
|
||||
* @param want, the want of the ability to free install.
|
||||
* @param userId, designation User ID.
|
||||
* @param callerToken, caller ability token.
|
||||
* @param requestCode, ability request code.
|
||||
* @param isRemote, is remote ability to free install.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int IsStartFreeInstall(const Want &want, int32_t userId, const sptr<IRemoteObject> &callerToken,
|
||||
int requestCode, bool isRemote);
|
||||
|
||||
private:
|
||||
std::weak_ptr<AbilityManagerService> server_;
|
||||
struct FreeInstallInfo {
|
||||
|
@ -465,6 +465,7 @@ private:
|
||||
void UpdateMissionSnapshot(const std::shared_ptr<AbilityRecord> &abilityRecord);
|
||||
void AddUninstallTags(const std::string &bundleName, int32_t uid);
|
||||
void RemoveMissionLocked(int32_t missionId);
|
||||
void TerminatePreviousAbility(const std::shared_ptr<AbilityRecord> &abilityRecord);
|
||||
|
||||
int userId_;
|
||||
mutable std::recursive_mutex managerLock_;
|
||||
|
@ -302,39 +302,9 @@ int AbilityManagerService::StartAbility(const Want &want, const sptr<IRemoteObje
|
||||
|
||||
HILOG_INFO("%{public}s", __func__);
|
||||
|
||||
if ((flags & Want::FLAG_INSTALL_ON_DEMAND) == Want::FLAG_INSTALL_ON_DEMAND) {
|
||||
HILOG_INFO("StartAbility with free install flags");
|
||||
Want fiWant = want;
|
||||
std::string freeInstallType = "StartAbility";
|
||||
fiWant.SetParam(FREE_INSTALL_TYPE, freeInstallType);
|
||||
int32_t validUserId = GetValidUserId(userId);
|
||||
auto manager = std::make_shared<FreeInstallManager>(weak_from_this());
|
||||
eventInfo.errCode = manager->FreeInstall(fiWant, validUserId, requestCode, callerToken,
|
||||
CheckIfOperateRemote(want));
|
||||
AAFWK::EventReport::SendAbilityEvent(AAFWK::START_ABILITY_ERROR,
|
||||
HiSysEventType::FAULT, eventInfo);
|
||||
return eventInfo.errCode;
|
||||
}
|
||||
|
||||
HILOG_INFO("Start ability come, ability is %{public}s, userId is %{public}d",
|
||||
want.GetElement().GetAbilityName().c_str(), userId);
|
||||
if (CheckIfOperateRemote(want)) {
|
||||
if (requestCode == DEFAULT_REQUEST_CODE) {
|
||||
HILOG_INFO("AbilityManagerService::StartAbility. try to StartRemoteAbility");
|
||||
eventInfo.errCode = StartRemoteAbility(want, requestCode);
|
||||
AAFWK::EventReport::SendAbilityEvent(AAFWK::START_ABILITY_ERROR,
|
||||
HiSysEventType::FAULT, eventInfo);
|
||||
return eventInfo.errCode;
|
||||
}
|
||||
int32_t missionId = GetMissionIdByAbilityToken(callerToken);
|
||||
Want newWant = want;
|
||||
newWant.SetParam(DMS_MISSION_ID, missionId);
|
||||
HILOG_INFO("AbilityManagerService::StartAbility. try to StartAbilityForResult");
|
||||
eventInfo.errCode = StartRemoteAbility(newWant, requestCode);
|
||||
AAFWK::EventReport::SendAbilityEvent(AAFWK::START_ABILITY_ERROR,
|
||||
HiSysEventType::FAULT, eventInfo);
|
||||
return eventInfo.errCode;
|
||||
}
|
||||
|
||||
int32_t ret = StartAbilityInner(want, callerToken, requestCode, -1, userId);
|
||||
if (ret != ERR_OK) {
|
||||
eventInfo.errCode = ret;
|
||||
@ -355,16 +325,34 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr<IRemot
|
||||
}
|
||||
|
||||
if (callerToken != nullptr && !VerificationAllToken(callerToken)) {
|
||||
auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(IPCSkeleton::GetCallingTokenID());
|
||||
if (tokenType != Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE ||
|
||||
iface_cast<ISystemAbilityTokenCallback>(callerToken) == nullptr) {
|
||||
auto isSpecificSA = AAFwk::PermissionVerification::GetInstance()->
|
||||
CheckSpecificSystemAbilityAccessPermission();
|
||||
if (!isSpecificSA) {
|
||||
HILOG_ERROR("%{public}s VerificationAllToken failed.", __func__);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
HILOG_INFO("%{public}s: Caller is system ability.", __func__);
|
||||
HILOG_INFO("%{public}s: Caller is specific system ability.", __func__);
|
||||
}
|
||||
int32_t oriValidUserId = GetValidUserId(userId);
|
||||
int32_t validUserId = oriValidUserId;
|
||||
int ret = IsStartFreeInstall(want, callerToken, requestCode, validUserId);
|
||||
if (ret != ERR_OK) {
|
||||
return ret;
|
||||
}
|
||||
if (callerToken != nullptr) {
|
||||
if (CheckIfOperateRemote(want)) {
|
||||
if (requestCode == DEFAULT_REQUEST_CODE) {
|
||||
HILOG_INFO("AbilityManagerService::StartAbility. try to StartRemoteAbility");
|
||||
return StartRemoteAbility(want, requestCode);
|
||||
}
|
||||
int32_t missionId = GetMissionIdByAbilityToken(callerToken);
|
||||
Want newWant = want;
|
||||
newWant.SetParam(DMS_MISSION_ID, missionId);
|
||||
HILOG_INFO("AbilityManagerService::StartAbility. try to StartAbilityForResult");
|
||||
return StartRemoteAbility(newWant, requestCode);
|
||||
}
|
||||
}
|
||||
|
||||
if (!JudgeMultiUserConcurrency(validUserId)) {
|
||||
HILOG_ERROR("Multi-user non-concurrent mode is not satisfied.");
|
||||
return ERR_INVALID_VALUE;
|
||||
@ -460,6 +448,10 @@ int AbilityManagerService::StartAbility(const Want &want, const AbilityStartSett
|
||||
}
|
||||
int32_t oriValidUserId = GetValidUserId(userId);
|
||||
int32_t validUserId = oriValidUserId;
|
||||
int ret = IsStartFreeInstall(want, callerToken, requestCode, validUserId);
|
||||
if (ret != ERR_OK) {
|
||||
return ret;
|
||||
}
|
||||
if (!JudgeMultiUserConcurrency(validUserId)) {
|
||||
HILOG_ERROR("Multi-user non-concurrent mode is not satisfied.");
|
||||
eventInfo.errCode = ERR_INVALID_VALUE;
|
||||
@ -543,7 +535,7 @@ int AbilityManagerService::StartAbility(const Want &want, const AbilityStartSett
|
||||
HiSysEventType::FAULT, eventInfo);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
int32_t ret = missionListManager->StartAbility(abilityRequest);
|
||||
ret = missionListManager->StartAbility(abilityRequest);
|
||||
if (ret != ERR_OK) {
|
||||
eventInfo.errCode = ret;
|
||||
AAFWK::EventReport::SendAbilityEvent(AAFWK::START_ABILITY_ERROR,
|
||||
@ -581,6 +573,10 @@ int AbilityManagerService::StartAbility(const Want &want, const StartOptions &st
|
||||
}
|
||||
int32_t oriValidUserId = GetValidUserId(userId);
|
||||
int32_t validUserId = oriValidUserId;
|
||||
int ret = IsStartFreeInstall(want, callerToken, requestCode, validUserId);
|
||||
if (ret != ERR_OK) {
|
||||
return ret;
|
||||
}
|
||||
if (!JudgeMultiUserConcurrency(validUserId)) {
|
||||
HILOG_ERROR("Multi-user non-concurrent mode is not satisfied.");
|
||||
eventInfo.errCode = ERR_INVALID_VALUE;
|
||||
@ -658,7 +654,7 @@ int AbilityManagerService::StartAbility(const Want &want, const StartOptions &st
|
||||
HiSysEventType::FAULT, eventInfo);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
int32_t ret = missionListManager->StartAbility(abilityRequest);
|
||||
ret = missionListManager->StartAbility(abilityRequest);
|
||||
if (ret != ERR_OK) {
|
||||
eventInfo.errCode = ret;
|
||||
AAFWK::EventReport::SendAbilityEvent(AAFWK::START_ABILITY_ERROR,
|
||||
@ -667,6 +663,18 @@ int AbilityManagerService::StartAbility(const Want &want, const StartOptions &st
|
||||
return ret;
|
||||
}
|
||||
|
||||
int AbilityManagerService::IsStartFreeInstall(
|
||||
const Want &want, const sptr<IRemoteObject> &callerToken, int requestCode, int32_t userId)
|
||||
{
|
||||
auto flags = want.GetFlags();
|
||||
if ((flags & Want::FLAG_INSTALL_ON_DEMAND) == Want::FLAG_INSTALL_ON_DEMAND) {
|
||||
HILOG_INFO("StartAbility with free install flags");
|
||||
auto manager = std::make_shared<FreeInstallManager>(weak_from_this());
|
||||
return manager->IsStartFreeInstall(want, userId, callerToken, requestCode, CheckIfOperateRemote(want));
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int AbilityManagerService::CheckOptExtensionAbility(const Want &want, AbilityRequest &abilityRequest,
|
||||
int32_t validUserId, AppExecFwk::ExtensionAbilityType extensionType)
|
||||
{
|
||||
@ -1259,16 +1267,20 @@ int AbilityManagerService::ConnectAbility(
|
||||
if (CheckIfOperateRemote(abilityWant)) {
|
||||
HILOG_INFO("AbilityManagerService::ConnectAbility. try to ConnectRemoteAbility");
|
||||
eventInfo.errCode = ConnectRemoteAbility(abilityWant, connect->AsObject());
|
||||
AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE_ERROR,
|
||||
HiSysEventType::FAULT, eventInfo);
|
||||
if (eventInfo.errCode != ERR_OK) {
|
||||
AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE_ERROR,
|
||||
HiSysEventType::FAULT, eventInfo);
|
||||
}
|
||||
return eventInfo.errCode;
|
||||
}
|
||||
|
||||
if (callerToken != nullptr && callerToken->GetObjectDescriptor() != u"ohos.aafwk.AbilityToken") {
|
||||
HILOG_INFO("%{public}s invalid Token.", __func__);
|
||||
eventInfo.errCode = ConnectLocalAbility(abilityWant, validUserId, connect, nullptr);
|
||||
AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE_ERROR,
|
||||
HiSysEventType::FAULT, eventInfo);
|
||||
if (eventInfo.errCode != ERR_OK) {
|
||||
AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE_ERROR,
|
||||
HiSysEventType::FAULT, eventInfo);
|
||||
}
|
||||
return eventInfo.errCode;
|
||||
}
|
||||
eventInfo.errCode = ConnectLocalAbility(abilityWant, validUserId, connect, callerToken);
|
||||
@ -1289,13 +1301,13 @@ int AbilityManagerService::DisconnectAbility(const sptr<IAbilityConnection> &con
|
||||
CHECK_POINTER_AND_RETURN(connect, ERR_INVALID_VALUE);
|
||||
CHECK_POINTER_AND_RETURN(connect->AsObject(), ERR_INVALID_VALUE);
|
||||
|
||||
eventInfo.errCode = DisconnectLocalAbility(connect);
|
||||
eventInfo.errCode |= DisconnectRemoteAbility(connect->AsObject());
|
||||
if (eventInfo.errCode != ERR_OK) {
|
||||
if (ERR_OK != DisconnectRemoteAbility(connect->AsObject()) &&
|
||||
ERR_OK != DisconnectRemoteAbility(connect->AsObject())) {
|
||||
eventInfo.errCode = INNER_ERR;
|
||||
AAFWK::EventReport::SendExtensionEvent(AAFWK::DISCONNECT_SERVICE_ERROR,
|
||||
HiSysEventType::FAULT, eventInfo);
|
||||
}
|
||||
return eventInfo.errCode;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int AbilityManagerService::ConnectLocalAbility(const Want &want, const int32_t userId,
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "os_account_manager.h"
|
||||
#endif // OS_ACCOUNT_PART_ENABLED
|
||||
#include "system_ability_token_callback.h"
|
||||
#include "system_ability_token_callback_proxy.h"
|
||||
#include "uri_permission_manager_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -42,6 +41,7 @@ const std::string DMS_PROCESS_NAME = "distributedsched";
|
||||
const std::string DMS_MISSION_ID = "dmsMissionId";
|
||||
const std::string DMS_SRC_NETWORK_ID = "dmsSrcNetworkId";
|
||||
const std::string ABILITY_OWNER_USERID = "AbilityMS_Owner_UserId";
|
||||
const std::u16string SYSTEM_ABILITY_TOKEN_CALLBACK = u"ohos.aafwk.ISystemAbilityTokenCallback";
|
||||
int64_t AbilityRecord::abilityRecordId = 0;
|
||||
int64_t AbilityRecord::g_abilityRecordEventId_ = 0;
|
||||
const int32_t DEFAULT_USER_ID = 0;
|
||||
@ -684,12 +684,22 @@ void SystemAbilityCallerRecord::SendResultToSystemAbility(int requestCode, int r
|
||||
HILOG_ERROR("CallerToken is nullptr");
|
||||
return;
|
||||
}
|
||||
auto object = iface_cast<ISystemAbilityTokenCallback>(callerToken);
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("Remote object is nullptr");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(SYSTEM_ABILITY_TOKEN_CALLBACK)) {
|
||||
HILOG_ERROR("SendResultToSystemAbility Write interface token failed.");
|
||||
return;
|
||||
}
|
||||
int result = object->SendResult(resultWant, callerUid, requestCode, accessToken, resultCode);
|
||||
if (!data.WriteParcelable(&resultWant)) {
|
||||
HILOG_ERROR("fail to WriteParcelable");
|
||||
return;
|
||||
}
|
||||
data.WriteInt32(callerUid);
|
||||
data.WriteInt32(requestCode);
|
||||
data.WriteUint32(accessToken);
|
||||
data.WriteInt32(resultCode);
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
int result = callerToken->SendRequest(ISystemAbilityTokenCallback::SEND_RESULT, data, reply, option);
|
||||
if (result != ERR_OK) {
|
||||
HILOG_ERROR("SendResultToSystemAbility error = %{public}d", result);
|
||||
}
|
||||
@ -724,11 +734,11 @@ void AbilityRecord::AddCallerRecord(const sptr<IRemoteObject> &callerToken, int
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_INFO("Add caller record.");
|
||||
auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
|
||||
if (requestCode != DEFAULT_REQUEST_CODE && callerToken != nullptr && abilityRecord == nullptr) {
|
||||
if (requestCode != DEFAULT_REQUEST_CODE && IsSystemAbilityCall(callerToken)) {
|
||||
AddSystemAbilityCallerRecord(callerToken, requestCode, srcAbilityId);
|
||||
return;
|
||||
}
|
||||
auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
|
||||
CHECK_POINTER(abilityRecord);
|
||||
|
||||
auto isExist = [&abilityRecord](const std::shared_ptr<CallerRecord> &callerRecord) {
|
||||
@ -751,27 +761,48 @@ void AbilityRecord::AddCallerRecord(const sptr<IRemoteObject> &callerToken, int
|
||||
abilityRecord->GetAbilityInfo().name.c_str());
|
||||
}
|
||||
|
||||
bool AbilityRecord::IsSystemAbilityCall(const sptr<IRemoteObject> &callerToken)
|
||||
{
|
||||
if (callerToken == nullptr) {
|
||||
return false;
|
||||
}
|
||||
auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
|
||||
if (abilityRecord != nullptr) {
|
||||
return false;
|
||||
}
|
||||
auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(IPCSkeleton::GetCallingTokenID());
|
||||
bool isNativeCall = tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE;
|
||||
if (!isNativeCall) {
|
||||
HILOG_INFO("Is not native call.");
|
||||
return false;
|
||||
}
|
||||
AccessToken::NativeTokenInfo nativeTokenInfo;
|
||||
int32_t result = AccessToken::AccessTokenKit::GetNativeTokenInfo(IPCSkeleton::GetCallingTokenID(),
|
||||
nativeTokenInfo);
|
||||
if (result == ERR_OK && nativeTokenInfo.processName == DMS_PROCESS_NAME) {
|
||||
HILOG_INFO("Is system ability call.");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void AbilityRecord::AddSystemAbilityCallerRecord(const sptr<IRemoteObject> &callerToken, int requestCode,
|
||||
std::string srcAbilityId)
|
||||
{
|
||||
auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(IPCSkeleton::GetCallingTokenID());
|
||||
if (tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE &&
|
||||
iface_cast<ISystemAbilityTokenCallback>(callerToken) != nullptr) {
|
||||
HILOG_INFO("Add system ability caller record.");
|
||||
std::shared_ptr<SystemAbilityCallerRecord> systemAbilityRecord =
|
||||
std::make_shared<SystemAbilityCallerRecord>(srcAbilityId, callerToken);
|
||||
auto isExist = [&srcAbilityId](const std::shared_ptr<CallerRecord> &callerRecord) {
|
||||
std::shared_ptr<SystemAbilityCallerRecord> saCaller = callerRecord->GetSaCaller();
|
||||
return (saCaller != nullptr && saCaller->GetSrcAbilityId() == srcAbilityId);
|
||||
};
|
||||
auto record = std::find_if(callerList_.begin(), callerList_.end(), isExist);
|
||||
if (record != callerList_.end()) {
|
||||
HILOG_INFO("Find same system ability caller record.");
|
||||
callerList_.erase(record);
|
||||
}
|
||||
callerList_.emplace_back(std::make_shared<CallerRecord>(requestCode, systemAbilityRecord));
|
||||
HILOG_INFO("Add system ability record end.");
|
||||
HILOG_INFO("Add system ability caller record.");
|
||||
std::shared_ptr<SystemAbilityCallerRecord> systemAbilityRecord =
|
||||
std::make_shared<SystemAbilityCallerRecord>(srcAbilityId, callerToken);
|
||||
auto isExist = [&srcAbilityId](const std::shared_ptr<CallerRecord> &callerRecord) {
|
||||
std::shared_ptr<SystemAbilityCallerRecord> saCaller = callerRecord->GetSaCaller();
|
||||
return (saCaller != nullptr && saCaller->GetSrcAbilityId() == srcAbilityId);
|
||||
};
|
||||
auto record = std::find_if(callerList_.begin(), callerList_.end(), isExist);
|
||||
if (record != callerList_.end()) {
|
||||
HILOG_INFO("Find same system ability caller record.");
|
||||
callerList_.erase(record);
|
||||
}
|
||||
callerList_.emplace_back(std::make_shared<CallerRecord>(requestCode, systemAbilityRecord));
|
||||
HILOG_INFO("Add system ability record end.");
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<CallerRecord>> AbilityRecord::GetCallerRecordList() const
|
||||
|
@ -486,6 +486,7 @@ DataAbilityManager::DataAbilityRecordPtr DataAbilityManager::LoadLocked(
|
||||
if (it != dataAbilityRecordsLoading_.end()) {
|
||||
dataAbilityRecordsLoading_.erase(it);
|
||||
}
|
||||
DelayedSingleton<AppScheduler>::GetInstance()->AttachTimeOut(dataAbilityRecord->GetToken());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -240,18 +240,8 @@ void FreeInstallManager::NotifyFreeInstallResult(const Want &want, int resultCod
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string freeInstallType = want.GetStringParam(FREE_INSTALL_TYPE);
|
||||
if (!isFromRemote && resultCode == ERR_OK && freeInstallType == "ConnectAbility") {
|
||||
if (!isFromRemote && resultCode == ERR_OK) {
|
||||
resultCode = ERR_OK;
|
||||
} else if (!isFromRemote && resultCode == ERR_OK && freeInstallType == "StartAbility") {
|
||||
HILOG_INFO("Handle apps startability.");
|
||||
auto server = server_.lock();
|
||||
CHECK_POINTER(server);
|
||||
if ((*it).want.GetBoolParam(FREE_INSTALL_UPGRADED_KEY, false)) {
|
||||
HILOG_INFO("Handle apps upgraded.");
|
||||
resultCode = server->StartAbilityInner((*it).want, nullptr, (*it).requestCode, -1, -1);
|
||||
}
|
||||
resultCode = server->StartAbilityInner((*it).want, (*it).callerToken, (*it).requestCode, -1, -1);
|
||||
}
|
||||
|
||||
if ((*it).promise != nullptr) {
|
||||
@ -306,7 +296,7 @@ int FreeInstallManager::HandleFreeInstallErrorCode(int resultCode)
|
||||
auto itToApp = FIErrorToAppMaps.find(static_cast<enum NativeFreeInstallError>(resultCode));
|
||||
if (itToApp == FIErrorToAppMaps.end()) {
|
||||
HILOG_ERROR("Undefind error code.");
|
||||
return resultCode;
|
||||
return NativeFreeInstallError::UNDEFINE_ERROR_CODE;
|
||||
}
|
||||
return itToApp->second;
|
||||
}
|
||||
@ -359,6 +349,21 @@ int FreeInstallManager::IsConnectFreeInstall(const Want &want, int32_t userId,
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
int FreeInstallManager::IsStartFreeInstall(const Want &want, int32_t userId,
|
||||
const sptr<IRemoteObject> &callerToken, int requestCode, bool isRemote)
|
||||
{
|
||||
if (CheckIsFreeInstall(want)) {
|
||||
int result = FreeInstall(want, userId, DEFAULT_INVAL_VALUE, callerToken, false);
|
||||
if (result) {
|
||||
HILOG_ERROR("AbilityManagerService::IsConnectFreeInstall. FreeInstall error");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
void FreeInstallManager::OnInstallFinished(int resultCode, const Want &want, int32_t userId)
|
||||
{
|
||||
HILOG_INFO("%{public}s resultCode = %{public}d", __func__, resultCode);
|
||||
|
@ -856,11 +856,12 @@ int MissionListManager::DispatchForeground(const std::shared_ptr<AbilityRecord>
|
||||
}
|
||||
|
||||
handler->RemoveEvent(AbilityManagerService::FOREGROUNDNEW_TIMEOUT_MSG, abilityRecord->GetEventId());
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
abilityRecord->SetStartingWindow(false);
|
||||
#endif
|
||||
auto self(shared_from_this());
|
||||
if (success) {
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
HILOG_INFO("%{public}s foreground successed.", __func__);
|
||||
abilityRecord->SetStartingWindow(false);
|
||||
#endif
|
||||
auto task = [self, abilityRecord]() { self->CompleteForegroundSuccess(abilityRecord); };
|
||||
handler->PostTask(task);
|
||||
} else {
|
||||
@ -926,6 +927,32 @@ void MissionListManager::CompleteForegroundSuccess(const std::shared_ptr<Ability
|
||||
|
||||
/* PostTask to trigger start Ability from waiting queue */
|
||||
handler->PostTask(startWaittingAbilityTask, "startWaittingAbility", NEXTABILITY_TIMEOUT);
|
||||
TerminatePreviousAbility(abilityRecord);
|
||||
}
|
||||
|
||||
void MissionListManager::TerminatePreviousAbility(const std::shared_ptr<AbilityRecord> &abilityRecord)
|
||||
{
|
||||
auto teminatingAbilityRecord = abilityRecord->GetPreAbilityRecord();
|
||||
if (!teminatingAbilityRecord) {
|
||||
HILOG_INFO("%{public}s, teminatingAbilityRecord is nullptr.", __func__);
|
||||
return;
|
||||
}
|
||||
abilityRecord->SetPreAbilityRecord(nullptr);
|
||||
auto self(shared_from_this());
|
||||
if (teminatingAbilityRecord->GetAbilityState() == AbilityState::FOREGROUND) {
|
||||
auto task = [teminatingAbilityRecord, self] {
|
||||
HILOG_INFO("%{public}s, teminatingAbilityRecord move to background.", __func__);
|
||||
self->CompleteBackground(teminatingAbilityRecord);
|
||||
};
|
||||
teminatingAbilityRecord->BackgroundAbility(task);
|
||||
}
|
||||
if (teminatingAbilityRecord->GetAbilityState() == AbilityState::BACKGROUND) {
|
||||
auto task = [teminatingAbilityRecord, self]() {
|
||||
HILOG_INFO("%{public}s, To terminate teminatingAbilityRecord.", __func__);
|
||||
self->CompleteTerminate(teminatingAbilityRecord);
|
||||
};
|
||||
teminatingAbilityRecord->Terminate(task);
|
||||
}
|
||||
}
|
||||
|
||||
int MissionListManager::DispatchBackground(const std::shared_ptr<AbilityRecord> &abilityRecord)
|
||||
@ -1052,7 +1079,9 @@ int MissionListManager::TerminateAbilityLocked(const std::shared_ptr<AbilityReco
|
||||
if (abilityRecord->IsAbilityState(FOREGROUND) || abilityRecord->IsAbilityState(FOREGROUNDING)) {
|
||||
HILOG_DEBUG("current ability is active");
|
||||
if (abilityRecord->GetNextAbilityRecord()) {
|
||||
abilityRecord->GetNextAbilityRecord()->ProcessForegroundAbility(nullptr);
|
||||
auto nextAbilityRecord = abilityRecord->GetNextAbilityRecord();
|
||||
nextAbilityRecord->SetPreAbilityRecord(abilityRecord);
|
||||
nextAbilityRecord->ProcessForegroundAbility(nullptr);
|
||||
} else {
|
||||
MoveToBackgroundTask(abilityRecord);
|
||||
}
|
||||
@ -1530,6 +1559,7 @@ void MissionListManager::CompleteForegroundFailed(const std::shared_ptr<AbilityR
|
||||
#endif
|
||||
|
||||
HandleForgroundNewTimeout(abilityRecord);
|
||||
TerminatePreviousAbility(abilityRecord);
|
||||
}
|
||||
|
||||
void MissionListManager::HandleTimeoutAndResumeAbility(const std::shared_ptr<AbilityRecord> &timeOutAbilityRecord)
|
||||
@ -2298,7 +2328,7 @@ void MissionListManager::StartingWindowCold(const std::shared_ptr<AbilityRecord>
|
||||
auto colorErrval = resourceMgr->GetColorById(colorId, bgColor);
|
||||
if (colorErrval != OHOS::Global::Resource::RState::SUCCESS) {
|
||||
HILOG_WARN("%{public}s. Failed to GetColorById.", __func__);
|
||||
bgColor = 0xffffffff;
|
||||
bgColor = 0x99ffffff;
|
||||
}
|
||||
HILOG_DEBUG("%{public}s colorId is %{public}u, bgColor is %{public}u.", __func__, colorId, bgColor);
|
||||
|
||||
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* 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 "system_ability_token_callback_proxy.h"
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "ipc_types.h"
|
||||
#include "message_parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
const std::u16string SYSTEM_ABILITY_TOKEN_CALLBACK_INTERFACE_TOKEN = u"ohos.aafwk.ISystemAbilityTokenCallback";
|
||||
|
||||
int32_t SystemAbilityTokenCallbackProxy::SendResult(OHOS::AAFwk::Want& want, int32_t callerUid,
|
||||
int32_t requestCode, uint32_t accessToken, int32_t resultCode)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(SYSTEM_ABILITY_TOKEN_CALLBACK_INTERFACE_TOKEN)) {
|
||||
HILOG_ERROR("SendResult Write interface token failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
if (!data.WriteParcelable(&want)) {
|
||||
HILOG_ERROR("fail to WriteParcelable");
|
||||
return INNER_ERR;
|
||||
}
|
||||
data.WriteInt32(callerUid);
|
||||
data.WriteInt32(requestCode);
|
||||
data.WriteUint32(accessToken);
|
||||
data.WriteInt32(resultCode);
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
int result = Remote()->SendRequest(ISystemAbilityTokenCallback::SEND_RESULT, data, reply, option);
|
||||
if (result != NO_ERROR) {
|
||||
HILOG_ERROR("SendResult SendRequest fail, error: %{public}d", result);
|
||||
return result;
|
||||
}
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
@ -66,7 +66,7 @@ public:
|
||||
AbilityConnectManager *ConnectManager() const;
|
||||
|
||||
AbilityRequest GenerateAbilityRequest(const std::string &deviceName, const std::string &abilityName,
|
||||
const std::string &appName, const std::string &bundleName);
|
||||
const std::string &appName, const std::string &bundleName, const std::string &moduleName);
|
||||
|
||||
static constexpr int TEST_WAIT_TIME = 1000000;
|
||||
|
||||
@ -85,9 +85,10 @@ private:
|
||||
};
|
||||
|
||||
AbilityRequest AbilityConnectManageTest::GenerateAbilityRequest(const std::string &deviceName,
|
||||
const std::string &abilityName, const std::string &appName, const std::string &bundleName)
|
||||
const std::string &abilityName, const std::string &appName, const std::string &bundleName,
|
||||
const std::string &moduleName)
|
||||
{
|
||||
ElementName element(deviceName, bundleName, abilityName);
|
||||
ElementName element(deviceName, bundleName, abilityName, moduleName);
|
||||
Want want;
|
||||
want.SetElement(element);
|
||||
|
||||
@ -97,6 +98,7 @@ AbilityRequest AbilityConnectManageTest::GenerateAbilityRequest(const std::strin
|
||||
abilityInfo.type = AbilityType::SERVICE;
|
||||
abilityInfo.name = abilityName;
|
||||
abilityInfo.bundleName = bundleName;
|
||||
abilityInfo.moduleName = moduleName;
|
||||
abilityInfo.deviceId = deviceName;
|
||||
ApplicationInfo appinfo;
|
||||
appinfo.name = appName;
|
||||
@ -122,14 +124,16 @@ void AbilityConnectManageTest::SetUp(void)
|
||||
std::string abilityName = "ServiceAbility";
|
||||
std::string appName = "hiservcie";
|
||||
std::string bundleName = "com.ix.hiservcie";
|
||||
abilityRequest_ = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
|
||||
std::string moduleName = "entry";
|
||||
abilityRequest_ = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName, moduleName);
|
||||
serviceRecord_ = AbilityRecord::CreateAbilityRecord(abilityRequest_);
|
||||
serviceToken_ = serviceRecord_->GetToken();
|
||||
std::string deviceName1 = "device";
|
||||
std::string abilityName1 = "musicServiceAbility";
|
||||
std::string appName1 = "musicservcie";
|
||||
std::string bundleName1 = "com.ix.musicservcie";
|
||||
abilityRequest1_ = GenerateAbilityRequest(deviceName1, abilityName1, appName1, bundleName1);
|
||||
std::string moduleName1 = "entry";
|
||||
abilityRequest1_ = GenerateAbilityRequest(deviceName1, abilityName1, appName1, bundleName1, moduleName1);
|
||||
serviceRecord1_ = AbilityRecord::CreateAbilityRecord(abilityRequest1_);
|
||||
serviceToken1_ = serviceRecord_->GetToken();
|
||||
callbackA_ = new AbilityConnectCallback();
|
||||
@ -529,7 +533,8 @@ HWTEST_F(AbilityConnectManageTest, AAFWK_Connect_Service_013, TestSize.Level1)
|
||||
std::string abilityNameB = "ServiceAbilityB";
|
||||
std::string appNameB = "hiservcieB";
|
||||
std::string bundleNameB = "com.ix.hiservcieB";
|
||||
auto abilityRequestB = GenerateAbilityRequest(deviceNameB, abilityNameB, appNameB, bundleNameB);
|
||||
std::string moduleNameB = "entry";
|
||||
auto abilityRequestB = GenerateAbilityRequest(deviceNameB, abilityNameB, appNameB, bundleNameB, moduleNameB);
|
||||
result = ConnectManager()->ConnectAbilityLocked(abilityRequestB, callbackA_, nullptr);
|
||||
EXPECT_EQ(0, result);
|
||||
|
||||
@ -568,7 +573,8 @@ HWTEST_F(AbilityConnectManageTest, AAFWK_Connect_Service_014, TestSize.Level1)
|
||||
std::string abilityNameB = "ServiceAbilityB";
|
||||
std::string appNameB = "hiservcieB";
|
||||
std::string bundleNameB = "com.ix.hiservcieB";
|
||||
auto abilityRequestB = GenerateAbilityRequest(deviceNameB, abilityNameB, appNameB, bundleNameB);
|
||||
std::string moduleNameB = "entry";
|
||||
auto abilityRequestB = GenerateAbilityRequest(deviceNameB, abilityNameB, appNameB, bundleNameB, moduleNameB);
|
||||
result = ConnectManager()->ConnectAbilityLocked(abilityRequestB, callbackB_, nullptr);
|
||||
EXPECT_EQ(0, result);
|
||||
|
||||
|
@ -277,7 +277,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_005, TestSize.Le
|
||||
want.SetElement(element);
|
||||
StartOptions abilityStartOptions;
|
||||
auto result = abilityMs_->StartAbility(want, abilityStartOptions, nullptr, 0, -1);
|
||||
EXPECT_EQ(OHOS::ERR_OK, result);
|
||||
EXPECT_NE(OHOS::ERR_OK, result);
|
||||
GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StartAbility_005 end";
|
||||
}
|
||||
|
||||
|
@ -235,6 +235,7 @@ HWTEST_F(AbilityTimeoutTest, OnAbilityDied_001, TestSize.Level1)
|
||||
auto mission = std::make_shared<Mission>(MOCK_MISSION_ID, abilityRecord, abilityRequest.abilityInfo.bundleName);
|
||||
abilityRecord->SetMission(mission);
|
||||
abilityRecord->SetMissionList(defList);
|
||||
abilityRecord->SetOwnerMissionUserId(MOCK_MAIN_USER_ID);
|
||||
defList->AddMissionToTop(mission);
|
||||
EXPECT_TRUE(defList->GetAbilityRecordByToken(abilityRecord->GetToken()) != nullptr);
|
||||
|
||||
@ -270,6 +271,7 @@ HWTEST_F(AbilityTimeoutTest, OnAbilityDied_002, TestSize.Level1)
|
||||
abilityRecord->SetMission(mission);
|
||||
abilityRecord->SetMissionList(lauList);
|
||||
abilityRecord->SetLauncherRoot();
|
||||
abilityRecord->SetOwnerMissionUserId(MOCK_MAIN_USER_ID);
|
||||
lauList->AddMissionToTop(mission);
|
||||
EXPECT_TRUE(lauList->GetAbilityRecordByToken(abilityRecord->GetToken()) != nullptr);
|
||||
|
||||
|
@ -29,7 +29,6 @@ ohos_unittest("app_scheduler_test") {
|
||||
|
||||
sources = [
|
||||
"${aafwk_path}/services/abilitymgr/src/app_scheduler.cpp",
|
||||
"${aafwk_path}/services/abilitymgr/src/system_ability_token_callback_proxy.cpp",
|
||||
"app_scheduler_test.cpp",
|
||||
]
|
||||
|
||||
|
@ -33,7 +33,6 @@ ohos_unittest("data_ability_manager_test") {
|
||||
|
||||
sources = [
|
||||
"${aafwk_path}/services/abilitymgr/src/app_scheduler.cpp",
|
||||
"${aafwk_path}/services/abilitymgr/src/system_ability_token_callback_proxy.cpp",
|
||||
"data_ability_manager_test.cpp", # add mock file
|
||||
]
|
||||
|
||||
|
@ -248,13 +248,15 @@ HWTEST_F(MissionListManagerTest, MissionListManager_005, Function | MediumTest |
|
||||
abilityRequest.callType = AbilityCallType::CALL_REQUEST_TYPE;
|
||||
abilityRequest.abilityInfo.bundleName = "test_bundle";
|
||||
abilityRequest.abilityInfo.name = "test_name";
|
||||
abilityRequest.abilityInfo.moduleName = "test_moduleName";
|
||||
abilityRequest.abilityInfo.launchMode = AppExecFwk::LaunchMode::SINGLETON;
|
||||
|
||||
Want want;
|
||||
AppExecFwk::AbilityInfo abilityInfo = abilityRequest.abilityInfo;
|
||||
AppExecFwk::ApplicationInfo applicationInfo;
|
||||
int32_t id;
|
||||
std::string missionName = "#" + abilityRequest.abilityInfo.bundleName + ":" + abilityRequest.abilityInfo.name;
|
||||
std::string missionName = "#" + abilityRequest.abilityInfo.bundleName + ":" +
|
||||
abilityRequest.abilityInfo.moduleName + ":" + abilityRequest.abilityInfo.name;
|
||||
|
||||
std::shared_ptr<MissionListManager> missionListMgr = std::make_shared<MissionListManager>(0);
|
||||
std::shared_ptr<AbilityRecord> abilityRecord =
|
||||
@ -293,13 +295,15 @@ HWTEST_F(MissionListManagerTest, MissionListManager_006, Function | MediumTest |
|
||||
abilityRequest.callType = AbilityCallType::CALL_REQUEST_TYPE;
|
||||
abilityRequest.abilityInfo.bundleName = "test_bundle";
|
||||
abilityRequest.abilityInfo.name = "test_name";
|
||||
abilityRequest.abilityInfo.moduleName = "test_moduleName";
|
||||
abilityRequest.abilityInfo.launchMode = AppExecFwk::LaunchMode::SINGLETON;
|
||||
abilityRequest.connect = connCallback;
|
||||
Want want;
|
||||
AppExecFwk::AbilityInfo abilityInfo = abilityRequest.abilityInfo;
|
||||
AppExecFwk::ApplicationInfo applicationInfo;
|
||||
int32_t id;
|
||||
std::string missionName = "#" + abilityRequest.abilityInfo.bundleName + ":" + abilityRequest.abilityInfo.name;
|
||||
std::string missionName = "#" + abilityRequest.abilityInfo.bundleName + ":" +
|
||||
abilityRequest.abilityInfo.moduleName + ":" + abilityRequest.abilityInfo.name;
|
||||
|
||||
std::shared_ptr<MissionListManager> missionListMgr = std::make_shared<MissionListManager>(0);
|
||||
std::shared_ptr<AbilityRecord> abilityRecord =
|
||||
@ -548,13 +552,15 @@ HWTEST_F(MissionListManagerTest, MissionListManager_014, Function | MediumTest |
|
||||
abilityRequest.callType = AbilityCallType::CALL_REQUEST_TYPE;
|
||||
abilityRequest.abilityInfo.bundleName = "test_bundle";
|
||||
abilityRequest.abilityInfo.name = "test_name";
|
||||
abilityRequest.abilityInfo.moduleName = "test_moduleName";
|
||||
abilityRequest.abilityInfo.launchMode = AppExecFwk::LaunchMode::SINGLETON;
|
||||
abilityRequest.connect = connCallback;
|
||||
Want want;
|
||||
AppExecFwk::AbilityInfo abilityInfo = abilityRequest.abilityInfo;
|
||||
AppExecFwk::ApplicationInfo applicationInfo;
|
||||
int32_t id;
|
||||
std::string missionName = "#" + abilityRequest.abilityInfo.bundleName + ":" + abilityRequest.abilityInfo.name;
|
||||
std::string missionName = "#" + abilityRequest.abilityInfo.bundleName + ":" +
|
||||
abilityRequest.abilityInfo.moduleName + ":" + abilityRequest.abilityInfo.name;
|
||||
|
||||
std::shared_ptr<MissionListManager> missionListMgr = std::make_shared<MissionListManager>(0);
|
||||
std::shared_ptr<AbilityRecord> abilityRecord =
|
||||
|
@ -40,6 +40,8 @@ const std::string DISCONNECT_SERVICE_ERROR = "DISCONNECT_SERVICE_ERROR";
|
||||
const std::string START_ABILITY = "START_ABILITY";
|
||||
const std::string TERMINATE_ABILITY = "TERMINATE_ABILITY";
|
||||
const std::string CLOSE_ABILITY = "CLOSE_ABILITY";
|
||||
const std::string ABILITY_ONFOREGROUND = "ABILITY_ONFOREGROUND";
|
||||
const std::string ABILITY_ONBACKGROUND = "ABILITY_ONBACKGROUND";
|
||||
// serviceExtensionAbility behavior event
|
||||
const std::string START_SERVICE = "START_SERVICE";
|
||||
const std::string STOP_SERVICE = "STOP_SERVICE";
|
||||
|
@ -31,6 +31,8 @@ public:
|
||||
|
||||
bool IsSACall();
|
||||
|
||||
bool CheckSpecificSystemAbilityAccessPermission();
|
||||
|
||||
bool VerifyRunningInfoPerm();
|
||||
|
||||
bool VerifyControllerPerm();
|
||||
|
@ -78,6 +78,12 @@ void EventReport::SendAbilityEvent(const std::string &eventName, HiSysEventType
|
||||
HiSysEvent::Domain::AAFWK,
|
||||
eventName,
|
||||
type);
|
||||
} else if (eventName == ABILITY_ONFOREGROUND || eventName == ABILITY_ONBACKGROUND) {
|
||||
HiSysEvent::Write(
|
||||
HiSysEvent::Domain::AAFWK,
|
||||
eventName,
|
||||
type,
|
||||
EVENT_KEY_ABILITY_NAME, eventInfo.abilityName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
const std::string DMS_PROCESS_NAME = "distributedsched";
|
||||
bool PermissionVerification::VerifyCallingPermission(const std::string &permissionName)
|
||||
{
|
||||
HILOG_DEBUG("VerifyCallingPermission permission %{public}s", permissionName.c_str());
|
||||
@ -48,6 +49,23 @@ bool PermissionVerification::IsSACall()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PermissionVerification::CheckSpecificSystemAbilityAccessPermission()
|
||||
{
|
||||
HILOG_DEBUG("PermissionVerification::CheckSpecifidSystemAbilityAccessToken is called.");
|
||||
if (!IsSACall()) {
|
||||
HILOG_ERROR("caller tokenType is not native, verify failed.");
|
||||
return false;
|
||||
}
|
||||
auto callerToken = GetCallingTokenID();
|
||||
Security::AccessToken::NativeTokenInfo nativeTokenInfo;
|
||||
int32_t result = Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(callerToken, nativeTokenInfo);
|
||||
if (result != ERR_OK || nativeTokenInfo.processName != DMS_PROCESS_NAME) {
|
||||
HILOG_ERROR("Check process name failed.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PermissionVerification::VerifyRunningInfoPerm()
|
||||
{
|
||||
if (IsSACall()) {
|
||||
|
@ -343,6 +343,7 @@ HWTEST_F(AbilityTimeoutModuleTest, OnAbilityDied_001, TestSize.Level1)
|
||||
|
||||
// died rootlauncher ability
|
||||
rootLauncher->SetAbilityState(AbilityState::FOREGROUND);
|
||||
rootLauncher->SetOwnerMissionUserId(MOCK_MAIN_USER_ID);
|
||||
abilityMs_->OnAbilityDied(rootLauncher);
|
||||
|
||||
EXPECT_TRUE(lauList->GetAbilityRecordByToken(rootLauncher->GetToken()) != nullptr);
|
||||
@ -378,6 +379,7 @@ HWTEST_F(AbilityTimeoutModuleTest, OnAbilityDied_002, TestSize.Level1)
|
||||
EXPECT_EQ(rootLauncher, ability);
|
||||
EXPECT_TRUE(rootLauncher->IsLauncherRoot());
|
||||
rootLauncher->SetAbilityState(AbilityState::FOREGROUND);
|
||||
rootLauncher->SetOwnerMissionUserId(MOCK_MAIN_USER_ID);
|
||||
|
||||
// add common ability to abilityMs
|
||||
auto commonAbility = CreateCommonAbility();
|
||||
@ -425,6 +427,7 @@ HWTEST_F(AbilityTimeoutModuleTest, OnAbilityDied_003, TestSize.Level1)
|
||||
|
||||
// died rootlauncher ability
|
||||
rootLauncher->SetAbilityState(AbilityState::FOREGROUND);
|
||||
rootLauncher->SetOwnerMissionUserId(MOCK_MAIN_USER_ID);
|
||||
int i = 0;
|
||||
while (i < rootLauncher->restratMax_) {
|
||||
abilityMs_->OnAbilityDied(rootLauncher);
|
||||
|
@ -277,8 +277,7 @@ HWTEST_F(AbilityToolTest, AbilityTool_Start_0600, TestSize.Level1)
|
||||
};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
AbilityToolCommand cmd(argc, argv);
|
||||
EXPECT_EQ(cmd.ExecCommand(), ABILITY_TOOL_HELP_MSG_WINDOW_MODE_INVALID + "\n" +
|
||||
ABILITY_TOOL_HELP_MSG_START);
|
||||
EXPECT_NE(cmd.ExecCommand().find(ABILITY_TOOL_HELP_MSG_START), string::npos);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -520,7 +519,7 @@ HWTEST_F(AbilityToolTest, AbilityTool_Test_0300, TestSize.Level1)
|
||||
};
|
||||
int argc = sizeof(argv) / sizeof(argv[0]);
|
||||
AbilityToolCommand cmd(argc, argv);
|
||||
EXPECT_EQ(cmd.ExecCommand(), ABILITY_TOOL_HELP_LACK_OPTIONS + "\n" + ABILITY_TOOL_HELP_MSG_TEST);
|
||||
EXPECT_NE(cmd.ExecCommand().find(ABILITY_TOOL_HELP_MSG_TEST), string::npos);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user