mirror of
https://github.com/openharmony/aafwk_standard.git
synced 2026-07-01 20:04:39 -04:00
@@ -225,10 +225,13 @@ ohos_shared_library("formprovider_napi") {
|
||||
deps = [
|
||||
":formutil_napi",
|
||||
"${ability_runtime_kits_path}/appkit:appkit_native",
|
||||
"${ability_runtime_path}/interfaces/kits/napi/aafwk/inner/napi_common:napi_common",
|
||||
"${form_runtime_path}:fmskit_native",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:want",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:runtime",
|
||||
|
||||
@@ -224,6 +224,25 @@ static void ParseFormInfoIntoNapi(napi_env env, const FormInfo &formInfo, napi_v
|
||||
HILOG_DEBUG("%{public}s, updateEnabled=%{public}d.", __func__, formInfo.updateEnabled);
|
||||
napi_set_named_property(env, result, "updateEnabled", updateEnabled);
|
||||
|
||||
// isStatic
|
||||
napi_value isStatic;
|
||||
napi_get_boolean(env, formInfo.isStatic, &isStatic);
|
||||
HILOG_DEBUG("%{public}s, isStatic=%{public}d.", __func__, formInfo.isStatic);
|
||||
napi_set_named_property(env, result, "isStatic", isStatic);
|
||||
|
||||
// window
|
||||
napi_value formWindowObject = nullptr;
|
||||
napi_create_object(env, &formWindowObject);
|
||||
napi_value autoDesignWidth;
|
||||
napi_get_boolean(env, formInfo.window.autoDesignWidth, &autoDesignWidth);
|
||||
HILOG_DEBUG("%{public}s, window.autoDesignWidth=%{public}d.", __func__, formInfo.window.autoDesignWidth);
|
||||
napi_set_named_property(env, formWindowObject, "autoDesignWidth", autoDesignWidth);
|
||||
napi_value designWidth;
|
||||
napi_create_int32(env, formInfo.window.designWidth, &designWidth);
|
||||
HILOG_DEBUG("%{public}s, window.designWidth=%{public}d.", __func__, formInfo.window.designWidth);
|
||||
napi_set_named_property(env, formWindowObject, "designWidth", designWidth);
|
||||
napi_set_named_property(env, result, "window", formWindowObject);
|
||||
|
||||
// formVisibleNotify
|
||||
napi_value formVisibleNotify;
|
||||
napi_create_int32(env, (int32_t)formInfo.formVisibleNotify, &formVisibleNotify);
|
||||
@@ -302,20 +321,6 @@ static void ParseFormInfoIntoNapi(napi_env env, const FormInfo &formInfo, napi_v
|
||||
return;
|
||||
}
|
||||
|
||||
static AsyncErrMsgCallbackInfo *InitErrMsg(napi_env env, int32_t code, int32_t type, napi_value callbackValue)
|
||||
{
|
||||
auto *asyncErrorInfo = new AsyncErrMsgCallbackInfo {
|
||||
.env = env,
|
||||
.asyncWork = nullptr,
|
||||
.deferred = nullptr,
|
||||
.callback = nullptr,
|
||||
.callbackValue = callbackValue,
|
||||
.code = code,
|
||||
.type = type
|
||||
};
|
||||
return asyncErrorInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call native kit function: DeleteForm
|
||||
*
|
||||
@@ -2602,10 +2607,11 @@ napi_value AcquireFormStateCallback(napi_env env, AsyncAcquireFormStateCallbackI
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
HILOG_INFO("%{public}s, napi_create_async_work complete", __func__);
|
||||
auto *asyncCallbackInfo = (AsyncAcquireFormStateCallbackInfo *) data;
|
||||
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
if (asyncCallbackInfo->result != ERR_OK) {
|
||||
FormHostClient::GetInstance()->OnAcquireState(FormState::UNKNOWN, asyncCallbackInfo->want);
|
||||
}
|
||||
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
delete asyncCallbackInfo;
|
||||
},
|
||||
(void *) asyncCallbackInfo,
|
||||
&asyncCallbackInfo->asyncWork);
|
||||
@@ -2635,10 +2641,11 @@ napi_value AcquireFormStatePromise(napi_env env, AsyncAcquireFormStateCallbackIn
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
HILOG_INFO("%{public}s, promise complete", __func__);
|
||||
auto *asyncCallbackInfo = (AsyncAcquireFormStateCallbackInfo *) data;
|
||||
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
if (asyncCallbackInfo->result != ERR_OK) {
|
||||
FormHostClient::GetInstance()->OnAcquireState(FormState::UNKNOWN, asyncCallbackInfo->want);
|
||||
}
|
||||
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
delete asyncCallbackInfo;
|
||||
},
|
||||
(void *) asyncCallbackInfo,
|
||||
&asyncCallbackInfo->asyncWork);
|
||||
|
||||
@@ -16,12 +16,13 @@
|
||||
#include "napi_form_provider.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <regex>
|
||||
#include <uv.h>
|
||||
#include <vector>
|
||||
|
||||
#include "form_mgr_errors.h"
|
||||
#include "form_mgr.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "napi_form_util.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
@@ -133,6 +134,166 @@ static std::string GetStringByProp(napi_env env, napi_value value, const std::st
|
||||
return result;
|
||||
}
|
||||
|
||||
static ErrCode UnwrapFormInfoRequiredField(napi_env env, napi_value value, FormInfo &formInfo)
|
||||
{
|
||||
if (!IsTypeForNapiValue(env, value, napi_object)) {
|
||||
HILOG_ERROR("%{public}s called. The type of the arg is not object.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!UnwrapStringByPropertyName(env, value, "moduleName", formInfo.moduleName)) {
|
||||
HILOG_ERROR("%{public}s called. Failed to get module name.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (!UnwrapStringByPropertyName(env, value, "abilityName", formInfo.abilityName)) {
|
||||
HILOG_ERROR("%{public}s called. Failed to get ability name.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (!UnwrapStringByPropertyName(env, value, "name", formInfo.name)) {
|
||||
HILOG_ERROR("%{public}s called. Failed to get form name.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (!UnwrapBooleanByPropertyName(env, value, "isDefault", formInfo.defaultFlag)) {
|
||||
HILOG_ERROR("%{public}s called. Failed to get form default flag.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (!UnwrapBooleanByPropertyName(env, value, "updateEnabled", formInfo.updateEnabled)) {
|
||||
HILOG_ERROR("%{public}s called. Failed to get form update enabled.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (!UnwrapInt32ByPropertyName(env, value, "defaultDimension", formInfo.defaultDimension)) {
|
||||
HILOG_ERROR("%{public}s called. Failed to get form default dimension.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
auto formType = (int32_t) FormType::JS;
|
||||
if (!UnwrapInt32ByPropertyName(env, value, "type", formType)) {
|
||||
HILOG_ERROR("%{public}s called. Failed to get form type.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (formType != (int32_t) FormType::JS) {
|
||||
HILOG_INFO("%{public}s called. Invalid form type.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
formInfo.type = FormType::JS;
|
||||
|
||||
napi_value jsArray = GetPropertyValueByPropertyName(env, value, "supportDimensions", napi_object);
|
||||
if (jsArray == nullptr) {
|
||||
HILOG_ERROR("%{public}s called. Failed to get form support dimensions array.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (!UnwrapArrayInt32FromJS(env, jsArray, formInfo.supportDimensions)) {
|
||||
HILOG_ERROR("%{public}s called. Failed to get form support dimensions.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static ErrCode UnwrapFormInfoCustomData(napi_env env, napi_value value, std::vector<FormCustomizeData> &customizeData)
|
||||
{
|
||||
napi_value jsArray = GetPropertyValueByPropertyName(env, value, "customizeData", napi_object);
|
||||
uint32_t arraySize = 0;
|
||||
if (jsArray == nullptr) {
|
||||
// customizeData can be empty
|
||||
return ERR_OK;
|
||||
}
|
||||
if (IsArrayForNapiValue(env, jsArray, arraySize)) {
|
||||
// wrong type for customizeData field, ignore
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < arraySize; i++) {
|
||||
napi_value jsValue = nullptr;
|
||||
if (napi_get_element(env, jsArray, i, &jsValue) != napi_ok) {
|
||||
// wrong type for customizeData, skip
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string customizeDataName;
|
||||
UnwrapStringByPropertyName(env, value, "name", customizeDataName);
|
||||
std::string customizeDataValue;
|
||||
UnwrapStringByPropertyName(env, value, "value", customizeDataValue);
|
||||
customizeData.push_back({customizeDataName, customizeDataValue});
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static ErrCode FormInfoCheck(const FormInfo &formInfo)
|
||||
{
|
||||
if (formInfo.moduleName.empty()) {
|
||||
HILOG_ERROR("%{public}s called. The moduleName is empty.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (formInfo.abilityName.empty()) {
|
||||
HILOG_ERROR("%{public}s called. The abilityName is empty.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (formInfo.name.empty()) {
|
||||
HILOG_ERROR("%{public}s called. The name is empty.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (formInfo.defaultDimension < Constants::DIM_KEY_MIN || formInfo.defaultDimension > Constants::DIM_KEY_MAX) {
|
||||
HILOG_ERROR("%{public}s called. Invalid dimension: %{public}d.", __func__, formInfo.defaultDimension);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (formInfo.supportDimensions.empty()) {
|
||||
HILOG_ERROR("%{public}s called. The supportDimensions is empty.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
bool inSupportDimensions = false;
|
||||
for (int32_t supportDimension : formInfo.supportDimensions) {
|
||||
if (supportDimension < Constants::DIM_KEY_MIN || supportDimension > Constants::DIM_KEY_MAX) {
|
||||
HILOG_ERROR("%{public}s called. Invalid dimension: %{public}d.", __func__, supportDimension);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (supportDimension == formInfo.defaultDimension) {
|
||||
inSupportDimensions = true;
|
||||
}
|
||||
}
|
||||
if (!inSupportDimensions) {
|
||||
HILOG_ERROR("%{public}s called. default dimension is not in the supportDimensions.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static ErrCode UnwrapFormInfo(napi_env env, napi_value value, FormInfo &formInfo)
|
||||
{
|
||||
ErrCode errCode = UnwrapFormInfoRequiredField(env, value, formInfo);
|
||||
if (errCode != ERR_OK) {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
UnwrapStringByPropertyName(env, value, "bundleName", formInfo.bundleName);
|
||||
UnwrapStringByPropertyName(env, value, "description", formInfo.description);
|
||||
UnwrapStringByPropertyName(env, value, "jsComponentName", formInfo.jsComponentName);
|
||||
UnwrapBooleanByPropertyName(env, value, "formVisibleNotify", formInfo.formVisibleNotify);
|
||||
UnwrapStringByPropertyName(env, value, "relatedBundleName", formInfo.relatedBundleName);
|
||||
UnwrapStringByPropertyName(env, value, "scheduledUpdateTime", formInfo.scheduledUpdateTime);
|
||||
UnwrapStringByPropertyName(env, value, "formConfigAbility", formInfo.formConfigAbility);
|
||||
UnwrapInt32ByPropertyName(env, value, "updateDuration", formInfo.updateDuration);
|
||||
UnwrapBooleanByPropertyName(env, value, "isStatic", formInfo.isStatic);
|
||||
|
||||
napi_value jsWindowValue = GetPropertyValueByPropertyName(env, value, "window", napi_object);
|
||||
if (jsWindowValue != nullptr) {
|
||||
UnwrapInt32ByPropertyName(env, jsWindowValue, "designWidth", formInfo.window.designWidth);
|
||||
UnwrapBooleanByPropertyName(env, jsWindowValue, "autoDesignWidth", formInfo.window.autoDesignWidth);
|
||||
}
|
||||
|
||||
auto colorMode = (int32_t) FormsColorMode::AUTO_MODE;
|
||||
UnwrapInt32ByPropertyName(env, value, "colorMode", colorMode);
|
||||
if (colorMode < (int32_t) FormsColorMode::AUTO_MODE || colorMode > (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;
|
||||
|
||||
UnwrapFormInfoCustomData(env, value, formInfo.customizeDatas);
|
||||
return FormInfoCheck(formInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call native kit function: SetFormNextRefreshTime
|
||||
*
|
||||
@@ -141,7 +302,7 @@ static std::string GetStringByProp(napi_env env, napi_value value, const std::st
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static void InnerSetFormNextRefreshTime(napi_env env, AsyncNextRefreshTimeFormCallbackInfo* const asyncCallbackInfo)
|
||||
static void InnerSetFormNextRefreshTime(napi_env, AsyncNextRefreshTimeFormCallbackInfo *const asyncCallbackInfo)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s called.", __func__);
|
||||
OHOS::AppExecFwk::Ability *ability = asyncCallbackInfo->ability;
|
||||
@@ -549,4 +710,530 @@ napi_value NAPI_UpdateForm(napi_env env, napi_callback_info info)
|
||||
napi_queue_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void InnerRequestPublishForm(napi_env env, AsyncRequestPublishFormCallbackInfo *const asyncCallbackInfo)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s called.", __func__);
|
||||
if (FormMgr::GetRecoverStatus() == Constants::IN_RECOVERING) {
|
||||
HILOG_ERROR("%{public}s error, form is in recover status, can't do action on form.", __func__);
|
||||
asyncCallbackInfo->result = ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR;
|
||||
return;
|
||||
}
|
||||
|
||||
ErrCode errCode = FormMgr::GetInstance().RequestPublishForm(asyncCallbackInfo->want,
|
||||
asyncCallbackInfo->withFormBindingData, asyncCallbackInfo->formProviderData);
|
||||
if (errCode != ERR_OK) {
|
||||
HILOG_ERROR("Failed to AddFormInfo, error code is %{public}d.", errCode);
|
||||
}
|
||||
asyncCallbackInfo->result = errCode;
|
||||
HILOG_DEBUG("%{public}s, end", __func__);
|
||||
}
|
||||
|
||||
static ErrCode RequestPublishFormParse(napi_env env, napi_value *argv,
|
||||
AsyncRequestPublishFormCallbackInfo *asyncCallbackInfo)
|
||||
{
|
||||
bool parseResult = UnwrapWant(env, argv[0], asyncCallbackInfo->want);
|
||||
if (!parseResult) {
|
||||
HILOG_ERROR("%{public}s, failed to parse want.", __func__);
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
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 {
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
|
||||
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_value resourceName;
|
||||
napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName);
|
||||
napi_create_async_work(
|
||||
env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
HILOG_INFO("%{public}s, napi_create_async_work running", __func__);
|
||||
auto *asyncCallbackInfo = (AsyncRequestPublishFormCallbackInfo *) data;
|
||||
InnerRequestPublishForm(env, asyncCallbackInfo);
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
HILOG_INFO("%{public}s, napi_create_async_work complete", __func__);
|
||||
auto *asyncCallbackInfo = (AsyncRequestPublishFormCallbackInfo *) data;
|
||||
|
||||
if (asyncCallbackInfo->callback != nullptr) {
|
||||
napi_value callback;
|
||||
napi_value callbackValues[ARGS_SIZE_TWO] = {nullptr, nullptr};
|
||||
InnerCreateCallbackRetMsg(env, asyncCallbackInfo->result, callbackValues);
|
||||
|
||||
napi_get_reference_value(env, asyncCallbackInfo->callback, &callback);
|
||||
napi_value callResult;
|
||||
napi_call_function(env, nullptr, callback, ARGS_SIZE_TWO, callbackValues, &callResult);
|
||||
napi_delete_reference(env, asyncCallbackInfo->callback);
|
||||
}
|
||||
|
||||
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
delete asyncCallbackInfo;
|
||||
},
|
||||
(void *) asyncCallbackInfo,
|
||||
&asyncCallbackInfo->asyncWork);
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork));
|
||||
return NapiGetResut(env, 1);
|
||||
}
|
||||
|
||||
static napi_value RequestPublishFormPromise(napi_env env, napi_value *argv, bool withFormBindingData)
|
||||
{
|
||||
HILOG_INFO("%{public}s, promise.", __func__);
|
||||
napi_deferred deferred;
|
||||
napi_value promise;
|
||||
NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
|
||||
|
||||
auto *asyncCallbackInfo = new AsyncRequestPublishFormCallbackInfo {
|
||||
.env = env,
|
||||
.ability = GetGlobalAbility(env),
|
||||
.deferred = deferred,
|
||||
.withFormBindingData = withFormBindingData,
|
||||
};
|
||||
|
||||
ErrCode errCode = RequestPublishFormParse(env, argv, asyncCallbackInfo);
|
||||
if (errCode != ERR_OK) {
|
||||
delete asyncCallbackInfo;
|
||||
return RetErrMsg(InitErrMsg(env, errCode, PROMISE_FLG, nullptr));
|
||||
}
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName);
|
||||
napi_create_async_work(
|
||||
env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
HILOG_INFO("%{public}s, promise running", __func__);
|
||||
auto *asyncCallbackInfo = (AsyncRequestPublishFormCallbackInfo *) data;
|
||||
InnerRequestPublishForm(env, asyncCallbackInfo);
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
HILOG_INFO("%{public}s, promise complete", __func__);
|
||||
auto *asyncCallbackInfo = (AsyncAddFormInfoCallbackInfo *) data;
|
||||
napi_value result;
|
||||
InnerCreatePromiseRetMsg(env, asyncCallbackInfo->result, &result);
|
||||
if (asyncCallbackInfo->result == ERR_OK) {
|
||||
napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result);
|
||||
} else {
|
||||
napi_reject_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result);
|
||||
}
|
||||
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
delete asyncCallbackInfo;
|
||||
},
|
||||
(void *) asyncCallbackInfo,
|
||||
&asyncCallbackInfo->asyncWork);
|
||||
napi_queue_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
return promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The implementation of Node-API interface: requestPinForm
|
||||
*
|
||||
* @param[in] env The environment that the Node-API call is invoked under
|
||||
* @param[out] info An opaque datatype that is passed to a callback function
|
||||
*
|
||||
* @return This is an opaque pointer that is used to represent a JavaScript value
|
||||
*/
|
||||
napi_value NAPI_RequestPublishForm(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
// Check the number of the arguments
|
||||
size_t argc = ARGS_SIZE_THREE;
|
||||
napi_value argv[ARGS_SIZE_THREE] = {nullptr, nullptr, nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
|
||||
if (argc > ARGS_SIZE_THREE) {
|
||||
HILOG_ERROR("%{public}s, wrong number of arguments.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc);
|
||||
|
||||
if (argc < ARGS_SIZE_TWO) {
|
||||
// promise, no form binding data
|
||||
return RequestPublishFormPromise(env, argv, false);
|
||||
} else if (argc > ARGS_SIZE_TWO) {
|
||||
// callback, with form binding data
|
||||
return RequestPublishFormCallback(env, argv, true);
|
||||
} else {
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
NAPI_CALL(env, napi_typeof(env, argv[1], &valueType));
|
||||
if (valueType == napi_function) {
|
||||
// callback, no form binding data
|
||||
return RequestPublishFormCallback(env, argv, false);
|
||||
} else {
|
||||
// promise, with form binding data
|
||||
return RequestPublishFormPromise(env, argv, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void InnerAddFormInfo(napi_env env, AsyncAddFormInfoCallbackInfo *const asyncCallbackInfo)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s called.", __func__);
|
||||
if (FormMgr::GetRecoverStatus() == Constants::IN_RECOVERING) {
|
||||
HILOG_ERROR("%{public}s error, form is in recover status, can't do action on form.", __func__);
|
||||
asyncCallbackInfo->result = ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR;
|
||||
return;
|
||||
}
|
||||
|
||||
ErrCode errCode = FormMgr::GetInstance().AddFormInfo(asyncCallbackInfo->formInfo);
|
||||
if (errCode != ERR_OK) {
|
||||
HILOG_ERROR("Failed to AddFormInfo, error code is %{public}d.", errCode);
|
||||
}
|
||||
asyncCallbackInfo->result = errCode;
|
||||
HILOG_DEBUG("%{public}s, end", __func__);
|
||||
}
|
||||
|
||||
static napi_value AddFormInfoCallback(napi_env env, AsyncAddFormInfoCallbackInfo *const asyncCallbackInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, asyncCallback.", __func__);
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName);
|
||||
napi_create_async_work(
|
||||
env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
HILOG_INFO("%{public}s, napi_create_async_work running", __func__);
|
||||
auto *asyncCallbackInfo = (AsyncAddFormInfoCallbackInfo *) data;
|
||||
InnerAddFormInfo(env, asyncCallbackInfo);
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
HILOG_INFO("%{public}s, napi_create_async_work complete", __func__);
|
||||
auto *asyncCallbackInfo = (AsyncAddFormInfoCallbackInfo *) data;
|
||||
|
||||
if (asyncCallbackInfo->callback != nullptr) {
|
||||
napi_value callback;
|
||||
napi_value callbackValues[ARGS_SIZE_TWO] = {nullptr, nullptr};
|
||||
InnerCreateCallbackRetMsg(env, asyncCallbackInfo->result, callbackValues);
|
||||
|
||||
napi_get_reference_value(env, asyncCallbackInfo->callback, &callback);
|
||||
napi_value callResult;
|
||||
napi_call_function(env, nullptr, callback, ARGS_SIZE_TWO, callbackValues, &callResult);
|
||||
napi_delete_reference(env, asyncCallbackInfo->callback);
|
||||
}
|
||||
|
||||
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
delete asyncCallbackInfo;
|
||||
},
|
||||
(void *) asyncCallbackInfo,
|
||||
&asyncCallbackInfo->asyncWork);
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork));
|
||||
return NapiGetResut(env, 1);
|
||||
}
|
||||
|
||||
static napi_value AddFormInfoPromise(napi_env env, AsyncAddFormInfoCallbackInfo *const asyncCallbackInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, promise.", __func__);
|
||||
napi_deferred deferred;
|
||||
napi_value promise;
|
||||
NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
|
||||
asyncCallbackInfo->deferred = deferred;
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName);
|
||||
napi_create_async_work(
|
||||
env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
HILOG_INFO("%{public}s, promise running", __func__);
|
||||
auto *asyncCallbackInfo = (AsyncAddFormInfoCallbackInfo *) data;
|
||||
InnerAddFormInfo(env, asyncCallbackInfo);
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
HILOG_INFO("%{public}s, promise complete", __func__);
|
||||
auto *asyncCallbackInfo = (AsyncAddFormInfoCallbackInfo *) data;
|
||||
napi_value result;
|
||||
InnerCreatePromiseRetMsg(env, asyncCallbackInfo->result, &result);
|
||||
if (asyncCallbackInfo->result == ERR_OK) {
|
||||
napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result);
|
||||
} else {
|
||||
napi_reject_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result);
|
||||
}
|
||||
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
delete asyncCallbackInfo;
|
||||
},
|
||||
(void *) asyncCallbackInfo,
|
||||
&asyncCallbackInfo->asyncWork);
|
||||
napi_queue_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
return promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The implementation of Node-API interface: addFormInfo
|
||||
*
|
||||
* @param[in] env The environment that the Node-API call is invoked under
|
||||
* @param[out] info An opaque datatype that is passed to a callback function
|
||||
*
|
||||
* @return This is an opaque pointer that is used to represent a JavaScript value
|
||||
*/
|
||||
napi_value NAPI_AddFormInfo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
// Check the number of the arguments
|
||||
size_t argc = ARGS_SIZE_TWO;
|
||||
napi_value argv[ARGS_SIZE_TWO] = {nullptr, nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
|
||||
if (argc > ARGS_SIZE_TWO) {
|
||||
HILOG_ERROR("%{public}s, wrong number of arguments.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc);
|
||||
|
||||
int32_t callbackType = (argc == ARGS_SIZE_TWO) ? CALLBACK_FLG : PROMISE_FLG;
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valueType));
|
||||
if (valueType != napi_object) {
|
||||
return RetErrMsg(InitErrMsg(env, ERR_APPEXECFWK_FORM_INVALID_PARAM, callbackType, argv[1]));
|
||||
}
|
||||
|
||||
auto *asyncCallbackInfo = new AsyncAddFormInfoCallbackInfo {
|
||||
.env = env,
|
||||
.ability = GetGlobalAbility(env),
|
||||
.asyncWork = nullptr,
|
||||
.deferred = nullptr,
|
||||
.callback = nullptr,
|
||||
.formInfo = {},
|
||||
.result = ERR_OK,
|
||||
};
|
||||
|
||||
ErrCode errCode = UnwrapFormInfo(env, argv[0], asyncCallbackInfo->formInfo);
|
||||
if (errCode != ERR_OK) {
|
||||
HILOG_ERROR("%{public}s, failed to parse formInfo.", __func__);
|
||||
delete asyncCallbackInfo;
|
||||
return RetErrMsg(InitErrMsg(env, errCode, callbackType, argv[1]));
|
||||
}
|
||||
|
||||
if (argc == ARGS_SIZE_TWO) {
|
||||
// Check the value type of the arguments
|
||||
valueType = napi_undefined;
|
||||
NAPI_CALL(env, napi_typeof(env, argv[1], &valueType));
|
||||
NAPI_ASSERT(env, valueType == napi_function,
|
||||
"The arguments[1] type of addDynamicForms is incorrect, expected type is function.");
|
||||
napi_create_reference(env, argv[1], REF_COUNT, &asyncCallbackInfo->callback);
|
||||
return AddFormInfoCallback(env, asyncCallbackInfo);
|
||||
} else {
|
||||
return AddFormInfoPromise(env, asyncCallbackInfo);
|
||||
}
|
||||
}
|
||||
|
||||
static void InnerRemoveFormInfo(napi_env env, AsyncRemoveFormInfoCallbackInfo *const asyncCallbackInfo)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s called.", __func__);
|
||||
if (FormMgr::GetRecoverStatus() == Constants::IN_RECOVERING) {
|
||||
HILOG_ERROR("%{public}s error, form is in recover status, can't do action on form.", __func__);
|
||||
asyncCallbackInfo->result = ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR;
|
||||
return;
|
||||
}
|
||||
|
||||
ErrCode errCode = FormMgr::GetInstance().RemoveFormInfo(asyncCallbackInfo->moduleName, asyncCallbackInfo->formName);
|
||||
if (errCode != ERR_OK) {
|
||||
HILOG_ERROR("Failed to AddFormInfo, error code is %{public}d.", errCode);
|
||||
}
|
||||
asyncCallbackInfo->result = errCode;
|
||||
HILOG_DEBUG("%{public}s, end", __func__);
|
||||
}
|
||||
|
||||
static napi_value RemoveFormInfoCallback(napi_env env, AsyncRemoveFormInfoCallbackInfo *const asyncCallbackInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, asyncCallback.", __func__);
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName);
|
||||
napi_create_async_work(
|
||||
env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
HILOG_INFO("%{public}s, napi_create_async_work running", __func__);
|
||||
auto *asyncCallbackInfo = (AsyncRemoveFormInfoCallbackInfo *) data;
|
||||
InnerRemoveFormInfo(env, asyncCallbackInfo);
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
HILOG_INFO("%{public}s, napi_create_async_work complete", __func__);
|
||||
auto *asyncCallbackInfo = (AsyncRemoveFormInfoCallbackInfo *) data;
|
||||
|
||||
if (asyncCallbackInfo->callback != nullptr) {
|
||||
napi_value callback;
|
||||
napi_value callbackValues[ARGS_SIZE_TWO] = {nullptr, nullptr};
|
||||
InnerCreateCallbackRetMsg(env, asyncCallbackInfo->result, callbackValues);
|
||||
|
||||
napi_get_reference_value(env, asyncCallbackInfo->callback, &callback);
|
||||
napi_value callResult;
|
||||
napi_call_function(env, nullptr, callback, ARGS_SIZE_TWO, callbackValues, &callResult);
|
||||
napi_delete_reference(env, asyncCallbackInfo->callback);
|
||||
}
|
||||
|
||||
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
delete asyncCallbackInfo;
|
||||
},
|
||||
(void *) asyncCallbackInfo,
|
||||
&asyncCallbackInfo->asyncWork);
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork));
|
||||
return NapiGetResut(env, 1);
|
||||
}
|
||||
|
||||
static napi_value RemoveFormInfoPromise(napi_env env, AsyncRemoveFormInfoCallbackInfo *const asyncCallbackInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, promise.", __func__);
|
||||
napi_deferred deferred;
|
||||
napi_value promise;
|
||||
NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
|
||||
asyncCallbackInfo->deferred = deferred;
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName);
|
||||
napi_create_async_work(
|
||||
env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
HILOG_INFO("%{public}s, promise running", __func__);
|
||||
auto *asyncCallbackInfo = (AsyncRemoveFormInfoCallbackInfo *) data;
|
||||
InnerRemoveFormInfo(env, asyncCallbackInfo);
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
HILOG_INFO("%{public}s, promise complete", __func__);
|
||||
auto *asyncCallbackInfo = (AsyncRemoveFormInfoCallbackInfo *) data;
|
||||
napi_value result;
|
||||
InnerCreatePromiseRetMsg(env, asyncCallbackInfo->result, &result);
|
||||
if (asyncCallbackInfo->result == ERR_OK) {
|
||||
napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result);
|
||||
} else {
|
||||
napi_reject_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result);
|
||||
}
|
||||
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
delete asyncCallbackInfo;
|
||||
},
|
||||
(void *) asyncCallbackInfo,
|
||||
&asyncCallbackInfo->asyncWork);
|
||||
napi_queue_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
return promise;
|
||||
}
|
||||
|
||||
static ErrCode GetRemoveFormInfoArgs(napi_env env, napi_value *argv, std::string &moduleName, std::string &formName)
|
||||
{
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
if (napi_typeof(env, argv[0], &valueType) != napi_ok) {
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (valueType != napi_string) {
|
||||
HILOG_ERROR("wrong type for argv[0].");
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (!UnwrapStringFromJS2(env, argv[0], moduleName)) {
|
||||
HILOG_ERROR("failed to get moduleName.");
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (moduleName.empty()) {
|
||||
HILOG_ERROR("moduleName is empty.");
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
valueType = napi_undefined;
|
||||
if (napi_typeof(env, argv[1], &valueType) != napi_ok) {
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (valueType != napi_string) {
|
||||
HILOG_ERROR("wrong type for argv[1].");
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (!UnwrapStringFromJS2(env, argv[1], formName)) {
|
||||
HILOG_ERROR("failed to get formName.");
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
if (formName.empty()) {
|
||||
HILOG_ERROR("formName is empty.");
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The implementation of Node-API interface: removeFormInfo
|
||||
*
|
||||
* @param[in] env The environment that the Node-API call is invoked under
|
||||
* @param[out] info An opaque datatype that is passed to a callback function
|
||||
*
|
||||
* @return This is an opaque pointer that is used to represent a JavaScript value
|
||||
*/
|
||||
napi_value NAPI_RemoveFormInfo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
// Check the number of the arguments
|
||||
size_t argc = ARGS_SIZE_THREE;
|
||||
napi_value argv[ARGS_SIZE_THREE] = {nullptr, nullptr, nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
|
||||
if (argc > ARGS_SIZE_THREE || argc < ARGS_SIZE_TWO) {
|
||||
HILOG_ERROR("%{public}s, wrong number of arguments.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc);
|
||||
|
||||
int32_t callbackType = (argc == ARGS_SIZE_THREE) ? CALLBACK_FLG : PROMISE_FLG;
|
||||
std::string moduleName;
|
||||
std::string formName;
|
||||
ErrCode errCode = GetRemoveFormInfoArgs(env, argv, moduleName, formName);
|
||||
if (errCode != ERR_OK) {
|
||||
return RetErrMsg(InitErrMsg(env, errCode, callbackType, argv[ARGS_SIZE_TWO]));
|
||||
}
|
||||
|
||||
auto *asyncCallbackInfo = new AsyncRemoveFormInfoCallbackInfo {
|
||||
.env = env,
|
||||
.ability = GetGlobalAbility(env),
|
||||
.moduleName = moduleName,
|
||||
.formName = formName,
|
||||
};
|
||||
|
||||
if (argc == ARGS_SIZE_THREE) {
|
||||
// Check the value type of the arguments
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_TWO], &valueType));
|
||||
NAPI_ASSERT(env, valueType == napi_function,
|
||||
"The arguments[2] type of removeDynamicForms is incorrect, expected type is function.");
|
||||
napi_create_reference(env, argv[ARGS_SIZE_TWO], REF_COUNT, &asyncCallbackInfo->callback);
|
||||
return RemoveFormInfoCallback(env, asyncCallbackInfo);
|
||||
} else {
|
||||
return RemoveFormInfoPromise(env, asyncCallbackInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,8 +46,43 @@ struct AsyncUpdateFormCallbackInfo {
|
||||
int result;
|
||||
};
|
||||
|
||||
struct AsyncRequestPublishFormCallbackInfo {
|
||||
napi_env env = nullptr;
|
||||
OHOS::AppExecFwk::Ability *ability = nullptr;
|
||||
napi_async_work asyncWork = nullptr;
|
||||
napi_deferred deferred = nullptr;
|
||||
napi_ref callback = nullptr;
|
||||
Want want {};
|
||||
bool withFormBindingData = false;
|
||||
std::unique_ptr<OHOS::AppExecFwk::FormProviderData> formProviderData = nullptr;
|
||||
int32_t result = OHOS::ERR_OK;
|
||||
};
|
||||
|
||||
struct AsyncAddFormInfoCallbackInfo {
|
||||
napi_env env = nullptr;
|
||||
OHOS::AppExecFwk::Ability *ability = nullptr;
|
||||
napi_async_work asyncWork = nullptr;
|
||||
napi_deferred deferred = nullptr;
|
||||
napi_ref callback = nullptr;
|
||||
OHOS::AppExecFwk::FormInfo formInfo {};
|
||||
int32_t result = OHOS::ERR_OK;
|
||||
};
|
||||
|
||||
struct AsyncRemoveFormInfoCallbackInfo {
|
||||
napi_env env = nullptr;
|
||||
OHOS::AppExecFwk::Ability *ability = nullptr;
|
||||
napi_async_work asyncWork = nullptr;
|
||||
napi_deferred deferred = nullptr;
|
||||
napi_ref callback = nullptr;
|
||||
std::string moduleName;
|
||||
std::string formName;
|
||||
int32_t result = OHOS::ERR_OK;
|
||||
};
|
||||
|
||||
napi_value NAPI_SetFormNextRefreshTime(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_UpdateForm(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_RequestPublishForm(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_AddFormInfo(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_RemoveFormInfo(napi_env env, napi_callback_info info);
|
||||
|
||||
#endif /* NAPI_FORM_PROVIDER_H_ */
|
||||
|
||||
@@ -14,11 +14,6 @@
|
||||
*/
|
||||
#include "napi/native_api.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "napi_form_provider.h"
|
||||
@@ -35,13 +30,16 @@ EXTERN_C_START
|
||||
*/
|
||||
static napi_value Init(napi_env env, napi_value exports)
|
||||
{
|
||||
HILOG_INFO("napi_moudule Init start...");
|
||||
HILOG_INFO("napi_module Init start...");
|
||||
napi_property_descriptor properties[] = {
|
||||
DECLARE_NAPI_FUNCTION("setFormNextRefreshTime", NAPI_SetFormNextRefreshTime),
|
||||
DECLARE_NAPI_FUNCTION("updateForm", NAPI_UpdateForm),
|
||||
DECLARE_NAPI_FUNCTION("requestPublishForm", NAPI_RequestPublishForm),
|
||||
DECLARE_NAPI_FUNCTION("addFormInfo", NAPI_AddFormInfo),
|
||||
DECLARE_NAPI_FUNCTION("removeFormInfo", NAPI_RemoveFormInfo),
|
||||
};
|
||||
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(properties) / sizeof(properties[0]), properties));
|
||||
HILOG_INFO("napi_moudule Init end...");
|
||||
HILOG_INFO("napi_module Init end...");
|
||||
|
||||
return exports;
|
||||
}
|
||||
@@ -55,8 +53,8 @@ static napi_module _module = {
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = Init,
|
||||
.nm_modname = "application.formProvider",
|
||||
.nm_priv = ((void *)0),
|
||||
.reserved = {0}
|
||||
.nm_priv = nullptr,
|
||||
.reserved = {nullptr}
|
||||
};
|
||||
|
||||
// Registers a Node-API module.
|
||||
|
||||
@@ -369,3 +369,17 @@ napi_value RetErrMsg(AsyncErrMsgCallbackInfo* asyncCallbackInfo)
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
AsyncErrMsgCallbackInfo *InitErrMsg(napi_env env, int32_t code, int32_t type, napi_value callbackValue)
|
||||
{
|
||||
auto *asyncErrorInfo = new AsyncErrMsgCallbackInfo {
|
||||
.env = env,
|
||||
.asyncWork = nullptr,
|
||||
.deferred = nullptr,
|
||||
.callback = nullptr,
|
||||
.callbackValue = callbackValue,
|
||||
.code = code,
|
||||
.type = type
|
||||
};
|
||||
return asyncErrorInfo;
|
||||
}
|
||||
|
||||
@@ -62,5 +62,6 @@ bool ConvertStringToInt64(const std::string &strInfo, int64_t &int64Value);
|
||||
void InnerCreateCallbackRetMsg(napi_env env, int32_t code, napi_value* result);
|
||||
void InnerCreatePromiseRetMsg(napi_env env, int32_t code, napi_value* result);
|
||||
napi_value RetErrMsg(AsyncErrMsgCallbackInfo* asyncCallbackInfo);
|
||||
AsyncErrMsgCallbackInfo *InitErrMsg(napi_env env, int32_t code, int32_t type, napi_value callbackValue);
|
||||
|
||||
#endif /* NAPI_FORM_UTIL_H_ */
|
||||
|
||||
@@ -122,6 +122,8 @@ namespace Constants {
|
||||
{3, "2*4"},
|
||||
{4, "4*4"},
|
||||
};
|
||||
const int32_t DIM_KEY_MIN = 1;
|
||||
const int32_t DIM_KEY_MAX = 4;
|
||||
const int MAX_FORMS = 512;
|
||||
const int MAX_RECORD_PER_APP = 256;
|
||||
const int MAX_TEMP_FORMS = 256;
|
||||
|
||||
@@ -82,6 +82,34 @@ public:
|
||||
*/
|
||||
virtual int SetNextRefreshTime(const int64_t formId, const int64_t nextTime) = 0;
|
||||
|
||||
/**
|
||||
* @brief Add the form info.
|
||||
*
|
||||
* @param formInfo Indicates the form info to be added.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual ErrCode AddFormInfo(FormInfo &formInfo) = 0;
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
virtual ErrCode RemoveFormInfo(const std::string &moduleName, const std::string &formName) = 0;
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
virtual ErrCode RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData) = 0;
|
||||
|
||||
/**
|
||||
* @brief Lifecycle update.
|
||||
* @param formIds The Id of the forms.
|
||||
@@ -297,7 +325,10 @@ public:
|
||||
FORM_MGR_GET_FORMS_INFO_BY_APP,
|
||||
FORM_MGR_GET_FORMS_INFO_BY_MODULE,
|
||||
FORM_MGR_ROUTER_EVENT,
|
||||
FORM_MGR_UPDATE_ROUTER_ACTION
|
||||
FORM_MGR_UPDATE_ROUTER_ACTION,
|
||||
FORM_MGR_ADD_FORM_INFO,
|
||||
FORM_MGR_REMOVE_FORM_INFO,
|
||||
FORM_MGR_REQUEST_PUBLISH_FORM
|
||||
};
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
|
||||
@@ -76,6 +76,34 @@ public:
|
||||
*/
|
||||
virtual int SetNextRefreshTime(const int64_t formId, const int64_t nextTime) override;
|
||||
|
||||
/**
|
||||
* @brief Add the form info.
|
||||
*
|
||||
* @param formInfo Indicates the form info to be added.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual ErrCode AddFormInfo(FormInfo &formInfo) override;
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
virtual ErrCode RemoveFormInfo(const std::string &moduleName, const std::string &formName) override;
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
virtual ErrCode RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData) override;
|
||||
|
||||
/**
|
||||
* @brief Lifecycle update.
|
||||
* @param formIds The Id of the forms.
|
||||
|
||||
@@ -86,6 +86,31 @@ private:
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t HandleSetNextRefreshTime(MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
/**
|
||||
* @brief handle AddFormInfo message.
|
||||
* @param data input param.
|
||||
* @param reply output param.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode HandleAddFormInfo(MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
/**
|
||||
* @brief handle RemoveFormInfo message.
|
||||
* @param data input param.
|
||||
* @param reply output param.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode HandleRemoveFormInfo(MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
/**
|
||||
* @brief handle RequestPublishForm message.
|
||||
* @param data input param.
|
||||
* @param reply output param.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode HandleRequestPublishForm(MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
/**
|
||||
* @brief Handle RequestForm message.
|
||||
* @param data input param.
|
||||
|
||||
@@ -212,6 +212,124 @@ 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;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
HILOG_ERROR("%{public}s, failed to write interface token", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteParcelable(&formInfo)) {
|
||||
HILOG_ERROR("%{public}s, failed to write formInfo", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
MessageOption option;
|
||||
int32_t error = Remote()->SendRequest(
|
||||
static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_ADD_FORM_INFO),
|
||||
data,
|
||||
reply,
|
||||
option);
|
||||
if (error != ERR_OK) {
|
||||
HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
|
||||
return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
|
||||
}
|
||||
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;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
HILOG_ERROR("%{public}s, failed to write interface token", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteString(moduleName)) {
|
||||
HILOG_ERROR("%{public}s, failed to write moduleName", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteString(formName)) {
|
||||
HILOG_ERROR("%{public}s, failed to write formName", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
MessageOption option;
|
||||
int32_t error = Remote()->SendRequest(
|
||||
static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REMOVE_FORM_INFO),
|
||||
data,
|
||||
reply,
|
||||
option);
|
||||
if (error != ERR_OK) {
|
||||
HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
|
||||
return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
|
||||
}
|
||||
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)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
HILOG_ERROR("%{public}s, failed to write interface token", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteParcelable(&want)) {
|
||||
HILOG_ERROR("%{public}s, failed to write want", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteBool(withFormBindingData)) {
|
||||
HILOG_ERROR("%{public}s, failed to write withFormBindingData", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
if (withFormBindingData) {
|
||||
if (!data.WriteParcelable(formBindingData.get())) {
|
||||
HILOG_ERROR("%{public}s, failed to write formBindingData", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
MessageOption option;
|
||||
int32_t error = Remote()->SendRequest(
|
||||
static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_FORM),
|
||||
data,
|
||||
reply,
|
||||
option);
|
||||
if (error != ERR_OK) {
|
||||
HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
|
||||
return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
|
||||
}
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Lifecycle update.
|
||||
* @param formIds The Id of the forms.
|
||||
|
||||
@@ -95,6 +95,12 @@ FormMgrStub::FormMgrStub()
|
||||
&FormMgrStub::HandleRouterEvent;
|
||||
memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_UPDATE_ROUTER_ACTION)] =
|
||||
&FormMgrStub::HandleUpdateRouterAction;
|
||||
memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_ADD_FORM_INFO)] =
|
||||
&FormMgrStub::HandleAddFormInfo;
|
||||
memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REMOVE_FORM_INFO)] =
|
||||
&FormMgrStub::HandleRemoveFormInfo;
|
||||
memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_FORM)] =
|
||||
&FormMgrStub::HandleRequestPublishForm;
|
||||
}
|
||||
|
||||
FormMgrStub::~FormMgrStub()
|
||||
@@ -220,6 +226,64 @@ int32_t FormMgrStub::HandleSetNextRefreshTime(MessageParcel &data, MessageParcel
|
||||
reply.WriteInt32(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief handle AddFormInfo message.
|
||||
* @param data input param.
|
||||
* @param reply output param.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FormMgrStub::HandleAddFormInfo(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::unique_ptr<FormInfo> formInfo(data.ReadParcelable<FormInfo>());
|
||||
if (formInfo == nullptr) {
|
||||
HILOG_ERROR("%{public}s, failed to get formInfo.", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
ErrCode result = AddFormInfo(*formInfo);
|
||||
reply.WriteInt32(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief handle RemoveFormInfo message.
|
||||
* @param data input param.
|
||||
* @param reply output param.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FormMgrStub::HandleRemoveFormInfo(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string moduleName = data.ReadString();
|
||||
std::string formName = data.ReadString();
|
||||
ErrCode result = RemoveFormInfo(moduleName, formName);
|
||||
reply.WriteInt32(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief handle RequestPublishForm message.
|
||||
* @param data input param.
|
||||
* @param reply output param.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode FormMgrStub::HandleRequestPublishForm(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::unique_ptr<Want> want(data.ReadParcelable<Want>());
|
||||
if (want == nullptr) {
|
||||
HILOG_ERROR("%{public}s, failed to get want.", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
bool withFormBindingData = data.ReadBool();
|
||||
std::unique_ptr<FormProviderData> formProviderData = nullptr;
|
||||
if (withFormBindingData) {
|
||||
formProviderData.reset(data.ReadParcelable<FormProviderData>());
|
||||
}
|
||||
|
||||
ErrCode result = RequestPublishForm(*want, withFormBindingData, formProviderData);
|
||||
reply.WriteInt32(result);
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @brief handle LifecycleUpdate message.
|
||||
* @param data input param.
|
||||
|
||||
@@ -191,6 +191,34 @@ public:
|
||||
*/
|
||||
int SetNextRefreshTime(const int64_t formId, const int64_t 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 AddFormInfo(FormInfo &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 RemoveFormInfo(const std::string &moduleName, const std::string &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 RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData);
|
||||
|
||||
/**
|
||||
* @brief Lifecycle Update.
|
||||
* @param formIds The id of the forms.
|
||||
|
||||
@@ -299,6 +299,61 @@ 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__);
|
||||
ErrCode errCode = Connect();
|
||||
if (errCode != ERR_OK) {
|
||||
HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
|
||||
return errCode;
|
||||
}
|
||||
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__);
|
||||
ErrCode errCode = Connect();
|
||||
if (errCode != ERR_OK) {
|
||||
HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
|
||||
return errCode;
|
||||
}
|
||||
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)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
ErrCode errCode = Connect();
|
||||
if (errCode != ERR_OK) {
|
||||
HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
|
||||
return errCode;
|
||||
}
|
||||
return remoteProxy_->RequestPublishForm(want, withFormBindingData, formBindingData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Lifecycle Update.
|
||||
* @param formIds The id of the forms.
|
||||
|
||||
@@ -44,10 +44,16 @@ public:
|
||||
|
||||
ErrCode InitFromJson(const std::string &formInfoStoragesJson);
|
||||
|
||||
ErrCode Update(int32_t userId);
|
||||
ErrCode UpdateStaticFormInfos(int32_t userId);
|
||||
|
||||
ErrCode Remove(int32_t userId);
|
||||
|
||||
ErrCode AddDynamicFormInfo(const FormInfo &formInfo, int32_t userId);
|
||||
|
||||
ErrCode RemoveDynamicFormInfo(const std::string &moduleName, const std::string &formName, int32_t userId);
|
||||
|
||||
ErrCode RemoveAllDynamicFormsInfo(int32_t userId);
|
||||
|
||||
bool Empty();
|
||||
|
||||
ErrCode GetAllFormsInfo(std::vector<FormInfo> &formInfos);
|
||||
@@ -55,6 +61,8 @@ public:
|
||||
ErrCode GetFormsInfoByModule(const std::string &moduleName, std::vector<FormInfo> &formInfos);
|
||||
|
||||
private:
|
||||
ErrCode UpdateFormInfoStorageLocked();
|
||||
|
||||
std::string bundleName_ {};
|
||||
mutable std::shared_timed_mutex formInfosMutex_ {};
|
||||
std::vector<AAFwk::FormInfoStorage> formInfoStorages_ {};
|
||||
@@ -68,7 +76,7 @@ public:
|
||||
|
||||
ErrCode Start();
|
||||
|
||||
ErrCode Update(const std::string &bundleNamef, int32_t userId);
|
||||
ErrCode UpdateStaticFormInfos(const std::string &bundleName, int32_t userId);
|
||||
|
||||
ErrCode Remove(const std::string &bundleName, int32_t userId);
|
||||
|
||||
@@ -79,10 +87,18 @@ public:
|
||||
ErrCode GetFormsInfoByModule(const std::string &bundleName, const std::string &moduleName,
|
||||
std::vector<FormInfo> &formInfos);
|
||||
|
||||
ErrCode AddDynamicFormInfo(FormInfo &formInfo, int32_t userId);
|
||||
|
||||
ErrCode RemoveDynamicFormInfo(const std::string &bundleName, const std::string &moduleName,
|
||||
const std::string &formName, int32_t userId);
|
||||
|
||||
ErrCode RemoveAllDynamicFormsInfo(const std::string &bundleName, int32_t userId);
|
||||
|
||||
private:
|
||||
std::shared_ptr<BundleFormInfo> GetOrCreateBundleFromInfo(const std::string &bundleName);
|
||||
bool IsCaller(std::string bundleName);
|
||||
bool CheckBundlePermission();
|
||||
static bool IsCaller(std::string bundleName);
|
||||
static bool CheckBundlePermission();
|
||||
static ErrCode CheckDynamicFormInfo(FormInfo &formInfo, const BundleInfo &bundleInfo);
|
||||
|
||||
mutable std::shared_timed_mutex bundleFormInfoMapMutex_ {};
|
||||
std::unordered_map<std::string, std::shared_ptr<BundleFormInfo>> bundleFormInfoMap_ {};
|
||||
|
||||
@@ -146,6 +146,34 @@ public:
|
||||
*/
|
||||
int SetNextRefreshTime(const int64_t formId, const int64_t 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 AddFormInfo(FormInfo &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 RemoveFormInfo(const std::string &moduleName, const std::string &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 RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData);
|
||||
|
||||
/**
|
||||
* @brief enable update form.
|
||||
* @param formIDs The id of the forms.
|
||||
|
||||
@@ -96,6 +96,34 @@ public:
|
||||
*/
|
||||
int SetNextRefreshTime(const int64_t formId, const int64_t nextTime) override;
|
||||
|
||||
/**
|
||||
* @brief Add the form info.
|
||||
*
|
||||
* @param formInfo Indicates the form info to be added.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode AddFormInfo(FormInfo &formInfo) override;
|
||||
|
||||
/**
|
||||
* @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 RemoveFormInfo(const std::string &moduleName, const std::string &formName) override;
|
||||
|
||||
/**
|
||||
* @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 RequestPublishForm(Want &want, bool withFormBindingData,
|
||||
std::unique_ptr<FormProviderData> &formBindingData) override;
|
||||
|
||||
/**
|
||||
* @brief lifecycle update.
|
||||
* @param formIds formIds of hostclient.
|
||||
|
||||
@@ -56,7 +56,7 @@ private:
|
||||
void HandleBundleFormInfoChanged(const std::string &bundleName, int32_t userId);
|
||||
void HandleBundleFormInfoRemoved(const std::string &bundleName, int32_t userId);
|
||||
void HandleProviderRemoved(const std::string &bundleName, const int32_t userId);
|
||||
void HandleBundleDataCleared(const std::string &bundleName, const int uid);
|
||||
void HandleBundleDataCleared(const std::string &bundleName, int32_t userId);
|
||||
void HandleFormHostDataCleared(const int uid);
|
||||
void ClearFormDBRecordData(const int uid, std::map<int64_t, bool> &removedFormsMap);
|
||||
void ClearTempFormRecordData(const int uid, std::map<int64_t, bool> &removedFormsMap);
|
||||
|
||||
@@ -139,16 +139,16 @@ ErrCode BundleFormInfo::InitFromJson(const std::string &formInfoStoragesJson)
|
||||
return ERR_APPEXECFWK_PARSE_BAD_PROFILE;
|
||||
}
|
||||
std::unique_lock<std::shared_timed_mutex> guard(formInfosMutex_);
|
||||
std::vector<AAFwk::FormInfoStorage> formInfoStorages = jsonObject.get<std::vector<AAFwk::FormInfoStorage>>();
|
||||
auto formInfoStorages = jsonObject.get<std::vector<AAFwk::FormInfoStorage>>();
|
||||
for (const auto &item : formInfoStorages) {
|
||||
formInfoStorages_.push_back(item);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode BundleFormInfo::Update(int32_t userId)
|
||||
ErrCode BundleFormInfo::UpdateStaticFormInfos(int32_t userId)
|
||||
{
|
||||
HILOG_INFO("Update form infos, userId is %{public}d.", userId);
|
||||
HILOG_INFO("Update static form infos, userId is %{public}d.", userId);
|
||||
std::unique_lock<std::shared_timed_mutex> guard(formInfosMutex_);
|
||||
std::vector<FormInfo> formInfos;
|
||||
ErrCode errCode = FormInfoHelper::LoadFormConfigInfoByBundleName(bundleName_, formInfos, userId);
|
||||
@@ -157,31 +157,25 @@ ErrCode BundleFormInfo::Update(int32_t userId)
|
||||
}
|
||||
|
||||
for (auto item = formInfoStorages_.begin(); item != formInfoStorages_.end();) {
|
||||
if (item->userId == userId) {
|
||||
item = formInfoStorages_.erase(item);
|
||||
} else {
|
||||
if (item->userId != userId) {
|
||||
++item;
|
||||
continue;
|
||||
}
|
||||
for (auto &formInfo : item->formInfos) {
|
||||
if (formInfo.isStatic) {
|
||||
continue;
|
||||
}
|
||||
// add dynamic form info
|
||||
formInfos.push_back(formInfo);
|
||||
}
|
||||
item = formInfoStorages_.erase(item);
|
||||
}
|
||||
|
||||
if (!formInfos.empty()) {
|
||||
AAFwk::FormInfoStorage formInfoStorage(userId, formInfos);
|
||||
formInfoStorages_.push_back(formInfoStorage);
|
||||
formInfoStorages_.emplace_back(userId, formInfos);
|
||||
}
|
||||
|
||||
if (formInfoStorages_.empty()) {
|
||||
HILOG_INFO("form info Storages is empty.");
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
nlohmann::json jsonObject = formInfoStorages_;
|
||||
if (jsonObject.is_discarded()) {
|
||||
HILOG_ERROR("bad form infos.");
|
||||
return ERR_APPEXECFWK_PARSE_BAD_PROFILE;
|
||||
}
|
||||
std::string formInfoStoragesStr = jsonObject.dump(Constants::DUMP_INDENT);
|
||||
errCode = FormInfoStorageMgr::GetInstance().UpdateBundleFormInfos(bundleName_, formInfoStoragesStr);
|
||||
return errCode;
|
||||
return UpdateFormInfoStorageLocked();
|
||||
}
|
||||
|
||||
ErrCode BundleFormInfo::Remove(int32_t userId)
|
||||
@@ -195,21 +189,88 @@ ErrCode BundleFormInfo::Remove(int32_t userId)
|
||||
++item;
|
||||
}
|
||||
}
|
||||
return UpdateFormInfoStorageLocked();
|
||||
}
|
||||
|
||||
ErrCode errCode;
|
||||
if (formInfoStorages_.empty()) {
|
||||
errCode = FormInfoStorageMgr::GetInstance().RemoveBundleFormInfos(bundleName_);
|
||||
} else {
|
||||
nlohmann::json jsonObject = formInfoStorages_;
|
||||
if (jsonObject.is_discarded()) {
|
||||
HILOG_ERROR("bad form infos.");
|
||||
return ERR_APPEXECFWK_PARSE_BAD_PROFILE;
|
||||
ErrCode BundleFormInfo::AddDynamicFormInfo(const FormInfo &formInfo, int32_t userId)
|
||||
{
|
||||
HILOG_INFO("Add dynamic form info, userId is %{public}d.", userId);
|
||||
std::unique_lock<std::shared_timed_mutex> guard(formInfosMutex_);
|
||||
for (auto &formInfoStorage : formInfoStorages_) {
|
||||
if (formInfoStorage.userId != userId) {
|
||||
continue;
|
||||
}
|
||||
bool isSame = false;
|
||||
for (auto &item : formInfoStorage.formInfos) {
|
||||
if (item.name == formInfo.name && item.moduleName == formInfo.moduleName) {
|
||||
isSame = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::string formInfoStoragesStr = jsonObject.dump(Constants::DUMP_INDENT);
|
||||
errCode = FormInfoStorageMgr::GetInstance().UpdateBundleFormInfos(bundleName_, formInfoStoragesStr);
|
||||
}
|
||||
|
||||
return errCode;
|
||||
if (isSame) {
|
||||
HILOG_ERROR("The same form already exists");
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
formInfoStorage.formInfos.push_back(formInfo);
|
||||
return UpdateFormInfoStorageLocked();
|
||||
}
|
||||
// no match user id
|
||||
std::vector<FormInfo> formInfos;
|
||||
formInfos.push_back(formInfo);
|
||||
formInfoStorages_.emplace_back(userId, formInfos);
|
||||
return UpdateFormInfoStorageLocked();
|
||||
}
|
||||
|
||||
ErrCode BundleFormInfo::RemoveDynamicFormInfo(const std::string &moduleName, const std::string &formName,
|
||||
int32_t userId)
|
||||
{
|
||||
HILOG_INFO("remove dynamic form info, userId is %{public}d.", userId);
|
||||
std::unique_lock<std::shared_timed_mutex> guard(formInfosMutex_);
|
||||
for (auto &formInfoStorage : formInfoStorages_) {
|
||||
if (formInfoStorage.userId != userId) {
|
||||
continue;
|
||||
}
|
||||
for (auto item = formInfoStorage.formInfos.begin(); item != formInfoStorage.formInfos.end();) {
|
||||
if (item->name != formName || item->moduleName != moduleName) {
|
||||
++item;
|
||||
continue;
|
||||
}
|
||||
// form found
|
||||
if (item->isStatic) {
|
||||
HILOG_ERROR("The specified form info is static, can not be removed.");
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
item = formInfoStorage.formInfos.erase(item);
|
||||
return UpdateFormInfoStorageLocked();
|
||||
}
|
||||
}
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ErrCode BundleFormInfo::RemoveAllDynamicFormsInfo(int32_t userId)
|
||||
{
|
||||
HILOG_INFO("remove all dynamic forms info, userId is %{public}d.", userId);
|
||||
std::unique_lock<std::shared_timed_mutex> guard(formInfosMutex_);
|
||||
int32_t numRemoved = 0;
|
||||
for (auto &formInfoStorage : formInfoStorages_) {
|
||||
if (formInfoStorage.userId != userId) {
|
||||
continue;
|
||||
}
|
||||
for (auto item = formInfoStorage.formInfos.begin(); item != formInfoStorage.formInfos.end();) {
|
||||
if (!item->isStatic) {
|
||||
item = formInfoStorage.formInfos.erase(item);
|
||||
} else {
|
||||
++item;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (numRemoved > 0) {
|
||||
HILOG_ERROR("%{public}d dynamic forms info removed.", numRemoved);
|
||||
return UpdateFormInfoStorageLocked();
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
bool BundleFormInfo::Empty()
|
||||
@@ -239,6 +300,23 @@ ErrCode BundleFormInfo::GetFormsInfoByModule(const std::string &moduleName, std:
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode BundleFormInfo::UpdateFormInfoStorageLocked()
|
||||
{
|
||||
ErrCode errCode;
|
||||
if (formInfoStorages_.empty()) {
|
||||
errCode = FormInfoStorageMgr::GetInstance().RemoveBundleFormInfos(bundleName_);
|
||||
} else {
|
||||
nlohmann::json jsonObject = formInfoStorages_;
|
||||
if (jsonObject.is_discarded()) {
|
||||
HILOG_ERROR("bad form infos.");
|
||||
return ERR_APPEXECFWK_PARSE_BAD_PROFILE;
|
||||
}
|
||||
std::string formInfoStoragesStr = jsonObject.dump(Constants::DUMP_INDENT);
|
||||
errCode = FormInfoStorageMgr::GetInstance().UpdateBundleFormInfos(bundleName_, formInfoStoragesStr);
|
||||
}
|
||||
return errCode;
|
||||
}
|
||||
|
||||
FormInfoMgr::FormInfoMgr()
|
||||
{
|
||||
HILOG_INFO("FormInfoMgr is created");
|
||||
@@ -271,7 +349,7 @@ ErrCode FormInfoMgr::Start()
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode FormInfoMgr::Update(const std::string &bundleName, int32_t userId)
|
||||
ErrCode FormInfoMgr::UpdateStaticFormInfos(const std::string &bundleName, int32_t userId)
|
||||
{
|
||||
if (bundleName.empty()) {
|
||||
HILOG_ERROR("bundleName is empty.");
|
||||
@@ -279,6 +357,7 @@ ErrCode FormInfoMgr::Update(const std::string &bundleName, int32_t userId)
|
||||
}
|
||||
|
||||
std::shared_ptr<BundleFormInfo> bundleFormInfoPtr;
|
||||
std::unique_lock<std::shared_timed_mutex> guard(bundleFormInfoMapMutex_);
|
||||
auto search = bundleFormInfoMap_.find(bundleName);
|
||||
if (search != bundleFormInfoMap_.end()) {
|
||||
bundleFormInfoPtr = search->second;
|
||||
@@ -286,7 +365,7 @@ ErrCode FormInfoMgr::Update(const std::string &bundleName, int32_t userId)
|
||||
bundleFormInfoPtr = std::make_shared<BundleFormInfo>(bundleName);
|
||||
}
|
||||
|
||||
ErrCode errCode = bundleFormInfoPtr->Update(userId);
|
||||
ErrCode errCode = bundleFormInfoPtr->UpdateStaticFormInfos(userId);
|
||||
if (errCode != ERR_OK) {
|
||||
return errCode;
|
||||
}
|
||||
@@ -296,7 +375,6 @@ ErrCode FormInfoMgr::Update(const std::string &bundleName, int32_t userId)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
std::unique_lock<std::shared_timed_mutex> guard(bundleFormInfoMapMutex_);
|
||||
bundleFormInfoMap_[bundleName] = bundleFormInfoPtr;
|
||||
HILOG_ERROR("update forms info success, bundleName=%{public}s.", bundleName.c_str());
|
||||
return ERR_OK;
|
||||
@@ -400,6 +478,91 @@ ErrCode FormInfoMgr::GetFormsInfoByModule(const std::string &bundleName, const s
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode FormInfoMgr::CheckDynamicFormInfo(FormInfo &formInfo, const BundleInfo &bundleInfo)
|
||||
{
|
||||
for (auto &moduleInfo : bundleInfo.hapModuleInfos) {
|
||||
if (formInfo.moduleName != moduleInfo.moduleName) {
|
||||
continue;
|
||||
}
|
||||
for (auto &abilityInfo : moduleInfo.abilityInfos) {
|
||||
if (formInfo.abilityName != abilityInfo.name) {
|
||||
continue;
|
||||
}
|
||||
formInfo.src = "";
|
||||
return ERR_OK;
|
||||
}
|
||||
for (auto &extensionInfos : moduleInfo.extensionInfos) {
|
||||
if (formInfo.abilityName != extensionInfos.name) {
|
||||
continue;
|
||||
}
|
||||
formInfo.src = "./js/" + formInfo.name + "/pages/index/index";
|
||||
return ERR_OK;
|
||||
}
|
||||
HILOG_ERROR("No match abilityName found");
|
||||
return ERR_APPEXECFWK_FORM_NO_SUCH_ABILITY;
|
||||
}
|
||||
|
||||
HILOG_ERROR("No match moduleName found");
|
||||
return ERR_APPEXECFWK_FORM_NO_SUCH_MODULE;
|
||||
}
|
||||
|
||||
ErrCode FormInfoMgr::AddDynamicFormInfo(FormInfo &formInfo, int32_t userId)
|
||||
{
|
||||
sptr<IBundleMgr> iBundleMgr = FormBmsHelper::GetInstance().GetBundleMgr();
|
||||
if (iBundleMgr == nullptr) {
|
||||
HILOG_ERROR("GetBundleMgr, failed to get IBundleMgr.");
|
||||
return ERR_APPEXECFWK_FORM_GET_BMS_FAILED;
|
||||
}
|
||||
|
||||
BundleInfo bundleInfo;
|
||||
int32_t flag = GET_BUNDLE_WITH_EXTENSION_INFO | GET_BUNDLE_WITH_ABILITIES;
|
||||
if (!IN_PROCESS_CALL(iBundleMgr->GetBundleInfo(formInfo.bundleName, flag, bundleInfo, userId))) {
|
||||
HILOG_ERROR("failed to get bundle info.");
|
||||
return ERR_APPEXECFWK_FORM_GET_INFO_FAILED;
|
||||
}
|
||||
|
||||
ErrCode errCode = CheckDynamicFormInfo(formInfo, bundleInfo);
|
||||
if (errCode != ERR_OK) {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
std::unique_lock<std::shared_timed_mutex> guard(bundleFormInfoMapMutex_);
|
||||
auto bundleFormInfoIter = bundleFormInfoMap_.find(formInfo.bundleName);
|
||||
std::shared_ptr<BundleFormInfo> bundleFormInfoPtr;
|
||||
if (bundleFormInfoIter != bundleFormInfoMap_.end()) {
|
||||
bundleFormInfoPtr = bundleFormInfoIter->second;
|
||||
} else {
|
||||
bundleFormInfoPtr = std::make_shared<BundleFormInfo>(formInfo.bundleName);
|
||||
}
|
||||
|
||||
return bundleFormInfoPtr->AddDynamicFormInfo(formInfo, userId);
|
||||
}
|
||||
|
||||
ErrCode FormInfoMgr::RemoveDynamicFormInfo(const std::string &bundleName, const std::string &moduleName,
|
||||
const std::string &formName, int32_t userId)
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex> guard(bundleFormInfoMapMutex_);
|
||||
auto bundleFormInfoIter = bundleFormInfoMap_.find(bundleName);
|
||||
if (bundleFormInfoIter == bundleFormInfoMap_.end()) {
|
||||
HILOG_ERROR("no forms found in bundle %{public}s.", bundleName.c_str());
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
return bundleFormInfoIter->second->RemoveDynamicFormInfo(moduleName, formName, userId);
|
||||
}
|
||||
|
||||
ErrCode FormInfoMgr::RemoveAllDynamicFormsInfo(const std::string &bundleName, int32_t userId)
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex> guard(bundleFormInfoMapMutex_);
|
||||
auto bundleFormInfoIter = bundleFormInfoMap_.find(bundleName);
|
||||
if (bundleFormInfoIter == bundleFormInfoMap_.end()) {
|
||||
HILOG_ERROR("no forms found in bundle %{public}s.", bundleName.c_str());
|
||||
return ERR_APPEXECFWK_FORM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
return bundleFormInfoIter->second->RemoveAllDynamicFormsInfo(userId);
|
||||
}
|
||||
|
||||
std::shared_ptr<BundleFormInfo> FormInfoMgr::GetOrCreateBundleFromInfo(const std::string &bundleName)
|
||||
{
|
||||
{
|
||||
|
||||
@@ -1293,6 +1293,67 @@ 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;
|
||||
if (!GetBundleName(bundleName)) {
|
||||
return ERR_APPEXECFWK_FORM_GET_BUNDLE_FAILED;
|
||||
}
|
||||
if (formInfo.bundleName != bundleName) {
|
||||
HILOG_WARN("The bundleName in formInfo does not match the bundleName of current calling user.");
|
||||
formInfo.bundleName = bundleName;
|
||||
}
|
||||
if (formInfo.isStatic) {
|
||||
HILOG_WARN("Only dynamic forms can be added.");
|
||||
formInfo.isStatic = false;
|
||||
}
|
||||
|
||||
int32_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
int32_t userId = GetCurrentUserId(callingUid);
|
||||
|
||||
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;
|
||||
if (!GetBundleName(bundleName)) {
|
||||
return ERR_APPEXECFWK_FORM_GET_BUNDLE_FAILED;
|
||||
}
|
||||
|
||||
int32_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
int32_t userId = GetCurrentUserId(callingUid);
|
||||
|
||||
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)
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get bundleName.
|
||||
* @param bundleName for output.
|
||||
|
||||
@@ -191,6 +191,48 @@ 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__);
|
||||
|
||||
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__);
|
||||
|
||||
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)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
|
||||
return FormMgrAdapter::GetInstance().RequestPublishForm(want, withFormBindingData, formBindingData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Form visible/invisible notify, send formIds to form manager service.
|
||||
|
||||
@@ -92,13 +92,7 @@ void FormSysEventReceiver::OnReceiveEvent(const EventFwk::CommonEventData &event
|
||||
} else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED) {
|
||||
auto task = [this, want, bundleName]() {
|
||||
int userId = want.GetIntParam(KEY_USER_ID, 0);
|
||||
sptr<IBundleMgr> iBundleMgr = FormBmsHelper::GetInstance().GetBundleMgr();
|
||||
if (iBundleMgr == nullptr) {
|
||||
HILOG_ERROR("%{public}s error, failed to get IBundleMgr.", __func__);
|
||||
return;
|
||||
}
|
||||
int uid = IN_PROCESS_CALL(iBundleMgr->GetUidByBundleName(bundleName, userId));
|
||||
HandleBundleDataCleared(bundleName, uid);
|
||||
HandleBundleDataCleared(bundleName, userId);
|
||||
};
|
||||
eventHandler_->PostTask(task);
|
||||
} else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED) {
|
||||
@@ -243,7 +237,7 @@ bool FormSysEventReceiver::ProviderFormUpdated(const int64_t formId,
|
||||
|
||||
void FormSysEventReceiver::HandleBundleFormInfoChanged(const std::string &bundleName, int32_t userId)
|
||||
{
|
||||
FormInfoMgr::GetInstance().Update(bundleName, userId);
|
||||
FormInfoMgr::GetInstance().UpdateStaticFormInfos(bundleName, userId);
|
||||
}
|
||||
|
||||
void FormSysEventReceiver::HandleBundleFormInfoRemoved(const std::string &bundleName, int32_t userId)
|
||||
@@ -251,9 +245,12 @@ void FormSysEventReceiver::HandleBundleFormInfoRemoved(const std::string &bundle
|
||||
FormInfoMgr::GetInstance().Remove(bundleName, userId);
|
||||
}
|
||||
|
||||
void FormSysEventReceiver::HandleBundleDataCleared(const std::string &bundleName, const int uid)
|
||||
void FormSysEventReceiver::HandleBundleDataCleared(const std::string &bundleName, int32_t userId)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s, bundleName:%{public}s, uid:%{public}d", __func__, bundleName.c_str(), uid);
|
||||
HILOG_DEBUG("%{public}s, bundleName:%{public}s, userId:%{public}d", __func__, bundleName.c_str(), userId);
|
||||
// clear dynamic form info
|
||||
FormInfoMgr::GetInstance().RemoveAllDynamicFormsInfo(bundleName, userId);
|
||||
|
||||
// as provider data is cleared
|
||||
std::set<int64_t> reCreateForms;
|
||||
FormDataMgr::GetInstance().GetReCreateFormRecordsByBundleName(bundleName, reCreateForms);
|
||||
@@ -263,6 +260,13 @@ void FormSysEventReceiver::HandleBundleDataCleared(const std::string &bundleName
|
||||
}
|
||||
}
|
||||
|
||||
sptr<IBundleMgr> iBundleMgr = FormBmsHelper::GetInstance().GetBundleMgr();
|
||||
if (iBundleMgr == nullptr) {
|
||||
HILOG_ERROR("%{public}s error, failed to get IBundleMgr.", __func__);
|
||||
return;
|
||||
}
|
||||
int uid = IN_PROCESS_CALL(iBundleMgr->GetUidByBundleName(bundleName, userId));
|
||||
|
||||
// as form host data is cleared
|
||||
HandleFormHostDataCleared(uid);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user