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