mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
@@ -160,6 +160,10 @@ std::string JsModuleReader::GetPresetAppHapPath(const std::string& inputPath, co
|
||||
}
|
||||
std::string tmpPath = inputPath.substr(inputPath.find_first_of("/") + 1);
|
||||
const std::string sharedBundleName = tmpPath.substr(0, tmpPath.find_first_of("/"));
|
||||
if (baseSharedBundleInfos.size() == 0) {
|
||||
presetAppHapPath = "/system/app/appServiceFwk/" + sharedBundleName + "/" + moduleName + ".hsp";
|
||||
return presetAppHapPath;
|
||||
}
|
||||
for (const auto &info : baseSharedBundleInfos) {
|
||||
if ((info.bundleName == sharedBundleName) && (info.moduleName == moduleName)) {
|
||||
presetAppHapPath = info.hapPath;
|
||||
|
||||
@@ -32,6 +32,7 @@ public:
|
||||
static constexpr char ABS_DATA_CODE_PATH[] = "/data/app/el1/bundle/public/";
|
||||
static constexpr char BUNDLE[] = "bundle/";
|
||||
static constexpr char MERGE_ABC_PATH[] = "ets/modules.abc";
|
||||
static constexpr char SYS_ABS_CODE_PATH[] = "/system/app/appServiceFwk/";
|
||||
static constexpr char SHARED_FILE_SUFFIX[] = ".hsp";
|
||||
JsModuleReader(const std::string& bundleName, const std::string& hapPath, bool isFormRender = false);
|
||||
~JsModuleReader() = default;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <cerrno>
|
||||
#include <climits>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <regex>
|
||||
|
||||
#include <atomic>
|
||||
@@ -88,6 +89,13 @@ constexpr char MERGE_ABC_PATH[] = "/ets/modules.abc";
|
||||
constexpr char BUNDLE_INSTALL_PATH[] = "/data/storage/el1/bundle/";
|
||||
constexpr const char* PERMISSION_RUN_ANY_CODE = "ohos.permission.RUN_ANY_CODE";
|
||||
|
||||
const std::string SYSTEM_KITS_CONFIG_PATH = "/system/etc/system_kits_config.json";
|
||||
|
||||
const std::string SYSTEM_KITS = "systemkits";
|
||||
const std::string NAMESPACE = "namespace";
|
||||
const std::string TARGET_OHM = "targetohm";
|
||||
const std::string SINCE_VERSION = "sinceVersion";
|
||||
|
||||
static auto PermissionCheckFunc = []() {
|
||||
Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
|
||||
|
||||
@@ -638,6 +646,8 @@ bool JsRuntime::Initialize(const Options& options)
|
||||
panda::JSNApi::SetHostResolveBufferTracker(
|
||||
vm, JsModuleReader(options.bundleName, options.hapPath, options.isUnique));
|
||||
isModular = !panda::JSNApi::IsBundle(vm);
|
||||
std::vector<panda::HmsMap> systemKitsMap = GetSystemKitsMap(apiTargetVersion_);
|
||||
panda::JSNApi::SetHmsModuleList(vm, systemKitsMap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1351,5 +1361,63 @@ void JsRuntime::SetDeviceDisconnectCallback(const std::function<bool()> &cb)
|
||||
CHECK_POINTER(jsEnv_);
|
||||
jsEnv_->SetDeviceDisconnectCallback(cb);
|
||||
}
|
||||
|
||||
std::vector<panda::HmsMap> JsRuntime::GetSystemKitsMap(uint32_t version)
|
||||
{
|
||||
std::vector<panda::HmsMap> systemKitsMap;
|
||||
nlohmann::json jsonBuf;
|
||||
if (access(SYSTEM_KITS_CONFIG_PATH.c_str(), F_OK) != 0) {
|
||||
return systemKitsMap;
|
||||
}
|
||||
|
||||
std::fstream in;
|
||||
char errBuf[256];
|
||||
errBuf[0] = '\0';
|
||||
in.open(SYSTEM_KITS_CONFIG_PATH, std::ios_base::in);
|
||||
if (!in.is_open()) {
|
||||
strerror_r(errno, errBuf, sizeof(errBuf));
|
||||
return systemKitsMap;
|
||||
}
|
||||
|
||||
in.seekg(0, std::ios::end);
|
||||
int64_t size = in.tellg();
|
||||
if (size <= 0) {
|
||||
HILOG_ERROR("the file is an empty file");
|
||||
in.close();
|
||||
return systemKitsMap;
|
||||
}
|
||||
|
||||
in.seekg(0, std::ios::beg);
|
||||
jsonBuf = nlohmann::json::parse(in, nullptr, false);
|
||||
in.close();
|
||||
if (jsonBuf.is_discarded()) {
|
||||
HILOG_ERROR("bad profile file");
|
||||
return systemKitsMap;
|
||||
}
|
||||
|
||||
if (!jsonBuf.contains(SYSTEM_KITS)) {
|
||||
HILOG_ERROR("json config doesn't contain systemkits.");
|
||||
return systemKitsMap;
|
||||
}
|
||||
for (auto &item : jsonBuf.at(SYSTEM_KITS).items()) {
|
||||
nlohmann::json& jsonObject = item.value();
|
||||
if (!jsonObject.contains(NAMESPACE) || !jsonObject.at(NAMESPACE).is_string() ||
|
||||
!jsonObject.contains(TARGET_OHM) || !jsonObject.at(TARGET_OHM).is_string() ||
|
||||
!jsonObject.contains(SINCE_VERSION) || !jsonObject.at(SINCE_VERSION).is_number()) {
|
||||
continue;
|
||||
}
|
||||
uint32_t sinceVersion = jsonObject.at(SINCE_VERSION).get<uint32_t>();
|
||||
if (version >= sinceVersion) {
|
||||
panda::HmsMap hmsMap = {
|
||||
.originalPath = jsonObject.at(NAMESPACE).get<std::string>(),
|
||||
.targetPath = jsonObject.at(TARGET_OHM).get<std::string>(),
|
||||
.sinceVersion = sinceVersion
|
||||
};
|
||||
systemKitsMap.emplace_back(hmsMap);
|
||||
}
|
||||
}
|
||||
HILOG_DEBUG("The size of the map is %{public}zu", systemKitsMap.size());
|
||||
return systemKitsMap;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -40,6 +40,7 @@ config("runtime_public_config") {
|
||||
include_dirs = [
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native/ability_business_error",
|
||||
"include",
|
||||
"//third_party/json/include",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -85,6 +86,7 @@ ohos_shared_library("runtime") {
|
||||
"${ability_runtime_native_path}/ability/native:ability_business_error",
|
||||
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
|
||||
"${ability_runtime_path}/js_environment/frameworks/js_environment:js_environment",
|
||||
"${third_party_path}/jsoncpp:jsoncpp",
|
||||
"${third_party_path}/zlib:shared_libz",
|
||||
]
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
namespace panda::ecmascript {
|
||||
class EcmaVM;
|
||||
} // namespace panda::ecmascript
|
||||
namespace panda {
|
||||
struct HmsMap;
|
||||
}
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class EventHandler;
|
||||
@@ -163,6 +166,8 @@ private:
|
||||
void PostPreload(const Options& options);
|
||||
void LoadAotFile(const Options& options);
|
||||
void SetRequestAotCallback();
|
||||
|
||||
std::vector<panda::HmsMap> GetSystemKitsMap(uint32_t version);
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
Reference in New Issue
Block a user