• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_UI_SERVICE_EXTENSION_CONTEXT_H
17 #define OHOS_ABILITY_RUNTIME_UI_SERVICE_EXTENSION_CONTEXT_H
18 
19 #include "extension_context.h"
20 
21 #include "ability_connect_callback.h"
22 #include "connection_manager.h"
23 #include "local_call_container.h"
24 #include "start_options.h"
25 #include "iability_callback.h"
26 #include "want.h"
27 #include "window.h"
28 #ifdef SUPPORT_SCREEN
29 #include "scene_board_judgement.h"
30 #include "ui_content.h"
31 #endif // SUPPORT_SCREEN
32 
33 namespace OHOS {
34 namespace AbilityRuntime {
35 /**
36  * @brief context supply for ui_service
37  *
38  */
39 class UIServiceExtensionContext : public ExtensionContext {
40 public:
41     UIServiceExtensionContext() = default;
42     virtual ~UIServiceExtensionContext() = default;
43 
44     /**
45      * @brief Starts a new ability.
46      * An ability using the AbilityInfo.AbilityType.SERVICE or AbilityInfo.AbilityType.PAGE template uses this method
47      * to start a specific ability. The system locates the target ability from installed abilities based on the value
48      * of the want parameter and then starts it. You can specify the ability to start using the want parameter.
49      *
50      * @param want Indicates the Want containing information about the target ability to start.
51      *
52      * @return errCode ERR_OK on success, others on failure.
53      */
54     ErrCode StartAbility(const AAFwk::Want &want, const AAFwk::StartOptions &startOptions) const;
55 
56     /**
57      * @brief Destroys the current ability.
58      *
59      * @return errCode ERR_OK on success, others on failure.
60      */
61     ErrCode TerminateSelf();
62 
63     void SetWindow(sptr<Rosen::Window> window);
64 
65     sptr<Rosen::Window> GetWindow();
66 
67     /**
68      * @brief Start a new ability using type;
69      * @return errCode ERR_OK on success, others on failure.
70     */
71     ErrCode StartAbilityByType(const std::string &type,
72     AAFwk::WantParams &wantParam, const std::shared_ptr<JsUIExtensionCallback> &uiExtensionCallbacks);
73 
74     /**
75      * @brief Connects the current ServiceExtensionAbility to an ability using
76      * the AbilityInfo.AbilityType.SERVICE template.
77      *
78      * @param want Indicates the want containing information about the ability to connect
79      *
80      * @param conn Indicates the callback object when the target ability is connected.
81      *
82      * @return Returns zero on success, others on failure.
83      */
84     ErrCode ConnectServiceExtensionAbility(
85         const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) const;
86 
87             /**
88      * @brief Disconnects the current ServiceExtensionAbility from an ability.
89      *
90      * @param conn Indicates the IAbilityConnection callback object passed by connectAbility after the connection
91      * is set up. The IAbilityConnection object uniquely identifies a connection between two abilities.
92      *
93      * @return errCode ERR_OK on success, others on failure.
94      */
95     ErrCode DisConnectServiceExtensionAbility(const AAFwk::Want &want,
96         const sptr<AbilityConnectCallback> &connectCallback, int32_t accountId = -1) const;
97 
98     /**
99      * @brief Get ui content object.
100      *
101      * @return UIContent object of ACE.
102      */
103     Ace::UIContent *GetUIContent();
104     using SelfType = UIServiceExtensionContext;
105     static const size_t CONTEXT_TYPE_ID;
106 
107 protected:
IsContext(size_t contextTypeId)108     bool IsContext(size_t contextTypeId) override
109     {
110         return contextTypeId == CONTEXT_TYPE_ID || ExtensionContext::IsContext(contextTypeId);
111     }
112 
113 private:
114     static int ILLEGAL_REQUEST_CODE;
115     sptr<Rosen::Window> window_ = nullptr;
116 };
117 }  // namespace AbilityRuntime
118 }  // namespace OHOS
119 #endif  // OHOS_ABILITY_RUNTIME_UI_SERVICE_EXTENSION_CONTEXT_H
120