/* * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "start_options.h" #include "hilog_tag_wrapper.h" #include "process_options.h" #include "start_window_option.h" namespace OHOS { namespace AAFwk { constexpr int MAX_SUPPOPRT_WINDOW_MODES_SIZE = 10; StartOptions::StartOptions(const StartOptions &other) { windowMode_ = other.windowMode_; displayId_ = other.displayId_; withAnimation_ = other.withAnimation_; windowLeft_ = other.windowLeft_; windowTop_ = other.windowTop_; windowWidth_ = other.windowWidth_; windowHeight_ = other.windowHeight_; windowLeftUsed_ = other.windowLeftUsed_; windowTopUsed_ = other.windowTopUsed_; windowWidthUsed_ = other.windowWidthUsed_; windowHeightUsed_ = other.windowHeightUsed_; processOptions = other.processOptions; windowFocused_ = other.windowFocused_; startWindowOption = other.startWindowOption; supportWindowModes_ = other.supportWindowModes_; } StartOptions &StartOptions::operator=(const StartOptions &other) { if (this != &other) { windowMode_ = other.windowMode_; displayId_ = other.displayId_; withAnimation_ = other.withAnimation_; windowLeft_ = other.windowLeft_; windowTop_ = other.windowTop_; windowWidth_ = other.windowWidth_; windowHeight_ = other.windowHeight_; windowLeftUsed_ = other.windowLeftUsed_; windowTopUsed_ = other.windowTopUsed_; windowWidthUsed_ = other.windowWidthUsed_; windowHeightUsed_ = other.windowHeightUsed_; processOptions = other.processOptions; windowFocused_ = other.windowFocused_; startWindowOption = other.startWindowOption; supportWindowModes_ = other.supportWindowModes_; } return *this; } bool StartOptions::ReadFromParcel(Parcel &parcel) { SetWindowMode(parcel.ReadInt32()); SetDisplayID(parcel.ReadInt32()); SetWithAnimation(parcel.ReadBool()); SetWindowLeft(parcel.ReadInt32()); SetWindowTop(parcel.ReadInt32()); SetWindowWidth(parcel.ReadInt32()); SetWindowHeight(parcel.ReadInt32()); SetWindowFocused(parcel.ReadBool()); windowLeftUsed_ = parcel.ReadBool(); windowTopUsed_ = parcel.ReadBool(); windowWidthUsed_ = parcel.ReadBool(); windowHeightUsed_ = parcel.ReadBool(); processOptions.reset(parcel.ReadParcelable()); startWindowOption.reset(parcel.ReadParcelable()); auto size = parcel.ReadInt32(); if (size > MAX_SUPPOPRT_WINDOW_MODES_SIZE) { TAG_LOGE(AAFwkTag::ABILITYMGR, "supportWindowModes size exceeds max"); return false; } for (int i = 0; i < size; i++) { supportWindowModes_.emplace_back(AppExecFwk::SupportWindowMode(parcel.ReadInt32())); } return true; } StartOptions *StartOptions::Unmarshalling(Parcel &parcel) { StartOptions *option = new (std::nothrow) StartOptions(); if (option == nullptr) { return nullptr; } if (!option->ReadFromParcel(parcel)) { delete option; option = nullptr; } return option; } bool StartOptions::Marshalling(Parcel &parcel) const { parcel.WriteInt32(GetWindowMode()); parcel.WriteInt32(GetDisplayID()); parcel.WriteBool(GetWithAnimation()); parcel.WriteInt32(GetWindowLeft()); parcel.WriteInt32(GetWindowTop()); parcel.WriteInt32(GetWindowWidth()); parcel.WriteInt32(GetWindowHeight()); parcel.WriteBool(GetWindowFocused()); parcel.WriteBool(windowLeftUsed_); parcel.WriteBool(windowTopUsed_); parcel.WriteBool(windowWidthUsed_); parcel.WriteBool(windowHeightUsed_); if (!parcel.WriteParcelable(processOptions.get())) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Write processOptions failed."); return false; } if (!parcel.WriteParcelable(startWindowOption.get())) { TAG_LOGE(AAFwkTag::ABILITYMGR, "write startWindowOption failed"); return false; } if (!parcel.WriteInt32(supportWindowModes_.size())) { TAG_LOGE(AAFwkTag::ABILITYMGR, "write supportWindowModes_ failed"); return false; } for (auto windowMode : supportWindowModes_) { if (!parcel.WriteInt32(static_cast(windowMode))) { TAG_LOGE(AAFwkTag::ABILITYMGR, "write windowMode failed"); return false; } } return true; } void StartOptions::SetWindowMode(int32_t windowMode) { windowMode_ = windowMode; } int32_t StartOptions::GetWindowMode() const { return windowMode_; } void StartOptions::SetDisplayID(int32_t id) { displayId_ = id; } int32_t StartOptions::GetDisplayID() const { return displayId_; } void StartOptions::SetWithAnimation(bool withAnimation) { withAnimation_ = withAnimation; } bool StartOptions::GetWithAnimation() const { return withAnimation_; } void StartOptions::SetWindowLeft(int32_t windowLeft) { windowLeft_ = windowLeft; } int32_t StartOptions::GetWindowLeft() const { return windowLeft_; } void StartOptions::SetWindowTop(int32_t windowTop) { windowTop_ = windowTop; } int32_t StartOptions::GetWindowTop() const { return windowTop_; } void StartOptions::SetWindowWidth(int32_t windowWidth) { windowWidth_ = windowWidth; } int32_t StartOptions::GetWindowWidth() const { return windowWidth_; } void StartOptions::SetWindowHeight(int32_t windowHeight) { windowHeight_ = windowHeight; } int32_t StartOptions::GetWindowHeight() const { return windowHeight_; } void StartOptions::SetWindowFocused(bool windowFocused) { windowFocused_ = windowFocused; } int32_t StartOptions::GetWindowFocused() const { return windowFocused_; } } // namespace AAFwk } // namespace OHOS