• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 FOUNDATION_APPEXECFWK_OHOS_DATA_ABILITY_IMPL_H
17 #define FOUNDATION_APPEXECFWK_OHOS_DATA_ABILITY_IMPL_H
18 
19 #include "ability_impl.h"
20 
21 namespace OHOS {
22 namespace NativeRdb {
23 class DataAbilityPredicates;
24 class ValuesBucket;
25 }  // namespace NativeRdb
26 namespace AppExecFwk {
27 class DataAbilityImpl final : public AbilityImpl {
28 public:
29     /**
30      * @brief Constructor.
31      *
32      */
33     DataAbilityImpl() = default;
34 
35     /**
36      * @brief Destructor.
37      *
38      */
39     ~DataAbilityImpl() = default;
40 
41     /**
42      * @brief Handling the life cycle switching of PageAbility.
43      *
44      * @param want Indicates the structure containing information about the ability.
45      * @param targetState The life cycle state to switch to.
46      *
47      */
48     void HandleAbilityTransaction(const Want &want, const AAFwk::LifeCycleStateInfo &targetState);
49 
50     /**
51      * @brief Obtains the MIME types of files supported.
52      *
53      * @param uri Indicates the path of the files to obtain.
54      * @param mimeTypeFilter Indicates the MIME types of the files to obtain. This parameter cannot be null.
55      *
56      * @return Returns the matched MIME types. If there is no match, null is returned.
57      */
58     std::vector<std::string> GetFileTypes(const Uri &uri, const std::string &mimeTypeFilter);
59 
60     /**
61      * @brief Opens a file in a specified remote path.
62      *
63      * @param uri Indicates the path of the file to open.
64      * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access
65      * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing file,
66      * "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing data,
67      *  or "rwt" for read and write access that truncates any existing file.
68      *
69      * @return Returns the file descriptor.
70      */
71     int OpenFile(const Uri &uri, const std::string &mode);
72 
73     /**
74      * @brief This is like openFile, open a file that need to be able to return sub-sections of files,often assets
75      * inside of their .hap.
76      *
77      * @param uri Indicates the path of the file to open.
78      * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access
79      * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing file,
80      * "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing
81      * data, or "rwt" for read and write access that truncates any existing file.
82      *
83      * @return Returns the RawFileDescriptor object containing file descriptor.
84      */
85     int OpenRawFile(const Uri &uri, const std::string &mode);
86 
87     /**
88      * @brief Inserts a single data record into the database.
89      *
90      * @param uri Indicates the path of the data to operate.
91      * @param value  Indicates the data record to insert. If this parameter is null, a blank row will be inserted.
92      *
93      * @return Returns the index of the inserted data record.
94      */
95     int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value);
96 
97     /**
98      * @brief Updates data records in the database.
99      *
100      * @param uri Indicates the path of data to update.
101      * @param value Indicates the data to update. This parameter can be null.
102      * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
103      *
104      * @return Returns the number of data records updated.
105      */
106     int Update(
107         const Uri &uri, const NativeRdb::ValuesBucket &value, const NativeRdb::DataAbilityPredicates &predicates);
108 
109     /**
110      * @brief Deletes one or more data records from the database.
111      *
112      * @param uri Indicates the path of the data to operate.
113      * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
114      *
115      * @return Returns the number of data records deleted.
116      */
117     int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates);
118 
119     /**
120      * @brief Deletes one or more data records from the database.
121      *
122      * @param uri Indicates the path of data to query.
123      * @param columns Indicates the columns to query. If this parameter is null, all columns are queried.
124      * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
125      *
126      * @return Returns the query result.
127      */
128     std::shared_ptr<NativeRdb::AbsSharedResultSet> Query(
129         const Uri &uri, std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates);
130 
131     /**
132      * @brief Obtains the MIME type matching the data specified by the URI of the Data ability. This method should be
133      * implemented by a Data ability. Data abilities supports general data types, including text, HTML, and JPEG.
134      *
135      * @param uri Indicates the URI of the data.
136      *
137      * @return Returns the MIME type that matches the data specified by uri.
138      */
139     std::string GetType(const Uri &uri);
140 
141     /**
142      * @brief Reloads data in the database.
143      *
144      * @param uri Indicates the position where the data is to reload. This parameter is mandatory.
145      * @param extras Indicates the PacMap object containing the additional parameters to be passed in this call. This
146      * parameter can be null. If a custom Sequenceable object is put in the PacMap object and will be transferred across
147      * processes, you must call BasePacMap.setClassLoader(ClassLoader) to set a class loader for the custom object.
148      *
149      * @return Returns true if the data is successfully reloaded; returns false otherwise.
150      */
151     bool Reload(const Uri &uri, const PacMap &extras);
152 
153     /**
154      * @brief Inserts multiple data records into the database.
155      *
156      * @param uri Indicates the path of the data to operate.
157      * @param values Indicates the data records to insert.
158      *
159      * @return Returns the number of data records inserted.
160      */
161     int BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values);
162 
163     /**
164      * @brief Converts the given uri that refer to the Data ability into a normalized URI. A normalized URI can be used
165      * across devices, persisted, backed up, and restored. It can refer to the same item in the Data ability even if the
166      * context has changed. If you implement URI normalization for a Data ability, you must also implement
167      * denormalizeUri(ohos.utils.net.Uri) to enable URI denormalization. After this feature is enabled, URIs passed to any
168      * method that is called on the Data ability must require normalization verification and denormalization. The default
169      * implementation of this method returns null, indicating that this Data ability does not support URI normalization.
170      *
171      * @param uri Indicates the Uri object to normalize.
172      *
173      * @return Returns the normalized Uri object if the Data ability supports URI normalization; returns null otherwise.
174      */
175     Uri NormalizeUri(const Uri &uri);
176 
177     /**
178      * @brief Converts the given normalized uri generated by normalizeUri(ohos.utils.net.Uri) into a denormalized one.
179      * The default implementation of this method returns the original URI passed to it.
180      *
181      * @param uri uri Indicates the Uri object to denormalize.
182      *
183      * @return Returns the denormalized Uri object if the denormalization is successful; returns the original Uri passed to
184      * this method if there is nothing to do; returns null if the data identified by the original Uri cannot be found in the
185      * current environment.
186      */
187     Uri DenormalizeUri(const Uri &uri);
188 
189     /**
190      * @brief Performs batch operations on the database.
191      *
192      * @param operations Indicates a list of database operations on the database.
193      * @return Returns the result of each operation, in array.
194      */
195     std::vector<std::shared_ptr<DataAbilityResult>> ExecuteBatch(
196         const std::vector<std::shared_ptr<DataAbilityOperation>> &operations);
197 };
198 }  // namespace AppExecFwk
199 }  // namespace OHOS
200 #endif  // FOUNDATION_APPEXECFWK_OHOS_DATA_ABILITY_IMPL_H