!9561 回退 'Pull Request !9388 : worker pac'

Merge pull request !9561 from openharmony_ci/revert-merge-9388-master
This commit is contained in:
openharmony_ci 2024-07-23 14:53:09 +00:00 committed by Gitee
commit b8e9e0bd14
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 37 additions and 52 deletions

View File

@ -1481,15 +1481,15 @@ void JsRuntime::InitWorkerModule(const Options& options)
{
CHECK_POINTER(jsEnv_);
std::shared_ptr<JsEnv::WorkerInfo> workerInfo = std::make_shared<JsEnv::WorkerInfo>();
workerInfo->codePath = panda::panda_file::StringPacProtect(options.codePath);
workerInfo->codePath = options.codePath;
workerInfo->isDebugVersion = options.isDebugVersion;
workerInfo->isBundle = options.isBundle;
workerInfo->packagePathStr = options.packagePathStr;
workerInfo->assetBasePathStr = options.assetBasePathStr;
workerInfo->hapPath = panda::panda_file::StringPacProtect(options.hapPath);
workerInfo->isStageModel = panda::panda_file::BoolPacProtect(options.isStageModel);
workerInfo->hapPath = options.hapPath;
workerInfo->isStageModel = options.isStageModel;
workerInfo->moduleName = options.moduleName;
workerInfo->apiTargetVersion = panda::panda_file::DataProtect(static_cast<uintptr_t>(options.apiTargetVersion));
workerInfo->apiTargetVersion = options.apiTargetVersion;
if (options.isJsFramework) {
SetJsFramework();
}

View File

@ -193,7 +193,7 @@ void AssetHelper::operator()(const std::string& uri, uint8_t** buff, size_t* buf
if (uri.find_first_of("/") == 0) {
TAG_LOGD(AAFwkTag::JSRUNTIME, "uri start with /modulename");
realPath = uri.substr(1);
} else if (uri.find("../") == 0 && !GetIsStageModel()) {
} else if (uri.find("../") == 0 && !workerInfo_->isStageModel) {
TAG_LOGD(AAFwkTag::JSRUNTIME, "uri start with ../");
realPath = uri.substr(PATH_THREE);
} else if (uri.find_first_of("@") == 0) {
@ -207,10 +207,10 @@ void AssetHelper::operator()(const std::string& uri, uint8_t** buff, size_t* buf
filePath = NormalizedFileName(realPath);
TAG_LOGI(AAFwkTag::JSRUNTIME, "filePath %{private}s", filePath.c_str());
if (!GetIsStageModel()) {
if (!workerInfo_->isStageModel) {
GetAmi(ami, filePath);
} else {
ami = (workerInfo_->codePath).GetOriginString() + filePath;
ami = workerInfo_->codePath + filePath;
}
TAG_LOGD(AAFwkTag::JSRUNTIME, "Get asset, ami: %{private}s", ami.c_str());
@ -251,11 +251,10 @@ void AssetHelper::operator()(const std::string& uri, uint8_t** buff, size_t* buf
filePath = NormalizedFileName(realPath);
// for safe reason, filePath must starts with 'abcs/' in restricted env
if (isRestricted && filePath.find(RESTRICTED_PREFIX_PATH)
&& (static_cast<int32_t>(workerInfo_->apiTargetVersion.GetOriginPointer())) >= API12) {
if (isRestricted && filePath.find(RESTRICTED_PREFIX_PATH) && workerInfo_->apiTargetVersion >= API12) {
filePath = RESTRICTED_PREFIX_PATH + filePath;
}
ami = (workerInfo_->codePath).GetOriginString() + filePath;
ami = workerInfo_->codePath + filePath;
TAG_LOGD(AAFwkTag::JSRUNTIME, "Get asset, ami: %{private}s", ami.c_str());
if (ami.find(CACHE_DIRECTORY) != std::string::npos) {
if (!ReadAmiData(ami, buff, buffSize, content, useSecureMem, isRestricted)) {
@ -316,10 +315,9 @@ bool AssetHelper::ReadAmiData(const std::string& ami, uint8_t** buff, size_t* bu
bool& useSecureMem, bool isRestricted)
{
// Current function is a private, validity of workerInfo_ has been checked by caller.
int32_t apiTargetVersion = static_cast<int32_t>(workerInfo_->apiTargetVersion.GetOriginPointer());
bool apiSatisfy = apiTargetVersion == 0 || apiTargetVersion > API8;
if (GetIsStageModel() && !isRestricted && apiSatisfy) {
if (apiTargetVersion >= API12) {
bool apiSatisfy = workerInfo_->apiTargetVersion == 0 || workerInfo_->apiTargetVersion > API8;
if (workerInfo_->isStageModel && !isRestricted && apiSatisfy) {
if (workerInfo_->apiTargetVersion >= API12) {
useSecureMem = true;
return GetSafeData(ami, buff, buffSize);
} else if (GetSafeData(ami, buff, buffSize)) {
@ -383,8 +381,8 @@ bool AssetHelper::ReadFilePathData(const std::string& filePath, uint8_t** buff,
std::string newHapPath;
size_t pos = filePath.find('/');
if (!GetIsStageModel()) {
newHapPath = (workerInfo_->hapPath).GetOriginString();
if (!workerInfo_->isStageModel) {
newHapPath = workerInfo_->hapPath;
} else {
for (auto hapModuleInfo : bundleInfo.hapModuleInfos) {
if (hapModuleInfo.moduleName == filePath.substr(0, pos)) {
@ -404,7 +402,7 @@ bool AssetHelper::ReadFilePathData(const std::string& filePath, uint8_t** buff,
std::unique_ptr<uint8_t[]> dataPtr = nullptr;
std::string realfilePath;
size_t fileLen = 0;
if (!GetIsStageModel()) {
if (!workerInfo_->isStageModel) {
bool flag = false;
for (const auto& basePath : workerInfo_->assetBasePathStr) {
realfilePath = basePath + filePath;
@ -421,12 +419,11 @@ bool AssetHelper::ReadFilePathData(const std::string& filePath, uint8_t** buff,
} else {
realfilePath = filePath.substr(pos + 1);
TAG_LOGD(AAFwkTag::JSRUNTIME, "realfilePath: %{private}s", realfilePath.c_str());
int32_t apiTargetVersion = static_cast<int32_t>(workerInfo_->apiTargetVersion.GetOriginPointer());
bool apiSatisfy = apiTargetVersion == 0 || apiTargetVersion > API8;
if (GetIsStageModel() && !isRestricted && apiSatisfy && !extractor->IsHapCompress(realfilePath)) {
bool apiSatisfy = workerInfo_->apiTargetVersion == 0 || workerInfo_->apiTargetVersion > API8;
if (workerInfo_->isStageModel && !isRestricted && apiSatisfy && !extractor->IsHapCompress(realfilePath)) {
TAG_LOGD(AAFwkTag::JSRUNTIME, "Use secure mem.");
auto safeData = extractor->GetSafeData(realfilePath);
if (apiTargetVersion >= API12) {
if (workerInfo_->apiTargetVersion >= API12) {
useSecureMem = true;
if (safeData == nullptr) {
TAG_LOGE(AAFwkTag::JSRUNTIME, "Get secure mem failed, file %{private}s.", filePath.c_str());
@ -466,7 +463,7 @@ void AssetHelper::GetAmi(std::string& ami, const std::string& filePath)
std::string fileName = filePath.substr(slashPos + 1);
std::string path = filePath.substr(0, slashPos + 1);
std::string loadPath = ExtractorUtil::GetLoadFilePath((workerInfo_->hapPath).GetOriginString());
std::string loadPath = ExtractorUtil::GetLoadFilePath(workerInfo_->hapPath);
bool newCreate = false;
std::shared_ptr<Extractor> extractor = ExtractorUtil::GetExtractor(loadPath, newCreate);
if (extractor == nullptr) {
@ -500,7 +497,7 @@ void AssetHelper::GetAmi(std::string& ami, const std::string& filePath)
}
}
TAG_LOGD(AAFwkTag::JSRUNTIME, "targetFilePath %{private}s", targetFilePath.c_str());
TAG_LOGI(AAFwkTag::JSRUNTIME, "targetFilePath %{public}s", targetFilePath.c_str());
if (!flag) {
TAG_LOGE(AAFwkTag::JSRUNTIME, "get targetFilePath failed!");
@ -511,19 +508,12 @@ void AssetHelper::GetAmi(std::string& ami, const std::string& filePath)
std::string filePathName = basePath + targetFilePath;
bool hasFile = extractor->HasEntry(filePathName);
if (hasFile) {
ami = (workerInfo_->hapPath).GetOriginString() + "/" + filePathName;
ami = workerInfo_->hapPath + "/" + filePathName;
return;
}
}
}
bool AssetHelper::GetIsStageModel()
{
bool stageModule = workerInfo_->isStageModel.GetBool();
TAG_LOGI(AAFwkTag::JSRUNTIME, "stagemodule: %{public}d", stageModule);
return stageModule;
}
int32_t GetContainerId()
{
#ifdef SUPPORT_SCREEN

View File

@ -35,9 +35,8 @@ class AssetHelper final {
public:
explicit AssetHelper(std::shared_ptr<JsEnv::WorkerInfo> workerInfo) : workerInfo_(workerInfo)
{
panda::panda_file::StringPacProtect codePath = panda::panda_file::StringPacProtect(workerInfo_->codePath);
if (!(codePath.GetOriginString()).empty() && (codePath.GetOriginString()).back() != '/') {
(workerInfo_->codePath).Append('/');
if (!(workerInfo_->codePath).empty() && (workerInfo->codePath).back() != '/') {
(workerInfo_->codePath).append("/");
}
}
@ -58,8 +57,6 @@ private:
void GetAmi(std::string& ami, const std::string& filePath);
bool GetSafeData(const std::string& ami, uint8_t** buff, size_t* buffSize);
bool GetIsStageModel();
std::shared_ptr<JsEnv::WorkerInfo> workerInfo_ = nullptr;
int fd_ = -1;

View File

@ -314,13 +314,13 @@ void NativeRuntimeImpl::InitWorkerModule(const Options& options, const std::shar
}
std::shared_ptr<JsEnv::WorkerInfo> workerInfo = std::make_shared<JsEnv::WorkerInfo>();
workerInfo->codePath = panda::panda_file::StringPacProtect(options.codePath);
workerInfo->codePath = options.codePath;
workerInfo->isDebugVersion = options.isDebugVersion;
workerInfo->isBundle = options.isBundle;
workerInfo->packagePathStr = options.packagePathStr;
workerInfo->assetBasePathStr = options.assetBasePathStr;
workerInfo->hapPath = panda::panda_file::StringPacProtect(options.hapPath);
workerInfo->isStageModel = panda::panda_file::BoolPacProtect(options.isStageModel);
workerInfo->hapPath = options.hapPath;
workerInfo->isStageModel = options.isStageModel;
workerInfo->moduleName = options.moduleName;
if (options.isJsFramework) {
SetJsFramework();

View File

@ -171,7 +171,7 @@ void OHOSJsEnvironmentImpl::InitWorkerModule(NativeEngine* engine, std::shared_p
engine->SetInitWorkerFunc(InitWorkerFunc);
engine->SetOffWorkerFunc(OffWorkerFunc);
engine->SetGetAssetFunc(AssetHelper(workerInfo));
engine->SetApiVersion(static_cast<int32_t>(workerInfo->apiTargetVersion.GetOriginPointer()));
engine->SetApiVersion(workerInfo->apiTargetVersion);
engine->SetGetContainerScopeIdFunc(GetContainerId);
engine->SetInitContainerScopeFunc(UpdateContainerScope);

View File

@ -22,20 +22,18 @@
#include "native_engine/native_engine.h"
#include "data_protect.h"
namespace OHOS {
namespace JsEnv {
struct WorkerInfo {
panda::panda_file::StringPacProtect codePath;
std::string codePath;
bool isDebugVersion = false;
bool isBundle = true;
std::string packagePathStr;
std::vector<std::string> assetBasePathStr;
panda::panda_file::StringPacProtect hapPath;
panda::panda_file::BoolPacProtect isStageModel = panda::panda_file::BoolPacProtect(true);
std::string hapPath;
bool isStageModel = true;
std::string moduleName;
panda::panda_file::DataProtect apiTargetVersion = panda::panda_file::DataProtect();
int32_t apiTargetVersion = 0;
};
class JsEnvironmentImpl {

View File

@ -66,9 +66,9 @@ sptr<Token> GetFuzzAbilityToken()
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
{
std::shared_ptr<JsEnv::WorkerInfo> workerInfo = std::make_shared<JsEnv::WorkerInfo>();
workerInfo->codePath = panda::panda_file::StringPacProtect("/data/test/codePath");
workerInfo->codePath = "/data/test/codePath";
workerInfo->packagePathStr = "/data/test/packagePath";
workerInfo->hapPath = panda::panda_file::StringPacProtect("/data/test/hapPath");
workerInfo->hapPath = "/data/test/hapPath";
workerInfo->moduleName = "moduleName";
AbilityRuntime::AssetHelper helper = AbilityRuntime::AssetHelper(workerInfo);
std::string jsonStr(data, size);

View File

@ -74,9 +74,9 @@ GetAssetFunc JsWorkerTest::TestGetGetAssetFunc() const
HWTEST_F(JsWorkerTest, AssetHelper_0100, TestSize.Level1)
{
std::shared_ptr<JsEnv::WorkerInfo> workerInfo = std::make_shared<JsEnv::WorkerInfo>();
workerInfo->codePath = panda::panda_file::StringPacProtect("/data/test/codePath");
workerInfo->codePath = "/data/test/codePath";
workerInfo->packagePathStr = "/data/test/packagePath";
workerInfo->hapPath = panda::panda_file::StringPacProtect("/data/test/hapPath");
workerInfo->hapPath = "/data/test/hapPath";
workerInfo->moduleName = "moduleName";
TestSetGetAssetFunc(AssetHelper(workerInfo));
@ -101,9 +101,9 @@ HWTEST_F(JsWorkerTest, AssetHelper_0100, TestSize.Level1)
HWTEST_F(JsWorkerTest, AssetHelper_0200, TestSize.Level1)
{
std::shared_ptr<JsEnv::WorkerInfo> workerInfo = std::make_shared<JsEnv::WorkerInfo>();
workerInfo->codePath = panda::panda_file::StringPacProtect("/data/test/codePath");
workerInfo->codePath = "/data/test/codePath";
workerInfo->packagePathStr = "/data/test/packagePath";
workerInfo->hapPath = panda::panda_file::StringPacProtect("/data/test/hapPath");
workerInfo->hapPath = "/data/test/hapPath";
workerInfo->moduleName = "moduleName";
AssetHelper helper = AssetHelper(workerInfo);