1 /* 2 * Copyright (c) 2021-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ABILITY_RUNTIME_START_OPTIONS_H 17 #define OHOS_ABILITY_RUNTIME_START_OPTIONS_H 18 19 #include <string> 20 21 #include "ability_info.h" 22 #include "ability_window_configuration.h" 23 #include "parcel.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 struct WindowCreateParams; 28 } 29 30 namespace AbilityRuntime { 31 constexpr int32_t USER_CANCEL = -7; 32 using OnRequestResult = std::function<void(const AppExecFwk::ElementName&, const std::string&)>; 33 using OnAtomicRequestSuccess = std::function<void(const std::string&)>; 34 using OnAtomicRequestFailure = std::function<void(const std::string&, int32_t, const std::string&)>; 35 struct OnRequestResultElement { 36 std::string requestId_; 37 OnRequestResult onRequestSuccess_; 38 OnRequestResult onRequestFailure_; 39 OnRequestResultElementOnRequestResultElement40 OnRequestResultElement(const std::string &requestId, OnRequestResult onRequestSucc, 41 OnRequestResult onRequestFail) : requestId_(requestId), onRequestSuccess_(onRequestSucc), 42 onRequestFailure_(onRequestFail) 43 {} 44 }; 45 struct OnAtomicRequestResult { 46 std::string requestId_; 47 std::string appId_; 48 OnAtomicRequestSuccess onRequestSuccess_; 49 OnAtomicRequestFailure onRequestFailure_; 50 OnAtomicRequestResultOnAtomicRequestResult51 OnAtomicRequestResult(const std::string &requestId, std::string appId, OnAtomicRequestSuccess onRequestSucc, 52 OnAtomicRequestFailure onRequestFail) : requestId_(requestId), appId_(appId), onRequestSuccess_(onRequestSucc), 53 onRequestFailure_(onRequestFail) 54 {} 55 }; 56 enum class FailureCode { 57 FAILURE_CODE_SYSTEM_MALFUNCTION = 0, 58 FAILURE_CODE_USER_CANCEL = 1, 59 FAILURE_CODE_USER_REFUSE = 2, 60 }; 61 } 62 63 namespace AAFwk { 64 class ProcessOptions; 65 class StartWindowOption; 66 67 class StartOptions final : public Parcelable, public std::enable_shared_from_this<StartOptions> { 68 public: 69 const int32_t DEFAULT_DISPLAY_ID {0}; 70 bool windowLeftUsed_ = false; 71 bool windowTopUsed_ = false; 72 bool windowWidthUsed_ = false; 73 bool windowHeightUsed_ = false; 74 bool minWindowWidthUsed_ = false; 75 bool minWindowHeightUsed_ = false; 76 bool maxWindowWidthUsed_ = false; 77 bool maxWindowHeightUsed_ = false; 78 std::shared_ptr<ProcessOptions> processOptions = nullptr; 79 std::shared_ptr<StartWindowOption> startWindowOption = nullptr; 80 std::vector<AppExecFwk::SupportWindowMode> supportWindowModes_; 81 std::string requestId_; 82 std::shared_ptr<Rosen::WindowCreateParams> windowCreateParams_ = nullptr; 83 84 StartOptions() = default; 85 ~StartOptions() = default; 86 StartOptions(const StartOptions &other); 87 StartOptions &operator=(const StartOptions &other); 88 89 bool ReadFromParcel(Parcel &parcel); 90 virtual bool Marshalling(Parcel &parcel) const override; 91 bool MarshallingTwo(Parcel &parcel) const; 92 static StartOptions *Unmarshalling(Parcel &parcel); 93 94 void SetWindowMode(int32_t windowMode); 95 int32_t GetWindowMode() const; 96 97 void SetDisplayID(int32_t displayId); 98 int32_t GetDisplayID() const; 99 100 void SetWithAnimation(bool withAnimation); 101 bool GetWithAnimation() const; 102 103 void SetWindowFocused(bool windowFocused); 104 int32_t GetWindowFocused() const; 105 106 void SetHideStartWindow(bool hideStartWindow); 107 bool GetHideStartWindow() const; 108 109 void SetWindowLeft(int32_t windowLeft); 110 int32_t GetWindowLeft() const; 111 112 void SetWindowTop(int32_t windowTop); 113 int32_t GetWindowTop() const; 114 115 void SetWindowWidth(int32_t windowWidth); 116 int32_t GetWindowWidth() const; 117 118 void SetWindowHeight(int32_t windowHeight); 119 int32_t GetWindowHeight() const; 120 121 void SetMinWindowWidth(int32_t minWindowWidth); 122 int32_t GetMinWindowWidth() const; 123 124 void SetMinWindowHeight(int32_t minWindowHeight); 125 int32_t GetMinWindowHeight() const; 126 127 void SetMaxWindowWidth(int32_t maxWindowWidth); 128 int32_t GetMaxWindowWidth() const; 129 130 void SetMaxWindowHeight(int32_t maxWindowHeight); 131 int32_t GetMaxWindowHeight() const; 132 private: 133 bool withAnimation_ = true; 134 bool windowFocused_ = true; 135 bool hideStartWindow_ = false; 136 int32_t windowMode_ = AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED; 137 int32_t displayId_ = -1; 138 int32_t windowLeft_ = 0; 139 int32_t windowTop_ = 0; 140 int32_t windowWidth_ = 0; 141 int32_t windowHeight_ = 0; 142 int32_t minWindowWidth_ = 0; 143 int32_t minWindowHeight_ = 0; 144 int32_t maxWindowWidth_ = 0; 145 int32_t maxWindowHeight_ = 0; 146 }; 147 } // namespace AAFwk 148 } // namespace OHOS 149 #endif // OHOS_ABILITY_RUNTIME_START_OPTIONS_H 150