• 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 #ifndef OHOS_AAFWK_ABILITY_SCHEDULER_INTERFACE_H
17 #define OHOS_AAFWK_ABILITY_SCHEDULER_INTERFACE_H
18 
19 #include "foundation/aafwk/standard/interfaces/innerkits/app_manager/include/appmgr/configuration.h"
20 #include <iremote_broker.h>
21 #include "lifecycle_state_info.h"
22 #include "pac_map.h"
23 #include "want.h"
24 
25 namespace OHOS {
26 namespace NativeRdb {
27 class AbsSharedResultSet;
28 class DataAbilityPredicates;
29 class ValuesBucket;
30 }
31 namespace AppExecFwk {
32 class DataAbilityResult;
33 class DataAbilityOperation;
34 }
35 namespace AAFwk {
36 using OHOS::AppExecFwk::PacMap;
37 using OHOS::AppExecFwk::Configuration;
38 
39 class IDataAbilityObserver;
40 
41 /**
42  * @class IAbilityScheduler
43  * IAbilityScheduler is used to schedule ability kit lifecycle.
44  */
45 class IAbilityScheduler : public OHOS::IRemoteBroker {
46 public:
47     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.aafwk.AbilityScheduler");
48 
49     /*
50      * ScheduleAbilityTransaction,  schedule ability to transform life state.
51      *
52      * @param Want, Special Want for service type's ability.
53      * @param targetState, The lifecycle state to be transformed
54      */
55     virtual void ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState) = 0;
56 
57     /*
58      * SendResult, Send result to app when ability is terminated with result want.
59      *
60      * @param requestCode, the requestCode of the ability to start.
61      * @param resultCode, the resultCode of the ability to terminate.
62      * @param resultWant, the want of the ability to terminate.
63      */
64     virtual void SendResult(int requestCode, int resultCode, const Want &resultWant) = 0;
65 
66     /*
67      * ScheduleConnectAbility,  schedule service ability to connect.
68      *
69      * @param Want, Special Want for service type's ability.
70      */
71     virtual void ScheduleConnectAbility(const Want &want) = 0;
72 
73     /*
74      * ScheduleDisconnectAbility, schedule service ability to disconnect.
75      */
76     virtual void ScheduleDisconnectAbility(const Want &want) = 0;
77 
78     /*
79      * ScheduleCommandAbility, schedule service ability to command.
80      */
81     virtual void ScheduleCommandAbility(const Want &want, bool restart, int startId) = 0;
82 
83     /*
84      * ScheduleSaveAbilityState, scheduling save ability state.
85      */
86     virtual void ScheduleSaveAbilityState() = 0;
87 
88     /*
89      * ScheduleRestoreAbilityState, scheduling restore ability state.
90      */
91     virtual void ScheduleRestoreAbilityState(const PacMap &inState) = 0;
92 
93     /*
94      * ScheduleUpdateConfiguration, scheduling update configuration.
95      */
96     virtual void ScheduleUpdateConfiguration(const AppExecFwk::Configuration &config) = 0;
97 
98     /**
99      * @brief Obtains the MIME types of files supported.
100      *
101      * @param uri Indicates the path of the files to obtain.
102      * @param mimeTypeFilter Indicates the MIME types of the files to obtain. This parameter cannot be null.
103      *
104      * @return Returns the matched MIME types. If there is no match, null is returned.
105      */
106     virtual std::vector<std::string> GetFileTypes(const Uri &uri, const std::string &mimeTypeFilter) = 0;
107 
108     /**
109      * @brief Opens a file in a specified remote path.
110      *
111      * @param uri Indicates the path of the file to open.
112      * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access
113      * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing file,
114      * "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing data,
115      *  or "rwt" for read and write access that truncates any existing file.
116      *
117      * @return Returns the file descriptor.
118      */
119     virtual int OpenFile(const Uri &uri, const std::string &mode) = 0;
120 
121     /**
122      * @brief This is like openFile, open a file that need to be able to return sub-sections of files,often assets
123      * inside of their .hap.
124      *
125      * @param uri Indicates the path of the file to open.
126      * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access
127      * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing file,
128      * "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing
129      * data, or "rwt" for read and write access that truncates any existing file.
130      *
131      * @return Returns the RawFileDescriptor object containing file descriptor.
132      */
133     virtual int OpenRawFile(const Uri &uri, const std::string &mode) = 0;
134 
135     /**
136      * @brief Inserts a single data record into the database.
137      *
138      * @param uri Indicates the path of the data to operate.
139      * @param value  Indicates the data record to insert. If this parameter is null, a blank row will be inserted.
140      *
141      * @return Returns the index of the inserted data record.
142      */
143     virtual int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value) = 0;
144 
145     /**
146      * @brief Updates data records in the database.
147      *
148      * @param uri Indicates the path of data to update.
149      * @param value Indicates the data to update. This parameter can be null.
150      * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
151      *
152      * @return Returns the number of data records updated.
153      */
154     virtual int Update(const Uri &uri, const NativeRdb::ValuesBucket &value,
155         const NativeRdb::DataAbilityPredicates &predicates) = 0;
156 
157     /**
158      * @brief Deletes one or more data records from the database.
159      *
160      * @param uri Indicates the path of the data to operate.
161      * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
162      *
163      * @return Returns the number of data records deleted.
164      */
165     virtual int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) = 0;
166 
167     /**
168      * @brief Calls the method of the Data ability.
169      *
170      * @param uri Indicates the Data ability of the method to call.
171      * @param method Indicates the method to call.
172      * @param arg Indicates the parameter of the String type.
173      * @param pacMap Defines a PacMap object for storing a series of values.
174      *
175      * @return Returns the call result.
176      */
177     virtual std::shared_ptr<AppExecFwk::PacMap> Call(
178         const Uri &uri, const std::string &method, const std::string &arg, const AppExecFwk::PacMap &pacMap) = 0;
179 
180     /**
181      * @brief Deletes one or more data records from the database.
182      *
183      * @param uri Indicates the path of data to query.
184      * @param columns Indicates the columns to query. If this parameter is null, all columns are queried.
185      * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
186      *
187      * @return Returns the query result.
188      */
189     virtual std::shared_ptr<NativeRdb::AbsSharedResultSet> Query(
190         const Uri &uri, std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates) = 0;
191 
192     /**
193      * @brief Obtains the MIME type matching the data specified by the URI of the Data ability. This method should be
194      * implemented by a Data ability. Data abilities supports general data types, including text, HTML, and JPEG.
195      *
196      * @param uri Indicates the URI of the data.
197      *
198      * @return Returns the MIME type that matches the data specified by uri.
199      */
200     virtual std::string GetType(const Uri &uri) = 0;
201 
202     /**
203      * @brief Reloads data in the database.
204      *
205      * @param uri Indicates the position where the data is to reload. This parameter is mandatory.
206      * @param extras Indicates the PacMap object containing the additional parameters to be passed in this call. This
207      * parameter can be null. If a custom Sequenceable object is put in the PacMap object and will be transferred across
208      * processes, you must call BasePacMap.setClassLoader(ClassLoader) to set a class loader for the custom object.
209      *
210      * @return Returns true if the data is successfully reloaded; returns false otherwise.
211      */
212     virtual bool Reload(const Uri &uri, const PacMap &extras) = 0;
213 
214     /**
215      * @brief Inserts multiple data records into the database.
216      *
217      * @param uri Indicates the path of the data to operate.
218      * @param values Indicates the data records to insert.
219      *
220      * @return Returns the number of data records inserted.
221      */
222     virtual int BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values) = 0;
223 
224     /**
225      * @brief Registers an observer to DataObsMgr specified by the given Uri.
226      *
227      * @param uri, Indicates the path of the data to operate.
228      * @param dataObserver, Indicates the IDataAbilityObserver object.
229      *
230      * @return Return true if success. otherwise return false.
231      */
232     virtual bool ScheduleRegisterObserver(const Uri &uri, const sptr<IDataAbilityObserver> &dataObserver) = 0;
233 
234     /**
235      * @brief Deregisters an observer used for DataObsMgr specified by the given Uri.
236      *
237      * @param uri, Indicates the path of the data to operate.
238      * @param dataObserver, Indicates the IDataAbilityObserver object.
239      *
240      * @return Return true if success. otherwise return false.
241      */
242     virtual bool ScheduleUnregisterObserver(const Uri &uri, const sptr<IDataAbilityObserver> &dataObserver) = 0;
243 
244 #ifdef SUPPORT_GRAPHICS
245     virtual void NotifyMultiWinModeChanged(int32_t winModeKey, bool flag) = 0;
246 
247     /**
248      * @brief notify this ability is top active ability.
249      *
250      * @param flag true: Indicates this ability is top active ability
251      */
252     virtual void NotifyTopActiveAbilityChanged(bool flag) = 0;
253 #endif
254 
255     /**
256      * @brief Notifies the registered observers of a change to the data resource specified by Uri.
257      *
258      * @param uri, Indicates the path of the data to operate.
259      *
260      * @return Return true if success. otherwise return false.
261      */
262     virtual bool ScheduleNotifyChange(const Uri &uri) = 0;
263     /**
264      * @brief Converts the given uri that refer to the Data ability into a normalized URI. A normalized URI can be used
265      * across devices, persisted, backed up, and restored. It can refer to the same item in the Data ability even if the
266      * context has changed. If you implement URI normalization for a Data ability, you must also implement
267      * denormalizeUri(ohos.utils.net.Uri) to enable URI denormalization. After this feature is enabled, URIs passed to
268      * any method that is called on the Data ability must require normalization verification and denormalization. The
269      * default implementation of this method returns null, indicating that this Data ability does not support URI
270      * normalization.
271      *
272      * @param uri Indicates the Uri object to normalize.
273      *
274      * @return Returns the normalized Uri object if the Data ability supports URI normalization; returns null otherwise.
275      */
276     virtual Uri NormalizeUri(const Uri &uri) = 0;
277 
278     /**
279      * @brief Converts the given normalized uri generated by normalizeUri(ohos.utils.net.Uri) into a denormalized one.
280      * The default implementation of this method returns the original URI passed to it.
281      *
282      * @param uri uri Indicates the Uri object to denormalize.
283      *
284      * @return Returns the denormalized Uri object if the denormalization is successful; returns the original Uri passed
285      * to this method if there is nothing to do; returns null if the data identified by the original Uri cannot be found
286      * in the current environment.
287      */
288     virtual Uri DenormalizeUri(const Uri &uri) = 0;
289     virtual std::vector<std::shared_ptr<AppExecFwk::DataAbilityResult>> ExecuteBatch(
290         const std::vector<std::shared_ptr<AppExecFwk::DataAbilityOperation>> &operations) = 0;
291     virtual void ContinueAbility(const std::string& deviceId) = 0;
292     virtual void NotifyContinuationResult(int32_t result) = 0;
293 
294     virtual void DumpAbilityInfo(const std::vector<std::string> &params, std::vector<std::string> &info) = 0;
295 
296     virtual sptr<IRemoteObject> CallRequest() = 0;
297 
298     enum {
299         // ipc id for scheduling ability to a state of life cycle
300         SCHEDULE_ABILITY_TRANSACTION = 0,
301 
302         // ipc id for sending result to caller
303         SEND_RESULT,
304 
305         // ipc id for scheduling service ability to connect
306         SCHEDULE_ABILITY_CONNECT,
307 
308         // ipc id for scheduling service ability to disconnect
309         SCHEDULE_ABILITY_DISCONNECT,
310 
311         // ipc id for scheduling service ability to command
312         SCHEDULE_ABILITY_COMMAND,
313 
314         // ipc id for scheduling save ability state
315         SCHEDULE_SAVE_ABILITY_STATE,
316 
317         // ipc id for scheduling restore ability state
318         SCHEDULE_RESTORE_ABILITY_STATE,
319 
320         // ipc id for scheduling getFileTypes
321         SCHEDULE_GETFILETYPES,
322 
323         // ipc id for scheduling openFile
324         SCHEDULE_OPENFILE,
325 
326         // ipc id for scheduling openRawFile
327         SCHEDULE_OPENRAWFILE,
328 
329         // ipc id for scheduling insert
330         SCHEDULE_INSERT,
331 
332         // ipc id for scheduling update
333         SCHEDULE_UPDATE,
334 
335         // ipc id for scheduling delete
336         SCHEDULE_DELETE,
337 
338         // ipc id for scheduling query
339         SCHEDULE_QUERY,
340 
341         // ipc id for scheduling getType
342         SCHEDULE_GETTYPE,
343 
344         // ipc id for scheduling Reload
345         SCHEDULE_RELOAD,
346 
347         // ipc id for scheduling BatchInsert​
348         SCHEDULE_BATCHINSERT,
349 
350         // ipc id for dataAbilityObServer Register
351         SCHEDULE_REGISTEROBSERVER,
352 
353         // ipc id for dataAbilityObServer UnReguster
354         SCHEDULE_UNREGISTEROBSERVER,
355 
356         // ipc id for dataAbilityObServer change
357         SCHEDULE_NOTIFYCHANGE,
358 
359         // ipc id for scheduling multi window changed
360         MULTI_WIN_CHANGED,
361 
362         // ipc id for scheduling update configuration
363         SCHEDULE_UPDATE_CONFIGURATION,
364 
365         // ipc id for notify this ability is top active
366         TOP_ACTIVE_ABILITY_CHANGED,
367         // ipc id for scheduling NormalizeUri
368         SCHEDULE_NORMALIZEURI,
369 
370         // ipc id for scheduling DenormalizeUri
371         SCHEDULE_DENORMALIZEURI,
372 
373         // ipc id for scheduling ExecuteBatch
374         SCHEDULE_EXECUTEBATCH,
375 
376         // ipc id for notify continuation result
377         NOTIFY_CONTINUATION_RESULT,
378 
379 		// ipc id for scheduling call request
380         REQUEST_CALL_REMOTE,
381 
382         // ipc id for continue ability
383         CONTINUE_ABILITY,
384 
385         // ipc id for dump ability runner
386         DUMP_ABILITY_RUNNER_INNER,
387 
388         SCHEDULE_CALL
389     };
390 };
391 }  // namespace AAFwk
392 }  // namespace OHOS
393 #endif  // OHOS_AAFWK_ABILITY_SCHEDULER_INTERFACE_H
394