mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-12-04 05:22:25 +00:00
commit
af4e25998f
@ -15,6 +15,7 @@
|
||||
|
||||
#include "js_quickfix_callback.h"
|
||||
|
||||
#include "file_mapper.h"
|
||||
#include "file_path_utils.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "js_runtime.h"
|
||||
@ -27,7 +28,7 @@ namespace {
|
||||
}
|
||||
|
||||
bool JsQuickfixCallback::operator()(std::string baseFileName, std::string &patchFileName,
|
||||
void **patchBuffer, size_t &patchSize)
|
||||
uint8_t **patchBuffer, size_t &patchSize)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::JSRUNTIME, "baseFileName: %{private}s", baseFileName.c_str());
|
||||
auto position = baseFileName.find(".abc");
|
||||
@ -56,13 +57,18 @@ bool JsQuickfixCallback::operator()(std::string baseFileName, std::string &patch
|
||||
TAG_LOGD(AAFwkTag::JSRUNTIME, "hqfFile: %{private}s, resolvedHqfFile: %{private}s", hqfFile.c_str(),
|
||||
resolvedHqfFile.c_str());
|
||||
|
||||
if (!JsRuntime::GetFileBuffer(resolvedHqfFile, patchFileName, newpatchBuffer_)) {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "GetFileBuffer failed");
|
||||
auto data = JsRuntime::GetSafeData(resolvedHqfFile, patchFileName);
|
||||
if (data == nullptr) {
|
||||
if (patchFileName.empty()) {
|
||||
TAG_LOGI(AAFwkTag::JSRUNTIME, "No need to load patch cause no ets. path: %{private}s",
|
||||
resolvedHqfFile.c_str());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
*patchBuffer = newpatchBuffer_.data();
|
||||
*patchBuffer = data->GetDataPtr();
|
||||
TAG_LOGD(AAFwkTag::JSRUNTIME, "patchFileName: %{private}s", patchFileName.c_str());
|
||||
patchSize = newpatchBuffer_.size();
|
||||
patchSize = data->GetDataLen();
|
||||
return true;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
|
||||
bool operator()(std::string baseFileName,
|
||||
std::string &patchFileName,
|
||||
void **patchBuffer,
|
||||
uint8_t **patchBuffer,
|
||||
size_t &patchSize);
|
||||
|
||||
private:
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "connect_server_manager.h"
|
||||
#include "ecmascript/napi/include/jsnapi.h"
|
||||
#include "extract_resource_manager.h"
|
||||
#include "file_mapper.h"
|
||||
#include "file_path_utils.h"
|
||||
#include "hdc_register.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
@ -484,6 +485,33 @@ bool JsRuntime::GetFileBuffer(const std::string& filePath, std::string& fileFull
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<AbilityBase::FileMapper> JsRuntime::GetSafeData(const std::string& path, std::string& fileFullName)
|
||||
{
|
||||
bool newCreate = false;
|
||||
auto extractor = ExtractorUtil::GetExtractor(path, newCreate, true);
|
||||
if (extractor == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "Get extractor failed. path: %{private}s", path.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<std::string> fileNames;
|
||||
extractor->GetSpecifiedTypeFiles(fileNames, ".abc");
|
||||
if (fileNames.empty()) {
|
||||
TAG_LOGI(AAFwkTag::JSRUNTIME, "There's no abc file in hap or hqf: %{private}s", path.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
std::string fileName = fileNames.front();
|
||||
fileFullName = path + "/" + fileName;
|
||||
|
||||
auto safeData = extractor->GetSafeData(fileName);
|
||||
if (safeData == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "Get safe data failed. path: %{private}s", path.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return safeData;
|
||||
}
|
||||
|
||||
bool JsRuntime::LoadRepairPatch(const std::string& hqfFile, const std::string& hapPath)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::JSRUNTIME, "called");
|
||||
@ -493,16 +521,18 @@ bool JsRuntime::LoadRepairPatch(const std::string& hqfFile, const std::string& h
|
||||
InitSourceMap(hqfFile);
|
||||
|
||||
std::string patchFile;
|
||||
std::vector<uint8_t> patchBuffer;
|
||||
if (!GetFileBuffer(hqfFile, patchFile, patchBuffer)) {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "LoadRepairPatch, get patch file buffer failed.");
|
||||
auto hqfSafeData = GetSafeData(hqfFile, patchFile);
|
||||
if (hqfSafeData == nullptr) {
|
||||
if (patchFile.empty()) {
|
||||
TAG_LOGI(AAFwkTag::JSRUNTIME, "No need to load patch cause no ets. path: %{private}s", hqfFile.c_str());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string baseFile;
|
||||
std::vector<uint8_t> baseBuffer;
|
||||
if (!GetFileBuffer(hapPath, baseFile, baseBuffer)) {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "LoadRepairPatch, get base file buffer failed.");
|
||||
auto hapSafeData = GetSafeData(hapPath, baseFile);
|
||||
if (hapSafeData == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -519,8 +549,8 @@ bool JsRuntime::LoadRepairPatch(const std::string& hqfFile, const std::string& h
|
||||
|
||||
TAG_LOGD(AAFwkTag::JSRUNTIME, "LoadRepairPatch, LoadPatch, patchFile: %{private}s, baseFile: %{private}s.",
|
||||
patchFile.c_str(), resolvedHapPath.c_str());
|
||||
auto ret = panda::JSNApi::LoadPatch(vm, patchFile, patchBuffer.data(), patchBuffer.size(),
|
||||
resolvedHapPath, baseBuffer.data(), baseBuffer.size());
|
||||
auto ret = panda::JSNApi::LoadPatch(vm, patchFile, hqfSafeData->GetDataPtr(), hqfSafeData->GetDataLen(),
|
||||
resolvedHapPath, hapSafeData->GetDataPtr(), hapSafeData->GetDataLen());
|
||||
if (ret != panda::JSNApi::PatchErrorCode::SUCCESS) {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "LoadPatch failed with %{public}d.", static_cast<int32_t>(ret));
|
||||
return false;
|
||||
|
@ -39,6 +39,7 @@ class EventHandler;
|
||||
|
||||
namespace AbilityBase {
|
||||
class Extractor;
|
||||
class FileMapper;
|
||||
} // namespace AbilityBase
|
||||
|
||||
namespace JsEnv {
|
||||
@ -116,6 +117,7 @@ public:
|
||||
void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) override;
|
||||
static bool GetFileBuffer(const std::string& filePath, std::string& fileFullName, std::vector<uint8_t>& buffer,
|
||||
bool isABC = true);
|
||||
static std::shared_ptr<AbilityBase::FileMapper> GetSafeData(const std::string& path, std::string& fileFullName);
|
||||
|
||||
void InitSourceMap(const std::shared_ptr<JsEnv::SourceMapOperator> operatorImpl);
|
||||
void InitSourceMap(const std::string hqfFilePath);
|
||||
|
@ -57,7 +57,7 @@ HWTEST_F(JsQuickfixCallbackTest, JsQuickfixCallbackTest_0100, TestSize.Level0)
|
||||
|
||||
std::string baseFileName = "<baseFileName>";
|
||||
std::string patchFileName;
|
||||
void* patchBuffer = nullptr;
|
||||
uint8_t* patchBuffer = nullptr;
|
||||
size_t patchSize = 0;
|
||||
bool res = jsQuickfixCallback(baseFileName, patchFileName, &patchBuffer, patchSize);
|
||||
EXPECT_FALSE(res);
|
||||
@ -78,7 +78,7 @@ HWTEST_F(JsQuickfixCallbackTest, JsQuickfixCallbackTest_0200, TestSize.Level0)
|
||||
|
||||
std::string baseFileName = "baseFileName.abc";
|
||||
std::string patchFileName;
|
||||
void* patchBuffer = nullptr;
|
||||
uint8_t* patchBuffer = nullptr;
|
||||
size_t patchSize = 0;
|
||||
bool res = jsQuickfixCallback(baseFileName, patchFileName, &patchBuffer, patchSize);
|
||||
EXPECT_FALSE(res);
|
||||
@ -99,7 +99,7 @@ HWTEST_F(JsQuickfixCallbackTest, JsQuickfixCallbackTest_0300, TestSize.Level0)
|
||||
|
||||
std::string baseFileName = "/data/storage/el1/bundle/entry/ets/modules.abc";
|
||||
std::string patchFileName;
|
||||
void* patchBuffer = nullptr;
|
||||
uint8_t* patchBuffer = nullptr;
|
||||
size_t patchSize = 0;
|
||||
bool res = jsQuickfixCallback(baseFileName, patchFileName, &patchBuffer, patchSize);
|
||||
EXPECT_FALSE(res);
|
||||
@ -120,7 +120,7 @@ HWTEST_F(JsQuickfixCallbackTest, JsQuickfixCallbackTest_0400, TestSize.Level0)
|
||||
|
||||
std::string baseFileName = "/data/storage/el1/bundle/bundle/ets/modules.abc";
|
||||
std::string patchFileName;
|
||||
void* patchBuffer = nullptr;
|
||||
uint8_t* patchBuffer = nullptr;
|
||||
size_t patchSize = 0;
|
||||
bool res = jsQuickfixCallback(baseFileName, patchFileName, &patchBuffer, patchSize);
|
||||
EXPECT_FALSE(res);
|
||||
|
Loading…
Reference in New Issue
Block a user