1 /* 2 * Copyright (c) 2021-2025 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_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_LAUNCHER_SERVICE_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_LAUNCHER_SERVICE_H 18 19 #include <string> 20 #include <vector> 21 22 #include "appexecfwk_errors.h" 23 #include "bundle_mgr_interface.h" 24 #include "securec.h" 25 #include "system_ability_definition.h" 26 #include "if_system_ability_manager.h" 27 #include "iservice_registry.h" 28 #include "bundle_monitor.h" 29 #include "bundle_status_callback_interface.h" 30 #include "launcher_ability_info.h" 31 #include "ability_info.h" 32 #include "application_info.h" 33 #include "want.h" 34 #include "app_log_wrapper.h" 35 36 namespace OHOS { 37 namespace AppExecFwk { 38 class LauncherService : public virtual RefBase { 39 public: 40 using Want = OHOS::AAFwk::Want; 41 42 LauncherService(); 43 virtual ~LauncherService(); 44 45 /** 46 * @brief Registers a callback method for monitoring bundle installation, uninstallation, and update events. 47 * @param callback Indicates the callback method to be called. 48 * @return Returns true if this function is successfully called; returns false otherwise. 49 */ 50 virtual bool RegisterCallback(const sptr<IBundleStatusCallback> &callback); 51 /** 52 * @brief Unregisters the callback method for monitoring bundle installation, uninstallation, and update events. 53 * @return Returns true if this function is successfully called; returns false otherwise. 54 */ 55 virtual bool UnRegisterCallback(); 56 /** 57 * @brief Obtains launcher abilities based on the bundle name and user id. 58 * @param bundleName Indicates the bundle name. 59 * @param userId Indicates the user ID. 60 * @param launcherAbilityInfos List of LauncherAbilityInfo objects if obtained; 61 * @return Returns true if this function is successfully called; returns false otherwise. 62 */ 63 virtual bool GetAbilityList( 64 const std::string &bundleName, const int userId, std::vector<LauncherAbilityInfo> &launcherAbilityInfos); 65 /** 66 * @brief Obtains information about the shortcuts of the application. 67 * @param bundleName Indicates the bundle name of the application. 68 * @param ShortcutInfo List of ShortcutInfo objects if obtained. 69 * @return Returns true if the function is successfully called; returns false otherwise. 70 */ 71 virtual ErrCode GetShortcutInfos(const std::string &bundleName, std::vector<ShortcutInfo> &shortcutInfo); 72 /** 73 * @brief Obtains information about the launcher ability of all application that appears on launcher. 74 * @param userId Indicates the id for the user. 75 * @param launcherAbilityInfo Indicates the obtained LauncherAbilityInfo object. 76 * @return Returns true if the function is successfully called; returns false otherwise. 77 */ 78 virtual bool GetAllLauncherAbilityInfos(int32_t userId, std::vector<LauncherAbilityInfo> &launcherAbilityInfos); 79 /** 80 * @brief Obtains information about the launcher ability of input bundleName and userId. 81 * @param bundleName Indicates the bundleName of the application. 82 * @param userId Indicates the id for the user. 83 * @param launcherAbilityInfos Indicates the obtained vector of the input bundle. 84 * @return Returns ERR code of the result. 85 */ 86 ErrCode GetLauncherAbilityByBundleName(const std::string &bundleName, const int32_t userId, 87 std::vector<LauncherAbilityInfo> &launcherAbilityInfos); 88 /** 89 * @brief Public interface obtains information about the launcher ability of input bundleName and userId. 90 * @param bundleName Indicates the bundleName of the application. 91 * @param userId Indicates the id for the user. 92 * @param launcherAbilityInfos Indicates the obtained vector of the input bundle. 93 * @return Returns ERR code of the result. 94 */ 95 ErrCode GetLauncherAbilityInfoSync(const std::string &bundleName, const int32_t userId, 96 std::vector<LauncherAbilityInfo> &launcherAbilityInfos); 97 /** 98 * @brief Obtains information about the launcher ability of input bundleName and userId. 99 * @param userId Indicates the id for the user. 100 * @param launcherAbilityInfos Indicates the obtained vector of all launcher bundle. 101 * @return Returns ERR code of the result. 102 */ 103 ErrCode GetAllLauncherAbility(const int32_t userId, std::vector<LauncherAbilityInfo> &launcherAbilityInfos); 104 /** 105 * @brief Obtains information about the shortcuts of the application. 106 * @param bundleName Indicates the bundle name of the application. 107 * @param ShortcutInfo List of ShortcutInfo objects if obtained. 108 * @return Returns err code of result. 109 */ 110 ErrCode GetShortcutInfoV9(const std::string &bundleName, 111 std::vector<ShortcutInfo> &shortcutInfos, int32_t userId = Constants::UNSPECIFIED_USERID); 112 113 /** 114 * @brief Obtains information about the shortcuts of the application by appIndex. 115 * @param bundleName Indicates the bundle name of the application. 116 * @param ShortcutInfo List of ShortcutInfo objects if obtained. 117 * @param appIndex Indicates the app index of clone applications. 118 * @param userId Indicates the user ID. 119 * @return Returns err code of result. 120 */ 121 ErrCode GetShortcutInfoByAppIndex(const std::string &bundleName, const int32_t appIndex, 122 std::vector<ShortcutInfo> &shortcutInfos); 123 124 private: 125 void InitWant(Want &want, const std::string &bundleName); 126 void ConvertAbilityToLauncherAbility(const AbilityInfo &ability, LauncherAbilityInfo &launcherAbility, 127 const int32_t userId); 128 129 private: 130 void Init(); 131 void OnDeath(); 132 static OHOS::sptr<OHOS::AppExecFwk::IBundleMgr> GetBundleMgr(); 133 134 std::shared_ptr<BundleMonitor> bundleMonitor_ = nullptr; 135 static OHOS::sptr<OHOS::AppExecFwk::IBundleMgr> bundleMgr_; 136 static OHOS::sptr<IRemoteObject::DeathRecipient> deathRecipient_; 137 138 static std::mutex bundleMgrMutex_; 139 DISALLOW_COPY_AND_MOVE(LauncherService); 140 141 class LauncherServiceDeathRecipient : public IRemoteObject::DeathRecipient { 142 virtual void OnRemoteDied([[maybe_unused]] const wptr<IRemoteObject>& remote) override; 143 }; 144 }; 145 } // namespace AppExecFwk 146 } // namespace OHOS 147 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_LAUNCHER_SERVICE_H