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_ABILITY_RUNTIME_ABILITY_SCHEDULER_INTERFACE_H
17 #define OHOS_ABILITY_RUNTIME_ABILITY_SCHEDULER_INTERFACE_H
18 
19 #include <iremote_broker.h>
20 #include "lifecycle_state_info.h"
21 #include "pac_map.h"
22 #include "ui_extension_window_command.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 class IDataAbilityObserver;
38 class SessionInfo;
39 
40 /**
41  * @class IAbilityScheduler
42  * IAbilityScheduler is used to schedule ability kit lifecycle.
43  */
44 class IAbilityScheduler : public OHOS::IRemoteBroker {
45 public:
46     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.aafwk.AbilityScheduler");
47 
48     /*
49      * ScheduleAbilityTransaction,  schedule ability to transform life state.
50      *
51      * @param Want, Special Want for service type's ability.
52      * @param targetState, The lifecycle state to be transformed
53      * @param sessionInfo, The session info
54      */
55     virtual bool ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
56         sptr<SessionInfo> sessionInfo = nullptr) = 0;
57 
58     /*
59      * ScheduleShareData,  schedule ability to share data.
60      *
61      * @param uniqueId, Indicates the uniqueId returned after the ability is started.
62      */
63     virtual void ScheduleShareData(const int32_t &uniqueId) = 0;
64 
65     /*
66      * SendResult, Send result to app when ability is terminated with result want.
67      *
68      * @param requestCode, the requestCode of the ability to start.
69      * @param resultCode, the resultCode of the ability to terminate.
70      * @param resultWant, the want of the ability to terminate.
71      */
72     virtual void SendResult(int requestCode, int resultCode, const Want &resultWant) = 0;
73 
74     /*
75      * ScheduleConnectAbility,  schedule service ability to connect.
76      *
77      * @param Want, Special Want for service type's ability.
78      */
79     virtual void ScheduleConnectAbility(const Want &want) = 0;
80 
81     /*
82      * ScheduleDisconnectAbility, schedule service ability to disconnect.
83      */
84     virtual void ScheduleDisconnectAbility(const Want &want) = 0;
85 
86     /*
87      * ScheduleCommandAbility, schedule service ability to command.
88      */
89     virtual void ScheduleCommandAbility(const Want &want, bool restart, int startId) = 0;
90 
91     virtual void ScheduleCommandAbilityWindow(const Want &want, const sptr<SessionInfo> &sessionInfo,
92         WindowCommand winCmd) = 0;
93 
94     /**
95      * SchedulePrepareTerminateAbility, schedule ability to prepare terminate.
96      */
97     virtual bool SchedulePrepareTerminateAbility() = 0;
98 
99     /*
100      * ScheduleSaveAbilityState, scheduling save ability state.
101      */
102     virtual void ScheduleSaveAbilityState() = 0;
103 
104     /*
105      * ScheduleRestoreAbilityState, scheduling restore ability state.
106      */
107     virtual void ScheduleRestoreAbilityState(const PacMap &inState) = 0;
108 
109     /**
110      * @brief Obtains the MIME types of files supported.
111      *
112      * @param uri Indicates the path of the files to obtain.
113      * @param mimeTypeFilter Indicates the MIME types of the files to obtain. This parameter cannot be null.
114      *
115      * @return Returns the matched MIME types. If there is no match, null is returned.
116      */
117     virtual std::vector<std::string> GetFileTypes(const Uri &uri, const std::string &mimeTypeFilter) = 0;
118 
119     /**
120      * @brief Opens a file in a specified remote path.
121      *
122      * @param uri Indicates the path of the file to open.
123      * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access
124      * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing file,
125      * "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing data,
126      *  or "rwt" for read and write access that truncates any existing file.
127      *
128      * @return Returns the file descriptor.
129      */
130     virtual int OpenFile(const Uri &uri, const std::string &mode) = 0;
131 
132     /**
133      * @brief This is like openFile, open a file that need to be able to return sub-sections of files,often assets
134      * inside of their .hap.
135      *
136      * @param uri Indicates the path of the file to open.
137      * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access
138      * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing file,
139      * "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing
140      * data, or "rwt" for read and write access that truncates any existing file.
141      *
142      * @return Returns the RawFileDescriptor object containing file descriptor.
143      */
144     virtual int OpenRawFile(const Uri &uri, const std::string &mode) = 0;
145 
146     /**
147      * @brief Inserts a single data record into the database.
148      *
149      * @param uri Indicates the path of the data to operate.
150      * @param value  Indicates the data record to insert. If this parameter is null, a blank row will be inserted.
151      *
152      * @return Returns the index of the inserted data record.
153      */
154     virtual int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value) = 0;
155 
156     /**
157      * @brief Updates data records in the database.
158      *
159      * @param uri Indicates the path of data to update.
160      * @param value Indicates the data to update. This parameter can be null.
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 updated.
164      */
165     virtual int Update(const Uri &uri, const NativeRdb::ValuesBucket &value,
166         const NativeRdb::DataAbilityPredicates &predicates) = 0;
167 
168     /**
169      * @brief Deletes one or more data records from the database.
170      *
171      * @param uri Indicates the path of the data to operate.
172      * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
173      *
174      * @return Returns the number of data records deleted.
175      */
176     virtual int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) = 0;
177 
178     /**
179      * @brief Calls the method of the Data ability.
180      *
181      * @param uri Indicates the Data ability of the method to call.
182      * @param method Indicates the method to call.
183      * @param arg Indicates the parameter of the String type.
184      * @param pacMap Defines a PacMap object for storing a series of values.
185      *
186      * @return Returns the call result.
187      */
188     virtual std::shared_ptr<AppExecFwk::PacMap> Call(
189         const Uri &uri, const std::string &method, const std::string &arg, const AppExecFwk::PacMap &pacMap) = 0;
190 
191     /**
192      * @brief Deletes one or more data records from the database.
193      *
194      * @param uri Indicates the path of data to query.
195      * @param columns Indicates the columns to query. If this parameter is null, all columns are queried.
196      * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
197      *
198      * @return Returns the query result.
199      */
200     virtual std::shared_ptr<NativeRdb::AbsSharedResultSet> Query(
201         const Uri &uri, std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates) = 0;
202 
203     /**
204      * @brief Obtains the MIME type matching the data specified by the URI of the Data ability. This method should be
205      * implemented by a Data ability. Data abilities supports general data types, including text, HTML, and JPEG.
206      *
207      * @param uri Indicates the URI of the data.
208      *
209      * @return Returns the MIME type that matches the data specified by uri.
210      */
211     virtual std::string GetType(const Uri &uri) = 0;
212 
213     /**
214      * @brief Reloads data in the database.
215      *
216      * @param uri Indicates the position where the data is to reload. This parameter is mandatory.
217      * @param extras Indicates the PacMap object containing the additional parameters to be passed in this call. This
218      * parameter can be null. If a custom Sequenceable object is put in the PacMap object and will be transferred across
219      * processes, you must call BasePacMap.setClassLoader(ClassLoader) to set a class loader for the custom object.
220      *
221      * @return Returns true if the data is successfully reloaded; returns false otherwise.
222      */
223     virtual bool Reload(const Uri &uri, const PacMap &extras) = 0;
224 
225     /**
226      * @brief Inserts multiple data records into the database.
227      *
228      * @param uri Indicates the path of the data to operate.
229      * @param values Indicates the data records to insert.
230      *
231      * @return Returns the number of data records inserted.
232      */
233     virtual int BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values) = 0;
234 
235     /**
236      * @brief Registers an observer to DataObsMgr specified by the given Uri.
237      *
238      * @param uri, Indicates the path of the data to operate.
239      * @param dataObserver, Indicates the IDataAbilityObserver object.
240      *
241      * @return Return true if success. otherwise return false.
242      */
243     virtual bool ScheduleRegisterObserver(const Uri &uri, const sptr<IDataAbilityObserver> &dataObserver) = 0;
244 
245     /**
246      * @brief Deregisters an observer used for DataObsMgr specified by the given Uri.
247      *
248      * @param uri, Indicates the path of the data to operate.
249      * @param dataObserver, Indicates the IDataAbilityObserver object.
250      *
251      * @return Return true if success. otherwise return false.
252      */
253     virtual bool ScheduleUnregisterObserver(const Uri &uri, const sptr<IDataAbilityObserver> &dataObserver) = 0;
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, uint32_t versionCode) = 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     virtual int CreateModalUIExtension(const Want &want) = 0;
296 
297     virtual void OnExecuteIntent(const Want &want) = 0;
298 
299     virtual void CallRequest() = 0;
300 
301     /**
302      * @brief Update sessionToken.
303      * @param sessionToken The token of session.
304      */
305     virtual void UpdateSessionToken(sptr<IRemoteObject> sessionToken) = 0;
306 
307     enum {
308         // ipc id for scheduling ability to a state of life cycle
309         SCHEDULE_ABILITY_TRANSACTION = 0,
310 
311         // ipc id for sending result to caller
312         SEND_RESULT,
313 
314         // ipc id for scheduling service ability to connect
315         SCHEDULE_ABILITY_CONNECT,
316 
317         // ipc id for scheduling service ability to disconnect
318         SCHEDULE_ABILITY_DISCONNECT,
319 
320         // ipc id for scheduling service ability to command
321         SCHEDULE_ABILITY_COMMAND,
322 
323         SCHEDULE_ABILITY_COMMAND_WINDOW,
324 
325         // ipc id for scheduling save ability state
326         SCHEDULE_SAVE_ABILITY_STATE,
327 
328         // ipc id for scheduling restore ability state
329         SCHEDULE_RESTORE_ABILITY_STATE,
330 
331         // ipc id for scheduling getFileTypes
332         SCHEDULE_GETFILETYPES,
333 
334         // ipc id for scheduling openFile
335         SCHEDULE_OPENFILE,
336 
337         // ipc id for scheduling openRawFile
338         SCHEDULE_OPENRAWFILE,
339 
340         // ipc id for scheduling insert
341         SCHEDULE_INSERT,
342 
343         // ipc id for scheduling update
344         SCHEDULE_UPDATE,
345 
346         // ipc id for scheduling delete
347         SCHEDULE_DELETE,
348 
349         // ipc id for scheduling query
350         SCHEDULE_QUERY,
351 
352         // ipc id for scheduling getType
353         SCHEDULE_GETTYPE,
354 
355         // ipc id for scheduling Reload
356         SCHEDULE_RELOAD,
357 
358         // ipc id for scheduling BatchInsert​
359         SCHEDULE_BATCHINSERT,
360 
361         // ipc id for dataAbilityObServer Register
362         SCHEDULE_REGISTEROBSERVER,
363 
364         // ipc id for dataAbilityObServer UnReguster
365         SCHEDULE_UNREGISTEROBSERVER,
366 
367         // ipc id for dataAbilityObServer change
368         SCHEDULE_NOTIFYCHANGE,
369 
370         // ipc id for scheduling NormalizeUri
371         SCHEDULE_NORMALIZEURI,
372 
373         // ipc id for scheduling DenormalizeUri
374         SCHEDULE_DENORMALIZEURI,
375 
376         // ipc id for scheduling ExecuteBatch
377         SCHEDULE_EXECUTEBATCH,
378 
379         // ipc id for notify continuation result
380         NOTIFY_CONTINUATION_RESULT,
381 
382         // ipc id for scheduling call request
383         REQUEST_CALL_REMOTE,
384 
385         // ipc id for continue ability
386         CONTINUE_ABILITY,
387 
388         // ipc id for dump ability runner
389         DUMP_ABILITY_RUNNER_INNER,
390 
391         SCHEDULE_CALL,
392 
393         SCHEDULE_SHARE_DATA,
394 
395         // ipc id for scheduling service ability to prepare terminate (30)
396         SCHEDULE_ABILITY_PREPARE_TERMINATE,
397 
398         SCHEDULE_ONEXECUTE_INTENT,
399 
400         CREATE_MODAL_UI_EXTENSION,
401 
402         UPDATE_SESSION_TOKEN
403     };
404 };
405 }  // namespace AAFwk
406 }  // namespace OHOS
407 #endif  // OHOS_ABILITY_RUNTIME_ABILITY_SCHEDULER_INTERFACE_H
408