• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "context_deal.h"
17 
18 #include <regex>
19 
20 #include "ability_constants.h"
21 #include "ability_manager_client.h"
22 #include "ability_manager_interface.h"
23 #include "application_context.h"
24 #include "directory_ex.h"
25 #include "file_ex.h"
26 #include "hilog_wrapper.h"
27 #include "iservice_registry.h"
28 #include "os_account_manager.h"
29 #include "spec_task_dispatcher.h"
30 #include "sys_mgr_client.h"
31 #include "system_ability_definition.h"
32 #include "task_dispatcher_context.h"
33 
34 #define MODE 0771
35 namespace OHOS {
36 namespace AppExecFwk {
37 using namespace OHOS::AbilityRuntime::Constants;
38 
39 const std::string ContextDeal::CONTEXT_DEAL_FILE_SEPARATOR("/");
40 const std::string ContextDeal::CONTEXT_DEAL_CODE_CACHE("code_cache");
41 const std::string ContextDeal::CONTEXT_DEAL_Files("files");
42 const std::string ContextDeal::CONTEXT_DEAL_NO_BACKUP_Files("no_backup");
43 const std::string ContextDeal::CONTEXT_DEAL_DIRNAME("preferences");
44 const int64_t ContextDeal::CONTEXT_CREATE_BY_SYSTEM_APP(0x00000001);
45 const std::string ContextDeal::CONTEXT_DISTRIBUTED_BASE_BEFORE("/mnt/hmdfs/");
46 const std::string ContextDeal::CONTEXT_DISTRIBUTED_BASE_MIDDLE("/device_view/local/data/");
47 const std::string ContextDeal::CONTEXT_DISTRIBUTED("distributedfiles");
48 const std::string ContextDeal::CONTEXT_DATA_STORAGE("/data/storage/");
49 const std::string ContextDeal::CONTEXT_ELS[] = {"el1", "el2"};
50 const std::string ContextDeal::CONTEXT_DEAL_DATA_APP("/data/app/");
51 const std::string ContextDeal::CONTEXT_DEAL_BASE("base");
52 const std::string ContextDeal::CONTEXT_DEAL_DATABASE("database");
53 const std::string ContextDeal::CONTEXT_DEAL_PREFERENCES("preferences");
54 const std::string ContextDeal::CONTEXT_DEAL_DISTRIBUTEDFILES("distributedfiles");
55 const std::string ContextDeal::CONTEXT_DEAL_CACHE("cache");
56 const std::string ContextDeal::CONTEXT_DEAL_DATA("data");
57 
ContextDeal(bool isCreateBySystemApp)58 ContextDeal::ContextDeal(bool isCreateBySystemApp) : isCreateBySystemApp_(isCreateBySystemApp)
59 {}
60 
61 /**
62  * Called when getting the ProcessInfo
63  *
64  * @return ProcessInfo
65  */
GetProcessInfo() const66 std::shared_ptr<ProcessInfo> ContextDeal::GetProcessInfo() const
67 {
68     return processInfo_;
69 }
70 
71 /**
72  * Called when setting the ProcessInfo
73  *
74  * @param info ProcessInfo instance
75  */
SetProcessInfo(const std::shared_ptr<ProcessInfo> & info)76 void ContextDeal::SetProcessInfo(const std::shared_ptr<ProcessInfo> &info)
77 {
78     HILOG_INFO("ContextDeal::SetProcessInfo begin");
79     if (info == nullptr) {
80         HILOG_ERROR("ContextDeal::SetProcessInfo failed, info is empty");
81         return;
82     }
83     HILOG_INFO("ContextDeal::SetProcessInfo end");
84     processInfo_ = info;
85 }
86 
87 /**
88  * @brief Obtains information about the current application. The returned application information includes basic
89  * information such as the application name and application permissions.
90  *
91  * @return Returns the ApplicationInfo for the current application.
92  */
GetApplicationInfo() const93 std::shared_ptr<ApplicationInfo> ContextDeal::GetApplicationInfo() const
94 {
95     return applicationInfo_;
96 }
97 
98 /**
99  * @brief Set ApplicationInfo
100  *
101  * @param info ApplicationInfo instance.
102  */
SetApplicationInfo(const std::shared_ptr<ApplicationInfo> & info)103 void ContextDeal::SetApplicationInfo(const std::shared_ptr<ApplicationInfo> &info)
104 {
105     HILOG_INFO("ContextDeal::SetApplicationInfo begin");
106     if (info == nullptr) {
107         HILOG_ERROR("ContextDeal::SetApplicationInfo failed, info is empty");
108         return;
109     }
110     applicationInfo_ = info;
111     HILOG_INFO("ContextDeal::SetApplicationInfo end");
112 }
113 
114 /**
115  * @brief Obtains the Context object of the application.
116  *
117  * @return Returns the Context object of the application.
118  */
GetApplicationContext() const119 std::shared_ptr<Context> ContextDeal::GetApplicationContext() const
120 {
121     return appContext_;
122 }
123 
124 /**
125  * @brief Set ApplicationContext
126  *
127  * @param context ApplicationContext instance.
128  */
SetApplicationContext(const std::shared_ptr<Context> & context)129 void ContextDeal::SetApplicationContext(const std::shared_ptr<Context> &context)
130 {
131     HILOG_INFO("ContextDeal::SetApplicationContext begin");
132     if (context == nullptr) {
133         HILOG_ERROR("ContextDeal::SetApplicationContext failed, context is empty");
134         return;
135     }
136     appContext_ = context;
137     HILOG_INFO("ContextDeal::SetApplicationContext end");
138 }
139 
140 /**
141  * @brief Obtains the path of the package containing the current ability. The returned path contains the resources,
142  *  source code, and configuration files of a module.
143  *
144  * @return Returns the path of the package file.
145  */
GetBundleCodePath()146 std::string ContextDeal::GetBundleCodePath()
147 {
148     if (applicationInfo_ == nullptr) {
149         return "";
150     }
151 
152     std::string dir;
153     if (isCreateBySystemApp_) {
154         dir = std::regex_replace(applicationInfo_->codePath, std::regex(ABS_CODE_PATH), LOCAL_BUNDLES);
155     } else {
156         dir = LOCAL_CODE_PATH;
157     }
158 
159     return dir;
160 }
161 
162 /**
163  * @brief SetBundleCodePath
164  *
165  * @param Returns string path
166  */
SetBundleCodePath(std::string & path)167 void ContextDeal::SetBundleCodePath(std::string &path)
168 {
169     path_ = path;
170 }
171 
172 /**
173  * @brief Obtains information about the current ability.
174  * The returned information includes the class name, bundle name, and other information about the current ability.
175  *
176  * @return Returns the AbilityInfo object for the current ability.
177  */
GetAbilityInfo()178 const std::shared_ptr<AbilityInfo> ContextDeal::GetAbilityInfo()
179 {
180     return abilityInfo_;
181 }
182 
183 /**
184  * @brief Set AbilityInfo
185  *
186  * @param info AbilityInfo instance.
187  */
SetAbilityInfo(const std::shared_ptr<AbilityInfo> & info)188 void ContextDeal::SetAbilityInfo(const std::shared_ptr<AbilityInfo> &info)
189 {
190     HILOG_INFO("ContextDeal::SetAbilityInfo begin");
191     if (info == nullptr) {
192         HILOG_ERROR("ContextDeal::SetAbilityInfo failed, info is empty");
193         return;
194     }
195     abilityInfo_ = info;
196     HILOG_INFO("ContextDeal::SetAbilityInfo end");
197 }
198 
199 /**
200  * @brief Obtains the Context object of the ability.
201  *
202  * @return Returns the Context object of the ability.
203  */
GetContext()204 std::shared_ptr<Context> ContextDeal::GetContext()
205 {
206     return abilityContext_;
207 }
208 
209 /**
210  * @brief Set Ability context
211  *
212  * @param context Ability object
213  */
SetContext(const std::shared_ptr<Context> & context)214 void ContextDeal::SetContext(const std::shared_ptr<Context> &context)
215 {
216     HILOG_INFO("ContextDeal::SetContext begin");
217     if (context == nullptr) {
218         HILOG_ERROR("ContextDeal::SetContext failed, context is empty");
219         return;
220     }
221     abilityContext_ = context;
222     HILOG_INFO("ContextDeal::SetContext end");
223 }
224 
225 /**
226  * @brief Obtains an IBundleMgr instance.
227  * You can use this instance to obtain information about the application bundle.
228  *
229  * @return Returns an IBundleMgr instance.
230  */
GetBundleManager() const231 sptr<IBundleMgr> ContextDeal::GetBundleManager() const
232 {
233     HILOG_INFO("ContextDeal::GetBundleManager begin");
234     auto bundleObj =
235         OHOS::DelayedSingleton<SysMrgClient>::GetInstance()->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
236     if (bundleObj == nullptr) {
237         HILOG_ERROR("failed to get bundle manager service");
238         return nullptr;
239     }
240     HILOG_INFO("ContextDeal::GetBundleManager before iface_cast<bundleObj>");
241     sptr<IBundleMgr> bms = iface_cast<IBundleMgr>(bundleObj);
242     HILOG_INFO("ContextDeal::GetBundleManager after iface_cast<bundleObj>");
243     HILOG_INFO("ContextDeal::GetBundleManager end");
244     return bms;
245 }
246 
247 /**
248  * @brief Obtains a resource manager.
249  *
250  * @return Returns a ResourceManager object.
251  */
GetResourceManager() const252 std::shared_ptr<Global::Resource::ResourceManager> ContextDeal::GetResourceManager() const
253 {
254     return resourceManager_;
255 }
256 
257 /**
258  * @brief Set Profile instance.
259  *
260  * @param Profile instance.
261  */
SetProfile(const std::shared_ptr<Profile> & profile)262 void ContextDeal::SetProfile(const std::shared_ptr<Profile> &profile)
263 {
264     HILOG_INFO("ContextDeal::SetProfile begin");
265     if (profile == nullptr) {
266         HILOG_ERROR("ContextDeal::SetProfile failed, profile is nullptr");
267         return;
268     }
269     profile_ = profile;
270     HILOG_INFO("ContextDeal::SetProfile end");
271 }
272 
273 /**
274  * @brief Obtains an Profile instance.
275  *
276  * @return Returns an Profile instance.
277  */
GetProfile() const278 std::shared_ptr<Profile> ContextDeal::GetProfile() const
279 {
280     return profile_;
281 }
282 
283 /**
284  * @brief Deletes the specified private file associated with the application.
285  *
286  * @param fileName Indicates the name of the file to delete. The file name cannot contain path separators.
287  *
288  * @return Returns true if the file is deleted successfully; returns false otherwise.
289  */
DeleteFile(const std::string & fileName)290 bool ContextDeal::DeleteFile(const std::string &fileName)
291 {
292     HILOG_INFO("ContextDeal::DeleteFile begin");
293     std::string path = GetDataDir() + CONTEXT_DEAL_FILE_SEPARATOR + fileName;
294     bool ret = OHOS::RemoveFile(path);
295     HILOG_INFO("ContextDeal::DeleteFile end");
296     return ret;
297 }
298 
299 /**
300  * @brief Destroys another ability that uses the AbilityInfo.AbilityType.SERVICE template.
301  * The current ability using either the AbilityInfo.AbilityType.SERVICE or AbilityInfo.AbilityType.PAGE
302  * template can call this method to destroy another ability that uses the AbilityInfo.AbilityType.SERVICE
303  * template. The current ability itself can be destroyed by calling the terminateAbility() method.
304  *
305  * @param want Indicates the Want containing information about the ability to destroy.
306  *
307  * @return Returns true if the ability is destroyed successfully; returns false otherwise.
308  */
StopAbility(const AAFwk::Want & want)309 bool ContextDeal::StopAbility(const AAFwk::Want &want)
310 {
311     return false;
312 }
313 
314 /**
315  * @brief Obtains the application-specific cache directory on the device's internal storage. The system
316  * automatically deletes files from the cache directory if disk space is required elsewhere on the device.
317  * Older files are always deleted first.
318  *
319  * @return Returns the application-specific cache directory.
320  */
GetCacheDir()321 std::string ContextDeal::GetCacheDir()
322 {
323     std::string dir = GetBaseDir() + CONTEXT_DEAL_FILE_SEPARATOR + CONTEXT_DEAL_CACHE;
324     CreateDirIfNotExist(dir);
325     HILOG_DEBUG("ContextDeal::GetCacheDir:%{public}s", dir.c_str());
326     return dir;
327 }
328 
IsUpdatingConfigurations()329 bool ContextDeal::IsUpdatingConfigurations()
330 {
331     return false;
332 }
333 
PrintDrawnCompleted()334 bool ContextDeal::PrintDrawnCompleted()
335 {
336     return false;
337 }
338 
339 /**
340  * @brief Obtains the application-specific code-cache directory on the device's internal storage.
341  * The system will delete any files stored in this location both when your specific application is upgraded,
342  * and when the entire platform is upgraded.
343  *
344  * @return Returns the application-specific code-cache directory.
345  */
GetCodeCacheDir()346 std::string ContextDeal::GetCodeCacheDir()
347 {
348     std::string dir = GetDataDir() + CONTEXT_DEAL_FILE_SEPARATOR + CONTEXT_DEAL_CODE_CACHE;
349     CreateDirIfNotExist(dir);
350     HILOG_DEBUG("ContextDeal::GetCodeCacheDir:%{public}s", dir.c_str());
351     return dir;
352 }
353 
354 /**
355  * @brief Obtains the local database path.
356  * If the local database path does not exist, the system creates one and returns the created path.
357  *
358  * @return Returns the local database file.
359  */
GetDatabaseDir()360 std::string ContextDeal::GetDatabaseDir()
361 {
362     std::string dir;
363     if (IsCreateBySystemApp()) {
364         dir = CONTEXT_DEAL_DATA_APP + currArea_ + CONTEXT_DEAL_FILE_SEPARATOR + std::to_string(GetCurrentAccountId())
365 		    + CONTEXT_DEAL_FILE_SEPARATOR + CONTEXT_DEAL_DATABASE + CONTEXT_DEAL_FILE_SEPARATOR + GetBundleName();
366     } else {
367         dir = CONTEXT_DATA_STORAGE + currArea_ + CONTEXT_DEAL_FILE_SEPARATOR + CONTEXT_DEAL_DATABASE;
368     }
369     CreateDirIfNotExist(dir);
370     HILOG_DEBUG("ContextDeal::GetDatabaseDir:%{public}s", dir.c_str());
371     return dir;
372 }
373 
374 /**
375  * @brief Obtains the absolute path where all private data files of this application are stored.
376  *
377  * @return Returns the absolute path storing all private data files of this application.
378  */
GetDataDir()379 std::string ContextDeal::GetDataDir()
380 {
381     std::string dir = GetBaseDir() + CONTEXT_DEAL_FILE_SEPARATOR + CONTEXT_DEAL_DATA;
382     CreateDirIfNotExist(dir);
383     HILOG_DEBUG("ContextDeal::GetDataDir dir = %{public}s", dir.c_str());
384     return dir;
385 }
386 
387 /**
388  * @brief Obtains the directory for storing custom data files of the application.
389  * You can use the returned File object to create and access files in this directory. The files
390  * can be accessible only by the current application.
391  *
392  * @param name Indicates the name of the directory to retrieve. This directory is created as part
393  * of your application data.
394  * @param mode Indicates the file operating mode. The value can be 0 or a combination of MODE_PRIVATE.
395  *
396  * @return Returns a File object for the requested directory.
397  */
GetDir(const std::string & name,int mode)398 std::string ContextDeal::GetDir(const std::string &name, int mode)
399 {
400     HILOG_INFO("ContextDeal::GetDir begin");
401     if (applicationInfo_ == nullptr) {
402         HILOG_ERROR("ContextDeal::GetDir failed, applicationInfo_ == nullptr");
403         return "";
404     }
405     std::string dir = applicationInfo_->dataDir + CONTEXT_DEAL_FILE_SEPARATOR + name;
406     if (!OHOS::FileExists(dir)) {
407         HILOG_INFO("ContextDeal::GetDir File is not exits");
408         OHOS::ForceCreateDirectory(dir);
409         OHOS::ChangeModeDirectory(dir, mode);
410     }
411     HILOG_INFO("ContextDeal::GetDir end");
412     return dir;
413 }
414 
415 /**
416  * @brief Obtains the absolute path to the application-specific cache directory
417  * on the primary external or shared storage device.
418  *
419  * @return Returns the absolute path to the application-specific cache directory on the external or
420  * shared storage device; returns null if the external or shared storage device is temporarily unavailable.
421  */
GetExternalCacheDir()422 std::string ContextDeal::GetExternalCacheDir()
423 {
424     return "";
425 }
426 
427 /**
428  * @brief Obtains the absolute path to the directory for storing files for the application on the
429  * primary external or shared storage device.
430  *
431  * @param type Indicates the type of the file directory to return
432  *
433  * @return Returns the absolute path to the application file directory on the external or shared storage
434  * device; returns null if the external or shared storage device is temporarily unavailable.
435  */
GetExternalFilesDir(std::string & type)436 std::string ContextDeal::GetExternalFilesDir(std::string &type)
437 {
438     return "";
439 }
440 
441 /**
442  * @brief Obtains the directory for storing files for the application on the device's internal storage.
443  *
444  * @return Returns the application file directory.
445  */
GetFilesDir()446 std::string ContextDeal::GetFilesDir()
447 {
448     std::string dir = GetBaseDir() + CONTEXT_DEAL_FILE_SEPARATOR + CONTEXT_DEAL_Files;
449     CreateDirIfNotExist(dir);
450     HILOG_DEBUG("ContextDeal::GetFilesDir dir = %{public}s", dir.c_str());
451     return dir;
452 }
453 
454 /**
455  * @brief Obtains the absolute path which app created and will be excluded from automatic backup to remote storage.
456  * The returned path maybe changed if the application is moved to an adopted storage device.
457  *
458  * @return The path of the directory holding application files that will not be automatically backed up to remote
459  * storage.
460  */
GetNoBackupFilesDir()461 std::string ContextDeal::GetNoBackupFilesDir()
462 {
463     HILOG_INFO("ContextDeal::GetNoBackupFilesDir begin");
464     std::string dir = GetDataDir() + CONTEXT_DEAL_FILE_SEPARATOR + CONTEXT_DEAL_NO_BACKUP_Files;
465     if (!OHOS::FileExists(dir)) {
466         HILOG_INFO("ContextDeal::GetDir GetNoBackupFilesDir is not exits");
467         OHOS::ForceCreateDirectory(dir);
468         OHOS::ChangeModeDirectory(dir, MODE);
469     }
470     HILOG_DEBUG("ContextDeal::GetCodeCacheDir:%{public}s", dir.c_str());
471     return dir;
472 }
473 
474 /**
475  * @brief Checks whether the current process has the given permission.
476  * You need to call requestPermissionsFromUser(std::vector<std::string>,std::vector<int>, int) to request a permission
477  * only if the current process does not have the specific permission.
478  *
479  * @param permission Indicates the permission to check. This parameter cannot be null.
480  *
481  * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the current process has the permission;
482  * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise.
483  */
VerifySelfPermission(const std::string & permission)484 int ContextDeal::VerifySelfPermission(const std::string &permission)
485 {
486     return 0;
487 }
488 
489 /**
490  * @brief Obtains the bundle name of the current ability.
491  *
492  * @return Returns the bundle name of the current ability.
493  */
GetBundleName() const494 std::string ContextDeal::GetBundleName() const
495 {
496     return (applicationInfo_ != nullptr) ? applicationInfo_->bundleName : "";
497 }
498 
499 /**
500  * @brief Obtains the path of the OHOS Ability Package (HAP} containing this ability.
501  *
502  * @return Returns the path of the HAP containing this ability.
503  */
GetBundleResourcePath()504 std::string ContextDeal::GetBundleResourcePath()
505 {
506     if (abilityInfo_ == nullptr) {
507         return "";
508     }
509 
510     std::string dir;
511     if (isCreateBySystemApp_) {
512         dir = std::regex_replace(abilityInfo_->resourcePath, std::regex(ABS_CODE_PATH), LOCAL_BUNDLES);
513     } else {
514         std::regex pattern(ABS_CODE_PATH + FILE_SEPARATOR + abilityInfo_->bundleName);
515         dir = std::regex_replace(abilityInfo_->resourcePath, pattern, LOCAL_CODE_PATH);
516     }
517     return dir;
518 }
519 
520 /**
521  * @brief Starts a new ability.
522  * An ability using the AbilityInfo.AbilityType.SERVICE or AbilityInfo.AbilityType.PAGE template uses this method
523  * to start a specific ability. The system locates the target ability from installed abilities based on the value
524  * of the want parameter and then starts it. You can specify the ability to start using the want parameter.
525  *
526  * @param want Indicates the Want containing information about the target ability to start.
527  *
528  * @param requestCode Indicates the request code returned after the ability using the AbilityInfo.AbilityType.PAGE
529  * template is started. You can define the request code to identify the results returned by abilities. The value
530  * ranges from 0 to 65535. This parameter takes effect only on abilities using the AbilityInfo.AbilityType.PAGE
531  * template.
532  *
533  * @return errCode ERR_OK on success, others on failure.
534  */
StartAbility(const AAFwk::Want & want,int requestCode)535 ErrCode ContextDeal::StartAbility(const AAFwk::Want &want, int requestCode)
536 {
537     HILOG_INFO("ContextDeal::StartAbility is called");
538     return ERR_INVALID_VALUE;
539 }
540 
541 /**
542  * @brief Remove permissions for all users who have access to specific permissions
543  *
544  * @param permission Indicates the permission to unauth. This parameter cannot be null.
545  * @param uri Indicates the URI to unauth. This parameter cannot be null.
546  * @param uid Indicates the UID of the unauth to check.
547  *
548  */
UnauthUriPermission(const std::string & permission,const Uri & uri,int uid)549 void ContextDeal::UnauthUriPermission(const std::string &permission, const Uri &uri, int uid)
550 {}
551 
552 /**
553  * @brief Obtains an ability manager.
554  * The ability manager provides information about running processes and memory usage of an application.
555  *
556  * @return Returns an IAbilityManager instance.
557  */
GetAbilityManager()558 sptr<AAFwk::IAbilityManager> ContextDeal::GetAbilityManager()
559 {
560     HILOG_INFO("ContextDeal::GetAbilityManager begin");
561     auto remoteObject = OHOS::DelayedSingleton<SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
562     if (remoteObject == nullptr) {
563         HILOG_ERROR("failed to get ability manager service");
564         return nullptr;
565     }
566     HILOG_INFO("ContextDeal::SetPattern before iface_cast<remoteObject>");
567     sptr<AAFwk::IAbilityManager> ams = iface_cast<AAFwk::IAbilityManager>(remoteObject);
568     HILOG_INFO("ContextDeal::SetPattern after iface_cast<remoteObject>");
569     HILOG_INFO("ContextDeal::GetAbilityManager end");
570     return ams;
571 }
572 
573 /**
574  * @brief Obtains the type of this application.
575  *
576  * @return Returns system if this application is a system application;
577  * returns normal if it is released in OHOS AppGallery;
578  * returns other if it is released by a third-party vendor;
579  * returns an empty string if the query fails.
580  */
GetAppType()581 std::string ContextDeal::GetAppType()
582 {
583     HILOG_INFO("ContextDeal::GetAppType begin");
584     sptr<IBundleMgr> ptr = GetBundleManager();
585     if (ptr == nullptr) {
586         HILOG_ERROR("GetAppType failed to get bundle manager service");
587         return "";
588     }
589     std::string retString = ptr->GetAppType(applicationInfo_->bundleName);
590     HILOG_INFO("ContextDeal::GetAppType end");
591     return retString;
592 }
593 
594 /**
595  * @brief Destroys another ability you had previously started by calling Ability.startAbilityForResult
596  * (ohos.aafwk.content.Want, int, ohos.aafwk.ability.startsetting.AbilityStartSetting) with the same requestCode passed.
597  *
598  * @param requestCode Indicates the request code passed for starting the ability.
599  *
600  * @return errCode ERR_OK on success, others on failure.
601  */
TerminateAbility(int requestCode)602 ErrCode ContextDeal::TerminateAbility(int requestCode)
603 {
604     return ERR_INVALID_VALUE;
605 }
606 
607 /**
608  * @brief Query whether the application of the specified PID and UID has been granted a certain permission
609  *
610  * @param permissions Indicates the list of permissions to be requested. This parameter cannot be null.
611  * @param pid Process id
612  * @param uid
613  * @return Returns 0 (IBundleManager.PERMISSION_GRANTED) if the current process has the permission;
614  * returns -1 (IBundleManager.PERMISSION_DENIED) otherwise.
615  */
VerifyPermission(const std::string & permission,int pid,int uid)616 int ContextDeal::VerifyPermission(const std::string &permission, int pid, int uid)
617 {
618     return 0;
619 }
620 
IsCreateBySystemApp() const621 bool ContextDeal::IsCreateBySystemApp() const
622 {
623     return (static_cast<uint64_t>(flags_) & static_cast<uint64_t>(CONTEXT_CREATE_BY_SYSTEM_APP)) == 1;
624 }
625 
GetCurrentAccountId() const626 int ContextDeal::GetCurrentAccountId() const
627 {
628     int userId = 0;
629     AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(userId);
630     return userId;
631 }
632 
CreateDirIfNotExist(const std::string & dirPath) const633 void ContextDeal::CreateDirIfNotExist(const std::string &dirPath) const
634 {
635     HILOG_INFO("CreateDirIfNotExist: create directory if not exists.");
636     if (!OHOS::FileExists(dirPath)) {
637         HILOG_INFO("ContextDeal::CreateDirIfNotExist File is not exits");
638         bool createDir = OHOS::ForceCreateDirectory(dirPath);
639         if (!createDir) {
640             HILOG_INFO("CreateDirIfNotExist: create dir %{public}s failed.", dirPath.c_str());
641             return;
642         }
643     }
644 }
645 
646 /**
647  * @brief Obtains the distributed file path.
648  * If the distributed file path does not exist, the system creates one and returns the created path. This method is
649  * applicable only to the context of an ability rather than that of an application.
650  *
651  * @return Returns the distributed file.
652  */
GetDistributedDir()653 std::string ContextDeal::GetDistributedDir()
654 {
655     HILOG_INFO("ContextDeal::GetDistributedDir");
656     std::string dir;
657     if (IsCreateBySystemApp()) {
658         dir = CONTEXT_DISTRIBUTED_BASE_BEFORE + std::to_string(GetCurrentAccountId()) +
659               CONTEXT_DISTRIBUTED_BASE_MIDDLE + GetBundleName();
660     } else {
661         dir = CONTEXT_DATA_STORAGE + currArea_ + CONTEXT_DEAL_FILE_SEPARATOR + CONTEXT_DEAL_DISTRIBUTEDFILES;
662     }
663     CreateDirIfNotExist(dir);
664     HILOG_INFO("ContextDeal::GetDistributedDir:%{public}s", dir.c_str());
665     return dir;
666 }
667 /**
668  * @brief Sets the pattern of this Context based on the specified pattern ID.
669  *
670  * @param patternId Indicates the resource ID of the pattern to set.
671  */
SetPattern(int patternId)672 void ContextDeal::SetPattern(int patternId)
673 {
674     HILOG_INFO("ContextDeal::SetPattern begin");
675     if (resourceManager_ != nullptr) {
676         if (!pattern_.empty()) {
677             pattern_.clear();
678         }
679         HILOG_INFO("ContextDeal::SetPattern before resourceManager_->GetPatternById");
680         OHOS::Global::Resource::RState errval = resourceManager_->GetPatternById(patternId, pattern_);
681         HILOG_INFO("ContextDeal::SetPattern after resourceManager_->GetPatternById");
682         if (errval != OHOS::Global::Resource::RState::SUCCESS) {
683             HILOG_ERROR("ContextDeal::SetPattern GetPatternById(patternId:%d) retval is %u", patternId, errval);
684         }
685     } else {
686         HILOG_ERROR("ContextDeal::SetPattern resourceManager_ is nullptr");
687     }
688     HILOG_INFO("ContextDeal::SetPattern end");
689 }
690 
691 /**
692  * @brief Obtains the Context object of this ability.
693  *
694  * @return Returns the Context object of this ability.
695  */
GetAbilityPackageContext()696 std::shared_ptr<Context> ContextDeal::GetAbilityPackageContext()
697 {
698     return nullptr;
699 }
700 
701 /**
702  * @brief Obtains the HapModuleInfo object of the application.
703  *
704  * @return Returns the HapModuleInfo object of the application.
705  */
GetHapModuleInfo()706 std::shared_ptr<HapModuleInfo> ContextDeal::GetHapModuleInfo()
707 {
708     // fix set HapModuleInfoLocal data failed, request only once
709     if (hapModuleInfoLocal_ == nullptr) {
710         HapModuleInfoRequestInit();
711         if (hapModuleInfoLocal_ == nullptr) {
712             HILOG_ERROR("hapModuleInfoLocal_ is nullptr");
713             return nullptr;
714         }
715     }
716     HILOG_INFO("ContextDeal::GetHapModuleInfo end");
717     return hapModuleInfoLocal_;
718 }
719 
720 /**
721  * @brief Obtains the name of the current process.
722  *
723  * @return Returns the current process name.
724  */
GetProcessName()725 std::string ContextDeal::GetProcessName()
726 {
727     return (processInfo_ != nullptr) ? processInfo_->GetProcessName() : "";
728 }
729 
730 /**
731  * @brief Obtains the bundle name of the ability that called the current ability.
732  * You can use the obtained bundle name to check whether the calling ability is allowed to receive the data you will
733  * send. If you did not use Ability.startAbilityForResult(ohos.aafwk.content.Want, int,
734  * ohos.aafwk.ability.startsetting.AbilityStartSetting) to start the calling ability, null is returned.
735  *
736  * @return Returns the bundle name of the calling ability; returns null if no calling ability is available.
737  */
GetCallingBundle()738 std::string ContextDeal::GetCallingBundle()
739 {
740     return "";
741 }
742 
743 /**
744  * @brief Requests certain permissions from the system.
745  * This method is called for permission request. This is an asynchronous method. When it is executed,
746  * the Ability.onRequestPermissionsFromUserResult(int, String[], int[]) method will be called back.
747  *
748  * @param permissions Indicates the list of permissions to be requested. This parameter cannot be null.
749  * @param permissionsState Indicates the list of permissions' state to be requested. This parameter cannot be null.
750  * @param requestCode Indicates the request code to be passed to the Ability.onRequestPermissionsFromUserResult(int,
751  * String[], int[]) callback method. This code cannot be a negative number.
752  *
753  */
RequestPermissionsFromUser(std::vector<std::string> & permissions,std::vector<int> & permissionsState,int requestCode)754 void ContextDeal::RequestPermissionsFromUser(std::vector<std::string> &permissions, std::vector<int> &permissionsState,
755     int requestCode) {}
756 
757 /**
758  * @brief Starts a new ability with special ability start setting.
759  *
760  * @param want Indicates the Want containing information about the target ability to start.
761  * @param requestCode Indicates the request code returned after the ability is started. You can define the request code
762  * to identify the results returned by abilities. The value ranges from 0 to 65535.
763  * @param abilityStartSetting Indicates the special start setting used in starting ability.
764  *
765  * @return errCode ERR_OK on success, others on failure.
766  */
StartAbility(const Want & want,int requestCode,const AbilityStartSetting & abilityStartSetting)767 ErrCode ContextDeal::StartAbility(const Want &want, int requestCode, const AbilityStartSetting &abilityStartSetting)
768 {
769     return ERR_INVALID_VALUE;
770 }
771 
772 /**
773  * @brief Destroys the current ability.
774  *
775  * @return errCode ERR_OK on success, others on failure.
776  */
TerminateAbility()777 ErrCode ContextDeal::TerminateAbility()
778 {
779     return ERR_INVALID_VALUE;
780 }
781 
782 /**
783  * @brief Connects the current ability to an ability
784  *
785  * @param want Indicates the want containing information about the ability to connect
786  *
787  * @param conn Indicates the callback object when the target ability is connected.
788  *
789  * @return True means success and false means failure
790  */
ConnectAbility(const Want & want,const sptr<AAFwk::IAbilityConnection> & conn)791 bool ContextDeal::ConnectAbility(const Want &want, const sptr<AAFwk::IAbilityConnection> &conn)
792 {
793     return false;
794 }
795 
796 /**
797  * @brief Disconnects the current ability from an ability
798  *
799  * @param conn Indicates the IAbilityConnection callback object passed by connectAbility after the connection
800  *              is set up. The IAbilityConnection object uniquely identifies a connection between two abilities.
801  *
802  * @return errCode ERR_OK on success, others on failure.
803  */
DisconnectAbility(const sptr<AAFwk::IAbilityConnection> & conn)804 ErrCode ContextDeal::DisconnectAbility(const sptr<AAFwk::IAbilityConnection> &conn)
805 {
806     return ERR_INVALID_VALUE;
807 }
808 
GetToken()809 sptr<IRemoteObject> ContextDeal::GetToken()
810 {
811     return nullptr;
812 }
813 
814 /**
815  * @brief init the ResourceManager for ContextDeal.
816  *
817  * @param the ResourceManager has been inited.
818  *
819  */
initResourceManager(const std::shared_ptr<Global::Resource::ResourceManager> & resourceManager)820 void ContextDeal::initResourceManager(const std::shared_ptr<Global::Resource::ResourceManager> &resourceManager)
821 {
822     HILOG_INFO("ContextDeal::initResourceManager. Start.");
823     resourceManager_ = resourceManager;
824     HILOG_INFO("ContextDeal::initResourceManager. End.");
825 }
826 
827 /**
828  * @brief Obtains information about the caller of this ability.
829  *
830  * @return Returns the caller information.
831  */
GetCaller()832 Uri ContextDeal::GetCaller()
833 {
834     Uri uri(uriString_);
835     return uri;
836 }
837 
838 /**
839  * @brief SerUriString
840  */
SerUriString(const std::string & uri)841 void ContextDeal::SerUriString(const std::string &uri)
842 {
843     uriString_ = uri;
844 }
845 
846 /**
847  * @brief Get the string of this Context based on the specified resource ID.
848  *
849  * @param resId Indicates the resource ID of the string to get.
850  *
851  * @return Returns the string of this Context.
852  */
GetString(int resId)853 std::string ContextDeal::GetString(int resId)
854 {
855     HILOG_INFO("ContextDeal::GetString begin");
856     if (resourceManager_ == nullptr) {
857         HILOG_ERROR("ContextDeal::GetString resourceManager_ is nullptr");
858         return "";
859     }
860 
861     std::string ret;
862     HILOG_INFO("ContextDeal::GetString before resourceManager_->GetStringById");
863     OHOS::Global::Resource::RState errval = resourceManager_->GetStringById(resId, ret);
864     HILOG_INFO("ContextDeal::GetString after resourceManager_->GetStringById");
865     if (errval == OHOS::Global::Resource::RState::SUCCESS) {
866         return ret;
867     } else {
868         HILOG_ERROR("ContextDeal::GetString GetStringById(resId:%d) retval is %u", resId, errval);
869         return "";
870     }
871     HILOG_INFO("ContextDeal::GetString end");
872 }
873 
874 /**
875  * @brief Get the string array of this Context based on the specified resource ID.
876  *
877  * @param resId Indicates the resource ID of the string array to get.
878  *
879  * @return Returns the string array of this Context.
880  */
GetStringArray(int resId)881 std::vector<std::string> ContextDeal::GetStringArray(int resId)
882 {
883     HILOG_INFO("ContextDeal::GetStringArray begin");
884     if (resourceManager_ == nullptr) {
885         HILOG_ERROR("ContextDeal::GetStringArray resourceManager_ is nullptr");
886         return std::vector<std::string>();
887     }
888 
889     std::vector<std::string> retv;
890     HILOG_INFO("ContextDeal::GetString before resourceManager_->GetStringArrayById");
891     OHOS::Global::Resource::RState errval = resourceManager_->GetStringArrayById(resId, retv);
892     HILOG_INFO("ContextDeal::GetString after resourceManager_->GetStringArrayById");
893     if (errval == OHOS::Global::Resource::RState::SUCCESS) {
894         return retv;
895     } else {
896         HILOG_ERROR("ContextDeal::GetStringArray GetStringArrayById(resId:%d) retval is %u", resId, errval);
897         return std::vector<std::string>();
898     }
899     HILOG_INFO("ContextDeal::GetStringArray end");
900 }
901 
902 /**
903  * @brief Get the integer array of this Context based on the specified resource ID.
904  *
905  * @param resId Indicates the resource ID of the integer array to get.
906  *
907  * @return Returns the integer array of this Context.
908  */
GetIntArray(int resId)909 std::vector<int> ContextDeal::GetIntArray(int resId)
910 {
911     HILOG_INFO("ContextDeal::GetIntArray begin");
912     if (resourceManager_ == nullptr) {
913         HILOG_ERROR("ContextDeal::GetIntArray resourceManager_ is nullptr");
914         return std::vector<int>();
915     }
916 
917     std::vector<int> retv;
918     HILOG_INFO("ContextDeal::GetString before resourceManager_->GetIntArrayById");
919     OHOS::Global::Resource::RState errval = resourceManager_->GetIntArrayById(resId, retv);
920     HILOG_INFO("ContextDeal::GetString after resourceManager_->GetIntArrayById");
921     if (errval == OHOS::Global::Resource::RState::SUCCESS) {
922         return retv;
923     } else {
924         HILOG_ERROR("ContextDeal::GetIntArray GetIntArrayById(resId:%d) retval is %u", resId, errval);
925         return std::vector<int>();
926     }
927     HILOG_INFO("ContextDeal::GetIntArray end");
928 }
929 
930 /**
931  * @brief Obtains the theme of this Context.
932  *
933  * @return theme Returns the theme of this Context.
934  */
GetTheme()935 std::map<std::string, std::string> ContextDeal::GetTheme()
936 {
937     HILOG_INFO("ContextDeal::GetTheme begin");
938     if (theme_.empty()) {
939         SetTheme(GetThemeId());
940     }
941     HILOG_INFO("ContextDeal::GetTheme end");
942     return theme_;
943 }
944 
945 /**
946  * @brief Sets the theme of this Context based on the specified theme ID.
947  *
948  * @param themeId Indicates the resource ID of the theme to set.
949  */
SetTheme(int themeId)950 void ContextDeal::SetTheme(int themeId)
951 {
952     HILOG_INFO("ContextDeal::SetTheme begin");
953     if (resourceManager_ == nullptr) {
954         HILOG_ERROR("ContextDeal::SetTheme resourceManager_ is nullptr");
955         return;
956     }
957 
958     auto hapModInfo = GetHapModuleInfo();
959     if (hapModInfo == nullptr) {
960         HILOG_ERROR("ContextDeal::SetTheme hapModInfo is nullptr");
961         return;
962     }
963 
964     if (!theme_.empty()) {
965         theme_.clear();
966     }
967     HILOG_INFO("ContextDeal::GetString before resourceManager_->GetThemeById");
968     OHOS::Global::Resource::RState errval = resourceManager_->GetThemeById(themeId, theme_);
969     HILOG_INFO("ContextDeal::GetString after resourceManager_->GetThemeById");
970     if (errval != OHOS::Global::Resource::RState::SUCCESS) {
971         HILOG_ERROR("ContextDeal::SetTheme GetThemeById(themeId:%d) retval is %u", themeId, errval);
972         return;
973     }
974 
975     HILOG_INFO("ContextDeal::SetTheme end");
976     return;
977 }
978 
979 /**
980  * @brief Obtains the pattern of this Context.
981  *
982  * @return getPattern in interface Context
983  */
GetPattern()984 std::map<std::string, std::string> ContextDeal::GetPattern()
985 {
986     HILOG_INFO("ContextDeal::GetPattern begin");
987     if (!pattern_.empty()) {
988         HILOG_INFO("ContextDeal::GetPattern end");
989         return pattern_;
990     } else {
991         HILOG_ERROR("ContextDeal::GetPattern pattern_ is empty");
992         return std::map<std::string, std::string>();
993     }
994 }
995 
996 /**
997  * @brief Get the color of this Context based on the specified resource ID.
998  *
999  * @param resId Indicates the resource ID of the color to get.
1000  *
1001  * @return Returns the color value of this Context.
1002  */
GetColor(int resId)1003 int ContextDeal::GetColor(int resId)
1004 {
1005     HILOG_INFO("ContextDeal::GetColor begin");
1006     if (resourceManager_ == nullptr) {
1007         HILOG_ERROR("ContextDeal::GetColor resourceManager_ is nullptr");
1008         return INVALID_RESOURCE_VALUE;
1009     }
1010 
1011     uint32_t ret = INVALID_RESOURCE_VALUE;
1012     HILOG_INFO("ContextDeal::GetString before resourceManager_->GetColorById");
1013     OHOS::Global::Resource::RState errval = resourceManager_->GetColorById(resId, ret);
1014     HILOG_INFO("ContextDeal::GetString after resourceManager_->GetColorById");
1015     if (errval == OHOS::Global::Resource::RState::SUCCESS) {
1016         return ret;
1017     } else {
1018         HILOG_ERROR("ContextDeal::GetColor GetColorById(resId:%d) retval is %u", resId, errval);
1019         return INVALID_RESOURCE_VALUE;
1020     }
1021     HILOG_INFO("ContextDeal::GetColor end");
1022 }
1023 
1024 /**
1025  * @brief Obtains the theme id of this Context.
1026  *
1027  * @return int Returns the theme id of this Context.
1028  */
GetThemeId()1029 int ContextDeal::GetThemeId()
1030 {
1031     auto hapModInfo = GetHapModuleInfo();
1032     if (hapModInfo != nullptr) {
1033         return -1;
1034     } else {
1035         HILOG_ERROR("ContextDeal::GetThemeId hapModInfo is nullptr");
1036         return -1;
1037     }
1038 }
1039 
1040 /**
1041  * @brief
1042  * Destroys this Service ability if the number of times it has been started equals the number represented by the
1043  * given {@code startId}. This method is the same as calling {@link #terminateAbility} to destroy this Service
1044  * ability, except that this method helps you avoid destroying it if a client has requested a Service
1045  * ability startup in {@link ohos.aafwk.ability.Ability#onCommand} but you are unaware of it.
1046  *
1047  * @param startId Indicates the number of startup times of this Service ability passed to
1048  *                {@link ohos.aafwk.ability.Ability#onCommand}. The {@code startId} is
1049  *                incremented by 1 every time this ability is started. For example,
1050  *                if this ability has been started for six times, the value of {@code startId} is {@code 6}.
1051  *
1052  * @return Returns {@code true} if the {@code startId} matches the number of startup times
1053  *         and this Service ability will be destroyed; returns {@code false} otherwise.
1054  */
TerminateAbilityResult(int startId)1055 bool ContextDeal::TerminateAbilityResult(int startId)
1056 {
1057     return false;
1058 }
1059 
1060 /**
1061  * @brief Obtains the current display orientation of this ability.
1062  *
1063  * @return Returns the current display orientation.
1064  */
GetDisplayOrientation()1065 int ContextDeal::GetDisplayOrientation()
1066 {
1067     HILOG_INFO("ContextDeal::GetDisplayOrientation begin");
1068     if (abilityInfo_ != nullptr) {
1069         HILOG_INFO("ContextDeal::GetDisplayOrientation end");
1070         return static_cast<int>(abilityInfo_->orientation);
1071     } else {
1072         HILOG_ERROR("ContextDeal::GetDisplayOrientation abilityInfo_ is nullptr");
1073         return static_cast<int>(DisplayOrientation::UNSPECIFIED);
1074     }
1075 }
1076 
1077 /**
1078  * @brief Obtains the path storing the preference file of the application.
1079  *        If the preference file path does not exist, the system creates one and returns the created path.
1080  *
1081  * @return Returns the preference file path .
1082  */
GetPreferencesDir()1083 std::string ContextDeal::GetPreferencesDir()
1084 {
1085     HILOG_INFO("ContextDeal::GetPreferencesDir begin");
1086     std::string dir = GetBaseDir() + CONTEXT_DEAL_FILE_SEPARATOR + CONTEXT_DEAL_PREFERENCES;
1087     CreateDirIfNotExist(dir);
1088     HILOG_DEBUG("ContextDeal::GetPreferencesDir:%{public}s", dir.c_str());
1089     return dir;
1090 }
1091 
1092 /**
1093  * @brief Set color mode
1094  *
1095  * @param the value of color mode.
1096  */
SetColorMode(int mode)1097 void ContextDeal::SetColorMode(int mode)
1098 {
1099     HILOG_INFO("ContextDeal::SetColorMode begin");
1100     auto hapModInfo = GetHapModuleInfo();
1101     if (hapModInfo == nullptr) {
1102         HILOG_ERROR("ContextDeal::SetColorMode hapModInfo is nullptr");
1103         return;
1104     }
1105 
1106     if (mode == static_cast<int>(ModuleColorMode::DARK)) {
1107         hapModInfo->colorMode = ModuleColorMode::DARK;
1108     } else if (mode == static_cast<int>(ModuleColorMode::LIGHT)) {
1109         hapModInfo->colorMode = ModuleColorMode::LIGHT;
1110     } else {  // default use AUTO
1111         hapModInfo->colorMode = ModuleColorMode::AUTO;
1112     }
1113     HILOG_INFO("ContextDeal::SetColorMode end");
1114 }
1115 
1116 /**
1117  * @brief Obtains color mode.
1118  *
1119  * @return Returns the color mode value.
1120  */
GetColorMode()1121 int ContextDeal::GetColorMode()
1122 {
1123     HILOG_INFO("ContextDeal::GetColorMode begin");
1124     auto hapModInfo = GetHapModuleInfo();
1125     if (hapModInfo == nullptr) {
1126         HILOG_ERROR("ContextDeal::GetColorMode hapModInfo is nullptr");
1127         return -1;
1128     }
1129     HILOG_INFO("ContextDeal::GetColorMode end");
1130     return static_cast<int>(hapModInfo->colorMode);
1131 }
1132 
1133 /**
1134  * @brief Set the LifeCycleStateInfo to the deal.
1135  *
1136  * @param info the info to set.
1137  */
SetLifeCycleStateInfo(const AAFwk::LifeCycleStateInfo & info)1138 void ContextDeal::SetLifeCycleStateInfo(const AAFwk::LifeCycleStateInfo &info)
1139 {
1140     lifeCycleStateInfo_ = info;
1141 }
1142 
1143 /**
1144  * @brief Obtains the unique ID of the mission containing this ability.
1145  *
1146  * @return Returns the unique mission ID.
1147  */
GetMissionId()1148 int ContextDeal::GetMissionId()
1149 {
1150     return lifeCycleStateInfo_.missionId;
1151 }
1152 
1153 /**
1154  * @brief Obtains the lifecycle state info.
1155  *
1156  * @return Returns the lifecycle state info.
1157  */
GetLifeCycleStateInfo() const1158 AAFwk::LifeCycleStateInfo ContextDeal::GetLifeCycleStateInfo() const
1159 {
1160     return lifeCycleStateInfo_;
1161 }
1162 
1163 /**
1164  * @brief Call this when your ability should be closed and the mission should be completely removed as a part of
1165  * finishing the root ability of the mission.
1166  */
TerminateAndRemoveMission()1167 void ContextDeal::TerminateAndRemoveMission()
1168 {
1169     HILOG_INFO("ContextDeal::TerminateAndRemoveMission begin");
1170     auto abilityManagerClient = AAFwk::AbilityManagerClient::GetInstance();
1171     if (abilityManagerClient == nullptr) {
1172         HILOG_ERROR("ContextDeal::TerminateAndRemoveMission abilityManagerClient is nullptr");
1173         return;
1174     }
1175 
1176     std::vector<int32_t> removeIdList = {GetMissionId()};
1177     HILOG_INFO("ContextDeal::TerminateAndRemoveMission before abilityManagerClient->RemoveMissions");
1178     ErrCode errval = abilityManagerClient->RemoveMissions(removeIdList);
1179     HILOG_INFO("ContextDeal::TerminateAndRemoveMission after abilityManagerClient->RemoveMissions");
1180     if (errval != ERR_OK) {
1181         HILOG_WARN("ContextDeal::TerminateAndRemoveMission RemoveMissions retval is ERROR(%d)", errval);
1182     }
1183     HILOG_INFO("ContextDeal::TerminateAndRemoveMission end");
1184 }
1185 
1186 /**
1187  * @brief Starts multiple abilities.
1188  *
1189  * @param wants Indicates the Want containing information array about the target ability to start.
1190  */
StartAbilities(const std::vector<AAFwk::Want> & wants)1191 void ContextDeal::StartAbilities(const std::vector<AAFwk::Want> &wants)
1192 {}
1193 
1194 /**
1195  * @brief Checks whether this ability is the first ability in a mission.
1196  *
1197  * @return Returns true is first in Mission.
1198  */
IsFirstInMission()1199 bool ContextDeal::IsFirstInMission()
1200 {
1201     return false;
1202 }
1203 
1204 /**
1205  * @brief Obtains a task dispatcher that is bound to the UI thread.
1206  *
1207  * @return Returns the task dispatcher that is bound to the UI thread.
1208  */
GetUITaskDispatcher()1209 std::shared_ptr<TaskDispatcher> ContextDeal::GetUITaskDispatcher()
1210 {
1211     return ContextDeal::GetMainTaskDispatcher();
1212 }
1213 
1214 /**
1215  * @brief Obtains a task dispatcher that is bound to the application main thread.
1216  *
1217  * @return Returns the task dispatcher that is bound to the application main thread.
1218  */
GetMainTaskDispatcher()1219 std::shared_ptr<TaskDispatcher> ContextDeal::GetMainTaskDispatcher()
1220 {
1221     HILOG_INFO("ContextDeal::GetMainTaskDispatcher begin");
1222     if (mainTaskDispatcher_ != nullptr) {
1223         return mainTaskDispatcher_;
1224     }
1225 
1226     if (mainEventRunner_ == nullptr) {
1227         HILOG_ERROR("ContextDeal::GetMainTaskDispatcher mainTaskDispatcher_ is nullptr");
1228         return nullptr;
1229     }
1230 
1231     std::shared_ptr<SpecDispatcherConfig> config =
1232         std::make_shared<SpecDispatcherConfig>(SpecDispatcherConfig::MAIN, TaskPriority::HIGH);
1233     if (config == nullptr) {
1234         HILOG_ERROR("ContextDeal::GetMainTaskDispatcher config is nullptr");
1235         return nullptr;
1236     }
1237 
1238     mainTaskDispatcher_ = std::make_shared<SpecTaskDispatcher>(config, mainEventRunner_);
1239     HILOG_INFO("ContextDeal::GetMainTaskDispatcher end");
1240     return mainTaskDispatcher_;
1241 }
1242 
1243 /**
1244  * @brief Creates a parallel task dispatcher with a specified priority.
1245  *
1246  * @param name Indicates the task dispatcher name. This parameter is used to locate problems.
1247  * @param priority Indicates the priority of all tasks dispatched by the parallel task dispatcher.
1248  *
1249  * @return Returns a parallel task dispatcher.
1250  */
CreateParallelTaskDispatcher(const std::string & name,const TaskPriority & priority)1251 std::shared_ptr<TaskDispatcher> ContextDeal::CreateParallelTaskDispatcher(
1252     const std::string &name, const TaskPriority &priority)
1253 {
1254     HILOG_INFO("ContextDeal::CreateParallelTaskDispatcher begin");
1255     if (appContext_ == nullptr) {
1256         HILOG_ERROR("ContextDeal::CreateParallelTaskDispatcher appContext_ is nullptr");
1257         return nullptr;
1258     }
1259 
1260     std::shared_ptr<TaskDispatcher> task = appContext_->CreateParallelTaskDispatcher(name, priority);
1261     HILOG_INFO("ContextDeal::CreateParallelTaskDispatcher end");
1262     return task;
1263 }
1264 
1265 /**
1266  * @brief Creates a serial task dispatcher with a specified priority.
1267  *
1268  * @param name Indicates the task dispatcher name. This parameter is used to locate problems.
1269  * @param priority Indicates the priority of all tasks dispatched by the created task dispatcher.
1270  *
1271  * @return Returns a serial task dispatcher.
1272  */
CreateSerialTaskDispatcher(const std::string & name,const TaskPriority & priority)1273 std::shared_ptr<TaskDispatcher> ContextDeal::CreateSerialTaskDispatcher(
1274     const std::string &name, const TaskPriority &priority)
1275 {
1276     HILOG_INFO("ContextDeal::CreateSerialTaskDispatcher begin");
1277     if (appContext_ == nullptr) {
1278         HILOG_ERROR("ContextDeal::CreateSerialTaskDispatcher appContext_ is nullptr");
1279         return nullptr;
1280     }
1281 
1282     std::shared_ptr<TaskDispatcher> task = appContext_->CreateSerialTaskDispatcher(name, priority);
1283     HILOG_INFO("ContextDeal::CreateSerialTaskDispatcher end");
1284     return task;
1285 }
1286 
1287 /**
1288  * @brief Obtains a global task dispatcher with a specified priority.
1289  *
1290  * @param priority Indicates the priority of all tasks dispatched by the global task dispatcher.
1291  *
1292  * @return Returns a global task dispatcher.
1293  */
GetGlobalTaskDispatcher(const TaskPriority & priority)1294 std::shared_ptr<TaskDispatcher> ContextDeal::GetGlobalTaskDispatcher(const TaskPriority &priority)
1295 {
1296     HILOG_INFO("ContextDeal::GetGlobalTaskDispatcher begin");
1297     if (appContext_ == nullptr) {
1298         HILOG_ERROR("ContextDeal::GetGlobalTaskDispatcher appContext_ is nullptr");
1299         return nullptr;
1300     }
1301 
1302     std::shared_ptr<TaskDispatcher> task = appContext_->GetGlobalTaskDispatcher(priority);
1303     HILOG_INFO("ContextDeal::GetGlobalTaskDispatcher end");
1304     return task;
1305 }
1306 
1307 /**
1308  * @brief Set EventRunner for main thread.
1309  *
1310  * @param runner The EventRunner.
1311  */
SetRunner(const std::shared_ptr<EventRunner> & runner)1312 void ContextDeal::SetRunner(const std::shared_ptr<EventRunner> &runner)
1313 {
1314     mainEventRunner_ = runner;
1315 }
1316 
1317 /**
1318  * @brief init HapModuleInfo data
1319  *
1320  * @return Returns true on success, others on failure.
1321  */
HapModuleInfoRequestInit()1322 bool ContextDeal::HapModuleInfoRequestInit()
1323 {
1324     HILOG_INFO("ContextDeal::HapModuleInfoRequestInit begin");
1325 
1326     sptr<IBundleMgr> ptr = GetBundleManager();
1327     if (ptr == nullptr) {
1328         HILOG_ERROR("GetHapModuleInfo failed to get bundle manager service");
1329         return false;
1330     }
1331 
1332     if (abilityInfo_ == nullptr) {
1333         HILOG_ERROR("GetHapModuleInfo failed for abilityInfo_ is nullptr");
1334         return false;
1335     }
1336 
1337     hapModuleInfoLocal_ = std::make_shared<HapModuleInfo>();
1338     if (!ptr->GetHapModuleInfo(*abilityInfo_.get(), *hapModuleInfoLocal_)) {
1339         HILOG_ERROR("IBundleMgr::GetHapModuleInfo failed, will retval false value");
1340         return false;
1341     }
1342     HILOG_INFO("ContextDeal::HapModuleInfoRequestInit end");
1343     return true;
1344 }
1345 
1346 /**
1347  * @brief Requires that tasks associated with a given capability token be moved to the background
1348  *
1349  * @param nonFirst If nonfirst is false and not the lowest ability of the mission, you cannot move mission to end
1350  *
1351  * @return Returns true on success, others on failure.
1352  */
MoveMissionToEnd(bool nonFirst)1353 bool ContextDeal::MoveMissionToEnd(bool nonFirst)
1354 {
1355     return false;
1356 }
1357 
1358 /**
1359  * @brief Sets the application to start its ability in lock mission mode.
1360  */
LockMission()1361 void ContextDeal::LockMission()
1362 {}
1363 
1364 /**
1365  * @brief Unlocks this ability by exiting the lock mission mode.
1366  */
UnlockMission()1367 void ContextDeal::UnlockMission()
1368 {}
1369 
1370 /**
1371  * @brief Sets description information about the mission containing this ability.
1372  *
1373  * @param MissionInformation Indicates the object containing information about the
1374  *                               mission. This parameter cannot be null.
1375  * @return Returns true on success, others on failure.
1376  */
SetMissionInformation(const MissionInformation & missionInformation)1377 bool ContextDeal::SetMissionInformation(const MissionInformation &missionInformation)
1378 {
1379     return false;
1380 }
1381 
GetBaseDir() const1382 std::string ContextDeal::GetBaseDir() const
1383 {
1384     std::string baseDir;
1385     if (IsCreateBySystemApp()) {
1386         baseDir = CONTEXT_DEAL_DATA_APP + currArea_ + CONTEXT_DEAL_FILE_SEPARATOR +
1387             std::to_string(GetCurrentAccountId()) + CONTEXT_DEAL_FILE_SEPARATOR + CONTEXT_DEAL_BASE +
1388             CONTEXT_DEAL_FILE_SEPARATOR + GetBundleName();
1389     } else {
1390         baseDir = CONTEXT_DATA_STORAGE + currArea_ + CONTEXT_DEAL_FILE_SEPARATOR + CONTEXT_DEAL_BASE;
1391     }
1392 
1393     HILOG_DEBUG("ContextDeal::GetBaseDir:%{public}s", baseDir.c_str());
1394     return baseDir;
1395 }
1396 }  // namespace AppExecFwk
1397 }  // namespace OHOS
1398