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