• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 FOUNDATION_DEFAULT_APPLICATION_FRAMEWORK_DEFAULT_APP_MGR
17 #define FOUNDATION_DEFAULT_APPLICATION_FRAMEWORK_DEFAULT_APP_MGR
18 
19 #include <mutex>
20 #include <set>
21 
22 #include "default_app_db_interface.h"
23 #include "nocopyable.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 class DefaultAppMgr {
28 public:
29     static DefaultAppMgr& GetInstance();
30     static bool VerifyElementFormat(const Element& element);
31     ErrCode IsDefaultApplication(int32_t userId, const std::string& type, bool& isDefaultApp) const;
32     ErrCode GetDefaultApplication(
33         int32_t userId, const std::string& type, BundleInfo& bundleInfo, bool backup = false) const;
34     ErrCode SetDefaultApplication(int32_t userId, const std::string& type, const Element& element) const;
35     ErrCode ResetDefaultApplication(int32_t userId, const std::string& type) const;
36     void HandleUninstallBundle(int32_t userId, const std::string& bundleName) const;
37     void HandleCreateUser(int32_t userId) const;
38     void HandleRemoveUser(int32_t userId) const;
39 
40     bool GetDefaultApplication(const AAFwk::Want& want, const int32_t userId, std::vector<AbilityInfo>& abilityInfos,
41         std::vector<ExtensionAbilityInfo>& extensionInfos, bool backup = false) const;
42 private:
43     DefaultAppMgr();
44     ~DefaultAppMgr();
45     DISALLOW_COPY_AND_MOVE(DefaultAppMgr);
46     void Init();
47     ErrCode GetBundleInfoByAppType(
48         int32_t userId, const std::string& type, BundleInfo& bundleInfo, bool backup = false) const;
49     ErrCode GetBundleInfoByFileType(
50         int32_t userId, const std::string& type, BundleInfo& bundleInfo, bool backup = false) const;
51     bool GetBundleInfo(int32_t userId, const std::string& type, const Element& element, BundleInfo& bundleInfo) const;
52     bool IsTypeValid(const std::string& type) const;
53     bool IsAppType(const std::string& type) const;
54     bool IsFileType(const std::string& type) const;
55     bool IsMatch(const std::string& type, const std::vector<Skill>& skills) const;
56     bool MatchAppType(const std::string& type, const std::vector<Skill>& skills) const;
57     bool MatchFileType(const std::string& type, const std::vector<Skill>& skills) const;
58     bool IsElementEmpty(const Element& element) const;
59     bool IsElementValid(int32_t userId, const std::string& type, const Element& element) const;
60     bool IsUserIdExist(int32_t userId) const;
61     ErrCode VerifyUserIdAndType(int32_t userId, const std::string& type) const;
62     bool IsBrowserSkillsValid(const std::vector<Skill>& skills) const;
63     bool IsEmailSkillsValid(const std::vector<Skill>& skills) const;
64     void ConvertTypeBySuffix(std::string& suffix) const;
65     bool IsBrowserWant(const AAFwk::Want& want) const;
66     bool IsEmailWant(const AAFwk::Want& want) const;
67     std::string GetType(const AAFwk::Want& want) const;
68     bool MatchActionAndType(const std::string& action, const std::string& type, const std::vector<Skill>& skills) const;
69 
70     std::shared_ptr<IDefaultAppDb> defaultAppDb_;
71     mutable std::mutex mutex_;
72 };
73 }
74 }
75 #endif
76