mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-23 07:10:19 +00:00
!2183 FormExtensionContext新增startAbility接口
Merge pull request !2183 from 闫文豪/feature52
This commit is contained in:
commit
e7036b45c5
@ -32,11 +32,9 @@ namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr int32_t INDEX_ZERO = 0;
|
||||
constexpr int32_t INDEX_ONE = 1;
|
||||
constexpr int32_t ERROR_CODE_ONE = 1;
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
constexpr size_t ARGC_THREE = 3;
|
||||
const int UPDATE_FORM_PARAMS_SIZE = 2;
|
||||
class JsFormExtensionContext final {
|
||||
public:
|
||||
@ -126,8 +124,8 @@ private:
|
||||
NativeValue* OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnStartAbility is called");
|
||||
// only support one or two or three params
|
||||
if (info.argc != ARGC_ONE && info.argc != ARGC_TWO && info.argc != ARGC_THREE) {
|
||||
// only support one or two params
|
||||
if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
@ -142,16 +140,8 @@ private:
|
||||
want.GetElement().GetAbilityName().c_str());
|
||||
unwrapArgc++;
|
||||
|
||||
AAFwk::StartOptions startOptions;
|
||||
if (info.argc > ARGC_ONE && info.argv[INDEX_ONE]->TypeOf() == NATIVE_OBJECT) {
|
||||
HILOG_INFO("OnStartAbility start options is used.");
|
||||
AppExecFwk::UnwrapStartOptions(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[INDEX_ONE]), startOptions);
|
||||
unwrapArgc++;
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_, want, startOptions, unwrapArgc](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
[weak = context_, want, unwrapArgc](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
HILOG_INFO("startAbility begin");
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
@ -161,8 +151,8 @@ private:
|
||||
}
|
||||
|
||||
ErrCode errcode = ERR_OK;
|
||||
(unwrapArgc == 1) ? errcode = context->StartAbility(want) :
|
||||
errcode = context->StartAbility(want, startOptions);
|
||||
// entry to the core functionality.
|
||||
errcode = context->StartAbility(want);
|
||||
if (errcode == 0) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
|
@ -53,18 +53,8 @@ int FormExtensionContext::UpdateForm(const int64_t formId, const AppExecFwk::For
|
||||
ErrCode FormExtensionContext::StartAbility(const AAFwk::Want &want) const
|
||||
{
|
||||
HILOG_DEBUG("%{public}s begin.", __func__);
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, -1);
|
||||
HILOG_DEBUG("%{public}s. End calling StartAbility. ret=%{public}d", __func__, err);
|
||||
if (err != ERR_OK) {
|
||||
HILOG_ERROR("FormExtensionContext::StartAbility is failed %{public}d", err);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
ErrCode FormExtensionContext::StartAbility(const AAFwk::Want &want, const AAFwk::StartOptions &startOptions) const
|
||||
{
|
||||
HILOG_DEBUG("%{public}s begin.", __func__);
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, startOptions, token_, -1);
|
||||
// route to FMS
|
||||
ErrCode err = AppExecFwk::FormMgr::GetInstance().StartAbility(want, token_);
|
||||
HILOG_DEBUG("%{public}s. End calling StartAbility. ret=%{public}d", __func__, err);
|
||||
if (err != ERR_OK) {
|
||||
HILOG_ERROR("FormExtensionContext::StartAbility is failed %{public}d", err);
|
||||
|
@ -55,7 +55,6 @@ public:
|
||||
* @return errCode ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode StartAbility(const AAFwk::Want &want) const;
|
||||
ErrCode StartAbility(const AAFwk::Want &want, const AAFwk::StartOptions &startOptions) const;
|
||||
|
||||
/**
|
||||
* @brief Obtains information about the current ability.
|
||||
|
Loading…
Reference in New Issue
Block a user