• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_WINDOW_H
17 #define OHOS_ABILITY_WINDOW_H
18 
19 #include <map>
20 
21 #include "nocopyable.h"
22 #include "window.h"
23 #include "window_option.h"
24 #include "window_scene.h"
25 #include "../../ability_runtime/include/ability_context.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 class IAbilityEvent;
30 class Ability;
31 class AbilityHandler;
32 class AbilityWindow : public NoCopyable {
33 public:
34     AbilityWindow();
35     virtual ~AbilityWindow();
36 
37     /**
38      * @brief Init the AbilityWindow object.
39      *
40      * @param handler The EventHandler of the Ability the AbilityWindow belong.
41      */
42     void Init(std::shared_ptr<AbilityHandler> &handler, std::shared_ptr<Ability> ability);
43 
44     /**
45      * @brief Sets the window config for the host ability to create window.
46      *
47      * @param winType Indicates window config.
48      * @param abilityContext Indicates runtime ability context.
49      * @param listener Indicates window lifecycle listener.
50      * @return true if init window success.
51      */
52     bool InitWindow(Rosen::WindowType winType,
53         std::shared_ptr<AbilityRuntime::AbilityContext> &abilityContext,
54         sptr<Rosen::IWindowLifeCycle> &listener, int32_t displayId, sptr<Rosen::WindowOption> option);
55 
56     /**
57      * @brief Called when this ability is started.
58      *
59      */
60     void OnPostAbilityStart();
61 
62     /**
63      * @brief Called when this ability is activated.
64      *
65      */
66     void OnPostAbilityActive();
67 
68     /**
69      * @brief Called when this ability is inactivated.
70      *
71      */
72     void OnPostAbilityInactive();
73 
74     /**
75      * @brief Called when this ability is background.
76      *
77      * @param sceneFlag flag for screen, lock or unlock, power on or off.
78      */
79     void OnPostAbilityBackground(uint32_t sceneFlag);
80 
81     /**
82      * @brief Called when this ability is foreground.
83      *
84      * @param sceneFlag flag for screen, lock or unlock, power on or off.
85      */
86     void OnPostAbilityForeground(uint32_t sceneFlag);
87 
88     /**
89      * @brief Called when this ability is stopped.
90      *
91      */
92     void OnPostAbilityStop();
93 
94     /**
95      * @brief Get the window belong to the ability.
96      *
97      * @return Returns a Window object pointer.
98      */
99     const sptr<Rosen::Window> GetWindow();
100 
101 private:
102     std::shared_ptr<AbilityHandler> handler_ = nullptr;
103     std::weak_ptr<IAbilityEvent> ability_;
104     std::shared_ptr<Rosen::WindowScene> windowScene_;
105     bool isWindowAttached = false;
106     Rosen::WindowType winType_ = Rosen::WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
107 };
108 }  // namespace AppExecFwk
109 }  // namespace OHOS
110 #endif  // OHOS_ABILITY_WINDOW_H