!1835 支持单实例Ability迁移

Merge pull request !1835 from 张亚菲/zyfContinue
This commit is contained in:
openharmony_ci
2022-05-30 07:39:42 +00:00
committed by Gitee
9 changed files with 64 additions and 11 deletions
@@ -1623,6 +1623,12 @@ protected:
*/
sptr<Rosen::WindowOption> GetWindowOption(const Want &want);
/**
* @brief Restore window stage data and scene in ability continuation.
*
*/
virtual void ContinuationRestore(const Want &want);
std::shared_ptr<Rosen::WindowScene> scene_ = nullptr;
sptr<Rosen::IWindowLifeCycle> sceneListener_ = nullptr;
sptr<AbilityDisplayListener> abilityDisplayListener_ = nullptr;
@@ -77,6 +77,7 @@ public:
protected:
void DoOnForeground(const Want &want) override;
void RequsetFocus(const Want &want) override;
void ContinuationRestore(const Want &want) override;
private:
void GetPageStackFromWant(const Want &want, std::string &pageStack);
+17 -7
View File
@@ -413,14 +413,19 @@ bool Ability::IsRestoredInContinuation() const
HILOG_ERROR("abilityContext_ is null");
return false;
}
if (launchParam_.launchReason == LaunchReason::LAUNCHREASON_CONTINUATION
&& abilityInfo_->launchMode == LaunchMode::STANDARD
&& abilityContext_->GetContentStorage() != nullptr) {
HILOG_INFO("Is Restored In Continuation");
return true;
if (launchParam_.launchReason != LaunchReason::LAUNCHREASON_CONTINUATION) {
HILOG_INFO("launchReason is %{public}d", launchParam_.launchReason);
return false;
}
HILOG_INFO("not Restored In Continuation");
return false;
if (abilityContext_->GetContentStorage() == nullptr) {
HILOG_INFO("not Restored In Continuation");
return false;
}
HILOG_INFO("Is Restored In Continuation");
return true;
}
void Ability::WaitingDistributedObjectSyncComplete(const Want& want)
@@ -3799,6 +3804,11 @@ int Ability::GetDisplayOrientation()
HILOG_DEBUG("%{public}s, get window orientation: UNSPECIFIED", __func__);
return 0;
}
void Ability::ContinuationRestore(const Want &want)
{
HILOG_INFO("%{public}s called.", __func__);
}
#endif
} // namespace AppExecFwk
} // namespace OHOS
@@ -347,6 +347,9 @@ void AbilityImpl::NewWant(const Want &want)
}
ability_->SetWant(want);
ability_->OnNewWant(want);
#ifdef SUPPORT_GRAPHICS
ability_->ContinuationRestore(want);
#endif
HILOG_INFO("%{public}s end.", __func__);
}
@@ -366,7 +366,7 @@ void JsAbility::DoOnForeground(const Want &want)
}
// multi-instance ability continuation
HILOG_INFO("lauch reason = %{public}d", launchParam_.launchReason);
HILOG_INFO("launch reason = %{public}d", launchParam_.launchReason);
if (IsRestoredInContinuation()) {
std::string pageStack;
GetPageStackFromWant(want, pageStack);
@@ -421,6 +421,26 @@ void JsAbility::RequsetFocus(const Want &want)
}
scene_->GoForeground(Ability::sceneFlag_);
}
void JsAbility::ContinuationRestore(const Want &want)
{
HILOG_INFO("%{public}s called.", __func__);
if (!IsRestoredInContinuation() || scene_ == nullptr) {
return;
}
std::string pageStack;
GetPageStackFromWant(want, pageStack);
HandleScope handleScope(jsRuntime_);
auto &engine = jsRuntime_.GetNativeEngine();
if (abilityContext_->GetContentStorage()) {
scene_->GetMainWindow()->SetUIContent(pageStack, &engine, abilityContext_->GetContentStorage()->Get(), true);
} else {
HILOG_ERROR("restore: content storage is nullptr");
}
OnSceneRestored();
WaitingDistributedObjectSyncComplete(want);
}
#endif
int32_t JsAbility::OnContinue(WantParams &wantParams)
@@ -516,7 +536,12 @@ void JsAbility::OnNewWant(const Want &want)
obj->SetProperty("lastRequestWant", jsWant);
CallObjectMethod("onNewWant", &jsWant, 1);
NativeValue *argv[] = {
jsWant,
CreateJsLaunchParam(nativeEngine, GetLaunchParam()),
};
CallObjectMethod("onNewWant", argv, ArraySize(argv));
HILOG_INFO("%{public}s end.", __func__);
}
@@ -50,9 +50,9 @@ void NewAbilityImpl::HandleAbilityTransaction(const Want &want, const AAFwk::Lif
#endif
SetLifeCycleStateInfo(targetState);
ability_->SetLaunchParam(targetState.launchParam);
if (ability_ && lifecycleState_ == AAFwk::ABILITY_STATE_INITIAL) {
ability_->SetStartAbilitySetting(targetState.setting);
ability_->SetLaunchParam(targetState.launchParam);
Start(want);
CheckAndRestore();
}
@@ -166,8 +166,15 @@ public:
OnConfigurationUpdated_++;
}
void ContinuationRestore(const Want &want)
{
GTEST_LOG_(INFO) << "Mock Ability::ContinuationRestore called";
continueRestoreCalled_ = true;
}
MockPageAbility::Event state_ = UNDEFINED;
bool onNewWantCalled_ = false;
bool continueRestoreCalled_ = false;
int OnConfigurationUpdated_ = 0;
std::vector<std::string> value;
};
@@ -1309,6 +1309,7 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_NewWant_001, TestSize.Level1)
Want want;
mockAbilityimpl->NewWant(want);
EXPECT_EQ(1, pMocKPageAbility->onNewWantCalled_);
EXPECT_EQ(1, pMocKPageAbility->continueRestoreCalled_);
}
}
}
@@ -32,7 +32,7 @@ class Ability {
}
onContinue(wantParams) {}
onConfigurationUpdated(config) {}
onNewWant(want) {}
onNewWant(want, param) {}
dump(params) {}
}