mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-23 07:10:19 +00:00
init cj context
Signed-off-by: liubinyu <liubinyu3@huawei.com> Change-Id: Ie0d4c929d8ad6a25fa6d40ea5a434e63ebfb53c5
This commit is contained in:
parent
fd6e6e67d8
commit
e00ffcd095
@ -108,6 +108,7 @@
|
||||
"//foundation/ability/ability_runtime/frameworks/native/ability/native:extension_module",
|
||||
"//foundation/ability/ability_runtime/frameworks/native/child_process:child_process",
|
||||
"//foundation/ability/ability_runtime/frameworks/native/insight_intent:insight_intent_innerkits",
|
||||
"//foundation/ability/ability_runtime/frameworks/cj:cj_ability_packages",
|
||||
"//foundation/ability/ability_runtime/frameworks/js/napi:napi_packages",
|
||||
"//foundation/ability/ability_runtime/cj_environment/frameworks/cj_environment:cj_environment",
|
||||
"//foundation/ability/ability_runtime/js_environment/frameworks/js_environment:js_environment",
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "cj_environment.h"
|
||||
|
||||
#include <regex>
|
||||
#include <string>
|
||||
|
||||
#include "cj_hilog.h"
|
||||
@ -27,8 +28,7 @@
|
||||
#include "event_handler.h"
|
||||
#endif
|
||||
|
||||
using namespace OHOS;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
const char DEBUGGER_LIBNAME[] = "libcj_debugger.z.so";
|
||||
const char DEBUGGER_SYMBOL_NAME[] = "StartDebuggerServer";
|
||||
@ -467,3 +467,10 @@ bool CJEnvironment::StartDebugger()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsCJAbility(const std::string& info)
|
||||
{
|
||||
// in cj application, the srcEntry format should be packageName.AbilityClassName.
|
||||
std::string pattern = "^([a-zA-Z0-9_]+\\.)+[a-zA-Z0-9_]+$";
|
||||
return std::regex_match(info, std::regex(pattern));
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ namespace {
|
||||
constexpr auto ERROR_BUF_SIZE = 255;
|
||||
static char g_dlError[ERROR_BUF_SIZE];
|
||||
static std::unordered_set<std::string> HasInited;
|
||||
static char* g_sharedLibsSonames = nullptr;
|
||||
}
|
||||
|
||||
enum ErrorCode {
|
||||
@ -48,6 +49,76 @@ static void ReadDlError()
|
||||
}
|
||||
}
|
||||
|
||||
static void InitSharedLibsSonames()
|
||||
{
|
||||
if (g_sharedLibsSonames != nullptr) {
|
||||
return;
|
||||
}
|
||||
const char* allowList[] = {
|
||||
"libc.so",
|
||||
"libdl.so",
|
||||
"libm.so",
|
||||
"libz.so",
|
||||
"libclang_rt.asan.so",
|
||||
"libclang_rt.tsan.so",
|
||||
// z library
|
||||
"libace_napi.z.so",
|
||||
"libace_ndk.z.so",
|
||||
"libbundle_ndk.z.so",
|
||||
"libdeviceinfo_ndk.z.so",
|
||||
"libEGL.so",
|
||||
"libGLESv3.so",
|
||||
"libhiappevent_ndk.z.so",
|
||||
"libhuks_ndk.z.so",
|
||||
"libhukssdk.z.so",
|
||||
"libnative_drawing.so",
|
||||
"libnative_window.so",
|
||||
"libnative_buffer.so",
|
||||
"libnative_vsync.so",
|
||||
"libOpenSLES.so",
|
||||
"libpixelmap_ndk.z.so",
|
||||
"libimage_ndk.z.so",
|
||||
"libimage_receiver_ndk.z.so",
|
||||
"libimage_source_ndk.z.so",
|
||||
"librawfile.z.so",
|
||||
"libuv.so",
|
||||
"libhilog.so",
|
||||
"libnative_image.so",
|
||||
"libnative_media_adec.so",
|
||||
"libnative_media_aenc.so",
|
||||
"libnative_media_codecbase.so",
|
||||
"libnative_media_core.so",
|
||||
"libnative_media_vdec.so",
|
||||
"libnative_media_venc.so",
|
||||
"libnative_media_avmuxer.so",
|
||||
"libnative_media_avdemuxer.so",
|
||||
"libnative_media_avsource.so",
|
||||
"libnative_avscreen_capture.so",
|
||||
"libavplayer.so",
|
||||
// adaptor library
|
||||
"libohosadaptor.so",
|
||||
"libusb_ndk.z.so",
|
||||
"libvulkan.so",
|
||||
};
|
||||
|
||||
size_t allowListLength = sizeof(allowList) / sizeof(char*);
|
||||
int32_t sharedLibsSonamesLength = 1;
|
||||
for (size_t i = 0; i < allowListLength; i++) {
|
||||
sharedLibsSonamesLength += strlen(allowList[i]) + 1;
|
||||
}
|
||||
g_sharedLibsSonames = new char[sharedLibsSonamesLength];
|
||||
int32_t cursor = 0;
|
||||
for (size_t i = 0; i < allowListLength; i++) {
|
||||
if (sprintf_s(g_sharedLibsSonames + cursor, sharedLibsSonamesLength - cursor, "%s:", allowList[i]) == -1) {
|
||||
delete[] g_sharedLibsSonames;
|
||||
g_sharedLibsSonames = nullptr;
|
||||
return;
|
||||
}
|
||||
cursor += strlen(allowList[i]) + 1;
|
||||
}
|
||||
g_sharedLibsSonames[cursor] = '\0';
|
||||
}
|
||||
|
||||
void DynamicInitNamespace(Dl_namespace* ns, void* parent, const char* entries, const char* name)
|
||||
{
|
||||
if (!ns || !entries || !name) {
|
||||
@ -74,16 +145,26 @@ void DynamicInitNamespace(Dl_namespace* ns, void* parent, const char* entries, c
|
||||
default:
|
||||
errMsg = "dlns_create failed, status: " + std::to_string(status);
|
||||
}
|
||||
(void)sprintf_s(g_dlError, sizeof(g_dlError), errMsg.c_str());
|
||||
if (sprintf_s(g_dlError, sizeof(g_dlError), errMsg.c_str()) == -1) {
|
||||
LOGE("Fail to generate error msg.");
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (parent) {
|
||||
dlns_inherit((Dl_namespace*)parent, ns, "allow_all_shared_libs");
|
||||
}
|
||||
Dl_namespace current;
|
||||
dlns_get(nullptr, ¤t);
|
||||
if (strcmp(name, "cj_app") != 0) {
|
||||
Dl_namespace current;
|
||||
dlns_get(nullptr, ¤t);
|
||||
dlns_inherit(ns, ¤t, "allow_all_shared_libs");
|
||||
} else {
|
||||
InitSharedLibsSonames();
|
||||
dlns_inherit(ns, ¤t, g_sharedLibsSonames);
|
||||
if (g_sharedLibsSonames != nullptr) {
|
||||
delete[] g_sharedLibsSonames;
|
||||
g_sharedLibsSonames = nullptr;
|
||||
}
|
||||
}
|
||||
HasInited.insert(std::string(name));
|
||||
}
|
||||
|
@ -92,6 +92,8 @@ private:
|
||||
bool isUISchedulerStarted_{false};
|
||||
void* uiScheduler_ {nullptr};
|
||||
};
|
||||
|
||||
CJ_EXPORT bool IsCJAbility(const std::string& info);
|
||||
}
|
||||
|
||||
#endif //OHOS_ABILITY_RUNTIME_CJ_ENVIRONMENT_H
|
||||
|
19
frameworks/cj/BUILD.gn
Normal file
19
frameworks/cj/BUILD.gn
Normal file
@ -0,0 +1,19 @@
|
||||
# Copyright (c) 2024 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
|
||||
group("cj_ability_packages") {
|
||||
deps = [ "${ability_runtime_path}/frameworks/cj/ffi:cj_ability_ffi" ]
|
||||
}
|
69
frameworks/cj/ffi/BUILD.gn
Normal file
69
frameworks/cj/ffi/BUILD.gn
Normal file
@ -0,0 +1,69 @@
|
||||
# Copyright (c) 2024 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
import("//foundation/ability/ability_runtime/cj_environment/cj_environment.gni")
|
||||
|
||||
ohos_shared_library("cj_ability_ffi") {
|
||||
defines = [
|
||||
"AMS_LOG_TAG = \"CJ_ABILITY_FFI\"",
|
||||
"AMS_LOG_DOMAIN = 0xD001150",
|
||||
]
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
include_dirs = [
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_delegator/",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
|
||||
"${ability_runtime_path}/tools/aa/include",
|
||||
"${ability_runtime_path}/frameworks/cj/ffi",
|
||||
"${ability_runtime_services_path}/common/include",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_native_path}/appkit:app_context",
|
||||
"${ability_runtime_native_path}/appkit:appkit_delegator",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"napi:cj_bind_native",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"cj_ability_delegator.cpp",
|
||||
"cj_application_context.cpp",
|
||||
"cj_element_name_ffi.cpp",
|
||||
"cj_utils_ffi.cpp",
|
||||
"cj_want_ffi.cpp",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-fstack-protector-all",
|
||||
"-fstack-protector-strong",
|
||||
"-O2",
|
||||
"-D_FORTIFY_SOURCE=2",
|
||||
]
|
||||
|
||||
cflags_cc = cflags
|
||||
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
145
frameworks/cj/ffi/cj_ability_delegator.cpp
Normal file
145
frameworks/cj/ffi/cj_ability_delegator.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "cj_ability_delegator.h"
|
||||
#include "ability_delegator_registry.h"
|
||||
#include "cj_application_context.h"
|
||||
#include "application_context.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityDelegatorCJ {
|
||||
using namespace OHOS::FFI;
|
||||
using namespace OHOS::AbilityRuntime;
|
||||
|
||||
int32_t CJAbilityDelegator::StartAbility(const AAFwk::Want &want)
|
||||
{
|
||||
return delegator_->StartAbility(want);
|
||||
}
|
||||
|
||||
std::shared_ptr<AppExecFwk::ShellCmdResult> CJAbilityDelegator::ExecuteShellCommand(const char* cmd, int64_t timeoutSec)
|
||||
{
|
||||
auto shellCmd = delegator_->ExecuteShellCommand(cmd, timeoutSec);
|
||||
std::shared_ptr<AppExecFwk::ShellCmdResult> ret = std::move(shellCmd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<AbilityRuntime::ApplicationContext> CJAbilityDelegator::GetAppContext()
|
||||
{
|
||||
auto context = delegator_->GetAppContext();
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "Failed to get AppContext from cj delegator.");
|
||||
return nullptr;
|
||||
}
|
||||
return context->GetApplicationContext();
|
||||
}
|
||||
|
||||
int32_t CJShellCmdResult::GetExitCode()
|
||||
{
|
||||
return shellCmdResultr_->GetExitCode();
|
||||
}
|
||||
|
||||
std::string CJShellCmdResult::GetStdResult()
|
||||
{
|
||||
return shellCmdResultr_->GetStdResult();
|
||||
}
|
||||
|
||||
std::string CJShellCmdResult::Dump()
|
||||
{
|
||||
return shellCmdResultr_->Dump();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
int64_t FFIAbilityDelegatorRegistryGetAbilityDelegator()
|
||||
{
|
||||
auto delegator = OHOS::AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (delegator == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "delegator is null.");
|
||||
return INVALID_CODE;
|
||||
}
|
||||
auto cjDelegator = FFI::FFIData::Create<CJAbilityDelegator>(delegator);
|
||||
return cjDelegator->GetID();
|
||||
}
|
||||
|
||||
int32_t FFIAbilityDelegatorStartAbility(int64_t id, WantHandle want)
|
||||
{
|
||||
auto cjDelegator = FFI::FFIData::GetData<CJAbilityDelegator>(id);
|
||||
if (cjDelegator == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "cj delegator is null.");
|
||||
return INVALID_CODE;
|
||||
}
|
||||
auto actualWant = reinterpret_cast<AAFwk::Want*>(want);
|
||||
return cjDelegator->StartAbility(*actualWant);
|
||||
}
|
||||
|
||||
int32_t FFIAbilityDelegatorExecuteShellCommand(int64_t id, const char* cmd, int64_t timeoutSec)
|
||||
{
|
||||
auto cjDelegator = FFI::FFIData::GetData<CJAbilityDelegator>(id);
|
||||
if (cjDelegator == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "cj delegator is null.");
|
||||
return INVALID_CODE;
|
||||
}
|
||||
auto cJShellCmdResult = FFI::FFIData::Create<CJShellCmdResult>(cjDelegator->ExecuteShellCommand(cmd, timeoutSec));
|
||||
return cJShellCmdResult->GetID();
|
||||
}
|
||||
|
||||
int32_t FFIGetExitCode(int64_t id)
|
||||
{
|
||||
auto cjShellCmdResult = FFI::FFIData::GetData<CJShellCmdResult>(id);
|
||||
if (cjShellCmdResult == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "cj shell command result is null.");
|
||||
return INVALID_CODE;
|
||||
}
|
||||
return cjShellCmdResult->GetExitCode();
|
||||
}
|
||||
|
||||
const char* FFIGetStdResult(int64_t id)
|
||||
{
|
||||
auto cjShellCmdResult = FFI::FFIData::GetData<CJShellCmdResult>(id);
|
||||
if (cjShellCmdResult == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "cj shell command result is null.");
|
||||
return nullptr;
|
||||
}
|
||||
return cjShellCmdResult->GetStdResult().c_str();
|
||||
}
|
||||
|
||||
const char* FFIDump(int64_t id)
|
||||
{
|
||||
auto cjShellCmdResult = FFI::FFIData::GetData<CJShellCmdResult>(id);
|
||||
if (cjShellCmdResult == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "cj shell command result is null.");
|
||||
return nullptr;
|
||||
}
|
||||
return cjShellCmdResult->Dump().c_str();
|
||||
}
|
||||
|
||||
int32_t FFIAbilityDelegatorApplicationContext(int64_t id)
|
||||
{
|
||||
auto cjDelegator = FFI::FFIData::GetData<CJAbilityDelegator>(id);
|
||||
if (cjDelegator == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "cj delegator is null.");
|
||||
return INVALID_CODE;
|
||||
}
|
||||
auto appContext = FFI::FFIData::Create<ApplicationContextCJ::CJApplicationContext>(cjDelegator->GetAppContext());
|
||||
if (appContext == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "app context is null.");
|
||||
return INVALID_CODE;
|
||||
}
|
||||
return appContext->GetID();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
64
frameworks/cj/ffi/cj_ability_delegator.h
Normal file
64
frameworks/cj/ffi/cj_ability_delegator.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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_CJ_ABILITY_DELEGATOR_FFI_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_ABILITY_DELEGATOR_FFI_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "ability_delegator_registry.h"
|
||||
#include "cj_macro.h"
|
||||
#include "ffi_remote_data.h"
|
||||
|
||||
using WantHandle = void*;
|
||||
namespace OHOS {
|
||||
namespace AbilityDelegatorCJ {
|
||||
|
||||
class CJAbilityDelegator : public FFI::FFIData {
|
||||
public:
|
||||
explicit CJAbilityDelegator(const std::shared_ptr<AppExecFwk::AbilityDelegator>& abilityDelegator)
|
||||
: delegator_(abilityDelegator) {};
|
||||
|
||||
int32_t StartAbility(const AAFwk::Want& want);
|
||||
std::shared_ptr<AppExecFwk::ShellCmdResult> ExecuteShellCommand(const char* cmd, int64_t timeoutSec);
|
||||
std::shared_ptr<AbilityRuntime::ApplicationContext> GetAppContext();
|
||||
|
||||
private:
|
||||
std::shared_ptr<AppExecFwk::AbilityDelegator> delegator_;
|
||||
};
|
||||
|
||||
class CJShellCmdResult : public FFI::FFIData {
|
||||
public:
|
||||
explicit CJShellCmdResult(std::shared_ptr<AppExecFwk::ShellCmdResult> shellCmdResult)
|
||||
: shellCmdResultr_(shellCmdResult) {};
|
||||
int32_t GetExitCode();
|
||||
std::string GetStdResult();
|
||||
std::string Dump();
|
||||
private:
|
||||
std::shared_ptr<AppExecFwk::ShellCmdResult> shellCmdResultr_;
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
CJ_EXPORT int64_t FFIAbilityDelegatorRegistryGetAbilityDelegator();
|
||||
CJ_EXPORT int32_t FFIAbilityDelegatorStartAbility(int64_t id, WantHandle want);
|
||||
CJ_EXPORT int32_t FFIAbilityDelegatorExecuteShellCommand(int64_t id, const char* cmd, int64_t timeoutSec);
|
||||
CJ_EXPORT int32_t FFIGetExitCode(int64_t id);
|
||||
CJ_EXPORT const char* FFIGetStdResult(int64_t id);
|
||||
CJ_EXPORT const char* FFIDump(int64_t id);
|
||||
CJ_EXPORT int32_t FFIAbilityDelegatorApplicationContext(int64_t id);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_ABILITY_DELEGATOR_FFI_H
|
79
frameworks/cj/ffi/cj_application_context.cpp
Normal file
79
frameworks/cj/ffi/cj_application_context.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "cj_application_context.h"
|
||||
|
||||
#include "ability_delegator_registry.h"
|
||||
#include "application_context.h"
|
||||
#include "cj_utils_ffi.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ApplicationContextCJ {
|
||||
using namespace OHOS::FFI;
|
||||
using namespace OHOS::AbilityRuntime;
|
||||
|
||||
int CJApplicationContext::GetArea()
|
||||
{
|
||||
auto context = applicationContext_.lock();
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "application context is null.");
|
||||
return INVALID_CODE;
|
||||
}
|
||||
return context->GetArea();
|
||||
}
|
||||
|
||||
std::shared_ptr<AppExecFwk::ApplicationInfo> CJApplicationContext::GetApplicationInfo()
|
||||
{
|
||||
auto context = applicationContext_.lock();
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "application context is null.");
|
||||
return nullptr;
|
||||
}
|
||||
return context->GetApplicationInfo();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
int64_t FFIGetArea(int64_t id)
|
||||
{
|
||||
auto context = FFI::FFIData::GetData<CJApplicationContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "cj application context is null.");
|
||||
return INVALID_CODE;
|
||||
}
|
||||
return context->GetArea();
|
||||
}
|
||||
|
||||
CApplicationInfo* FFICJApplicationInfo(int64_t id)
|
||||
{
|
||||
auto context = FFI::FFIData::GetData<CJApplicationContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "cj application context is null.");
|
||||
return nullptr;
|
||||
}
|
||||
auto appInfo = context->GetApplicationInfo();
|
||||
CApplicationInfo* buffer = static_cast<CApplicationInfo*>(malloc(sizeof(CApplicationInfo)));
|
||||
if (buffer == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "fail to malloc appinfo.");
|
||||
return nullptr;
|
||||
}
|
||||
buffer->name = CreateCStringFromString(appInfo->name);
|
||||
buffer->bundleName = CreateCStringFromString(appInfo->bundleName);
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
50
frameworks/cj/ffi/cj_application_context.h
Normal file
50
frameworks/cj/ffi/cj_application_context.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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_CJ_APPLICATION_CONTEXT_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_APPLICATION_CONTEXT_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "cj_macro.h"
|
||||
#include "ffi_remote_data.h"
|
||||
#include "ability_delegator_registry.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ApplicationContextCJ {
|
||||
class CJApplicationContext : public FFI::FFIData {
|
||||
public:
|
||||
explicit CJApplicationContext(std::weak_ptr<AbilityRuntime::Context> &&applicationContext)
|
||||
: applicationContext_(std::move(applicationContext)) {};
|
||||
|
||||
int GetArea();
|
||||
std::shared_ptr<AppExecFwk::ApplicationInfo> GetApplicationInfo();
|
||||
|
||||
private:
|
||||
std::weak_ptr<AbilityRuntime::Context> applicationContext_;
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
struct CApplicationInfo {
|
||||
const char* name;
|
||||
const char* bundleName;
|
||||
};
|
||||
|
||||
CJ_EXPORT int64_t FFIGetArea(int64_t id);
|
||||
CJ_EXPORT CApplicationInfo* FFICJApplicationInfo(int64_t id);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_APPLICATION_CONTEXT_H
|
67
frameworks/cj/ffi/cj_element_name_ffi.cpp
Normal file
67
frameworks/cj/ffi/cj_element_name_ffi.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "cj_element_name_ffi.h"
|
||||
|
||||
#include "cj_utils_ffi.h"
|
||||
#include "element_name.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
using OHOS::AppExecFwk::ElementName;
|
||||
|
||||
ElementNameHandle FFICJElementNameCreateWithContent(
|
||||
const char* deviceId, const char* bundleName, const char* abilityName, const char* moduleName)
|
||||
{
|
||||
return new ElementName(deviceId, bundleName, abilityName, moduleName);
|
||||
}
|
||||
|
||||
void FFICJElementNameDelete(ElementNameHandle elementNameHandle)
|
||||
{
|
||||
if (elementNameHandle == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "input element name handle is null.");
|
||||
return;
|
||||
}
|
||||
auto actualElementName = reinterpret_cast<ElementName*>(elementNameHandle);
|
||||
delete actualElementName;
|
||||
actualElementName = nullptr;
|
||||
}
|
||||
|
||||
// The return variable needs to delete in Cangjie by `FFICJElementNameParamsDelete`.
|
||||
ElementNameParams* FFICJElementNameGetElementNameInfo(ElementNameHandle elementNameHandle)
|
||||
{
|
||||
ElementNameParams* buffer = static_cast<ElementNameParams*>(malloc(sizeof(ElementNameParams)));
|
||||
if (buffer == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "fail to malloc element name params.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto actualElementName = reinterpret_cast<ElementName*>(elementNameHandle);
|
||||
buffer->deviceId = CreateCStringFromString(actualElementName->GetDeviceID());
|
||||
buffer->bundleName = CreateCStringFromString(actualElementName->GetBundleName());
|
||||
buffer->abilityName = CreateCStringFromString(actualElementName->GetAbilityName());
|
||||
buffer->moduleName = CreateCStringFromString(actualElementName->GetModuleName());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void FFICJElementNameParamsDelete(ElementNameParams* elementNameParams)
|
||||
{
|
||||
free(static_cast<void*>(elementNameParams->deviceId));
|
||||
free(static_cast<void*>(elementNameParams->bundleName));
|
||||
free(static_cast<void*>(elementNameParams->abilityName));
|
||||
free(static_cast<void*>(elementNameParams->moduleName));
|
||||
free(static_cast<void*>(elementNameParams->deviceId));
|
||||
free(static_cast<void*>(elementNameParams));
|
||||
}
|
38
frameworks/cj/ffi/cj_element_name_ffi.h
Normal file
38
frameworks/cj/ffi/cj_element_name_ffi.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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_CJ_ELEMENT_NAME_FFI_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_ELEMENT_NAME_FFI_H
|
||||
|
||||
#include "cj_macro.h"
|
||||
|
||||
using ElementNameHandle = void*;
|
||||
|
||||
extern "C" {
|
||||
struct ElementNameParams {
|
||||
char* deviceId;
|
||||
char* bundleName;
|
||||
char* abilityName;
|
||||
char* moduleName;
|
||||
};
|
||||
|
||||
CJ_EXPORT ElementNameHandle FFICJElementNameCreateWithContent(
|
||||
char* deviceId, char* bundleName, char* abilityName, char* moduleName);
|
||||
CJ_EXPORT void FFICJElementNameDelete(ElementNameHandle elementNameHandle);
|
||||
CJ_EXPORT ElementNameParams* FFICJElementNameGetElementNameInfo(ElementNameHandle elementNameHandle);
|
||||
CJ_EXPORT void FFICJElementNameParamsDelete(ElementNameParams* elementNameParams);
|
||||
};
|
||||
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_ELEMENT_NAME_FFI_H
|
27
frameworks/cj/ffi/cj_macro.h
Normal file
27
frameworks/cj/ffi/cj_macro.h
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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_CJ_MACRO_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_MACRO_H
|
||||
|
||||
#define INVALID_CODE 1
|
||||
|
||||
#ifdef WINDOWS_PLATFORM
|
||||
#define CJ_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define CJ_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_MACRO_H
|
34
frameworks/cj/ffi/cj_remote_object_ffi.h
Normal file
34
frameworks/cj/ffi/cj_remote_object_ffi.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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_CJ_REMOTE_OBJECT_FFI_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_REMOTE_OBJECT_FFI_H
|
||||
|
||||
#include "ffi_remote_data.h"
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class CJRemoteObject : public FFI::FFIData {
|
||||
public:
|
||||
explicit CJRemoteObject(const sptr<IRemoteObject>& remoteObject) : remoteObject_(remoteObject) {}
|
||||
|
||||
private:
|
||||
sptr<IRemoteObject> remoteObject_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_REMOTE_OBJECT_FFI_H
|
37
frameworks/cj/ffi/cj_utils_ffi.cpp
Normal file
37
frameworks/cj/ffi/cj_utils_ffi.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "cj_utils_ffi.h"
|
||||
|
||||
#include "securec.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
char* CreateCStringFromString(const std::string& source)
|
||||
{
|
||||
size_t length = source.size() + 1;
|
||||
auto res = static_cast<char*>(malloc(length));
|
||||
if (res == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::DEFAULT, "fail to mallc string.");
|
||||
return nullptr;
|
||||
}
|
||||
if (strcpy_s(res, length, source.c_str()) != 0) {
|
||||
free(res);
|
||||
TAG_LOGE(AAFwkTag::DEFAULT, "fail to strcpy source.");
|
||||
return nullptr;
|
||||
}
|
||||
return res;
|
||||
}
|
24
frameworks/cj/ffi/cj_utils_ffi.h
Normal file
24
frameworks/cj/ffi/cj_utils_ffi.h
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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_CJ_UTILS_FFI_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_UTILS_FFI_H
|
||||
|
||||
#include <string>
|
||||
|
||||
// The return variable needs free in CJ.
|
||||
char* CreateCStringFromString(const std::string& source);
|
||||
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_UTILS_FFI_H
|
124
frameworks/cj/ffi/cj_want_ffi.cpp
Normal file
124
frameworks/cj/ffi/cj_want_ffi.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "cj_want_ffi.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cj_utils_ffi.h"
|
||||
#include "want.h"
|
||||
#include "want_params_wrapper.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
using OHOS::AAFwk::Want;
|
||||
using OHOS::AppExecFwk::ElementName;
|
||||
|
||||
// Attention: The function does not handle entities.
|
||||
WantHandle FFICJWantCreateWithWantInfo(CJWantParams params)
|
||||
{
|
||||
Want* want = new (std::nothrow) Want();
|
||||
if (want == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::DEFAULT, "fail to new want.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto element = reinterpret_cast<ElementName*>(params.elementName);
|
||||
want->SetElement(*element);
|
||||
want->SetFlags(params.flags);
|
||||
want->SetUri(params.uri);
|
||||
want->SetAction(params.action);
|
||||
want->SetType(params.wantType);
|
||||
want->SetParams(OHOS::AAFwk::WantParamWrapper::ParseWantParams(params.parameters));
|
||||
|
||||
return want;
|
||||
}
|
||||
|
||||
void FFICJWantDelete(WantHandle want)
|
||||
{
|
||||
if (want == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::DEFAULT, "input want handle is null.");
|
||||
return;
|
||||
}
|
||||
auto actualWant = reinterpret_cast<Want*>(want);
|
||||
delete actualWant;
|
||||
actualWant = nullptr;
|
||||
}
|
||||
|
||||
CJWantParams* FFICJWantGetWantInfo(WantHandle want)
|
||||
{
|
||||
CJWantParams* buffer = static_cast<CJWantParams*>(malloc(sizeof(CJWantParams)));
|
||||
if (buffer == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::DEFAULT, "fail to malloc want params.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto actualWant = reinterpret_cast<Want*>(want);
|
||||
auto element = actualWant->GetElement();
|
||||
ElementNameHandle elementName = new ElementName(
|
||||
element.GetDeviceID(), element.GetBundleName(), element.GetAbilityName(), element.GetModuleName());
|
||||
if (elementName == nullptr) {
|
||||
free(buffer);
|
||||
TAG_LOGE(AAFwkTag::DEFAULT, "fail to new element name.");
|
||||
return nullptr;
|
||||
}
|
||||
buffer->elementName = elementName;
|
||||
buffer->flags = actualWant->GetFlags();
|
||||
buffer->uri = CreateCStringFromString(actualWant->GetUriString());
|
||||
buffer->action = CreateCStringFromString(actualWant->GetAction());
|
||||
buffer->wantType = CreateCStringFromString(actualWant->GetType());
|
||||
buffer->entities = const_cast<std::vector<std::string>*>(&(actualWant->GetEntities())); // reference vector<String>
|
||||
buffer->parameters = CreateCStringFromString(OHOS::AAFwk::WantParamWrapper(actualWant->GetParams()).ToString());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void FFICJWantParamsDelete(CJWantParams* params)
|
||||
{
|
||||
if (params == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::DEFAULT, "input want params is null.");
|
||||
return;
|
||||
}
|
||||
auto actualElementName = reinterpret_cast<ElementName*>(params->elementName);
|
||||
delete actualElementName;
|
||||
actualElementName = nullptr;
|
||||
|
||||
free(static_cast<void*>(params->uri));
|
||||
free(static_cast<void*>(params->action));
|
||||
free(static_cast<void*>(params->wantType));
|
||||
free(static_cast<void*>(params->parameters));
|
||||
// Entities are reference, do not free.
|
||||
free(static_cast<void*>(params));
|
||||
}
|
||||
|
||||
void FFICJWantAddEntity(WantHandle want, const char* entity)
|
||||
{
|
||||
if (want == nullptr || entity == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::DEFAULT, "input want handle or entity is null.");
|
||||
return;
|
||||
}
|
||||
auto actualWant = reinterpret_cast<Want*>(want);
|
||||
actualWant->AddEntity(entity);
|
||||
}
|
||||
|
||||
WantHandle FFICJWantParseUri(const char* uri)
|
||||
{
|
||||
if (uri == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::DEFAULT, "input uri is null.");
|
||||
return nullptr;
|
||||
}
|
||||
return Want::ParseUri(uri);
|
||||
}
|
47
frameworks/cj/ffi/cj_want_ffi.h
Normal file
47
frameworks/cj/ffi/cj_want_ffi.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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_CJ_WANT_FFI_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_WANT_FFI_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "cj_macro.h"
|
||||
#include "cj_element_name_ffi.h"
|
||||
|
||||
using WantHandle = void*;
|
||||
using VectorStringHandle = void*;
|
||||
using VectorInt32Handle = void*;
|
||||
|
||||
extern "C" {
|
||||
struct CJWantParams {
|
||||
ElementNameHandle elementName;
|
||||
uint32_t flags;
|
||||
char* uri;
|
||||
char* action;
|
||||
VectorStringHandle entities;
|
||||
char* wantType;
|
||||
char* parameters;
|
||||
};
|
||||
|
||||
CJ_EXPORT void FFICJWantDelete(WantHandle want);
|
||||
CJ_EXPORT CJWantParams* FFICJWantGetWantInfo(WantHandle want);
|
||||
CJ_EXPORT void FFICJWantParamsDelete(CJWantParams* params);
|
||||
CJ_EXPORT WantHandle FFICJWantCreateWithWantInfo(CJWantParams params);
|
||||
CJ_EXPORT WantHandle FFICJWantParseUri(const char* uri);
|
||||
CJ_EXPORT void FFICJWantAddEntity(WantHandle want, const char* entity);
|
||||
};
|
||||
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_WANT_FFI_H
|
28
frameworks/cj/mock/BUILD.gn
Normal file
28
frameworks/cj/mock/BUILD.gn
Normal file
@ -0,0 +1,28 @@
|
||||
# Copyright (c) 2024 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ohos_shared_library("cj_ability_ffi") {
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
|
||||
sources = [ "cj_ability_ffi.cpp" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("cj_delegator_ffi") {
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
|
||||
sources = [ "cj_delegator_ffi.cpp" ]
|
||||
}
|
83
frameworks/cj/mock/cj_ability_ffi.cpp
Normal file
83
frameworks/cj/mock/cj_ability_ffi.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 <cstdint>
|
||||
|
||||
extern "C" {
|
||||
int FFICJWantDelete();
|
||||
int FFICJWantGetWantInfo();
|
||||
int FFICJWantParamsDelete();
|
||||
int FFICJWantCreateWithWantInfo();
|
||||
int FFICJWantParseUri();
|
||||
int FFICJWantAddEntity();
|
||||
int FFICJElementNameCreateWithContent();
|
||||
int FFICJElementNameDelete();
|
||||
int FFICJElementNameGetElementNameInfo();
|
||||
int FFICJElementNameParamsDelete();
|
||||
int FFIAbilityGetAbilityContext();
|
||||
int FFIAbilityContextGetFilesDir();
|
||||
int FFIGetContext();
|
||||
int FFICreateNapiValue();
|
||||
int FFIGetArea();
|
||||
int FFICJApplicationInfo();
|
||||
int FFIAbilityDelegatorRegistryGetAbilityDelegator();
|
||||
int FFIAbilityDelegatorStartAbility();
|
||||
int FFIAbilityDelegatorExecuteShellCommand();
|
||||
int FFIGetExitCode();
|
||||
int FFIGetStdResult();
|
||||
int FFIDump();
|
||||
int FFIAbilityDelegatorApplicationContext();
|
||||
|
||||
struct AbilityContextBroker {
|
||||
int64_t isAbilityContextExisted = 1;
|
||||
int64_t getSizeOfStartOptions = 1;
|
||||
int64_t getAbilityInfo = 1;
|
||||
int64_t getHapModuleInfo = 1;
|
||||
int64_t getConfiguration = 1;
|
||||
int64_t startAbility = 1;
|
||||
int64_t startAbilityWithOption = 1;
|
||||
int64_t startAbilityWithAccount = 1;
|
||||
int64_t startAbilityWithAccountAndOption = 1;
|
||||
int64_t startServiceExtensionAbility = 1;
|
||||
int64_t startServiceExtensionAbilityWithAccount = 1;
|
||||
int64_t stopServiceExtensionAbility = 1;
|
||||
int64_t stopServiceExtensionAbilityWithAccount = 1;
|
||||
int64_t terminateSelf = 1;
|
||||
int64_t terminateSelfWithResult = 1;
|
||||
int64_t isTerminating = 1;
|
||||
int64_t connectAbility = 1;
|
||||
int64_t connectAbilityWithAccount = 1;
|
||||
int64_t disconnectAbility = 1;
|
||||
int64_t startAbilityForResult = 1;
|
||||
int64_t startAbilityForResultWithOption = 1;
|
||||
int64_t startAbilityForResultWithAccount = 1;
|
||||
int64_t startAbilityForResultWithAccountAndOption = 1;
|
||||
int64_t requestPermissionsFromUser = 1;
|
||||
int64_t setMissionLabel = 1;
|
||||
int64_t setMissionIcon = 1;
|
||||
};
|
||||
|
||||
AbilityContextBroker* FFIAbilityContextGetBroker()
|
||||
{
|
||||
static AbilityContextBroker globalBroker;
|
||||
return &globalBroker;
|
||||
}
|
||||
|
||||
void RegisterCJAbilityStageFuncs() {}
|
||||
void RegisterCJAbilityConnectCallbackFuncs() {}
|
||||
void RegisterCJAbilityCallbacks() {}
|
||||
void RegisterCJAbilityFuncs() {}
|
||||
void FFIAbilityContextRequestDialogService() {}
|
||||
}
|
20
frameworks/cj/mock/cj_delegator_ffi.cpp
Normal file
20
frameworks/cj/mock/cj_delegator_ffi.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 <cstdint>
|
||||
|
||||
extern "C" {
|
||||
void RegisterCJTestRunnerFuncs() {}
|
||||
}
|
@ -674,6 +674,27 @@ ErrCode AbilityContextImpl::RequestDialogService(napi_env env, AAFwk::Want &want
|
||||
return err;
|
||||
}
|
||||
|
||||
ErrCode AbilityContextImpl::RequestDialogService(AAFwk::Want &want, RequestDialogResultTask &&task)
|
||||
{
|
||||
want.SetParam(RequestConstants::REQUEST_TOKEN_KEY, token_);
|
||||
int32_t left;
|
||||
int32_t top;
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
GetWindowRect(left, top, width, height);
|
||||
want.SetParam(RequestConstants::WINDOW_RECTANGLE_LEFT_KEY, left);
|
||||
want.SetParam(RequestConstants::WINDOW_RECTANGLE_TOP_KEY, top);
|
||||
want.SetParam(RequestConstants::WINDOW_RECTANGLE_WIDTH_KEY, width);
|
||||
want.SetParam(RequestConstants::WINDOW_RECTANGLE_HEIGHT_KEY, height);
|
||||
|
||||
sptr<IRemoteObject> remoteObject = new DialogRequestCallbackImpl(std::move(task));
|
||||
want.SetParam(RequestConstants::REQUEST_CALLBACK_KEY, remoteObject);
|
||||
|
||||
auto err = AAFwk::AbilityManagerClient::GetInstance()->RequestDialogService(want, token_);
|
||||
TAG_LOGD(AAFwkTag::CONTEXT, "RequestDialogService ret=%{public}d", static_cast<int32_t>(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
ErrCode AbilityContextImpl::ReportDrawnCompleted()
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::CONTEXT, "called.");
|
||||
|
@ -285,7 +285,11 @@ ohos_shared_library("abilitykit_native") {
|
||||
defines = []
|
||||
|
||||
if (cj_frontend) {
|
||||
sources += [ "${ability_runtime_native_path}/ability/native/ability_runtime/cj_ability_object.cpp" ]
|
||||
sources += [
|
||||
"${ability_runtime_native_path}/ability/native/ability_runtime/cj_ability_connect_callback_object.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/ability_runtime/cj_ability_context.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/ability_runtime/cj_ability_context_object.cpp",
|
||||
]
|
||||
include_dirs += [
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime",
|
||||
"${ability_runtime_path}/frameworks/cj/ffi",
|
||||
@ -294,6 +298,7 @@ ohos_shared_library("abilitykit_native") {
|
||||
"napi:cj_bind_ffi",
|
||||
"napi:cj_bind_native",
|
||||
]
|
||||
defines += [ "CJ_FRONTEND" ]
|
||||
}
|
||||
|
||||
if (background_task_mgr_continuous_task_enable) {
|
||||
@ -552,12 +557,13 @@ ohos_shared_library("uiabilitykit_native") {
|
||||
|
||||
if (cj_frontend) {
|
||||
sources += [
|
||||
"${ability_runtime_native_path}/ability/native/ability_runtime/cj_ability_ffi.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/ability_runtime/cj_ability_object.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/ability_runtime/cj_ui_ability.cpp",
|
||||
]
|
||||
|
||||
include_dirs += [ "${ability_runtime_path}/frameworks/cj/ffi" ]
|
||||
|
||||
defines = [ "CJ_FRONTEND" ]
|
||||
external_deps += [
|
||||
"napi:cj_bind_ffi",
|
||||
"napi:cj_bind_native",
|
||||
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "cj_ability_connect_callback_object.h"
|
||||
|
||||
#include "cj_remote_object_ffi.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
using namespace OHOS::AbilityRuntime;
|
||||
|
||||
namespace {
|
||||
CJAbilityConnectCallbackFuncs* g_cjAbilityConnectCallbackFuncs = nullptr;
|
||||
}
|
||||
|
||||
void RegisterCJAbilityConnectCallbackFuncs(void (*registerFunc)(CJAbilityConnectCallbackFuncs* result))
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::CONTEXT, "RegisterCJAbilityConnectCallbackFuncs start.");
|
||||
if (g_cjAbilityConnectCallbackFuncs != nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "Repeated registration for cangjie functions of CJAbilityConnectCallback.");
|
||||
return;
|
||||
}
|
||||
|
||||
g_cjAbilityConnectCallbackFuncs = new CJAbilityConnectCallbackFuncs();
|
||||
registerFunc(g_cjAbilityConnectCallbackFuncs);
|
||||
}
|
||||
|
||||
CJAbilityConnectCallback::~CJAbilityConnectCallback()
|
||||
{
|
||||
if (g_cjAbilityConnectCallbackFuncs == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "Cangjie functions for CJAbilityConnectCallbacks are not registered");
|
||||
return;
|
||||
}
|
||||
g_cjAbilityConnectCallbackFuncs->release(callbackId_);
|
||||
}
|
||||
|
||||
void CJAbilityConnectCallback::OnAbilityConnectDone(
|
||||
const AppExecFwk::ElementName& element, const sptr<IRemoteObject>& remoteObject, int resultCode)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::CONTEXT, "OnAbilityConnectDone begin, resultCode:%{public}d", resultCode);
|
||||
if (g_cjAbilityConnectCallbackFuncs == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "Cangjie functions for CJAbilityConnectCallbacks are not registered");
|
||||
return;
|
||||
}
|
||||
|
||||
ElementNameHandle elementNameHandle = const_cast<AppExecFwk::ElementName*>(&element);
|
||||
// The cj side is responsible for the release.
|
||||
auto cjRemoteObj = FFI::FFIData::Create<AppExecFwk::CJRemoteObject>(remoteObject);
|
||||
g_cjAbilityConnectCallbackFuncs->onConnect(callbackId_, elementNameHandle, cjRemoteObj->GetID(), resultCode);
|
||||
}
|
||||
|
||||
void CJAbilityConnectCallback::OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int resultCode)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::CONTEXT, "OnAbilityDisconnectDone begin, resultCode:%{public}d", resultCode);
|
||||
if (g_cjAbilityConnectCallbackFuncs == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "Cangjie functions for CJAbilityConnectCallbacks are not registered");
|
||||
return;
|
||||
}
|
||||
|
||||
ElementNameHandle elementNameHandle = const_cast<AppExecFwk::ElementName*>(&element);
|
||||
g_cjAbilityConnectCallbackFuncs->onDisconnect(callbackId_, elementNameHandle, resultCode);
|
||||
}
|
@ -0,0 +1,329 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "ability_runtime/cj_ability_context.h"
|
||||
|
||||
#include "cj_common_ffi.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "cj_ability_connect_callback_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> CJAbilityContext::GetAbilityContext()
|
||||
{
|
||||
return context_;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> CJAbilityContext::GetToken()
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return nullptr;
|
||||
}
|
||||
return context_->GetToken();
|
||||
}
|
||||
|
||||
std::string CJAbilityContext::GetPreferencesDir()
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return "";
|
||||
}
|
||||
return context_->GetPreferencesDir();
|
||||
}
|
||||
|
||||
std::string CJAbilityContext::GetDatabaseDir()
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return "";
|
||||
}
|
||||
return context_->GetDatabaseDir();
|
||||
}
|
||||
|
||||
std::string CJAbilityContext::GetBundleName()
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return "";
|
||||
}
|
||||
return context_->GetBundleName();
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::GetArea()
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->GetArea();
|
||||
}
|
||||
|
||||
std::shared_ptr<AppExecFwk::AbilityInfo> CJAbilityContext::GetAbilityInfo()
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return nullptr;
|
||||
}
|
||||
return context_->GetAbilityInfo();
|
||||
}
|
||||
|
||||
std::shared_ptr<AppExecFwk::HapModuleInfo> CJAbilityContext::GetHapModuleInfo()
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return nullptr;
|
||||
}
|
||||
return context_->GetHapModuleInfo();
|
||||
}
|
||||
|
||||
std::shared_ptr<AppExecFwk::Configuration> CJAbilityContext::GetConfiguration()
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return nullptr;
|
||||
}
|
||||
return context_->GetConfiguration();
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::StartAbility(const AAFwk::Want& want)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
// -1 is default accountId which is the same as js.
|
||||
return context_->StartAbility(want, -1);
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::StartAbility(const AAFwk::Want& want, const AAFwk::StartOptions& startOptions)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->StartAbility(want, startOptions, -1);
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::StartAbilityWithAccount(const AAFwk::Want& want, int32_t accountId)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->StartAbilityWithAccount(want, accountId, -1);
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::StartAbilityWithAccount(
|
||||
const AAFwk::Want& want, int32_t accountId, const AAFwk::StartOptions& startOptions)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->StartAbilityWithAccount(want, accountId, startOptions, -1);
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::StartServiceExtensionAbility(const Want& want)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->StartServiceExtensionAbility(want);
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::StartServiceExtensionAbilityWithAccount(const Want& want, int32_t accountId)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->StartServiceExtensionAbility(want, accountId);
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::StopServiceExtensionAbility(const Want& want)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->StopServiceExtensionAbility(want);
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::StopServiceExtensionAbilityWithAccount(const Want& want, int32_t accountId)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->StopServiceExtensionAbility(want, accountId);
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::TerminateSelf()
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->TerminateSelf();
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::TerminateSelfWithResult(const AAFwk::Want& want, int32_t resultCode)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->TerminateAbilityWithResult(want, resultCode);
|
||||
}
|
||||
|
||||
std::tuple<int32_t, bool> CJAbilityContext::IsTerminating()
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return std::make_tuple(ERR_INVALID_INSTANCE_CODE, false);
|
||||
}
|
||||
return std::make_tuple(SUCCESS_CODE, context_->IsTerminating());
|
||||
}
|
||||
|
||||
bool CJAbilityContext::ConnectAbility(const AAFwk::Want& want, int64_t connectionId)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto connection = new CJAbilityConnectCallback(connectionId);
|
||||
return context_->ConnectAbility(want, connection);
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::ConnectAbilityWithAccount(
|
||||
const AAFwk::Want& want, int32_t accountId, int64_t connectionId)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto connection = new CJAbilityConnectCallback(connectionId);
|
||||
return context_->ConnectAbilityWithAccount(want, accountId, connection);
|
||||
}
|
||||
|
||||
void CJAbilityContext::DisconnectAbility(const AAFwk::Want& want, int64_t connectionId)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null");
|
||||
return;
|
||||
}
|
||||
auto connection = new CJAbilityConnectCallback(connectionId);
|
||||
context_->ConnectAbility(want, connection);
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::StartAbilityForResult(const AAFwk::Want& want, int32_t requestCode, RuntimeTask&& task)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->StartAbilityForResult(want, requestCode, std::move(task));
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::StartAbilityForResult(
|
||||
const AAFwk::Want& want, const AAFwk::StartOptions& startOptions, int32_t requestCode, RuntimeTask&& task)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->StartAbilityForResult(want, startOptions, requestCode, std::move(task));
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::StartAbilityForResultWithAccount(
|
||||
const AAFwk::Want& want, int32_t accountId, int32_t requestCode, RuntimeTask&& task)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->StartAbilityForResultWithAccount(want, accountId, requestCode, std::move(task));
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::StartAbilityForResultWithAccount(const AAFwk::Want& want, int32_t accountId,
|
||||
const AAFwk::StartOptions& startOptions, int32_t requestCode, RuntimeTask&& task)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->StartAbilityForResultWithAccount(want, accountId, startOptions, requestCode, std::move(task));
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::RequestPermissionsFromUser(
|
||||
AppExecFwk::Ability* ability, std::vector<std::string>& permissions, PermissionRequestTask&& task)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return SUCCESS_CODE;
|
||||
}
|
||||
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
int32_t CJAbilityContext::SetMissionLabel(const std::string& label)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->SetMissionLabel(label);
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::SetMissionIcon(const std::shared_ptr<OHOS::Media::PixelMap>& icon)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->SetMissionIcon(icon);
|
||||
}
|
||||
#endif
|
||||
|
||||
void CJAbilityContext::InheritWindowMode(AAFwk::Want& want)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::CONTEXT, "CJAbilityContext::InheritWindowMode called");
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
// Only split mode need inherit.
|
||||
auto windowMode = context_->GetCurrentWindowMode();
|
||||
if (windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY ||
|
||||
windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY) {
|
||||
want.SetParam(Want::PARAM_RESV_WINDOW_MODE, windowMode);
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::CONTEXT,
|
||||
"CJAbilityContext::InheritWindowMode called end. window mode is %{public}d", windowMode);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t CJAbilityContext::RequestDialogService(AAFwk::Want& want, RequestDialogResultTask&& task)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null.");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context_->RequestDialogService(want, std::move(task));
|
||||
}
|
||||
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -0,0 +1,526 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "cj_ability_context_object.h"
|
||||
|
||||
#include "accesstoken_kit.h"
|
||||
#include "cj_ability_context.h"
|
||||
#include "cj_ability_connect_callback_object.h"
|
||||
#include "cj_common_ffi.h"
|
||||
#include "ffi_remote_data.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "napi_common_start_options.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "pixel_map.h"
|
||||
|
||||
using namespace OHOS::FFI;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr int64_t NOT_SUPPORT = 1;
|
||||
// g_cjAbilityCallbacks is used to save cangjie functions.
|
||||
// It is assigned by the global variable REGISTER_ABILITY_CONTEXT_CALLBACK on the cangjie side which invokes
|
||||
// RegisterCJAbilityCallbacks. And it is never released.
|
||||
CJAbilityCallbacks* g_cjAbilityCallbacks = nullptr;
|
||||
}
|
||||
|
||||
void RegisterCJAbilityCallbacks(void (*registerFunc)(CJAbilityCallbacks*))
|
||||
{
|
||||
if (g_cjAbilityCallbacks != nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "Repeated registration for cj functions of CJAbility.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (registerFunc == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "RegisterCJAbilityCallbacks failed, registerFunc is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
g_cjAbilityCallbacks = new CJAbilityCallbacks();
|
||||
registerFunc(g_cjAbilityCallbacks);
|
||||
}
|
||||
|
||||
void UnWrapStartOption(CJStartOptions* source, AAFwk::StartOptions& target)
|
||||
{
|
||||
if (source == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "UnWrapStartOption failed, source is nullptr");
|
||||
return;
|
||||
}
|
||||
target.SetWindowMode(source->windowMode);
|
||||
target.SetDisplayID(source->displayId);
|
||||
}
|
||||
|
||||
std::function<void(int32_t, CJAbilityResult*)> WrapCJAbilityResultTask(int64_t lambdaId)
|
||||
{
|
||||
auto cjTask = [lambdaId](int32_t error, CJAbilityResult* abilityResult) {
|
||||
if (g_cjAbilityCallbacks == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "StartAbilityForResult failed, cangjie callbacks are not registered");
|
||||
return;
|
||||
}
|
||||
g_cjAbilityCallbacks->invokeAbilityResultCallback(lambdaId, error, abilityResult);
|
||||
TAG_LOGD(AAFwkTag::CONTEXT, "WrapCJAbilityResultTask: error is %{public}d", error);
|
||||
};
|
||||
return cjTask;
|
||||
}
|
||||
|
||||
RuntimeTask WrapRuntimeTask(std::function<void(int32_t, CJAbilityResult*)> cjTask, int32_t error)
|
||||
{
|
||||
RuntimeTask task = [cjTask, error](int32_t resultCode, const AAFwk::Want& want, bool isInner) {
|
||||
WantHandle wantHandle = const_cast<AAFwk::Want*>(&want);
|
||||
CJAbilityResult abilityResult = { resultCode, wantHandle };
|
||||
cjTask(error, &abilityResult);
|
||||
TAG_LOGD(AAFwkTag::CONTEXT, "WrapRuntimeTask: error is %{public}d", error);
|
||||
};
|
||||
return task;
|
||||
}
|
||||
|
||||
bool FFIAbilityContextIsAbilityContextExisted(int64_t id)
|
||||
{
|
||||
return FFIData::GetData<CJAbilityContext>(id) != nullptr;
|
||||
}
|
||||
|
||||
int64_t FFIAbilityContextGetSizeOfStartOptions()
|
||||
{
|
||||
return sizeof(CJStartOptions);
|
||||
}
|
||||
|
||||
int64_t FFIAbilityContextGetAbilityInfo(int64_t id)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "GetAbilityInfo failed, invalid id of CJAbilityContext");
|
||||
return INVALID_DATA_ID;
|
||||
}
|
||||
return NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int64_t FFIAbilityContextGetHapModuleInfo(int64_t id)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "GetHapModuleInfo failed, invalid id of CJAbilityContext");
|
||||
return INVALID_DATA_ID;
|
||||
}
|
||||
auto hapModuleInfo = context->GetHapModuleInfo();
|
||||
return NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int64_t FFIAbilityContextGetConfiguration(int64_t id)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "GetConfiguration failed, invalid id of CJAbilityContext");
|
||||
return INVALID_DATA_ID;
|
||||
}
|
||||
auto configuration = context->GetConfiguration();
|
||||
return NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextStartAbility(int64_t id, WantHandle want)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "StartAbility failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
|
||||
auto actualWant = reinterpret_cast<Want*>(want);
|
||||
context->InheritWindowMode(*actualWant);
|
||||
return context->StartAbility(*actualWant);
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextStartAbilityWithOption(int64_t id, WantHandle want, CJStartOptions* startOption)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "StartAbility failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto actualWant = reinterpret_cast<Want*>(want);
|
||||
context->InheritWindowMode(*actualWant);
|
||||
AAFwk::StartOptions option;
|
||||
UnWrapStartOption(startOption, option);
|
||||
return context->StartAbility(*actualWant, option);
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextStartAbilityWithAccount(int64_t id, WantHandle want, int32_t accountId)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "StartAbilityWithAccount failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto actualWant = reinterpret_cast<Want*>(want);
|
||||
context->InheritWindowMode(*actualWant);
|
||||
return context->StartAbilityWithAccount(*actualWant, accountId);
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextStartAbilityWithAccountAndOption(
|
||||
int64_t id, WantHandle want, int32_t accountId, CJStartOptions* startOption)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "StartAbilityWithAccount failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto actualWant = reinterpret_cast<Want*>(want);
|
||||
context->InheritWindowMode(*actualWant);
|
||||
AAFwk::StartOptions option;
|
||||
UnWrapStartOption(startOption, option);
|
||||
return context->StartAbilityWithAccount(*actualWant, accountId, option);
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextStartServiceExtensionAbility(int64_t id, WantHandle want)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "StartServiceExtensionAbility failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto actualWant = reinterpret_cast<Want*>(want);
|
||||
return context->StartServiceExtensionAbility(*actualWant);
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextStartServiceExtensionAbilityWithAccount(int64_t id, WantHandle want, int32_t accountId)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "StartServiceExtensionAbilityWithAccount failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto actualWant = reinterpret_cast<Want*>(want);
|
||||
return context->StartServiceExtensionAbilityWithAccount(*actualWant, accountId);
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextStopServiceExtensionAbility(int64_t id, WantHandle want)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "StopServiceExtensionAbility failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto actualWant = reinterpret_cast<Want*>(want);
|
||||
return context->StopServiceExtensionAbility(*actualWant);
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextStopServiceExtensionAbilityWithAccount(int64_t id, WantHandle want, int32_t accountId)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "StopServiceExtensionAbilityWithAccount failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto actualWant = reinterpret_cast<Want*>(want);
|
||||
return context->StopServiceExtensionAbilityWithAccount(*actualWant, accountId);
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextTerminateSelf(int64_t id)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "TerminateSelf failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context->TerminateSelf();
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextTerminateSelfWithResult(int64_t id, WantHandle want, int32_t resultCode)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "TerminateSelfWithResult failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto actualWant = reinterpret_cast<Want*>(want);
|
||||
return context->TerminateSelfWithResult(*actualWant, resultCode);
|
||||
}
|
||||
|
||||
RetDataBool FFIAbilityContextIsTerminating(int64_t id)
|
||||
{
|
||||
RetDataBool res = { ERR_INVALID_INSTANCE_CODE, false };
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "IsTerminating failed, invalid id of CJAbilityContext");
|
||||
return res;
|
||||
}
|
||||
|
||||
auto [code, data] = context->IsTerminating();
|
||||
res.code = code;
|
||||
res.data = data;
|
||||
return res;
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextConnectAbility(int64_t id, WantHandle want, int64_t connection)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "ConnectAbility failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto actualWant = reinterpret_cast<AAFwk::Want*>(want);
|
||||
auto res = context->ConnectAbility(*actualWant, connection);
|
||||
return res ? SUCCESS_CODE : ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextConnectAbilityWithAccount(int64_t id, WantHandle want, int32_t accountId, int64_t connection)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "ConnectAbility failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto actualWant = reinterpret_cast<AAFwk::Want*>(want);
|
||||
auto res = context->ConnectAbilityWithAccount(*actualWant, accountId, connection);
|
||||
return res ? SUCCESS_CODE : ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextDisconnectAbility(int64_t id, WantHandle want, int64_t connection)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "ConnectAbility failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto actualWant = reinterpret_cast<AAFwk::Want*>(want);
|
||||
context->ConnectAbility(*actualWant, connection);
|
||||
return SUCCESS_CODE;
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextStartAbilityForResult(int64_t id, WantHandle want, int32_t requestCode, int64_t lambdaId)
|
||||
{
|
||||
auto cjTask = WrapCJAbilityResultTask(lambdaId);
|
||||
RuntimeTask task = WrapRuntimeTask(cjTask, SUCCESS_CODE);
|
||||
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "StartAbilityForResult failed, invalid id of CJAbilityContext");
|
||||
cjTask(ERR_INVALID_INSTANCE_CODE, nullptr);
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
|
||||
auto actualWant = reinterpret_cast<AAFwk::Want*>(want);
|
||||
context->InheritWindowMode(*actualWant);
|
||||
return context->StartAbilityForResult(*actualWant, requestCode, std::move(task));
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextStartAbilityForResultWithOption(
|
||||
int64_t id, WantHandle want, CJStartOptions* startOption, int32_t requestCode, int64_t lambdaId)
|
||||
{
|
||||
auto cjTask = WrapCJAbilityResultTask(lambdaId);
|
||||
RuntimeTask task = WrapRuntimeTask(cjTask, SUCCESS_CODE);
|
||||
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "StartAbilityForResult failed, invalid id of CJAbilityContext");
|
||||
cjTask(ERR_INVALID_INSTANCE_CODE, nullptr);
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
|
||||
auto actualWant = reinterpret_cast<AAFwk::Want*>(want);
|
||||
context->InheritWindowMode(*actualWant);
|
||||
AAFwk::StartOptions option;
|
||||
UnWrapStartOption(startOption, option);
|
||||
return context->StartAbilityForResult(*actualWant, option, requestCode, std::move(task));
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextStartAbilityForResultWithAccount(
|
||||
int64_t id, WantHandle want, int32_t accountId, int32_t requestCode, int64_t lambdaId)
|
||||
{
|
||||
auto cjTask = WrapCJAbilityResultTask(lambdaId);
|
||||
RuntimeTask task = WrapRuntimeTask(cjTask, SUCCESS_CODE);
|
||||
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "StartAbilityForResult failed, invalid id of CJAbilityContext");
|
||||
cjTask(ERR_INVALID_INSTANCE_CODE, nullptr);
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
|
||||
auto actualWant = reinterpret_cast<AAFwk::Want*>(want);
|
||||
context->InheritWindowMode(*actualWant);
|
||||
return context->StartAbilityForResultWithAccount(*actualWant, accountId, requestCode, std::move(task));
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextStartAbilityForResultWithAccountAndOption(
|
||||
int64_t id, WantHandle want, int32_t accountId, CJStartOptions* startOption, int32_t requestCode, int64_t lambdaId)
|
||||
{
|
||||
auto cjTask = WrapCJAbilityResultTask(lambdaId);
|
||||
RuntimeTask task = WrapRuntimeTask(cjTask, SUCCESS_CODE);
|
||||
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "StartAbilityForResult failed, invalid id of CJAbilityContext");
|
||||
cjTask(ERR_INVALID_INSTANCE_CODE, nullptr);
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
|
||||
auto actualWant = reinterpret_cast<AAFwk::Want*>(want);
|
||||
context->InheritWindowMode(*actualWant);
|
||||
AAFwk::StartOptions option;
|
||||
UnWrapStartOption(startOption, option);
|
||||
return context->StartAbilityForResultWithAccount(*actualWant, accountId, option, requestCode, std::move(task));
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextRequestPermissionsFromUser(
|
||||
int64_t id, VectorStringHandle permissions, int32_t requestCode, int64_t lambdaId)
|
||||
{
|
||||
auto cjTask = [lambdaId](int32_t error, CJPermissionRequestResult* cjPermissionRequestResult) {
|
||||
if (g_cjAbilityCallbacks == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "RequestPermissionsFromUser failed, cangjie callbacks are not registered");
|
||||
return;
|
||||
}
|
||||
g_cjAbilityCallbacks->invokePermissionRequestResultCallback(lambdaId, error, cjPermissionRequestResult);
|
||||
TAG_LOGD(AAFwkTag::CONTEXT, "RequestPermissionsFromUser callback is called, error is %{public}d", error);
|
||||
};
|
||||
PermissionRequestTask task = [cjTask](const std::vector<std::string>& permissions,
|
||||
const std::vector<int>& grantResults) {
|
||||
VectorStringHandle permissionList = const_cast<std::vector<std::string>*>(&permissions);
|
||||
VectorInt32Handle result = const_cast<std::vector<int>*>(&grantResults);
|
||||
CJPermissionRequestResult cjPermissionRequestResult = { permissionList, result };
|
||||
cjTask(SUCCESS_CODE, &cjPermissionRequestResult);
|
||||
};
|
||||
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "RequestPermissionsFromUser failed, invalid id of CJAbilityContext");
|
||||
cjTask(ERR_INVALID_INSTANCE_CODE, nullptr);
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
|
||||
auto actualPermissions = reinterpret_cast<std::vector<std::string>*>(permissions);
|
||||
if (actualPermissions->empty()) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "Params do not meet specification, permissions is empty.");
|
||||
cjTask(ERR_INVALID_INSTANCE_CODE, nullptr);
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
int32_t FFIAbilityContextSetMissionLabel(int64_t id, const char* label)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "SetMissionLabel failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return context->SetMissionLabel(label);
|
||||
}
|
||||
|
||||
int32_t FFIAbilityContextSetMissionIcon(int64_t id, int64_t pixelMapId)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "SetMissionIcon failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t FFIAbilityContextRequestDialogService(int64_t id, WantHandle want, int64_t lambdaId)
|
||||
{
|
||||
auto context = FFIData::GetData<CJAbilityContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "RequestDialogService failed, invalid id of CJAbilityContext");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
RequestDialogResultTask task = [lambdaId](int32_t resultCode, const AAFwk::Want &resultWant) {
|
||||
if (g_cjAbilityCallbacks == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "RequestDialogService failed, cangjie callbacks are not registered");
|
||||
return;
|
||||
}
|
||||
CJDialogRequestResult dialogRequestResult = {
|
||||
.resultCode = resultCode,
|
||||
.wantHandle = (WantHandle)&resultWant
|
||||
};
|
||||
g_cjAbilityCallbacks->invokeDialogRequestResultCallback(lambdaId, resultCode, &dialogRequestResult);
|
||||
TAG_LOGD(AAFwkTag::CONTEXT, "RequestDialogService callback is called, resultCode is %{public}d", resultCode);
|
||||
};
|
||||
auto actualWant = reinterpret_cast<AAFwk::Want*>(want);
|
||||
return context->RequestDialogService(*actualWant, std::move(task));
|
||||
}
|
||||
|
||||
#define EXPORT __attribute__((visibility("default")))
|
||||
EXPORT AbilityContextBroker* FFIAbilityContextGetBroker()
|
||||
{
|
||||
static AbilityContextBroker contextFuncs = {
|
||||
.isAbilityContextExisted = FFIAbilityContextIsAbilityContextExisted,
|
||||
.getSizeOfStartOptions = FFIAbilityContextGetSizeOfStartOptions,
|
||||
.getAbilityInfo = FFIAbilityContextGetAbilityInfo,
|
||||
.getHapModuleInfo = FFIAbilityContextGetHapModuleInfo,
|
||||
.getConfiguration = FFIAbilityContextGetConfiguration,
|
||||
.startAbility = FFIAbilityContextStartAbility,
|
||||
.startAbilityWithOption = FFIAbilityContextStartAbilityWithOption,
|
||||
.startAbilityWithAccount = FFIAbilityContextStartAbilityWithAccount,
|
||||
.startAbilityWithAccountAndOption = FFIAbilityContextStartAbilityWithAccountAndOption,
|
||||
.startServiceExtensionAbility = FFIAbilityContextStartServiceExtensionAbility,
|
||||
.startServiceExtensionAbilityWithAccount = FFIAbilityContextStartServiceExtensionAbilityWithAccount,
|
||||
.stopServiceExtensionAbility = FFIAbilityContextStopServiceExtensionAbility,
|
||||
.stopServiceExtensionAbilityWithAccount = FFIAbilityContextStopServiceExtensionAbilityWithAccount,
|
||||
.terminateSelf = FFIAbilityContextTerminateSelf,
|
||||
.terminateSelfWithResult = FFIAbilityContextTerminateSelfWithResult,
|
||||
.isTerminating = FFIAbilityContextIsTerminating,
|
||||
.connectAbility = FFIAbilityContextConnectAbility,
|
||||
.connectAbilityWithAccount = FFIAbilityContextConnectAbilityWithAccount,
|
||||
.disconnectAbility = FFIAbilityContextDisconnectAbility,
|
||||
.startAbilityForResult = FFIAbilityContextStartAbilityForResult,
|
||||
.startAbilityForResultWithOption = FFIAbilityContextStartAbilityForResultWithOption,
|
||||
.startAbilityForResultWithAccount = FFIAbilityContextStartAbilityForResultWithAccount,
|
||||
.startAbilityForResultWithAccountAndOption = FFIAbilityContextStartAbilityForResultWithAccountAndOption,
|
||||
.requestPermissionsFromUser = FFIAbilityContextRequestPermissionsFromUser,
|
||||
.setMissionLabel = FFIAbilityContextSetMissionLabel,
|
||||
.setMissionIcon = FFIAbilityContextSetMissionIcon };
|
||||
return &contextFuncs;
|
||||
}
|
||||
|
||||
EXPORT void *FFIGetContext(int64_t id)
|
||||
{
|
||||
if (auto cjContext = FFIData::GetData<CJAbilityContext>(id)) {
|
||||
return cjContext->GetAbilityContext().get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
typedef struct napi_env__ *napi_env;
|
||||
typedef struct napi_value__* napi_value;
|
||||
|
||||
EXPORT napi_value FFICreateNapiValue(void *env, void *context)
|
||||
{
|
||||
napi_value result = nullptr;
|
||||
napi_create_object((napi_env)env, &result);
|
||||
if (result == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "FFICreateNapiValue create object failed.");
|
||||
return nullptr;
|
||||
}
|
||||
auto nativeFinalize = [](napi_env env, void* data, void* hint) {
|
||||
auto tmp = reinterpret_cast<std::weak_ptr<Context> *>(data);
|
||||
delete tmp;
|
||||
};
|
||||
auto tmpContext = reinterpret_cast<AbilityContext*>(context);
|
||||
auto weakContext = new std::weak_ptr<Context>(tmpContext->weak_from_this());
|
||||
napi_wrap((napi_env)env, result, weakContext, nativeFinalize, nullptr, nullptr);
|
||||
napi_value value = nullptr;
|
||||
napi_get_boolean((napi_env)env, true, &value);
|
||||
napi_set_named_property((napi_env)env, result, "stageMode", value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#undef EXPORT
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "ability_runtime/cj_ability_ffi.h"
|
||||
|
||||
#include "ability_runtime/cj_ui_ability.h"
|
||||
#include "ability_runtime/cj_ability_context.h"
|
||||
#include "cj_common_ffi.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
extern "C" {
|
||||
int64_t FFIAbilityGetAbilityContext(AbilityHandle abilityHandle)
|
||||
{
|
||||
if (abilityHandle == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "ability handle is null");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto ability = static_cast<CJUIAbility*>(abilityHandle);
|
||||
auto context = ability->GetAbilityContext();
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "GetAbilityContext failed, abilityContext is null");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto cjContext = FFI::FFIData::Create<CJAbilityContext>(context);
|
||||
return cjContext->GetID();
|
||||
}
|
||||
|
||||
void FFIAbilityContextGetFilesDir(int64_t id, void(*accept)(const char*))
|
||||
{
|
||||
auto cjContext = FFI::FFIData::GetData<CJAbilityContext>(id);
|
||||
if (cjContext == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "cj abilityContext is null");
|
||||
return;
|
||||
}
|
||||
auto context = cjContext->GetAbilityContext();
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "context is null");
|
||||
return;
|
||||
}
|
||||
auto filesDir = context->GetFilesDir();
|
||||
accept(filesDir.c_str());
|
||||
}
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -15,8 +15,10 @@
|
||||
|
||||
#include "ability_runtime/cj_ability_object.h"
|
||||
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
using namespace OHOS::AbilityRuntime;
|
||||
|
||||
@ -31,20 +33,20 @@ CJAbilityFuncs* g_cjAbilityFuncs = nullptr;
|
||||
|
||||
void RegisterCJAbilityFuncs(void (*registerFunc)(CJAbilityFuncs*))
|
||||
{
|
||||
HILOG_INFO("RegisterCJAbilityFuncs start.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "RegisterCJAbilityFuncs start.");
|
||||
if (g_cjAbilityFuncs != nullptr) {
|
||||
HILOG_ERROR("Repeated registration for cj functions of CJAbility.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "Repeated registration for cj functions of CJAbility.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (registerFunc == nullptr) {
|
||||
HILOG_ERROR("RegisterCJAbilityFuncs failed, registerFunc is nullptr.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "RegisterCJAbilityFuncs failed, registerFunc is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
g_cjAbilityFuncs = new CJAbilityFuncs();
|
||||
registerFunc(g_cjAbilityFuncs);
|
||||
HILOG_INFO("RegisterCJAbilityFuncs end.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "RegisterCJAbilityFuncs end.");
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
@ -52,12 +54,12 @@ namespace AbilityRuntime {
|
||||
std::shared_ptr<CJAbilityObject> CJAbilityObject::LoadModule(const std::string& name)
|
||||
{
|
||||
if (g_cjAbilityFuncs == nullptr) {
|
||||
HILOG_ERROR("CJ functions for CJAbility are not registered");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJ functions for CJAbility are not registered");
|
||||
return nullptr;
|
||||
}
|
||||
auto id = g_cjAbilityFuncs->cjAbilityCreate(name.c_str());
|
||||
if (id == 0) {
|
||||
HILOG_ERROR(
|
||||
TAG_LOGE(AAFwkTag::UIABILITY,
|
||||
"Failed to invoke CJAbilityObject::LoadModule. Ability: %{public}s is not registered.", name.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
@ -75,7 +77,7 @@ CJAbilityObject::~CJAbilityObject()
|
||||
void CJAbilityObject::OnStart(const AAFwk::Want& want, const AAFwk::LaunchParam& launchParam) const
|
||||
{
|
||||
if (g_cjAbilityFuncs == nullptr) {
|
||||
HILOG_ERROR("CJ functions for CJAbility are not registered");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJ functions for CJAbility are not registered");
|
||||
return;
|
||||
}
|
||||
WantHandle wantHandle = const_cast<AAFwk::Want*>(&want);
|
||||
@ -88,7 +90,7 @@ void CJAbilityObject::OnStart(const AAFwk::Want& want, const AAFwk::LaunchParam&
|
||||
void CJAbilityObject::OnStop() const
|
||||
{
|
||||
if (g_cjAbilityFuncs == nullptr) {
|
||||
HILOG_ERROR("CJ functions for CJAbility are not registered");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJ functions for CJAbility are not registered");
|
||||
return;
|
||||
}
|
||||
g_cjAbilityFuncs->cjAbilityOnStop(id_);
|
||||
@ -97,7 +99,7 @@ void CJAbilityObject::OnStop() const
|
||||
void CJAbilityObject::OnSceneCreated(OHOS::Rosen::CJWindowStageImpl* cjWindowStage) const
|
||||
{
|
||||
if (g_cjAbilityFuncs == nullptr) {
|
||||
HILOG_ERROR("CJ functions for CJAbility are not registered");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJ functions for CJAbility are not registered");
|
||||
return;
|
||||
}
|
||||
WindowStagePtr windowStage = reinterpret_cast<WindowStagePtr>(cjWindowStage);
|
||||
@ -107,7 +109,7 @@ void CJAbilityObject::OnSceneCreated(OHOS::Rosen::CJWindowStageImpl* cjWindowSta
|
||||
void CJAbilityObject::OnSceneRestored(OHOS::Rosen::CJWindowStageImpl* cjWindowStage) const
|
||||
{
|
||||
if (g_cjAbilityFuncs == nullptr) {
|
||||
HILOG_ERROR("CJ functions for CJAbility are not registered");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJ functions for CJAbility are not registered");
|
||||
return;
|
||||
}
|
||||
WindowStagePtr windowStage = reinterpret_cast<WindowStagePtr>(cjWindowStage);
|
||||
@ -117,7 +119,7 @@ void CJAbilityObject::OnSceneRestored(OHOS::Rosen::CJWindowStageImpl* cjWindowSt
|
||||
void CJAbilityObject::OnSceneDestroyed() const
|
||||
{
|
||||
if (g_cjAbilityFuncs == nullptr) {
|
||||
HILOG_ERROR("CJ functions for CJAbility are not registered");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJ functions for CJAbility are not registered");
|
||||
return;
|
||||
}
|
||||
g_cjAbilityFuncs->cjAbilityOnSceneDestroyed(id_);
|
||||
@ -126,7 +128,7 @@ void CJAbilityObject::OnSceneDestroyed() const
|
||||
void CJAbilityObject::OnForeground(const Want& want) const
|
||||
{
|
||||
if (g_cjAbilityFuncs == nullptr) {
|
||||
HILOG_ERROR("CJ functions for CJAbility are not registered");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJ functions for CJAbility are not registered");
|
||||
return;
|
||||
}
|
||||
WantHandle wantHandle = const_cast<AAFwk::Want*>(&want);
|
||||
@ -136,7 +138,7 @@ void CJAbilityObject::OnForeground(const Want& want) const
|
||||
void CJAbilityObject::OnBackground() const
|
||||
{
|
||||
if (g_cjAbilityFuncs == nullptr) {
|
||||
HILOG_ERROR("CJ functions for CJAbility are not registered");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJ functions for CJAbility are not registered");
|
||||
return;
|
||||
}
|
||||
g_cjAbilityFuncs->cjAbilityOnBackground(id_);
|
||||
@ -145,7 +147,7 @@ void CJAbilityObject::OnBackground() const
|
||||
void CJAbilityObject::OnConfigurationUpdated(const std::shared_ptr<AppExecFwk::Configuration>& configuration) const
|
||||
{
|
||||
if (g_cjAbilityFuncs == nullptr) {
|
||||
HILOG_ERROR("CJ functions for CJAbility are not registered");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJ functions for CJAbility are not registered");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -153,7 +155,7 @@ void CJAbilityObject::OnConfigurationUpdated(const std::shared_ptr<AppExecFwk::C
|
||||
void CJAbilityObject::OnNewWant(const AAFwk::Want& want, const AAFwk::LaunchParam& launchParam) const
|
||||
{
|
||||
if (g_cjAbilityFuncs == nullptr) {
|
||||
HILOG_ERROR("CJ functions for CJAbility are not registered");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJ functions for CJAbility are not registered");
|
||||
return;
|
||||
}
|
||||
WantHandle wantHandle = const_cast<AAFwk::Want*>(&want);
|
||||
@ -166,14 +168,14 @@ void CJAbilityObject::OnNewWant(const AAFwk::Want& want, const AAFwk::LaunchPara
|
||||
void CJAbilityObject::Dump(const std::vector<std::string>& params, std::vector<std::string>& info) const
|
||||
{
|
||||
if (g_cjAbilityFuncs == nullptr) {
|
||||
HILOG_ERROR("CJ functions for CJAbility are not registered");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJ functions for CJAbility are not registered");
|
||||
return;
|
||||
}
|
||||
|
||||
VectorStringHandle paramHandle = const_cast<std::vector<std::string>*>(¶ms);
|
||||
VectorStringHandle cjInfo = g_cjAbilityFuncs->cjAbilityDump(id_, paramHandle);
|
||||
if (cjInfo == nullptr) {
|
||||
HILOG_ERROR("CJ info nullptr");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJ info nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -189,7 +191,7 @@ void CJAbilityObject::Dump(const std::vector<std::string>& params, std::vector<s
|
||||
int32_t CJAbilityObject::OnContinue(AAFwk::WantParams& wantParams) const
|
||||
{
|
||||
if (g_cjAbilityFuncs == nullptr) {
|
||||
HILOG_ERROR("CJ functions for CJAbility are not registered");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJ functions for CJAbility are not registered");
|
||||
return ContinuationManager::OnContinueResult::REJECT;
|
||||
}
|
||||
return 0;
|
||||
@ -198,7 +200,7 @@ int32_t CJAbilityObject::OnContinue(AAFwk::WantParams& wantParams) const
|
||||
void CJAbilityObject::Init(AbilityHandle ability) const
|
||||
{
|
||||
if (g_cjAbilityFuncs == nullptr) {
|
||||
HILOG_ERROR("CJ functions for CJAbility are not registered");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJ functions for CJAbility are not registered");
|
||||
return;
|
||||
}
|
||||
g_cjAbilityFuncs->cjAbilityInit(id_, ability);
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "context/application_context.h"
|
||||
#include "connection_manager.h"
|
||||
#include "context/context.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
@ -34,6 +35,7 @@
|
||||
#include "insight_intent_execute_param.h"
|
||||
#include "cj_runtime.h"
|
||||
#include "cj_ability_object.h"
|
||||
#include "cj_ability_context.h"
|
||||
#include "time_util.h"
|
||||
#include "scene_board_judgement.h"
|
||||
#include "string_wrapper.h"
|
||||
@ -58,12 +60,12 @@ UIAbility *CJUIAbility::Create(const std::unique_ptr<Runtime> &runtime)
|
||||
|
||||
CJUIAbility::CJUIAbility(CJRuntime &cjRuntime) : cjRuntime_(cjRuntime)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Called.");
|
||||
}
|
||||
|
||||
CJUIAbility::~CJUIAbility()
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Called.");
|
||||
if (abilityContext_ != nullptr) {
|
||||
abilityContext_->Unbind();
|
||||
}
|
||||
@ -75,12 +77,12 @@ void CJUIAbility::Init(std::shared_ptr<AppExecFwk::AbilityLocalRecord> record,
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
if (record == nullptr) {
|
||||
HILOG_ERROR("AbilityLocalRecord is nullptr.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "AbilityLocalRecord is nullptr.");
|
||||
return;
|
||||
}
|
||||
auto abilityInfo = record->GetAbilityInfo();
|
||||
if (abilityInfo == nullptr) {
|
||||
HILOG_ERROR("AbilityInfo is nullptr.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "AbilityInfo is nullptr.");
|
||||
return;
|
||||
}
|
||||
UIAbility::Init(record, application, handler, token);
|
||||
@ -98,13 +100,12 @@ void CJUIAbility::SetAbilityContext(
|
||||
const std::shared_ptr<AbilityInfo> &abilityInfo)
|
||||
{
|
||||
if (!abilityInfo) {
|
||||
HILOG_ERROR("abilityInfo is nullptr");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "abilityInfo is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
cjAbilityObj_ = CJAbilityObject::LoadModule(abilityInfo->name);
|
||||
if (!cjAbilityObj_) {
|
||||
HILOG_ERROR("Failed to get CJAbility object.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "Failed to get CJAbility object.");
|
||||
return;
|
||||
}
|
||||
cjAbilityObj_->Init(this);
|
||||
@ -113,11 +114,11 @@ void CJUIAbility::SetAbilityContext(
|
||||
void CJUIAbility::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_INFO("Begin ability is %{public}s.", GetAbilityName().c_str());
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Begin ability is %{public}s.", GetAbilityName().c_str());
|
||||
UIAbility::OnStart(want, sessionInfo);
|
||||
|
||||
if (!cjAbilityObj_) {
|
||||
HILOG_ERROR("CJAbility is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJAbility is not loaded.");
|
||||
return;
|
||||
}
|
||||
std::string methodName = "OnStart";
|
||||
@ -127,10 +128,10 @@ void CJUIAbility::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo
|
||||
|
||||
auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (delegator) {
|
||||
HILOG_DEBUG("Call PostPerformStart.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Call PostPerformStart.");
|
||||
delegator->PostPerformStart(CreateADelegatorAbilityProperty());
|
||||
}
|
||||
HILOG_INFO("End ability is %{public}s.", GetAbilityName().c_str());
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "End ability is %{public}s.", GetAbilityName().c_str());
|
||||
}
|
||||
|
||||
void CJUIAbility::AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState state, const std::string &methodName) const
|
||||
@ -151,26 +152,26 @@ void CJUIAbility::AddLifecycleEventAfterCall(FreezeUtil::TimeoutState state, con
|
||||
|
||||
int32_t CJUIAbility::OnShare(WantParams &wantParams)
|
||||
{
|
||||
HILOG_DEBUG("Begin.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Begin.");
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void CJUIAbility::OnStop()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("Begin.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Begin.");
|
||||
if (abilityContext_) {
|
||||
HILOG_DEBUG("Set terminating true.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Set terminating true.");
|
||||
abilityContext_->SetTerminating(true);
|
||||
}
|
||||
UIAbility::OnStop();
|
||||
if (!cjAbilityObj_) {
|
||||
HILOG_ERROR("CJAbility is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJAbility is not loaded.");
|
||||
return;
|
||||
}
|
||||
cjAbilityObj_->OnStop();
|
||||
CJUIAbility::OnStopCallback();
|
||||
HILOG_DEBUG("End.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "End.");
|
||||
}
|
||||
|
||||
void CJUIAbility::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, bool &isAsyncCallback)
|
||||
@ -182,49 +183,48 @@ void CJUIAbility::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callbackI
|
||||
}
|
||||
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("Begin");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Begin");
|
||||
if (abilityContext_) {
|
||||
HILOG_DEBUG("Set terminating true.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Set terminating true.");
|
||||
abilityContext_->SetTerminating(true);
|
||||
}
|
||||
|
||||
UIAbility::OnStop();
|
||||
cjAbilityObj_->OnStop();
|
||||
OnStopCallback();
|
||||
HILOG_DEBUG("End.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "End.");
|
||||
}
|
||||
|
||||
void CJUIAbility::OnStopCallback()
|
||||
{
|
||||
auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (delegator) {
|
||||
HILOG_DEBUG("Call PostPerformStop.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Call PostPerformStop.");
|
||||
delegator->PostPerformStop(CreateADelegatorAbilityProperty());
|
||||
}
|
||||
|
||||
bool ret = ConnectionManager::GetInstance().DisconnectCaller(AbilityContext::token_);
|
||||
if (!ret) {
|
||||
HILOG_ERROR("The service connection is disconnected.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "The service connection is disconnected.");
|
||||
}
|
||||
ConnectionManager::GetInstance().ReportConnectionLeakEvent(getpid(), gettid());
|
||||
HILOG_DEBUG("The service connection is not disconnected.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "The service connection is not disconnected.");
|
||||
}
|
||||
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
void CJUIAbility::OnSceneCreated()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("Begin ability is %{public}s.", GetAbilityName().c_str());
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Begin ability is %{public}s.", GetAbilityName().c_str());
|
||||
UIAbility::OnSceneCreated();
|
||||
|
||||
if (!cjAbilityObj_) {
|
||||
HILOG_ERROR("CJAbility is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJAbility is not loaded.");
|
||||
return;
|
||||
}
|
||||
|
||||
cjWindowStage_ = OHOS::Rosen::CJWindowStageImpl::CreateCJWindowStage(GetScene());
|
||||
if (!cjWindowStage_) {
|
||||
HILOG_ERROR("Failed to create CJWindowStage object.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "Failed to create CJWindowStage object.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -238,47 +238,46 @@ void CJUIAbility::OnSceneCreated()
|
||||
|
||||
auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (delegator) {
|
||||
HILOG_DEBUG("Call PostPerformScenceCreated.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Call PostPerformScenceCreated.");
|
||||
delegator->PostPerformScenceCreated(CreateADelegatorAbilityProperty());
|
||||
}
|
||||
|
||||
HILOG_DEBUG("End ability is %{public}s.", GetAbilityName().c_str());
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "End ability is %{public}s.", GetAbilityName().c_str());
|
||||
}
|
||||
|
||||
void CJUIAbility::OnSceneRestored()
|
||||
{
|
||||
UIAbility::OnSceneRestored();
|
||||
HILOG_DEBUG("called.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "called.");
|
||||
|
||||
if (!cjAbilityObj_) {
|
||||
HILOG_ERROR("CJAbility is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJAbility is not loaded.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cjWindowStage_) {
|
||||
cjWindowStage_ = OHOS::Rosen::CJWindowStageImpl::CreateCJWindowStage(scene_);
|
||||
if (!cjWindowStage_) {
|
||||
HILOG_ERROR("Failed to create CJWindowStage object.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "Failed to create CJWindowStage object.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
cjAbilityObj_->OnSceneRestored(cjWindowStage_.get());
|
||||
|
||||
auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (delegator) {
|
||||
HILOG_DEBUG("Call PostPerformScenceRestored.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Call PostPerformScenceRestored.");
|
||||
delegator->PostPerformScenceRestored(CreateADelegatorAbilityProperty());
|
||||
}
|
||||
}
|
||||
|
||||
void CJUIAbility::OnSceneDestroyed()
|
||||
{
|
||||
HILOG_DEBUG("Begin ability is %{public}s.", GetAbilityName().c_str());
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Begin ability is %{public}s.", GetAbilityName().c_str());
|
||||
UIAbility::onSceneDestroyed();
|
||||
|
||||
if (!cjAbilityObj_) {
|
||||
HILOG_ERROR("CJAbility is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJAbility is not loaded.");
|
||||
return;
|
||||
}
|
||||
cjAbilityObj_->OnSceneDestroyed();
|
||||
@ -286,23 +285,23 @@ void CJUIAbility::OnSceneDestroyed()
|
||||
if (scene_ != nullptr) {
|
||||
auto window = scene_->GetMainWindow();
|
||||
if (window != nullptr) {
|
||||
HILOG_DEBUG("Call window UnregisterDisplayMoveListener.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Call window UnregisterDisplayMoveListener.");
|
||||
window->UnregisterDisplayMoveListener(abilityDisplayMoveListener_);
|
||||
}
|
||||
}
|
||||
|
||||
auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (delegator) {
|
||||
HILOG_DEBUG("Call delegator PostPerformScenceDestroyed.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Call delegator PostPerformScenceDestroyed.");
|
||||
delegator->PostPerformScenceDestroyed(CreateADelegatorAbilityProperty());
|
||||
}
|
||||
HILOG_DEBUG("End ability is %{public}s.", GetAbilityName().c_str());
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "End ability is %{public}s.", GetAbilityName().c_str());
|
||||
}
|
||||
|
||||
void CJUIAbility::OnForeground(const Want &want)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("Begin ability is %{public}s.", GetAbilityName().c_str());
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Begin ability is %{public}s.", GetAbilityName().c_str());
|
||||
|
||||
UIAbility::OnForeground(want);
|
||||
CallOnForegroundFunc(want);
|
||||
@ -311,7 +310,7 @@ void CJUIAbility::OnForeground(const Want &want)
|
||||
void CJUIAbility::CallOnForegroundFunc(const Want &want)
|
||||
{
|
||||
if (!cjAbilityObj_) {
|
||||
HILOG_ERROR("CJAbility is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJAbility is not loaded.");
|
||||
return;
|
||||
}
|
||||
std::string methodName = "OnForeground";
|
||||
@ -321,22 +320,22 @@ void CJUIAbility::CallOnForegroundFunc(const Want &want)
|
||||
|
||||
auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (delegator) {
|
||||
HILOG_DEBUG("Call PostPerformForeground.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Call PostPerformForeground.");
|
||||
delegator->PostPerformForeground(CreateADelegatorAbilityProperty());
|
||||
}
|
||||
|
||||
HILOG_DEBUG("End ability is %{public}s.", GetAbilityName().c_str());
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "End ability is %{public}s.", GetAbilityName().c_str());
|
||||
}
|
||||
|
||||
void CJUIAbility::OnBackground()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("Begin ability is %{public}s.", GetAbilityName().c_str());
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Begin ability is %{public}s.", GetAbilityName().c_str());
|
||||
|
||||
UIAbility::OnBackground();
|
||||
|
||||
if (!cjAbilityObj_) {
|
||||
HILOG_ERROR("CJAbility is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJAbility is not loaded.");
|
||||
return;
|
||||
}
|
||||
std::string methodName = "OnBackground";
|
||||
@ -346,17 +345,17 @@ void CJUIAbility::OnBackground()
|
||||
|
||||
auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (delegator) {
|
||||
HILOG_DEBUG("Call PostPerformBackground.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Call PostPerformBackground.");
|
||||
delegator->PostPerformBackground(CreateADelegatorAbilityProperty());
|
||||
}
|
||||
|
||||
HILOG_DEBUG("End ability is %{public}s.", GetAbilityName().c_str());
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "End ability is %{public}s.", GetAbilityName().c_str());
|
||||
}
|
||||
|
||||
bool CJUIAbility::OnBackPress()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("Begin ability: %{public}s.", GetAbilityName().c_str());
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Begin ability: %{public}s.", GetAbilityName().c_str());
|
||||
UIAbility::OnBackPress();
|
||||
return true;
|
||||
}
|
||||
@ -364,7 +363,7 @@ bool CJUIAbility::OnBackPress()
|
||||
bool CJUIAbility::OnPrepareTerminate()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("Begin ability: %{public}s.", GetAbilityName().c_str());
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Begin ability: %{public}s.", GetAbilityName().c_str());
|
||||
UIAbility::OnPrepareTerminate();
|
||||
|
||||
return true;
|
||||
@ -395,7 +394,7 @@ void CJUIAbility::AbilityContinuationOrRecover(const Want &want)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
// multi-instance ability continuation
|
||||
HILOG_DEBUG("Launch reason is %{public}d.", launchParam_.launchReason);
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Launch reason is %{public}d.", launchParam_.launchReason);
|
||||
if (IsRestoredInContinuation()) {
|
||||
RestorePageStack(want);
|
||||
OnSceneRestored();
|
||||
@ -413,7 +412,7 @@ void CJUIAbility::DoOnForeground(const Want &want)
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
if (scene_ == nullptr) {
|
||||
if ((abilityContext_ == nullptr) || (sceneListener_ == nullptr)) {
|
||||
HILOG_ERROR("AbilityContext or sceneListener_ is nullptr .");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "AbilityContext or sceneListener_ is nullptr .");
|
||||
return;
|
||||
}
|
||||
scene_ = std::make_shared<Rosen::WindowScene>();
|
||||
@ -421,32 +420,32 @@ void CJUIAbility::DoOnForeground(const Want &want)
|
||||
} else {
|
||||
auto window = scene_->GetMainWindow();
|
||||
if (window == nullptr) {
|
||||
HILOG_ERROR("MainWindow is nullptr .");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "MainWindow is nullptr .");
|
||||
return;
|
||||
}
|
||||
if (want.HasParameter(Want::PARAM_RESV_WINDOW_MODE)) {
|
||||
HILOG_ERROR("want has parameter PARAM_RESV_WINDOW_MODE.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "want has parameter PARAM_RESV_WINDOW_MODE.");
|
||||
auto windowMode = want.GetIntParam(
|
||||
Want::PARAM_RESV_WINDOW_MODE, AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED);
|
||||
window->SetWindowMode(static_cast<Rosen::WindowMode>(windowMode));
|
||||
windowMode_ = windowMode;
|
||||
HILOG_DEBUG("Set window mode is %{public}d .", windowMode);
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Set window mode is %{public}d .", windowMode);
|
||||
}
|
||||
}
|
||||
|
||||
auto window = scene_->GetMainWindow();
|
||||
if (window == nullptr) {
|
||||
HILOG_ERROR("MainWindow is nullptr .");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "MainWindow is nullptr .");
|
||||
return;
|
||||
}
|
||||
if (securityFlag_) {
|
||||
window->SetSystemPrivacyMode(true);
|
||||
}
|
||||
|
||||
HILOG_INFO("Move scene to foreground, sceneFlag_: %{public}d .", UIAbility::sceneFlag_);
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Move scene to foreground, sceneFlag_: %{public}d .", UIAbility::sceneFlag_);
|
||||
AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState::FOREGROUND, METHOD_NAME);
|
||||
scene_->GoForeground(UIAbility::sceneFlag_);
|
||||
HILOG_DEBUG("End.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "End.");
|
||||
}
|
||||
|
||||
void CJUIAbility::InitSceneDoOnForeground(std::shared_ptr<Rosen::WindowScene> scene, const Want &want)
|
||||
@ -459,9 +458,9 @@ void CJUIAbility::InitSceneDoOnForeground(std::shared_ptr<Rosen::WindowScene> sc
|
||||
bool flag = std::regex_match(strDisplayId, sm, formatRegex);
|
||||
if (flag && !strDisplayId.empty()) {
|
||||
displayId = strtol(strDisplayId.c_str(), nullptr, BASE_DISPLAY_ID_NUM);
|
||||
HILOG_DEBUG("Success displayId is %{public}d .", displayId);
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Success displayId is %{public}d .", displayId);
|
||||
} else {
|
||||
HILOG_ERROR("Failed to formatRegex: [%{public}s] .", strDisplayId.c_str());
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "Failed to formatRegex: [%{public}s] .", strDisplayId.c_str());
|
||||
}
|
||||
}
|
||||
Rosen::WMError ret = Rosen::WMError::WM_OK;
|
||||
@ -474,17 +473,18 @@ void CJUIAbility::InitSceneDoOnForeground(std::shared_ptr<Rosen::WindowScene> sc
|
||||
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option);
|
||||
}
|
||||
if (ret != Rosen::WMError::WM_OK) {
|
||||
HILOG_ERROR("Failed to init window scene .");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "Failed to init window scene .");
|
||||
return;
|
||||
}
|
||||
|
||||
AbilityContinuationOrRecover(want);
|
||||
auto window = scene_->GetMainWindow();
|
||||
if (window) {
|
||||
HILOG_DEBUG("Call RegisterDisplayMoveListener, windowId: %{public}d .", window->GetWindowId());
|
||||
TAG_LOGD(AAFwkTag::UIABILITY,
|
||||
"Call RegisterDisplayMoveListener, windowId: %{public}d .", window->GetWindowId());
|
||||
abilityDisplayMoveListener_ = new AbilityDisplayMoveListener(weak_from_this());
|
||||
if (abilityDisplayMoveListener_ == nullptr) {
|
||||
HILOG_ERROR("abilityDisplayMoveListener_ is nullptr .");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "abilityDisplayMoveListener_ is nullptr .");
|
||||
return;
|
||||
}
|
||||
window->RegisterDisplayMoveListener(abilityDisplayMoveListener_);
|
||||
@ -493,9 +493,9 @@ void CJUIAbility::InitSceneDoOnForeground(std::shared_ptr<Rosen::WindowScene> sc
|
||||
|
||||
void CJUIAbility::RequestFocus(const Want &want)
|
||||
{
|
||||
HILOG_INFO("Lifecycle: begin .");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Lifecycle: begin .");
|
||||
if (scene_ == nullptr) {
|
||||
HILOG_ERROR("scene_ is nullptr .");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "scene_ is nullptr .");
|
||||
return;
|
||||
}
|
||||
auto window = scene_->GetMainWindow();
|
||||
@ -503,18 +503,18 @@ void CJUIAbility::RequestFocus(const Want &want)
|
||||
auto windowMode = want.GetIntParam(
|
||||
Want::PARAM_RESV_WINDOW_MODE, AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED);
|
||||
window->SetWindowMode(static_cast<Rosen::WindowMode>(windowMode));
|
||||
HILOG_DEBUG("Set window mode is %{public}d .", windowMode);
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Set window mode is %{public}d .", windowMode);
|
||||
}
|
||||
AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState::FOREGROUND, METHOD_NAME);
|
||||
scene_->GoForeground(UIAbility::sceneFlag_);
|
||||
HILOG_INFO("Lifecycle: end .");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Lifecycle: end .");
|
||||
}
|
||||
|
||||
void CJUIAbility::ContinuationRestore(const Want &want)
|
||||
{
|
||||
HILOG_DEBUG("Called .");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Called .");
|
||||
if (!IsRestoredInContinuation() || scene_ == nullptr) {
|
||||
HILOG_ERROR("Is not in continuation or scene_ is nullptr .");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "Is not in continuation or scene_ is nullptr .");
|
||||
return;
|
||||
}
|
||||
RestorePageStack(want);
|
||||
@ -524,9 +524,9 @@ void CJUIAbility::ContinuationRestore(const Want &want)
|
||||
|
||||
std::shared_ptr<Rosen::CJWindowStageImpl> CJUIAbility::GetCJWindowStage()
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Called.");
|
||||
if (cjWindowStage_ == nullptr) {
|
||||
HILOG_ERROR("CJWindowSatge is nullptr .");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJWindowSatge is nullptr .");
|
||||
}
|
||||
return cjWindowStage_;
|
||||
}
|
||||
@ -540,7 +540,7 @@ void CJUIAbility::ExecuteInsightIntentRepeateForeground(const Want &want,
|
||||
const std::shared_ptr<InsightIntentExecuteParam> &executeParam,
|
||||
std::unique_ptr<InsightIntentExecutorAsyncCallback> callback)
|
||||
{
|
||||
HILOG_DEBUG("called .");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "called .");
|
||||
if (executeParam == nullptr) {
|
||||
HILOG_WARN("Intention execute param invalid.");
|
||||
RequestFocus(want);
|
||||
@ -549,10 +549,10 @@ void CJUIAbility::ExecuteInsightIntentRepeateForeground(const Want &want,
|
||||
}
|
||||
|
||||
auto asyncCallback = [weak = weak_from_this(), want](InsightIntentExecuteResult result) {
|
||||
HILOG_DEBUG("Begin request focus .");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Begin request focus .");
|
||||
auto ability = weak.lock();
|
||||
if (ability == nullptr) {
|
||||
HILOG_ERROR("ability is nullptr .");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "ability is nullptr .");
|
||||
return;
|
||||
}
|
||||
ability->RequestFocus(want);
|
||||
@ -562,7 +562,7 @@ void CJUIAbility::ExecuteInsightIntentRepeateForeground(const Want &want,
|
||||
InsightIntentExecutorInfo executeInfo;
|
||||
auto ret = GetInsightIntentExecutorInfo(want, executeParam, executeInfo);
|
||||
if (!ret) {
|
||||
HILOG_ERROR("Get Intention executor failed.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "Get Intention executor failed.");
|
||||
InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback),
|
||||
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
|
||||
return;
|
||||
@ -573,7 +573,7 @@ void CJUIAbility::ExecuteInsightIntentMoveToForeground(const Want &want,
|
||||
const std::shared_ptr<InsightIntentExecuteParam> &executeParam,
|
||||
std::unique_ptr<InsightIntentExecutorAsyncCallback> callback)
|
||||
{
|
||||
HILOG_DEBUG("called.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "called.");
|
||||
if (executeParam == nullptr) {
|
||||
HILOG_WARN("Intention execute param invalid.");
|
||||
OnForeground(want);
|
||||
@ -584,10 +584,10 @@ void CJUIAbility::ExecuteInsightIntentMoveToForeground(const Want &want,
|
||||
UIAbility::OnForeground(want);
|
||||
|
||||
auto asyncCallback = [weak = weak_from_this(), want](InsightIntentExecuteResult result) {
|
||||
HILOG_DEBUG("Begin call onForeground.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Begin call onForeground.");
|
||||
auto ability = weak.lock();
|
||||
if (ability == nullptr) {
|
||||
HILOG_ERROR("ability is nullptr.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "ability is nullptr.");
|
||||
return;
|
||||
}
|
||||
ability->CallOnForegroundFunc(want);
|
||||
@ -597,7 +597,7 @@ void CJUIAbility::ExecuteInsightIntentMoveToForeground(const Want &want,
|
||||
InsightIntentExecutorInfo executeInfo;
|
||||
auto ret = GetInsightIntentExecutorInfo(want, executeParam, executeInfo);
|
||||
if (!ret) {
|
||||
HILOG_ERROR("Get Intention executor failed.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "Get Intention executor failed.");
|
||||
InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback),
|
||||
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
|
||||
return;
|
||||
@ -608,10 +608,10 @@ bool CJUIAbility::GetInsightIntentExecutorInfo(const Want &want,
|
||||
const std::shared_ptr<InsightIntentExecuteParam> &executeParam,
|
||||
InsightIntentExecutorInfo& executeInfo)
|
||||
{
|
||||
HILOG_DEBUG("called.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "called.");
|
||||
auto context = GetAbilityContext();
|
||||
if (executeParam == nullptr || context == nullptr || abilityInfo_ == nullptr || cjWindowStage_ == nullptr) {
|
||||
HILOG_ERROR("Param invalid.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "Param invalid.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -629,11 +629,11 @@ bool CJUIAbility::GetInsightIntentExecutorInfo(const Want &want,
|
||||
int32_t CJUIAbility::OnContinue(WantParams &wantParams)
|
||||
{
|
||||
if (!cjAbilityObj_) {
|
||||
HILOG_ERROR("CJAbility is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJAbility is not loaded.");
|
||||
return AppExecFwk::ContinuationManagerStage::OnContinueResult::REJECT;
|
||||
}
|
||||
auto res = cjAbilityObj_->OnContinue(wantParams);
|
||||
HILOG_INFO("CJAbility::OnContinue end, return value is %{public}d", res);
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "CJAbility::OnContinue end, return value is %{public}d", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -646,36 +646,36 @@ int32_t CJUIAbility::OnSaveState(int32_t reason, WantParams &wantParams)
|
||||
void CJUIAbility::OnConfigurationUpdated(const Configuration &configuration)
|
||||
{
|
||||
UIAbility::OnConfigurationUpdated(configuration);
|
||||
HILOG_DEBUG("Called.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Called.");
|
||||
auto fullConfig = GetAbilityContext()->GetConfiguration();
|
||||
if (!fullConfig) {
|
||||
HILOG_ERROR("configuration is nullptr.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "configuration is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cjAbilityObj_) {
|
||||
HILOG_ERROR("CJAbility is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJAbility is not loaded.");
|
||||
return;
|
||||
}
|
||||
|
||||
cjAbilityObj_->OnConfigurationUpdated(fullConfig);
|
||||
HILOG_INFO("CJAbility::OnConfigurationUpdated end");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "CJAbility::OnConfigurationUpdated end");
|
||||
}
|
||||
|
||||
void CJUIAbility::OnMemoryLevel(int level)
|
||||
{
|
||||
UIAbility::OnMemoryLevel(level);
|
||||
HILOG_DEBUG("Called.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Called.");
|
||||
}
|
||||
|
||||
void CJUIAbility::UpdateContextConfiguration()
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Called.");
|
||||
}
|
||||
|
||||
void CJUIAbility::OnNewWant(const Want &want)
|
||||
{
|
||||
HILOG_DEBUG("Begin.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Begin.");
|
||||
UIAbility::OnNewWant(want);
|
||||
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
@ -684,7 +684,7 @@ void CJUIAbility::OnNewWant(const Want &want)
|
||||
}
|
||||
#endif
|
||||
if (!cjAbilityObj_) {
|
||||
HILOG_ERROR("CJAbility is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJAbility is not loaded.");
|
||||
return;
|
||||
}
|
||||
std::string methodName = "OnNewWant";
|
||||
@ -692,19 +692,19 @@ void CJUIAbility::OnNewWant(const Want &want)
|
||||
cjAbilityObj_->OnNewWant(want, GetLaunchParam());
|
||||
AddLifecycleEventAfterCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
|
||||
HILOG_DEBUG("End.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "End.");
|
||||
}
|
||||
|
||||
void CJUIAbility::OnAbilityResult(int requestCode, int resultCode, const Want &resultData)
|
||||
{
|
||||
HILOG_DEBUG("Begin .");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Begin .");
|
||||
UIAbility::OnAbilityResult(requestCode, resultCode, resultData);
|
||||
if (abilityContext_ == nullptr) {
|
||||
HILOG_ERROR("abilityContext_ is nullptr .");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "abilityContext_ is nullptr .");
|
||||
return;
|
||||
}
|
||||
abilityContext_->OnAbilityResult(requestCode, resultCode, resultData);
|
||||
HILOG_DEBUG("End .");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "End .");
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> CJUIAbility::CallRequest()
|
||||
@ -715,7 +715,7 @@ sptr<IRemoteObject> CJUIAbility::CallRequest()
|
||||
std::shared_ptr<AppExecFwk::ADelegatorAbilityProperty> CJUIAbility::CreateADelegatorAbilityProperty()
|
||||
{
|
||||
if (abilityContext_ == nullptr) {
|
||||
HILOG_ERROR("abilityContext_ is nullptr.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "abilityContext_ is nullptr.");
|
||||
return nullptr;
|
||||
}
|
||||
auto property = std::make_shared<AppExecFwk::ADelegatorAbilityProperty>();
|
||||
@ -739,20 +739,20 @@ std::shared_ptr<AppExecFwk::ADelegatorAbilityProperty> CJUIAbility::CreateADeleg
|
||||
void CJUIAbility::Dump(const std::vector<std::string> ¶ms, std::vector<std::string> &info)
|
||||
{
|
||||
UIAbility::Dump(params, info);
|
||||
HILOG_DEBUG("Called.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Called.");
|
||||
if (!cjAbilityObj_) {
|
||||
HILOG_ERROR("CJAbility is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "CJAbility is not loaded.");
|
||||
return;
|
||||
}
|
||||
cjAbilityObj_->Dump(params, info);
|
||||
HILOG_DEBUG("Dump info size: %{public}zu.", info.size());
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Dump info size: %{public}zu.", info.size());
|
||||
}
|
||||
|
||||
std::shared_ptr<CJAbilityObject> CJUIAbility::GetCJAbility()
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Called.");
|
||||
if (cjAbilityObj_ == nullptr) {
|
||||
HILOG_ERROR("cjAbility object is nullptr.");
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "cjAbility object is nullptr.");
|
||||
}
|
||||
return cjAbilityObj_;
|
||||
}
|
||||
|
@ -83,6 +83,10 @@
|
||||
*ExtensionModuleLoader*;
|
||||
*SysMrgClient*;
|
||||
};
|
||||
extern "C" {
|
||||
Ffi*;
|
||||
FFI*;
|
||||
};
|
||||
local:
|
||||
*;
|
||||
};
|
@ -400,6 +400,7 @@ bool AbilityRecovery::IsSaveAbilityState(StateReason reason)
|
||||
|
||||
case StateReason::CPP_CRASH:
|
||||
case StateReason::JS_ERROR:
|
||||
case StateReason::CJ_ERROR:
|
||||
case StateReason::APP_FREEZE:
|
||||
if ((saveOccasion_ & SaveOccasionFlag::SAVE_WHEN_ERROR) != 0) {
|
||||
ret = true;
|
||||
|
@ -355,6 +355,7 @@ bool AppRecovery::ShouldSaveAppState(StateReason reason)
|
||||
|
||||
case StateReason::CPP_CRASH:
|
||||
case StateReason::JS_ERROR:
|
||||
case StateReason::CJ_ERROR:
|
||||
case StateReason::APP_FREEZE: // appfreeze could not callback to js function safely.
|
||||
if ((saveOccasion_ & SaveOccasionFlag::SAVE_WHEN_ERROR) != 0) {
|
||||
ret = true;
|
||||
@ -394,6 +395,12 @@ bool AppRecovery::ShouldRecoverApp(StateReason reason)
|
||||
}
|
||||
break;
|
||||
|
||||
case StateReason::CJ_ERROR:
|
||||
if (isAlwaysStart || (restartFlag_ & RestartFlag::RESTART_WHEN_CJ_CRASH) != 0) {
|
||||
ret = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case StateReason::APP_FREEZE:
|
||||
if (isAlwaysStart || (restartFlag_ & RestartFlag::RESTART_WHEN_APP_FREEZE) != 0) {
|
||||
ret = true;
|
||||
|
@ -23,7 +23,9 @@
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "js_ui_ability.h"
|
||||
#ifdef CJ_FRONTEND
|
||||
#include "cj_ui_ability.h"
|
||||
#endif
|
||||
#include "ohos_application.h"
|
||||
#include "reverse_continuation_scheduler_primary_stage.h"
|
||||
#include "runtime.h"
|
||||
@ -50,8 +52,10 @@ UIAbility *UIAbility::Create(const std::unique_ptr<Runtime> &runtime)
|
||||
switch (runtime->GetLanguage()) {
|
||||
case Runtime::Language::JS:
|
||||
return JsUIAbility::Create(runtime);
|
||||
#ifdef CJ_FRONTEND
|
||||
case Runtime::Language::CJ:
|
||||
return CJUIAbility::Create(runtime);
|
||||
#endif
|
||||
default:
|
||||
return new (std::nothrow) UIAbility();
|
||||
}
|
||||
|
@ -203,6 +203,8 @@ ohos_shared_library("appkit_native") {
|
||||
|
||||
include_dirs +=
|
||||
[ "${ability_runtime_path}/cj_environment/interfaces/inner_api" ]
|
||||
|
||||
deps += [ "${ability_runtime_path}/cj_environment/frameworks/cj_environment:cj_environment" ]
|
||||
}
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
@ -419,14 +421,15 @@ ohos_shared_library("appkit_delegator") {
|
||||
"json:nlohmann_json_static",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
public_external_deps = [ "ability_base:configuration" ]
|
||||
|
||||
if (cj_frontend) {
|
||||
sources += [
|
||||
"${ability_runtime_native_path}/appkit/ability_delegator/runner_runtime/cj_test_runner.cpp",
|
||||
"${ability_runtime_native_path}/appkit/ability_delegator/runner_runtime/cj_test_runner_object.cpp",
|
||||
]
|
||||
}
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [ "icu:shared_icuuc" ]
|
||||
}
|
||||
|
@ -17,7 +17,9 @@
|
||||
#include "bundle_mgr_helper.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#ifdef CJ_FRONTEND
|
||||
#include "runner_runtime/cj_test_runner.h"
|
||||
#endif
|
||||
#include "runner_runtime/js_test_runner.h"
|
||||
#include "runtime.h"
|
||||
#include "sys_mgr_client.h"
|
||||
@ -59,8 +61,10 @@ std::unique_ptr<TestRunner> TestRunner::Create(const std::unique_ptr<AbilityRunt
|
||||
switch (runtime->GetLanguage()) {
|
||||
case AbilityRuntime::Runtime::Language::JS:
|
||||
return RunnerRuntime::JsTestRunner::Create(runtime, args, bundleInfo, isFaJsModel);
|
||||
#ifdef CJ_FRONTEND
|
||||
case AbilityRuntime::Runtime::Language::CJ:
|
||||
return RunnerRuntime::CJTestRunner::Create(runtime, args, bundleInfo);
|
||||
#endif
|
||||
default:
|
||||
return std::make_unique<TestRunner>();
|
||||
}
|
||||
|
@ -19,7 +19,9 @@
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hitrace_meter.h"
|
||||
#ifdef CJ_FRONTEND
|
||||
#include "cj_ability_stage.h"
|
||||
#endif
|
||||
#include "js_ability_stage.h"
|
||||
#include "runtime.h"
|
||||
|
||||
@ -36,8 +38,10 @@ std::shared_ptr<AbilityStage> AbilityStage::Create(
|
||||
switch (runtime->GetLanguage()) {
|
||||
case Runtime::Language::JS:
|
||||
return JsAbilityStage::Create(runtime, hapModuleInfo);
|
||||
#ifdef CJ_FRONTEND
|
||||
case Runtime::Language::CJ:
|
||||
return CJAbilityStage::Create(runtime, hapModuleInfo);
|
||||
#endif
|
||||
default:
|
||||
return std::make_shared<AbilityStage>();
|
||||
}
|
||||
|
@ -50,6 +50,19 @@ bool ApplicationDataManager::NotifyUnhandledException(const std::string &errMsg)
|
||||
return AppRecovery::GetInstance().TryRecoverApp(StateReason::JS_ERROR);
|
||||
}
|
||||
|
||||
bool ApplicationDataManager::NotifyCJUnhandledException(const std::string &errMsg)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "Notify error observer come.");
|
||||
if (errorObserver_) {
|
||||
errorObserver_->OnUnhandledException(errMsg);
|
||||
return true;
|
||||
}
|
||||
|
||||
// if apprecovery is enabled, we could callback to save current state
|
||||
// and restart as developer wants
|
||||
return AppRecovery::GetInstance().TryRecoverApp(StateReason::CJ_ERROR);
|
||||
}
|
||||
|
||||
void ApplicationDataManager::RemoveErrorObserver()
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "Remove error observer come.");
|
||||
@ -68,5 +81,18 @@ bool ApplicationDataManager::NotifyExceptionObject(const AppExecFwk::ErrorObject
|
||||
// and restart as developer wants
|
||||
return AppRecovery::GetInstance().TryRecoverApp(StateReason::JS_ERROR);
|
||||
}
|
||||
|
||||
bool ApplicationDataManager::NotifyCJExceptionObject(const AppExecFwk::ErrorObject &errorObj)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "Notify Exception error observer come.");
|
||||
if (errorObserver_) {
|
||||
errorObserver_->OnExceptionObject(errorObj);
|
||||
return true;
|
||||
}
|
||||
|
||||
// if apprecovery is enabled, we could callback to save current state
|
||||
// and restart as developer wants
|
||||
return AppRecovery::GetInstance().TryRecoverApp(StateReason::CJ_ERROR);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -70,6 +70,9 @@
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "js_runtime.h"
|
||||
#ifdef CJ_FRONTEND
|
||||
#include "cj_runtime.h"
|
||||
#endif
|
||||
#include "ohos_application.h"
|
||||
#include "overlay_module_info.h"
|
||||
#include "parameters.h"
|
||||
@ -1218,7 +1221,60 @@ bool GetBundleForLaunchApplication(std::shared_ptr<BundleMgrHelper> bundleMgrHel
|
||||
}
|
||||
return queryResult;
|
||||
}
|
||||
|
||||
#ifdef CJ_FRONTEND
|
||||
CJUncaughtExceptionInfo MainThread::CreateCjExceptionInfo(const std::string &bundleName,
|
||||
uint32_t versionCode, const std::string &hapPath)
|
||||
{
|
||||
CJUncaughtExceptionInfo uncaughtExceptionInfo;
|
||||
wptr<MainThread> weak_this = this;
|
||||
uncaughtExceptionInfo.hapPath = hapPath.c_str();
|
||||
uncaughtExceptionInfo.uncaughtTask = [weak_this, bundleName, versionCode]
|
||||
(std::string summary, const CJErrorObject errorObj) {
|
||||
auto appThread = weak_this.promote();
|
||||
if (appThread == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "appThread is nullptr.");
|
||||
return;
|
||||
}
|
||||
time_t timet;
|
||||
time(&timet);
|
||||
std::string errName = errorObj.name ? errorObj.name : "[none]";
|
||||
std::string errMsg = errorObj.name ? errorObj.message : "[none]";
|
||||
std::string errStack = errorObj.name ? errorObj.stack : "[none]";
|
||||
HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, "CJ_ERROR",
|
||||
OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
|
||||
EVENT_KEY_PACKAGE_NAME, bundleName,
|
||||
EVENT_KEY_VERSION, std::to_string(versionCode),
|
||||
EVENT_KEY_TYPE, JSCRASH_TYPE,
|
||||
EVENT_KEY_HAPPEN_TIME, timet,
|
||||
EVENT_KEY_REASON, errName,
|
||||
EVENT_KEY_JSVM, JSVM_TYPE,
|
||||
EVENT_KEY_SUMMARY, summary);
|
||||
ErrorObject appExecErrorObj = {
|
||||
.name = errName,
|
||||
.message = errMsg,
|
||||
.stack = errStack
|
||||
};
|
||||
FaultData faultData;
|
||||
faultData.faultType = FaultDataType::CJ_ERROR;
|
||||
faultData.errorObject = appExecErrorObj;
|
||||
DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance()->NotifyAppFault(faultData);
|
||||
if (ApplicationDataManager::GetInstance().NotifyCJUnhandledException(summary) &&
|
||||
ApplicationDataManager::GetInstance().NotifyCJExceptionObject(appExecErrorObj)) {
|
||||
return;
|
||||
}
|
||||
// if app's callback has been registered, let app decide whether exit or not.
|
||||
TAG_LOGE(AAFwkTag::APPKIT,
|
||||
"\n%{public}s is about to exit due to RuntimeError\nError type:%{public}s\n%{public}s\n"
|
||||
"message: %{public}s\n"
|
||||
"stack: %{public}s",
|
||||
bundleName.c_str(), errName.c_str(), summary.c_str(), errMsg.c_str(), errStack.c_str());
|
||||
AAFwk::ExitReason exitReason = { REASON_CJ_ERROR, errName };
|
||||
AbilityManagerClient::GetInstance()->RecordAppExitReason(exitReason);
|
||||
appThread->ScheduleProcessSecurityExit();
|
||||
};
|
||||
return uncaughtExceptionInfo;
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
*
|
||||
* @brief Launch the application.
|
||||
@ -1266,6 +1322,9 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
bool moduelJson = false;
|
||||
bool isStageBased = false;
|
||||
bool findEntryHapModuleInfo = false;
|
||||
#ifdef CJ_FRONTEND
|
||||
bool isCJApp = false;
|
||||
#endif
|
||||
AppExecFwk::HapModuleInfo entryHapModuleInfo;
|
||||
if (!bundleInfo.hapModuleInfos.empty()) {
|
||||
for (auto hapModuleInfo : bundleInfo.hapModuleInfos) {
|
||||
@ -1279,6 +1338,11 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
TAG_LOGW(AAFwkTag::APPKIT, "HandleLaunchApplication find entry hap module info failed!");
|
||||
entryHapModuleInfo = bundleInfo.hapModuleInfos.back();
|
||||
}
|
||||
#ifdef CJ_FRONTEND
|
||||
if (!entryHapModuleInfo.abilityInfos.empty()) {
|
||||
isCJApp = IsCJAbility(entryHapModuleInfo.abilityInfos.front().srcEntrance);
|
||||
}
|
||||
#endif
|
||||
moduelJson = entryHapModuleInfo.isModuleJson;
|
||||
isStageBased = entryHapModuleInfo.isStageBasedModel;
|
||||
}
|
||||
@ -1361,7 +1425,15 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
GetNativeLibPath(bundleInfo, hspList, appLibPaths);
|
||||
bool isSystemApp = bundleInfo.applicationInfo.isSystemApp;
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "the application isSystemApp: %{public}d", isSystemApp);
|
||||
AbilityRuntime::JsRuntime::SetAppLibPath(appLibPaths, isSystemApp);
|
||||
#ifdef CJ_FRONTEND
|
||||
if (isCJApp) {
|
||||
AbilityRuntime::CJRuntime::SetAppLibPath(appLibPaths);
|
||||
} else {
|
||||
#endif
|
||||
AbilityRuntime::JsRuntime::SetAppLibPath(appLibPaths, isSystemApp);
|
||||
#ifdef CJ_FRONTEND
|
||||
}
|
||||
#endif
|
||||
|
||||
if (isStageBased) {
|
||||
// Create runtime
|
||||
@ -1380,6 +1452,9 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
options.uid = bundleInfo.applicationInfo.uid;
|
||||
options.apiTargetVersion = appInfo.apiTargetVersion;
|
||||
options.pkgContextInfoJsonStringMap = pkgContextInfoJsonStringMap;
|
||||
#ifdef CJ_FRONTEND
|
||||
options.lang = isCJApp ? AbilityRuntime::Runtime::Language::CJ : AbilityRuntime::Runtime::Language::JS;
|
||||
#endif
|
||||
if (applicationInfo_->appProvisionType == Constants::APP_PROVISION_TYPE_DEBUG) {
|
||||
TAG_LOGD(AAFwkTag::JSRUNTIME, "Start Multi-Thread Mode: %{public}d.", appLaunchData.GetMultiThread());
|
||||
options.isMultiThread = appLaunchData.GetMultiThread();
|
||||
@ -1449,60 +1524,69 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
runtime->RegisterQuickFixQueryFunc(modulePaths);
|
||||
}
|
||||
|
||||
auto& jsEngine = (static_cast<AbilityRuntime::JsRuntime&>(*runtime)).GetNativeEngine();
|
||||
auto bundleName = appInfo.bundleName;
|
||||
auto versionCode = appInfo.versionCode;
|
||||
JsEnv::UncaughtExceptionInfo uncaughtExceptionInfo;
|
||||
uncaughtExceptionInfo.hapPath = hapPath;
|
||||
wptr<MainThread> weak = this;
|
||||
uncaughtExceptionInfo.uncaughtTask = [weak, bundleName, versionCode, appRunningId = std::move(appRunningId),
|
||||
pid, processName] (std::string summary, const JsEnv::ErrorObject errorObj) {
|
||||
auto appThread = weak.promote();
|
||||
if (appThread == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "appThread is nullptr.");
|
||||
return;
|
||||
}
|
||||
time_t timet;
|
||||
time(&timet);
|
||||
HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, "JS_ERROR",
|
||||
OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
|
||||
EVENT_KEY_PACKAGE_NAME, bundleName,
|
||||
EVENT_KEY_VERSION, std::to_string(versionCode),
|
||||
EVENT_KEY_TYPE, JSCRASH_TYPE,
|
||||
EVENT_KEY_HAPPEN_TIME, timet,
|
||||
EVENT_KEY_REASON, errorObj.name,
|
||||
EVENT_KEY_JSVM, JSVM_TYPE,
|
||||
EVENT_KEY_SUMMARY, summary,
|
||||
EVENT_KEY_APP_RUNING_UNIQUE_ID, appRunningId);
|
||||
ErrorObject appExecErrorObj = {
|
||||
.name = errorObj.name,
|
||||
.message = errorObj.message,
|
||||
.stack = errorObj.stack
|
||||
#ifdef CJ_FRONTEND
|
||||
if (!isCJApp) {
|
||||
#endif
|
||||
JsEnv::UncaughtExceptionInfo uncaughtExceptionInfo;
|
||||
uncaughtExceptionInfo.hapPath = hapPath;
|
||||
wptr<MainThread> weak = this;
|
||||
uncaughtExceptionInfo.uncaughtTask = [weak, bundleName, versionCode, appRunningId = std::move(appRunningId),
|
||||
pid, processName] (std::string summary, const JsEnv::ErrorObject errorObj) {
|
||||
auto appThread = weak.promote();
|
||||
if (appThread == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "appThread is nullptr.");
|
||||
return;
|
||||
}
|
||||
time_t timet;
|
||||
time(&timet);
|
||||
HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, "JS_ERROR",
|
||||
OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
|
||||
EVENT_KEY_PACKAGE_NAME, bundleName,
|
||||
EVENT_KEY_VERSION, std::to_string(versionCode),
|
||||
EVENT_KEY_TYPE, JSCRASH_TYPE,
|
||||
EVENT_KEY_HAPPEN_TIME, timet,
|
||||
EVENT_KEY_REASON, errorObj.name,
|
||||
EVENT_KEY_JSVM, JSVM_TYPE,
|
||||
EVENT_KEY_SUMMARY, summary,
|
||||
EVENT_KEY_APP_RUNING_UNIQUE_ID, appRunningId);
|
||||
ErrorObject appExecErrorObj = {
|
||||
.name = errorObj.name,
|
||||
.message = errorObj.message,
|
||||
.stack = errorObj.stack
|
||||
};
|
||||
FaultData faultData;
|
||||
faultData.faultType = FaultDataType::JS_ERROR;
|
||||
faultData.errorObject = appExecErrorObj;
|
||||
DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance()->NotifyAppFault(faultData);
|
||||
int result = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::FRAMEWORK, "PROCESS_KILL",
|
||||
HiviewDFX::HiSysEvent::EventType::FAULT, "PID", pid, "PROCESS_NAME", processName,
|
||||
"MSG", KILL_REASON);
|
||||
TAG_LOGI(AAFwkTag::APPKIT, "hisysevent write result=%{public}d, send event [FRAMEWORK,PROCESS_KILL],"
|
||||
" pid=%{public}d, processName=%{public}s, msg=%{public}s", result, pid, processName.c_str(),
|
||||
KILL_REASON);
|
||||
|
||||
if (ApplicationDataManager::GetInstance().NotifyUnhandledException(summary) &&
|
||||
ApplicationDataManager::GetInstance().NotifyExceptionObject(appExecErrorObj)) {
|
||||
return;
|
||||
}
|
||||
// if app's callback has been registered, let app decide whether exit or not.
|
||||
TAG_LOGE(AAFwkTag::APPKIT,
|
||||
"\n%{public}s is about to exit due to RuntimeError\nError type:%{public}s\n%{public}s",
|
||||
bundleName.c_str(), errorObj.name.c_str(), summary.c_str());
|
||||
AAFwk::ExitReason exitReason = { REASON_JS_ERROR, errorObj.name };
|
||||
AbilityManagerClient::GetInstance()->RecordAppExitReason(exitReason);
|
||||
appThread->ScheduleProcessSecurityExit();
|
||||
};
|
||||
FaultData faultData;
|
||||
faultData.faultType = FaultDataType::JS_ERROR;
|
||||
faultData.errorObject = appExecErrorObj;
|
||||
DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance()->NotifyAppFault(faultData);
|
||||
int result = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::FRAMEWORK, "PROCESS_KILL",
|
||||
HiviewDFX::HiSysEvent::EventType::FAULT, "PID", pid, "PROCESS_NAME", processName,
|
||||
"MSG", KILL_REASON);
|
||||
TAG_LOGI(AAFwkTag::APPKIT, "hisysevent write result=%{public}d, send event [FRAMEWORK,PROCESS_KILL],"
|
||||
" pid=%{public}d, processName=%{public}s, msg=%{public}s", result, pid, processName.c_str(),
|
||||
KILL_REASON);
|
||||
(static_cast<AbilityRuntime::JsRuntime&>(*runtime)).RegisterUncaughtExceptionHandler(uncaughtExceptionInfo);
|
||||
#ifdef CJ_FRONTEND
|
||||
} else {
|
||||
auto expectionInfo = CreateCjExceptionInfo(bundleName, versionCode, hapPath);
|
||||
(static_cast<AbilityRuntime::CJRuntime&>(*runtime)).RegisterUncaughtExceptionHandler(expectionInfo);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ApplicationDataManager::GetInstance().NotifyUnhandledException(summary) &&
|
||||
ApplicationDataManager::GetInstance().NotifyExceptionObject(appExecErrorObj)) {
|
||||
return;
|
||||
}
|
||||
// if app's callback has been registered, let app decide whether exit or not.
|
||||
TAG_LOGE(AAFwkTag::APPKIT,
|
||||
"\n%{public}s is about to exit due to RuntimeError\nError type:%{public}s\n%{public}s",
|
||||
bundleName.c_str(), errorObj.name.c_str(), summary.c_str());
|
||||
AAFwk::ExitReason exitReason = { REASON_JS_ERROR, errorObj.name };
|
||||
AbilityManagerClient::GetInstance()->RecordAppExitReason(exitReason);
|
||||
appThread->ScheduleProcessSecurityExit();
|
||||
};
|
||||
(static_cast<AbilityRuntime::JsRuntime&>(*runtime)).RegisterUncaughtExceptionHandler(uncaughtExceptionInfo);
|
||||
application_->SetRuntime(std::move(runtime));
|
||||
|
||||
std::weak_ptr<OHOSApplication> wpApplication = application_;
|
||||
@ -1515,30 +1599,37 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "failed.");
|
||||
return nullptr;
|
||||
});
|
||||
if (application_ != nullptr) {
|
||||
LoadAllExtensions(jsEngine);
|
||||
#ifdef CJ_FRONTEND
|
||||
if (!isCJApp) {
|
||||
#endif
|
||||
auto& jsEngine = (static_cast<AbilityRuntime::JsRuntime&>(*application_->GetRuntime())).GetNativeEngine();
|
||||
if (application_ != nullptr) {
|
||||
LoadAllExtensions(jsEngine);
|
||||
}
|
||||
|
||||
IdleTimeCallback callback = [wpApplication](int32_t idleTime) {
|
||||
auto app = wpApplication.lock();
|
||||
if (app == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "app is nullptr.");
|
||||
return;
|
||||
}
|
||||
auto &runtime = app->GetRuntime();
|
||||
if (runtime == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "runtime is nullptr.");
|
||||
return;
|
||||
}
|
||||
auto& nativeEngine = (static_cast<AbilityRuntime::JsRuntime&>(*runtime)).GetNativeEngine();
|
||||
nativeEngine.NotifyIdleTime(idleTime);
|
||||
};
|
||||
idleTime_ = std::make_shared<IdleTime>(mainHandler_, callback);
|
||||
idleTime_->Start();
|
||||
|
||||
IdleNotifyStatusCallback cb = idleTime_->GetIdleNotifyFunc();
|
||||
jsEngine.NotifyIdleStatusControl(cb);
|
||||
}
|
||||
|
||||
IdleTimeCallback callback = [wpApplication](int32_t idleTime) {
|
||||
auto app = wpApplication.lock();
|
||||
if (app == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "app is nullptr.");
|
||||
return;
|
||||
}
|
||||
auto &runtime = app->GetRuntime();
|
||||
if (runtime == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "runtime is nullptr.");
|
||||
return;
|
||||
}
|
||||
auto& nativeEngine = (static_cast<AbilityRuntime::JsRuntime&>(*runtime)).GetNativeEngine();
|
||||
nativeEngine.NotifyIdleTime(idleTime);
|
||||
};
|
||||
idleTime_ = std::make_shared<IdleTime>(mainHandler_, callback);
|
||||
idleTime_->Start();
|
||||
|
||||
IdleNotifyStatusCallback cb = idleTime_->GetIdleNotifyFunc();
|
||||
jsEngine.NotifyIdleStatusControl(cb);
|
||||
#ifdef CJ_FRONTEND
|
||||
}
|
||||
#endif
|
||||
|
||||
auto usertestInfo = appLaunchData.GetUserTestInfo();
|
||||
if (usertestInfo) {
|
||||
|
@ -15,7 +15,9 @@
|
||||
|
||||
#include "runtime.h"
|
||||
|
||||
#ifdef CJ_FRONTEND
|
||||
#include "cj_runtime.h"
|
||||
#endif
|
||||
#include "js_runtime.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -29,8 +31,10 @@ std::unique_ptr<Runtime> Runtime::Create(const Runtime::Options& options)
|
||||
switch (options.lang) {
|
||||
case Runtime::Language::JS:
|
||||
return JsRuntime::Create(options);
|
||||
#ifdef CJ_FRONTEND
|
||||
case Runtime::Language::CJ:
|
||||
return CJRuntime::Create(options);
|
||||
#endif
|
||||
default:
|
||||
return std::unique_ptr<Runtime>();
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ enum Reason {
|
||||
REASON_NORMAL,
|
||||
REASON_CPP_CRASH,
|
||||
REASON_JS_ERROR,
|
||||
REASON_CJ_ERROR,
|
||||
REASON_APP_FREEZE,
|
||||
REASON_PERFORMANCE_CONTROL,
|
||||
REASON_RESOURCE_CONTROL,
|
||||
|
@ -33,6 +33,7 @@ enum class FaultDataType {
|
||||
UNKNOWN = -1,
|
||||
CPP_CRASH,
|
||||
JS_ERROR,
|
||||
CJ_ERROR,
|
||||
APP_FREEZE,
|
||||
PERFORMANCE_CONTROL,
|
||||
RESOURCE_CONTROL
|
||||
|
@ -295,6 +295,17 @@ public:
|
||||
*/
|
||||
virtual ErrCode RequestDialogService(napi_env env, AAFwk::Want &want, RequestDialogResultTask &&task) = 0;
|
||||
|
||||
/**
|
||||
* @brief Requests dialogService from the system.
|
||||
* This method is called for dialog request. This is an asynchronous method. When it is executed,
|
||||
* the task will be called back.
|
||||
*
|
||||
* @param want Indicates the dialog service to be requested.
|
||||
* @param task The callback or promise fo js interface.
|
||||
* @return Returns ERR_OK if success.
|
||||
*/
|
||||
virtual ErrCode RequestDialogService(AAFwk::Want &want, RequestDialogResultTask &&task) = 0;
|
||||
|
||||
/**
|
||||
* @brief Report drawn completed.
|
||||
*
|
||||
|
@ -200,6 +200,8 @@ public:
|
||||
|
||||
ErrCode RequestDialogService(napi_env env, AAFwk::Want &want, RequestDialogResultTask &&task) override;
|
||||
|
||||
ErrCode RequestDialogService(AAFwk::Want &want, RequestDialogResultTask &&task) override;
|
||||
|
||||
ErrCode ReportDrawnCompleted() override;
|
||||
|
||||
ErrCode GetMissionId(int32_t &missionId) override;
|
||||
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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_CJ_ABILITY_CONNECT_CALLBACK_OBJECT_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_ABILITY_CONNECT_CALLBACK_OBJECT_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "ability_connect_callback.h"
|
||||
#include "cj_element_name_ffi.h"
|
||||
|
||||
extern "C" {
|
||||
struct CJAbilityConnectCallbackFuncs {
|
||||
void (*onConnect)(int64_t id, ElementNameHandle elementNameHandle, int64_t remoteObjectId, int32_t resultCode);
|
||||
void (*onDisconnect)(int64_t id, ElementNameHandle elementNameHandle, int32_t resultCode);
|
||||
void (*release)(int64_t id);
|
||||
};
|
||||
|
||||
#define EXPORT __attribute__((visibility("default")))
|
||||
EXPORT void RegisterCJAbilityConnectCallbackFuncs(void (*registerFunc)(CJAbilityConnectCallbackFuncs* result));
|
||||
#undef EXPORT
|
||||
};
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class CJAbilityConnectCallback : public AbilityConnectCallback {
|
||||
public:
|
||||
explicit CJAbilityConnectCallback(int64_t id) : callbackId_(id) {};
|
||||
~CJAbilityConnectCallback() override;
|
||||
|
||||
void OnAbilityConnectDone(
|
||||
const AppExecFwk::ElementName& element, const sptr<IRemoteObject>& remoteObject, int resultCode) override;
|
||||
void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int resultCode) override;
|
||||
|
||||
private:
|
||||
int64_t callbackId_ = 0;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_ABILITY_CONNECT_CALLBACK_OBJECT_H
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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_CJ_ABILITY_CONTEXT_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_ABILITY_CONTEXT_H
|
||||
|
||||
#include "ability.h"
|
||||
#include "ability_context_impl.h"
|
||||
#include "ffi_remote_data.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class CJAbilityContext : public FFI::FFIData {
|
||||
public:
|
||||
explicit CJAbilityContext(const std::shared_ptr<AbilityRuntime::AbilityContext>& abilityContext)
|
||||
: context_(abilityContext) {};
|
||||
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> GetAbilityContext();
|
||||
sptr<IRemoteObject> GetToken();
|
||||
std::string GetPreferencesDir();
|
||||
std::string GetDatabaseDir();
|
||||
std::string GetBundleName();
|
||||
int32_t GetArea();
|
||||
std::shared_ptr<AppExecFwk::AbilityInfo> GetAbilityInfo();
|
||||
std::shared_ptr<AppExecFwk::HapModuleInfo> GetHapModuleInfo();
|
||||
std::shared_ptr<AppExecFwk::Configuration> GetConfiguration();
|
||||
int32_t StartAbility(const AAFwk::Want& want);
|
||||
int32_t StartAbility(const AAFwk::Want& want, const AAFwk::StartOptions& startOptions);
|
||||
int32_t StartAbilityWithAccount(const AAFwk::Want& want, int32_t accountId);
|
||||
int32_t StartAbilityWithAccount(
|
||||
const AAFwk::Want& want, int32_t accountId, const AAFwk::StartOptions& startOptions);
|
||||
int32_t StartServiceExtensionAbility(const AAFwk::Want& want);
|
||||
int32_t StartServiceExtensionAbilityWithAccount(const AAFwk::Want& want, int32_t accountId);
|
||||
int32_t StopServiceExtensionAbility(const AAFwk::Want& want);
|
||||
int32_t StopServiceExtensionAbilityWithAccount(const AAFwk::Want& want, int32_t accountId);
|
||||
int32_t TerminateSelf();
|
||||
int32_t TerminateSelfWithResult(const AAFwk::Want& want, int32_t resultCode);
|
||||
std::tuple<int32_t, bool> IsTerminating();
|
||||
bool ConnectAbility(const AAFwk::Want& want, int64_t connectionId);
|
||||
int32_t ConnectAbilityWithAccount(
|
||||
const AAFwk::Want& want, int32_t accountId, int64_t connectionId);
|
||||
void DisconnectAbility(const AAFwk::Want& want, int64_t connectionId);
|
||||
int32_t StartAbilityForResult(const AAFwk::Want& want, int32_t requestCode, RuntimeTask&& task);
|
||||
int32_t StartAbilityForResult(
|
||||
const AAFwk::Want& want, const AAFwk::StartOptions& startOptions, int32_t requestCode, RuntimeTask&& task);
|
||||
int32_t StartAbilityForResultWithAccount(
|
||||
const AAFwk::Want& want, int32_t accountId, int32_t requestCode, RuntimeTask&& task);
|
||||
int32_t StartAbilityForResultWithAccount(const AAFwk::Want& want, int32_t accountId,
|
||||
const AAFwk::StartOptions& startOptions, int32_t requestCode, RuntimeTask&& task);
|
||||
int32_t RequestPermissionsFromUser(
|
||||
AppExecFwk::Ability* ability, std::vector<std::string>& permissions, PermissionRequestTask&& task);
|
||||
void InheritWindowMode(AAFwk::Want& want);
|
||||
int32_t RequestDialogService(AAFwk::Want& want, RequestDialogResultTask&& task);
|
||||
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
int32_t SetMissionLabel(const std::string& label);
|
||||
int32_t SetMissionIcon(const std::shared_ptr<OHOS::Media::PixelMap>& icon);
|
||||
#endif
|
||||
|
||||
private:
|
||||
std::shared_ptr<AbilityContext> context_;
|
||||
};
|
||||
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_ABILITY_CONTEXT_H
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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_CJ_ABILITY_CONTEXT_BROKER_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_ABILITY_CONTEXT_BROKER_H
|
||||
|
||||
#include "ability_context_impl.h"
|
||||
#include "cj_common_ffi.h"
|
||||
#include "cj_want_ffi.h"
|
||||
|
||||
extern "C" {
|
||||
struct CJStartOptions {
|
||||
int32_t windowMode;
|
||||
int32_t displayId;
|
||||
};
|
||||
|
||||
using VectorStringHandle = void*;
|
||||
|
||||
struct AbilityContextBroker {
|
||||
bool (*isAbilityContextExisted)(int64_t id);
|
||||
int64_t (*getSizeOfStartOptions)();
|
||||
|
||||
int64_t (*getAbilityInfo)(int64_t id);
|
||||
int64_t (*getHapModuleInfo)(int64_t id);
|
||||
int64_t (*getConfiguration)(int64_t id);
|
||||
|
||||
int32_t (*startAbility)(int64_t id, WantHandle wantHandle);
|
||||
int32_t (*startAbilityWithOption)(int64_t id, WantHandle wantHandle, CJStartOptions* startOption);
|
||||
int32_t (*startAbilityWithAccount)(int64_t id, WantHandle wantHandle, int32_t accountId);
|
||||
int32_t (*startAbilityWithAccountAndOption)(
|
||||
int64_t id, WantHandle wantHandle, int32_t accountId, CJStartOptions* startOption);
|
||||
int32_t (*startServiceExtensionAbility)(int64_t id, WantHandle want);
|
||||
int32_t (*startServiceExtensionAbilityWithAccount)(int64_t id, WantHandle want, int32_t accountId);
|
||||
int32_t (*stopServiceExtensionAbility)(int64_t id, WantHandle want);
|
||||
int32_t (*stopServiceExtensionAbilityWithAccount)(int64_t id, WantHandle want, int32_t accountId);
|
||||
|
||||
int32_t (*terminateSelf)(int64_t id);
|
||||
int32_t (*terminateSelfWithResult)(int64_t id, WantHandle want, int32_t resultCode);
|
||||
RetDataBool (*isTerminating)(int64_t id);
|
||||
|
||||
int32_t (*connectAbility)(int64_t id, WantHandle want, int64_t connection);
|
||||
int32_t (*connectAbilityWithAccount)(int64_t id, WantHandle want, int32_t accountId, int64_t connection);
|
||||
int32_t (*disconnectAbility)(int64_t id, WantHandle want, int64_t connection);
|
||||
int32_t (*startAbilityForResult)(int64_t id, WantHandle want, int32_t requestCode, int64_t lambdaId);
|
||||
int32_t (*startAbilityForResultWithOption)(
|
||||
int64_t id, WantHandle want, CJStartOptions* startOption, int32_t requestCode, int64_t lambdaId);
|
||||
int32_t (*startAbilityForResultWithAccount)(
|
||||
int64_t id, WantHandle want, int32_t accountId, int32_t requestCode, int64_t lambdaId);
|
||||
int32_t (*startAbilityForResultWithAccountAndOption)(int64_t id, WantHandle want, int32_t accountId,
|
||||
CJStartOptions* startOption, int32_t requestCode, int64_t lambdaId);
|
||||
int32_t (*requestPermissionsFromUser)(
|
||||
int64_t id, VectorStringHandle permissions, int32_t requestCode, int64_t lambdaId);
|
||||
|
||||
int32_t (*setMissionLabel)(int64_t id, const char* label);
|
||||
int32_t (*setMissionIcon)(int64_t id, int64_t pixelMapId);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_ABILITY_CONTEXT_BROKER_H
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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_CJ_ABILITY_CONTEXT_OBJECT_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_ABILITY_CONTEXT_OBJECT_H
|
||||
|
||||
#include "cj_want_ffi.h"
|
||||
#include "cj_ability_context_broker.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
|
||||
extern "C" {
|
||||
struct CJAbilityResult {
|
||||
int32_t resultCode;
|
||||
WantHandle wantHandle;
|
||||
};
|
||||
|
||||
struct CJPermissionRequestResult {
|
||||
VectorStringHandle permissions;
|
||||
VectorInt32Handle authResults;
|
||||
};
|
||||
|
||||
struct CJDialogRequestResult {
|
||||
int32_t resultCode;
|
||||
WantHandle wantHandle;
|
||||
};
|
||||
|
||||
CJ_EXPORT int32_t FFIAbilityContextRequestDialogService(int64_t id, WantHandle want, int64_t lambdaId);
|
||||
|
||||
struct CJAbilityCallbacks {
|
||||
void (*invokeAbilityResultCallback)(int64_t id, int32_t error, CJAbilityResult* cjAbilityResult);
|
||||
void (*invokePermissionRequestResultCallback)(
|
||||
int64_t id, int32_t error, CJPermissionRequestResult* cjPermissionRequestResult);
|
||||
void (*invokeDialogRequestResultCallback)(
|
||||
int64_t id, int32_t error, CJDialogRequestResult* cjDialogRequestResult);
|
||||
};
|
||||
|
||||
CJ_EXPORT void RegisterCJAbilityCallbacks(void (*registerFunc)(CJAbilityCallbacks*));
|
||||
}
|
||||
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_ABILITY_CONTEXT_OBJECT_H
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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_CJ_ABILITY_FFI_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_ABILITY_FFI_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#ifdef WINDOWS_PLATFORM
|
||||
#define CJ_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define CJ_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
using AbilityHandle = void*;
|
||||
|
||||
extern "C" {
|
||||
CJ_EXPORT int64_t FFIAbilityGetAbilityContext(AbilityHandle abilityHandle);
|
||||
CJ_EXPORT void FFIAbilityContextGetFilesDir(int64_t id, void(*accept)(const char*));
|
||||
}
|
||||
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_ABILITY_FFI_H
|
@ -102,4 +102,4 @@ private:
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FOUNDATION_APPEXECFWK_OHOS_CJ_ABILITY_PROXY_H
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_ABILITY_OBJECT_H
|
||||
|
@ -44,6 +44,7 @@ enum RestartFlag {
|
||||
ALWAYS_RESTART = 0x0000,
|
||||
RESTART_WHEN_JS_CRASH = 0x0001,
|
||||
RESTART_WHEN_APP_FREEZE = 0x0002,
|
||||
RESTART_WHEN_CJ_CRASH = 0x0004,
|
||||
NO_RESTART = 0xFFFF,
|
||||
};
|
||||
|
||||
@ -65,6 +66,7 @@ enum StateReason {
|
||||
CPP_CRASH,
|
||||
JS_ERROR,
|
||||
APP_FREEZE,
|
||||
CJ_ERROR,
|
||||
};
|
||||
|
||||
} // namespace AAFwk
|
||||
|
@ -28,8 +28,10 @@ public:
|
||||
static ApplicationDataManager &GetInstance();
|
||||
void AddErrorObserver(const std::shared_ptr<IErrorObserver> &observer);
|
||||
bool NotifyUnhandledException(const std::string &errMsg);
|
||||
bool NotifyCJUnhandledException(const std::string &errMsg);
|
||||
void RemoveErrorObserver();
|
||||
bool NotifyExceptionObject(const AppExecFwk::ErrorObject &errorObj);
|
||||
bool NotifyCJExceptionObject(const AppExecFwk::ErrorObject &errorObj);
|
||||
|
||||
private:
|
||||
ApplicationDataManager();
|
||||
|
@ -32,6 +32,9 @@
|
||||
#include "resource_manager.h"
|
||||
#include "foundation/ability/ability_runtime/interfaces/inner_api/runtime/include/runtime.h"
|
||||
#include "ipc_singleton.h"
|
||||
#ifdef CJ_FRONTEND
|
||||
#include "cj_environment.h"
|
||||
#endif
|
||||
#include "js_runtime.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "overlay_event_subscriber.h"
|
||||
@ -282,7 +285,10 @@ public:
|
||||
const sptr<IQuickFixCallback> &callback, const int32_t recordId) override;
|
||||
|
||||
int32_t ScheduleNotifyAppFault(const FaultData &faultData) override;
|
||||
|
||||
#ifdef CJ_FRONTEND
|
||||
CJUncaughtExceptionInfo CreateCjExceptionInfo(const std::string &bundleName, uint32_t versionCode,
|
||||
const std::string &hapPath);
|
||||
#endif
|
||||
/**
|
||||
* @brief Notify NativeEngine GC of status change.
|
||||
*
|
||||
|
@ -223,11 +223,9 @@ int32_t GetUserIdByUid(int32_t uid)
|
||||
|
||||
bool IsCjAbility(const std::string& info)
|
||||
{
|
||||
std::string cjCheckFlag = ".cj";
|
||||
if (info.length() < cjCheckFlag.length()) {
|
||||
return false;
|
||||
}
|
||||
return info.substr(info.length() - cjCheckFlag.length()) == cjCheckFlag;
|
||||
// in cj application, the srcEntry format should be packageName.AbilityClassName.
|
||||
std::string pattern = "^([a-zA-Z0-9_]+\\.)+[a-zA-Z0-9_]+$";
|
||||
return std::regex_match(info, std::regex(pattern));
|
||||
}
|
||||
|
||||
bool IsCjApplication(const BundleInfo &bundleInfo)
|
||||
|
Loading…
Reference in New Issue
Block a user