mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-12-04 05:29:08 +00:00
!148 support onCommand for Pa
Merge pull request !148 from zero-cyc/cherry-pick-1631957928
This commit is contained in:
commit
9c483d8ce9
@ -131,5 +131,13 @@ void AceServiceAbility::OnDisconnect(const Want &want)
|
||||
LOGI("AceServiceAbility::OnDisconnect end");
|
||||
}
|
||||
|
||||
void AceServiceAbility::OnCommand(const AAFwk::Want &want, bool restart, int startId)
|
||||
{
|
||||
LOGI("AceServiceAbility::OnCommand start");
|
||||
Ability::OnCommand(want, restart, startId);
|
||||
Platform::PaContainer::OnCommand(want, startId, abilityId_);
|
||||
LOGI("AceServiceAbility::OnCommand end");
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace OHOS::Ace
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
void OnStop() override;
|
||||
sptr<IRemoteObject> OnConnect(const OHOS::AAFwk::Want &want) override;
|
||||
void OnDisconnect(const OHOS::AAFwk::Want &want) override;
|
||||
void OnCommand(const AAFwk::Want &want, bool restart, int startId) override;
|
||||
|
||||
private:
|
||||
int32_t abilityId_ = 100000;
|
||||
|
@ -533,7 +533,7 @@ sptr<IRemoteObject> PaContainer::OnConnect(int32_t instanceId, const OHOS::AAFwk
|
||||
LOGI("OnConnect with id %{private}d", instanceId);
|
||||
auto container = AceEngine::Get().GetContainer(instanceId);
|
||||
if (!container) {
|
||||
LOGE("no AceContainer with id %{private}d", instanceId);
|
||||
LOGE("no pa container with id %{private}d", instanceId);
|
||||
return nullptr;
|
||||
}
|
||||
auto aceContainer = AceType::DynamicCast<PaContainer>(container);
|
||||
@ -554,7 +554,7 @@ void PaContainer::OnDisConnect(int32_t instanceId, const OHOS::AAFwk::Want &want
|
||||
LOGI("OnDisConnect with id %{private}d", instanceId);
|
||||
auto container = AceEngine::Get().GetContainer(instanceId);
|
||||
if (!container) {
|
||||
LOGE("no AceContainer with id %{private}d", instanceId);
|
||||
LOGE("no pa container with id %{private}d", instanceId);
|
||||
return;
|
||||
}
|
||||
auto aceContainer = AceType::DynamicCast<PaContainer>(container);
|
||||
@ -569,4 +569,24 @@ void PaContainer::OnDisConnect(int32_t instanceId, const OHOS::AAFwk::Want &want
|
||||
}
|
||||
}
|
||||
|
||||
void PaContainer::OnCommand(const OHOS::AAFwk::Want &want, int startId, int32_t instanceId)
|
||||
{
|
||||
LOGI("OnCommand with id %{private}d", instanceId);
|
||||
auto container = AceEngine::Get().GetContainer(instanceId);
|
||||
if (!container) {
|
||||
LOGE("no pa container with id %{private}d", instanceId);
|
||||
return;
|
||||
}
|
||||
auto aceContainer = AceType::DynamicCast<PaContainer>(container);
|
||||
auto back = aceContainer->GetBackend();
|
||||
if (back) {
|
||||
auto paBackend = AceType::DynamicCast<PaBackend>(back);
|
||||
if (paBackend == nullptr) {
|
||||
LOGE("DynamicCast paBackend failed with id %{private}d", instanceId);
|
||||
return;
|
||||
}
|
||||
paBackend->OnCommand(want, startId);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::Platform
|
||||
|
@ -149,6 +149,7 @@ public:
|
||||
static sptr<IRemoteObject> OnConnect(int32_t instanceId, const OHOS::AAFwk::Want &want);
|
||||
static void OnDisConnect(int32_t instanceId, const OHOS::AAFwk::Want &want);
|
||||
static AppExecFwk::FormProviderData GetFormData(int32_t formId);
|
||||
static void OnCommand(const OHOS::AAFwk::Want &want, int startId, int32_t instanceId);
|
||||
|
||||
private:
|
||||
void InitializeBackend();
|
||||
|
@ -58,7 +58,7 @@ BackendDelegateImpl::BackendDelegateImpl(const BackendDelegateImplBuilder &build
|
||||
castTemptoNormalCallback_(builder.castTemptoNormalCallback),
|
||||
visibilityChangedCallback_(builder.visibilityChangedCallback),
|
||||
acquireStateCallback_(builder.acquireStateCallback),
|
||||
|
||||
commandCallback_(builder.commandCallback),
|
||||
manifestParser_(AceType::MakeRefPtr<ManifestParser>()),
|
||||
ability_(builder.ability),
|
||||
type_(builder.type),
|
||||
@ -385,4 +385,10 @@ void BackendDelegateImpl::OnAcquireState(const OHOS::AAFwk::Want &want)
|
||||
TaskExecutor::TaskType::JS);
|
||||
}
|
||||
|
||||
void BackendDelegateImpl::OnCommand(const OHOS::AAFwk::Want &want, int startId)
|
||||
{
|
||||
taskExecutor_->PostTask([commandCallback = commandCallback_, want, startId] { commandCallback(want, startId); },
|
||||
TaskExecutor::TaskType::JS);
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::Framework
|
||||
|
@ -66,6 +66,7 @@ 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 CommandCallback = std::function<void(const OHOS::AAFwk::Want &want, int startId)>;
|
||||
|
||||
struct BackendDelegateImplBuilder {
|
||||
RefPtr<TaskExecutor> taskExecutor;
|
||||
@ -93,6 +94,7 @@ struct BackendDelegateImplBuilder {
|
||||
CastTemptoNormalCallback castTemptoNormalCallback;
|
||||
VisibilityChangedCallback visibilityChangedCallback;
|
||||
AcquireStateCallback acquireStateCallback;
|
||||
CommandCallback commandCallback;
|
||||
void* ability;
|
||||
BackendType type;
|
||||
};
|
||||
@ -143,6 +145,7 @@ public:
|
||||
void OnApplicationDestroy(const std::string &packageName);
|
||||
sptr<IRemoteObject> OnConnect(const OHOS::AAFwk::Want &want);
|
||||
void OnDisConnect(const OHOS::AAFwk::Want &want);
|
||||
void OnCommand(const OHOS::AAFwk::Want &want, int startId);
|
||||
|
||||
int32_t Insert(const Uri& uri, const OHOS::NativeRdb::ValuesBucket& value);
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> Query(
|
||||
@ -207,6 +210,7 @@ private:
|
||||
CastTemptoNormalCallback castTemptoNormalCallback_;
|
||||
VisibilityChangedCallback visibilityChangedCallback_;
|
||||
AcquireStateCallback acquireStateCallback_;
|
||||
CommandCallback commandCallback_;
|
||||
|
||||
RefPtr<Framework::ManifestParser> manifestParser_;
|
||||
void* ability_;
|
||||
|
@ -74,6 +74,8 @@ public:
|
||||
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 void OnCommand(const OHOS::AAFwk::Want &want, int startId) = 0;
|
||||
|
||||
void SetFormData(const AppExecFwk::FormProviderData &formProviderData)
|
||||
{
|
||||
formProviderData_ = formProviderData;
|
||||
|
@ -1084,7 +1084,6 @@ sptr<IRemoteObject> QjsPaEngine::OnConnectService(const OHOS::AAFwk::Want &want)
|
||||
JSValue jsWant = (JSValue)*nativeWant;
|
||||
JSValueConst argv[] = { jsWant };
|
||||
JSValue retVal = QJSUtils::Call(ctx, onConnectFunc, JS_UNDEFINED, countof(argv), argv);
|
||||
js_std_loop(ctx);
|
||||
if (JS_IsException(retVal)) {
|
||||
LOGE("Qjs onConnectService FAILED!");
|
||||
JS_FreeValue(ctx, globalObj);
|
||||
@ -1095,7 +1094,6 @@ sptr<IRemoteObject> QjsPaEngine::OnConnectService(const OHOS::AAFwk::Want &want)
|
||||
auto remoteObj = NAPI_ohos_rpc_getNativeRemoteObject(reinterpret_cast<napi_env>(nativeEngine_),
|
||||
reinterpret_cast<napi_value>(nativeValue));
|
||||
JS_FreeValue(ctx, globalObj);
|
||||
JS_FreeValue(ctx, retVal);
|
||||
return remoteObj;
|
||||
}
|
||||
}
|
||||
@ -1128,6 +1126,7 @@ void QjsPaEngine::OnDisconnectService(const OHOS::AAFwk::Want &want)
|
||||
LOGE("Qjs OnDisconnectService FAILED!");
|
||||
}
|
||||
JS_FreeValue(ctx, globalObj);
|
||||
JS_FreeValue(ctx, retVal);
|
||||
}
|
||||
|
||||
void QjsPaEngine::OnDelete(const int64_t formId)
|
||||
@ -1261,4 +1260,38 @@ void QjsPaEngine::OnAcquireState(const OHOS::AAFwk::Want &want)
|
||||
return;
|
||||
}
|
||||
|
||||
void QjsPaEngine::OnCommand(const OHOS::AAFwk::Want &want, int startId)
|
||||
{
|
||||
LOGI("OnCommand");
|
||||
JSContext *ctx = engineInstance_->GetQjsContext();
|
||||
ACE_DCHECK(ctx);
|
||||
|
||||
QJSHandleScope handleScope(ctx);
|
||||
JSValue globalObj = JS_GetGlobalObject(ctx);
|
||||
JSValue paObj = QJSUtils::GetPropertyStr(ctx, globalObj, "pa");
|
||||
if (!JS_IsObject(paObj)) {
|
||||
LOGE("get onCommand function error");
|
||||
return;
|
||||
}
|
||||
JSValue onCommandFunc = QJSUtils::GetPropertyStr(ctx, paObj, "onCommand");
|
||||
if (!JS_IsFunction(ctx, onCommandFunc)) {
|
||||
LOGE("onCommand function is not found!");
|
||||
JS_FreeValue(ctx, globalObj);
|
||||
return;
|
||||
}
|
||||
napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast<napi_env>(nativeEngine_), want);
|
||||
NativeValue* nativeWant = reinterpret_cast<NativeValue*>(napiWant);
|
||||
JSValue jsWant = (JSValue)*nativeWant;
|
||||
JSValueConst argv[] = {
|
||||
jsWant,
|
||||
JS_NewInt32(ctx, startId)
|
||||
};
|
||||
JSValue retVal = QJSUtils::Call(ctx, onCommandFunc, JS_UNDEFINED, countof(argv), argv);
|
||||
if (JS_IsException(retVal)) {
|
||||
LOGE("Qjs onCommand FAILED!");
|
||||
}
|
||||
JS_FreeValue(ctx, globalObj);
|
||||
JS_FreeValue(ctx, retVal);
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::Framework
|
||||
|
@ -163,6 +163,7 @@ public:
|
||||
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;
|
||||
void OnCommand(const OHOS::AAFwk::Want &want, int startId) override;
|
||||
|
||||
private:
|
||||
void GetLoadOptions(std::string& optionStr);
|
||||
|
@ -280,6 +280,15 @@ void PaBackend::InitializeBackendDelegate(const RefPtr<TaskExecutor> &taskExecut
|
||||
jsBackendEngine->OnAcquireState(want);
|
||||
};
|
||||
|
||||
builder.commandCallback = [weakEngine = WeakPtr<Framework::JsBackendEngine>(jsBackendEngine_)](
|
||||
const OHOS::AAFwk::Want &want, int startId) {
|
||||
auto jsBackendEngine = weakEngine.Upgrade();
|
||||
if (!jsBackendEngine) {
|
||||
return;
|
||||
}
|
||||
jsBackendEngine->OnCommand(want, startId);
|
||||
};
|
||||
|
||||
builder.taskExecutor = taskExecutor;
|
||||
builder.ability = ability_;
|
||||
builder.type = type_;
|
||||
@ -414,4 +423,9 @@ void PaBackend::OnDisConnect(const OHOS::AAFwk::Want &want)
|
||||
delegate_->OnDisConnect(want);
|
||||
}
|
||||
|
||||
void PaBackend::OnCommand(const OHOS::AAFwk::Want &want, int startId)
|
||||
{
|
||||
delegate_->OnCommand(want, startId);
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
@ -93,6 +93,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void OnCommand(const OHOS::AAFwk::Want &want, int startId);
|
||||
|
||||
private:
|
||||
void InitializeBackendDelegate(const RefPtr<TaskExecutor>& taskExecutor);
|
||||
BackendType type_ = BackendType::SERVICE;
|
||||
|
Loading…
Reference in New Issue
Block a user