1 /* 2 * Copyright (c) 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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_D_BUNDLEMGR_INCLUDE_DISTRIBUTED_BMS_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_D_BUNDLEMGR_INCLUDE_DISTRIBUTED_BMS_H 18 19 #include <memory> 20 21 #include "bundle_info.h" 22 #include "bundle_mgr_interface.h" 23 #include "distributed_bms_host.h" 24 #include "distributed_monitor.h" 25 #include "if_system_ability_manager.h" 26 #include "iremote_object.h" 27 #include "resource_manager.h" 28 #include "singleton.h" 29 #include "system_ability.h" 30 namespace OHOS { 31 namespace AppExecFwk { 32 class DistributedBms : public SystemAbility, public DistributedBmsHost { 33 DECLARE_DELAYED_SINGLETON(DistributedBms); 34 DECLARE_SYSTEM_ABILITY(DistributedBms); 35 36 public: 37 OHOS::sptr<OHOS::AppExecFwk::IBundleMgr> GetBundleMgr(); 38 39 /** 40 * @brief get remote ability info 41 * @param elementName Indicates the elementName. 42 * @param remoteAbilityInfo Indicates the remote ability info. 43 * @return Returns true when get remote ability info success; returns false otherwise. 44 */ 45 int32_t GetRemoteAbilityInfo( 46 const OHOS::AppExecFwk::ElementName &elementName, RemoteAbilityInfo &remoteAbilityInfo) override; 47 48 /** 49 * @brief get remote ability info 50 * @param elementName Indicates the elementName. 51 * @param localeInfo Indicates the localeInfo. 52 * @param remoteAbilityInfo Indicates the remote ability info. 53 * @return Returns true when get remote ability info success; returns false otherwise. 54 */ 55 int32_t GetRemoteAbilityInfo(const OHOS::AppExecFwk::ElementName &elementName, const std::string &localeInfo, 56 RemoteAbilityInfo &remoteAbilityInfo) override; 57 /** 58 * @brief get remote ability infos 59 * @param elementNames Indicates the elementNames. 60 * @param remoteAbilityInfos Indicates the remote ability infos. 61 * @return Returns true when get remote ability info success; returns false otherwise. 62 */ 63 int32_t GetRemoteAbilityInfos( 64 const std::vector<ElementName> &elementNames, std::vector<RemoteAbilityInfo> &remoteAbilityInfos) override; 65 66 /** 67 * @brief get remote ability infos 68 * @param elementNames Indicates the elementNames. 69 * @param localeInfo Indicates the localeInfo. 70 * @param remoteAbilityInfos Indicates the remote ability infos. 71 * @return Returns true when get remote ability info success; returns false otherwise. 72 */ 73 int32_t GetRemoteAbilityInfos(const std::vector<ElementName> &elementNames, const std::string &localeInfo, 74 std::vector<RemoteAbilityInfo> &remoteAbilityInfos) override; 75 76 /** 77 * @brief get ability info 78 * @param elementName Indicates the elementName. 79 * @param remoteAbilityInfo Indicates the remote ability info. 80 * @return Returns true when get remote ability info success; returns false otherwise. 81 */ 82 int32_t GetAbilityInfo( 83 const OHOS::AppExecFwk::ElementName &elementName, RemoteAbilityInfo &remoteAbilityInfo) override; 84 85 /** 86 * @brief get ability info 87 * @param elementName Indicates the elementName. 88 * @param localeInfo Indicates the localeInfo. 89 * @param remoteAbilityInfo Indicates the remote ability info. 90 * @return Returns true when get remote ability info success; returns false otherwise. 91 */ 92 int32_t GetAbilityInfo(const OHOS::AppExecFwk::ElementName &elementName, const std::string &localeInfo, 93 RemoteAbilityInfo &remoteAbilityInfo) override; 94 /** 95 * @brief get ability infos 96 * @param elementNames Indicates the elementNames. 97 * @param remoteAbilityInfos Indicates the remote ability infos. 98 * @return Returns true when get remote ability info success; returns false otherwise. 99 */ 100 int32_t GetAbilityInfos( 101 const std::vector<ElementName> &elementNames, std::vector<RemoteAbilityInfo> &remoteAbilityInfos) override; 102 103 /** 104 * @brief get ability infos 105 * @param elementNames Indicates the elementNames. 106 * @param localeInfo Indicates the localeInfo. 107 * @param remoteAbilityInfos Indicates the remote ability infos. 108 * @return Returns true when get remote ability info success; returns false otherwise. 109 */ 110 int32_t GetAbilityInfos(const std::vector<ElementName> &elementNames, const std::string &localeInfo, 111 std::vector<RemoteAbilityInfo> &remoteAbilityInfos) override; 112 113 bool GetDistributedBundleInfo(const std::string &networkId, const std::string &bundleName, 114 DistributedBundleInfo &distributedBundleInfo) override; 115 116 /** 117 * @brief Start the bundle manager service. 118 * @return 119 */ 120 virtual void OnStart() override; 121 /** 122 * @brief Stop the bundle manager service. 123 * @return 124 */ 125 virtual void OnStop() override; 126 private: 127 OHOS::sptr<OHOS::AppExecFwk::IBundleMgr> bundleMgr_; 128 std::shared_ptr<DistributedMonitor> distributedSub_; 129 std::mutex bundleMgrMutex_; 130 131 void Init(); 132 bool GetMediaBase64(std::unique_ptr<uint8_t[]> &data, int64_t fileLength, 133 std::string &imageType, std::string &value); 134 std::unique_ptr<unsigned char[]> LoadResourceFile(std::string &path, int &len); 135 std::unique_ptr<char[]> EncodeBase64(std::unique_ptr<uint8_t[]> &data, int srcLen); 136 int32_t GetAbilityIconByContent( 137 const AbilityInfo &abilityInfo, int32_t userId, RemoteAbilityInfo &remoteAbilityInfo); 138 int32_t Base64WithoutCompress(std::unique_ptr<uint8_t[]> &imageContent, size_t imageContentSize, 139 RemoteAbilityInfo &remoteAbilityInfo); 140 }; 141 } // namespace AppExecFwk 142 } // namespace OHOS 143 #endif // FOUNDATION_APPEXECFWK_SERVICES_D_BUNDLEMGR_INCLUDE_DISTRIBUTED_BMS_H