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 #include "ability_impl.h"
17 #include "app_log_wrapper.h"
18 #include "data_ability_predicates.h"
19 #include "values_bucket.h"
20 #include "ability_keyevent.h"
21 #include "ability_touchevent.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
Init(std::shared_ptr<OHOSApplication> & application,const std::shared_ptr<AbilityLocalRecord> & record,std::shared_ptr<Ability> & ability,std::shared_ptr<AbilityHandler> & handler,const sptr<IRemoteObject> & token,std::shared_ptr<ContextDeal> & contextDeal)25 void AbilityImpl::Init(std::shared_ptr<OHOSApplication> &application, const std::shared_ptr<AbilityLocalRecord> &record,
26 std::shared_ptr<Ability> &ability, std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &token,
27 std::shared_ptr<ContextDeal> &contextDeal)
28 {
29 APP_LOGI("AbilityImpl::init begin");
30
31 if ((token == nullptr) || (application == nullptr) || (handler == nullptr) || (record == nullptr) ||
32 ability == nullptr || contextDeal == nullptr) {
33 APP_LOGE("AbilityImpl::init failed, token is nullptr, application is nullptr, handler is nullptr, record is "
34 "nullptr, ability is nullptr, contextDeal is nullptr");
35 return;
36 }
37
38 token_ = record->GetToken();
39 record->SetAbilityImpl(shared_from_this());
40 ability_ = ability;
41 ability_->Init(record->GetAbilityInfo(), application, handler, token);
42 lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL;
43 abilityLifecycleCallbacks_ = application;
44 contextDeal_ = contextDeal;
45
46 // Multimodal Events
47 #ifdef MMI_COMPILE
48 abilityKeyEventHandle_ = sptr<AbilityKeyEventHandle>(new (std::nothrow) AbilityKeyEventHandle(shared_from_this()));
49 abilityTouchEventHandle_ =
50 sptr<AbilityTouchEventHandle>(new (std::nothrow) AbilityTouchEventHandle(shared_from_this()));
51 #endif
52
53 APP_LOGI("AbilityImpl::init end");
54 }
55
56 /**
57 * @brief Toggles the lifecycle status of Ability to AAFwk::ABILITY_STATE_INACTIVE. And notifies the application
58 * that it belongs to of the lifecycle status.
59 *
60 * @param want The Want object to switch the life cycle.
61 */
Start(const Want & want)62 void AbilityImpl::Start(const Want &want)
63 {
64 APP_LOGI("%{public}s begin.", __func__);
65 if (ability_ == nullptr || abilityLifecycleCallbacks_ == nullptr) {
66 APP_LOGE("AbilityImpl::Start ability_ or abilityLifecycleCallbacks_ is nullptr");
67 return;
68 }
69
70 if (ability_->GetAbilityInfo()->type == AbilityType::PAGE) {
71 ability_->HandleCreateAsContinuation(want);
72 }
73
74 APP_LOGI("AbilityImpl::Start");
75 ability_->OnStart(want);
76 if (ability_->GetAbilityInfo()->type == AbilityType::DATA) {
77 lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE;
78 } else {
79 lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE;
80 }
81
82 abilityLifecycleCallbacks_->OnAbilityStart(ability_);
83
84 // Multimodal Events Register
85 MMIRegister();
86 APP_LOGI("%{public}s end.", __func__);
87 }
88
89 /**
90 * @brief Toggles the lifecycle status of Ability to AAFwk::ABILITY_STATE_INITIAL. And notifies the application
91 * that it belongs to of the lifecycle status.
92 *
93 */
Stop()94 void AbilityImpl::Stop()
95 {
96 APP_LOGI("%{public}s begin.", __func__);
97 if (ability_ == nullptr || abilityLifecycleCallbacks_ == nullptr) {
98 APP_LOGE("AbilityImpl::Stop ability_ or abilityLifecycleCallbacks_ is nullptr");
99 return;
100 }
101
102 APP_LOGI("AbilityImpl::Stop");
103 ability_->OnStop();
104 lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL;
105 abilityLifecycleCallbacks_->OnAbilityStop(ability_);
106
107 // Multimodal Events UnRegister
108 MMIUnRegister();
109 APP_LOGI("%{public}s end.", __func__);
110 }
111
112 /**
113 * @brief Toggles the lifecycle status of Ability to AAFwk::ABILITY_STATE_ACTIVE. And notifies the application
114 * that it belongs to of the lifecycle status.
115 *
116 */
Active()117 void AbilityImpl::Active()
118 {
119 APP_LOGI("%{public}s begin.", __func__);
120 if (ability_ == nullptr || abilityLifecycleCallbacks_ == nullptr) {
121 APP_LOGE("AbilityImpl::Active ability_ or abilityLifecycleCallbacks_ is nullptr");
122 return;
123 }
124
125 APP_LOGI("AbilityImpl::Active");
126 ability_->OnActive();
127
128 if ((lifecycleState_ == AAFwk::ABILITY_STATE_INACTIVE) && (ability_->GetAbilityInfo()->type == AbilityType::PAGE)) {
129 ability_->OnTopActiveAbilityChanged(true);
130 ability_->OnWindowFocusChanged(true);
131 }
132
133 lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE;
134 abilityLifecycleCallbacks_->OnAbilityActive(ability_);
135 APP_LOGI("%{public}s end.", __func__);
136 }
137
138 /**
139 * @brief Toggles the lifecycle status of Ability to AAFwk::ABILITY_STATE_INACTIVE. And notifies the application
140 * that it belongs to of the lifecycle status.
141 *
142 */
Inactive()143 void AbilityImpl::Inactive()
144 {
145 APP_LOGI("%{public}s begin.", __func__);
146 if (ability_ == nullptr || abilityLifecycleCallbacks_ == nullptr) {
147 APP_LOGE("AbilityImpl::Inactive ability_ or abilityLifecycleCallbacks_ is nullptr");
148 return;
149 }
150
151 APP_LOGI("AbilityImpl::Inactive");
152 ability_->OnInactive();
153
154 if ((lifecycleState_ == AAFwk::ABILITY_STATE_ACTIVE) && (ability_->GetAbilityInfo()->type == AbilityType::PAGE)) {
155 ability_->OnTopActiveAbilityChanged(false);
156 ability_->OnWindowFocusChanged(false);
157 }
158
159 lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE;
160 abilityLifecycleCallbacks_->OnAbilityInactive(ability_);
161 APP_LOGI("%{public}s end.", __func__);
162 }
163
164 /**
165 * @brief Toggles the lifecycle status of Ability to AAFwk::ABILITY_STATE_INACTIVE. And notifies the application
166 * that it belongs to of the lifecycle status.
167 *
168 * @param want The Want object to switch the life cycle.
169 */
Foreground(const Want & want)170 void AbilityImpl::Foreground(const Want &want)
171 {
172 APP_LOGI("%{public}s begin.", __func__);
173 if (ability_ == nullptr || abilityLifecycleCallbacks_ == nullptr) {
174 APP_LOGE("AbilityImpl::Foreground ability_ or abilityLifecycleCallbacks_ is nullptr");
175 return;
176 }
177
178 APP_LOGI("AbilityImpl::Foreground");
179 ability_->OnForeground(want);
180 lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE;
181 abilityLifecycleCallbacks_->OnAbilityForeground(ability_);
182 APP_LOGI("%{public}s end.", __func__);
183 }
184
185 /**
186 * @brief Toggles the lifecycle status of Ability to AAFwk::ABILITY_STATE_BACKGROUND. And notifies the application
187 * that it belongs to of the lifecycle status.
188 *
189 */
Background()190 void AbilityImpl::Background()
191 {
192 APP_LOGI("%{public}s begin.", __func__);
193 if (ability_ == nullptr || abilityLifecycleCallbacks_ == nullptr) {
194 APP_LOGE("AbilityImpl::Background ability_ or abilityLifecycleCallbacks_ is nullptr");
195 return;
196 }
197
198 APP_LOGI("AbilityImpl::Background");
199 ability_->OnLeaveForeground();
200 ability_->OnBackground();
201 lifecycleState_ = AAFwk::ABILITY_STATE_BACKGROUND;
202 abilityLifecycleCallbacks_->OnAbilityBackground(ability_);
203 APP_LOGI("%{public}s end.", __func__);
204 }
205
206 /**
207 * @brief Save data and states of an ability when it is restored by the system. and Calling information back to Ability.
208 * This method should be implemented by a Page ability.
209 * @param instate The Want object to connect to.
210 *
211 */
DispatchSaveAbilityState(PacMap & outState)212 void AbilityImpl::DispatchSaveAbilityState(PacMap &outState)
213 {
214 APP_LOGI("%{public}s begin.", __func__);
215 if (ability_ == nullptr || abilityLifecycleCallbacks_ == nullptr) {
216 APP_LOGE("AbilityImpl::DispatchSaveAbilityState ability_ or abilityLifecycleCallbacks_ is nullptr");
217 return;
218 }
219
220 APP_LOGI("AbilityImpl::DispatchSaveAbilityState");
221 ability_->OnSaveAbilityState(outState);
222 abilityLifecycleCallbacks_->OnAbilitySaveState(outState);
223 APP_LOGI("%{public}s end.", __func__);
224 }
225
226 /**
227 * @brief Restores data and states of an ability when it is restored by the system. and Calling information back to
228 * Ability. This method should be implemented by a Page ability.
229 * @param instate The Want object to connect to.
230 *
231 */
DispatchRestoreAbilityState(const PacMap & inState)232 void AbilityImpl::DispatchRestoreAbilityState(const PacMap &inState)
233 {
234 APP_LOGI("%{public}s begin.", __func__);
235 if (ability_ == nullptr) {
236 APP_LOGE("AbilityImpl::DispatchRestoreAbilityState ability_ is nullptr");
237 return;
238 }
239
240 hasSaveData_ = true;
241 restoreData_ = inState;
242 APP_LOGI("%{public}s end.", __func__);
243 }
244
HandleAbilityTransaction(const Want & want,const AAFwk::LifeCycleStateInfo & targetState)245 void AbilityImpl::HandleAbilityTransaction(const Want &want, const AAFwk::LifeCycleStateInfo &targetState)
246 {}
247
248 /**
249 * @brief Connect the ability. and Calling information back to Ability.
250 *
251 * @param want The Want object to connect to.
252 *
253 */
ConnectAbility(const Want & want)254 sptr<IRemoteObject> AbilityImpl::ConnectAbility(const Want &want)
255 {
256 APP_LOGI("%{public}s begin.", __func__);
257 if (ability_ == nullptr) {
258 APP_LOGE("AbilityImpl::ConnectAbility ability_ is nullptr");
259 return nullptr;
260 }
261
262 APP_LOGI("AbilityImpl:: ConnectAbility");
263 sptr<IRemoteObject> object = ability_->OnConnect(want);
264 lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE;
265 abilityLifecycleCallbacks_->OnAbilityActive(ability_);
266 APP_LOGI("%{public}s end.", __func__);
267
268 return object;
269 }
270
271 /**
272 * @brief Disconnects the connected object.
273 *
274 * @param want The Want object to disconnect to.
275 */
DisconnectAbility(const Want & want)276 void AbilityImpl::DisconnectAbility(const Want &want)
277 {
278 APP_LOGI("%{public}s begin.", __func__);
279 if (ability_ == nullptr) {
280 APP_LOGE("AbilityImpl::DisconnectAbility ability_ is nullptr");
281 return;
282 }
283
284 ability_->OnDisconnect(want);
285 APP_LOGI("%{public}s end.", __func__);
286 }
287
288 /**
289 * @brief Command the ability. and Calling information back to Ability.
290 *
291 * @param want The Want object to command to.
292 *
293 * * @param restart Indicates the startup mode. The value true indicates that Service is restarted after being
294 * destroyed, and the value false indicates a normal startup.
295 *
296 * @param startId Indicates the number of times the Service ability has been started. The startId is incremented by 1
297 * every time the ability is started. For example, if the ability has been started for six times, the value of startId
298 * is 6.
299 */
CommandAbility(const Want & want,bool restart,int startId)300 void AbilityImpl::CommandAbility(const Want &want, bool restart, int startId)
301 {
302 APP_LOGI("%{public}s begin.", __func__);
303 if (ability_ == nullptr) {
304 APP_LOGE("AbilityImpl::CommandAbility ability_ is nullptr");
305 return;
306 }
307
308 APP_LOGI("AbilityImpl:: CommandAbility");
309 ability_->OnCommand(want, restart, startId);
310 lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE;
311 abilityLifecycleCallbacks_->OnAbilityActive(ability_);
312 APP_LOGI("%{public}s end.", __func__);
313 }
314
315 /**
316 * @brief Gets the current Ability status.
317 *
318 */
GetCurrentState()319 int AbilityImpl::GetCurrentState()
320 {
321 return lifecycleState_;
322 }
323
324 /**
325 * @brief Execution the KeyDown callback of the ability
326 * @param keyCode Indicates the code of the key pressed.
327 * @param keyEvent Indicates the key-down event.
328 *
329 * @return Returns true if this event is handled and will not be passed further; returns false if this event is
330 * not handled and should be passed to other handlers.
331 *
332 */
DoKeyDown(int keyCode,const KeyEvent & keyEvent)333 bool AbilityImpl::DoKeyDown(int keyCode, const KeyEvent &keyEvent)
334 {
335 APP_LOGI("AbilityImpl::DoKeyDown called");
336 return false;
337 }
338
339 /**
340 * @brief Execution the KeyUp callback of the ability
341 * @param keyCode Indicates the code of the key released.
342 * @param keyEvent Indicates the key-up event.
343 *
344 * @return Returns true if this event is handled and will not be passed further; returns false if this event is
345 * not handled and should be passed to other handlers.
346 *
347 */
DoKeyUp(int keyCode,const KeyEvent & keyEvent)348 bool AbilityImpl::DoKeyUp(int keyCode, const KeyEvent &keyEvent)
349 {
350 APP_LOGI("AbilityImpl::DoKeyUp called");
351 return false;
352 }
353
354 /**
355 * @brief Called when a touch event is dispatched to this ability. The default implementation of this callback
356 * does nothing and returns false.
357 * @param touchEvent Indicates information about the touch event.
358 *
359 * @return Returns true if the event is handled; returns false otherwise.
360 *
361 */
DoTouchEvent(const TouchEvent & touchEvent)362 bool AbilityImpl::DoTouchEvent(const TouchEvent &touchEvent)
363 {
364 APP_LOGI("AbilityImpl::DoTouchEvent called");
365 return false;
366 }
367
368 /**
369 * @brief Send the result code and data to be returned by this Page ability to the caller.
370 * When a Page ability is destroyed, the caller overrides the AbilitySlice#onAbilityResult(int, int, Want) method to
371 * receive the result set in the current method. This method can be called only after the ability has been initialized.
372 *
373 * @param requestCode Indicates the request code.
374 * @param resultCode Indicates the result code returned after the ability is destroyed. You can define the result code
375 * to identify an error.
376 * @param resultData Indicates the data returned after the ability is destroyed. You can define the data returned. This
377 * parameter can be null.
378 */
SendResult(int requestCode,int resultCode,const Want & resultData)379 void AbilityImpl::SendResult(int requestCode, int resultCode, const Want &resultData)
380 {
381 APP_LOGI("%{public}s begin.", __func__);
382 if (ability_ == nullptr) {
383 APP_LOGE("AbilityImpl::SendResult ability_ is nullptr");
384 return;
385 }
386
387 if (resultData.HasParameter(OHOS_RESULT_PERMISSION_KEY) && resultData.HasParameter(OHOS_RESULT_PERMISSIONS_LIST) &&
388 resultData.HasParameter(OHOS_RESULT_CALLER_BUNDLERNAME)) {
389
390 if (resultCode > 0) {
391 std::vector<std::string> permissions = resultData.GetStringArrayParam(OHOS_RESULT_PERMISSIONS_LIST);
392 std::vector<std::string> grantYes = resultData.GetStringArrayParam(OHOS_RESULT_PERMISSIONS_LIST_YES);
393 std::vector<std::string> grantNo = resultData.GetStringArrayParam(OHOS_RESULT_PERMISSIONS_LIST_NO);
394 std::vector<int> grantResult;
395 int intOK = 0;
396 for (size_t i = 0; i < permissions.size(); i++) {
397 intOK = 0;
398 for (size_t j = 0; j < grantYes.size(); j++) {
399 if (permissions[i] == grantYes[j]) {
400 intOK = 1;
401 break;
402 }
403 }
404 grantResult.push_back(intOK);
405 }
406 APP_LOGI("%{public}s begin OnRequestPermissionsFromUserResult.", __func__);
407 ability_->OnRequestPermissionsFromUserResult(requestCode, permissions, grantResult);
408 APP_LOGI("%{public}s end OnRequestPermissionsFromUserResult.", __func__);
409 } else {
410 APP_LOGI("%{public}s user cancel permissions.", __func__);
411 }
412 } else {
413 ability_->OnAbilityResult(requestCode, resultCode, resultData);
414 }
415 APP_LOGI("%{public}s end.", __func__);
416 }
417
418 /**
419 * @brief Called when the launch mode of an ability is set to singleInstance. This happens when you re-launch
420 * an ability that has been at the top of the ability stack.
421 *
422 * @param want Indicates the new Want containing information about the ability.
423 */
NewWant(const Want & want)424 void AbilityImpl::NewWant(const Want &want)
425 {
426 APP_LOGI("%{public}s begin.", __func__);
427 if (ability_ == nullptr) {
428 APP_LOGE("AbilityImpl::NewWant ability_ is nullptr");
429 return;
430 }
431 ability_->SetWant(want);
432 ability_->OnNewWant(want);
433 APP_LOGI("%{public}s end.", __func__);
434 }
435
436 /**
437 * @brief Obtains the MIME types of files supported.
438 *
439 * @param uri Indicates the path of the files to obtain.
440 * @param mimeTypeFilter Indicates the MIME types of the files to obtain. This parameter cannot be null.
441 *
442 * @return Returns the matched MIME types. If there is no match, null is returned.
443 */
GetFileTypes(const Uri & uri,const std::string & mimeTypeFilter)444 std::vector<std::string> AbilityImpl::GetFileTypes(const Uri &uri, const std::string &mimeTypeFilter)
445 {
446 APP_LOGI("AbilityImpl::GetFileTypes");
447 std::vector<std::string> types;
448 return types;
449 }
450
451 /**
452 * @brief Opens a file in a specified remote path.
453 *
454 * @param uri Indicates the path of the file to open.
455 * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access
456 * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing file,
457 * "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing data,
458 * or "rwt" for read and write access that truncates any existing file.
459 *
460 * @return Returns the file descriptor.
461 */
OpenFile(const Uri & uri,const std::string & mode)462 int AbilityImpl::OpenFile(const Uri &uri, const std::string &mode)
463 {
464 APP_LOGI("AbilityImpl::OpenFile");
465 return -1;
466 }
467
468 /**
469 * @brief This is like openFile, open a file that need to be able to return sub-sections of files,often assets
470 * inside of their .hap.
471 *
472 * @param uri Indicates the path of the file to open.
473 * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access
474 * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing file,
475 * "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing
476 * data, or "rwt" for read and write access that truncates any existing file.
477 *
478 * @return Returns the RawFileDescriptor object containing file descriptor.
479 */
OpenRawFile(const Uri & uri,const std::string & mode)480 int AbilityImpl::OpenRawFile(const Uri &uri, const std::string &mode)
481 {
482 APP_LOGI("AbilityImpl::OpenRawFile");
483 return -1;
484 }
485
486 /**
487 * @brief Inserts a single data record into the database.
488 *
489 * @param uri Indicates the path of the data to operate.
490 * @param value Indicates the data record to insert. If this parameter is null, a blank row will be inserted.
491 *
492 * @return Returns the index of the inserted data record.
493 */
Insert(const Uri & uri,const NativeRdb::ValuesBucket & value)494 int AbilityImpl::Insert(const Uri &uri, const NativeRdb::ValuesBucket &value)
495 {
496 APP_LOGI("AbilityImpl::Insert");
497 return -1;
498 }
499
500 /**
501 * @brief Updates data records in the database.
502 *
503 * @param uri Indicates the path of data to update.
504 * @param value Indicates the data to update. This parameter can be null.
505 * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
506 *
507 * @return Returns the number of data records updated.
508 */
Update(const Uri & uri,const NativeRdb::ValuesBucket & value,const NativeRdb::DataAbilityPredicates & predicates)509 int AbilityImpl::Update(
510 const Uri &uri, const NativeRdb::ValuesBucket &value, const NativeRdb::DataAbilityPredicates &predicates)
511 {
512 APP_LOGI("AbilityImpl::Update");
513 return -1;
514 }
515
516 /**
517 * @brief Deletes one or more data records from the database.
518 *
519 * @param uri Indicates the path of the data to operate.
520 * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
521 *
522 * @return Returns the number of data records deleted.
523 */
Delete(const Uri & uri,const NativeRdb::DataAbilityPredicates & predicates)524 int AbilityImpl::Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates)
525 {
526 APP_LOGI("AbilityImpl::Delete");
527 return -1;
528 }
529
530 /**
531 * @brief Deletes one or more data records from the database.
532 *
533 * @param uri Indicates the path of data to query.
534 * @param columns Indicates the columns to query. If this parameter is null, all columns are queried.
535 * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
536 *
537 * @return Returns the query result.
538 */
Query(const Uri & uri,std::vector<std::string> & columns,const NativeRdb::DataAbilityPredicates & predicates)539 std::shared_ptr<NativeRdb::AbsSharedResultSet> AbilityImpl::Query(
540 const Uri &uri, std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates)
541 {
542 APP_LOGI("AbilityImpl::Query");
543 return nullptr;
544 }
545
546 /**
547 * @brief Obtains the MIME type matching the data specified by the URI of the Data ability. This method should be
548 * implemented by a Data ability. Data abilities supports general data types, including text, HTML, and JPEG.
549 *
550 * @param uri Indicates the URI of the data.
551 *
552 * @return Returns the MIME type that matches the data specified by uri.
553 */
GetType(const Uri & uri)554 std::string AbilityImpl::GetType(const Uri &uri)
555 {
556 APP_LOGI("AbilityImpl::GetType");
557 return "";
558 }
559
560 /**
561 * @brief Reloads data in the database.
562 *
563 * @param uri Indicates the position where the data is to reload. This parameter is mandatory.
564 * @param extras Indicates the PacMap object containing the additional parameters to be passed in this call. This
565 * parameter can be null. If a custom Sequenceable object is put in the PacMap object and will be transferred across
566 * processes, you must call BasePacMap.setClassLoader(ClassLoader) to set a class loader for the custom object.
567 *
568 * @return Returns true if the data is successfully reloaded; returns false otherwise.
569 */
Reload(const Uri & uri,const PacMap & extras)570 bool AbilityImpl::Reload(const Uri &uri, const PacMap &extras)
571 {
572 return false;
573 }
574
575 /**
576 * @brief Inserts multiple data records into the database.
577 *
578 * @param uri Indicates the path of the data to operate.
579 * @param values Indicates the data records to insert.
580 *
581 * @return Returns the number of data records inserted.
582 */
BatchInsert(const Uri & uri,const std::vector<NativeRdb::ValuesBucket> & values)583 int AbilityImpl::BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values)
584 {
585 APP_LOGI("AbilityImpl::BatchInsert");
586 return -1;
587 }
588
589 /**
590 * @brief SerUriString
591 */
SerUriString(const std::string & uri)592 void AbilityImpl::SerUriString(const std::string &uri)
593 {
594 APP_LOGI("%{public}s begin.", __func__);
595 if (contextDeal_ == nullptr) {
596 APP_LOGE("AbilityImpl::SerUriString contextDeal_ is nullptr");
597 return;
598 }
599 contextDeal_->SerUriString(uri);
600 APP_LOGI("%{public}s end.", __func__);
601 }
602
603 /**
604 * @brief Set the LifeCycleStateInfo to the deal.
605 *
606 * @param info the info to set.
607 */
SetLifeCycleStateInfo(const AAFwk::LifeCycleStateInfo & info)608 void AbilityImpl::SetLifeCycleStateInfo(const AAFwk::LifeCycleStateInfo &info)
609 {
610 if (contextDeal_ == nullptr) {
611 APP_LOGE("AbilityImpl::SetLifeCycleStateInfo contextDeal_ is nullptr");
612 return;
613 }
614 contextDeal_->SetLifeCycleStateInfo(info);
615 }
616
617 /**
618 * @brief Check if it needs to restore the data to the ability.
619 *
620 * @return Return true if need and success, otherwise return false.
621 */
CheckAndRestore()622 bool AbilityImpl::CheckAndRestore()
623 {
624 APP_LOGI("AbilityImpl::CheckAndRestore called start");
625 if (!hasSaveData_) {
626 APP_LOGE("AbilityImpl::CheckAndRestore hasSaveData_ is false");
627 return false;
628 }
629
630 if (ability_ == nullptr) {
631 APP_LOGE("AbilityImpl::CheckAndRestore ability_ is nullptr");
632 return false;
633 }
634
635 APP_LOGI("AbilityImpl::CheckAndRestore ready to restore");
636 ability_->OnRestoreAbilityState(restoreData_);
637
638 APP_LOGI("AbilityImpl::CheckAndRestore called end");
639 return true;
640 }
641
642 /**
643 * @brief Set deviceId/bundleName/abilityName of the calling ability
644 *
645 * @param deviceId deviceId of the calling ability
646 *
647 * @param deviceId bundleName of the calling ability
648 *
649 * @param deviceId abilityName of the calling ability
650 */
SetCallingContext(const std::string & deviceId,const std::string & bundleName,const std::string & abilityName)651 void AbilityImpl::SetCallingContext(
652 const std::string &deviceId, const std::string &bundleName, const std::string &abilityName)
653 {
654 if (ability_ != nullptr) {
655 ability_->SetCallingContext(deviceId, bundleName, abilityName);
656 }
657 }
658
659 /**
660 * @brief Converts the given uri that refer to the Data ability into a normalized URI. A normalized URI can be used
661 * across devices, persisted, backed up, and restored. It can refer to the same item in the Data ability even if the
662 * context has changed. If you implement URI normalization for a Data ability, you must also implement
663 * denormalizeUri(ohos.utils.net.Uri) to enable URI denormalization. After this feature is enabled, URIs passed to any
664 * method that is called on the Data ability must require normalization verification and denormalization. The default
665 * implementation of this method returns null, indicating that this Data ability does not support URI normalization.
666 *
667 * @param uri Indicates the Uri object to normalize.
668 *
669 * @return Returns the normalized Uri object if the Data ability supports URI normalization; returns null otherwise.
670 */
NormalizeUri(const Uri & uri)671 Uri AbilityImpl::NormalizeUri(const Uri &uri)
672 {
673 APP_LOGI("AbilityImpl::NormalizeUri");
674 return uri;
675 }
676
677 /**
678 * @brief Converts the given normalized uri generated by normalizeUri(ohos.utils.net.Uri) into a denormalized one.
679 * The default implementation of this method returns the original URI passed to it.
680 *
681 * @param uri uri Indicates the Uri object to denormalize.
682 *
683 * @return Returns the denormalized Uri object if the denormalization is successful; returns the original Uri passed to
684 * this method if there is nothing to do; returns null if the data identified by the original Uri cannot be found in the
685 * current environment.
686 */
DenormalizeUri(const Uri & uri)687 Uri AbilityImpl::DenormalizeUri(const Uri &uri)
688 {
689 APP_LOGI("AbilityImpl::DenormalizeUri");
690 return uri;
691 }
692
693 /*
694 * @brief ScheduleUpdateConfiguration, scheduling update configuration.
695 */
ScheduleUpdateConfiguration(const AAFwk::DummyConfiguration & config)696 void AbilityImpl::ScheduleUpdateConfiguration(const AAFwk::DummyConfiguration &config)
697 {
698 APP_LOGI("%{public}s begin.", __func__);
699 if (ability_ == nullptr) {
700 APP_LOGE("AbilityImpl::ScheduleUpdateConfiguration ability_ is nullptr");
701 }
702
703 Configuration configtest;
704 ability_->OnConfigurationUpdated(configtest);
705 APP_LOGI("%{public}s end.", __func__);
706 }
707 /**
708 * @brief Multimodal Events Register.
709 */
MMIRegister()710 void AbilityImpl::MMIRegister()
711 {
712 #ifdef MMI_COMPILE
713 APP_LOGI("%{public}s called.", __func__);
714 int32_t ret = 0;
715 int32_t windowID = 0;
716 if (ability_->GetAbilityInfo()->type == AppExecFwk::AbilityType::PAGE) {
717 if (ability_->GetWindow() != nullptr) {
718 windowID = ability_->GetWindow()->GetWindowID();
719 }
720 }
721
722 // register keyEvent
723 ret = MMIEventHdl->RegisterStandardizedEventHandle(token_, windowID, abilityKeyEventHandle_);
724 APP_LOGI("MMIRegister :token:%{public}p windowID:%{public}d", token_.GetRefPtr(), windowID);
725 APP_LOGI("MMIRegister :keyEventHandler:%{public}p", abilityKeyEventHandle_.GetRefPtr());
726 APP_LOGI("MMIRegister :RegisterkeyEventHandler ret:%{public}d", ret);
727
728 // register touchEvent
729 ret = MMIEventHdl->RegisterStandardizedEventHandle(token_, windowID, abilityTouchEventHandle_);
730 APP_LOGI("MMIRegister :token:%{public}p windowID:%{public}d", token_.GetRefPtr(), windowID);
731 APP_LOGI("MMIRegister :touchEventHandler:%{public}p", abilityTouchEventHandle_.GetRefPtr());
732 APP_LOGI("MMIRegister :RegistertouchEventHandler ret:%{public}d", ret);
733 #endif
734 }
735
736 /**
737 * @brief Multimodal Events UnRegister.
738 */
MMIUnRegister()739 void AbilityImpl::MMIUnRegister()
740 {
741 #ifdef MMI_COMPILE
742 APP_LOGI("%{public}s called.", __func__);
743 int32_t ret = 0;
744 int32_t windowID = 0;
745 if (ability_->GetAbilityInfo()->type == AppExecFwk::AbilityType::PAGE) {
746 if (ability_->GetWindow() != nullptr) {
747 windowID = ability_->GetWindow()->GetWindowID();
748 }
749 }
750 // unregister keyEvent
751 ret = MMIEventHdl->UnregisterStandardizedEventHandle(token_, windowID, abilityKeyEventHandle_);
752 APP_LOGI("MMIUnRegister :token:%{public}p windowID:%{public}d", token_.GetRefPtr(), windowID);
753 APP_LOGI("MMIUnRegister :keyEventHandler:%{public}p", abilityKeyEventHandle_.GetRefPtr());
754 APP_LOGI("MMIUnRegister :UnRegisterkeyEventHandler ret:%{public}d", ret);
755
756 // unregister touchEvent
757 ret = MMIEventHdl->UnregisterStandardizedEventHandle(token_, windowID, abilityTouchEventHandle_);
758 APP_LOGI("MMIUnRegister :token:%{public}p windowID:%{public}d", token_.GetRefPtr(), windowID);
759 APP_LOGI("MMIUnRegister :touchEventHandler:%{public}p", abilityTouchEventHandle_.GetRefPtr());
760 APP_LOGI("MMIUnRegister :UnRegistertouchEventHandler ret:%{public}d", ret);
761 #endif
762 }
763
764 /**
765 * @brief Create a PostEvent timeout task. The default delay is 5000ms
766 *
767 * @return Return a smart pointer to a timeout object
768 */
CreatePostEventTimeouter(std::string taskstr)769 std::shared_ptr<AbilityPostEventTimeout> AbilityImpl::CreatePostEventTimeouter(std::string taskstr)
770 {
771 if (ability_ == nullptr) {
772 APP_LOGE("AbilityImpl::CreatePostEventTimeouter ability_ is nullptr");
773 return nullptr;
774 }
775
776 return ability_->CreatePostEventTimeouter(taskstr);
777 }
778
ExecuteBatch(const std::vector<std::shared_ptr<DataAbilityOperation>> & operations)779 std::vector<std::shared_ptr<DataAbilityResult>> AbilityImpl::ExecuteBatch(
780 const std::vector<std::shared_ptr<DataAbilityOperation>> &operations)
781 {
782 APP_LOGI("AbilityImpl::ExecuteBatch");
783 std::vector<std::shared_ptr<DataAbilityResult>> results;
784 return results;
785 }
786
787 } // namespace AppExecFwk
788 } // namespace OHOS