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