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 static std::vector<std::string> Normalize(const std::string& param); 32 33 ErrCode IsDefaultApplication(int32_t userId, const std::string& type, bool& isDefaultApp) const; 34 ErrCode GetDefaultApplication( 35 int32_t userId, const std::string& type, BundleInfo& bundleInfo, bool backup = false) const; 36 ErrCode SetDefaultApplication(int32_t userId, const std::string& type, const Element& element) const; 37 ErrCode ResetDefaultApplication(int32_t userId, const std::string& type) const; 38 39 void HandleUninstallBundle(int32_t userId, const std::string& bundleName) const; 40 void HandleCreateUser(int32_t userId) const; 41 void HandleRemoveUser(int32_t userId) const; 42 43 bool GetDefaultApplication(const AAFwk::Want& want, const int32_t userId, std::vector<AbilityInfo>& abilityInfos, 44 std::vector<ExtensionAbilityInfo>& extensionInfos, bool backup = false) const; 45 private: 46 DefaultAppMgr(); 47 ~DefaultAppMgr(); 48 DISALLOW_COPY_AND_MOVE(DefaultAppMgr); 49 50 static bool IsAppType(const std::string& param); 51 static bool IsSpecificMimeType(const std::string& param); 52 53 void Init(); 54 ErrCode GetBundleInfoByAppType( 55 int32_t userId, const std::string& appType, BundleInfo& bundleInfo, bool backup = false) const; 56 ErrCode GetBundleInfoByUtd( 57 int32_t userId, const std::string& utd, BundleInfo& bundleInfo, bool backup = false) const; 58 bool GetBundleInfo(int32_t userId, const std::string& type, const Element& element, BundleInfo& bundleInfo) const; 59 bool IsMatch(const std::string& type, const std::vector<Skill>& skills) const; 60 bool MatchAppType(const std::string& type, const std::vector<Skill>& skills) const; 61 bool MatchUtd(const std::string& utd, const std::vector<Skill>& skills) const; 62 bool IsElementEmpty(const Element& element) const; 63 bool IsElementValid(int32_t userId, const std::string& type, const Element& element) const; 64 bool IsUserIdExist(int32_t userId) const; 65 bool IsBrowserSkillsValid(const std::vector<Skill>& skills) const; 66 bool IsEmailSkillsValid(const std::vector<Skill>& skills) const; 67 bool IsBrowserWant(const AAFwk::Want& want) const; 68 bool IsEmailWant(const AAFwk::Want& want) const; 69 std::string GetTypeFromWant(const AAFwk::Want& want) const; 70 bool MatchActionAndType(const std::string& action, const std::string& type, const std::vector<Skill>& skills) const; 71 bool GetBrokerBundleInfo(const Element& element, BundleInfo& bundleInfo) const; 72 ErrCode VerifyPermission(const std::string& permissionName) const; 73 74 ErrCode IsDefaultApplicationInternal(int32_t userId, const std::string& normalizedType, bool& isDefaultApp) const; 75 ErrCode GetDefaultApplicationInternal( 76 int32_t userId, const std::string& normalizedType, BundleInfo& bundleInfo, bool backup = false) const; 77 ErrCode SetDefaultApplicationInternal( 78 int32_t userId, const std::string& normalizedType, const Element& element) const; 79 ErrCode ResetDefaultApplicationInternal(int32_t userId, const std::string& normalizedType) const; 80 81 std::shared_ptr<IDefaultAppDb> defaultAppDb_; 82 mutable std::mutex mutex_; 83 }; 84 } 85 } 86 #endif 87