• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 INPUTMETHOD_EXTENSION_CONTEXT_H
17 #define INPUTMETHOD_EXTENSION_CONTEXT_H
18 
19 #include "ability_connect_callback.h"
20 #include "connection_manager.h"
21 #include "extension_context.h"
22 #include "start_options.h"
23 #include "want.h"
24 
25 namespace OHOS {
26 namespace AbilityRuntime {
27 /**
28  * @brief context supply for inputmethod
29  *
30  */
31 class InputMethodExtensionContext : public ExtensionContext {
32 public:
33     InputMethodExtensionContext() = default;
34     virtual ~InputMethodExtensionContext() = default;
35 
36     /**
37    * @brief Starts a new ability.
38    * An ability using the AbilityInfo.AbilityType.INPUTMETHOD or
39    * AbilityInfo.AbilityType.PAGE template uses this method to start a specific
40    * ability. The system locates the target ability from installed abilities
41    * based on the value of the want parameter and then starts it. You can
42    * specify the ability to start using the want parameter.
43    *
44    * @param want Indicates the Want containing information about the target
45    * ability to start.
46    *
47    * @return errCode ERR_OK on success, others on failure.
48    */
49     ErrCode StartAbility(const AAFwk::Want &want) const;
50 
51     ErrCode StartAbility(const AAFwk::Want &want, const AAFwk::StartOptions &startOptions) const;
52 
53     /**
54    * @brief Connects the current ability to an ability using the
55    * AbilityInfo.AbilityType.INPUTMETHOD template.
56    *
57    * @param want Indicates the want containing information about the ability to
58    * connect
59    *
60    * @param conn Indicates the callback object when the target ability is
61    * connected.
62    *
63    * @return True means success and false means failure
64    */
65     bool ConnectAbility(const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) const;
66 
67     /**
68    * @brief Starts a new ability.
69    * An ability using the AbilityInfo.AbilityType.INPUTMETHOD or
70    * AbilityInfo.AbilityType.PAGE template uses this method to start a specific
71    * ability. The system locates the target ability from installed abilities
72    * based on the value of the want parameter and then starts it. You can
73    * specify the ability to start using the want parameter.
74    *
75    * @param want Indicates the Want containing information about the target
76    * ability to start.
77    * @param accountId caller user.
78    *
79    * @return errCode ERR_OK on success, others on failure.
80    */
81     ErrCode StartAbilityWithAccount(const AAFwk::Want &want, int accountId) const;
82 
83     ErrCode StartAbilityWithAccount(
84         const AAFwk::Want &want, int accountId, const AAFwk::StartOptions &startOptions) const;
85 
86     /**
87    * @brief Connects the current ability to an ability using the
88    * AbilityInfo.AbilityType.INPUTMETHOD template.
89    *
90    * @param want Indicates the want containing information about the ability to
91    * connect.
92    *
93    * @param accountId caller user.
94    *
95    * @param conn Indicates the callback object when the target ability is
96    * connected.
97    *
98    * @return True means success and false means failure.
99    */
100     bool ConnectAbilityWithAccount(
101         const AAFwk::Want &want, int accountId, const sptr<AbilityConnectCallback> &connectCallback) const;
102 
103     /**
104    * @brief Disconnects the current ability from an ability.
105    *
106    * @param conn Indicates the IAbilityConnection callback object passed by
107    * connectAbility after the connection is set up. The IAbilityConnection
108    * object uniquely identifies a connection between two abilities.
109    *
110    * @return errCode ERR_OK on success, others on failure.
111    */
112     ErrCode DisconnectAbility(const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) const;
113 
114     /**
115    * @brief Destroys the current ability.
116    *
117    * @return errCode ERR_OK on success, others on failure.
118    */
119     ErrCode TerminateAbility();
120 
121     using SelfType = InputMethodExtensionContext;
122     static const size_t CONTEXT_TYPE_ID;
123 
124 protected:
IsContext(size_t contextTypeId)125     bool IsContext(size_t contextTypeId) override
126     {
127         return contextTypeId == CONTEXT_TYPE_ID || ExtensionContext::IsContext(contextTypeId);
128     }
129 
130 private:
131     static int ILLEGAL_REQUEST_CODE;
132     /**
133    * @brief Get Current Ability Type
134    *
135    * @return Current Ability Type
136    */
137     OHOS::AppExecFwk::AbilityType GetAbilityInfoType() const;
138 };
139 } // namespace AbilityRuntime
140 } // namespace OHOS
141 #endif // INPUTMETHOD_EXTENSION_CONTEXT_H