mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
!350 start options deliver to window
Merge pull request !350 from 李伟峰/master
This commit is contained in:
@@ -64,6 +64,9 @@ public:
|
||||
|
||||
virtual ErrCode StartAbilityForResult(const AAFwk::Want &Want, int requestCode, RuntimeTask &&task) = 0;
|
||||
|
||||
virtual ErrCode StartAbilityForResult(const AAFwk::Want &Want, const AAFwk::StartOptions &startOptions,
|
||||
int requestCode, RuntimeTask &&task) = 0;
|
||||
|
||||
virtual ErrCode TerminateAbilityWithResult(const AAFwk::Want &want, int resultCode) = 0;
|
||||
|
||||
virtual ErrCode RestoreWindowStage(void* contentStorage) = 0;
|
||||
|
||||
@@ -43,6 +43,8 @@ public:
|
||||
ErrCode StartAbility(const AAFwk::Want &want, int requestCode) override;
|
||||
ErrCode StartAbility(const AAFwk::Want &want, const AAFwk::StartOptions &startOptions, int requestCode) override;
|
||||
ErrCode StartAbilityForResult(const AAFwk::Want &want, int requestCode, RuntimeTask &&task) override;
|
||||
ErrCode StartAbilityForResult(const AAFwk::Want &want, const AAFwk::StartOptions &startOptions,
|
||||
int requestCode, RuntimeTask &&task) override;
|
||||
ErrCode TerminateAbilityWithResult(const AAFwk::Want &want, int resultCode) override;
|
||||
void OnAbilityResult(int requestCode, int resultCode, const AAFwk::Want &resultData) override;
|
||||
bool ConnectAbility(const AAFwk::Want &want,
|
||||
|
||||
@@ -86,6 +86,15 @@ ErrCode AbilityContextImpl::StartAbilityForResult(const AAFwk::Want &want, int r
|
||||
return err;
|
||||
}
|
||||
|
||||
ErrCode AbilityContextImpl::StartAbilityForResult(const AAFwk::Want &want, const AAFwk::StartOptions &startOptions,
|
||||
int requestCode, RuntimeTask &&task)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s. Start calling StartAbilityForResult.", __func__);
|
||||
resultCallbacks_.insert(make_pair(requestCode, std::move(task)));
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, startOptions, token_, requestCode);
|
||||
HILOG_INFO("%{public}s. End calling StartAbilityForResult. ret=%{public}d", __func__, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
ErrCode AbilityContextImpl::TerminateAbilityWithResult(const AAFwk::Want &want, int resultCode)
|
||||
{
|
||||
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
int TerminateAbility(Want &want);
|
||||
|
||||
/**
|
||||
* @brief By binding an action, you can set different action parameters in Intent to present different initial
|
||||
* @brief By binding an action, you can set different action parameters in want to present different initial
|
||||
* pages. You must register actions in the profile file.
|
||||
*
|
||||
* @param action Indicates the action to bind.
|
||||
@@ -199,8 +199,8 @@ public:
|
||||
* Starts a new ability with specific start settings.
|
||||
* A Page or Service ability uses this method to start a specific ability.
|
||||
* The system locates the target ability from installed abilities based on
|
||||
* the value of the intent parameter and then starts it. You can specify the
|
||||
* ability to start using the intent parameter.
|
||||
* the value of the want parameter and then starts it. You can specify the
|
||||
* ability to start using the want parameter.
|
||||
*
|
||||
* @param want Indicates the ability to start.
|
||||
* @param abilityStartSetting Indicates the setting ability used to start.
|
||||
@@ -387,7 +387,7 @@ public:
|
||||
*
|
||||
* @param windowOption Indicates the window option defined by the user.
|
||||
*/
|
||||
virtual void InitWindow(Rosen::WindowType winType, int32_t displayId);
|
||||
virtual void InitWindow(Rosen::WindowType winType, int32_t displayId, sptr<Rosen::WindowOption> option);
|
||||
|
||||
/**
|
||||
* @brief Get the window belong to the ability.
|
||||
@@ -850,10 +850,10 @@ public:
|
||||
|
||||
/**
|
||||
* @brief A Page or Service ability uses this method to start a specific ability. The system locates the target
|
||||
* ability from installed abilities based on the value of the intent parameter and then starts it. You can specify
|
||||
* the ability to start using the intent parameter.
|
||||
* ability from installed abilities based on the value of the want parameter and then starts it. You can specify
|
||||
* the ability to start using the want parameter.
|
||||
*
|
||||
* @param intent Indicates the ability to start.
|
||||
* @param want Indicates the ability to start.
|
||||
*
|
||||
* @return errCode ERR_OK on success, others on failure.
|
||||
*/
|
||||
@@ -1492,10 +1492,10 @@ private:
|
||||
// Keep consistent with DMS defines. Used to callback to DMS.
|
||||
static const std::string DMS_SESSION_ID;
|
||||
|
||||
// The originating deviceId passed by DMS using intent param.
|
||||
// The originating deviceId passed by DMS using want param.
|
||||
static const std::string DMS_ORIGIN_DEVICE_ID;
|
||||
|
||||
// If session id cannot get from intent, assign it as default.
|
||||
// If session id cannot get from want, assign it as default.
|
||||
static const int DEFAULT_DMS_SESSION_ID;
|
||||
|
||||
std::vector<int64_t> lostedByReconnectTempForms_;
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
*/
|
||||
bool InitWindow(Rosen::WindowType winType,
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> &abilityContext,
|
||||
sptr<Rosen::IWindowLifeCycle> &listener, int32_t displayId);
|
||||
sptr<Rosen::IWindowLifeCycle> &listener, int32_t displayId, sptr<Rosen::WindowOption> option);
|
||||
|
||||
/**
|
||||
* @brief Called when this ability is started.
|
||||
|
||||
@@ -202,8 +202,8 @@ void Ability::OnStart(const Want &want)
|
||||
abilityInfo_->name.c_str(),
|
||||
winType,
|
||||
displayId);
|
||||
|
||||
InitWindow(winType, displayId);
|
||||
auto option = GetWindowOption(want);
|
||||
InitWindow(winType, displayId, option);
|
||||
|
||||
if (abilityWindow_ != nullptr) {
|
||||
APP_LOGI("%{public}s begin abilityWindow_->OnPostAbilityStart.", __func__);
|
||||
@@ -677,7 +677,7 @@ void Ability::SetUIContent(int layoutRes, std::shared_ptr<Context> &context, int
|
||||
*
|
||||
* @param windowOption Indicates the window option defined by the user.
|
||||
*/
|
||||
void Ability::InitWindow(Rosen::WindowType winType, int32_t displayId)
|
||||
void Ability::InitWindow(Rosen::WindowType winType, int32_t displayId, sptr<Rosen::WindowOption> option)
|
||||
{
|
||||
if (abilityWindow_ == nullptr) {
|
||||
APP_LOGE("Ability::InitWindow abilityWindow_ is nullptr");
|
||||
@@ -686,11 +686,11 @@ void Ability::InitWindow(Rosen::WindowType winType, int32_t displayId)
|
||||
bool useNewMission = AbilityImpl::IsUseNewMission();
|
||||
APP_LOGI("%{public}s beign abilityWindow_->InitWindow.", __func__);
|
||||
if (useNewMission) {
|
||||
abilityWindow_->InitWindow(winType, abilityContext_, sceneListener_, displayId);
|
||||
abilityWindow_->InitWindow(winType, abilityContext_, sceneListener_, displayId, option);
|
||||
} else {
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> context = nullptr;
|
||||
sptr<Rosen::IWindowLifeCycle> listener = nullptr;
|
||||
abilityWindow_->InitWindow(winType, context, listener, displayId);
|
||||
abilityWindow_->InitWindow(winType, context, listener, displayId, option);
|
||||
}
|
||||
APP_LOGI("%{public}s end abilityWindow_->InitWindow.", __func__);
|
||||
}
|
||||
@@ -3247,7 +3247,7 @@ sptr<Rosen::WindowOption> Ability::GetWindowOption(const Want &want)
|
||||
APP_LOGE("Ability::GetWindowOption option is null.");
|
||||
return nullptr;
|
||||
}
|
||||
auto windowMode = want.GetIntParam(StartOptions::STRING_WINDOW_MODE,
|
||||
auto windowMode = want.GetIntParam(Want::PARAM_RESV_WINDOW_MODE,
|
||||
AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED);
|
||||
APP_LOGI("Ability::GetWindowOption window mode is %{public}d.", windowMode);
|
||||
option->SetWindowMode(static_cast<Rosen::WindowMode>(windowMode));
|
||||
|
||||
@@ -319,7 +319,7 @@ void JsAbility::DoOnForeground(const Want& want)
|
||||
}
|
||||
}
|
||||
auto option = GetWindowOption(want);
|
||||
Rosen::WMError ret = scene_->Init(displayId, abilityContext_, sceneListener_);
|
||||
Rosen::WMError ret = scene_->Init(displayId, abilityContext_, sceneListener_, option);
|
||||
if (ret != Rosen::WMError::WM_OK) {
|
||||
HILOG_ERROR("%{public}s error. failed to init window scene!", __func__);
|
||||
return;
|
||||
|
||||
@@ -152,8 +152,16 @@ NativeValue* JsAbilityContext::OnStartAbilityForResult(NativeEngine& engine, Nat
|
||||
HILOG_ERROR("%s Failed to parse want!", __func__);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
decltype(info.argc) unwrapArgc = 1;
|
||||
AAFwk::StartOptions startOptions;
|
||||
if (info.argc > ARGC_ONE && info.argv[1]->TypeOf() == NATIVE_OBJECT) {
|
||||
HILOG_INFO("OnStartAbilityForResult start options is used.");
|
||||
AppExecFwk::UnwrapStartOptions(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[1]), startOptions);
|
||||
unwrapArgc++;
|
||||
}
|
||||
|
||||
NativeValue* lastParam = info.argc == 1 ? nullptr : info.argv[1];
|
||||
NativeValue* lastParam = info.argc == unwrapArgc ? nullptr : info.argv[unwrapArgc];
|
||||
NativeValue* result = nullptr;
|
||||
std::unique_ptr<AsyncTask> uasyncTask =
|
||||
CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, nullptr, &result);
|
||||
@@ -175,7 +183,8 @@ NativeValue* JsAbilityContext::OnStartAbilityForResult(NativeEngine& engine, Nat
|
||||
asyncTask->Reject(engine, CreateJsError(engine, 1, "context is released!"));
|
||||
} else {
|
||||
curRequestCode_ = (curRequestCode_ == INT_MAX) ? 0 : (curRequestCode_ + 1);
|
||||
context->StartAbilityForResult(want, curRequestCode_, std::move(task));
|
||||
(unwrapArgc == 1) ? context->StartAbilityForResult(want, curRequestCode_, std::move(task)) :
|
||||
context->StartAbilityForResult(want, startOptions, curRequestCode_, std::move(task));
|
||||
}
|
||||
HILOG_INFO("OnStartAbilityForResult is called end");
|
||||
return result;
|
||||
|
||||
@@ -50,10 +50,10 @@ void AbilityWindow::Init(std::shared_ptr<AbilityHandler>& handler, std::shared_p
|
||||
*/
|
||||
bool AbilityWindow::InitWindow(Rosen::WindowType winType,
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> &abilityContext,
|
||||
sptr<Rosen::IWindowLifeCycle> &listener, int32_t displayId)
|
||||
sptr<Rosen::IWindowLifeCycle> &listener, int32_t displayId, sptr<Rosen::WindowOption> option)
|
||||
{
|
||||
APP_LOGI("%{public}s begin.", __func__);
|
||||
auto ret = windowScene_->Init(displayId, abilityContext, listener);
|
||||
auto ret = windowScene_->Init(displayId, abilityContext, listener, option);
|
||||
if (ret != OHOS::Rosen::WMError::WM_OK) {
|
||||
APP_LOGE("%{public}s error. failed to init window scene!", __func__);
|
||||
return false;
|
||||
|
||||
@@ -66,6 +66,8 @@ const std::string Want::OCT_SEMICOLON("073"); // ';'
|
||||
const std::string Want::MIME_TYPE("mime-type");
|
||||
const std::string Want::WANT_HEADER("#Intent;");
|
||||
|
||||
const std::string Want::PARAM_RESV_WINDOW_MODE("ohos.aafwk.param.windowMode");
|
||||
|
||||
/**
|
||||
* @description:Default construcotr of Want class, which is used to initialzie flags and URI.
|
||||
* @param None
|
||||
|
||||
@@ -24,7 +24,6 @@ namespace OHOS {
|
||||
namespace AAFwk {
|
||||
class StartOptions : public Parcelable {
|
||||
public:
|
||||
static const std::string STRING_WINDOW_MODE;
|
||||
static const std::string STRING_DISPLAY_ID;
|
||||
const int32_t DEFAULT_DISPLAY_ID {0};
|
||||
|
||||
|
||||
@@ -787,6 +787,9 @@ public:
|
||||
static constexpr int HEX_STRING_BUF_LEN = 36;
|
||||
static constexpr int HEX_STRING_LEN = 10;
|
||||
|
||||
// reserved param definition
|
||||
static const std::string PARAM_RESV_WINDOW_MODE;
|
||||
|
||||
private:
|
||||
WantParams parameters_;
|
||||
Operation operation_;
|
||||
|
||||
@@ -708,6 +708,10 @@ bool UnwrapWantParams(napi_env env, napi_value param, AAFwk::WantParams &wantPar
|
||||
NAPI_CALL_BASE(env, napi_get_element(env, jsProNameList, index, &jsProName), false);
|
||||
|
||||
std::string strProName = UnwrapStringFromJS(env, jsProName);
|
||||
/* skip reserved param */
|
||||
if (strProName == Want::PARAM_RESV_WINDOW_MODE) {
|
||||
continue;
|
||||
}
|
||||
HILOG_INFO("%{public}s called. Property name=%{public}s.", __func__, strProName.c_str());
|
||||
NAPI_CALL_BASE(env, napi_get_named_property(env, param, strProName.c_str(), &jsProValue), false);
|
||||
NAPI_CALL_BASE(env, napi_typeof(env, jsProValue, &jsValueType), false);
|
||||
|
||||
@@ -393,9 +393,8 @@ int AbilityManagerService::StartAbility(const Want &want, const StartOptions &st
|
||||
}
|
||||
}
|
||||
|
||||
abilityRequest.want.SetParam(StartOptions::STRING_WINDOW_MODE, startOptions.GetWindowMode());
|
||||
abilityRequest.want.SetParam(StartOptions::STRING_DISPLAY_ID, startOptions.GetDisplayID());
|
||||
|
||||
abilityRequest.want.SetParam(Want::PARAM_RESV_WINDOW_MODE, startOptions.GetWindowMode());
|
||||
if (useNewMission_) {
|
||||
return currentMissionListManager_->StartAbility(abilityRequest);
|
||||
} else {
|
||||
@@ -631,7 +630,7 @@ int AbilityManagerService::MinimizeAbility(const sptr<IRemoteObject> &token)
|
||||
if (!IsAbilityControllerResuming(abilityRecord->GetAbilityInfo().bundleName)) {
|
||||
return ERR_WOULD_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
if (useNewMission_) {
|
||||
return currentMissionListManager_->MinimizeAbility(token);
|
||||
} else {
|
||||
@@ -2591,7 +2590,7 @@ void AbilityManagerService::StartSystemApplication()
|
||||
HILOG_INFO("start mms");
|
||||
StartingMmsAbility();
|
||||
}
|
||||
|
||||
|
||||
// Location may change
|
||||
DelayedSingleton<AppScheduler>::GetInstance()->StartupResidentProcess();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
|
||||
const std::string StartOptions::STRING_WINDOW_MODE = "ohos.aafwk.windowMode";
|
||||
const std::string StartOptions::STRING_DISPLAY_ID = "ohos.aafwk.displayId";
|
||||
|
||||
bool StartOptions::ReadFromParcel(Parcel &parcel)
|
||||
|
||||
Reference in New Issue
Block a user