Add enum to continuation and app recovery.

Sig:SIG_ApplicationFramework
Feature or BugFix: Feature
Binary Source: No

Signed-off-by: zhangyafei.echo <zhangyafei12@huawei.com>
Change-Id: I11148aa67d0bfe6392f648655c875ec0e986a58a
This commit is contained in:
zhangyafei.echo 2024-05-15 14:11:27 +08:00
parent 913e682dea
commit cdeac0e592
22 changed files with 115 additions and 70 deletions

View File

@ -1245,8 +1245,8 @@ public:
* @param ability
* @return WMError
*/
virtual WMError NapiSetUIContent(const std::string& contentInfo, napi_env env,
napi_value storage, bool isDistributed = false, sptr<IRemoteObject> token = nullptr,
virtual WMError NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage,
BackupAndRestoreType type = BackupAndRestoreType::NONE, sptr<IRemoteObject> token = nullptr,
AppExecFwk::Ability* ability = nullptr)
{
return WMError::WM_OK;
@ -1285,7 +1285,10 @@ public:
*
* @return UI content info.
*/
virtual std::string GetContentInfo() { return std::string(); }
virtual std::string GetContentInfo(BackupAndRestoreType type = BackupAndRestoreType::CONTINUATION)
{
return std::string();
}
/**
* @brief Get ui content object.
*
@ -1882,7 +1885,7 @@ public:
* @return Rect of window.
*/
virtual Rect GetHostWindowRect(int32_t hostWindowId) { return {}; }
/**
* @brief Set Shaped Window Mask.
*

View File

@ -21,6 +21,7 @@
#include "window.h"
#include "window_option.h"
#include "wm_common.h"
namespace OHOS::AppExecFwk {
class Configuration;
@ -150,7 +151,7 @@ public:
*
* @return content info of main window
*/
std::string GetContentInfo() const;
std::string GetContentInfo(BackupAndRestoreType type = BackupAndRestoreType::CONTINUATION) const;
/**
* @brief Handle and notify memory.

View File

@ -392,11 +392,20 @@ enum class WindowGravity : uint32_t {
*/
enum class WindowSetUIContentType: uint32_t {
DEFAULT,
DISTRIBUTE,
RESTORE,
BY_NAME,
BY_ABC,
};
/**
* @brief Enumerates restore type.
*/
enum class BackupAndRestoreType: int32_t {
NONE = 0, // no backup and restore
CONTINUATION = 1, // distribute
APP_RECOVERY = 2, // app recovery
};
/**
* @struct PointInfo.
*

View File

@ -122,7 +122,7 @@ int32_t CJWindowStageImpl::OnLoadContent(const std::string &contexUrl,
if (isLoadedByName) {
ret = window->SetUIContentByName(contexUrl, nullptr, nullptr);
} else {
ret = window->NapiSetUIContent(contexUrl, nullptr, nullptr, false);
ret = window->NapiSetUIContent(contexUrl, nullptr, nullptr);
}
TLOGI(WmsLogTag::WMS_DIALOG,
"[WindowStage] LoadContent [%{public}u, %{public}s] load content end, ret = %{public}d",

View File

@ -268,7 +268,7 @@ static void LoadContentTask(std::shared_ptr<NativeReference> contentStorage, std
if (isLoadedByName) {
ret = windowImpl->SetUIContentByName(contextUrl, env, nativeStorage);
} else {
ret = windowImpl->NapiSetUIContent(contextUrl, env, nativeStorage, false, parentToken);
ret = windowImpl->NapiSetUIContent(contextUrl, env, nativeStorage, BackupAndRestoreType::NONE, parentToken);
}
if (ret == WMError::WM_OK) {
task.Resolve(env, NapiGetUndefined(env));

View File

@ -300,7 +300,7 @@ static void LoadContentTask(std::shared_ptr<NativeReference> contentStorage, std
if (isLoadedByName) {
ret = windowImpl->SetUIContentByName(contextUrl, env, nativeStorage);
} else {
ret = windowImpl->NapiSetUIContent(contextUrl, env, nativeStorage, false, parentToken);
ret = windowImpl->NapiSetUIContent(contextUrl, env, nativeStorage, BackupAndRestoreType::NONE, parentToken);
}
if (ret == WMError::WM_OK) {
task.Resolve(env, NapiGetUndefined(env));
@ -622,7 +622,7 @@ napi_value JsExtensionWindow::OnLoadContent(napi_env env, napi_callback_info inf
napi_create_reference(env, storage, 1, &result);
contentStorage = std::shared_ptr<NativeReference>(reinterpret_cast<NativeReference*>(result));
}
sptr<IRemoteObject> parentToken = sessionInfo_->parentToken;
NapiAsyncTask::CompleteCallback complete =
[extwin = extensionWindow_, contentStorage, contextUrl, parentToken, isLoadedByName](

View File

@ -1827,7 +1827,7 @@ static void LoadContentTask(std::shared_ptr<NativeReference> contentStorage, std
ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->SetUIContentByName(contextUrl, env, nativeStorage, ability));
} else {
ret = WM_JS_TO_ERROR_CODE_MAP.at(
weakWindow->NapiSetUIContent(contextUrl, env, nativeStorage, false, nullptr, ability));
weakWindow->NapiSetUIContent(contextUrl, env, nativeStorage, BackupAndRestoreType::NONE, nullptr, ability));
}
if (ret == WmErrorCode::WM_OK) {
task.Resolve(env, NapiGetUndefined(env));

View File

@ -326,7 +326,7 @@ static void LoadContentTask(std::shared_ptr<NativeReference> contentStorage, std
if (isLoadedByName) {
ret = weakWindow->SetUIContentByName(contextUrl, env, nativeStorage);
} else {
ret = weakWindow->NapiSetUIContent(contextUrl, env, nativeStorage, false);
ret = weakWindow->NapiSetUIContent(contextUrl, env, nativeStorage);
}
if (ret == WMError::WM_OK) {
task.Resolve(env, NapiGetUndefined(env));

View File

@ -212,8 +212,8 @@ public:
virtual void UnregisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener) = 0;
virtual void NotifyTouchDialogTarget(int32_t posX = 0, int32_t posY = 0) = 0;
virtual void SetAceAbilityHandler(const sptr<IAceAbilityHandler>& handler) = 0;
virtual WMError NapiSetUIContent(const std::string& contentInfo, napi_env env,
napi_value storage, bool isDistributed = false, sptr<IRemoteObject> token = nullptr,
virtual WMError NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage,
BackupAndRestoreType type = BackupAndRestoreType::NONE, sptr<IRemoteObject> token = nullptr,
AppExecFwk::Ability* ability = nullptr) = 0;
virtual WMError SetUIContentByName(const std::string& contentInfo, napi_env env, napi_value storage,
AppExecFwk::Ability* ability = nullptr)
@ -225,7 +225,7 @@ public:
{
return WMError::WM_OK;
}
virtual std::string GetContentInfo() = 0;
virtual std::string GetContentInfo(BackupAndRestoreType type = BackupAndRestoreType::CONTINUATION) = 0;
virtual Ace::UIContent* GetUIContent() const = 0;
virtual void OnNewWant(const AAFwk::Want& want) = 0;
virtual void SetRequestedOrientation(Orientation) = 0;
@ -320,7 +320,7 @@ public:
return WMError::WM_ERROR_DEVICE_NOT_SUPPORT;
}
virtual WMError Recover(uint32_t reason = 0) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; };
virtual WMError Maximize(MaximizeLayoutOption option) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; }
virtual WMError SetWindowMask(const std::vector<std::vector<uint32_t>>& windowMask)

View File

@ -170,9 +170,9 @@ public:
virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
void NotifyTouchDialogTarget(int32_t posX = 0, int32_t posY = 0) override;
virtual WMError NapiSetUIContent(const std::string& contentInfo, napi_env env,
napi_value storage, bool isdistributed, sptr<IRemoteObject> token, AppExecFwk::Ability* ability) override;
virtual std::string GetContentInfo() override;
virtual WMError NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage,
BackupAndRestoreType type, sptr<IRemoteObject> token, AppExecFwk::Ability* ability) override;
virtual std::string GetContentInfo(BackupAndRestoreType type = BackupAndRestoreType::CONTINUATION) override;
virtual const std::shared_ptr<AbilityRuntime::Context> GetContext() const override;
virtual Ace::UIContent* GetUIContent() const override;
virtual void OnNewWant(const AAFwk::Want& want) override;

View File

@ -753,6 +753,12 @@ struct MaximizeLayoutOption {
ShowType decor = ShowType::HIDE;
ShowType dock = ShowType::HIDE;
};
enum class BackupAndRestoreType: int32_t {
NONE = 0, // no backup and restore
CONTINUATION = 1, // distribute
APP_RECOVERY = 2, // app recovery
};
}
}
#endif // OHOS_ROSEN_WM_COMMON_H

View File

@ -233,8 +233,8 @@ void WindowImpl::OnNewWant(const AAFwk::Want& want)
return;
}
WMError WindowImpl::NapiSetUIContent(const std::string& contentInfo,
napi_env env, napi_value storage, bool isdistributed, sptr<IRemoteObject> token, AppExecFwk::Ability* ability)
WMError WindowImpl::NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage,
BackupAndRestoreType type, sptr<IRemoteObject> token, AppExecFwk::Ability* ability)
{
WLOGFD("NapiSetUIContent: %{public}s", contentInfo.c_str());
if (uiContent_) {
@ -250,8 +250,9 @@ WMError WindowImpl::NapiSetUIContent(const std::string& contentInfo,
WLOGFE("fail to NapiSetUIContent");
return WMError::WM_ERROR_NULLPTR;
}
if (isdistributed) {
uiContent->Restore(this, contentInfo, storage);
if (type != BackupAndRestoreType::NONE) {
uiContent->Restore(this, contentInfo, storage, type == BackupAndRestoreType::CONTINUATION ?
Ace::ContentInfoType::CONTINUATION : Ace::ContentInfoType::APP_RECOVERY);
} else {
uiContent->Initialize(this, contentInfo, storage);
}
@ -273,7 +274,7 @@ Ace::UIContent* WindowImpl::GetUIContent() const
return uiContent_.get();
}
std::string WindowImpl::GetContentInfo()
std::string WindowImpl::GetContentInfo(BackupAndRestoreType type)
{
return "";
}

View File

@ -39,9 +39,9 @@ public:
MOCK_METHOD0(UnFocus, void());
MOCK_METHOD0(Destroy, void());
MOCK_METHOD1(OnNewWant, void(const OHOS::AAFwk::Want& want));
MOCK_METHOD3(Restore, UIContentErrorCode(OHOS::Rosen::Window* window, const std::string& contentInfo,
napi_value storage));
MOCK_CONST_METHOD0(GetContentInfo, std::string());
MOCK_METHOD4(Restore, UIContentErrorCode(OHOS::Rosen::Window* window, const std::string& contentInfo,
napi_value storage, ContentInfoType type));
MOCK_CONST_METHOD1(GetContentInfo, std::string(ContentInfoType type));
MOCK_METHOD0(DestroyUIDirector, void());
MOCK_METHOD0(ProcessBackPressed, bool());
MOCK_METHOD1(ProcessPointerEvent, bool(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent));

View File

@ -42,8 +42,8 @@ public:
const NotifyTransferComponentDataForResultFunc& func) override;
void TriggerBindModalUIExtension() override;
WMError SetPrivacyMode(bool isPrivacyMode) override;
WMError NapiSetUIContent(const std::string& contentInfo, napi_env env,
napi_value storage, bool isdistributed, sptr<IRemoteObject> token, AppExecFwk::Ability* ability) override;
WMError NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage,
BackupAndRestoreType type, sptr<IRemoteObject> token, AppExecFwk::Ability* ability) override;
WSError UpdateRect(const WSRect& rect, SizeChangeReason reason,
const std::shared_ptr<RSTransaction>& rsTransaction = nullptr) override;

View File

@ -266,13 +266,13 @@ public:
void PerformBack() override;
void NotifyForegroundInteractiveStatus(bool interactive);
virtual bool PreNotifyKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) override;
virtual WMError NapiSetUIContent(const std::string& contentInfo, napi_env env,
napi_value storage, bool isdistributed, sptr<IRemoteObject> token, AppExecFwk::Ability* ability) override;
virtual WMError NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage,
BackupAndRestoreType type, sptr<IRemoteObject> token, AppExecFwk::Ability* ability) override;
virtual WMError SetUIContentByName(const std::string& contentInfo, napi_env env, napi_value storage,
AppExecFwk::Ability* ability) override;
virtual WMError SetUIContentByAbc(const std::string& abcPath, napi_env env, napi_value storage,
AppExecFwk::Ability* ability) override;
virtual std::string GetContentInfo() override;
virtual std::string GetContentInfo(BackupAndRestoreType type = BackupAndRestoreType::CONTINUATION) override;
virtual const std::shared_ptr<AbilityRuntime::Context> GetContext() const override;
virtual Ace::UIContent* GetUIContent() const override;
virtual Ace::UIContent* GetUIContentWithId(uint32_t winId) const override;
@ -584,7 +584,7 @@ private:
void UpdateDecorEnable(bool needNotify = false);
WMError SetFloatingMaximize(bool isEnter);
WMError SetUIContentInner(const std::string& contentInfo, napi_env env, napi_value storage,
WindowSetUIContentType type, AppExecFwk::Ability* ability);
WindowSetUIContentType setUIContentType, BackupAndRestoreType restoreType, AppExecFwk::Ability* ability);
std::shared_ptr<std::vector<uint8_t>> GetAbcContent(const std::string& abcPath);
// colorspace, gamut

View File

@ -68,8 +68,8 @@ public:
WMError Hide(uint32_t reason = 0, bool withAnimation = false, bool isFromInnerkits = true) override;
WMError Destroy() override;
virtual WMError Destroy(bool needNotifyServer, bool needClearListener = true);
WMError NapiSetUIContent(const std::string& contentInfo, napi_env env,
napi_value storage, bool isdistributed, sptr<IRemoteObject> token, AppExecFwk::Ability* ability) override;
WMError NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage,
BackupAndRestoreType type, sptr<IRemoteObject> token, AppExecFwk::Ability* ability) override;
WMError SetUIContentByName(const std::string& contentInfo, napi_env env, napi_value storage,
AppExecFwk::Ability* ability) override;
WMError SetUIContentByAbc(const std::string& abcPath, napi_env env, napi_value storage,
@ -98,7 +98,7 @@ public:
uint32_t GetWindowId() const override;
Rect GetRect() const override;
bool GetFocusable() const override;
std::string GetContentInfo() override;
std::string GetContentInfo(BackupAndRestoreType type = BackupAndRestoreType::CONTINUATION) override;
Ace::UIContent* GetUIContent() const override;
Ace::UIContent* GetUIContentWithId(uint32_t winId) const override;
void OnNewWant(const AAFwk::Want& want) override;
@ -222,7 +222,7 @@ public:
WMError UnregisterWindowRectChangeListener(const sptr<IWindowRectChangeListener>& listener) override;
virtual WMError GetCallingWindowWindowStatus(WindowStatus& windowStatus) const override;
virtual WMError GetCallingWindowRect(Rect& rect) const override;
protected:
WMError Connect();
bool IsWindowSessionInvalid() const;
@ -334,9 +334,10 @@ private:
void NotifyAfterPaused();
WMError InitUIContent(const std::string& contentInfo, napi_env env, napi_value storage,
WindowSetUIContentType type, AppExecFwk::Ability* ability, OHOS::Ace::UIContentErrorCode& aceRet);
WindowSetUIContentType setUIContentType, BackupAndRestoreType restoreType, AppExecFwk::Ability* ability,
OHOS::Ace::UIContentErrorCode& aceRet);
WMError SetUIContentInner(const std::string& contentInfo, napi_env env, napi_value storage,
WindowSetUIContentType type, AppExecFwk::Ability* ability);
WindowSetUIContentType setUIContentType, BackupAndRestoreType restoreType, AppExecFwk::Ability* ability);
std::shared_ptr<std::vector<uint8_t>> GetAbcContent(const std::string& abcPath);
void UpdateRectForRotation(const Rect& wmRect, const Rect& preRect, WindowSizeChangeReason wmReason,

View File

@ -354,8 +354,8 @@ void WindowExtensionSessionImpl::NotifyKeyEvent(const std::shared_ptr<MMI::KeyEv
DispatchKeyEventCallback(keyEvent, isConsumed);
}
WMError WindowExtensionSessionImpl::NapiSetUIContent(const std::string& contentInfo,
napi_env env, napi_value storage, bool isdistributed, sptr<IRemoteObject> token, AppExecFwk::Ability* ability)
WMError WindowExtensionSessionImpl::NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage,
BackupAndRestoreType type, sptr<IRemoteObject> token, AppExecFwk::Ability* ability)
{
WLOGFD("WindowExtensionSessionImpl NapiSetUIContent: %{public}s state:%{public}u", contentInfo.c_str(), state_);
if (uiContent_) {

View File

@ -545,26 +545,29 @@ void WindowImpl::OnNewWant(const AAFwk::Want& want)
}
WMError WindowImpl::NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage,
bool isdistributed, sptr<IRemoteObject> token, AppExecFwk::Ability* ability)
BackupAndRestoreType type, sptr<IRemoteObject> token, AppExecFwk::Ability* ability)
{
return SetUIContentInner(contentInfo, env, storage,
isdistributed ? WindowSetUIContentType::DISTRIBUTE : WindowSetUIContentType::DEFAULT, ability);
type == BackupAndRestoreType::NONE ? WindowSetUIContentType::DEFAULT : WindowSetUIContentType::RESTORE,
type, ability);
}
WMError WindowImpl::SetUIContentByName(
const std::string& contentInfo, napi_env env, napi_value storage, AppExecFwk::Ability* ability)
{
return SetUIContentInner(contentInfo, env, storage, WindowSetUIContentType::BY_NAME, ability);
return SetUIContentInner(contentInfo, env, storage, WindowSetUIContentType::BY_NAME,
BackupAndRestoreType::NONE, ability);
}
WMError WindowImpl::SetUIContentByAbc(
const std::string& contentInfo, napi_env env, napi_value storage, AppExecFwk::Ability* ability)
{
return SetUIContentInner(contentInfo, env, storage, WindowSetUIContentType::BY_ABC, ability);
return SetUIContentInner(contentInfo, env, storage, WindowSetUIContentType::BY_ABC,
BackupAndRestoreType::NONE, ability);
}
WMError WindowImpl::SetUIContentInner(const std::string& contentInfo, napi_env env, napi_value storage,
WindowSetUIContentType type, AppExecFwk::Ability* ability)
WindowSetUIContentType setUIContentType, BackupAndRestoreType restoreType, AppExecFwk::Ability* ability)
{
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "loadContent");
if (!IsWindowValid()) {
@ -587,13 +590,14 @@ WMError WindowImpl::SetUIContentInner(const std::string& contentInfo, napi_env e
}
OHOS::Ace::UIContentErrorCode aceRet = OHOS::Ace::UIContentErrorCode::NO_ERRORS;
switch (type) {
switch (setUIContentType) {
default:
case WindowSetUIContentType::DEFAULT:
aceRet = uiContent->Initialize(this, contentInfo, storage);
break;
case WindowSetUIContentType::DISTRIBUTE:
aceRet = uiContent->Restore(this, contentInfo, storage);
case WindowSetUIContentType::RESTORE:
aceRet = uiContent->Restore(this, contentInfo, storage, restoreType == BackupAndRestoreType::CONTINUATION ?
Ace::ContentInfoType::CONTINUATION : Ace::ContentInfoType::APP_RECOVERY);
break;
case WindowSetUIContentType::BY_NAME:
aceRet = uiContent->InitializeByName(this, contentInfo, storage);
@ -682,14 +686,20 @@ Ace::UIContent* WindowImpl::GetUIContentWithId(uint32_t winId) const
return nullptr;
}
std::string WindowImpl::GetContentInfo()
std::string WindowImpl::GetContentInfo(BackupAndRestoreType type)
{
WLOGFD("GetContentInfo");
if (type != BackupAndRestoreType::CONTINUATION && type != BackupAndRestoreType::APP_RECOVERY) {
WLOGFE("Invalid type %{public}d", type);
return "";
}
if (uiContent_ == nullptr) {
WLOGFE("fail to GetContentInfo id: %{public}u", property_->GetWindowId());
return "";
}
return uiContent_->GetContentInfo();
return uiContent_->GetContentInfo(type == BackupAndRestoreType::CONTINUATION ?
Ace::ContentInfoType::CONTINUATION : Ace::ContentInfoType::APP_RECOVERY);
}
ColorSpace WindowImpl::GetColorSpaceFromSurfaceGamut(GraphicColorGamut colorGamut)

View File

@ -209,13 +209,13 @@ void WindowScene::UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configur
mainWindow_->UpdateConfiguration(configuration);
}
std::string WindowScene::GetContentInfo() const
std::string WindowScene::GetContentInfo(BackupAndRestoreType type) const
{
if (mainWindow_ == nullptr) {
WLOGFE("Get content info failed, because main window is null");
return "";
}
return mainWindow_->GetContentInfo();
return mainWindow_->GetContentInfo(type);
}
WMError WindowScene::NotifyMemoryLevel(int32_t level)

View File

@ -746,26 +746,30 @@ void WindowSessionImpl::UpdateTitleButtonVisibility()
}
WMError WindowSessionImpl::NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage,
bool isdistributed, sptr<IRemoteObject> token, AppExecFwk::Ability* ability)
BackupAndRestoreType type, sptr<IRemoteObject> token, AppExecFwk::Ability* ability)
{
return SetUIContentInner(contentInfo, env, storage,
isdistributed ? WindowSetUIContentType::DISTRIBUTE : WindowSetUIContentType::DEFAULT, ability);
type == BackupAndRestoreType::NONE ? WindowSetUIContentType::DEFAULT : WindowSetUIContentType::RESTORE,
type, ability);
}
WMError WindowSessionImpl::SetUIContentByName(
const std::string& contentInfo, napi_env env, napi_value storage, AppExecFwk::Ability* ability)
{
return SetUIContentInner(contentInfo, env, storage, WindowSetUIContentType::BY_NAME, ability);
return SetUIContentInner(contentInfo, env, storage, WindowSetUIContentType::BY_NAME,
BackupAndRestoreType::NONE, ability);
}
WMError WindowSessionImpl::SetUIContentByAbc(
const std::string& contentInfo, napi_env env, napi_value storage, AppExecFwk::Ability* ability)
{
return SetUIContentInner(contentInfo, env, storage, WindowSetUIContentType::BY_ABC, ability);
return SetUIContentInner(contentInfo, env, storage, WindowSetUIContentType::BY_ABC,
BackupAndRestoreType::NONE, ability);
}
WMError WindowSessionImpl::InitUIContent(const std::string& contentInfo, napi_env env, napi_value storage,
WindowSetUIContentType type, AppExecFwk::Ability* ability, OHOS::Ace::UIContentErrorCode& aceRet)
WindowSetUIContentType setUIContentType, BackupAndRestoreType restoreType, AppExecFwk::Ability* ability,
OHOS::Ace::UIContentErrorCode& aceRet)
{
{
std::shared_lock<std::shared_mutex> lock(uiContentMutex_);
@ -783,7 +787,7 @@ WMError WindowSessionImpl::InitUIContent(const std::string& contentInfo, napi_en
TLOGE(WmsLogTag::WMS_LIFE, "fail to NapiSetUIContent id: %{public}d", GetPersistentId());
return WMError::WM_ERROR_NULLPTR;
}
switch (type) {
switch (setUIContentType) {
default:
case WindowSetUIContentType::DEFAULT:
if (isUIExtensionAbilityProcess_ && property_->GetExtensionFlag() == true) {
@ -793,8 +797,9 @@ WMError WindowSessionImpl::InitUIContent(const std::string& contentInfo, napi_en
}
aceRet = uiContent->Initialize(this, contentInfo, storage);
break;
case WindowSetUIContentType::DISTRIBUTE:
aceRet = uiContent->Restore(this, contentInfo, storage);
case WindowSetUIContentType::RESTORE:
aceRet = uiContent->Restore(this, contentInfo, storage, restoreType == BackupAndRestoreType::CONTINUATION ?
Ace::ContentInfoType::CONTINUATION : Ace::ContentInfoType::APP_RECOVERY);
break;
case WindowSetUIContentType::BY_NAME:
aceRet = uiContent->InitializeByName(this, contentInfo, storage);
@ -815,7 +820,7 @@ WMError WindowSessionImpl::InitUIContent(const std::string& contentInfo, napi_en
}
WMError WindowSessionImpl::SetUIContentInner(const std::string& contentInfo, napi_env env, napi_value storage,
WindowSetUIContentType type, AppExecFwk::Ability* ability)
WindowSetUIContentType setUIContentType, BackupAndRestoreType restoreType, AppExecFwk::Ability* ability)
{
TLOGI(WmsLogTag::WMS_LIFE, "NapiSetUIContent: %{public}s state:%{public}u", contentInfo.c_str(), state_);
if (IsWindowSessionInvalid()) {
@ -824,7 +829,7 @@ WMError WindowSessionImpl::SetUIContentInner(const std::string& contentInfo, nap
return WMError::WM_ERROR_INVALID_WINDOW;
}
OHOS::Ace::UIContentErrorCode aceRet = OHOS::Ace::UIContentErrorCode::NO_ERRORS;
WMError initUIContentRet = InitUIContent(contentInfo, env, storage, type, ability, aceRet);
WMError initUIContentRet = InitUIContent(contentInfo, env, storage, setUIContentType, restoreType, ability, aceRet);
if (initUIContentRet != WMError::WM_OK) {
return initUIContentRet;
}
@ -1193,15 +1198,21 @@ Orientation WindowSessionImpl::GetRequestedOrientation()
return property_->GetRequestedOrientation();
}
std::string WindowSessionImpl::GetContentInfo()
std::string WindowSessionImpl::GetContentInfo(BackupAndRestoreType type)
{
WLOGFD("GetContentInfo");
if (type != BackupAndRestoreType::CONTINUATION && type != BackupAndRestoreType::APP_RECOVERY) {
WLOGFE("Invalid type %{public}d", type);
return "";
}
std::shared_lock<std::shared_mutex> lock(uiContentMutex_);
if (uiContent_ == nullptr) {
WLOGFE("fail to GetContentInfo id: %{public}d", GetPersistentId());
return "";
}
return uiContent_->GetContentInfo();
return uiContent_->GetContentInfo(type == BackupAndRestoreType::CONTINUATION ?
Ace::ContentInfoType::CONTINUATION : Ace::ContentInfoType::APP_RECOVERY);
}
Ace::UIContent* WindowSessionImpl::GetUIContent() const

View File

@ -2185,7 +2185,7 @@ HWTEST_F(WindowImplTest, GetContentInfo, Function | SmallTest | Level3)
ASSERT_EQ(std::string(""), window->GetContentInfo());
window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window->uiContent_.get());
EXPECT_CALL(*content, GetContentInfo()).Times(1).WillOnce(Return("info"));
EXPECT_CALL(*content, GetContentInfo(_)).Times(1).WillOnce(Return("info"));
ASSERT_EQ(std::string("info"), window->GetContentInfo());
EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
EXPECT_CALL(*content, Destroy());

View File

@ -1961,7 +1961,8 @@ HWTEST_F(WindowSessionImplTest, SetUIContentInner, Function | SmallTest | Level2
ASSERT_NE(window, nullptr);
window->property_->SetPersistentId(1);
std::string url = "";
WMError res1 = window->SetUIContentInner(url, nullptr, nullptr, WindowSetUIContentType::DEFAULT, nullptr);
WMError res1 = window->SetUIContentInner(url, nullptr, nullptr, WindowSetUIContentType::DEFAULT,
BackupAndRestoreType::NONE, nullptr);
ASSERT_EQ(res1, WMError::WM_ERROR_INVALID_WINDOW);
GTEST_LOG_(INFO) << "WindowSessionImplTest: SetUIContentInner end";
}
@ -1986,7 +1987,7 @@ HWTEST_F(WindowSessionImplTest, TestGetUIContentWithId, Function | SmallTest | L
ASSERT_NE(nullptr, session);
ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
ASSERT_EQ(nullptr, window->GetUIContentWithId(102));
ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
GTEST_LOG_(INFO) << "WindowSessionImplTest: TestGetUIContentWithId end";
@ -2196,7 +2197,8 @@ HWTEST_F(WindowSessionImplTest, NapiSetUIContent, Function | SmallTest | Level2)
window->SetUIContentByName(url, nullptr, nullptr, nullptr);
window->SetUIContentByAbc(url, nullptr, nullptr, nullptr);
WMError res1 = window->NapiSetUIContent(url, nullptr, nullptr, true, nullptr, ability);
WMError res1 = window->NapiSetUIContent(url, nullptr, nullptr, BackupAndRestoreType::CONTINUATION,
nullptr, ability);
ASSERT_EQ(res1, WMError::WM_ERROR_INVALID_WINDOW);
}
@ -2215,7 +2217,8 @@ HWTEST_F(WindowSessionImplTest, GetAbcContent, Function | SmallTest | Level2)
ASSERT_NE(window, nullptr);
window->property_->SetPersistentId(1);
std::string url = "";
WMError res = window->SetUIContentInner(url, nullptr, nullptr, WindowSetUIContentType::BY_ABC, nullptr);
WMError res = window->SetUIContentInner(url, nullptr, nullptr, WindowSetUIContentType::BY_ABC,
BackupAndRestoreType::NONE, nullptr);
ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
}