mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-23 07:10:19 +00:00
Developers can use custom app package names in Cangjie applications
Signed-off-by: wentao <wentao18@huawei.com>
This commit is contained in:
parent
a0691142c8
commit
ede1dc1e25
@ -411,6 +411,7 @@ void* CJEnvironment::LoadCJLibrary(const char* dlName)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
isLoadCJLibrary_ = true;
|
||||
return handle;
|
||||
}
|
||||
|
||||
@ -437,9 +438,15 @@ void* CJEnvironment::LoadCJLibrary(OHOS::CJEnvironment::LibraryKind kind, const
|
||||
LOGE("load cj library failed: %{public}s", DynamicGetError());
|
||||
return nullptr;
|
||||
}
|
||||
isLoadCJLibrary_ = true;
|
||||
return handle;
|
||||
}
|
||||
|
||||
bool CJEnvironment::CheckLoadCJLibrary()
|
||||
{
|
||||
return isLoadCJLibrary_;
|
||||
}
|
||||
|
||||
void CJEnvironment::UnLoadCJLibrary(void* handle)
|
||||
{
|
||||
DynamicFreeLibrary(handle);
|
||||
@ -516,6 +523,9 @@ CJ_EXPORT extern "C" CJEnvMethods* OHOS_GetCJEnvInstance()
|
||||
},
|
||||
.setSanitizerKindRuntimeVersion = [](SanitizerKind kind) {
|
||||
return CJEnvironment::GetInstance()->SetSanitizerKindRuntimeVersion(kind);
|
||||
},
|
||||
.checkLoadCJLibrary = []() {
|
||||
return CJEnvironment::GetInstance()->CheckLoadCJLibrary();
|
||||
}
|
||||
};
|
||||
return &gCJEnvMethods;
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
return isUISchedulerStarted_;
|
||||
}
|
||||
bool StartUIScheduler();
|
||||
bool CheckLoadCJLibrary();
|
||||
void StopUIScheduler();
|
||||
enum LibraryKind {
|
||||
SYSTEM,
|
||||
@ -86,6 +87,7 @@ private:
|
||||
bool LoadRuntimeApis();
|
||||
static CJRuntimeAPI lazyApis_;
|
||||
bool isRuntimeStarted_{false};
|
||||
bool isLoadCJLibrary_{false};
|
||||
bool isUISchedulerStarted_{false};
|
||||
void* uiScheduler_ {nullptr};
|
||||
SanitizerKind sanitizerKind_ {SanitizerKind::NONE};
|
||||
|
@ -51,6 +51,7 @@ struct CJEnvMethods {
|
||||
bool (*startDebugger)() = nullptr;
|
||||
void (*registerCJUncaughtExceptionHandler)(const CJUncaughtExceptionInfo& uncaughtExceptionInfo) = nullptr;
|
||||
void (*setSanitizerKindRuntimeVersion)(SanitizerKind kind) = nullptr;
|
||||
bool (*checkLoadCJLibrary)() = nullptr;
|
||||
};
|
||||
|
||||
class CJEnv {
|
||||
|
@ -1345,7 +1345,9 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
}
|
||||
#ifdef CJ_FRONTEND
|
||||
if (!entryHapModuleInfo.abilityInfos.empty()) {
|
||||
isCJApp = AbilityRuntime::CJRuntime::IsCJAbility(entryHapModuleInfo.abilityInfos.front().srcEntrance);
|
||||
auto srcEntrancenName = entryHapModuleInfo.abilityInfos.front().srcEntrance;
|
||||
isCJApp = AbilityRuntime::CJRuntime::IsCJAbility(srcEntrancenName);
|
||||
AbilityRuntime::CJRuntime::SetPackageName(srcEntrancenName);
|
||||
}
|
||||
#endif
|
||||
moduelJson = entryHapModuleInfo.isModuleJson;
|
||||
|
@ -69,6 +69,8 @@ CJEnvMethods* CJEnv::LoadInstance()
|
||||
}
|
||||
AppLibPathVec CJRuntime::appLibPaths_;
|
||||
|
||||
std::string CJRuntime::packageName_;
|
||||
|
||||
std::unique_ptr<CJRuntime> CJRuntime::Create(const Options& options)
|
||||
{
|
||||
auto instance = std::make_unique<CJRuntime>();
|
||||
@ -152,10 +154,13 @@ bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths)
|
||||
return false;
|
||||
}
|
||||
void* handle = nullptr;
|
||||
// According to the OHOS rule, the format of the SO name is as follows
|
||||
auto targetSoName = "lib" + packageName_ + ".so";
|
||||
|
||||
for (const auto& libPath : appLibPaths) {
|
||||
for (auto& itor : std::filesystem::directory_iterator(libPath)) {
|
||||
// According to the convention, the names of cj generated products must contain the following keywords
|
||||
if (itor.path().string().find("ohos_app_cangjie") == std::string::npos) {
|
||||
if (itor.path().string().find(targetSoName) == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
handle = cjEnv->loadCJLibrary(itor.path().c_str());
|
||||
@ -171,6 +176,13 @@ bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths)
|
||||
return true;
|
||||
}
|
||||
|
||||
void CJRuntime::SetPackageName(std::string srcEntryName)
|
||||
{
|
||||
// According to the srcEntry rule in the Cangjie application,
|
||||
// the last '.' The previous strings were all package names
|
||||
packageName_ = srcEntryName.substr(0, srcEntryName.find_last_of("."));
|
||||
}
|
||||
|
||||
void CJRuntime::SetSanitizerVersion(SanitizerKind kind)
|
||||
{
|
||||
auto cjEnv = OHOS::CJEnv::LoadInstance();
|
||||
|
@ -36,6 +36,7 @@ public:
|
||||
static void SetAppLibPath(const AppLibPathMap& appLibPaths);
|
||||
static bool IsCJAbility(const std::string& info);
|
||||
static void SetSanitizerVersion(SanitizerKind kind);
|
||||
static void SetPackageName(std::string srcEntryName);
|
||||
~CJRuntime() override = default;
|
||||
|
||||
Language GetLanguage() const override
|
||||
@ -78,6 +79,7 @@ private:
|
||||
std::string bundleName_;
|
||||
uint32_t instanceId_ = 0;
|
||||
static AppLibPathVec appLibPaths_;
|
||||
static std::string packageName_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user