mirror of
https://github.com/openharmony/ace_ace_engine.git
synced 2026-07-18 20:54:27 -04:00
FA卡片能力补齐需求回合
Signed-off-by: liweifeng <liweifeng2@huawei.com> Change-Id: I8a60a6ca07ef4c5f70b310eab7ad63204f3b1e1f
This commit is contained in:
@@ -142,6 +142,17 @@ void AceFormAbility::OnTriggerEvent(const int64_t formId, const std::string& mes
|
||||
Platform::PaContainer::OnTriggerEvent(instanceId_, formId, message);
|
||||
}
|
||||
|
||||
AppExecFwk::FormState AceFormAbility::OnAcquireFormState(const OHOS::AAFwk::Want &want)
|
||||
{
|
||||
LOGI("AceFormAbility::OnAcquireState called");
|
||||
int32_t formState = Platform::PaContainer::OnAcquireFormState(instanceId_, want);
|
||||
if (formState <= (int32_t) AppExecFwk::FormState::UNKNOWN || formState > (int32_t) AppExecFwk::FormState::READY) {
|
||||
return AppExecFwk::FormState::UNKNOWN;
|
||||
} else {
|
||||
return (AppExecFwk::FormState) formState;
|
||||
}
|
||||
}
|
||||
|
||||
void AceFormAbility::OnUpdate(const int64_t formId)
|
||||
{
|
||||
LOGI("AceFormAbility::OnUpdate called: %{public}s", std::to_string(formId).c_str());
|
||||
|
||||
@@ -69,6 +69,14 @@ public:
|
||||
*/
|
||||
virtual void OnTriggerEvent(const int64_t formId, const std::string& message) override;
|
||||
|
||||
/**
|
||||
* @brief Called to notify the form supplier to acquire form state.
|
||||
*
|
||||
* @param want Indicates the detailed information about the form to be obtained, including
|
||||
* the bundle name, module name, ability name, form name and form dimension.
|
||||
*/
|
||||
virtual AppExecFwk::FormState OnAcquireFormState(const OHOS::AAFwk::Want& want) override;
|
||||
|
||||
/**
|
||||
* @brief Called to notify the form provider to update a specified form.
|
||||
*
|
||||
|
||||
@@ -199,6 +199,29 @@ bool PaContainer::OnTriggerEvent(int32_t instanceId, int64_t formId, const std::
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t PaContainer::OnAcquireFormState(int32_t instanceId, const OHOS::AAFwk::Want& want)
|
||||
{
|
||||
LOGI("PA: PaContainer::OnAcquireFormState start");
|
||||
auto container = AceEngine::Get().GetContainer(instanceId);
|
||||
if (!container) {
|
||||
LOGE("PA: container is nullptr");
|
||||
return -1;
|
||||
}
|
||||
auto aceContainer = AceType::DynamicCast<PaContainer>(container);
|
||||
if (!aceContainer) {
|
||||
LOGE("PA: aceContainer is nullptr");
|
||||
return -1;
|
||||
}
|
||||
auto paBackend = AceType::DynamicCast<PaBackend>(aceContainer->GetBackend());
|
||||
if (!paBackend) {
|
||||
LOGE("PA: paBackend is nullptr");
|
||||
return -1;
|
||||
}
|
||||
int32_t formState = paBackend->OnAcquireFormState(want);
|
||||
LOGI("PA: PaContainer::OnAcquireFormState end");
|
||||
return formState;
|
||||
}
|
||||
|
||||
bool PaContainer::OnUpdate(int32_t instanceId, int64_t formId)
|
||||
{
|
||||
LOGI("PA: PaContainer::OnUpdate start");
|
||||
|
||||
@@ -132,6 +132,7 @@ public:
|
||||
static bool OnCreate(int32_t instanceId, const OHOS::AAFwk::Want& want);
|
||||
static bool OnDelete(int32_t instanceId, int64_t formId);
|
||||
static bool OnTriggerEvent(int32_t instanceId, int64_t formId, const std::string& message);
|
||||
static int32_t OnAcquireFormState(int32_t instanceId, const OHOS::AAFwk::Want& want);
|
||||
static bool OnUpdate(int32_t instanceId, int64_t formId);
|
||||
static bool OnCastTemptoNormal(int32_t instanceId, int64_t formId);
|
||||
static bool OnVisibilityChanged(int32_t instanceId, const std::map<int64_t, int32_t>& formEventsMap);
|
||||
|
||||
@@ -459,10 +459,13 @@ void BackendDelegateImpl::OnVisibilityChanged(const std::map<int64_t, int32_t>&
|
||||
TaskExecutor::TaskType::JS);
|
||||
}
|
||||
|
||||
void BackendDelegateImpl::OnAcquireState(const OHOS::AAFwk::Want& want)
|
||||
int32_t BackendDelegateImpl::OnAcquireFormState(const OHOS::AAFwk::Want &want)
|
||||
{
|
||||
taskExecutor_->PostTask([acquireStateCallback = acquireStateCallback_, want] { acquireStateCallback(want); },
|
||||
auto ret = (int32_t) AppExecFwk::FormState::UNKNOWN;
|
||||
taskExecutor_->PostSyncTask(
|
||||
[acquireStateCallback = acquireStateCallback_, &ret, want] { ret = acquireStateCallback(want); },
|
||||
TaskExecutor::TaskType::JS);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void BackendDelegateImpl::OnCommand(const OHOS::AAFwk::Want &want, int startId)
|
||||
|
||||
@@ -63,7 +63,7 @@ using TriggerEventCallback = std::function<void(const int64_t formId, const std:
|
||||
using UpdateFormCallback = std::function<void(const int64_t formId)>;
|
||||
using CastTemptoNormalCallback = std::function<void(const int64_t formId)>;
|
||||
using VisibilityChangedCallback = std::function<void(const std::map<int64_t, int32_t>& formEventsMap)>;
|
||||
using AcquireStateCallback = std::function<void(const OHOS::AAFwk::Want &want)>;
|
||||
using AcquireStateCallback = std::function<int32_t(const OHOS::AAFwk::Want &want)>;
|
||||
using CommandCallback = std::function<void(const OHOS::AAFwk::Want &want, int startId)>;
|
||||
using CommandApplicationCallback = std::function<void(const std::string& intent, int startId)>;
|
||||
|
||||
@@ -184,7 +184,7 @@ public:
|
||||
void OnUpdate(const int64_t formId);
|
||||
void OnCastTemptoNormal(const int64_t formId);
|
||||
void OnVisibilityChanged(const std::map<int64_t, int32_t>& formEventsMap);
|
||||
void OnAcquireState(const OHOS::AAFwk::Want& want);
|
||||
int32_t OnAcquireFormState(const OHOS::AAFwk::Want& want);
|
||||
|
||||
private:
|
||||
void LoadPa(const std::string& url, const OHOS::AAFwk::Want& want);
|
||||
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
virtual void OnUpdate(const int64_t formId) = 0;
|
||||
virtual void OnCastTemptoNormal(const int64_t formId) = 0;
|
||||
virtual void OnVisibilityChanged(const std::map<int64_t, int32_t>& formEventsMap) = 0;
|
||||
virtual void OnAcquireState(const OHOS::AAFwk::Want &want) = 0;
|
||||
virtual int32_t OnAcquireFormState(const OHOS::AAFwk::Want &want) = 0;
|
||||
virtual void OnCommand(const OHOS::AAFwk::Want &want, int startId) = 0;
|
||||
|
||||
void SetFormData(const AppExecFwk::FormProviderData &formProviderData)
|
||||
|
||||
@@ -1539,12 +1539,35 @@ void JsiPaEngine::OnVisibilityChanged(const std::map<int64_t, int32_t>& formEven
|
||||
CallFunc(func, argv);
|
||||
}
|
||||
|
||||
void JsiPaEngine::OnAcquireState(const OHOS::AAFwk::Want &want)
|
||||
int32_t JsiPaEngine::OnAcquireFormState(const OHOS::AAFwk::Want &want)
|
||||
{
|
||||
LOGI("JsiPaEngine OnAcquireState");
|
||||
LOGI("JsiPaEngine OnAcquireFormState");
|
||||
ACE_DCHECK(engineInstance_);
|
||||
shared_ptr<JsRuntime> runtime = engineInstance_->GetJsRuntime();
|
||||
|
||||
const std::vector<shared_ptr<JsValue>>& argv = { WantToJsValue(want) };
|
||||
auto func = GetPaFunc("onAcquireState");
|
||||
CallFunc(func, argv);
|
||||
auto func = GetPaFunc("onAcquireFormState");
|
||||
|
||||
if (func == nullptr) {
|
||||
LOGI("no OnAcquireFormState!");
|
||||
return (int32_t)AppExecFwk::FormState::DEFAULT;
|
||||
}
|
||||
|
||||
auto result = CallFunc(func, argv);
|
||||
auto arkJSValue = std::static_pointer_cast<ArkJSValue>(result);
|
||||
if (arkJSValue->IsException(runtime)) {
|
||||
LOGE("JsiPaEngine CallFunc FAILED!");
|
||||
return (int32_t)AppExecFwk::FormState::DEFAULT;
|
||||
}
|
||||
|
||||
if (!arkJSValue->IsInt32(runtime)) {
|
||||
LOGE("invalid return value!");
|
||||
return (int32_t)AppExecFwk::FormState::DEFAULT;
|
||||
}
|
||||
|
||||
int32_t formState = arkJSValue->ToInt32(runtime);
|
||||
LOGI("JsiPaEngine OnAcquireFormState, formState: %{public}d", formState);
|
||||
return formState;
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
@@ -162,7 +162,7 @@ public:
|
||||
void OnUpdate(const int64_t formId) override;
|
||||
void OnCastTemptoNormal(const int64_t formId) override;
|
||||
void OnVisibilityChanged(const std::map<int64_t, int32_t>& formEventsMap) override;
|
||||
void OnAcquireState(const OHOS::AAFwk::Want &want) override;
|
||||
int32_t OnAcquireFormState(const OHOS::AAFwk::Want &want) override;
|
||||
|
||||
private:
|
||||
void SetPostTask(NativeEngine* nativeEngine);
|
||||
|
||||
@@ -1481,14 +1481,18 @@ void QjsPaEngine::OnVisibilityChanged(const std::map<int64_t, int32_t>& formEven
|
||||
return;
|
||||
}
|
||||
|
||||
void QjsPaEngine::OnAcquireState(const OHOS::AAFwk::Want& want)
|
||||
int32_t QjsPaEngine::OnAcquireFormState(const OHOS::AAFwk::Want& want)
|
||||
{
|
||||
LOGI("PA: QjsPaEngine OnAcquireState");
|
||||
LOGI("PA: QjsPaEngine OnAcquireFormState");
|
||||
JSContext* ctx = engineInstance_->GetQjsContext();
|
||||
ACE_DCHECK(ctx);
|
||||
|
||||
Framework::QJSHandleScope handleScope(ctx);
|
||||
JSValue paFunc = GetPaFunc("onAcquireState");
|
||||
JSValue paFunc = GetPaFunc("onAcquireFormState");
|
||||
if (JS_IsUndefined(paFunc)) {
|
||||
LOGI("no OnAcquireFormState!");
|
||||
return (int32_t)AppExecFwk::FormState::DEFAULT;
|
||||
}
|
||||
|
||||
napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast<napi_env>(nativeEngine_), want);
|
||||
NativeValue* nativeWant = reinterpret_cast<NativeValue*>(napiWant);
|
||||
@@ -1496,10 +1500,18 @@ void QjsPaEngine::OnAcquireState(const OHOS::AAFwk::Want& want)
|
||||
JSValueConst argv[] = { jsWant };
|
||||
JSValue retVal = Framework::QJSUtils::Call(ctx, paFunc, JS_UNDEFINED, countof(argv), argv);
|
||||
if (JS_IsException(retVal)) {
|
||||
LOGE("PA: OnAcquireState FAILED!");
|
||||
return;
|
||||
LOGE("PA: OnAcquireFormState FAILED!");
|
||||
return (int32_t)AppExecFwk::FormState::DEFAULT;
|
||||
}
|
||||
return;
|
||||
|
||||
if (!JS_IsNumber(retVal)) {
|
||||
LOGE("invalid return value!");
|
||||
return (int32_t)AppExecFwk::FormState::DEFAULT;
|
||||
}
|
||||
|
||||
int32_t formState = GetJsInt32Val(ctx, retVal);
|
||||
LOGI("JsiPaEngine OnAcquireFormState, formState: %{public}d", formState);
|
||||
return formState;
|
||||
}
|
||||
|
||||
void QjsPaEngine::OnCommand(const OHOS::AAFwk::Want &want, int startId)
|
||||
|
||||
@@ -171,7 +171,7 @@ public:
|
||||
void OnUpdate(const int64_t formId) override;
|
||||
void OnCastTemptoNormal(const int64_t formId) override;
|
||||
void OnVisibilityChanged(const std::map<int64_t, int32_t>& formEventsMap) override;
|
||||
void OnAcquireState(const OHOS::AAFwk::Want &want) override;
|
||||
int32_t OnAcquireFormState(const OHOS::AAFwk::Want &want) override;
|
||||
void OnCommand(const OHOS::AAFwk::Want &want, int startId) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -296,12 +296,12 @@ void PaBackend::InitializeBackendDelegate(const RefPtr<TaskExecutor>& taskExecut
|
||||
};
|
||||
|
||||
builder.acquireStateCallback = [weakEngine = WeakPtr<JsBackendEngine>(jsBackendEngine_)](
|
||||
const OHOS::AAFwk::Want& want) {
|
||||
const OHOS::AAFwk::Want& want) -> int32_t {
|
||||
auto jsBackendEngine = weakEngine.Upgrade();
|
||||
if (!jsBackendEngine) {
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
jsBackendEngine->OnAcquireState(want);
|
||||
return jsBackendEngine->OnAcquireFormState(want);
|
||||
};
|
||||
|
||||
builder.commandApplicationCallback = [weakEngine = WeakPtr<JsBackendEngine>(jsBackendEngine_)](
|
||||
@@ -494,9 +494,9 @@ void PaBackend::OnVisibilityChanged(const std::map<int64_t, int32_t>& formEvents
|
||||
delegate_->OnVisibilityChanged(formEventsMap);
|
||||
}
|
||||
|
||||
void PaBackend::OnAcquireState(const OHOS::AAFwk::Want& want)
|
||||
int32_t PaBackend::OnAcquireFormState(const OHOS::AAFwk::Want& want)
|
||||
{
|
||||
delegate_->OnAcquireState(want);
|
||||
return delegate_->OnAcquireFormState(want);
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> PaBackend::OnConnect(const OHOS::AAFwk::Want& want)
|
||||
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
void OnUpdate(const int64_t formId);
|
||||
void OnCastTemptoNormal(const int64_t formId);
|
||||
void OnVisibilityChanged(const std::map<int64_t, int32_t>& formEventsMap);
|
||||
void OnAcquireState(const OHOS::AAFwk::Want& want);
|
||||
int32_t OnAcquireFormState(const OHOS::AAFwk::Want& want);
|
||||
sptr<IRemoteObject> OnConnect(const OHOS::AAFwk::Want& want);
|
||||
void OnDisConnect(const OHOS::AAFwk::Want& want);
|
||||
|
||||
|
||||
@@ -337,7 +337,7 @@ void FormElement::OnActionEvent(const std::string& action) const
|
||||
auto context = GetContext().Upgrade();
|
||||
if (context) {
|
||||
LOGI("send action evetn to ability to process");
|
||||
context->OnActionEvent(action);
|
||||
context->OnActionEvent(formManagerBridge_->WrapAction(action));
|
||||
}
|
||||
#else
|
||||
HandleOnRouterEvent(eventAction);
|
||||
|
||||
@@ -406,6 +406,15 @@ void FormManagerDelegate::OnDeathReceived()
|
||||
LOGE("relink to form manager fail!!!");
|
||||
}
|
||||
}
|
||||
std::string FormManagerDelegate::WrapAction(const std::string& action)
|
||||
{
|
||||
auto eventAction = JsonUtil::ParseJsonString(action);
|
||||
if (!eventAction->Contains("bundleName")) {
|
||||
eventAction->Put("bundleName", wantCache_.GetElement().GetBundleName().c_str());
|
||||
}
|
||||
auto newAction = eventAction->ToString();
|
||||
OHOS::AppExecFwk::FormMgr::GetInstance().UpdateRouterAction(runningCardId_, newAction);
|
||||
return newAction;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
@@ -68,6 +68,7 @@ public:
|
||||
|
||||
void OnActionEvent(const std::string& action);
|
||||
|
||||
std::string WrapAction(const std::string& action);
|
||||
#ifdef OHOS_STANDARD_SYSTEM
|
||||
void ProcessFormUpdate(const AppExecFwk::FormJsInfo &formJsInfo);
|
||||
void ProcessFormUninstall(const int64_t formId);
|
||||
|
||||
Reference in New Issue
Block a user