Signed-off-by: zhuhan <zhuhan10@huawei.com>
Change-Id: I0ffcc5e4d3b7539a6cc5bc40b74526f43ad34bf1
This commit is contained in:
zhuhan
2023-05-26 17:08:24 +08:00
parent 6ccd524111
commit fd45affbab
2 changed files with 25 additions and 20 deletions
+17 -16
View File
@@ -107,7 +107,7 @@ void OffWorkerFunc(NativeEngine* nativeEngine)
using Extractor = AbilityBase::Extractor;
using ExtractorUtil = AbilityBase::ExtractorUtil;
using BundleMgrProxy = AppExecFwk::BundleMgrProxy;
using IBundleMgr = AppExecFwk::IBundleMgr;
std::string AssetHelper::NormalizedFileName(const std::string& fileName) const
{
@@ -126,7 +126,7 @@ std::string AssetHelper::NormalizedFileName(const std::string& fileName) const
return normalizedFilePath;
}
void AssetHelper::operator()(const std::string& uri, std::vector<uint8_t>& content, std::string &ami) const
void AssetHelper::operator()(const std::string& uri, std::vector<uint8_t>& content, std::string &ami)
{
if (uri.empty()) {
HILOG_ERROR("Uri is empty.");
@@ -197,23 +197,24 @@ void AssetHelper::operator()(const std::string& uri, std::vector<uint8_t>& conte
}
}
sptr<BundleMgrProxy> AssetHelper::GetBundleMgrProxy() const
sptr<IBundleMgr> AssetHelper::GetBundleMgrProxy()
{
auto systemAbilityManager =
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (!systemAbilityManager) {
HILOG_ERROR("fail to get system ability mgr.");
return nullptr;
}
auto remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
if (!remoteObject) {
HILOG_ERROR("fail to get bundle manager proxy.");
return nullptr;
if (bundleMgrProxy_ == nullptr) {
auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (!systemAbilityManager) {
HILOG_ERROR("fail to get system ability mgr.");
return nullptr;
}
auto remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
if (!remoteObject) {
HILOG_ERROR("fail to get bundle manager proxy.");
return nullptr;
}
bundleMgrProxy_ = iface_cast<IBundleMgr>(remoteObject);
}
HILOG_DEBUG("get bundle manager proxy success.");
return iface_cast<BundleMgrProxy>(remoteObject);
return bundleMgrProxy_;
}
bool AssetHelper::ReadAmiData(const std::string& ami, std::vector<uint8_t>& content) const
@@ -243,7 +244,7 @@ bool AssetHelper::ReadAmiData(const std::string& ami, std::vector<uint8_t>& cont
return true;
}
bool AssetHelper::ReadFilePathData(const std::string& filePath, std::vector<uint8_t>& content) const
bool AssetHelper::ReadFilePathData(const std::string& filePath, std::vector<uint8_t>& content)
{
auto bundleMgrProxy = GetBundleMgrProxy();
if (!bundleMgrProxy) {
+8 -4
View File
@@ -29,7 +29,8 @@ int32_t GetContainerId();
void UpdateContainerScope(int32_t id);
void RestoreContainerScope(int32_t id);
struct AssetHelper final {
class AssetHelper final {
public:
explicit AssetHelper(const std::string& codePath, bool isDebugVersion, bool isBundle)
: codePath_(codePath), isDebugVersion_(isDebugVersion), isBundle_(isBundle)
{
@@ -40,17 +41,20 @@ struct AssetHelper final {
std::string NormalizedFileName(const std::string& fileName) const;
void operator()(const std::string& uri, std::vector<uint8_t>& content, std::string &ami) const;
void operator()(const std::string& uri, std::vector<uint8_t>& content, std::string &ami);
sptr<AppExecFwk::BundleMgrProxy> GetBundleMgrProxy() const;
sptr<AppExecFwk::IBundleMgr> GetBundleMgrProxy();
bool ReadAmiData(const std::string& ami, std::vector<uint8_t>& content) const;
bool ReadFilePathData(const std::string& filePath, std::vector<uint8_t>& content) const;
bool ReadFilePathData(const std::string& filePath, std::vector<uint8_t>& content);
std::string codePath_;
bool isDebugVersion_ = false;
bool isBundle_ = true;
private:
sptr<AppExecFwk::IBundleMgr> bundleMgrProxy_ = nullptr;
};
} // namespace AbilityRuntime