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
+1
View File
@@ -25,6 +25,7 @@ ace_engine_path = "//foundation/arkui/ace_engine"
bundlefwk_path = "//foundation/bundlemanager/bundle_framework"
bundlefwk_inner_api_path = "${bundlefwk_path}/interfaces/inner_api"
bundlefwk_services_path = "${bundlefwk_path}/services"
multimedia_path = "//foundation/multimedia/image_standard"
multimodalinput_path = "//foundation/multimodalinput/input"
@@ -113,7 +113,7 @@ void JsAbility::Init(const std::shared_ptr<AbilityInfo> &abilityInfo,
auto &engine = jsRuntime_.GetNativeEngine();
jsAbilityObj_ =
jsRuntime_.LoadModule(moduleName, srcPath, abilityInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE);
jsRuntime_.LoadModule(moduleName, srcPath, abilityInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE, abilityInfo->hapPath);
if (jsAbilityObj_ == nullptr) {
HILOG_ERROR("Failed to get AbilityStage object");
return;
@@ -92,7 +92,7 @@ void JsFormExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
HandleScope handleScope(jsRuntime_);
auto& engine = jsRuntime_.GetNativeEngine();
jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath, abilityInfo_->compileMode == CompileMode::ES_MODULE);
jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath, abilityInfo_->compileMode == CompileMode::ES_MODULE, abilityInfo_->hapPath);
if (jsObj_ == nullptr) {
HILOG_ERROR("Failed to get jsObj_");
return;
@@ -90,7 +90,7 @@ void JsServiceExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
HandleScope handleScope(jsRuntime_);
auto& engine = jsRuntime_.GetNativeEngine();
jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath, abilityInfo_->compileMode == CompileMode::ES_MODULE);
jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath, abilityInfo_->compileMode == CompileMode::ES_MODULE, abilityInfo_->hapPath);
if (jsObj_ == nullptr) {
HILOG_ERROR("Failed to get jsObj_");
return;
@@ -92,7 +92,7 @@ void JsStaticSubscriberExtension::Init(const std::shared_ptr<AbilityLocalRecord>
HandleScope handleScope(jsRuntime_);
auto& engine = jsRuntime_.GetNativeEngine();
jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath, abilityInfo_->compileMode == CompileMode::ES_MODULE);
jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath, abilityInfo_->compileMode == CompileMode::ES_MODULE, abilityInfo_->hapPath);
if (jsObj_ == nullptr) {
HILOG_ERROR("Failed to get jsObj_");
return;
@@ -63,11 +63,13 @@ JsTestRunner::JsTestRunner(
srcPath.append(".abc");
srcPath_ = srcPath;
}
HILOG_INFO("JsTestRunner srcPath is %{public}s", srcPath_.c_str());
HILOG_DEBUG("JsTestRunner srcPath is %{public}s", srcPath_.c_str());
if (!isFaJsModel) {
std::string moduleName;
hapPath_ = bundleInfo.hapModuleInfos.back().hapPath;
HILOG_DEBUG("JsTestRunner hapPath is %{public}s", hapPath_.c_str());
jsTestRunnerObj_ = jsRuntime_.LoadModule(moduleName, srcPath_,
bundleInfo.hapModuleInfos.back().compileMode == AppExecFwk::CompileMode::ES_MODULE);
bundleInfo.hapModuleInfos.back().compileMode == AppExecFwk::CompileMode::ES_MODULE, hapPath_);
}
}
@@ -87,7 +89,7 @@ bool JsTestRunner::Initialize()
HILOG_ERROR("mgmtResult init error");
return false;
}
if (!jsRuntime_.RunSandboxScript(srcPath_)) {
if (!jsRuntime_.RunSandboxScript(srcPath_, hapPath_)) {
HILOG_ERROR("RunScript srcPath_ err");
return false;
}
@@ -69,7 +69,7 @@ std::shared_ptr<AbilityStage> JsAbilityStage::Create(
std::string moduleName(hapModuleInfo.moduleName);
moduleName.append("::").append("AbilityStage");
auto moduleObj =
jsRuntime.LoadModule(moduleName, srcPath, hapModuleInfo.compileMode == AppExecFwk::CompileMode::ES_MODULE);
jsRuntime.LoadModule(moduleName, srcPath, hapModuleInfo.compileMode == AppExecFwk::CompileMode::ES_MODULE, hapModuleInfo.hapPath);
return std::make_shared<JsAbilityStage>(jsRuntime, std::move(moduleObj));
}
@@ -82,7 +82,7 @@ std::shared_ptr<AbilityStage> JsAbilityStage::Create(
std::string moduleName(hapModuleInfo.moduleName);
moduleName.append("::").append("AbilityStage");
moduleObj =
jsRuntime.LoadModule(moduleName, srcPath, hapModuleInfo.compileMode == AppExecFwk::CompileMode::ES_MODULE);
jsRuntime.LoadModule(moduleName, srcPath, hapModuleInfo.compileMode == AppExecFwk::CompileMode::ES_MODULE, hapModuleInfo.hapPath);
HILOG_INFO("JsAbilityStage srcPath is %{public}s", srcPath.c_str());
}
return std::make_shared<JsAbilityStage>(jsRuntime, std::move(moduleObj));
@@ -937,6 +937,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
AbilityRuntime::Runtime::Options options;
options.bundleName = appInfo.bundleName;
options.codePath = LOCAL_CODE_PATH;
options.hapPath = bundleInfo.hapModuleInfos.back().hapPath;
options.eventRunner = mainHandler_->GetEventRunner();
options.loadAce = true;
std::string nativeLibraryPath = appInfo.nativeLibraryPath;
@@ -1225,6 +1226,7 @@ bool MainThread::PrepareAbilityDelegator(const std::shared_ptr<UserTestRecord> &
AbilityRuntime::Runtime::Options options;
options.codePath = LOCAL_CODE_PATH;
options.eventRunner = mainHandler_->GetEventRunner();
options.hapPath = bundleInfo.hapModuleInfos.back().hapPath;
options.loadAce = false;
if (bundleInfo.hapModuleInfos.empty() || bundleInfo.hapModuleInfos.front().abilityInfos.empty()) {
HILOG_ERROR("Failed to abilityInfos");
@@ -20,6 +20,7 @@
#include <vector>
#include "hilog_wrapper.h"
#include "js_runtime_utils.h"
namespace OHOS {
namespace AbilityRuntime {
@@ -49,11 +50,6 @@ inline bool StringEndWith(const std::string& str, const char* endStr, size_t end
return ((len >= endStrLen) && (str.compare(len - endStrLen, endStrLen, endStr) == 0));
}
inline bool StringStartWith(const std::string& str, const char* startStr, size_t startStrLen)
{
return ((str.length() >= startStrLen) && (str.compare(0, startStrLen, startStr) == 0));
}
void SplitString(const std::string& str, std::vector<std::string>& out, size_t pos = 0, const char* seps = "\\/")
{
if (str.empty() || pos >= str.length()) {
@@ -101,44 +97,9 @@ inline std::string StripString(const std::string& str, const char* charSet = " \
std::string JsModuleSearcher::operator()(const std::string& curJsModulePath, const std::string& newJsModuleUri) const
{
HILOG_INFO("Search JS module (%{public}s, %{public}s) begin",
curJsModulePath.c_str(), newJsModuleUri.c_str());
std::string newJsModulePath;
if (curJsModulePath.empty() || newJsModuleUri.empty()) {
return newJsModulePath;
}
std::string normalizeUri = newJsModuleUri;
replace(normalizeUri.begin(), normalizeUri.end(), '\\', '/');
switch (normalizeUri[0]) {
case '.': {
newJsModulePath = MakeNewJsModulePath(curJsModulePath, normalizeUri);
break;
}
case '@': {
newJsModulePath = ParseOhmUri(curJsModulePath, normalizeUri);
if (newJsModulePath.empty()) {
newJsModulePath = FindNpmPackage(curJsModulePath, normalizeUri);
}
break;
}
default: {
newJsModulePath = FindNpmPackage(curJsModulePath, normalizeUri);
break;
}
}
FixExtName(newJsModulePath);
HILOG_INFO("Search JS module (%{public}s, %{public}s) => %{public}s end",
curJsModulePath.c_str(), normalizeUri.c_str(), newJsModulePath.c_str());
return newJsModulePath;
return ParseJsModuleUri(curJsModulePath, newJsModuleUri);
}
void JsModuleSearcher::FixExtName(std::string& path)
{
if (path.empty()) {
@@ -381,5 +342,53 @@ std::string JsModuleSearcher::ParseOhmUri(const std::string& curJsModulePath, co
return FindNpmPackageInTopLevel(moduleInstallPath, JoinString(pathVector, '/', index + 1));
}
std::string JsModuleSearcher::ParseJsModuleUri(const std::string& curJsModulePath, const std::string& newJsModuleUri) const
{
HILOG_DEBUG("Search JS module ParseJsModuleUri (%{public}s, %{public}s) begin", curJsModulePath.c_str(),
newJsModuleUri.c_str());
std::string newJsModulePath;
if (curJsModulePath.empty() || newJsModuleUri.empty()) {
return newJsModulePath;
}
std::string normalizeUri = newJsModuleUri;
replace(normalizeUri.begin(), normalizeUri.end(), '\\', '/');
switch (normalizeUri[0]) {
case '.': {
newJsModulePath = MakeNewJsModulePath(curJsModulePath, normalizeUri);
break;
}
case '@': {
newJsModulePath = ParseOhmUri(curJsModulePath, normalizeUri);
if (newJsModulePath.empty()) {
newJsModulePath = FindNpmPackage(curJsModulePath, normalizeUri);
}
break;
}
default: {
newJsModulePath = FindNpmPackage(curJsModulePath, normalizeUri);
break;
}
}
FixExtName(newJsModulePath);
HILOG_DEBUG("Search JS module ParseJsModuleUri (%{public}s, %{public}s) => %{public}s end",
curJsModulePath.c_str(), normalizeUri.c_str(), newJsModulePath.c_str());
return newJsModulePath;
}
bool JsModuleSearcher::GetABCFileBuffer(
const std::string& curJsModulePath, const std::string& newJsModuleUri, std::ostream &dest) const
{
std::string newJsModulePath = ParseJsModuleUri(curJsModulePath, newJsModuleUri);
if (!GetABCFile(hapPath_, newJsModulePath, dest)) {
HILOG_ERROR("Get abc file failed");
return false;
}
return true;
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -16,6 +16,7 @@
#ifndef OHOS_ABILITY_RUNTIME_JS_MODULE_SEARCHER_H
#define OHOS_ABILITY_RUNTIME_JS_MODULE_SEARCHER_H
#include <sstream>
#include <string>
namespace OHOS {
@@ -23,6 +24,10 @@ namespace AbilityRuntime {
class JsModuleSearcher final {
public:
explicit JsModuleSearcher(const std::string& bundleName) : bundleName_(bundleName) {}
explicit JsModuleSearcher(const std::string& bundleName, const std::string& hapPath) {
bundleName_ = bundleName;
hapPath_ = hapPath;
}
~JsModuleSearcher() = default;
JsModuleSearcher(const JsModuleSearcher&) = default;
@@ -31,6 +36,8 @@ public:
JsModuleSearcher& operator=(JsModuleSearcher&&) = default;
std::string operator()(const std::string& curJsModulePath, const std::string& newJsModuleUri) const;
bool GetABCFileBuffer(
const std::string& curJsModulePath, const std::string& newJsModuleUri, std::ostream &dest) const;
private:
static void FixExtName(std::string& path);
@@ -42,8 +49,10 @@ private:
static std::string FindNpmPackage(const std::string& curJsModulePath, const std::string& npmPackage);
std::string ParseOhmUri(const std::string& curJsModulePath, const std::string& newJsModuleUri) const;
std::string ParseJsModuleUri(const std::string& curJsModulePath, const std::string& newJsModuleUri) const;
std::string bundleName_;
std::string hapPath_;
};
} // namespace AbilityRuntime
} // namespace OHOS
+42 -15
View File
@@ -22,6 +22,7 @@
#include <sys/epoll.h>
#include <unistd.h>
#include "connect_server_manager.h"
#include "event_handler.h"
#include "hdc_register.h"
@@ -106,14 +107,25 @@ public:
debugMode_ = true;
}
bool RunScript(const std::string& path) override
bool RunScript(const std::string& path, const std::string& hapPath) override
{
return nativeEngine_->RunScriptPath(path.c_str()) != nullptr;
bool result = false;
if (!hapPath.empty()) {
std::ostringstream outStreamForABC;
if (!GetABCFile(hapPath, path, outStreamForABC)) {
HILOG_ERROR("Get abc file failed");
return result;
}
result = nativeEngine_->RunScriptPath(path.c_str()) != nullptr; //, (void *)outStreamForABC
} else {
result = nativeEngine_->RunScriptPath(path.c_str()) != nullptr;
}
return result;
}
NativeValue* LoadJsModule(const std::string& path) override
NativeValue* LoadJsModule(const std::string& path, const std::string& hapPath) override
{
if (!RunScript(path)) {
if (!RunScript(path, hapPath)) {
HILOG_ERROR("Failed to run script: %{public}s", path.c_str());
return nullptr;
}
@@ -177,7 +189,11 @@ private:
if (!options.preload) {
bundleName_ = options.bundleName;
panda::JSNApi::SetHostResolvePathTracker(vm_, JsModuleSearcher(options.bundleName));
if (!options.hapPath.empty()) {
panda::JSNApi::SetHostResolvePathTracker(vm_, JsModuleSearcher(options.bundleName, options.hapPath));
} else {
panda::JSNApi::SetHostResolvePathTracker(vm_, JsModuleSearcher(options.bundleName));
}
}
return JsRuntime::Initialize(options);
}
@@ -226,7 +242,7 @@ void InitSyscapModule(NativeEngine& engine, NativeObject& globalObject)
bool MakeFilePath(const std::string& codePath, const std::string& modulePath, std::string& fileName)
{
std::string path(codePath);
path.append("/").append(modulePath);
path.append("/").append(modulePath);// phone/./ets/MainAbility6/MainAbility6.abc
if (path.length() > PATH_MAX) {
HILOG_ERROR("Path length(%{public}d) longer than MAX(%{public}d)", (int32_t)path.length(), PATH_MAX);
return false;
@@ -468,13 +484,13 @@ void JsRuntime::Deinitialize()
nativeEngine_.reset();
}
NativeValue* JsRuntime::LoadJsBundle(const std::string& path)
NativeValue* JsRuntime::LoadJsBundle(const std::string& path, const std::string& hapPath)
{
NativeObject* globalObj = ConvertNativeValueTo<NativeObject>(nativeEngine_->GetGlobal());
NativeValue* exports = nativeEngine_->CreateObject();
globalObj->SetProperty("exports", exports);
if (!RunScript(path)) {
if (!RunScript(path, hapPath)) {
HILOG_ERROR("Failed to run script: %{public}s", path.c_str());
return nullptr;
}
@@ -494,8 +510,8 @@ NativeValue* JsRuntime::LoadJsBundle(const std::string& path)
return exportObj;
}
std::unique_ptr<NativeReference> JsRuntime::LoadModule(
const std::string& moduleName, const std::string& modulePath, bool esmodule)
std::unique_ptr<NativeReference> JsRuntime::LoadModule(const std::string& moduleName,
const std::string& modulePath, bool esmodule, const std::string& hapPath)
{
HILOG_INFO("JsRuntime::LoadModule(%{public}s, %{public}s, %{public}s)", moduleName.c_str(), modulePath.c_str(),
esmodule ? "true" : "false");
@@ -514,7 +530,7 @@ std::unique_ptr<NativeReference> JsRuntime::LoadModule(
return std::unique_ptr<NativeReference>();
}
classValue = esmodule ? LoadJsModule(fileName) : LoadJsBundle(fileName);
classValue = esmodule ? LoadJsModule(fileName, hapPath) : LoadJsBundle(fileName, hapPath);
if (classValue == nullptr) {
return std::unique_ptr<NativeReference>();
}
@@ -550,12 +566,23 @@ std::unique_ptr<NativeReference> JsRuntime::LoadSystemModule(
return std::unique_ptr<NativeReference>(nativeEngine_->CreateReference(instanceValue, 1));
}
bool JsRuntime::RunScript(const std::string& path)
bool JsRuntime::RunScript(const std::string& path, const std::string& hapPath)
{
return nativeEngine_->RunScript(path.c_str()) != nullptr;
bool result = false;
if (!hapPath.empty()) {
std::ostringstream outStreamForABC;
if (!GetABCFile(hapPath, path, outStreamForABC)) {
HILOG_ERROR("Get abc file failed");
return result;
}
result = nativeEngine_->RunScript(path.c_str()) != nullptr; //, (void *)outStreamForABC
} else {
result = nativeEngine_->RunScript(path.c_str()) != nullptr;
}
return result;
}
bool JsRuntime::RunSandboxScript(const std::string& path)
bool JsRuntime::RunSandboxScript(const std::string& path, const std::string& hapPath)
{
std::string fileName;
if (!MakeFilePath(codePath_, path, fileName)) {
@@ -563,7 +590,7 @@ bool JsRuntime::RunSandboxScript(const std::string& path)
return false;
}
if (!RunScript(fileName)) {
if (!RunScript(fileName, hapPath)) {
HILOG_ERROR("Failed to run script: %{public}s", fileName.c_str());
return false;
}
@@ -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
+38
View File
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "runtime_extractor.h"
#include "hilog_wrapper.h"
namespace OHOS {
namespace AbilityRuntime {
RuntimeExtractor::RuntimeExtractor(const std::string &source) : AppExecFwk::BaseExtractor(source)
{
HILOG_DEBUG("RuntimeExtractor is created");
}
RuntimeExtractor::~RuntimeExtractor()
{
HILOG_DEBUG("RuntimeExtractor destroyed");
}
bool RuntimeExtractor::ExtractABCFile(const std::string& srcPath, std::ostream &dest) const
{
HILOG_DEBUG("%{public}s: hapPath is %{public}s", __func__, srcPath.c_str());
return AppExecFwk::BaseExtractor::ExtractByName(srcPath, dest);
}
} // namespace AbilityRuntime
} // namespace OHOS
+29 -1
View File
@@ -48,7 +48,6 @@ ohos_shared_library("runtime") {
configs = [
":runtime_config",
"//arkcompiler/ets_runtime:ark_jsruntime_public_config",
"${ability_runtime_services_path}/common:common_config",
]
public_configs = [ ":runtime_public_config" ]
@@ -56,6 +55,7 @@ ohos_shared_library("runtime") {
deps = [
"//arkcompiler/ets_runtime:libark_jsruntime",
"//foundation/arkui/napi:ace_napi_ark",
":runtime_extractor"
]
external_deps = [
@@ -93,3 +93,31 @@ ohos_shared_library("runtime") {
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_source_set("runtime_extractor") {
include_dirs = [ "include" ]
sources = [
"${ability_runtime_native_path}/runtime/runtime_extractor.cpp",
]
configs = [
"${ability_runtime_services_path}/common:common_config",
]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
public_deps = [
"${bundlefwk_services_path}/bundlemgr:parser_common",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
]
subsystem_name = "ability"
part_name = "ability_runtime"
}
@@ -55,8 +55,8 @@ public:
return Language::JS;
}
std::unique_ptr<NativeReference> LoadModule(
const std::string& moduleName, const std::string& modulePath, bool esmodule = false);
std::unique_ptr<NativeReference> LoadModule(const std::string& moduleName,
const std::string& modulePath, bool esmodule = false, const std::string& hapPath = nullptr);
std::unique_ptr<NativeReference> LoadSystemModule(
const std::string& moduleName, NativeValue* const* argv = nullptr, size_t argc = 0);
void PostTask(const std::function<void()>& task, const std::string& name, int64_t delayTime);
@@ -65,8 +65,8 @@ public:
std::string BuildJsStackTrace() override;
void NotifyApplicationState(bool isBackground) override;
bool RunSandboxScript(const std::string& path);
virtual bool RunScript(const std::string& path) = 0;
bool RunSandboxScript(const std::string& path, const std::string& hapPath);
virtual bool RunScript(const std::string& path, const std::string& hapPath = nullptr) = 0;
void PreloadSystemModule(const std::string& moduleName) override;
@@ -76,8 +76,8 @@ protected:
virtual bool Initialize(const Options& options);
void Deinitialize();
virtual NativeValue* LoadJsBundle(const std::string& path);
virtual NativeValue* LoadJsModule(const std::string& path) = 0;
virtual NativeValue* LoadJsBundle(const std::string& path, const std::string& hapPath);
virtual NativeValue* LoadJsModule(const std::string& path, const std::string& hapPath) = 0;
bool isArkEngine_ = false;
bool debugMode_ = false;
@@ -18,6 +18,7 @@
#include <cstdint>
#include <memory>
#include <sstream>
#include <type_traits>
#include "native_engine/native_engine.h"
@@ -111,6 +112,8 @@ NativeValue* CreateNativeArray(NativeEngine& engine, const std::vector<T>& data)
return arrayValue;
}
bool StringStartWith(const std::string& str, const char* startStr, size_t startStrLen);
bool StringEndWith(const std::string& str, const char* endStr, size_t endStrLen);
NativeValue* CreateJsError(NativeEngine& engine, int32_t errCode, const std::string& message = std::string());
void BindNativeFunction(NativeEngine& engine, NativeObject& object, const char* name, NativeCallback func);
void BindNativeProperty(NativeObject& object, const char* name, NativeCallback getter);
@@ -184,6 +187,8 @@ std::unique_ptr<AsyncTask> CreateAsyncTaskWithLastParam(NativeEngine& engine, Na
std::unique_ptr<AsyncTask> CreateAsyncTaskWithLastParam(NativeEngine& engine, NativeValue* lastParam,
nullptr_t, nullptr_t, NativeValue** result);
bool GetABCFile(const std::string& hapPath, const std::string& srcPath, std::ostream &dest);
} // namespace AbilityRuntime
} // namespace OHOS
@@ -34,6 +34,7 @@ public:
std::string bundleName;
std::string codePath;
std::string packagePath;
std::string hapPath;
std::shared_ptr<AppExecFwk::EventRunner> eventRunner;
bool loadAce = true;
bool preload = false;
+38
View File
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_RUNTIME_EXTRACTOR_H
#define OHOS_ABILITY_RUNTIME_RUNTIME_EXTRACTOR_H
#include "base_extractor.h"
namespace OHOS {
namespace AbilityRuntime {
class RuntimeExtractor : public AppExecFwk::BaseExtractor {
public:
explicit RuntimeExtractor(const std::string &source);
virtual ~RuntimeExtractor() override;
/**
* @brief Extract the abc file of a hap to dest stream.
* @param srcPath Indicates the src path of the abc file in hap.
* @param dest Indicates the obtained std::ostream object.
* @return Returns true if the Profile is successfully extracted; returns false otherwise.
*/
bool ExtractABCFile(const std::string& srcPath, std::ostream &dest) const;
};
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_RUNTIME_EXTRACTOR_H
@@ -69,6 +69,7 @@ private:
JsRuntime &jsRuntime_;
std::unique_ptr<NativeReference> jsTestRunnerObj_;
std::string srcPath_;
std::string hapPath_;
bool isFaJsModel_ = false;
};
} // namespace RunnerRuntime
@@ -23,6 +23,8 @@ constexpr const char* ABS_CODE_PATH = "/data/app/el1/bundle/public";
constexpr const char* LOCAL_CODE_PATH = "/data/storage/el1/bundle";
constexpr const char* LOCAL_BUNDLES = "/data/bundles";
constexpr const char* FILE_SEPARATOR = "/";
constexpr const char SYSTEM_APP_PATH[] = "/system/app";
} // namespace Constants
} // namespace AbilityRuntime
} // namespace OHOS