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_RUNTIME_ABILITY_WINDOW_H
17 #define OHOS_ABILITY_RUNTIME_ABILITY_WINDOW_H
18 
19 #include <map>
20 
21 #include "nocopyable.h"
22 #include "session_info.h"
23 #include "window.h"
24 #include "window_option.h"
25 #include "window_scene.h"
26 #include "foundation/ability/ability_runtime/interfaces/kits/native/ability/ability_runtime/ability_context.h"
27 
28 #ifdef SUPPORT_GRAPHICS
29 #include "pixel_map.h"
30 #endif
31 
32 namespace OHOS {
33 namespace AppExecFwk {
34 class IAbilityEvent;
35 class Ability;
36 class AbilityHandler;
37 class AbilityWindow : public NoCopyable {
38 public:
39     AbilityWindow();
40     virtual ~AbilityWindow();
41 
42     /**
43      * @brief Init the AbilityWindow object.
44      *
45      * @param handler The EventHandler of the Ability the AbilityWindow belong.
46      */
47     void Init(std::shared_ptr<AbilityHandler> &handler, std::shared_ptr<Ability> ability);
48 
49     bool InitWindow(std::shared_ptr<AbilityRuntime::AbilityContext> &abilityContext,
50         sptr<Rosen::IWindowLifeCycle> &listener, int32_t displayId, sptr<Rosen::WindowOption> option, bool isPrivacy);
51 
52     /**
53      * @brief Called when this ability is background.
54      *
55      * @param sceneFlag flag for screen, lock or unlock, power on or off.
56      */
57     void OnPostAbilityBackground(uint32_t sceneFlag);
58 
59     /**
60      * @brief Called when this ability is foreground.
61      *
62      * @param sceneFlag flag for screen, lock or unlock, power on or off.
63      */
64     void OnPostAbilityForeground(uint32_t sceneFlag);
65 
66     /**
67      * @brief Called when this ability is stopped.
68      *
69      */
70     void OnPostAbilityStop();
71 
72     /**
73      * @brief Get the window belong to the ability.
74      *
75      * @return Returns a Window object pointer.
76      */
77     const sptr<Rosen::Window> GetWindow();
78 
79 #ifdef SUPPORT_GRAPHICS
80     /**
81      * @brief Set mission label of this ability.
82      *
83      * @param label the label of this ability.
84      * @return Returns ERR_OK if success.
85      */
86     virtual ErrCode SetMissionLabel(const std::string &label);
87 
88     /**
89      * @brief Set mission icon of this ability.
90      *
91      * @param icon the icon of this ability.
92      * @return Returns ERR_OK if success.
93      */
94     virtual ErrCode SetMissionIcon(const std::shared_ptr<OHOS::Media::PixelMap> &icon);
95     void SetSessionToken(sptr<IRemoteObject> sessionToken);
96 #endif
97 
98 private:
99 #ifdef SUPPORT_GRAPHICS
100     sptr<IRemoteObject> GetSessionToken();
101 #endif
102 
103 private:
104     std::shared_ptr<AbilityHandler> handler_ = nullptr;
105     std::weak_ptr<IAbilityEvent> ability_;
106     std::shared_ptr<Rosen::WindowScene> windowScene_;
107     bool isWindowAttached = false;
108     std::mutex sessionTokenMutex_;
109     sptr<IRemoteObject> sessionToken_ = nullptr;
110 };
111 }  // namespace AppExecFwk
112 }  // namespace OHOS
113 #endif  // OHOS_ABILITY_RUNTIME_ABILITY_WINDOW_H
114