IssueNo:#I5825N

Description: 不解压HAP加载应用代码
Sig:SIG_ApplicationFramework
Feature or Bugfix:Feature
Binary Source: No

Signed-off-by: dy_study <dingyao5@huawei.com>
Change-Id: I4255164c1df585e91f789f5b31d04c0eed976034
This commit is contained in:
dy_study
2022-08-09 19:59:59 +08:00
parent 338fba8a77
commit c826f327de
20 changed files with 277 additions and 72 deletions
@@ -15,8 +15,12 @@
#include "js_runtime_utils.h"
#include <regex>
#include "ability_constants.h"
#include "hilog_wrapper.h"
#include "js_runtime.h"
#include "runtime_extractor.h"
namespace OHOS {
namespace AbilityRuntime {
@@ -38,6 +42,11 @@ std::unique_ptr<AsyncTask> CreateAsyncTaskWithLastParam(NativeEngine& engine, Na
} // namespace
// Help Functions
bool StringStartWith(const std::string& str, const char* startStr, size_t startStrLen)
{
return ((str.length() >= startStrLen) && (str.compare(0, startStrLen, startStr) == 0));
}
NativeValue* CreateJsError(NativeEngine& engine, int32_t errCode, const std::string& message)
{
return engine.CreateError(CreateJsValue(engine, errCode), CreateJsValue(engine, message));
@@ -237,5 +246,38 @@ std::unique_ptr<AsyncTask> CreateAsyncTaskWithLastParam(NativeEngine& engine, Na
return CreateAsyncTaskWithLastParam(engine, lastParam, std::unique_ptr<AsyncTask::ExecuteCallback>(),
std::unique_ptr<AsyncTask::CompleteCallback>(), result);
}
bool GetABCFile(const std::string& hapPath, const std::string& srcPath, std::ostream &dest)
{
if (hapPath.empty() || srcPath.empty()) {
HILOG_ERROR("GetABCFile::hapPath or srcPath is nullptr");
return false;
}
std::string loadPath;
if (!StringStartWith(hapPath, Constants::SYSTEM_APP_PATH, sizeof(Constants::SYSTEM_APP_PATH) - 1)) {
std::regex hapPattern(std::string(Constants::ABS_CODE_PATH) + std::string(Constants::FILE_SEPARATOR));
loadPath = std::regex_replace(hapPath, hapPattern, "");
loadPath = std::string(Constants::LOCAL_CODE_PATH) + std::string(Constants::FILE_SEPARATOR) +
loadPath.substr(loadPath.find(std::string(Constants::FILE_SEPARATOR)) + 1);
} else {
loadPath = hapPath;
}
RuntimeExtractor runtimeExtractor(loadPath);
if (!runtimeExtractor.Init()) {
HILOG_ERROR("GetABCFile::Runtime extractor init failed");
return false;
}
std::regex srcPattern(std::string(Constants::LOCAL_CODE_PATH) + std::string(Constants::FILE_SEPARATOR));
std::string relativePath = std::regex_replace(srcPath, srcPattern, "");
relativePath = relativePath.substr(relativePath.find(std::string(Constants::FILE_SEPARATOR)) + 1);
if (!runtimeExtractor.ExtractABCFile(relativePath, dest)) {
HILOG_ERROR("GetABCFile::Extract abc file failed");
return false;
}
return true;
}
} // namespace AbilityRuntime
} // namespace OHOS