• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #include "app_context.h"
17 #include "hilog_wrapper.h"
18 
19 namespace OHOS {
20 namespace AppExecFwk {
AppContext()21 AppContext::AppContext()
22 {}
~AppContext()23 AppContext::~AppContext()
24 {}
25 
26 /**
27  * @brief Obtains information about the current ability.
28  * The returned information includes the class name, bundle name, and other information about the current ability.
29  *
30  * @return Returns the AbilityInfo object for the current ability.
31  */
GetAbilityInfo()32 const std::shared_ptr<AbilityInfo> AppContext::GetAbilityInfo()
33 {
34     return nullptr;
35 }
36 
37 /**
38  * @brief Starts a new ability.
39  * An ability using the AbilityInfo.AbilityType.SERVICE or AbilityInfo.AbilityType.PAGE template uses this method
40  * to start a specific ability. The system locates the target ability from installed abilities based on the value
41  * of the want parameter and then starts it. You can specify the ability to start using the want parameter.
42  *
43  * @param want Indicates the Want containing information about the target ability to start.
44  *
45  * @param requestCode Indicates the request code returned after the ability using the AbilityInfo.AbilityType.PAGE
46  * template is started. You can define the request code to identify the results returned by abilities. The value
47  * ranges from 0 to 65535. This parameter takes effect only on abilities using the AbilityInfo.AbilityType.PAGE
48  * template.
49  *
50  * @return errCode ERR_OK on success, others on failure.
51  */
StartAbility(const AAFwk::Want & want,int requestCode)52 ErrCode AppContext::StartAbility(const AAFwk::Want &want, int requestCode)
53 {
54     return ERR_INVALID_VALUE;
55 }
56 
57 /**
58  * @brief Starts a new ability with special ability start setting.
59  *
60  * @param want Indicates the Want containing information about the target ability to start.
61  * @param requestCode Indicates the request code returned after the ability is started. You can define the request code
62  * to identify the results returned by abilities. The value ranges from 0 to 65535.
63  * @param abilityStartSetting Indicates the special start setting used in starting ability.
64  *
65  * @return errCode ERR_OK on success, others on failure.
66  */
StartAbility(const Want & want,int requestCode,const AbilityStartSetting & abilityStartSetting)67 ErrCode AppContext::StartAbility(const Want &want, int requestCode,
68     const AbilityStartSetting &abilityStartSetting)
69 {
70     return ERR_INVALID_VALUE;
71 }
72 
73 /**
74  * @brief Destroys another ability you had previously started by calling Ability.startAbilityForResult
75  * (ohos.aafwk.content.Want, int, ohos.aafwk.ability.startsetting.AbilityStartSetting) with the same requestCode passed.
76  *
77  * @param requestCode Indicates the request code passed for starting the ability.
78  *
79  * @return errCode ERR_OK on success, others on failure.
80  */
TerminateAbility(int requestCode)81 ErrCode AppContext::TerminateAbility(int requestCode)
82 {
83     return ERR_INVALID_VALUE;
84 }
85 
86 /**
87  * @brief Destroys the current ability.
88  *
89  * @return errCode ERR_OK on success, others on failure.
90  */
TerminateAbility()91 ErrCode AppContext::TerminateAbility()
92 {
93     return ERR_INVALID_VALUE;
94 }
95 
96 /**
97  * @brief
98  * Destroys this Service ability if the number of times it has been started equals the number represented by the
99  * given {@code startId}. This method is the same as calling {@link #terminateAbility} to destroy this Service
100  * ability, except that this method helps you avoid destroying it if a client has requested a Service
101  * ability startup in {@link ohos.aafwk.ability.Ability#onCommand} but you are unaware of it.
102  *
103  * @param startId Indicates the number of startup times of this Service ability passed to
104  *                {@link ohos.aafwk.ability.Ability#onCommand}. The {@code startId} is
105  *                incremented by 1 every time this ability is started. For example,
106  *                if this ability has been started for six times, the value of {@code startId} is {@code 6}.
107  *
108  * @return Returns {@code true} if the {@code startId} matches the number of startup times
109  *         and this Service ability will be destroyed; returns {@code false} otherwise.
110  */
TerminateAbilityResult(int startId)111 bool AppContext::TerminateAbilityResult(int startId)
112 {
113     return false;
114 }
115 
116 /**
117  * @brief Obtains the bundle name of the ability that called the current ability.
118  * You can use the obtained bundle name to check whether the calling ability is allowed to receive the data you will
119  * send. If you did not use Ability.startAbilityForResult(ohos.aafwk.content.Want, int,
120  * ohos.aafwk.ability.startsetting.AbilityStartSetting) to start the calling ability, null is returned.
121  *
122  * @return Returns the bundle name of the calling ability; returns null if no calling ability is available.
123  */
GetCallingBundle()124 std::string AppContext::GetCallingBundle()
125 {
126     return "";
127 }
128 
129 /**
130  * @brief Connects the current ability to an ability
131  *
132  * @param want Indicates the want containing information about the ability to connect
133  *
134  * @param conn Indicates the callback object when the target ability is connected.
135  *
136  * @return True means success and false means failure
137  */
ConnectAbility(const Want & want,const sptr<AAFwk::IAbilityConnection> & conn)138 bool AppContext::ConnectAbility(const Want &want, const sptr<AAFwk::IAbilityConnection> &conn)
139 {
140     return false;
141 }
142 
143 /**
144  * @brief Disconnects the current ability from an ability
145  *
146  * @param conn Indicates the IAbilityConnection callback object passed by connectAbility after the connection
147  *              is set up. The IAbilityConnection object uniquely identifies a connection between two abilities.
148  *
149  * @return errCode ERR_OK on success, others on failure.
150  */
DisconnectAbility(const sptr<AAFwk::IAbilityConnection> & conn)151 ErrCode AppContext::DisconnectAbility(const sptr<AAFwk::IAbilityConnection> &conn)
152 {
153     return ERR_INVALID_VALUE;
154 }
155 
156 /**
157  * @brief Destroys another ability that uses the AbilityInfo.AbilityType.SERVICE template.
158  * The current ability using either the AbilityInfo.AbilityType.SERVICE or AbilityInfo.AbilityType.PAGE
159  * template can call this method to destroy another ability that uses the AbilityInfo.AbilityType.SERVICE
160  * template. The current ability itself can be destroyed by calling the terminateAbility() method.
161  *
162  * @param want Indicates the Want containing information about the ability to destroy.
163  *
164  * @return Returns true if the ability is destroyed successfully; returns false otherwise.
165  */
StopAbility(const AAFwk::Want & want)166 bool AppContext::StopAbility(const AAFwk::Want &want)
167 {
168     return false;
169 }
170 
GetToken()171 sptr<IRemoteObject> AppContext::GetToken()
172 {
173     return nullptr;
174 }
175 
176 /**
177  * @brief Starts multiple abilities.
178  *
179  * @param wants Indicates the Want containing information array about the target ability to start.
180  */
StartAbilities(const std::vector<AAFwk::Want> & wants)181 void AppContext::StartAbilities(const std::vector<AAFwk::Want> &wants)
182 {}
183 
184 /**
185  * @brief Obtains the unique ID of the mission containing this ability.
186  *
187  * @return Returns the unique mission ID.
188  */
GetMissionId()189 int AppContext::GetMissionId()
190 {
191     return -1;
192 }
193 }  // namespace AppExecFwk
194 }  // namespace OHOS
195