mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-30 02:41:51 +00:00
Merge branch 'master' of https://gitee.com/xuzhihao666/ability_ability_runtime_2
Signed-off-by: xuzhihao <xuzhihao16@huawei.com>
This commit is contained in:
commit
2ec820e6ee
@ -70,6 +70,7 @@ graphic_2d_path = "//foundation/graphic/graphic_2d"
|
||||
srms_inner_api_path =
|
||||
"${ability_runtime_path}/service_router_framework/interfaces/inner_api"
|
||||
fuzz_test_output_path = "ability_runtime/ability_runtime"
|
||||
accessibility_path = "//foundation/barrierfree/accessibility"
|
||||
|
||||
declare_args() {
|
||||
background_task_mgr_continuous_task_enable = true
|
||||
@ -84,6 +85,8 @@ declare_args() {
|
||||
ability_fault_and_exit_test = false
|
||||
ability_command_for_test = false
|
||||
ability_runtime_feature_coverage = false
|
||||
ability_runtime_auto_fill_ability =
|
||||
"com.ohos.passwordbox/entry/AutoFillAbility"
|
||||
|
||||
if (!defined(global_parts_info) ||
|
||||
defined(global_parts_info.account_os_account)) {
|
||||
@ -147,4 +150,11 @@ declare_args() {
|
||||
} else {
|
||||
ecologic_rule_enabled = false
|
||||
}
|
||||
|
||||
if (!defined(global_parts_info) ||
|
||||
defined(global_parts_info.hiviewdfx_hichecker)) {
|
||||
hichecker_enabled = true
|
||||
} else {
|
||||
hichecker_enabled = false
|
||||
}
|
||||
}
|
||||
|
14
bundle.json
14
bundle.json
@ -21,6 +21,7 @@
|
||||
"SystemCapability.Ability.AbilityTools.AbilityAssistant"
|
||||
],
|
||||
"features": [
|
||||
"ability_runtime_auto_fill_ability",
|
||||
"ability_runtime_graphics",
|
||||
"ability_runtime_power"
|
||||
],
|
||||
@ -42,6 +43,7 @@
|
||||
"background_task_mgr",
|
||||
"bundle_framework",
|
||||
"common_event_service",
|
||||
"config_policy",
|
||||
"c_utils",
|
||||
"data_share",
|
||||
"dlp_permission_service",
|
||||
@ -394,6 +396,18 @@
|
||||
"header_files": []
|
||||
},
|
||||
"name": "//foundation/ability/ability_runtime/interfaces/inner_api/session_handler:session_handler"
|
||||
},
|
||||
{
|
||||
"header": {
|
||||
"header_base": "//foundation/ability/ability_runtime/interfaces/inner_api/auto_fill_manager/include",
|
||||
"header_files": [
|
||||
"auto_fill_error.h",
|
||||
"auto_fill_manager.h",
|
||||
"fill_request_callback_interface.h",
|
||||
"save_request_callback_interface.h"
|
||||
]
|
||||
},
|
||||
"name": "//foundation/ability/ability_runtime/interfaces/inner_api/auto_fill_manager:auto_fill_manager"
|
||||
}
|
||||
],
|
||||
"test": [
|
||||
|
@ -41,11 +41,16 @@ group("napi_packages") {
|
||||
"${ability_runtime_napi_path}/app/recovery:apprecovery_napi",
|
||||
"${ability_runtime_napi_path}/app/test_runner:testrunner_napi",
|
||||
"${ability_runtime_napi_path}/application_context_constant:contextconstant_napi",
|
||||
"${ability_runtime_napi_path}/auto_fill_extension_ability:autofillextensionability_napi",
|
||||
"${ability_runtime_napi_path}/auto_fill_extension_context:autofillextensioncontext_napi",
|
||||
"${ability_runtime_napi_path}/auto_fill_manager:autofillmanager_napi",
|
||||
"${ability_runtime_napi_path}/callee:callee_napi",
|
||||
"${ability_runtime_napi_path}/caller:caller_napi",
|
||||
"${ability_runtime_napi_path}/configuration_constant:configurationconstant",
|
||||
"${ability_runtime_napi_path}/configuration_constant:configurationconstant_napi",
|
||||
"${ability_runtime_napi_path}/dataUriUtils:datauriutils_napi",
|
||||
"${ability_runtime_napi_path}/embeddable_ui_ability:embeddableuiability_napi",
|
||||
"${ability_runtime_napi_path}/embeddable_ui_ability_context:embeddableuiabilitycontext_napi",
|
||||
"${ability_runtime_napi_path}/extension_ability:extensionability_napi",
|
||||
"${ability_runtime_napi_path}/extensioncontext:extensioncontext_napi",
|
||||
"${ability_runtime_napi_path}/featureAbility:featureability",
|
||||
@ -59,6 +64,7 @@ group("napi_packages") {
|
||||
"${ability_runtime_napi_path}/js_child_process:childprocess_napi",
|
||||
"${ability_runtime_napi_path}/js_child_process_manager:childprocessmanager_napi",
|
||||
"${ability_runtime_napi_path}/js_dialog_request:dialogrequest_napi",
|
||||
"${ability_runtime_napi_path}/js_dialog_session:dialogsession_napi",
|
||||
"${ability_runtime_napi_path}/js_mission_manager:missionmanager",
|
||||
"${ability_runtime_napi_path}/mission_manager:distributedmissionmanager",
|
||||
"${ability_runtime_napi_path}/mission_manager:missionmanager_napi",
|
||||
|
@ -46,7 +46,7 @@ void JsAbilityAutoStartupCallBack::Register(napi_value value)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
std::lock_guard<std::mutex> lock(mutexlock);
|
||||
for (auto callback : callbacks_) {
|
||||
for (const auto &callback : callbacks_) {
|
||||
if (IsJsCallbackEquals(callback, value)) {
|
||||
HILOG_ERROR("The current callback already exists.");
|
||||
return;
|
||||
@ -128,7 +128,8 @@ void JsAbilityAutoStartupCallBack::JSCallFunctionWorker(const AutoStartupInfo &i
|
||||
}
|
||||
}
|
||||
|
||||
bool JsAbilityAutoStartupCallBack::IsJsCallbackEquals(std::shared_ptr<NativeReference> callback, napi_value value)
|
||||
bool JsAbilityAutoStartupCallBack::IsJsCallbackEquals(const std::shared_ptr<NativeReference> &callback,
|
||||
napi_value value)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
HILOG_ERROR("Invalid jsCallback.");
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
private:
|
||||
void JSCallFunction(const AutoStartupInfo &info, const std::string &methodName);
|
||||
void JSCallFunctionWorker(const AutoStartupInfo &info, const std::string &methodName);
|
||||
bool IsJsCallbackEquals(std::shared_ptr<NativeReference> callback, napi_value value);
|
||||
bool IsJsCallbackEquals(const std::shared_ptr<NativeReference> &callback, napi_value value);
|
||||
|
||||
napi_env env_;
|
||||
std::vector<std::shared_ptr<NativeReference>> callbacks_;
|
||||
|
@ -113,7 +113,11 @@ napi_value JsAbilityAutoStartupManager::OnRegisterAutoStartupCallback(napi_env e
|
||||
if (ret != ERR_OK) {
|
||||
jsAutoStartupCallback_ = nullptr;
|
||||
HILOG_ERROR("Register auto start up listener wrong[%{public}d].", ret);
|
||||
ThrowError(env, GetJsErrorCodeByNativeError(ret));
|
||||
if (ret == CHECK_PERMISSION_FAILED) {
|
||||
ThrowNoPermissionError(env, PermissionConstants::PERMISSION_MANAGE_APP_BOOT);
|
||||
} else {
|
||||
ThrowError(env, GetJsErrorCodeByNativeError(ret));
|
||||
}
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
}
|
||||
@ -155,7 +159,11 @@ napi_value JsAbilityAutoStartupManager::OnUnregisterAutoStartupCallback(napi_env
|
||||
auto ret = AbilityManagerClient::GetInstance()->UnregisterAutoStartupSystemCallback(
|
||||
jsAutoStartupCallback_->AsObject());
|
||||
if (ret != ERR_OK) {
|
||||
ThrowError(env, GetJsErrorCodeByNativeError(ret));
|
||||
if (ret == CHECK_PERMISSION_FAILED) {
|
||||
ThrowNoPermissionError(env, PermissionConstants::PERMISSION_MANAGE_APP_BOOT);
|
||||
} else {
|
||||
ThrowError(env, GetJsErrorCodeByNativeError(ret));
|
||||
}
|
||||
}
|
||||
jsAutoStartupCallback_ = nullptr;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ private:
|
||||
napi_value OnSetApplicationAutoStartup(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnCancelApplicationAutoStartup(napi_env env, NapiCallbackInfo &info);
|
||||
napi_value OnQueryAllAutoStartupApplications(napi_env env, const NapiCallbackInfo &info);
|
||||
bool CheckCallerIsSystemApp();
|
||||
static bool CheckCallerIsSystemApp();
|
||||
|
||||
sptr<JsAbilityAutoStartupCallBack> jsAutoStartupCallback_;
|
||||
};
|
||||
|
@ -31,6 +31,7 @@ ohos_shared_library("abilityconstant_napi") {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
@ -56,6 +57,7 @@ ohos_shared_library("abilityconstant") {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
|
@ -59,6 +59,7 @@ static napi_value InitLaunchReasonObject(napi_env env)
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "APP_RECOVERY", LAUNCHREASON_APP_RECOVERY));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "SHARE", LAUNCHREASON_SHARE));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "AUTO_STARTUP", LAUNCHREASON_AUTO_STARTUP));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "INSIGHT_INTENT", LAUNCHREASON_INSIGHT_INTENT));
|
||||
|
||||
HILOG_DEBUG("end");
|
||||
return object;
|
||||
|
@ -187,6 +187,9 @@ class AbilityContext extends Context {
|
||||
return this.__context_impl__.startAbilityByType(type, wantParam, abilityStartCallback, callback);
|
||||
}
|
||||
|
||||
requestModalUIExtension(want, callback) {
|
||||
return this.__context_impl__.requestModalUIExtension(want, callback);
|
||||
}
|
||||
}
|
||||
|
||||
export default AbilityContext;
|
||||
|
@ -24,6 +24,7 @@ template("abilitymanager") {
|
||||
|
||||
sources = [
|
||||
"ability_manager_module.cpp",
|
||||
"js_ability_foreground_state_observer.cpp",
|
||||
"js_ability_manager.cpp",
|
||||
"js_ability_manager_utils.cpp",
|
||||
]
|
||||
@ -36,6 +37,7 @@ template("abilitymanager") {
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_innerkits_path}/runtime:runtime",
|
||||
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
|
||||
"${ability_runtime_native_path}/ability/native:ability_business_error",
|
||||
@ -52,7 +54,7 @@ template("abilitymanager") {
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"ipc:ipc_napi_common",
|
||||
"ipc:ipc_napi",
|
||||
"napi:ace_napi",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "js_ability_foreground_state_observer.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_runtime_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
}
|
||||
JSAbilityForegroundStateObserver::JSAbilityForegroundStateObserver(napi_env env) : env_(env) {}
|
||||
|
||||
void JSAbilityForegroundStateObserver::OnAbilityStateChanged(const AbilityStateData &abilityStateData)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (!valid_) {
|
||||
HILOG_ERROR("The app manager may has destoryed.");
|
||||
return;
|
||||
}
|
||||
wptr<JSAbilityForegroundStateObserver> jsObserver = this;
|
||||
std::unique_ptr<NapiAsyncTask::CompleteCallback> complete = std::make_unique<NapiAsyncTask::CompleteCallback>(
|
||||
[jsObserver, abilityStateData](napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
sptr<JSAbilityForegroundStateObserver> jsObserverSptr = jsObserver.promote();
|
||||
if (jsObserverSptr == nullptr) {
|
||||
HILOG_ERROR("Js Observer Sptr is nullptr.");
|
||||
return;
|
||||
}
|
||||
jsObserverSptr->HandleOnAbilityStateChanged(abilityStateData);
|
||||
});
|
||||
napi_ref callback = nullptr;
|
||||
NapiAsyncTask::Schedule("JSAbilityForegroundStateObserver::OnAbilityStateChanged", env_,
|
||||
std::make_unique<NapiAsyncTask>(callback, nullptr, std::move(complete)));
|
||||
}
|
||||
|
||||
void JSAbilityForegroundStateObserver::HandleOnAbilityStateChanged(const AbilityStateData &abilityStateData)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
std::lock_guard<std::mutex> lock(mutexlock);
|
||||
for (auto &item : jsObserverObjectSet_) {
|
||||
if (item == nullptr) {
|
||||
continue;
|
||||
}
|
||||
napi_value obj = item->GetNapiValue();
|
||||
napi_value argv[] = { CreateJsAbilityStateData(env_, abilityStateData) };
|
||||
CallJsFunction(obj, "onAbilityStateChanged", argv, ARGC_ONE);
|
||||
}
|
||||
}
|
||||
|
||||
void JSAbilityForegroundStateObserver::CallJsFunction(
|
||||
const napi_value &value, const char *methodName, const napi_value *argv, const size_t argc)
|
||||
{
|
||||
HILOG_DEBUG("Begin.");
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("Value is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
napi_value method = nullptr;
|
||||
napi_get_named_property(env_, value, methodName, &method);
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Get name from object Failed.");
|
||||
return;
|
||||
}
|
||||
napi_value callResult = nullptr;
|
||||
napi_status status = napi_call_function(env_, value, method, argc, argv, &callResult);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("Call Js Function failed %{public}d.", status);
|
||||
}
|
||||
HILOG_DEBUG("End.");
|
||||
}
|
||||
|
||||
bool JSAbilityForegroundStateObserver::IsObserverObjectExsit(const napi_value &jsObserverObject)
|
||||
{
|
||||
if (jsObserverObject == nullptr) {
|
||||
HILOG_ERROR("Observer is null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GetObserverObject(jsObserverObject) == nullptr) {
|
||||
HILOG_DEBUG("Observer is not exists.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void JSAbilityForegroundStateObserver::AddJsObserverObject(const napi_value &jsObserverObject)
|
||||
{
|
||||
if (jsObserverObject == nullptr) {
|
||||
HILOG_ERROR("Observer is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsObserverObjectExsit(jsObserverObject)) {
|
||||
HILOG_DEBUG("Observer is exists.");
|
||||
return;
|
||||
}
|
||||
napi_ref ref = nullptr;
|
||||
napi_create_reference(env_, jsObserverObject, 1, &ref);
|
||||
std::lock_guard<std::mutex> lock(mutexlock);
|
||||
jsObserverObjectSet_.emplace(std::shared_ptr<NativeReference>(reinterpret_cast<NativeReference *>(ref)));
|
||||
}
|
||||
|
||||
void JSAbilityForegroundStateObserver::RemoveJsObserverObject(const napi_value &jsObserverObject)
|
||||
{
|
||||
if (jsObserverObject == nullptr) {
|
||||
HILOG_ERROR("Observer is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto observer = GetObserverObject(jsObserverObject);
|
||||
std::lock_guard<std::mutex> lock(mutexlock);
|
||||
if (observer != nullptr) {
|
||||
jsObserverObjectSet_.erase(observer);
|
||||
}
|
||||
}
|
||||
|
||||
void JSAbilityForegroundStateObserver::RemoveAllJsObserverObject()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutexlock);
|
||||
if (!jsObserverObjectSet_.empty()) {
|
||||
jsObserverObjectSet_.clear();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<NativeReference> JSAbilityForegroundStateObserver::GetObserverObject(const napi_value &jsObserverObject)
|
||||
{
|
||||
if (jsObserverObject == nullptr) {
|
||||
HILOG_ERROR("Observer is null.");
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mutexlock);
|
||||
for (auto &observer : jsObserverObjectSet_) {
|
||||
if (observer == nullptr) {
|
||||
HILOG_ERROR("Invalid observer.");
|
||||
continue;
|
||||
}
|
||||
|
||||
napi_value value = observer->GetNapiValue();
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("Failed to get object.");
|
||||
continue;
|
||||
}
|
||||
|
||||
bool isEqual = false;
|
||||
napi_strict_equals(env_, value, jsObserverObject, &isEqual);
|
||||
if (isEqual) {
|
||||
return observer;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void JSAbilityForegroundStateObserver::SetValid(const bool valid)
|
||||
{
|
||||
valid_ = valid;
|
||||
}
|
||||
|
||||
bool JSAbilityForegroundStateObserver::IsEmpty()
|
||||
{
|
||||
return jsObserverObjectSet_.empty();
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_JS_ABILITY_FOREGROUND_STATE_OBSERVER_H
|
||||
#define OHOS_ABILITY_RUNTIME_JS_ABILITY_FOREGROUND_STATE_OBSERVER_H
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "ability_foreground_state_observer_stub.h"
|
||||
#include "ability_state_data.h"
|
||||
#include "event_handler.h"
|
||||
#include "js_ability_manager_utils.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using OHOS::AppExecFwk::AbilityForegroundStateObserverStub;
|
||||
using OHOS::AppExecFwk::AbilityStateData;
|
||||
class JSAbilityForegroundStateObserver : public AbilityForegroundStateObserverStub {
|
||||
public:
|
||||
explicit JSAbilityForegroundStateObserver(napi_env engine);
|
||||
virtual ~JSAbilityForegroundStateObserver() = default;
|
||||
|
||||
void OnAbilityStateChanged(const AbilityStateData &abilityStateData);
|
||||
void HandleOnAbilityStateChanged(const AbilityStateData &abilityStateData);
|
||||
void CallJsFunction(const napi_value &value, const char *methodName, const napi_value *argv, const size_t argc);
|
||||
void AddJsObserverObject(const napi_value &jsObserverObject);
|
||||
void RemoveJsObserverObject(const napi_value &jsObserverObject);
|
||||
void RemoveAllJsObserverObject();
|
||||
std::shared_ptr<NativeReference> GetObserverObject(const napi_value &jsObserverObject);
|
||||
bool IsObserverObjectExsit(const napi_value &jsObserverObject);
|
||||
bool IsEmpty();
|
||||
void SetValid(bool valid);
|
||||
|
||||
private:
|
||||
napi_env env_;
|
||||
volatile bool valid_ = true;
|
||||
std::mutex mutexlock;
|
||||
std::set<std::shared_ptr<NativeReference>> jsObserverObjectSet_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_JS_ABILITY_FOREGROUND_STATE_OBSERVER_H
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 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
|
||||
@ -23,20 +23,21 @@
|
||||
#include "acquire_share_data_callback_stub.h"
|
||||
#include "app_mgr_interface.h"
|
||||
#include "errors.h"
|
||||
#include "event_runner.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "js_ability_foreground_state_observer.h"
|
||||
#include "js_ability_manager_utils.h"
|
||||
#include "js_error_utils.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "js_ability_manager_utils.h"
|
||||
#include "event_runner.h"
|
||||
#include "napi_common_configuration.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "tokenid_kit.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -51,11 +52,12 @@ OHOS::sptr<OHOS::AppExecFwk::IAppMgr> GetAppManagerInstance()
|
||||
return OHOS::iface_cast<OHOS::AppExecFwk::IAppMgr>(appObject);
|
||||
}
|
||||
|
||||
|
||||
constexpr size_t ARGC_ZERO = 0;
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
constexpr size_t INDEX_ZERO = 0;
|
||||
constexpr size_t INDEX_ONE = 1;
|
||||
constexpr const char *ON_OFF_TYPE_ABILITY_FOREGROUND_STATE = "abilityForegroundState";
|
||||
static std::shared_ptr<AppExecFwk::EventHandler> mainHandler_ = nullptr;
|
||||
|
||||
class JsAbilityManager final {
|
||||
@ -98,8 +100,125 @@ public:
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsAbilityManager, OnNotifySaveAsResult);
|
||||
}
|
||||
static napi_value GetForegroundUIAbilities(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_CB_INFO_AND_CALL(env, info, JsAbilityManager, OnGetForegroundUIAbilities);
|
||||
}
|
||||
|
||||
static napi_value On(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_CB_INFO_AND_CALL(env, info, JsAbilityManager, OnOn);
|
||||
}
|
||||
|
||||
static napi_value Off(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_CB_INFO_AND_CALL(env, info, JsAbilityManager, OnOff);
|
||||
}
|
||||
|
||||
private:
|
||||
sptr<OHOS::AbilityRuntime::JSAbilityForegroundStateObserver> observerForeground_ = nullptr;
|
||||
sptr<OHOS::AppExecFwk::IAppMgr> appManager_ = nullptr;
|
||||
|
||||
std::string ParseParamType(const napi_env &env, size_t argc, const napi_value *argv)
|
||||
{
|
||||
std::string type;
|
||||
if (argc > INDEX_ZERO && ConvertFromJsValue(env, argv[INDEX_ZERO], type)) {
|
||||
return type;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
napi_value OnOn(napi_env env, size_t argc, napi_value *argv)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (argc < ARGC_TWO) {
|
||||
HILOG_ERROR("Not enough params.");
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
if (!AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object)) {
|
||||
HILOG_ERROR("Invalid param.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
std::string type = ParseParamType(env, argc, argv);
|
||||
if (type == ON_OFF_TYPE_ABILITY_FOREGROUND_STATE) {
|
||||
OnOnAbilityForeground(env, argc, argv);
|
||||
}
|
||||
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
napi_value OnOnAbilityForeground(napi_env env, size_t argc, napi_value *argv)
|
||||
{
|
||||
if (observerForeground_ == nullptr) {
|
||||
observerForeground_ = new (std::nothrow) JSAbilityForegroundStateObserver(env);
|
||||
if (observerForeground_ == nullptr) {
|
||||
HILOG_ERROR("observerForeground_ is nullptr.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
}
|
||||
|
||||
if (observerForeground_->IsEmpty()) {
|
||||
int32_t ret = GetAppManagerInstance()->RegisterAbilityForegroundStateObserver(observerForeground_);
|
||||
if (ret != NO_ERROR) {
|
||||
HILOG_ERROR("Failed error: %{public}d.", ret);
|
||||
ThrowErrorByNativeErr(env, ret);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
}
|
||||
observerForeground_->AddJsObserverObject(argv[INDEX_ONE]);
|
||||
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
napi_value OnOff(napi_env env, size_t argc, napi_value *argv)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Not enough params when off.");
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
if (argc == ARGC_TWO && !AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object)) {
|
||||
HILOG_ERROR("Invalid param.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
std::string type = ParseParamType(env, argc, argv);
|
||||
if (type == ON_OFF_TYPE_ABILITY_FOREGROUND_STATE) {
|
||||
OnOffAbilityForeground(env, argc, argv);
|
||||
}
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
napi_value OnOffAbilityForeground(napi_env env, size_t argc, napi_value *argv)
|
||||
{
|
||||
if (observerForeground_ == nullptr) {
|
||||
HILOG_ERROR("Observer is nullptr.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
if (argc == ARGC_TWO) {
|
||||
observerForeground_->RemoveJsObserverObject(argv[INDEX_ONE]);
|
||||
} else {
|
||||
observerForeground_->RemoveAllJsObserverObject();
|
||||
}
|
||||
|
||||
if (observerForeground_->IsEmpty()) {
|
||||
int32_t ret = GetAppManagerInstance()->UnregisterAbilityForegroundStateObserver(observerForeground_);
|
||||
if (ret != NO_ERROR) {
|
||||
HILOG_ERROR("Failed error: %{public}d.", ret);
|
||||
ThrowErrorByNativeErr(env, ret);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
}
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
napi_value OnGetAbilityRunningInfos(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("%{public}s is called", __FUNCTION__);
|
||||
@ -337,9 +456,29 @@ private:
|
||||
|
||||
napi_value lastParam = (info.argc == ARGC_TWO) ? nullptr : info.argv[ARGC_TWO];
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JsAbilityManager::OnNotifySaveAsResult",
|
||||
env, CreateAsyncTaskWithLastParam(env,
|
||||
lastParam, std::move(execute), std::move(complete), &result));
|
||||
NapiAsyncTask::ScheduleHighQos("JsAbilityManager::OnNotifySaveAsResult", env,
|
||||
CreateAsyncTaskWithLastParam(env, lastParam, std::move(execute), std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value OnGetForegroundUIAbilities(napi_env env, size_t argc, napi_value *argv)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
NapiAsyncTask::CompleteCallback complete = [](napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
std::vector<AppExecFwk::AbilityStateData> list;
|
||||
int32_t ret = AbilityManagerClient::GetInstance()->GetForegroundUIAbilities(list);
|
||||
if (ret == ERR_OK) {
|
||||
task.ResolveWithNoError(env, CreateJsAbilityStateDataArray(env, list));
|
||||
} else {
|
||||
HILOG_ERROR("Failed error: %{public}d.", ret);
|
||||
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret)));
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (argc > ARGC_ZERO) ? argv[INDEX_ZERO] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::Schedule("JsAbilityManager::OnGetForegroundUIAbilities", env,
|
||||
CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@ -364,6 +503,10 @@ napi_value JsAbilityManagerInit(napi_env env, napi_value exportObj)
|
||||
BindNativeFunction(env, exportObj, "getTopAbility", moduleName, JsAbilityManager::GetTopAbility);
|
||||
BindNativeFunction(env, exportObj, "acquireShareData", moduleName, JsAbilityManager::AcquireShareData);
|
||||
BindNativeFunction(env, exportObj, "notifySaveAsResult", moduleName, JsAbilityManager::NotifySaveAsResult);
|
||||
BindNativeFunction(
|
||||
env, exportObj, "getForegroundUIAbilities", moduleName, JsAbilityManager::GetForegroundUIAbilities);
|
||||
BindNativeFunction(env, exportObj, "on", moduleName, JsAbilityManager::On);
|
||||
BindNativeFunction(env, exportObj, "off", moduleName, JsAbilityManager::Off);
|
||||
HILOG_INFO("JsAbilityManagerInit end");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 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
|
||||
@ -19,10 +19,10 @@
|
||||
|
||||
#include "ability_state.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "napi_remote_object.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "napi_remote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
@ -115,5 +115,36 @@ napi_value AbilityStateInit(napi_env env)
|
||||
napi_set_named_property(env, objValue, "BACKGROUNDING", CreateJsValue(env, AAFwk::AbilityState::BACKGROUNDING));
|
||||
return objValue;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
napi_value CreateJsAbilityStateData(napi_env env, const AbilityStateData &abilityStateData)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
napi_value object = nullptr;
|
||||
napi_create_object(env, &object);
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("ObjValue nullptr.");
|
||||
return nullptr;
|
||||
}
|
||||
napi_set_named_property(env, object, "bundleName", CreateJsValue(env, abilityStateData.bundleName));
|
||||
napi_set_named_property(env, object, "moduleName", CreateJsValue(env, abilityStateData.moduleName));
|
||||
napi_set_named_property(env, object, "abilityName", CreateJsValue(env, abilityStateData.abilityName));
|
||||
napi_set_named_property(env, object, "pid", CreateJsValue(env, abilityStateData.pid));
|
||||
napi_set_named_property(env, object, "uid", CreateJsValue(env, abilityStateData.uid));
|
||||
napi_set_named_property(env, object, "state", CreateJsValue(env, abilityStateData.abilityState));
|
||||
napi_set_named_property(env, object, "abilityType", CreateJsValue(env, abilityStateData.abilityType));
|
||||
return object;
|
||||
}
|
||||
|
||||
napi_value CreateJsAbilityStateDataArray(
|
||||
napi_env env, const std::vector<AppExecFwk::AbilityStateData> &abilityStateDatas)
|
||||
{
|
||||
napi_value arrayValue = nullptr;
|
||||
napi_create_array_with_length(env, abilityStateDatas.size(), &arrayValue);
|
||||
uint32_t index = 0;
|
||||
for (const auto &abilityStateData : abilityStateDatas) {
|
||||
napi_set_element(env, arrayValue, index++, CreateJsAbilityStateData(env, abilityStateData));
|
||||
}
|
||||
return arrayValue;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 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
|
||||
@ -17,12 +17,14 @@
|
||||
#define OHOS_ABILITY_RUNTIME_JS_ABILITY_MANAGER_UTILS_H
|
||||
|
||||
#include "ability_running_info.h"
|
||||
#include "extension_running_info.h"
|
||||
#include "ability_state_data.h"
|
||||
#include "element_name.h"
|
||||
#include "extension_running_info.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using OHOS::AppExecFwk::AbilityStateData;
|
||||
napi_value CreateJsAbilityRunningInfoArray(
|
||||
napi_env env, const std::vector<AAFwk::AbilityRunningInfo> &infos);
|
||||
napi_value CreateJsExtensionRunningInfoArray(
|
||||
@ -31,6 +33,9 @@ napi_value CreateJsAbilityRunningInfo(napi_env env, const AAFwk::AbilityRunningI
|
||||
napi_value CreateJsExtensionRunningInfo(napi_env env, const AAFwk::ExtensionRunningInfo &info);
|
||||
napi_value AbilityStateInit(napi_env env);
|
||||
napi_value CreateJsElementName(napi_env env, const AppExecFwk::ElementName &elementName);
|
||||
napi_value CreateJsAbilityStateData(napi_env env, const AbilityStateData &abilityStateData);
|
||||
napi_value CreateJsAbilityStateDataArray(
|
||||
napi_env env, const std::vector<AppExecFwk::AbilityStateData> &abilityStateDatas);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_JS_ABILITY_MANAGER_UTILS_H
|
||||
|
@ -19,6 +19,9 @@ class AbilityStage {
|
||||
onAcceptWant(want) {
|
||||
console.log('onAcceptWant, want:' + want.abilityName);
|
||||
}
|
||||
onNewProcessRequest(want) {
|
||||
console.log('onNewProcessRequest, want:' + want.abilityName);
|
||||
}
|
||||
onConfigurationUpdated(config) { }
|
||||
onConfigurationUpdate(newConfig) { }
|
||||
onMemoryLevel(level) { }
|
||||
|
@ -28,8 +28,6 @@ JSAppStateObserver::~JSAppStateObserver() = default;
|
||||
|
||||
void JSAppStateObserver::OnForegroundApplicationChanged(const AppStateData &appStateData)
|
||||
{
|
||||
HILOG_DEBUG("onForegroundApplicationChanged bundleName:%{public}s, uid:%{public}d, state:%{public}d",
|
||||
appStateData.bundleName.c_str(), appStateData.uid, appStateData.state);
|
||||
wptr<JSAppStateObserver> jsObserver = this;
|
||||
std::unique_ptr<NapiAsyncTask::CompleteCallback> complete = std::make_unique<NapiAsyncTask::CompleteCallback>
|
||||
([jsObserver, appStateData](napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
@ -44,12 +42,11 @@ void JSAppStateObserver::OnForegroundApplicationChanged(const AppStateData &appS
|
||||
std::unique_ptr<NapiAsyncTask::ExecuteCallback> execute = nullptr;
|
||||
NapiAsyncTask::Schedule("JSAppStateObserver::OnForegroundApplicationChanged",
|
||||
env_, std::make_unique<NapiAsyncTask>(callback, std::move(execute), std::move(complete)));
|
||||
HILOG_DEBUG("OnForegroundApplicationChanged end");
|
||||
}
|
||||
|
||||
void JSAppStateObserver::HandleOnForegroundApplicationChanged(const AppStateData &appStateData)
|
||||
{
|
||||
HILOG_DEBUG("HandleOnForegroundApplicationChanged bundleName:%{public}s, uid:%{public}d, state:%{public}d.",
|
||||
HILOG_INFO("HandleOnForegroundApplicationChanged bundleName:%{public}s, uid:%{public}d, state:%{public}d.",
|
||||
appStateData.bundleName.c_str(), appStateData.uid, appStateData.state);
|
||||
auto tmpMap = jsObserverObjectMap_;
|
||||
for (auto &item : tmpMap) {
|
||||
@ -61,7 +58,6 @@ void JSAppStateObserver::HandleOnForegroundApplicationChanged(const AppStateData
|
||||
|
||||
void JSAppStateObserver::OnAbilityStateChanged(const AbilityStateData &abilityStateData)
|
||||
{
|
||||
HILOG_INFO("OnAbilityStateChanged start");
|
||||
wptr<JSAppStateObserver> jsObserver = this;
|
||||
std::unique_ptr<NapiAsyncTask::CompleteCallback> complete = std::make_unique<NapiAsyncTask::CompleteCallback>
|
||||
([jsObserver, abilityStateData](napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
@ -91,7 +87,6 @@ void JSAppStateObserver::HandleOnAbilityStateChanged(const AbilityStateData &abi
|
||||
|
||||
void JSAppStateObserver::OnExtensionStateChanged(const AbilityStateData &abilityStateData)
|
||||
{
|
||||
HILOG_INFO("OnExtensionStateChanged start");
|
||||
wptr<JSAppStateObserver> jsObserver = this;
|
||||
std::unique_ptr<NapiAsyncTask::CompleteCallback> complete = std::make_unique<NapiAsyncTask::CompleteCallback>
|
||||
([jsObserver, abilityStateData](napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
@ -121,7 +116,6 @@ void JSAppStateObserver::HandleOnExtensionStateChanged(const AbilityStateData &a
|
||||
|
||||
void JSAppStateObserver::OnProcessCreated(const ProcessData &processData)
|
||||
{
|
||||
HILOG_INFO("OnProcessCreated start");
|
||||
wptr<JSAppStateObserver> jsObserver = this;
|
||||
std::unique_ptr<NapiAsyncTask::CompleteCallback> complete = std::make_unique<NapiAsyncTask::CompleteCallback>
|
||||
([jsObserver, processData](napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
@ -151,7 +145,6 @@ void JSAppStateObserver::HandleOnProcessCreated(const ProcessData &processData)
|
||||
|
||||
void JSAppStateObserver::OnProcessStateChanged(const ProcessData &processData)
|
||||
{
|
||||
HILOG_INFO("OnProcessStateChanged start");
|
||||
wptr<JSAppStateObserver> jsObserver = this;
|
||||
std::unique_ptr<NapiAsyncTask::CompleteCallback> complete = std::make_unique<NapiAsyncTask::CompleteCallback>
|
||||
([jsObserver, processData](napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
@ -181,7 +174,6 @@ void JSAppStateObserver::HandleOnProcessStateChanged(const ProcessData &processD
|
||||
|
||||
void JSAppStateObserver::OnProcessDied(const ProcessData &processData)
|
||||
{
|
||||
HILOG_INFO("OnProcessDied begin");
|
||||
wptr<JSAppStateObserver> jsObserver = this;
|
||||
std::unique_ptr<NapiAsyncTask::CompleteCallback> complete = std::make_unique<NapiAsyncTask::CompleteCallback>
|
||||
([jsObserver, processData](napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
@ -212,7 +204,7 @@ void JSAppStateObserver::HandleOnProcessDied(const ProcessData &processData)
|
||||
void JSAppStateObserver::CallJsFunction(
|
||||
napi_value value, const char *methodName, napi_value* argv, size_t argc)
|
||||
{
|
||||
HILOG_INFO("CallJsFunction start, method:%{public}s", methodName);
|
||||
HILOG_DEBUG("CallJsFunction start, method:%{public}s", methodName);
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("Failed to get object");
|
||||
return;
|
||||
@ -226,7 +218,7 @@ void JSAppStateObserver::CallJsFunction(
|
||||
}
|
||||
napi_value callResult = nullptr;
|
||||
napi_call_function(env_, value, method, argc, argv, &callResult);
|
||||
HILOG_INFO("CallJsFunction finish");
|
||||
HILOG_DEBUG("CallJsFunction finish");
|
||||
}
|
||||
|
||||
void JSAppStateObserver::AddJsObserverObject(const int32_t observerId, napi_value jsObserverObject)
|
||||
|
@ -109,10 +109,6 @@ class ApplicationContext {
|
||||
return this.__context_impl__.off(type, callbackId, callback);
|
||||
}
|
||||
|
||||
off(type, callback) {
|
||||
return this.__context_impl__.off(type, callback);
|
||||
}
|
||||
|
||||
createBundleContext(bundleName) {
|
||||
return this.__context_impl__.createBundleContext(bundleName);
|
||||
}
|
||||
@ -125,6 +121,10 @@ class ApplicationContext {
|
||||
return this.__context_impl__.createModuleContext(bundleName, moduleName);
|
||||
}
|
||||
|
||||
createModuleResourceManager(bundleName, moduleName) {
|
||||
return this.__context_impl__.createModuleResourceManager(bundleName, moduleName);
|
||||
}
|
||||
|
||||
getGroupDir(groupId, callback) {
|
||||
return this.__context_impl__.getGroupDir(groupId, callback);
|
||||
}
|
||||
@ -197,6 +197,10 @@ class ApplicationContext {
|
||||
return this.__context_impl__.tempDir;
|
||||
}
|
||||
|
||||
get resourceDir() {
|
||||
return this.__context_impl__.resourceDir;
|
||||
}
|
||||
|
||||
get filesDir() {
|
||||
return this.__context_impl__.filesDir;
|
||||
}
|
||||
|
@ -82,6 +82,10 @@ class Context {
|
||||
return this.__context_impl__.createModuleContext(bundleName, moduleName);
|
||||
}
|
||||
|
||||
createModuleResourceManager(bundleName, moduleName) {
|
||||
return this.__context_impl__.createModuleResourceManager(bundleName, moduleName);
|
||||
}
|
||||
|
||||
getApplicationContext() {
|
||||
return this.__context_impl__.getApplicationContext();
|
||||
}
|
||||
@ -114,6 +118,10 @@ class Context {
|
||||
return this.__context_impl__.tempDir;
|
||||
}
|
||||
|
||||
get resourceDir() {
|
||||
return this.__context_impl__.resourceDir;
|
||||
}
|
||||
|
||||
get filesDir() {
|
||||
return this.__context_impl__.filesDir;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ ohos_shared_library("appmanager") {
|
||||
|
||||
sources = [
|
||||
"app_manager_module.cpp",
|
||||
"js_app_foreground_state_observer.cpp",
|
||||
"js_app_manager.cpp",
|
||||
"js_app_manager_utils.cpp",
|
||||
"js_app_state_observer.cpp",
|
||||
|
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "js_app_foreground_state_observer.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_app_manager_utils.h"
|
||||
#include "js_runtime_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
}
|
||||
JSAppForegroundStateObserver::JSAppForegroundStateObserver(napi_env env) : env_(env) {}
|
||||
|
||||
void JSAppForegroundStateObserver::OnAppStateChanged(const AppStateData &appStateData)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (!valid_) {
|
||||
HILOG_ERROR("The app manager may has destoryed.");
|
||||
return;
|
||||
}
|
||||
wptr<JSAppForegroundStateObserver> self = this;
|
||||
std::unique_ptr<NapiAsyncTask::CompleteCallback> complete = std::make_unique<NapiAsyncTask::CompleteCallback>(
|
||||
[self, appStateData](napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
sptr<JSAppForegroundStateObserver> jsObserver = self.promote();
|
||||
if (jsObserver == nullptr) {
|
||||
HILOG_ERROR("Js Observer Sptr is nullptr.");
|
||||
return;
|
||||
}
|
||||
jsObserver->HandleOnAppStateChanged(appStateData);
|
||||
});
|
||||
napi_ref callback = nullptr;
|
||||
NapiAsyncTask::Schedule("JSAppForegroundStateObserver::OnAppStateChanged", env_,
|
||||
std::make_unique<NapiAsyncTask>(callback, nullptr, std::move(complete)));
|
||||
}
|
||||
|
||||
void JSAppForegroundStateObserver::HandleOnAppStateChanged(const AppStateData &appStateData)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
std::lock_guard<std::mutex> lock(jsObserverObjectSetLock_);
|
||||
for (auto &item : jsObserverObjectSet_) {
|
||||
napi_value obj = item->GetNapiValue();
|
||||
napi_value argv[] = { CreateJsAppStateData(env_, appStateData) };
|
||||
CallJsFunction(obj, "onAppStateChanged", argv, ARGC_ONE);
|
||||
}
|
||||
}
|
||||
|
||||
void JSAppForegroundStateObserver::CallJsFunction(
|
||||
const napi_value value, const char *methodName, const napi_value *argv, const size_t argc)
|
||||
{
|
||||
HILOG_DEBUG("Begin.");
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("value is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
napi_value method = nullptr;
|
||||
napi_get_named_property(env_, value, methodName, &method);
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Get name from object Failed.");
|
||||
return;
|
||||
}
|
||||
napi_value callResult = nullptr;
|
||||
napi_status status = napi_call_function(env_, value, method, argc, argv, &callResult);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("Call Js Function failed %{public}d.", status);
|
||||
}
|
||||
HILOG_DEBUG("End.");
|
||||
}
|
||||
|
||||
void JSAppForegroundStateObserver::AddJsObserverObject(const napi_value &jsObserverObject)
|
||||
{
|
||||
if (jsObserverObject == nullptr) {
|
||||
HILOG_ERROR("Observer is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetObserverObject(jsObserverObject) == nullptr) {
|
||||
std::lock_guard<std::mutex> lock(jsObserverObjectSetLock_);
|
||||
napi_ref ref = nullptr;
|
||||
napi_create_reference(env_, jsObserverObject, 1, &ref);
|
||||
jsObserverObjectSet_.emplace(std::shared_ptr<NativeReference>(reinterpret_cast<NativeReference *>(ref)));
|
||||
} else {
|
||||
HILOG_DEBUG("Observer is exists.");
|
||||
}
|
||||
}
|
||||
|
||||
void JSAppForegroundStateObserver::RemoveAllJsObserverObjects()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(jsObserverObjectSetLock_);
|
||||
jsObserverObjectSet_.clear();
|
||||
}
|
||||
|
||||
void JSAppForegroundStateObserver::RemoveJsObserverObject(const napi_value &jsObserverObject)
|
||||
{
|
||||
if (jsObserverObject == nullptr) {
|
||||
HILOG_ERROR("Observer is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto observer = GetObserverObject(jsObserverObject);
|
||||
if (observer != nullptr) {
|
||||
std::lock_guard<std::mutex> lock(jsObserverObjectSetLock_);
|
||||
jsObserverObjectSet_.erase(observer);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<NativeReference> JSAppForegroundStateObserver::GetObserverObject(const napi_value &jsObserverObject)
|
||||
{
|
||||
if (jsObserverObject == nullptr) {
|
||||
HILOG_ERROR("Observer is null.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(jsObserverObjectSetLock_);
|
||||
for (auto &observer : jsObserverObjectSet_) {
|
||||
if (observer == nullptr) {
|
||||
HILOG_ERROR("Invalid observer.");
|
||||
continue;
|
||||
}
|
||||
|
||||
napi_value value = observer->GetNapiValue();
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("Failed to get object.");
|
||||
continue;
|
||||
}
|
||||
|
||||
bool isEqual = false;
|
||||
napi_strict_equals(env_, value, jsObserverObject, &isEqual);
|
||||
if (isEqual) {
|
||||
return observer;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void JSAppForegroundStateObserver::SetValid(bool valid)
|
||||
{
|
||||
valid_ = valid;
|
||||
}
|
||||
|
||||
bool JSAppForegroundStateObserver::IsEmpty()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(jsObserverObjectSetLock_);
|
||||
return jsObserverObjectSet_.empty();
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_JS_APP_FOREGROUND_STATE_OBSERVER_H
|
||||
#define OHOS_ABILITY_RUNTIME_JS_APP_FOREGROUND_STATE_OBSERVER_H
|
||||
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
|
||||
#include "app_foreground_state_observer_stub.h"
|
||||
#include "event_handler.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using OHOS::AppExecFwk::AppForegroundStateObserverStub;
|
||||
using OHOS::AppExecFwk::AppStateData;
|
||||
class JSAppForegroundStateObserver : public AppForegroundStateObserverStub {
|
||||
public:
|
||||
explicit JSAppForegroundStateObserver(napi_env engine);
|
||||
virtual ~JSAppForegroundStateObserver() = default;
|
||||
void OnAppStateChanged(const AppStateData &appStateData);
|
||||
void HandleOnAppStateChanged(const AppStateData &appStateData);
|
||||
void CallJsFunction(const napi_value value, const char *methodName, const napi_value *argv, const size_t argc);
|
||||
void AddJsObserverObject(const napi_value &jsObserverObject);
|
||||
void RemoveJsObserverObject(const napi_value &jsObserverObject);
|
||||
void RemoveAllJsObserverObjects();
|
||||
std::shared_ptr<NativeReference> GetObserverObject(const napi_value &jsObserverObject);
|
||||
bool IsEmpty();
|
||||
void SetValid(bool valid);
|
||||
|
||||
private:
|
||||
napi_env env_;
|
||||
volatile bool valid_ = true;
|
||||
std::set<std::shared_ptr<NativeReference>> jsObserverObjectSet_;
|
||||
std::mutex jsObserverObjectSetLock_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_JS_APP_FOREGROUND_STATE_OBSERVER_H
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 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
|
||||
@ -21,19 +21,20 @@
|
||||
#include "ability_manager_interface.h"
|
||||
#include "ability_runtime_error_util.h"
|
||||
#include "app_mgr_interface.h"
|
||||
#include "event_runner.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "js_app_foreground_state_observer.h"
|
||||
#include "js_app_manager_utils.h"
|
||||
#include "js_app_state_observer.h"
|
||||
#include "js_error_utils.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "js_app_manager_utils.h"
|
||||
#include "event_runner.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "js_app_state_observer.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
@ -47,6 +48,7 @@ constexpr size_t ARGC_TWO = 2;
|
||||
constexpr size_t ARGC_THREE = 3;
|
||||
constexpr const char* ON_OFF_TYPE = "applicationState";
|
||||
constexpr const char* ON_OFF_TYPE_SYNC = "applicationStateEvent";
|
||||
constexpr const char *ON_OFF_TYPE_APP_FOREGROUND_STATE = "appForegroundState";
|
||||
|
||||
class JsAppManager final {
|
||||
public:
|
||||
@ -59,6 +61,9 @@ public:
|
||||
HILOG_INFO("Set valid false");
|
||||
observer_->SetValid(false);
|
||||
}
|
||||
if (observerForeground_ != nullptr) {
|
||||
observerForeground_->SetValid(false);
|
||||
}
|
||||
}
|
||||
|
||||
static void Finalizer(napi_env env, void* data, void* hint)
|
||||
@ -131,11 +136,17 @@ public:
|
||||
{
|
||||
GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnGetRunningProcessInfoByBundleName);
|
||||
}
|
||||
|
||||
static napi_value IsApplicationRunning(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnIsApplicationRunning);
|
||||
}
|
||||
private:
|
||||
sptr<OHOS::AppExecFwk::IAppMgr> appManager_ = nullptr;
|
||||
sptr<OHOS::AAFwk::IAbilityManager> abilityManager_ = nullptr;
|
||||
sptr<JSAppStateObserver> observer_ = nullptr;
|
||||
sptr<JSAppStateObserver> observerSync_ = nullptr;
|
||||
sptr<JSAppForegroundStateObserver> observerForeground_ = nullptr;
|
||||
int32_t serialNumber_ = 0;
|
||||
|
||||
napi_value OnOn(napi_env env, size_t argc, napi_value* argv)
|
||||
@ -144,7 +155,10 @@ private:
|
||||
std::string type = ParseParamType(env, argc, argv);
|
||||
if (type == ON_OFF_TYPE_SYNC) {
|
||||
return OnOnNew(env, argc, argv);
|
||||
} else if (type == ON_OFF_TYPE_APP_FOREGROUND_STATE) {
|
||||
return OnOnForeground(env, argc, argv);
|
||||
}
|
||||
|
||||
return OnOnOld(env, argc, argv);
|
||||
}
|
||||
|
||||
@ -237,13 +251,51 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
napi_value OnOff(napi_env env, size_t argc, napi_value* argv)
|
||||
napi_value OnOnForeground(napi_env env, size_t argc, napi_value *argv)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (argc < ARGC_TWO) {
|
||||
HILOG_ERROR("Not enough params.");
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
if (!AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object)) {
|
||||
HILOG_ERROR("Invalid param.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
if (observerForeground_ == nullptr) {
|
||||
observerForeground_ = new (std::nothrow) JSAppForegroundStateObserver(env);
|
||||
}
|
||||
|
||||
if (appManager_ == nullptr || observerForeground_ == nullptr) {
|
||||
HILOG_ERROR("AppManager or observer is nullptr.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
if (observerForeground_->IsEmpty()) {
|
||||
int32_t ret = appManager_->RegisterAppForegroundStateObserver(observerForeground_);
|
||||
if (ret != NO_ERROR) {
|
||||
HILOG_ERROR("Failed error: %{public}d.", ret);
|
||||
ThrowErrorByNativeErr(env, ret);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
}
|
||||
observerForeground_->AddJsObserverObject(argv[INDEX_ONE]);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
napi_value OnOff(napi_env env, size_t argc, napi_value *argv)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
std::string type = ParseParamType(env, argc, argv);
|
||||
if (type == ON_OFF_TYPE_SYNC) {
|
||||
return OnOffNew(env, argc, argv);
|
||||
} else if (type == ON_OFF_TYPE_APP_FOREGROUND_STATE) {
|
||||
return OnOffForeground(env, argc, argv);
|
||||
}
|
||||
|
||||
return OnOffOld(env, argc, argv);
|
||||
}
|
||||
|
||||
@ -336,7 +388,41 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
napi_value OnGetForegroundApplications(napi_env env, size_t argc, napi_value* argv)
|
||||
napi_value OnOffForeground(napi_env env, size_t argc, napi_value *argv)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (observerForeground_ == nullptr || appManager_ == nullptr) {
|
||||
HILOG_ERROR("Observer or appManager nullptr.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
if (argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Not enough params when off.");
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
if (argc == ARGC_ONE) {
|
||||
observerForeground_->RemoveAllJsObserverObjects();
|
||||
} else if (argc == ARGC_TWO) {
|
||||
if (!AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object)) {
|
||||
HILOG_ERROR("Invalid param.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
observerForeground_->RemoveJsObserverObject(argv[INDEX_ONE]);
|
||||
}
|
||||
if (observerForeground_->IsEmpty()) {
|
||||
int32_t ret = appManager_->UnregisterAppForegroundStateObserver(observerForeground_);
|
||||
if (ret != NO_ERROR) {
|
||||
HILOG_ERROR("Failed error: %{public}d.", ret);
|
||||
ThrowErrorByNativeErr(env, ret);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
}
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
napi_value OnGetForegroundApplications(napi_env env, size_t argc, napi_value *argv)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
@ -709,6 +795,51 @@ private:
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value OnIsApplicationRunning(napi_env env, size_t argc, napi_value *argv)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (argc < ARGC_ONE) {
|
||||
HILOG_ERROR("Params not match.");
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
std::string bundleName;
|
||||
if (!ConvertFromJsValue(env, argv[0], bundleName)) {
|
||||
HILOG_ERROR("Get bundle name wrong.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
auto innerErrorCode = std::make_shared<int32_t>(ERR_OK);
|
||||
auto isRunning = std::make_shared<bool>(false);
|
||||
wptr<OHOS::AppExecFwk::IAppMgr> appManager = appManager_;
|
||||
NapiAsyncTask::ExecuteCallback execute =
|
||||
[bundleName, appManager, innerErrorCode, isRunning]() {
|
||||
sptr<OHOS::AppExecFwk::IAppMgr> appMgr = appManager.promote();
|
||||
if (appMgr == nullptr) {
|
||||
HILOG_ERROR("App manager is nullptr.");
|
||||
*innerErrorCode = static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER);
|
||||
return;
|
||||
}
|
||||
*innerErrorCode = appMgr->IsApplicationRunning(bundleName, *isRunning);
|
||||
};
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[innerErrorCode, isRunning](napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
if (*innerErrorCode == ERR_OK) {
|
||||
task.ResolveWithNoError(env, CreateJsValue(env, *isRunning));
|
||||
} else {
|
||||
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrorCode));
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnIsApplicationRunning",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, std::move(execute), std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CheckOnOffType(napi_env env, size_t argc, napi_value* argv)
|
||||
{
|
||||
if (argc < ARGC_ONE) {
|
||||
@ -805,6 +936,8 @@ napi_value JsAppManagerInit(napi_env env, napi_value exportObj)
|
||||
JsAppManager::GetProcessMemoryByPid);
|
||||
BindNativeFunction(env, exportObj, "getRunningProcessInfoByBundleName", moduleName,
|
||||
JsAppManager::GetRunningProcessInfoByBundleName);
|
||||
BindNativeFunction(env, exportObj, "isApplicationRunning", moduleName,
|
||||
JsAppManager::IsApplicationRunning);
|
||||
HILOG_DEBUG("end");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
@ -36,6 +36,8 @@ napi_value CreateJsAppStateData(napi_env env, const AppStateData &appStateData)
|
||||
napi_set_named_property(env, object, "bundleName", CreateJsValue(env, appStateData.bundleName));
|
||||
napi_set_named_property(env, object, "uid", CreateJsValue(env, appStateData.uid));
|
||||
napi_set_named_property(env, object, "state", CreateJsValue(env, appStateData.state));
|
||||
napi_set_named_property(env, object, "isSplitScreenMode", CreateJsValue(env, appStateData.isSplitScreenMode));
|
||||
napi_set_named_property(env, object, "isFloatingWindowMode", CreateJsValue(env, appStateData.isFloatingWindowMode));
|
||||
HILOG_DEBUG("end.");
|
||||
return object;
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ static napi_value InitAreaModeObject(napi_env env)
|
||||
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "EL1", 0));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "EL2", 1));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "EL3", 2));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "EL4", 3));
|
||||
|
||||
return object;
|
||||
}
|
||||
|
50
frameworks/js/napi/auto_fill_extension_ability/BUILD.gn
Normal file
50
frameworks/js/napi/auto_fill_extension_ability/BUILD.gn
Normal file
@ -0,0 +1,50 @@
|
||||
# Copyright (c) 2023 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("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
es2abc_gen_abc("gen_auto_fill_extension_ability_abc") {
|
||||
src_js = rebase_path("auto_fill_extension_ability.js")
|
||||
dst_file = rebase_path(target_out_dir + "/auto_fill_extension_ability.abc")
|
||||
in_puts = [ "auto_fill_extension_ability.js" ]
|
||||
out_puts = [ target_out_dir + "/auto_fill_extension_ability.abc" ]
|
||||
extra_args = [ "--module" ]
|
||||
}
|
||||
|
||||
gen_js_obj("auto_fill_extension_ability_js") {
|
||||
input = "auto_fill_extension_ability.js"
|
||||
output = target_out_dir + "/auto_fill_extension_ability.o"
|
||||
}
|
||||
|
||||
gen_js_obj("auto_fill_extension_ability_abc") {
|
||||
input = get_label_info(":gen_auto_fill_extension_ability_abc",
|
||||
"target_out_dir") + "/auto_fill_extension_ability.abc"
|
||||
output = target_out_dir + "/auto_fill_extension_ability_abc.o"
|
||||
dep = ":gen_auto_fill_extension_ability_abc"
|
||||
}
|
||||
|
||||
ohos_shared_library("autofillextensionability_napi") {
|
||||
sources = [ "auto_fill_extension_ability_module.cpp" ]
|
||||
|
||||
deps = [
|
||||
":auto_fill_extension_ability_abc",
|
||||
":auto_fill_extension_ability_js",
|
||||
]
|
||||
|
||||
external_deps = [ "napi:ace_napi" ]
|
||||
|
||||
relative_install_dir = "module/app/ability"
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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.
|
||||
*/
|
||||
|
||||
let ExtensionAbility = requireNapi('app.ability.ExtensionAbility');
|
||||
|
||||
class AutoFillExtensionAbility extends ExtensionAbility {
|
||||
onCreate() {
|
||||
console.log('onCreate');
|
||||
}
|
||||
|
||||
onFillRequest(session, request, callback) {
|
||||
console.log('onFillRequest');
|
||||
}
|
||||
|
||||
onSaveRequest(session, request, callback) {
|
||||
console.log('onSaveRequest');
|
||||
}
|
||||
|
||||
onSessionDestroy(session) {
|
||||
console.log('onSessionDestroy');
|
||||
}
|
||||
|
||||
onForeground() {
|
||||
console.log('onForeground');
|
||||
}
|
||||
|
||||
onBackground() {
|
||||
console.log('onBackground');
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
console.log('onDestroy');
|
||||
}
|
||||
}
|
||||
|
||||
export default AutoFillExtensionAbility;
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "native_engine/native_engine.h"
|
||||
|
||||
extern const char _binary_auto_fill_extension_ability_js_start[];
|
||||
extern const char _binary_auto_fill_extension_ability_js_end[];
|
||||
extern const char _binary_auto_fill_extension_ability_abc_start[];
|
||||
extern const char _binary_auto_fill_extension_ability_abc_end[];
|
||||
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_filename = "app/ability/libautofillextensionability_napi.so/auto_fill_extension_ability.js",
|
||||
.nm_modname = "app.ability.AutoFillExtensionAbility",
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor)) void NAPI_app_ability_AutoFillExtensionAbility_AutoRegister()
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) void NAPI_app_ability_AutoFillExtensionAbility_GetJSCode(
|
||||
const char **buf, int *bufLen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_auto_fill_extension_ability_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_auto_fill_extension_ability_js_end - _binary_auto_fill_extension_ability_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) void NAPI_app_ability_AutoFillExtensionAbility_GetABCCode(
|
||||
const char **buf, int *buflen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_auto_fill_extension_ability_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_auto_fill_extension_ability_abc_end - _binary_auto_fill_extension_ability_abc_start;
|
||||
}
|
||||
}
|
50
frameworks/js/napi/auto_fill_extension_context/BUILD.gn
Executable file
50
frameworks/js/napi/auto_fill_extension_context/BUILD.gn
Executable file
@ -0,0 +1,50 @@
|
||||
# Copyright (c) 2023 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("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
es2abc_gen_abc("gen_auto_fill_extension_context_abc") {
|
||||
src_js = rebase_path("auto_fill_extension_context.js")
|
||||
dst_file = rebase_path(target_out_dir + "/auto_fill_extension_context.abc")
|
||||
in_puts = [ "auto_fill_extension_context.js" ]
|
||||
out_puts = [ target_out_dir + "/auto_fill_extension_context.abc" ]
|
||||
extra_args = [ "--module" ]
|
||||
}
|
||||
|
||||
gen_js_obj("auto_fill_extension_context_js") {
|
||||
input = "auto_fill_extension_context.js"
|
||||
output = target_out_dir + "/auto_fill_extension_context.o"
|
||||
}
|
||||
|
||||
gen_js_obj("auto_fill_extension_context_abc") {
|
||||
input = get_label_info(":gen_auto_fill_extension_context_abc",
|
||||
"target_out_dir") + "/auto_fill_extension_context.abc"
|
||||
output = target_out_dir + "/auto_fill_extension_context_abc.o"
|
||||
dep = ":gen_auto_fill_extension_context_abc"
|
||||
}
|
||||
|
||||
ohos_shared_library("autofillextensioncontext_napi") {
|
||||
sources = [ "auto_fill_extension_context_module.cpp" ]
|
||||
|
||||
deps = [
|
||||
":auto_fill_extension_context_abc",
|
||||
":auto_fill_extension_context_js",
|
||||
]
|
||||
|
||||
external_deps = [ "napi:ace_napi" ]
|
||||
|
||||
relative_install_dir = "module/application"
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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.
|
||||
*/
|
||||
|
||||
let ExtensionContext = requireNapi('application.ExtensionContext');
|
||||
|
||||
class AutoFillExtensionContext extends ExtensionContext {
|
||||
constructor(obj) {
|
||||
super(obj);
|
||||
}
|
||||
}
|
||||
|
||||
export default AutoFillExtensionContext;
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "native_engine/native_engine.h"
|
||||
|
||||
extern const char _binary_auto_fill_extension_context_js_start[];
|
||||
extern const char _binary_auto_fill_extension_context_js_end[];
|
||||
extern const char _binary_auto_fill_extension_context_abc_start[];
|
||||
extern const char _binary_auto_fill_extension_context_abc_end[];
|
||||
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_filename = "application/autofillextensioncontext_napi.so/auto_fill_extension_context.js",
|
||||
.nm_modname = "application.AutoFillExtensionContext",
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor)) void NAPI_application_AutoFillExtensionContext_AutoRegister()
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) void NAPI_application_AutoFillExtensionContext_GetJSCode(
|
||||
const char **buf, int *bufLen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_auto_fill_extension_context_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_auto_fill_extension_context_js_end - _binary_auto_fill_extension_context_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) void NAPI_application_AutoFillExtensionContext_GetABCCode(
|
||||
const char **buf, int *buflen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_auto_fill_extension_context_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_auto_fill_extension_context_abc_end - _binary_auto_fill_extension_context_abc_start;
|
||||
}
|
||||
}
|
53
frameworks/js/napi/auto_fill_manager/BUILD.gn
Normal file
53
frameworks/js/napi/auto_fill_manager/BUILD.gn
Normal file
@ -0,0 +1,53 @@
|
||||
# Copyright (c) 2023 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/arkui/ace_engine/ace_config.gni")
|
||||
|
||||
ohos_shared_library("autofillmanager_napi") {
|
||||
sources = [
|
||||
"auto_fill_manager_module.cpp",
|
||||
"js_auto_fill_manager.cpp",
|
||||
"js_save_request_callback.cpp",
|
||||
]
|
||||
|
||||
configs = [ "${ability_runtime_services_path}/common:common_config" ]
|
||||
|
||||
include_dirs = [
|
||||
"${ability_runtime_path}/interfaces/inner_api/auto_fill_manager/include",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/auto_fill_manager:auto_fill_manager",
|
||||
"${ability_runtime_innerkits_path}/runtime:runtime",
|
||||
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
|
||||
"${ability_runtime_native_path}/ability/native:ability_business_error",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:view_data",
|
||||
"hilog:libhilog",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [ "ace_engine:ace_uicontent" ]
|
||||
}
|
||||
|
||||
relative_install_dir = "module/app/ability"
|
||||
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "js_auto_fill_manager.h"
|
||||
#include "napi/native_api.h"
|
||||
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_register_func = OHOS::AbilityRuntime::JsAutoFillManagerInit,
|
||||
.nm_modname = "app.ability.autoFillManager",
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor)) void NAPI_app_ability_autofillmanager_AutoRegister(void)
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
166
frameworks/js/napi/auto_fill_manager/js_auto_fill_manager.cpp
Normal file
166
frameworks/js/napi/auto_fill_manager/js_auto_fill_manager.cpp
Normal file
@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "js_auto_fill_manager.h"
|
||||
|
||||
#include "ability_business_error.h"
|
||||
#include "auto_fill_manager.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "js_error_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr int32_t INDEX_ZERO = 0;
|
||||
constexpr int32_t INDEX_ONE = 1;
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
} // namespace
|
||||
|
||||
void JsAutoFillManager::Finalizer(napi_env env, void *data, void *hint)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
std::unique_ptr<JsAutoFillManager>(static_cast<JsAutoFillManager *>(data));
|
||||
}
|
||||
|
||||
napi_value JsAutoFillManager::RequestAutoSave(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsAutoFillManager, OnRequestAutoSave);
|
||||
}
|
||||
|
||||
napi_value JsAutoFillManager::OnRequestAutoSave(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (info.argc < ARGC_ONE) {
|
||||
HILOG_ERROR("The param is invalid.");
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
napi_value instanceIdValue = nullptr;
|
||||
if (napi_get_named_property(env, info.argv[INDEX_ZERO], "instanceId_", &instanceIdValue) != napi_ok) {
|
||||
HILOG_ERROR("Get function by name failed.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
int32_t instanceId = -1;
|
||||
if (!ConvertFromJsValue(env, instanceIdValue, instanceId)) {
|
||||
HILOG_ERROR("Failed to parse type.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
auto saveCallback = GetCallbackByInstanceId(instanceId);
|
||||
if (saveCallback != nullptr) {
|
||||
HILOG_ERROR("There are other requests in progress.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
auto autoSaveMangerFunc = std::bind(&JsAutoFillManager::OnRequestAutoSaveDone, this, std::placeholders::_1);
|
||||
saveCallback = std::make_shared<JsSaveRequestCallback>(env, instanceId, autoSaveMangerFunc);
|
||||
if (saveCallback == nullptr) {
|
||||
HILOG_ERROR("saveCallback is nullptr.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
if (info.argc != ARGC_ONE) {
|
||||
if (!CheckTypeForNapiValue(env, info.argv[INDEX_ONE], napi_object)) {
|
||||
HILOG_ERROR("Second input parameter error.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
saveCallback->Register(info.argv[INDEX_ONE]);
|
||||
}
|
||||
OnRequestAutoSaveInner(env, instanceId, saveCallback);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
void JsAutoFillManager::OnRequestAutoSaveInner(napi_env env, int32_t instanceId,
|
||||
const std::shared_ptr<JsSaveRequestCallback> &saveRequestCallback)
|
||||
{
|
||||
auto uiContent = Ace::UIContent::GetUIContent(instanceId);
|
||||
if (uiContent == nullptr) {
|
||||
HILOG_ERROR("UIContent is nullptr.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
|
||||
return;
|
||||
}
|
||||
if (uiContent->CheckNeedAutoSave()) {
|
||||
AbilityBase::ViewData viewData;
|
||||
uiContent->DumpViewData(viewData);
|
||||
auto ret = AutoFillManager::GetInstance().RequestAutoSave(uiContent, viewData, saveRequestCallback);
|
||||
if (ret != ERR_OK) {
|
||||
HILOG_ERROR("Request auto save error[%{public}d].", ret);
|
||||
ThrowError(env, GetJsErrorCodeByNativeError(ret));
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mutexLock_);
|
||||
saveRequestObject_.emplace(instanceId, saveRequestCallback);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<JsSaveRequestCallback> JsAutoFillManager::GetCallbackByInstanceId(int32_t instanceId)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutexLock_);
|
||||
auto iter = saveRequestObject_.find(instanceId);
|
||||
if (iter != saveRequestObject_.end()) {
|
||||
return iter->second.lock();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void JsAutoFillManager::OnRequestAutoSaveDone(int32_t instanceId)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutexLock_);
|
||||
auto iter = saveRequestObject_.find(instanceId);
|
||||
if (iter != saveRequestObject_.end()) {
|
||||
saveRequestObject_.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
napi_value CreateJsAutoFillType(napi_env env)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
napi_value objValue = nullptr;
|
||||
napi_create_object(env, &objValue);
|
||||
|
||||
napi_set_named_property(env, objValue, "UNSPECIFIED", CreateJsValue(env, AbilityBase::AutoFillType::UNSPECIFIED));
|
||||
napi_set_named_property(env, objValue, "PASSWORD", CreateJsValue(env, AbilityBase::AutoFillType::PASSWORD));
|
||||
napi_set_named_property(env, objValue, "USER_NAME", CreateJsValue(env, AbilityBase::AutoFillType::USER_NAME));
|
||||
napi_set_named_property(env, objValue, "NEW_PASSWORD", CreateJsValue(env, AbilityBase::AutoFillType::NEW_PASSWORD));
|
||||
return objValue;
|
||||
}
|
||||
|
||||
napi_value JsAutoFillManagerInit(napi_env env, napi_value exportObj)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (env == nullptr || exportObj == nullptr) {
|
||||
HILOG_ERROR("Env or exportObj nullptr.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto jsAbilityAutoFillManager = std::make_unique<JsAutoFillManager>();
|
||||
napi_wrap(env, exportObj, jsAbilityAutoFillManager.release(), JsAutoFillManager::Finalizer, nullptr, nullptr);
|
||||
|
||||
napi_set_named_property(env, exportObj, "AutoFillType", CreateJsAutoFillType(env));
|
||||
|
||||
const char *moduleName = "JsAutoFillManager";
|
||||
BindNativeFunction(env, exportObj, "requestAutoSave", moduleName, JsAutoFillManager::RequestAutoSave);
|
||||
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
49
frameworks/js/napi/auto_fill_manager/js_auto_fill_manager.h
Normal file
49
frameworks/js/napi/auto_fill_manager/js_auto_fill_manager.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_JS_AUTO_FILL_MANAGER_H
|
||||
#define OHOS_ABILITY_RUNTIME_JS_AUTO_FILL_MANAGER_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "js_auto_fill_manager.h"
|
||||
#include "js_save_request_callback.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "native_engine/native_value.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class JsAutoFillManager {
|
||||
public:
|
||||
JsAutoFillManager() = default;
|
||||
~JsAutoFillManager() = default;
|
||||
static void Finalizer(napi_env env, void *data, void *hint);
|
||||
static napi_value RequestAutoSave(napi_env env, napi_callback_info info);
|
||||
|
||||
private:
|
||||
napi_value OnRequestAutoSave(napi_env env, NapiCallbackInfo &info);
|
||||
void OnRequestAutoSaveInner(napi_env env, int32_t instanceId,
|
||||
const std::shared_ptr<JsSaveRequestCallback> &saveRequestCallback);
|
||||
std::shared_ptr<JsSaveRequestCallback> GetCallbackByInstanceId(int32_t instanceId);
|
||||
void OnRequestAutoSaveDone(int32_t instanceId);
|
||||
|
||||
std::mutex mutexLock_;
|
||||
std::map<int32_t, std::weak_ptr<JsSaveRequestCallback>> saveRequestObject_;
|
||||
};
|
||||
napi_value JsAutoFillManagerInit(napi_env env, napi_value exportObj);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_JS_AUTO_FILL_MANAGER_H
|
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "js_save_request_callback.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_auto_fill_manager.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
const std::string METHOD_ON_SAVE_REQUEST_SUCCESS = "onSuccess";
|
||||
const std::string METHOD_ON_SAVE_REQUEST_FAILED = "onFailure";
|
||||
} // namespace
|
||||
JsSaveRequestCallback::JsSaveRequestCallback(napi_env env, int32_t instanceId, AutoFillManagerFunc autoFillManagerFunc)
|
||||
: env_(env), instanceId_(instanceId), autoFillManagerFunc_(autoFillManagerFunc){}
|
||||
|
||||
JsSaveRequestCallback::~JsSaveRequestCallback() {}
|
||||
|
||||
void JsSaveRequestCallback::OnSaveRequestSuccess()
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
JSCallFunction(METHOD_ON_SAVE_REQUEST_SUCCESS);
|
||||
if (autoFillManagerFunc_ != nullptr) {
|
||||
autoFillManagerFunc_(instanceId_);
|
||||
}
|
||||
}
|
||||
|
||||
void JsSaveRequestCallback::OnSaveRequestFailed()
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
JSCallFunction(METHOD_ON_SAVE_REQUEST_FAILED);
|
||||
if (autoFillManagerFunc_ != nullptr) {
|
||||
autoFillManagerFunc_(instanceId_);
|
||||
}
|
||||
}
|
||||
|
||||
void JsSaveRequestCallback::Register(napi_value value)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
std::lock_guard<std::mutex> lock(callbackMutex_);
|
||||
if (IsJsCallbackEquals(callback_, value)) {
|
||||
HILOG_ERROR("The current callback already exists.");
|
||||
return;
|
||||
}
|
||||
|
||||
napi_ref ref = nullptr;
|
||||
napi_create_reference(env_, value, 1, &ref);
|
||||
callback_ = std::unique_ptr<NativeReference>(reinterpret_cast<NativeReference *>(ref));
|
||||
}
|
||||
|
||||
void JsSaveRequestCallback::JSCallFunction(const std::string &methodName)
|
||||
{
|
||||
NapiAsyncTask::CompleteCallback complete = [this, methodName](napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
JSCallFunctionWorker(methodName);
|
||||
};
|
||||
|
||||
NapiAsyncTask::Schedule("JsSaveRequestCallback::JSCallFunction:" + methodName,
|
||||
env_,
|
||||
CreateAsyncTaskWithLastParam(env_, nullptr, nullptr, std::move(complete), nullptr));
|
||||
}
|
||||
|
||||
void JsSaveRequestCallback::JSCallFunctionWorker(const std::string &methodName)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(callbackMutex_);
|
||||
if (callback_ == nullptr) {
|
||||
HILOG_ERROR("callback is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto obj = callback_->GetNapiValue();
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get value.");
|
||||
return;
|
||||
}
|
||||
|
||||
napi_value funcObject;
|
||||
if (napi_get_named_property(env_, obj, methodName.c_str(), &funcObject) != napi_ok) {
|
||||
HILOG_ERROR("Get function by name failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
napi_call_function(env_, obj, funcObject, 0, NULL, nullptr);
|
||||
}
|
||||
|
||||
bool JsSaveRequestCallback::IsJsCallbackEquals(std::shared_ptr<NativeReference> callback, napi_value value)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
HILOG_ERROR("Invalid jsCallback.");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto object = callback->GetNapiValue();
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("Failed to get object.");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
if (napi_strict_equals(env_, object, value, &result) != napi_ok) {
|
||||
HILOG_ERROR("Object does not match value.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_JS_SAVE_REQUEST_CALLBACK_H
|
||||
#define OHOS_ABILITY_RUNTIME_JS_SAVE_REQUEST_CALLBACK_H
|
||||
|
||||
#include "save_request_callback_interface.h"
|
||||
#include "native_engine/native_value.h"
|
||||
|
||||
class NativeReference;
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using AutoFillManagerFunc = std::function<void(int32_t)>;
|
||||
class JsSaveRequestCallback : public ISaveRequestCallback {
|
||||
public:
|
||||
JsSaveRequestCallback(napi_env env, int32_t instanceId, AutoFillManagerFunc autoFillManagerFunc);
|
||||
virtual ~JsSaveRequestCallback();
|
||||
|
||||
void Register(napi_value value);
|
||||
void OnSaveRequestSuccess() override;
|
||||
void OnSaveRequestFailed() override;
|
||||
|
||||
private:
|
||||
void JSCallFunction(const std::string &methodName);
|
||||
void JSCallFunctionWorker(const std::string &methodName);
|
||||
bool IsJsCallbackEquals(std::shared_ptr<NativeReference> callback, napi_value value);
|
||||
|
||||
napi_env env_;
|
||||
std::shared_ptr<NativeReference> callback_;
|
||||
std::mutex callbackMutex_;
|
||||
int32_t instanceId_;
|
||||
AutoFillManagerFunc autoFillManagerFunc_ = nullptr;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_JS_SAVE_REQUEST_CALLBACK_H
|
@ -68,17 +68,8 @@ class Callee extends rpc.RemoteObject {
|
||||
|
||||
onRemoteMessageRequest(code, data, reply, option) {
|
||||
console.log('Callee onRemoteMessageRequest code [' + typeof code + ' ' + code + ']');
|
||||
if (this.startUpNewRule && rpc.IPCSkeleton.isLocalCalling()) {
|
||||
console.log('Use new start up rule, check caller permission.');
|
||||
let accessManger = accessControl.createAtManager();
|
||||
let accessTokenId = rpc.IPCSkeleton.getCallingTokenId();
|
||||
let grantStatus =
|
||||
accessManger.verifyAccessTokenSync(accessTokenId, PERMISSION_ABILITY_BACKGROUND_COMMUNICATION);
|
||||
if (grantStatus === accessControl.GrantStatus.PERMISSION_DENIED) {
|
||||
console.log(
|
||||
'Callee onRemoteMessageRequest error, the Caller does not have PERMISSION_ABILITY_BACKGROUND_COMMUNICATION');
|
||||
return false;
|
||||
}
|
||||
if (!this.StartUpRuleCheck()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof code !== 'number' || typeof data !== 'object' ||
|
||||
@ -163,6 +154,22 @@ class Callee extends rpc.RemoteObject {
|
||||
this.callList.delete(method);
|
||||
console.log('Callee off method [' + method + ']');
|
||||
}
|
||||
|
||||
StartUpRuleCheck() {
|
||||
if (this.startUpNewRule && rpc.IPCSkeleton.isLocalCalling()) {
|
||||
console.log('Use new start up rule, check caller permission.');
|
||||
let accessManger = accessControl.createAtManager();
|
||||
let accessTokenId = rpc.IPCSkeleton.getCallingTokenId();
|
||||
let grantStatus =
|
||||
accessManger.verifyAccessTokenSync(accessTokenId, PERMISSION_ABILITY_BACKGROUND_COMMUNICATION);
|
||||
if (grantStatus === accessControl.GrantStatus.PERMISSION_DENIED) {
|
||||
console.log(
|
||||
'Callee onRemoteMessageRequest error, the Caller does not have PERMISSION_ABILITY_BACKGROUND_COMMUNICATION');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export default Callee;
|
||||
|
@ -55,42 +55,20 @@ class Caller {
|
||||
|
||||
call(method, data) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
console.log('Caller call method [' + method + ']');
|
||||
if (typeof method !== 'string' || typeof data !== 'object') {
|
||||
console.log('Caller call ' + typeof method + ' ' + typeof data);
|
||||
reject(new BusinessError(ERROR_CODE_INVALID_PARAM));
|
||||
return;
|
||||
}
|
||||
|
||||
if (method === '' || data == null) {
|
||||
console.log('Caller call ' + method + ', ' + data);
|
||||
reject(new BusinessError(ERROR_CODE_INVALID_PARAM));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.releaseState === true) {
|
||||
console.log('Caller call this.callee release');
|
||||
reject(new BusinessError(ERROR_CODE_CALLER_RELEASED));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.__call_obj__.callee == null) {
|
||||
console.log('Caller call this.callee is nullptr');
|
||||
reject(new BusinessError(ERROR_CODE_CLAAEE_INVALID));
|
||||
const checkError = this.callCheck(method, data);
|
||||
if (checkError != null) {
|
||||
reject(checkError);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Caller call msgData rpc.MessageSequence create');
|
||||
let msgData = rpc.MessageSequence.create();
|
||||
msgData.writeString(method);
|
||||
let msgData = this.buildMsgData(method, data);
|
||||
let msgReply = rpc.MessageSequence.create();
|
||||
let option = rpc.MessageOption();
|
||||
msgData.writeParcelable(data);
|
||||
|
||||
let retData = undefined;
|
||||
try {
|
||||
retData = await this.__call_obj__.callee.sendMessageRequest(EVENT_CALL_NOTIFY, msgData, msgReply,
|
||||
option);
|
||||
rpc.MessageOption());
|
||||
console.log('Caller call msgData rpc.sendMessageRequest called');
|
||||
if (retData.errCode !== 0) {
|
||||
msgData.reclaim();
|
||||
@ -107,7 +85,6 @@ class Caller {
|
||||
let retval = retData.reply.readInt();
|
||||
let str = retData.reply.readString();
|
||||
if (retval === REQUEST_SUCCESS && str === 'object') {
|
||||
console.log('Caller call return str ' + str);
|
||||
msgData.reclaim();
|
||||
msgReply.reclaim();
|
||||
} else {
|
||||
@ -132,42 +109,21 @@ class Caller {
|
||||
callWithResult(method, data) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
console.log('Caller callWithResult method [' + method + ']');
|
||||
if (typeof method !== 'string' || typeof data !== 'object') {
|
||||
console.log('Caller callWithResult ' + typeof method + ' ' + typeof data);
|
||||
reject(new BusinessError(ERROR_CODE_INVALID_PARAM));
|
||||
return;
|
||||
}
|
||||
|
||||
if (method === '' || data == null) {
|
||||
console.log('Caller callWithResult ' + method + ', ' + data);
|
||||
reject(new BusinessError(ERROR_CODE_INVALID_PARAM));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.releaseState === true) {
|
||||
console.log('Caller callWithResult this.callee release');
|
||||
reject(new BusinessError(ERROR_CODE_CALLER_RELEASED));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.__call_obj__.callee == null) {
|
||||
console.log('Caller callWithResult this.callee is nullptr');
|
||||
reject(new BusinessError(ERROR_CODE_CLAAEE_INVALID));
|
||||
const checkError = this.callCheck(method, data);
|
||||
if (checkError != null) {
|
||||
reject(checkError);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Caller callWithResult msgData rpc.MessageSequence create');
|
||||
let msgData = rpc.MessageSequence.create();
|
||||
msgData.writeString(method);
|
||||
let msgData = this.buildMsgData(method, data);
|
||||
let msgReply = rpc.MessageSequence.create();
|
||||
let option = rpc.MessageOption();
|
||||
msgData.writeParcelable(data);
|
||||
|
||||
let reply = undefined;
|
||||
let retData = undefined;
|
||||
try {
|
||||
retData = await this.__call_obj__.callee.sendMessageRequest(EVENT_CALL_NOTIFY, msgData, msgReply,
|
||||
option);
|
||||
rpc.MessageOption());
|
||||
console.log('Caller callWithResult msgData rpc.sendMessageRequest called');
|
||||
if (retData.errCode !== 0) {
|
||||
msgData.reclaim();
|
||||
@ -184,7 +140,6 @@ class Caller {
|
||||
let retval = retData.reply.readInt();
|
||||
let str = retData.reply.readString();
|
||||
if (retval === REQUEST_SUCCESS && str === 'object') {
|
||||
console.log('Caller callWithResult return str ' + str);
|
||||
msgData.reclaim();
|
||||
reply = retData.reply;
|
||||
} else {
|
||||
@ -286,6 +241,36 @@ class Caller {
|
||||
}
|
||||
// Empty
|
||||
}
|
||||
|
||||
callCheck(method, data) {
|
||||
if (typeof method !== 'string' || typeof data !== 'object') {
|
||||
console.log('Caller callCheck ' + typeof method + ' ' + typeof data);
|
||||
return new BusinessError(ERROR_CODE_INVALID_PARAM);
|
||||
}
|
||||
|
||||
if (method === '' || data == null) {
|
||||
console.log('Caller callCheck ' + method + ', ' + data);
|
||||
return new BusinessError(ERROR_CODE_INVALID_PARAM);
|
||||
}
|
||||
|
||||
if (this.releaseState === true) {
|
||||
console.log('Caller callCheck this.callee release');
|
||||
return new BusinessError(ERROR_CODE_CALLER_RELEASED);
|
||||
}
|
||||
|
||||
if (this.__call_obj__.callee == null) {
|
||||
console.log('Caller callCheck this.callee is nullptr');
|
||||
return new BusinessError(ERROR_CODE_CLAAEE_INVALID);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
buildMsgData(method, data) {
|
||||
let msgData = rpc.MessageSequence.create();
|
||||
msgData.writeString(method);
|
||||
msgData.writeParcelable(data);
|
||||
return msgData;
|
||||
}
|
||||
}
|
||||
|
||||
export default Caller;
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/templates/abc/ohos_abc.gni")
|
||||
|
||||
es2abc_gen_abc("gen_data_uri_utils_abc") {
|
||||
src_js = rebase_path("data_uri_utils.js")
|
||||
@ -34,17 +35,11 @@ gen_js_obj("data_uri_utils_abc") {
|
||||
dep = ":gen_data_uri_utils_abc"
|
||||
}
|
||||
|
||||
ohos_shared_library("datauriutils_napi") {
|
||||
sources = [ "data_uri_utils_module.cpp" ]
|
||||
|
||||
deps = [
|
||||
":data_uri_utils_abc",
|
||||
":data_uri_utils_js",
|
||||
]
|
||||
|
||||
external_deps = [ "napi:ace_napi" ]
|
||||
|
||||
relative_install_dir = "module/ability"
|
||||
ohos_abc("datauriutils_napi") {
|
||||
sources = [ "data_uri_utils.js" ]
|
||||
output_name = "datauriutils"
|
||||
install_images = [ "system" ]
|
||||
module_install_dir = "etc/abc/ability"
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
||||
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
extern const char _binary_data_uri_utils_js_start[];
|
||||
extern const char _binary_data_uri_utils_js_end[];
|
||||
extern const char _binary_data_uri_utils_abc_start[];
|
||||
extern const char _binary_data_uri_utils_abc_end[];
|
||||
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_filename = "ability/libdatauriutils_napi.so/data_uri_utils.js",
|
||||
.nm_modname = "ability.dataUriUtils",
|
||||
};
|
||||
extern "C" __attribute__((constructor))
|
||||
void NAPI_ability_dataUriUtils_AutoRegister()
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_ability_dataUriUtils_GetJSCode(const char **buf, int *bufLen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_data_uri_utils_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_data_uri_utils_js_end - _binary_data_uri_utils_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
// dataUriUtils js register
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_ability_dataUriUtils_GetABCCode(const char **buf, int *buflen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_data_uri_utils_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_data_uri_utils_abc_end - _binary_data_uri_utils_abc_start;
|
||||
}
|
||||
}
|
50
frameworks/js/napi/embeddable_ui_ability/BUILD.gn
Normal file
50
frameworks/js/napi/embeddable_ui_ability/BUILD.gn
Normal file
@ -0,0 +1,50 @@
|
||||
# Copyright (c) 2023 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("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
es2abc_gen_abc("gen_embeddable_ui_ability_abc") {
|
||||
src_js = rebase_path("embeddable_ui_ability.js")
|
||||
dst_file = rebase_path(target_out_dir + "/embeddable_ui_ability.abc")
|
||||
in_puts = [ "embeddable_ui_ability.js" ]
|
||||
out_puts = [ target_out_dir + "/embeddable_ui_ability.abc" ]
|
||||
extra_args = [ "--module" ]
|
||||
}
|
||||
|
||||
gen_js_obj("embeddable_ui_ability_js") {
|
||||
input = "embeddable_ui_ability.js"
|
||||
output = target_out_dir + "/embeddable_ui_ability.o"
|
||||
}
|
||||
|
||||
gen_js_obj("embeddable_ui_ability_abc") {
|
||||
input = get_label_info(":gen_embeddable_ui_ability_abc", "target_out_dir") +
|
||||
"/embeddable_ui_ability.abc"
|
||||
output = target_out_dir + "/embeddable_ui_ability_abc.o"
|
||||
dep = ":gen_embeddable_ui_ability_abc"
|
||||
}
|
||||
|
||||
ohos_shared_library("embeddableuiability_napi") {
|
||||
sources = [ "embeddable_ui_ability_module.cpp" ]
|
||||
|
||||
deps = [
|
||||
":embeddable_ui_ability_abc",
|
||||
":embeddable_ui_ability_js",
|
||||
]
|
||||
|
||||
external_deps = [ "napi:ace_napi" ]
|
||||
|
||||
relative_install_dir = "module/app/ability"
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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.
|
||||
*/
|
||||
|
||||
let UIAbility = requireNapi('app.ability.UIAbility');
|
||||
|
||||
class EmbeddableUIAbility extends UIAbility {
|
||||
}
|
||||
|
||||
export default EmbeddableUIAbility;
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "native_engine/native_engine.h"
|
||||
|
||||
extern const char _binary_embeddable_ui_ability_js_start[];
|
||||
extern const char _binary_embeddable_ui_ability_js_end[];
|
||||
extern const char _binary_embeddable_ui_ability_abc_start[];
|
||||
extern const char _binary_embeddable_ui_ability_abc_end[];
|
||||
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_filename = "app/ability/libembeddableuiability_napi.so/embeddable_ui_ability.js",
|
||||
.nm_modname = "app.ability.EmbeddableUIAbility",
|
||||
};
|
||||
extern "C" __attribute__((constructor)) void NAPI_app_ability_EmbeddableUIAbility_AutoRegister()
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) void NAPI_app_ability_EmbeddableUIAbility_GetJSCode(
|
||||
const char **buf, int *bufLen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_embeddable_ui_ability_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_embeddable_ui_ability_js_end - _binary_embeddable_ui_ability_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) void NAPI_app_ability_EmbeddableUIAbility_GetABCCode(
|
||||
const char **buf, int *buflen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_embeddable_ui_ability_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_embeddable_ui_ability_abc_end - _binary_embeddable_ui_ability_abc_start;
|
||||
}
|
||||
}
|
51
frameworks/js/napi/embeddable_ui_ability_context/BUILD.gn
Normal file
51
frameworks/js/napi/embeddable_ui_ability_context/BUILD.gn
Normal file
@ -0,0 +1,51 @@
|
||||
# Copyright (c) 2023 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("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
es2abc_gen_abc("gen_embeddable_ui_ability_context_abc") {
|
||||
src_js = rebase_path("embeddable_ui_ability_context.js")
|
||||
dst_file = rebase_path(target_out_dir + "/embeddable_ui_ability_context.abc")
|
||||
in_puts = [ "embeddable_ui_ability_context.js" ]
|
||||
out_puts = [ target_out_dir + "/embeddable_ui_ability_context.abc" ]
|
||||
extra_args = [ "--module" ]
|
||||
}
|
||||
|
||||
gen_js_obj("embeddable_ui_ability_context_js") {
|
||||
input = "embeddable_ui_ability_context.js"
|
||||
output = target_out_dir + "/embeddable_ui_ability_context.o"
|
||||
}
|
||||
|
||||
gen_js_obj("embeddable_ui_ability_context_abc") {
|
||||
input =
|
||||
get_label_info(":gen_embeddable_ui_ability_context_abc",
|
||||
"target_out_dir") + "/embeddable_ui_ability_context.abc"
|
||||
output = target_out_dir + "/embeddable_ui_ability_context_abc.o"
|
||||
dep = ":gen_embeddable_ui_ability_context_abc"
|
||||
}
|
||||
|
||||
ohos_shared_library("embeddableuiabilitycontext_napi") {
|
||||
sources = [ "embeddable_ui_ability_context_module.cpp" ]
|
||||
|
||||
deps = [
|
||||
":embeddable_ui_ability_context_abc",
|
||||
":embeddable_ui_ability_context_js",
|
||||
]
|
||||
|
||||
external_deps = [ "napi:ace_napi" ]
|
||||
|
||||
relative_install_dir = "module/application"
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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.
|
||||
*/
|
||||
|
||||
let AbilityContext = requireNapi('application.AbilityContext');
|
||||
|
||||
class EmbeddableUIAbilityContext extends AbilityContext {
|
||||
constructor(obj) {
|
||||
super(obj);
|
||||
this.abilityInfo = obj.abilityInfo;
|
||||
this.currentHapModuleInfo = obj.currentHapModuleInfo;
|
||||
this.config = obj.config;
|
||||
}
|
||||
|
||||
onUpdateConfiguration(config) {
|
||||
this.config = config;
|
||||
}
|
||||
}
|
||||
|
||||
export default EmbeddableUIAbilityContext;
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "native_engine/native_engine.h"
|
||||
|
||||
extern const char _binary_embeddable_ui_ability_context_js_start[];
|
||||
extern const char _binary_embeddable_ui_ability_context_js_end[];
|
||||
extern const char _binary_embeddable_ui_ability_context_abc_start[];
|
||||
extern const char _binary_embeddable_ui_ability_context_abc_end[];
|
||||
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_filename = "application/libembeddableuiabilitycontext_napi.so/embeddable_ui_ability_context.js",
|
||||
.nm_modname = "application.EmbeddableUIAbilityContext",
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor)) void NAPI_application_EmbeddableUIAbilityContext_AutoRegister()
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) void NAPI_application_EmbeddableUIAbilityContext_GetJSCode(
|
||||
const char **buf, int *bufLen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_embeddable_ui_ability_context_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_embeddable_ui_ability_context_js_end - _binary_embeddable_ui_ability_context_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
// embeddable_ui_ability_context JS register
|
||||
extern "C" __attribute__((visibility("default"))) void NAPI_application_EmbeddableUIAbilityContext_GetABCCode(
|
||||
const char **buf, int *buflen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_embeddable_ui_ability_context_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_embeddable_ui_ability_context_abc_end - _binary_embeddable_ui_ability_context_abc_start;
|
||||
}
|
||||
}
|
@ -63,6 +63,7 @@ ohos_shared_library("featureability") {
|
||||
|
||||
if (ability_runtime_relational) {
|
||||
include_dirs += [
|
||||
"${common_tool_path}",
|
||||
"${relational_store_napi_path}/common/include",
|
||||
"${relational_store_napi_path}/dataability/include",
|
||||
"${relational_store_napi_path}/rdb/include",
|
||||
|
@ -530,6 +530,11 @@ napi_value SetResultAsync(
|
||||
[](napi_env env, void *data) {
|
||||
HILOG_INFO("NAPI_SetResult, worker pool thread enter.");
|
||||
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
HILOG_ERROR("NAPI_SetResult, execute asyncCallbackInfo is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
if (asyncCallbackInfo->ability != nullptr) {
|
||||
asyncCallbackInfo->ability->SetResult(
|
||||
asyncCallbackInfo->param.requestCode, asyncCallbackInfo->param.want);
|
||||
@ -542,6 +547,10 @@ napi_value SetResultAsync(
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
HILOG_INFO("NAPI_SetResult, main event thread complete.");
|
||||
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
HILOG_ERROR("NAPI_SetResult, complete asyncCallbackInfo is nullptr");
|
||||
return;
|
||||
}
|
||||
napi_value result[ARGS_TWO] = {nullptr};
|
||||
napi_value callback = nullptr;
|
||||
napi_value undefined = nullptr;
|
||||
@ -587,6 +596,11 @@ napi_value SetResultPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo)
|
||||
[](napi_env env, void *data) {
|
||||
HILOG_INFO("NAPI_SetResult, worker pool thread execute.");
|
||||
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
HILOG_ERROR("NAPI_SetResult promise, execute asyncCallbackInfo is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
if (asyncCallbackInfo->ability != nullptr) {
|
||||
asyncCallbackInfo->ability->SetResult(
|
||||
asyncCallbackInfo->param.requestCode, asyncCallbackInfo->param.want);
|
||||
@ -599,6 +613,10 @@ napi_value SetResultPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo)
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
HILOG_INFO("NAPI_SetResult, main event thread complete.");
|
||||
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
HILOG_ERROR("NAPI_SetResult promise, execute asyncCallbackInfo is nullptr");
|
||||
return;
|
||||
}
|
||||
napi_value result = nullptr;
|
||||
napi_get_null(env, &result);
|
||||
napi_resolve_deferred(env, asyncCallbackInfo->deferred, result);
|
||||
@ -763,7 +781,10 @@ napi_value UnwrapForResultParam(CallAbilityParam ¶m, napi_env env, napi_valu
|
||||
}
|
||||
|
||||
// unwrap the param : abilityStartSetting (optional)
|
||||
napi_value jsSettingObj = GetPropertyValueByPropertyName(env, args, "abilityStartSetting", napi_object);
|
||||
napi_value jsSettingObj = GetPropertyValueByPropertyName(env, args, "abilityStartSettings", napi_object);
|
||||
if (jsSettingObj == nullptr) {
|
||||
jsSettingObj = GetPropertyValueByPropertyName(env, args, "abilityStartSetting", napi_object);
|
||||
}
|
||||
if (jsSettingObj != nullptr) {
|
||||
param.setting = AbilityStartSetting::GetEmptySetting();
|
||||
if (!UnwrapAbilityStartSetting(env, jsSettingObj, *(param.setting))) {
|
||||
@ -1072,6 +1093,11 @@ void GetDataAbilityHelperAsyncCompleteCB(napi_env env, napi_status status, void
|
||||
{
|
||||
HILOG_INFO("NAPI_GetDataAbilityHelper, main event thread complete.");
|
||||
DataAbilityHelperCB *dataAbilityHelperCB = static_cast<DataAbilityHelperCB *>(data);
|
||||
if (dataAbilityHelperCB == nullptr) {
|
||||
HILOG_ERROR("GetDataAbilityHelperAsyncCompleteCB, dataAbilityHelperCB is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<DataAbilityHelperCB> callbackPtr {dataAbilityHelperCB};
|
||||
napi_value uri = nullptr;
|
||||
napi_value callback = nullptr;
|
||||
@ -1104,6 +1130,11 @@ void GetDataAbilityHelperPromiseCompleteCB(napi_env env, napi_status status, voi
|
||||
{
|
||||
HILOG_INFO("NAPI_GetDataAbilityHelper, main event thread complete.");
|
||||
DataAbilityHelperCB *dataAbilityHelperCB = static_cast<DataAbilityHelperCB *>(data);
|
||||
if (dataAbilityHelperCB == nullptr) {
|
||||
HILOG_INFO("GetDataAbilityHelperPromiseCompleteCB, dataAbilityHelperCB is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
napi_value uri = nullptr;
|
||||
napi_value result = nullptr;
|
||||
napi_get_reference_value(env, dataAbilityHelperCB->uri, &uri);
|
||||
@ -1252,7 +1283,12 @@ napi_value ContinueAbilityAsync(napi_env env, napi_value *args, AsyncCallbackInf
|
||||
napi_create_async_work(env, nullptr, resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
HILOG_INFO("NAPI_ContinueAbility, worker pool thread execute.");
|
||||
AsyncCallbackInfo *asyncCallbackInfo = (AsyncCallbackInfo *)data;
|
||||
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
HILOG_ERROR("NAPI_ContinueAbility, asyncCallbackInfo is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (asyncCallbackInfo->ability != nullptr) {
|
||||
asyncCallbackInfo->ability->ContinueAbility(asyncCallbackInfo->optionInfo.deviceId);
|
||||
} else {
|
||||
@ -1262,7 +1298,11 @@ napi_value ContinueAbilityAsync(napi_env env, napi_value *args, AsyncCallbackInf
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
HILOG_INFO("NAPI_ContinueAbility, main event thread end.");
|
||||
AsyncCallbackInfo *asyncCallbackInfo = (AsyncCallbackInfo *)data;
|
||||
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
HILOG_ERROR("NAPI_ContinueAbility complete, asyncCallbackInfo is nullptr.");
|
||||
return;
|
||||
}
|
||||
napi_value callback = nullptr;
|
||||
napi_value undefined = nullptr;
|
||||
napi_value result[ARGS_TWO] = {nullptr};
|
||||
@ -1321,7 +1361,11 @@ napi_value ContinueAbilityPromise(napi_env env, napi_value *args, AsyncCallbackI
|
||||
napi_create_async_work(env, nullptr, resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
HILOG_INFO("NAPI_ContinueAbility, worker pool thread execute.");
|
||||
AsyncCallbackInfo *asyncCallbackInfo = (AsyncCallbackInfo *)data;
|
||||
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
HILOG_ERROR("NAPI_ContinueAbility, worker pool thread execute asyncCallbackInfo is nullptr.");
|
||||
return;
|
||||
}
|
||||
if (asyncCallbackInfo->ability != nullptr) {
|
||||
asyncCallbackInfo->ability->ContinueAbility(asyncCallbackInfo->optionInfo.deviceId);
|
||||
} else {
|
||||
@ -1331,7 +1375,11 @@ napi_value ContinueAbilityPromise(napi_env env, napi_value *args, AsyncCallbackI
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
HILOG_INFO("NAPI_ContinueAbility, main event thread complete.");
|
||||
AsyncCallbackInfo *asyncCallbackInfo = (AsyncCallbackInfo *)data;
|
||||
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
HILOG_ERROR("NAPI_ContinueAbility, main event thread complete asyncCallbackInfo is nullptr.");
|
||||
return;
|
||||
}
|
||||
napi_value result = nullptr;
|
||||
napi_get_null(env, &result);
|
||||
napi_resolve_deferred(env, asyncCallbackInfo->deferred, result);
|
||||
|
@ -38,6 +38,7 @@ ohos_shared_library("napi_ability_common") {
|
||||
"${ability_runtime_innerkits_path}/wantagent:wantagent_innerkits",
|
||||
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
|
||||
"${ability_runtime_native_path}/ability/native:abilitykit_native",
|
||||
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
@ -50,7 +51,7 @@ ohos_shared_library("napi_ability_common") {
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"ipc:ipc_napi_common",
|
||||
"ipc:ipc_napi",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
|
@ -3135,7 +3135,10 @@ bool UnwrapParamForWant(napi_env env, napi_value args, AbilityType, CallAbilityP
|
||||
|
||||
ret = UnwrapWant(env, jsWant, param.want);
|
||||
|
||||
napi_value jsSettingObj = GetPropertyValueByPropertyName(env, args, "abilityStartSetting", napi_object);
|
||||
napi_value jsSettingObj = GetPropertyValueByPropertyName(env, args, "abilityStartSettings", napi_object);
|
||||
if (jsSettingObj == nullptr) {
|
||||
jsSettingObj = GetPropertyValueByPropertyName(env, args, "abilityStartSetting", napi_object);
|
||||
}
|
||||
if (jsSettingObj != nullptr) {
|
||||
param.setting = AbilityStartSetting::GetEmptySetting();
|
||||
if (!UnwrapAbilityStartSetting(env, jsSettingObj, *(param.setting))) {
|
||||
|
@ -54,7 +54,7 @@ ohos_shared_library("napi_common") {
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"ipc:ipc_napi_common",
|
||||
"ipc:ipc_napi",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
|
@ -43,6 +43,35 @@ bool UnwrapStartOptions(napi_env env, napi_value param, AAFwk::StartOptions &sta
|
||||
startOptions.SetDisplayID(displayId);
|
||||
}
|
||||
|
||||
bool withAnimation = true;
|
||||
if (UnwrapBooleanByPropertyName(env, param, "withAnimation", withAnimation)) {
|
||||
startOptions.SetWithAnimation(withAnimation);
|
||||
}
|
||||
|
||||
int32_t windowLeft = 0;
|
||||
if (UnwrapInt32ByPropertyName(env, param, "windowLeft", windowLeft)) {
|
||||
startOptions.SetWindowLeft(windowLeft);
|
||||
startOptions.windowLeftUsed_ = true;
|
||||
}
|
||||
|
||||
int32_t windowTop = 0;
|
||||
if (UnwrapInt32ByPropertyName(env, param, "windowTop", windowTop)) {
|
||||
startOptions.SetWindowTop(windowTop);
|
||||
startOptions.windowTopUsed_ = true;
|
||||
}
|
||||
|
||||
int32_t windowWidth = 0;
|
||||
if (UnwrapInt32ByPropertyName(env, param, "windowWidth", windowWidth)) {
|
||||
startOptions.SetWindowWidth(windowWidth);
|
||||
startOptions.windowWidthUsed_ = true;
|
||||
}
|
||||
|
||||
int32_t windowHeight = 0;
|
||||
if (UnwrapInt32ByPropertyName(env, param, "windowHeight", windowHeight)) {
|
||||
startOptions.SetWindowHeight(windowHeight);
|
||||
startOptions.windowHeightUsed_ = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
EXTERN_C_END
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 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
|
||||
@ -15,24 +15,24 @@
|
||||
|
||||
#include "napi_common_want.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "array_wrapper.h"
|
||||
#include "bool_wrapper.h"
|
||||
#include "byte_wrapper.h"
|
||||
#include "double_wrapper.h"
|
||||
#include "float_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "int_wrapper.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "long_wrapper.h"
|
||||
#include "napi_remote_object.h"
|
||||
#include "remote_object_wrapper.h"
|
||||
#include "short_wrapper.h"
|
||||
#include "string_wrapper.h"
|
||||
#include "tokenid_kit.h"
|
||||
#include "zchar_wrapper.h"
|
||||
#include "remote_object_wrapper.h"
|
||||
#include "want_params_wrapper.h"
|
||||
#include "napi_remote_object.h"
|
||||
#include "zchar_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
|
@ -21,9 +21,9 @@
|
||||
*/
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_modname = "app.ability.insightintent",
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = OHOS::AbilityRuntime::JsInsightIntentInit,
|
||||
.nm_modname = "app.ability.insightintent",
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -43,31 +43,36 @@ constexpr size_t ARGC_ONE = 1;
|
||||
class JsInsightIntentExecuteCallbackClient : public InsightIntentExecuteCallbackInterface,
|
||||
public std::enable_shared_from_this<JsInsightIntentExecuteCallbackClient> {
|
||||
public:
|
||||
using InsightIntentExecuteTask = std::function<void(int32_t resultCode,
|
||||
AppExecFwk::InsightIntentExecuteResult executeResult)>;
|
||||
explicit JsInsightIntentExecuteCallbackClient(InsightIntentExecuteTask &&task) : task_(std::move(task))
|
||||
{
|
||||
handler_ = std::make_shared<EventHandler>(EventRunner::GetMainEventRunner());
|
||||
}
|
||||
JsInsightIntentExecuteCallbackClient(napi_env env, napi_deferred nativeDeferred, napi_ref callbackRef)
|
||||
: env_(env), nativeDeferred_(nativeDeferred), callbackRef_(callbackRef) {}
|
||||
|
||||
virtual ~JsInsightIntentExecuteCallbackClient() = default;
|
||||
|
||||
void ProcessInsightIntentExecute(int32_t resultCode,
|
||||
AppExecFwk::InsightIntentExecuteResult executeResult) override
|
||||
{
|
||||
if (handler_) {
|
||||
handler_->PostSyncTask([client = weak_from_this(), resultCode, executeResult] () {
|
||||
auto impl = client.lock();
|
||||
if (impl == nullptr) {
|
||||
return;
|
||||
}
|
||||
impl->task_(resultCode, executeResult);
|
||||
});
|
||||
NapiAsyncTask::CompleteCallback complete = [resultCode = resultCode, executeResult = executeResult]
|
||||
(napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
if (resultCode != 0) {
|
||||
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(resultCode)));
|
||||
} else {
|
||||
task.ResolveWithNoError(env, CreateJsExecuteResult(env, executeResult));
|
||||
}
|
||||
};
|
||||
std::unique_ptr<NapiAsyncTask> asyncTask = nullptr;
|
||||
if (nativeDeferred_) {
|
||||
asyncTask = std::make_unique<NapiAsyncTask>(nativeDeferred_, nullptr,
|
||||
std::make_unique<NapiAsyncTask::CompleteCallback>(std::move(complete)));
|
||||
} else {
|
||||
asyncTask = std::make_unique<NapiAsyncTask>(callbackRef_, nullptr,
|
||||
std::make_unique<NapiAsyncTask::CompleteCallback>(std::move(complete)));
|
||||
}
|
||||
NapiAsyncTask::Schedule("JsInsightIntentDriver::OnExecute", env_, std::move(asyncTask));
|
||||
}
|
||||
private:
|
||||
InsightIntentExecuteTask task_;
|
||||
std::shared_ptr<EventHandler> handler_ = nullptr;
|
||||
napi_env env_;
|
||||
napi_deferred nativeDeferred_ = nullptr;
|
||||
napi_ref callbackRef_ = nullptr;
|
||||
};
|
||||
|
||||
class JsInsightIntentDriver {
|
||||
@ -104,25 +109,27 @@ private:
|
||||
}
|
||||
|
||||
napi_value lastParam = (info.argc == 1) ? nullptr : info.argv[INDEX_ONE];
|
||||
napi_value result = nullptr;
|
||||
napi_valuetype type = napi_undefined;
|
||||
napi_typeof(env, lastParam, &type);
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_deferred nativeDeferred = nullptr;
|
||||
napi_ref callbackRef = nullptr;
|
||||
std::unique_ptr<NapiAsyncTask> asyncTask = nullptr;
|
||||
if (lastParam == nullptr || type != napi_function) {
|
||||
napi_create_promise(env, &nativeDeferred, &result);
|
||||
asyncTask = std::make_unique<NapiAsyncTask>(nativeDeferred, nullptr, nullptr);
|
||||
} else {
|
||||
napi_get_undefined(env, &result);
|
||||
napi_create_reference(env, lastParam, 1, &callbackRef);
|
||||
asyncTask = std::make_unique<NapiAsyncTask>(callbackRef, nullptr, nullptr);
|
||||
}
|
||||
|
||||
std::unique_ptr<NapiAsyncTask> uasyncTask = CreateAsyncTaskWithLastParam(
|
||||
env, lastParam, nullptr, nullptr, &result);
|
||||
std::shared_ptr<NapiAsyncTask> asyncTask = std::move(uasyncTask);
|
||||
if (asyncTask == nullptr) {
|
||||
HILOG_ERROR("asyncTask is nullptr");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
JsInsightIntentExecuteCallbackClient::InsightIntentExecuteTask task = [env, asyncTask]
|
||||
(int32_t resultCode, InsightIntentExecuteResult executeResult) {
|
||||
if (resultCode != 0) {
|
||||
asyncTask->Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(resultCode)));
|
||||
return;
|
||||
} else {
|
||||
asyncTask->ResolveWithNoError(env, CreateJsExecuteResult(env, executeResult));
|
||||
}
|
||||
};
|
||||
auto client = std::make_shared<JsInsightIntentExecuteCallbackClient>(std::move(task));
|
||||
auto client = std::make_shared<JsInsightIntentExecuteCallbackClient>(env, nativeDeferred, callbackRef);
|
||||
uint64_t key = InsightIntentHostClient::GetInstance()->AddInsightIntentExecute(client);
|
||||
auto err = AbilityManagerClient::GetInstance()->ExecuteIntent(key,
|
||||
InsightIntentHostClient::GetInstance(), param);
|
||||
|
@ -21,9 +21,9 @@
|
||||
*/
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_modname = "app.ability.insightIntentDriver",
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = OHOS::AbilityRuntime::JsInsightIntentDriverInit,
|
||||
.nm_modname = "app.ability.insightIntentDriver",
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -22,8 +22,8 @@ extern const char _binary_insight_intent_executor_abc_end[];
|
||||
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_modname = "app.ability.InsightIntentExecutor",
|
||||
.nm_filename = "app/ability/insightintentexecutor_napi.so/insight_intent_executor.js",
|
||||
.nm_modname = "app.ability.InsightIntentExecutor",
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor))
|
||||
|
@ -25,8 +25,8 @@ extern const char _binary_insight_intent_context_abc_end[];
|
||||
*/
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_modname = "app.ability.InsightIntentContext",
|
||||
.nm_filename = "app/ability/insightintentcontext_napi.so",
|
||||
.nm_modname = "app.ability.InsightIntentContext",
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -33,6 +33,7 @@ constexpr size_t ARGC_TWO = 2;
|
||||
|
||||
enum {
|
||||
MODE_SELF_FORK = 0,
|
||||
MODE_APP_SPAWN_FORK = 1,
|
||||
};
|
||||
}
|
||||
|
||||
@ -55,7 +56,7 @@ public:
|
||||
private:
|
||||
napi_value OnStartChildProcess(napi_env env, size_t argc, napi_value* argv)
|
||||
{
|
||||
HILOG_INFO("%{public}s is called", __FUNCTION__);
|
||||
HILOG_INFO("called.");
|
||||
if (ChildProcessManager::GetInstance().IsChildProcess()) {
|
||||
HILOG_ERROR("Already in child process");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_OPERATION_NOT_SUPPORTED);
|
||||
@ -79,24 +80,14 @@ private:
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
HILOG_DEBUG("StartMode: %{public}d", startMode);
|
||||
if (startMode != MODE_SELF_FORK) {
|
||||
if (startMode != MODE_SELF_FORK && startMode != MODE_APP_SPAWN_FORK) {
|
||||
HILOG_ERROR("Not supported StartMode");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
NapiAsyncTask::CompleteCallback complete = [srcEntry, startMode](napi_env env, NapiAsyncTask &task,
|
||||
int32_t status) {
|
||||
switch (startMode) {
|
||||
case MODE_SELF_FORK: {
|
||||
SelfForkProcess(env, task, srcEntry);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
HILOG_ERROR("Not supported StartMode");
|
||||
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
|
||||
break;
|
||||
}
|
||||
}
|
||||
ForkProcess(env, task, srcEntry, startMode);
|
||||
};
|
||||
napi_value lastParam = (argc <= ARGC_TWO) ? nullptr : argv[ARGC_TWO];
|
||||
napi_value result = nullptr;
|
||||
@ -105,11 +96,27 @@ private:
|
||||
return result;
|
||||
}
|
||||
|
||||
static void SelfForkProcess(napi_env env, NapiAsyncTask &task, const std::string &srcEntry)
|
||||
static void ForkProcess(napi_env env, NapiAsyncTask &task, const std::string &srcEntry, const int32_t startMode)
|
||||
{
|
||||
pid_t pid;
|
||||
ChildProcessManagerErrorCode errorCode =
|
||||
ChildProcessManager::GetInstance().StartChildProcessBySelfFork(srcEntry, pid);
|
||||
HILOG_DEBUG("called.");
|
||||
pid_t pid = 0;
|
||||
ChildProcessManagerErrorCode errorCode;
|
||||
switch (startMode) {
|
||||
case MODE_SELF_FORK: {
|
||||
errorCode = ChildProcessManager::GetInstance().StartChildProcessBySelfFork(srcEntry, pid);
|
||||
break;
|
||||
}
|
||||
case MODE_APP_SPAWN_FORK: {
|
||||
errorCode = ChildProcessManager::GetInstance().StartChildProcessByAppSpawnFork(srcEntry, pid);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
HILOG_ERROR("Not supported StartMode");
|
||||
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
|
||||
return;
|
||||
}
|
||||
}
|
||||
HILOG_DEBUG("ChildProcessManager start resultCode: %{public}d, pid:%{public}d", errorCode, pid);
|
||||
if (errorCode == ChildProcessManagerErrorCode::ERR_OK) {
|
||||
task.ResolveWithNoError(env, CreateJsValue(env, pid));
|
||||
} else {
|
||||
@ -120,7 +127,7 @@ private:
|
||||
|
||||
napi_value JsChildProcessManagerInit(napi_env env, napi_value exportObj)
|
||||
{
|
||||
HILOG_INFO("%{public}s is called", __FUNCTION__);
|
||||
HILOG_INFO("called.");
|
||||
if (env == nullptr || exportObj == nullptr) {
|
||||
HILOG_ERROR("Invalid input params");
|
||||
return nullptr;
|
||||
|
56
frameworks/js/napi/js_dialog_session/BUILD.gn
Normal file
56
frameworks/js/napi/js_dialog_session/BUILD.gn
Normal file
@ -0,0 +1,56 @@
|
||||
# Copyright (c) 2023 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")
|
||||
|
||||
ohos_shared_library("dialogsession_napi") {
|
||||
sources = [
|
||||
"js_dialog_session.cpp",
|
||||
"js_dialog_session_utils.cpp",
|
||||
"native_module.cpp",
|
||||
]
|
||||
|
||||
configs = [ "${ability_runtime_services_path}/common:common_config" ]
|
||||
|
||||
include_dirs = []
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
|
||||
"${ability_runtime_innerkits_path}/runtime:runtime",
|
||||
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
|
||||
"${ability_runtime_native_path}/appkit:app_context",
|
||||
"//third_party/json:nlohmann_json_static",
|
||||
"//third_party/jsoncpp:jsoncpp",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:extractortool",
|
||||
"ability_base:want",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"ffrt:libffrt",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
relative_install_dir = "module/app/ability"
|
||||
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
138
frameworks/js/napi/js_dialog_session/js_dialog_session.cpp
Normal file
138
frameworks/js/napi/js_dialog_session/js_dialog_session.cpp
Normal file
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "js_dialog_session.h"
|
||||
|
||||
#include "ability_manager_client.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_error_utils.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi_common_ability.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "napi_remote_object.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using AAFwk::AbilityManagerClient;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
constexpr size_t ARGC_THREE = 3;
|
||||
|
||||
class JsDialogSession {
|
||||
public:
|
||||
JsDialogSession() = default;
|
||||
~JsDialogSession() = default;
|
||||
|
||||
static void Finalizer(napi_env env, void* data, void* hint)
|
||||
{
|
||||
HILOG_INFO("JsDialogSession::Finalizer is called");
|
||||
std::unique_ptr<JsDialogSession>(static_cast<JsDialogSession*>(data));
|
||||
}
|
||||
|
||||
static napi_value GetDialogSessionInfo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsDialogSession, OnGetDialogSessionInfo);
|
||||
}
|
||||
|
||||
static napi_value SendDialogResult(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsDialogSession, OnSendDialogResult);
|
||||
}
|
||||
|
||||
private:
|
||||
napi_value OnGetDialogSessionInfo(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
HILOG_DEBUG("enter, argc = %{public}d", static_cast<int32_t>(info.argc));
|
||||
if (info.argc < 1) {
|
||||
HILOG_ERROR("not enough params");
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string dialogSessionId = "";
|
||||
if (!ConvertFromJsValue(env, info.argv[0], dialogSessionId)) {
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
sptr<AAFwk::DialogSessionInfo> dialogSessionInfo;
|
||||
HILOG_DEBUG("GetDialogSessionInfo begin");
|
||||
auto errcode = AbilityManagerClient::GetInstance()->GetDialogSessionInfo(dialogSessionId, dialogSessionInfo);
|
||||
if (errcode || dialogSessionInfo == nullptr) {
|
||||
HILOG_ERROR("GetDialogSessionInfo error");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
return OHOS::AppExecFwk::WrapDialogSessionInfo(env, *dialogSessionInfo);
|
||||
}
|
||||
|
||||
napi_value OnSendDialogResult(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
HILOG_DEBUG("enter, argc = %{public}d", static_cast<int32_t>(info.argc));
|
||||
if (info.argc < ARGC_THREE) {
|
||||
HILOG_ERROR("not enough params");
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string dialogSessionId = "";
|
||||
if (!ConvertFromJsValue(env, info.argv[0], dialogSessionId)) {
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
AAFwk::Want want;
|
||||
if (!AppExecFwk::UnwrapWant(env, info.argv[1], want)) {
|
||||
HILOG_ERROR("Failed to unwrap want");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
bool isAllow = false;
|
||||
if (!ConvertFromJsValue(env, info.argv[ARGC_TWO], isAllow)) {
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[dialogSessionId, want, isAllow](napi_env env, NapiAsyncTask &task, int32_t status) {
|
||||
auto errorcode = AbilityManagerClient::GetInstance()->SendDialogResult(want, dialogSessionId, isAllow);
|
||||
if (errorcode) {
|
||||
task.Reject(env, CreateJsError(env, errorcode, "Send dialog result failed"));
|
||||
} else {
|
||||
task.ResolveWithNoError(env, CreateJsUndefined(env));
|
||||
}
|
||||
};
|
||||
napi_value lastParam = (info.argc > ARGC_THREE) ? info.argv[ARGC_THREE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::Schedule("JsDialogSession::OnSendDialogResult",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
napi_value JsDialogSessionInit(napi_env env, napi_value exportObj)
|
||||
{
|
||||
HILOG_INFO("JsDialogSessionInit is called");
|
||||
if (env == nullptr || exportObj == nullptr) {
|
||||
HILOG_INFO("Invalid input parameters");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<JsDialogSession> jsDialogSession = std::make_unique<JsDialogSession>();
|
||||
napi_wrap(env, exportObj, jsDialogSession.release(), JsDialogSession::Finalizer, nullptr, nullptr);
|
||||
|
||||
const char *moduleName = "JsDialogSession";
|
||||
BindNativeFunction(env, exportObj, "getDialogSessionInfo", moduleName, JsDialogSession::GetDialogSessionInfo);
|
||||
BindNativeFunction(env, exportObj, "sendDialogResult", moduleName, JsDialogSession::SendDialogResult);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // nampspace OHOS
|
28
frameworks/js/napi/js_dialog_session/js_dialog_session.h
Normal file
28
frameworks/js/napi/js_dialog_session/js_dialog_session.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_JS_DIALOG_SESSION_H
|
||||
#define OHOS_ABILITY_RUNTIME_JS_DIALOG_SESSION_H
|
||||
|
||||
#include "js_dialog_session_utils.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
napi_value JsDialogSessionInit(napi_env env, napi_value exportObj);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_JS_DIALOG_SESSION_H
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "js_dialog_session_utils.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "json/json.h"
|
||||
#include "napi_common_ability.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi_remote_object.h"
|
||||
#include "want.h"
|
||||
#include "want_params_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
napi_value WrapArrayDialogAbilityInfoToJS(napi_env env, const std::vector<DialogAbilityInfo> &value)
|
||||
{
|
||||
napi_value jsArray = nullptr;
|
||||
napi_value jsValue = nullptr;
|
||||
uint32_t index = 0;
|
||||
|
||||
NAPI_CALL(env, napi_create_array(env, &jsArray));
|
||||
for (uint32_t i = 0; i < value.size(); i++) {
|
||||
jsValue = WrapDialogAbilityInfo(env, value[i]);
|
||||
if (jsValue && napi_set_element(env, jsArray, index, jsValue) == napi_ok) {
|
||||
index++;
|
||||
}
|
||||
}
|
||||
return jsArray;
|
||||
}
|
||||
|
||||
napi_value WrapDialogAbilityInfo(napi_env env, const AAFwk::DialogAbilityInfo &dialogAbilityInfo)
|
||||
{
|
||||
napi_value jsObject = nullptr;
|
||||
napi_value jsValue = nullptr;
|
||||
NAPI_CALL(env, napi_create_object(env, &jsObject));
|
||||
|
||||
jsValue = nullptr;
|
||||
jsValue = WrapStringToJS(env, dialogAbilityInfo.bundleName);
|
||||
SetPropertyValueByPropertyName(env, jsObject, "bundleName", jsValue);
|
||||
jsValue = WrapStringToJS(env, dialogAbilityInfo.moduleName);
|
||||
SetPropertyValueByPropertyName(env, jsObject, "moduleName", jsValue);
|
||||
jsValue = WrapStringToJS(env, dialogAbilityInfo.abilityName);
|
||||
SetPropertyValueByPropertyName(env, jsObject, "abilityName", jsValue);
|
||||
|
||||
jsValue = nullptr;
|
||||
jsValue = WrapInt32ToJS(env, dialogAbilityInfo.bundleIconId);
|
||||
SetPropertyValueByPropertyName(env, jsObject, "bundleIconId", jsValue);
|
||||
jsValue = WrapInt32ToJS(env, dialogAbilityInfo.bundleLabelId);
|
||||
SetPropertyValueByPropertyName(env, jsObject, "bundleLabelId", jsValue);
|
||||
jsValue = WrapInt32ToJS(env, dialogAbilityInfo.abilityIconId);
|
||||
SetPropertyValueByPropertyName(env, jsObject, "abilityIconId", jsValue);
|
||||
jsValue = WrapInt32ToJS(env, dialogAbilityInfo.abilityLabelId);
|
||||
SetPropertyValueByPropertyName(env, jsObject, "abilityLabelId", jsValue);
|
||||
|
||||
return jsObject;
|
||||
}
|
||||
|
||||
napi_value WrapDialogSessionInfo(napi_env env, const AAFwk::DialogSessionInfo &dialogSessionInfo)
|
||||
{
|
||||
napi_value jsObject = nullptr;
|
||||
napi_value jsValue = nullptr;
|
||||
NAPI_CALL(env, napi_create_object(env, &jsObject));
|
||||
jsValue = WrapDialogAbilityInfo(env, dialogSessionInfo.callerAbilityInfo);
|
||||
SetPropertyValueByPropertyName(env, jsObject, "callerAbilityInfo", jsValue);
|
||||
|
||||
jsValue = nullptr;
|
||||
jsValue = WrapArrayDialogAbilityInfoToJS(env, dialogSessionInfo.targetAbilityInfos);
|
||||
SetPropertyValueByPropertyName(env, jsObject, "targetAbilityInfos", jsValue);
|
||||
|
||||
jsValue = nullptr;
|
||||
jsValue = AppExecFwk::WrapWantParams(env, dialogSessionInfo.parameters);
|
||||
SetPropertyValueByPropertyName(env, jsObject, "parameters", jsValue);
|
||||
|
||||
return jsObject;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // nampspace OHOS
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_JS_DIALOG_SESSION_UTILS_H
|
||||
#define OHOS_ABILITY_RUNTIME_JS_DIALOG_SESSION_UTILS_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "js_dialog_session.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "dialog_session_record.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
napi_value WrapArrayDialogAbilityInfoToJS(napi_env env, const std::vector<DialogAbilityInfo> &value);
|
||||
napi_value WrapDialogSessionInfo(napi_env env, const AAFwk::DialogSessionInfo &dialogSessionInfo);
|
||||
napi_value WrapDialogAbilityInfo(napi_env env, const AAFwk::DialogAbilityInfo &dialogAbilityInfo);
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_JS_DIALOG_SESSION_UTILS_H
|
29
frameworks/js/napi/js_dialog_session/native_module.cpp
Normal file
29
frameworks/js/napi/js_dialog_session/native_module.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "js_dialog_session.h"
|
||||
#include "napi/native_api.h"
|
||||
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_filename = "app/ability/libdialogsession_napi.so/dialogsession.js",
|
||||
.nm_register_func = OHOS::AbilityRuntime::JsDialogSessionInit,
|
||||
.nm_modname = "app.ability.dialogSession",
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor)) void NAPI_app_ability_dialogsession_AutoRegister(void)
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
@ -651,6 +651,11 @@ private:
|
||||
}
|
||||
uint32_t nativeArrayLen = 0;
|
||||
napi_get_array_length(env, argv[0], &nativeArrayLen);
|
||||
if (nativeArrayLen == 0) {
|
||||
HILOG_ERROR("OnMoveMissionsToForeground MissionId is null");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
napi_value element = nullptr;
|
||||
for (uint32_t i = 0; i < nativeArrayLen; i++) {
|
||||
int32_t missionId = 0;
|
||||
@ -705,6 +710,11 @@ private:
|
||||
}
|
||||
uint32_t nativeArrayLen = 0;
|
||||
napi_get_array_length(env, argv[0], &nativeArrayLen);
|
||||
if (nativeArrayLen == 0) {
|
||||
HILOG_ERROR("OnMoveMissionsToBackground MissionId is null");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
napi_value element = nullptr;
|
||||
for (uint32_t i = 0; i < nativeArrayLen; i++) {
|
||||
int32_t missionId;
|
||||
|
@ -1199,7 +1199,7 @@ void UvWorkNotifySnapshot(uv_work_t *work, int status)
|
||||
result[0] =
|
||||
WrapString(registerMissionCB->cbBase.cbInfo.env, registerMissionCB->deviceId.c_str(), "deviceId");
|
||||
result[1] =
|
||||
WrapInt32(registerMissionCB->cbBase.cbInfo.env, registerMissionCB->missionId, "missionId");
|
||||
CreateInt32(registerMissionCB->cbBase.cbInfo.env, registerMissionCB->missionId, "missionId");
|
||||
CallbackReturn(&result[0], registerMissionCB);
|
||||
|
||||
napi_close_handle_scope(registerMissionCB->cbBase.cbInfo.env, scope);
|
||||
@ -1282,7 +1282,7 @@ void UvWorkNotifyNetDisconnect(uv_work_t *work, int status)
|
||||
WrapString(registerMissionCB->cbBase.cbInfo.env, registerMissionCB->deviceId.c_str(), "deviceId");
|
||||
HILOG_INFO("UvWorkNotifyNetDisconnect, state = %{public}d", registerMissionCB->state);
|
||||
result[1] =
|
||||
WrapInt32(registerMissionCB->cbBase.cbInfo.env, registerMissionCB->state, "state");
|
||||
CreateInt32(registerMissionCB->cbBase.cbInfo.env, registerMissionCB->state, "state");
|
||||
|
||||
CallbackReturn(&result[0], registerMissionCB);
|
||||
|
||||
@ -1341,7 +1341,7 @@ void UnRegisterMissionExecuteCB(napi_env env, void *data)
|
||||
registration = registration_[registerMissionCB->deviceId];
|
||||
} else {
|
||||
HILOG_INFO("registration not exits.");
|
||||
registerMissionCB->result = -1;
|
||||
registerMissionCB->result = INVALID_PARAMETERS_ERR;
|
||||
return;
|
||||
}
|
||||
registerMissionCB->missionRegistration = registration;
|
||||
@ -1511,15 +1511,11 @@ napi_value WrapString(napi_env &env, const std::string ¶m, const std::string
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
|
||||
napi_value jsObject = nullptr;
|
||||
napi_create_object(env, &jsObject);
|
||||
|
||||
napi_value jsValue = nullptr;
|
||||
HILOG_DEBUG("%{public}s called. %{public}s = %{public}s", __func__, paramName.c_str(), param.c_str());
|
||||
napi_create_string_utf8(env, param.c_str(), NAPI_AUTO_LENGTH, &jsValue);
|
||||
napi_set_named_property(env, jsObject, paramName.c_str(), jsValue);
|
||||
|
||||
return jsObject;
|
||||
return jsValue;
|
||||
}
|
||||
|
||||
napi_value WrapInt32(napi_env &env, int32_t num, const std::string ¶mName)
|
||||
@ -1537,6 +1533,16 @@ napi_value WrapInt32(napi_env &env, int32_t num, const std::string ¶mName)
|
||||
return jsObject;
|
||||
}
|
||||
|
||||
napi_value CreateInt32(napi_env &env, int32_t num, const std::string ¶mName)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s called. %{public}s = %{public}d", __func__, paramName.c_str(), num);
|
||||
|
||||
napi_value jsValue = nullptr;
|
||||
napi_create_int32(env, num, &jsValue);
|
||||
|
||||
return jsValue;
|
||||
}
|
||||
|
||||
ContinueAbilityCB *CreateContinueAbilityCBCBInfo(napi_env &env)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
|
@ -39,6 +39,7 @@ napi_value NAPI_NotifyToOff(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_ContinueAbility(napi_env env, napi_callback_info info);
|
||||
napi_value WrapString(napi_env &env, const std::string &deviceId, const std::string ¶mName);
|
||||
napi_value WrapInt32(napi_env &env, int32_t num, const std::string ¶mName);
|
||||
napi_value CreateInt32(napi_env &env, int32_t num, const std::string ¶mName);
|
||||
|
||||
class NAPIMissionContinue : public MissionContinueStub {
|
||||
public:
|
||||
|
@ -63,6 +63,7 @@ ohos_shared_library("particleability") {
|
||||
|
||||
if (ability_runtime_relational) {
|
||||
include_dirs += [
|
||||
"${common_tool_path}",
|
||||
"${relational_store_napi_path}/common/include",
|
||||
"${relational_store_napi_path}/dataability/include",
|
||||
"${relational_store_napi_path}/rdb/include",
|
||||
|
@ -105,6 +105,10 @@ class ServiceExtensionContext extends ExtensionContext {
|
||||
return this.__context_impl__.terminateSelf(callback);
|
||||
}
|
||||
|
||||
requestModalUIExtension(want, callback) {
|
||||
return this.__context_impl__.requestModalUIExtension(want, callback);
|
||||
}
|
||||
|
||||
startAbilityByCall(want) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (typeof want !== 'object' || want == null) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2022-2023 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
|
||||
@ -30,6 +30,7 @@ ohos_shared_library("uripermissionmanager_napi") {
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
|
||||
"${ability_runtime_native_path}/ability/native:abilitykit_native",
|
||||
"${ability_runtime_services_path}/common:app_util",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
@ -39,8 +40,9 @@ ohos_shared_library("uripermissionmanager_napi") {
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"ipc:ipc_napi_common",
|
||||
"ipc:ipc_napi",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 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
|
||||
@ -18,11 +18,13 @@
|
||||
#include "ability_business_error.h"
|
||||
#include "ability_manager_errors.h"
|
||||
#include "ability_runtime_error_util.h"
|
||||
#include "app_utils.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "js_error_utils.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "parameters.h"
|
||||
#include "tokenid_kit.h"
|
||||
#include "uri.h"
|
||||
#include "uri_permission_manager_client.h"
|
||||
@ -92,8 +94,14 @@ private:
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[uriStr, flag, targetBundleName](napi_env env, NapiAsyncTask& task, int32_t status) {
|
||||
Uri uri(uriStr);
|
||||
auto errCode = AAFwk::UriPermissionManagerClient::GetInstance().GrantUriPermission(uri, flag,
|
||||
targetBundleName, 0);
|
||||
int errCode;
|
||||
if (AAFwk::AppUtils::GetInstance().JudgePCDevice()) {
|
||||
errCode = AAFwk::UriPermissionManagerClient::GetInstance().GrantUriPermissionFor2In1(
|
||||
uri, flag, targetBundleName);
|
||||
} else {
|
||||
errCode = AAFwk::UriPermissionManagerClient::GetInstance().GrantUriPermission(
|
||||
uri, flag, targetBundleName, 0);
|
||||
}
|
||||
if (errCode == ERR_OK) {
|
||||
task.ResolveWithNoError(env, CreateJsUndefined(env));
|
||||
} else if (errCode == AAFwk::CHECK_PERMISSION_FAILED) {
|
||||
|
@ -88,6 +88,7 @@ napi_value WantConstantInit(napi_env env, napi_value exports)
|
||||
SetNamedProperty(env, Flags, 0x00008000, "FLAG_ABILITY_CLEAR_MISSION");
|
||||
SetNamedProperty(env, Flags, 0x10000000, "FLAG_ABILITY_NEW_MISSION");
|
||||
SetNamedProperty(env, Flags, 0x20000000, "FLAG_ABILITY_MISSION_TOP");
|
||||
SetNamedProperty(env, Flags, 0x40000000, "FLAG_START_WITHOUT_TIPS");
|
||||
|
||||
#ifdef ENABLE_ERRCODE
|
||||
napi_value params = nullptr;
|
||||
|
@ -772,10 +772,17 @@ int32_t JsWantAgent::GetTriggerInfo(napi_env env, napi_value param, TriggerInfo
|
||||
|
||||
std::shared_ptr<AAFwk::WantParams> extraInfo = nullptr;
|
||||
bool hasExtraInfo = false;
|
||||
napi_has_named_property(env, param, "extraInfo", &hasExtraInfo);
|
||||
napi_value jsExtraInfo = nullptr;
|
||||
napi_has_named_property(env, param, "extraInfos", &hasExtraInfo);
|
||||
if (hasExtraInfo) {
|
||||
napi_get_named_property(env, param, "extraInfos", &jsExtraInfo);
|
||||
} else {
|
||||
napi_has_named_property(env, param, "extraInfo", &hasExtraInfo);
|
||||
if (hasExtraInfo) {
|
||||
napi_get_named_property(env, param, "extraInfo", &jsExtraInfo);
|
||||
}
|
||||
}
|
||||
if (hasExtraInfo) {
|
||||
napi_value jsExtraInfo = nullptr;
|
||||
napi_get_named_property(env, param, "extraInfo", &jsExtraInfo);
|
||||
extraInfo = std::make_shared<AAFwk::WantParams>();
|
||||
if (!UnwrapWantParams(env, (jsExtraInfo),
|
||||
*extraInfo)) {
|
||||
@ -913,10 +920,17 @@ int32_t JsWantAgent::GetWantAgentParam(napi_env env, napi_callback_info info, Wa
|
||||
}
|
||||
|
||||
bool hasExtraInfo = false;
|
||||
napi_has_named_property(env, argv[0], "extraInfo", &hasExtraInfo);
|
||||
napi_value jsExtraInfo = nullptr;
|
||||
napi_has_named_property(env, argv[0], "extraInfos", &hasExtraInfo);
|
||||
if (hasExtraInfo) {
|
||||
napi_get_named_property(env, argv[0], "extraInfos", &jsExtraInfo);
|
||||
} else {
|
||||
napi_has_named_property(env, argv[0], "extraInfo", &hasExtraInfo);
|
||||
if (hasExtraInfo) {
|
||||
napi_get_named_property(env, argv[0], "extraInfo", &jsExtraInfo);
|
||||
}
|
||||
}
|
||||
if (hasExtraInfo) {
|
||||
napi_value jsExtraInfo = nullptr;
|
||||
napi_get_named_property(env, argv[0], "extraInfo", &jsExtraInfo);
|
||||
if (!CheckTypeForNapiValue(env, jsExtraInfo, napi_object)) {
|
||||
HILOG_ERROR("ExtraInfo type error!");
|
||||
return PARAMETER_ERROR;
|
||||
@ -1300,6 +1314,8 @@ napi_value JsWantAgentInit(napi_env env, napi_value exportObj)
|
||||
|
||||
napi_set_named_property(env, exportObj, "WantAgentFlags", WantAgentFlagsInit(env));
|
||||
napi_set_named_property(env, exportObj, "OperationType", WantAgentOperationTypeInit(env));
|
||||
napi_set_named_property(env, exportObj, "actionFlags", WantAgentFlagsInit(env));
|
||||
napi_set_named_property(env, exportObj, "actionType", WantAgentOperationTypeInit(env));
|
||||
|
||||
HILOG_DEBUG("JsWantAgentInit BindNativeFunction called");
|
||||
const char* moduleName = "JsWantAgent";
|
||||
|
@ -38,6 +38,9 @@ config("ability_context_public_config") {
|
||||
if (ability_runtime_graphics) {
|
||||
defines = [ "SUPPORT_GRAPHICS" ]
|
||||
}
|
||||
if (hichecker_enabled) {
|
||||
defines += [ "SUPPORT_HICHECKER" ]
|
||||
}
|
||||
}
|
||||
|
||||
ohos_shared_library("ability_context_native") {
|
||||
@ -49,6 +52,7 @@ ohos_shared_library("ability_context_native") {
|
||||
"ability_runtime/authorization_result.cpp",
|
||||
"ability_runtime/connection_manager.cpp",
|
||||
"ability_runtime/dialog_request_callback_impl.cpp",
|
||||
"ability_runtime/dialog_ui_extension_callback.cpp",
|
||||
"ability_runtime/js_extension_context.cpp",
|
||||
"ability_runtime/local_call_container.cpp",
|
||||
"ability_runtime/local_call_record.cpp",
|
||||
@ -71,20 +75,28 @@ ohos_shared_library("ability_context_native") {
|
||||
"ability_base:want",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libtoken_callback_sdk",
|
||||
"ace_engine:ace_uicontent",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"faultloggerd:libdfx_dumpcatcher",
|
||||
"hichecker:libhichecker",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
"window_manager:libwsutils",
|
||||
"window_manager:scene_session",
|
||||
"window_manager:session_manager",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [
|
||||
"ace_engine:ace_uicontent",
|
||||
"window_manager:libwsutils",
|
||||
"window_manager:scene_session",
|
||||
"window_manager:session_manager_lite",
|
||||
]
|
||||
}
|
||||
|
||||
if (hichecker_enabled) {
|
||||
external_deps += [ "hichecker:libhichecker" ]
|
||||
}
|
||||
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "hitrace_meter.h"
|
||||
#include "connection_manager.h"
|
||||
#include "dialog_request_callback_impl.h"
|
||||
#include "dialog_ui_extension_callback.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "remote_object_wrapper.h"
|
||||
#include "request_constants.h"
|
||||
@ -36,6 +37,7 @@ namespace AbilityRuntime {
|
||||
const size_t AbilityContext::CONTEXT_TYPE_ID(std::hash<const char*> {} ("AbilityContext"));
|
||||
const std::string START_ABILITY_TYPE = "ABILITY_INNER_START_WITH_ACCOUNT";
|
||||
const std::string UIEXTENSION_TARGET_TYPE_KEY = "ability.want.params.uiExtensionTargetType";
|
||||
const std::string FLAG_AUTH_READ_URI_PERMISSION = "ability.want.params.uriPermissionFlag";
|
||||
|
||||
struct RequestResult {
|
||||
int32_t resultCode {0};
|
||||
@ -96,6 +98,11 @@ std::string AbilityContextImpl::GetTempDir()
|
||||
return stageContext_ ? stageContext_->GetTempDir() : "";
|
||||
}
|
||||
|
||||
std::string AbilityContextImpl::GetResourceDir()
|
||||
{
|
||||
return stageContext_ ? stageContext_->GetResourceDir() : "";
|
||||
}
|
||||
|
||||
std::string AbilityContextImpl::GetFilesDir()
|
||||
{
|
||||
return stageContext_ ? stageContext_->GetFilesDir() : "";
|
||||
@ -138,6 +145,22 @@ ErrCode AbilityContextImpl::StartAbility(const AAFwk::Want& want, int requestCod
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("StartAbility");
|
||||
int32_t screenMode = want.GetIntParam(AAFwk::SCREEN_MODE_KEY, AAFwk::IDLE_SCREEN_MODE);
|
||||
if (screenMode == AAFwk::HALF_SCREEN_MODE) {
|
||||
auto uiContent = GetUIContent();
|
||||
if (uiContent == nullptr) {
|
||||
HILOG_ERROR("uiContent is nullptr");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
Ace::ModalUIExtensionCallbacks callback;
|
||||
Ace::ModalUIExtensionConfig config;
|
||||
int32_t sessionId = uiContent->CreateModalUIExtension(want, callback, config);
|
||||
if (sessionId == 0) {
|
||||
HILOG_ERROR("CreateModalUIExtension failed");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, requestCode);
|
||||
if (err != ERR_OK) {
|
||||
HILOG_ERROR("StartAbility. ret=%{public}d", err);
|
||||
@ -149,7 +172,7 @@ ErrCode AbilityContextImpl::StartAbilityAsCaller(const AAFwk::Want &want, int re
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("StartAbilityAsCaller");
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbilityAsCaller(want, token_, requestCode);
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbilityAsCaller(want, token_, nullptr, requestCode);
|
||||
if (err != ERR_OK) {
|
||||
HILOG_ERROR("StartAbilityAsCaller. ret=%{public}d", err);
|
||||
}
|
||||
@ -185,7 +208,7 @@ ErrCode AbilityContextImpl::StartAbilityAsCaller(const AAFwk::Want &want, const
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("StartAbilityAsCaller");
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbilityAsCaller(want,
|
||||
startOptions, token_, requestCode);
|
||||
startOptions, token_, nullptr, requestCode);
|
||||
if (err != ERR_OK) {
|
||||
HILOG_ERROR("StartAbilityAsCaller. ret=%{public}d", err);
|
||||
}
|
||||
@ -210,7 +233,7 @@ ErrCode AbilityContextImpl::StartAbilityForResult(const AAFwk::Want& want, int r
|
||||
{
|
||||
HILOG_DEBUG("StartAbilityForResult");
|
||||
resultCallbacks_.insert(make_pair(requestCode, std::move(task)));
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, requestCode);
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, requestCode, -1);
|
||||
if (err != ERR_OK && err != AAFwk::START_ABILITY_WAITING) {
|
||||
HILOG_ERROR("StartAbilityForResult. ret=%{public}d", err);
|
||||
OnAbilityResultInner(requestCode, err, want);
|
||||
@ -289,7 +312,7 @@ ErrCode AbilityContextImpl::TerminateAbilityWithResult(const AAFwk::Want& want,
|
||||
isTerminating_ = true;
|
||||
|
||||
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
|
||||
auto sessionToken = sessionToken_.promote();
|
||||
auto sessionToken = GetSessionToken();
|
||||
if (sessionToken == nullptr) {
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
@ -309,10 +332,17 @@ ErrCode AbilityContextImpl::TerminateAbilityWithResult(const AAFwk::Want& want,
|
||||
|
||||
void AbilityContextImpl::SetWeakSessionToken(const wptr<IRemoteObject>& sessionToken)
|
||||
{
|
||||
std::lock_guard lock(sessionTokenMutex_);
|
||||
HILOG_DEBUG("Start calling SetWeakSessionToken.");
|
||||
sessionToken_ = sessionToken;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> AbilityContextImpl::GetSessionToken()
|
||||
{
|
||||
std::lock_guard lock(sessionTokenMutex_);
|
||||
return sessionToken_.promote();
|
||||
}
|
||||
|
||||
void AbilityContextImpl::OnAbilityResult(int requestCode, int resultCode, const AAFwk::Want& resultData)
|
||||
{
|
||||
HILOG_DEBUG("Start calling OnAbilityResult.");
|
||||
@ -416,6 +446,12 @@ std::shared_ptr<Context> AbilityContextImpl::CreateModuleContext(const std::stri
|
||||
return stageContext_ ? stageContext_->CreateModuleContext(bundleName, moduleName) : nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Global::Resource::ResourceManager> AbilityContextImpl::CreateModuleResourceManager(
|
||||
const std::string &bundleName, const std::string &moduleName)
|
||||
{
|
||||
return stageContext_ ? stageContext_->CreateModuleResourceManager(bundleName, moduleName) : nullptr;
|
||||
}
|
||||
|
||||
void AbilityContextImpl::SetAbilityInfo(const std::shared_ptr<AppExecFwk::AbilityInfo>& abilityInfo)
|
||||
{
|
||||
abilityInfo_ = abilityInfo;
|
||||
@ -476,7 +512,7 @@ ErrCode AbilityContextImpl::TerminateSelf()
|
||||
{
|
||||
HILOG_DEBUG("TerminateSelf");
|
||||
isTerminating_ = true;
|
||||
auto sessionToken = sessionToken_.promote();
|
||||
auto sessionToken = GetSessionToken();
|
||||
if (sessionToken == nullptr) {
|
||||
HILOG_WARN("sessionToken is null");
|
||||
}
|
||||
@ -747,6 +783,11 @@ ErrCode AbilityContextImpl::StartAbilityByType(const std::string &type,
|
||||
wantParams.SetParam(UIEXTENSION_TARGET_TYPE_KEY, AAFwk::String::Box(type));
|
||||
AAFwk::Want want;
|
||||
want.SetParams(wantParams);
|
||||
if (wantParams.HasParam(FLAG_AUTH_READ_URI_PERMISSION)) {
|
||||
int32_t flag = wantParams.GetIntParam(FLAG_AUTH_READ_URI_PERMISSION, 0);
|
||||
want.SetFlags(flag);
|
||||
wantParams.Remove(FLAG_AUTH_READ_URI_PERMISSION);
|
||||
}
|
||||
Ace::ModalUIExtensionCallbacks callback;
|
||||
callback.onError = std::bind(&JsUIExtensionCallback::OnError, uiExtensionCallbacks, std::placeholders::_1);
|
||||
callback.onRelease = std::bind(&JsUIExtensionCallback::OnRelease, uiExtensionCallbacks, std::placeholders::_1);
|
||||
@ -760,6 +801,38 @@ ErrCode AbilityContextImpl::StartAbilityByType(const std::string &type,
|
||||
uiExtensionCallbacks->SetSessionId(sessionId);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode AbilityContextImpl::CreateModalUIExtensionWithApp(const AAFwk::Want &want)
|
||||
{
|
||||
HILOG_DEBUG("call");
|
||||
auto uiContent = GetUIContent();
|
||||
if (uiContent == nullptr) {
|
||||
HILOG_ERROR("uiContent is nullptr");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
auto disposedCallback = std::make_shared<DialogUIExtensionCallback>();
|
||||
Ace::ModalUIExtensionCallbacks callback;
|
||||
callback.onError = std::bind(&DialogUIExtensionCallback::OnError, disposedCallback);
|
||||
callback.onRelease = std::bind(&DialogUIExtensionCallback::OnRelease, disposedCallback);
|
||||
Ace::ModalUIExtensionConfig config;
|
||||
int32_t sessionId = uiContent->CreateModalUIExtension(want, callback, config);
|
||||
if (sessionId == 0) {
|
||||
HILOG_ERROR("CreateModalUIExtension is failed");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
disposedCallback->SetUIContent(uiContent);
|
||||
disposedCallback->SetSessionId(sessionId);
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
ErrCode AbilityContextImpl::RequestModalUIExtension(const AAFwk::Want& want)
|
||||
{
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->RequestModalUIExtension(want);
|
||||
if (err != ERR_OK) {
|
||||
HILOG_ERROR("RequestModalUIExtension is failed %{public}d", err);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
@ -18,7 +18,9 @@
|
||||
#include "ability_context.h"
|
||||
#include "ability_manager_client.h"
|
||||
#include "dfx_dump_catcher.h"
|
||||
#ifdef SUPPORT_HICHECKER
|
||||
#include "hichecker.h"
|
||||
#endif
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -237,6 +239,7 @@ bool ConnectionManager::RemoveConnection(const sptr<AbilityConnection> connectio
|
||||
void ConnectionManager::ReportConnectionLeakEvent(const int pid, const int tid)
|
||||
{
|
||||
HILOG_DEBUG("pid:%{public}d, tid:%{public}d.", pid, tid);
|
||||
#ifdef SUPPORT_HICHECKER
|
||||
if (HiChecker::Contains(Rule::RULE_CHECK_ABILITY_CONNECTION_LEAK)) {
|
||||
DfxDumpCatcher dumpLog;
|
||||
std::string stackTrace;
|
||||
@ -252,6 +255,7 @@ void ConnectionManager::ReportConnectionLeakEvent(const int pid, const int tid)
|
||||
HILOG_ERROR("dumpCatch stackTrace failed.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ConnectionManager::IsConnectCallerEqual(const sptr<IRemoteObject>& connectCaller,
|
||||
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "dialog_ui_extension_callback.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
void DialogUIExtensionCallback::OnRelease()
|
||||
{
|
||||
HILOG_DEBUG("Called");
|
||||
|
||||
if (uiContent_ == nullptr) {
|
||||
HILOG_ERROR("uiContent_ is nullptr.");
|
||||
return;
|
||||
}
|
||||
uiContent_->CloseModalUIExtension(sessionId_);
|
||||
}
|
||||
|
||||
void DialogUIExtensionCallback::OnError()
|
||||
{
|
||||
HILOG_DEBUG("Called");
|
||||
|
||||
if (uiContent_ == nullptr) {
|
||||
HILOG_ERROR("uiContent_ is nullptr.");
|
||||
return;
|
||||
}
|
||||
uiContent_->CloseModalUIExtension(sessionId_);
|
||||
}
|
||||
|
||||
void DialogUIExtensionCallback::SetSessionId(int32_t sessionId)
|
||||
{
|
||||
sessionId_= sessionId;
|
||||
}
|
||||
|
||||
void DialogUIExtensionCallback::SetUIContent(Ace::UIContent *uiContent)
|
||||
{
|
||||
uiContent_ = uiContent;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -21,32 +21,27 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
int LocalCallContainer::StartAbilityByCallInner(const Want& want, const std::shared_ptr<CallerCallBack>& callback,
|
||||
const sptr<IRemoteObject>& callerToken, int32_t accountId)
|
||||
int LocalCallContainer::StartAbilityByCallInner(const Want& want, std::shared_ptr<CallerCallBack> callback,
|
||||
sptr<IRemoteObject> callerToken, int32_t accountId)
|
||||
{
|
||||
HILOG_DEBUG("start ability by call.");
|
||||
AppExecFwk::ElementName element = want.GetElement();
|
||||
HILOG_DEBUG("start ability by call, element:%{public}s", element.GetURI().c_str());
|
||||
if (callback == nullptr) {
|
||||
HILOG_ERROR("callback is nullptr.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
if (want.GetElement().GetBundleName().empty() ||
|
||||
want.GetElement().GetAbilityName().empty()) {
|
||||
if (element.GetBundleName().empty() || element.GetAbilityName().empty()) {
|
||||
HILOG_ERROR("the element of want is empty.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
if (want.GetElement().GetDeviceID().empty()) {
|
||||
if (element.GetDeviceID().empty()) {
|
||||
HILOG_DEBUG("start ability by call, element:DeviceID is empty");
|
||||
}
|
||||
HILOG_DEBUG("start ability by call, element:%{public}s", want.GetElement().GetURI().c_str());
|
||||
|
||||
int32_t oriValidUserId = GetValidUserId(accountId);
|
||||
AppExecFwk::ElementName element = want.GetElement();
|
||||
std::shared_ptr<LocalCallRecord> localCallRecord;
|
||||
if (!GetCallLocalRecord(element, localCallRecord, oriValidUserId)) {
|
||||
localCallRecord = std::make_shared<LocalCallRecord>(element);
|
||||
if (localCallRecord == nullptr) {
|
||||
HILOG_ERROR("LocalCallContainer::StartAbilityByCallInner Create local call record failed");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
localCallRecord->SetUserId(oriValidUserId);
|
||||
HILOG_DEBUG("create local call record and set user id[%{public}d] to record", oriValidUserId);
|
||||
}
|
||||
@ -61,20 +56,16 @@ int LocalCallContainer::StartAbilityByCallInner(const Want& want, const std::sha
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
auto abilityClient = AAFwk::AbilityManagerClient::GetInstance();
|
||||
if (abilityClient == nullptr) {
|
||||
HILOG_ERROR("LocalCallContainer::StartAbilityByCallInner abilityClient is nullptr");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
sptr<CallerConnection> connect = new (std::nothrow) CallerConnection();
|
||||
if (connect == nullptr) {
|
||||
HILOG_ERROR("LocalCallContainer::StartAbilityByCallInner Create local call connection failed");
|
||||
HILOG_ERROR("StartAbilityByCallInner Create local call connection failed");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
connections_.emplace(connect);
|
||||
connect->SetRecordAndContainer(localCallRecord, shared_from_this());
|
||||
HILOG_DEBUG("LocalCallContainer::StartAbilityByCallInner connections_.size is %{public}zu", connections_.size());
|
||||
auto retval = abilityClient->StartAbilityByCall(want, connect, callerToken, oriValidUserId);
|
||||
HILOG_DEBUG("StartAbilityByCallInner connections_.size is %{public}zu", connections_.size());
|
||||
auto retval = AAFwk::AbilityManagerClient::GetInstance()->StartAbilityByCall(want, connect,
|
||||
callerToken, oriValidUserId);
|
||||
if (retval != ERR_OK) {
|
||||
ClearFailedCallConnection(callback);
|
||||
}
|
||||
@ -95,7 +86,7 @@ int LocalCallContainer::ReleaseCall(const std::shared_ptr<CallerCallBack>& callb
|
||||
}
|
||||
auto localCallRecord = callback->GetRecord();
|
||||
if (localCallRecord == nullptr) {
|
||||
HILOG_ERROR("LocalCallContainer::ReleaseCall abilityClient is nullptr");
|
||||
HILOG_ERROR("LocalCallContainer::ReleaseCall localCallRecord is nullptr");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
localCallRecord->RemoveCaller(callback);
|
||||
|
@ -12,7 +12,6 @@
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//commonlibrary/memory_utils/purgeable_mem_config.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
import("//foundation/distributeddatamgr/relational_store/relational_store.gni")
|
||||
|
||||
@ -90,6 +89,7 @@ config("ability_public_config") {
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native/recovery/",
|
||||
"${accessibility_path}/interfaces/innerkits/common/include/",
|
||||
"//third_party/libuv/include",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
|
||||
"${ability_runtime_innerkits_path}/ability_manager/include/continuation",
|
||||
@ -166,7 +166,7 @@ ohos_shared_library("abilitykit_utils") {
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_napi_common",
|
||||
"ipc:ipc_napi",
|
||||
"napi:ace_napi",
|
||||
"resource_management:global_resmgr",
|
||||
]
|
||||
@ -250,6 +250,7 @@ ohos_shared_library("abilitykit_native") {
|
||||
"${ability_runtime_native_path}/appkit:app_context",
|
||||
"${ability_runtime_native_path}/appkit:app_context_utils",
|
||||
"${ability_runtime_native_path}/appkit:appkit_delegator",
|
||||
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
|
||||
"${ability_runtime_path}/utils/global/freeze:freeze_util",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
]
|
||||
@ -272,12 +273,11 @@ ohos_shared_library("abilitykit_native") {
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"ipc:ipc_js",
|
||||
"ipc:ipc_napi_common",
|
||||
"ipc:ipc_napi",
|
||||
"napi:ace_napi",
|
||||
"relational_store:native_rdb",
|
||||
"resource_management:global_resmgr",
|
||||
"samgr:samgr_proxy",
|
||||
"window_manager:libwsutils",
|
||||
]
|
||||
|
||||
defines = []
|
||||
@ -287,12 +287,6 @@ ohos_shared_library("abilitykit_native") {
|
||||
defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ]
|
||||
}
|
||||
|
||||
if (purgeable_ashmem_enable && defined(global_parts_info) &&
|
||||
defined(global_parts_info.resourceschedule_memmgr_plugin)) {
|
||||
defines += [ "IMAGE_PURGEABLE_PIXELMAP" ]
|
||||
external_deps += [ "memmgr_plugin:libpurgeablemem_plugin" ]
|
||||
}
|
||||
|
||||
if (efficiency_manager) {
|
||||
external_deps += [ "efficiency_manager:suspend_manager_client" ]
|
||||
defines += [ "EFFICIENCY_MANAGER_ENABLE" ]
|
||||
@ -321,6 +315,7 @@ ohos_shared_library("abilitykit_native") {
|
||||
"input:libmmi-client",
|
||||
"window_manager:libdm",
|
||||
"window_manager:libwm",
|
||||
"window_manager:libwsutils",
|
||||
"window_manager:windowstage_kit",
|
||||
]
|
||||
}
|
||||
@ -359,6 +354,8 @@ config("extensionkit_public_config") {
|
||||
}
|
||||
|
||||
ohos_shared_library("extensionkit_native") {
|
||||
defines = [ "AMS_LOG_TAG = \"Ability\"" ]
|
||||
defines += [ "AMS_LOG_DOMAIN = 0xD001300" ]
|
||||
include_dirs = [
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime",
|
||||
@ -436,7 +433,7 @@ ohos_shared_library("insight_intent_executor") {
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
"ipc:ipc_napi_common",
|
||||
"ipc:ipc_napi",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
@ -480,6 +477,7 @@ ohos_shared_library("uiabilitykit_native") {
|
||||
include_dirs = [
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability",
|
||||
"${ability_runtime_path}/utils/global/time/include",
|
||||
]
|
||||
|
||||
@ -500,6 +498,7 @@ ohos_shared_library("uiabilitykit_native") {
|
||||
deps = [
|
||||
":abilitykit_native",
|
||||
":continuation_ipc",
|
||||
":ui_extension",
|
||||
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
|
||||
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
|
||||
"${ability_runtime_innerkits_path}/runtime:runtime",
|
||||
@ -523,11 +522,9 @@ ohos_shared_library("uiabilitykit_native") {
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
"ipc:ipc_napi_common",
|
||||
"ipc:ipc_napi",
|
||||
"napi:ace_napi",
|
||||
"resource_management:global_resmgr",
|
||||
"window_manager:libwsutils",
|
||||
"window_manager:windowstage_kit",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
@ -536,6 +533,8 @@ ohos_shared_library("uiabilitykit_native") {
|
||||
"ability_base:session_info",
|
||||
"window_manager:libdm",
|
||||
"window_manager:libwm",
|
||||
"window_manager:libwsutils",
|
||||
"window_manager:windowstage_kit",
|
||||
]
|
||||
}
|
||||
|
||||
@ -597,6 +596,8 @@ ohos_shared_library("ability_thread") {
|
||||
}
|
||||
|
||||
ohos_shared_library("form_extension") {
|
||||
defines = [ "AMS_LOG_TAG = \"Ability\"" ]
|
||||
defines += [ "AMS_LOG_DOMAIN = 0xD001300" ]
|
||||
if (ability_runtime_graphics) {
|
||||
include_dirs = [
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native",
|
||||
@ -630,7 +631,7 @@ ohos_shared_library("form_extension") {
|
||||
"form_fwk:formutil_napi",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"ipc:ipc_napi_common",
|
||||
"ipc:ipc_napi",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
}
|
||||
@ -665,6 +666,8 @@ ohos_shared_library("form_extension_module") {
|
||||
}
|
||||
|
||||
ohos_shared_library("service_extension") {
|
||||
defines = [ "AMS_LOG_TAG = \"Ability\"" ]
|
||||
defines += [ "AMS_LOG_DOMAIN = 0xD001300" ]
|
||||
include_dirs = [
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime",
|
||||
@ -684,7 +687,9 @@ ohos_shared_library("service_extension") {
|
||||
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
|
||||
"${ability_runtime_native_path}/ability:ability_context_native",
|
||||
"${ability_runtime_native_path}/ability/native:ability_business_error",
|
||||
"${ability_runtime_native_path}/ability/native:insight_intent_executor",
|
||||
"${ability_runtime_native_path}/appkit:app_context",
|
||||
"${ability_runtime_native_path}/insight_intent/insight_intent_context:insightintentcontext",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
@ -696,7 +701,7 @@ ohos_shared_library("service_extension") {
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
"ipc:ipc_napi_common",
|
||||
"ipc:ipc_napi",
|
||||
"napi:ace_napi",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
@ -906,6 +911,7 @@ group("extension_blocklist_config") {
|
||||
group("extension_module") {
|
||||
deps = [
|
||||
":action_extension_module",
|
||||
":auto_fill_extension_module",
|
||||
":service_extension_module",
|
||||
":share_extension_module",
|
||||
":ui_extension_module",
|
||||
@ -920,6 +926,7 @@ config("ui_extension_public_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"${ability_runtime_path}/interfaces/inner_api/insight_intent/insight_intent_context",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native/insight_intent_executor",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability",
|
||||
]
|
||||
@ -927,6 +934,7 @@ config("ui_extension_public_config") {
|
||||
|
||||
ohos_shared_library("ui_extension") {
|
||||
sources = [
|
||||
"${ability_runtime_native_path}/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/ui_extension_ability/js_ui_extension.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/ui_extension_ability/js_ui_extension_base.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp",
|
||||
@ -946,6 +954,7 @@ ohos_shared_library("ui_extension") {
|
||||
"${ability_runtime_native_path}/ability/native:ability_business_error",
|
||||
"${ability_runtime_native_path}/ability/native:insight_intent_executor",
|
||||
"${ability_runtime_native_path}/appkit:app_context",
|
||||
"${ability_runtime_native_path}/appkit:app_context_utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
@ -953,18 +962,20 @@ ohos_shared_library("ui_extension") {
|
||||
"ability_base:want",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libtokenid_sdk",
|
||||
"ace_engine:ace_uicontent",
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
"ipc:ipc_napi_common",
|
||||
"ipc:ipc_napi",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [ "window_manager:libwm" ]
|
||||
external_deps += [
|
||||
"ace_engine:ace_uicontent",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
}
|
||||
|
||||
subsystem_name = "ability"
|
||||
@ -1027,7 +1038,7 @@ ohos_shared_library("share_extension") {
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_napi_common",
|
||||
"ipc:ipc_napi",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
@ -1069,7 +1080,7 @@ ohos_shared_library("action_extension") {
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_napi_common",
|
||||
"ipc:ipc_napi",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
@ -1159,3 +1170,86 @@ ohos_shared_library("action_extension_module") {
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
||||
|
||||
config("auto_fill_extension_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native/auto_fill_extension_ability",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("auto_fill_extension") {
|
||||
configs = [ ":auto_fill_extension_config" ]
|
||||
|
||||
sources = [
|
||||
"${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/auto_fill_extension.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/js_auto_fill_extension.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/js_auto_fill_extension_context.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/js_auto_fill_extension_util.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/js_fill_request_callback.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/js_save_request_callback.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
":abilitykit_native",
|
||||
":insight_intent_executor",
|
||||
":ui_extension",
|
||||
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
|
||||
"${ability_runtime_innerkits_path}/runtime:runtime",
|
||||
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
|
||||
"${ability_runtime_native_path}/ability:ability_context_native",
|
||||
"${ability_runtime_native_path}/ability/native:ability_business_error",
|
||||
"${ability_runtime_native_path}/appkit:app_context",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:view_data",
|
||||
"ability_base:want",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libtokenid_sdk",
|
||||
"ace_engine:ace_uicontent",
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
"ipc:ipc_napi",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [ "window_manager:libwm" ]
|
||||
}
|
||||
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
||||
|
||||
ohos_shared_library("auto_fill_extension_module") {
|
||||
sources = [ "${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/auto_fill_extension_module_loader.cpp" ]
|
||||
|
||||
configs = [
|
||||
":ability_config",
|
||||
":auto_fill_extension_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
":auto_fill_extension",
|
||||
"${ability_runtime_innerkits_path}/runtime:runtime",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:configuration",
|
||||
"ability_base:session_info",
|
||||
"ability_base:want",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"hilog:libhilog",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
relative_install_dir = "extensionability/"
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "ability_post_event_timeout.h"
|
||||
#include "ability_runtime/js_ability.h"
|
||||
#include "abs_shared_result_set.h"
|
||||
#include "bundle_mgr_helper.h"
|
||||
#include "configuration_convertor.h"
|
||||
#include "connection_manager.h"
|
||||
#include "continuation_manager.h"
|
||||
@ -41,6 +42,7 @@
|
||||
#include "reverse_continuation_scheduler_replica_handler_interface.h"
|
||||
#include "runtime.h"
|
||||
#include "scene_board_judgement.h"
|
||||
#include "singleton.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "task_handler_client.h"
|
||||
#include "values_bucket.h"
|
||||
@ -55,10 +57,6 @@
|
||||
#include "key_event.h"
|
||||
#endif
|
||||
|
||||
#ifdef IMAGE_PURGEABLE_PIXELMAP
|
||||
#include "purgeable_resource_manager.h"
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
const std::string Ability::SYSTEM_UI("com.ohos.systemui");
|
||||
@ -171,12 +169,14 @@ void Ability::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
|
||||
securityFlag_ = want.GetBoolParam(DLP_PARAMS_SECURITY_FLAG, false);
|
||||
(const_cast<Want &>(want)).RemoveParam(DLP_PARAMS_SECURITY_FLAG);
|
||||
SetWant(want);
|
||||
sessionInfo_ = sessionInfo;
|
||||
if (sessionInfo != nullptr) {
|
||||
SetSessionToken(sessionInfo->sessionToken);
|
||||
}
|
||||
HILOG_INFO("AbilityName is %{public}s.", abilityInfo_->name.c_str());
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
if (abilityInfo_->type == AppExecFwk::AbilityType::PAGE) {
|
||||
int defualtDisplayId = Rosen::WindowScene::DEFAULT_DISPLAY_ID;
|
||||
int displayId = want.GetIntParam(Want::PARAM_RESV_DISPLAY_ID, defualtDisplayId);
|
||||
int32_t defualtDisplayId = static_cast<int32_t>(Rosen::DisplayManager::GetInstance().GetDefaultDisplayId());
|
||||
int32_t displayId = want.GetIntParam(Want::PARAM_RESV_DISPLAY_ID, defualtDisplayId);
|
||||
HILOG_DEBUG("abilityName:%{public}s, displayId:%{public}d", abilityInfo_->name.c_str(), displayId);
|
||||
if (!abilityInfo_->isStageBasedModel) {
|
||||
auto option = GetWindowOption(want);
|
||||
@ -1036,13 +1036,13 @@ std::shared_ptr<AbilityPostEventTimeout> Ability::CreatePostEventTimeouter(std::
|
||||
int Ability::StartBackgroundRunning(const AbilityRuntime::WantAgent::WantAgent &wantAgent)
|
||||
{
|
||||
#ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
|
||||
auto bundleMgr = GetBundleMgr();
|
||||
if (bundleMgr == nullptr) {
|
||||
HILOG_ERROR("Ability::GetBundleMgr failed");
|
||||
auto bundleMgrHelper = DelayedSingleton<BundleMgrHelper>::GetInstance();
|
||||
if (bundleMgrHelper == nullptr) {
|
||||
HILOG_ERROR("Failed to get bundleMgrHelper.");
|
||||
return ERR_NULL_OBJECT;
|
||||
}
|
||||
if (abilityInfo_ == nullptr) {
|
||||
HILOG_ERROR("ability info is null");
|
||||
HILOG_ERROR("The ability info is nullptr.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
Want want;
|
||||
@ -1050,8 +1050,8 @@ int Ability::StartBackgroundRunning(const AbilityRuntime::WantAgent::WantAgent &
|
||||
want.AddEntity("entity.system.home");
|
||||
want.SetElementName("", abilityInfo_->bundleName, "", "");
|
||||
AppExecFwk::AbilityInfo abilityInfo;
|
||||
bundleMgr->QueryAbilityInfo(want, abilityInfo);
|
||||
std::string appName = bundleMgr->GetAbilityLabel(abilityInfo_->bundleName, abilityInfo.name);
|
||||
bundleMgrHelper->QueryAbilityInfo(want, abilityInfo);
|
||||
std::string appName = bundleMgrHelper->GetAbilityLabel(abilityInfo_->bundleName, abilityInfo.name);
|
||||
uint32_t defaultBgMode = 0;
|
||||
BackgroundTaskMgr::ContinuousTaskParam taskParam = BackgroundTaskMgr::ContinuousTaskParam(false, defaultBgMode,
|
||||
std::make_shared<AbilityRuntime::WantAgent::WantAgent>(wantAgent), abilityInfo_->name, GetToken(), appName);
|
||||
@ -1070,35 +1070,6 @@ int Ability::StopBackgroundRunning()
|
||||
#endif
|
||||
}
|
||||
|
||||
sptr<IBundleMgr> Ability::GetBundleMgr()
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
if (iBundleMgr_ == nullptr) {
|
||||
sptr<ISystemAbilityManager> systemAbilityManager =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
auto remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
|
||||
if (remoteObject == nullptr) {
|
||||
HILOG_ERROR("Failed to get bundle manager service.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
iBundleMgr_ = iface_cast<IBundleMgr>(remoteObject);
|
||||
if (iBundleMgr_ == nullptr) {
|
||||
HILOG_ERROR("Failed to get remote object.");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return iBundleMgr_;
|
||||
}
|
||||
|
||||
void Ability::SetBundleManager(const sptr<IBundleMgr> &bundleManager)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
|
||||
iBundleMgr_ = bundleManager;
|
||||
}
|
||||
|
||||
void Ability::SetStartAbilitySetting(std::shared_ptr<AbilityStartSetting> setting)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
@ -1576,9 +1547,6 @@ void Ability::OnBackground()
|
||||
HILOG_ERROR("Ability::OnBackground error. lifecycle_ == nullptr.");
|
||||
return;
|
||||
}
|
||||
#ifdef IMAGE_PURGEABLE_PIXELMAP
|
||||
PurgeableMem::PurgeableResourceManager::GetInstance().EndAccessPurgeableMem();
|
||||
#endif
|
||||
lifecycle_->DispatchLifecycle(LifeCycle::Event::ON_BACKGROUND);
|
||||
HILOG_DEBUG("end");
|
||||
AAFwk::EventInfo eventInfo;
|
||||
@ -1628,7 +1596,7 @@ void Ability::InitWindow(int32_t displayId, sptr<Rosen::WindowOption> option)
|
||||
HILOG_ERROR("Ability window is nullptr.");
|
||||
return;
|
||||
}
|
||||
abilityWindow_->SetSessionInfo(sessionInfo_);
|
||||
abilityWindow_->SetSessionToken(sessionToken_);
|
||||
abilityWindow_->InitWindow(abilityContext_, sceneListener_, displayId, option, securityFlag_);
|
||||
}
|
||||
|
||||
@ -2139,6 +2107,33 @@ void Ability::ContinuationRestore(const Want &want)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
}
|
||||
|
||||
int Ability::CreateModalUIExtension(const Want &want)
|
||||
{
|
||||
HILOG_DEBUG("call");
|
||||
auto abilityContextImpl = GetAbilityContext();
|
||||
if (abilityContextImpl == nullptr) {
|
||||
HILOG_ERROR("abilitycontext is nullptr");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
return abilityContextImpl->CreateModalUIExtensionWithApp(want);
|
||||
}
|
||||
|
||||
void Ability::SetSessionToken(sptr<IRemoteObject> sessionToken)
|
||||
{
|
||||
std::lock_guard lock(sessionTokenMutex_);
|
||||
sessionToken_ = sessionToken;
|
||||
}
|
||||
|
||||
void Ability::UpdateSessionToken(sptr<IRemoteObject> sessionToken)
|
||||
{
|
||||
SetSessionToken(sessionToken);
|
||||
if (abilityWindow_ == nullptr) {
|
||||
HILOG_ERROR("Ability window is nullptr.");
|
||||
return;
|
||||
}
|
||||
abilityWindow_->SetSessionToken(sessionToken_);
|
||||
}
|
||||
#endif
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -85,11 +85,7 @@ ErrCode AbilityContext::TerminateAbility()
|
||||
case AppExecFwk::AbilityType::PAGE:
|
||||
HILOG_DEBUG("Terminate ability begin, type is page, ability is %{public}s.", info->name.c_str());
|
||||
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
|
||||
if (sessionInfo_ == nullptr) {
|
||||
HILOG_ERROR("sessionInfo_ is nullptr.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
auto sessionToken = sessionInfo_->sessionToken;
|
||||
auto sessionToken = GetSessionToken();
|
||||
if (sessionToken == nullptr) {
|
||||
HILOG_ERROR("sessionToken is nullptr.");
|
||||
return ERR_INVALID_VALUE;
|
||||
@ -317,5 +313,11 @@ void AbilityContext::StartAbilities(const std::vector<AAFwk::Want> &wants)
|
||||
}
|
||||
HILOG_DEBUG("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> AbilityContext::GetSessionToken()
|
||||
{
|
||||
std::lock_guard lock(sessionTokenMutex_);
|
||||
return sessionToken_;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -195,13 +195,14 @@ void AbilityProcess::RequestPermissionsFromUser(
|
||||
HILOG_DEBUG("permission: %{public}s.", permission.c_str());
|
||||
PermissionListState permState;
|
||||
permState.permissionName = permission;
|
||||
permState.state = -1;
|
||||
permState.state = Security::AccessToken::SETTING_OPER;
|
||||
permList.emplace_back(permState);
|
||||
}
|
||||
HILOG_DEBUG("permList size: %{public}zu, permissions size: %{public}zu.",
|
||||
permList.size(), param.permission_list.size());
|
||||
|
||||
auto ret = AccessTokenKit::GetSelfPermissionsState(permList);
|
||||
Security::AccessToken::PermissionGrantInfo grantInfo;
|
||||
auto ret = AccessTokenKit::GetSelfPermissionsState(permList, grantInfo);
|
||||
if (permList.size() != param.permission_list.size()) {
|
||||
HILOG_ERROR("Returned permList size: %{public}zu.", permList.size());
|
||||
return;
|
||||
|
@ -44,6 +44,9 @@
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
const std::string METHOD_NAME = "WindowScene::GoForeground";
|
||||
#endif
|
||||
napi_value PromiseCallback(napi_env env, napi_callback_info info)
|
||||
{
|
||||
void *data = nullptr;
|
||||
@ -282,6 +285,7 @@ void JsAbility::OnStop()
|
||||
abilityContext_->SetTerminating(true);
|
||||
}
|
||||
Ability::OnStop();
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
CallObjectMethod("onDestroy");
|
||||
OnStopCallback();
|
||||
HILOG_DEBUG("OnStop end.");
|
||||
@ -394,6 +398,7 @@ void JsAbility::OnSceneRestored()
|
||||
{
|
||||
Ability::OnSceneRestored();
|
||||
HILOG_DEBUG("OnSceneRestored");
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto jsAppWindowStage = CreateAppWindowStage();
|
||||
if (jsAppWindowStage == nullptr) {
|
||||
HILOG_ERROR("Failed to create jsAppWindowStage object by LoadSystemModule");
|
||||
@ -415,7 +420,7 @@ void JsAbility::onSceneDestroyed()
|
||||
{
|
||||
HILOG_DEBUG("onSceneDestroyed begin, ability is %{public}s.", GetAbilityName().c_str());
|
||||
Ability::onSceneDestroyed();
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
CallObjectMethod("onWindowStageDestroy");
|
||||
|
||||
if (scene_ != nullptr) {
|
||||
@ -491,6 +496,7 @@ void JsAbility::OnBackground()
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("OnBackground begin, ability is %{public}s.", GetAbilityName().c_str());
|
||||
std::string methodName = "OnBackground";
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::BACKGROUND, methodName);
|
||||
CallObjectMethod("onBackground");
|
||||
AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState::BACKGROUND, methodName);
|
||||
@ -515,7 +521,7 @@ bool JsAbility::OnBackPress()
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("call, ability: %{public}s.", GetAbilityName().c_str());
|
||||
Ability::OnBackPress();
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto env = jsRuntime_.GetNapiEnv();
|
||||
napi_value jsValue = CallObjectMethod("onBackPressed", nullptr, 0, true);
|
||||
bool ret = false;
|
||||
@ -532,7 +538,7 @@ bool JsAbility::OnPrepareTerminate()
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("call, ability: %{public}s.", GetAbilityName().c_str());
|
||||
Ability::OnPrepareTerminate();
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto env = jsRuntime_.GetNapiEnv();
|
||||
napi_value jsValue = CallObjectMethod("onPrepareToTerminate", nullptr, 0, true);
|
||||
bool ret = false;
|
||||
@ -611,7 +617,7 @@ void JsAbility::DoOnForeground(const Want &want)
|
||||
return;
|
||||
}
|
||||
scene_ = std::make_shared<Rosen::WindowScene>();
|
||||
int32_t displayId = Rosen::WindowScene::DEFAULT_DISPLAY_ID;
|
||||
int32_t displayId = static_cast<int32_t>(Rosen::DisplayManager::GetInstance().GetDefaultDisplayId());
|
||||
if (setting_ != nullptr) {
|
||||
std::string strDisplayId =
|
||||
setting_->GetProperty(OHOS::AppExecFwk::AbilityStartSetting::WINDOW_DISPLAY_ID_KEY);
|
||||
@ -628,9 +634,10 @@ void JsAbility::DoOnForeground(const Want &want)
|
||||
}
|
||||
auto option = GetWindowOption(want);
|
||||
Rosen::WMError ret = Rosen::WMError::WM_OK;
|
||||
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && sessionInfo_ != nullptr) {
|
||||
abilityContext_->SetWeakSessionToken(sessionInfo_->sessionToken);
|
||||
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option, sessionInfo_->sessionToken);
|
||||
auto sessionToken = GetSessionToken();
|
||||
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && sessionToken != nullptr) {
|
||||
abilityContext_->SetWeakSessionToken(sessionToken);
|
||||
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option, sessionToken);
|
||||
} else {
|
||||
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option);
|
||||
}
|
||||
@ -662,6 +669,7 @@ void JsAbility::DoOnForeground(const Want &want)
|
||||
}
|
||||
|
||||
HILOG_INFO("Move scene to foreground, sceneFlag_:%{public}d.", Ability::sceneFlag_);
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::FOREGROUND, METHOD_NAME);
|
||||
scene_->GoForeground(Ability::sceneFlag_);
|
||||
HILOG_DEBUG("%{public}s end scene_->GoForeground.", __func__);
|
||||
}
|
||||
@ -680,10 +688,8 @@ void JsAbility::RequestFocus(const Want &want)
|
||||
window->SetWindowMode(static_cast<Rosen::WindowMode>(windowMode));
|
||||
HILOG_DEBUG("set window mode = %{public}d.", windowMode);
|
||||
}
|
||||
std::string methodName = "RequestFocus";
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::FOREGROUND, METHOD_NAME);
|
||||
scene_->GoForeground(Ability::sceneFlag_);
|
||||
AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
HILOG_INFO("Lifecycle: end.");
|
||||
}
|
||||
|
||||
|
@ -19,14 +19,15 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "ability_manager_client.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "event_handler.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "ability_runtime/js_caller_complex.h"
|
||||
#include "js_context_utils.h"
|
||||
#include "js_data_struct_converter.h"
|
||||
#include "js_error_utils.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "ability_runtime/js_caller_complex.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "mission_info.h"
|
||||
#include "napi_common_ability.h"
|
||||
#include "napi_common_start_options.h"
|
||||
@ -34,10 +35,8 @@
|
||||
#include "napi_common_want.h"
|
||||
#include "napi_remote_object.h"
|
||||
#include "start_options.h"
|
||||
#include "want.h"
|
||||
#include "event_handler.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "tokenid_kit.h"
|
||||
#include "want.h"
|
||||
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
#include "pixel_map_napi.h"
|
||||
@ -202,6 +201,11 @@ napi_value JsAbilityContext::StartAbilityByType(napi_env env, napi_callback_info
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsAbilityContext, OnStartAbilityByType);
|
||||
}
|
||||
|
||||
napi_value JsAbilityContext::RequestModalUIExtension(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsAbilityContext, OnRequestModalUIExtension);
|
||||
}
|
||||
|
||||
void JsAbilityContext::ClearFailedCallConnection(
|
||||
const std::weak_ptr<AbilityContext>& abilityContext, const std::shared_ptr<CallerCallBack> &callback)
|
||||
{
|
||||
@ -227,14 +231,14 @@ napi_value JsAbilityContext::OnStartAbility(napi_env env, NapiCallbackInfo& info
|
||||
}
|
||||
|
||||
AAFwk::Want want;
|
||||
OHOS::AppExecFwk::UnwrapWant(env, info.argv[0], want);
|
||||
OHOS::AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want);
|
||||
InheritWindowMode(want);
|
||||
decltype(info.argc) unwrapArgc = 1;
|
||||
decltype(info.argc) unwrapArgc = ARGC_ONE;
|
||||
HILOG_INFO("StartAbility, ability:%{public}s.", want.GetElement().GetAbilityName().c_str());
|
||||
AAFwk::StartOptions startOptions;
|
||||
if (info.argc > ARGC_ONE && CheckTypeForNapiValue(env, info.argv[1], napi_object)) {
|
||||
if (info.argc > ARGC_ONE && CheckTypeForNapiValue(env, info.argv[INDEX_ONE], napi_object)) {
|
||||
HILOG_DEBUG("OnStartAbility start options is used.");
|
||||
AppExecFwk::UnwrapStartOptions(env, info.argv[1], startOptions);
|
||||
AppExecFwk::UnwrapStartOptions(env, info.argv[INDEX_ONE], startOptions);
|
||||
unwrapArgc++;
|
||||
}
|
||||
|
||||
@ -259,7 +263,7 @@ napi_value JsAbilityContext::OnStartAbility(napi_env env, NapiCallbackInfo& info
|
||||
return;
|
||||
}
|
||||
|
||||
*innerErrorCode = (unwrapArgc == 1) ?
|
||||
*innerErrorCode = (unwrapArgc == ARGC_ONE) ?
|
||||
context->StartAbility(want, -1) : context->StartAbility(want, startOptions, -1);
|
||||
if ((want.GetFlags() & Want::FLAG_INSTALL_ON_DEMAND) == Want::FLAG_INSTALL_ON_DEMAND &&
|
||||
*innerErrorCode != 0 && observer != nullptr) {
|
||||
@ -303,14 +307,14 @@ napi_value JsAbilityContext::OnStartAbilityAsCaller(napi_env env, NapiCallbackIn
|
||||
}
|
||||
|
||||
AAFwk::Want want;
|
||||
OHOS::AppExecFwk::UnwrapWant(env, info.argv[0], want);
|
||||
OHOS::AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want);
|
||||
InheritWindowMode(want);
|
||||
decltype(info.argc) unwrapArgc = 1;
|
||||
decltype(info.argc) unwrapArgc = ARGC_ONE;
|
||||
HILOG_INFO("StartAbilityAsCaller, ability:%{public}s.", want.GetElement().GetAbilityName().c_str());
|
||||
AAFwk::StartOptions startOptions;
|
||||
if (info.argc > ARGC_ONE && CheckTypeForNapiValue(env, info.argv[1], napi_object)) {
|
||||
if (info.argc > ARGC_ONE && CheckTypeForNapiValue(env, info.argv[INDEX_ONE], napi_object)) {
|
||||
HILOG_DEBUG("OnStartAbilityAsCaller start options is used.");
|
||||
AppExecFwk::UnwrapStartOptions(env, info.argv[1], startOptions);
|
||||
AppExecFwk::UnwrapStartOptions(env, info.argv[INDEX_ONE], startOptions);
|
||||
unwrapArgc++;
|
||||
}
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
@ -321,7 +325,7 @@ napi_value JsAbilityContext::OnStartAbilityAsCaller(napi_env env, NapiCallbackIn
|
||||
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT));
|
||||
return;
|
||||
}
|
||||
auto innerErrorCode = (unwrapArgc == 1) ?
|
||||
auto innerErrorCode = (unwrapArgc == ARGC_ONE) ?
|
||||
context->StartAbilityAsCaller(want, -1) : context->StartAbilityAsCaller(want, startOptions, -1);
|
||||
if (innerErrorCode == 0) {
|
||||
task.Resolve(env, CreateJsUndefined(env));
|
||||
@ -349,12 +353,12 @@ napi_value JsAbilityContext::OnStartAbilityWithAccount(napi_env env, NapiCallbac
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
AAFwk::Want want;
|
||||
OHOS::AppExecFwk::UnwrapWant(env, info.argv[0], want);
|
||||
OHOS::AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want);
|
||||
InheritWindowMode(want);
|
||||
decltype(info.argc) unwrapArgc = 1;
|
||||
decltype(info.argc) unwrapArgc = ARGC_ONE;
|
||||
HILOG_INFO("StartAbilityWithAccount, ability:%{public}s", want.GetElement().GetAbilityName().c_str());
|
||||
int32_t accountId = 0;
|
||||
if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[1], accountId)) {
|
||||
if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[INDEX_ONE], accountId)) {
|
||||
HILOG_DEBUG("the second parameter is invalid.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
@ -363,7 +367,7 @@ napi_value JsAbilityContext::OnStartAbilityWithAccount(napi_env env, NapiCallbac
|
||||
AAFwk::StartOptions startOptions;
|
||||
if (info.argc > ARGC_TWO && CheckTypeForNapiValue(env, info.argv[INDEX_TWO], napi_object)) {
|
||||
HILOG_DEBUG("OnStartAbilityWithAccount start options is used.");
|
||||
AppExecFwk::UnwrapStartOptions(env, info.argv[ARGC_TWO], startOptions);
|
||||
AppExecFwk::UnwrapStartOptions(env, info.argv[INDEX_TWO], startOptions);
|
||||
unwrapArgc++;
|
||||
}
|
||||
|
||||
@ -426,7 +430,8 @@ napi_value JsAbilityContext::OnStartAbilityByCall(napi_env env, NapiCallbackInfo
|
||||
}
|
||||
|
||||
AAFwk::Want want;
|
||||
if (!CheckTypeForNapiValue(env, info.argv[0], napi_object) || !AppExecFwk::UnwrapWant(env, info.argv[0], want)) {
|
||||
if (!CheckTypeForNapiValue(env, info.argv[INDEX_ZERO], napi_object) ||
|
||||
!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want)) {
|
||||
HILOG_ERROR("Failed to parse want!");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
@ -438,14 +443,14 @@ napi_value JsAbilityContext::OnStartAbilityByCall(napi_env env, NapiCallbackInfo
|
||||
napi_value retsult = nullptr;
|
||||
int32_t userId = DEFAULT_INVAL_VALUE;
|
||||
if (info.argc > ARGC_ONE) {
|
||||
if (CheckTypeForNapiValue(env, info.argv[ARGC_ONE], napi_number)) {
|
||||
if (!ConvertFromJsValue(env, info.argv[ARGC_ONE], userId)) {
|
||||
if (CheckTypeForNapiValue(env, info.argv[INDEX_ONE], napi_number)) {
|
||||
if (!ConvertFromJsValue(env, info.argv[INDEX_ONE], userId)) {
|
||||
HILOG_ERROR("Failed to parse accountId!");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
} else if (CheckTypeForNapiValue(env, info.argv[ARGC_ONE], napi_function)) {
|
||||
lastParam = info.argv[ARGC_ONE];
|
||||
} else if (CheckTypeForNapiValue(env, info.argv[INDEX_ONE], napi_function)) {
|
||||
lastParam = info.argv[INDEX_ONE];
|
||||
} else {
|
||||
HILOG_ERROR("Failed, input param type invalid");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
@ -453,8 +458,8 @@ napi_value JsAbilityContext::OnStartAbilityByCall(napi_env env, NapiCallbackInfo
|
||||
}
|
||||
}
|
||||
|
||||
if (info.argc > ARGC_TWO && CheckTypeForNapiValue(env, info.argv[ARGC_TWO], napi_function)) {
|
||||
lastParam = info.argv[ARGC_TWO];
|
||||
if (info.argc > ARGC_TWO && CheckTypeForNapiValue(env, info.argv[INDEX_TWO], napi_function)) {
|
||||
lastParam = info.argv[INDEX_TWO];
|
||||
}
|
||||
|
||||
auto callBackDone = [calldata = calls] (const sptr<IRemoteObject> &obj) {
|
||||
@ -560,17 +565,17 @@ napi_value JsAbilityContext::OnStartAbilityForResult(napi_env env, NapiCallbackI
|
||||
}
|
||||
|
||||
AAFwk::Want want;
|
||||
if (!AppExecFwk::UnwrapWant(env, info.argv[0], want)) {
|
||||
if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want)) {
|
||||
HILOG_ERROR("Failed to parse want!");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
InheritWindowMode(want);
|
||||
decltype(info.argc) unwrapArgc = 1;
|
||||
decltype(info.argc) unwrapArgc = ARGC_ONE;
|
||||
AAFwk::StartOptions startOptions;
|
||||
if (info.argc > ARGC_ONE && CheckTypeForNapiValue(env, info.argv[1], napi_object)) {
|
||||
if (info.argc > ARGC_ONE && CheckTypeForNapiValue(env, info.argv[INDEX_ONE], napi_object)) {
|
||||
HILOG_DEBUG("OnStartAbilityForResult begin options is used.");
|
||||
AppExecFwk::UnwrapStartOptions(env, info.argv[1], startOptions);
|
||||
AppExecFwk::UnwrapStartOptions(env, info.argv[INDEX_ONE], startOptions);
|
||||
unwrapArgc++;
|
||||
}
|
||||
|
||||
@ -588,6 +593,7 @@ napi_value JsAbilityContext::OnStartAbilityForResult(napi_env env, NapiCallbackI
|
||||
RuntimeTask task = [env, asyncTask, &observer = freeInstallObserver_](int resultCode, const AAFwk::Want& want,
|
||||
bool isInner) {
|
||||
HILOG_DEBUG("OnStartAbilityForResult async callback is begin");
|
||||
HandleScope handleScope(env);
|
||||
napi_value abilityResult = AppExecFwk::WrapAbilityResult(env, resultCode, want);
|
||||
if (abilityResult == nullptr) {
|
||||
HILOG_WARN("wrap abilityResult error");
|
||||
@ -614,7 +620,7 @@ napi_value JsAbilityContext::OnStartAbilityForResult(napi_env env, NapiCallbackI
|
||||
} else {
|
||||
want.SetParam(Want::PARAM_RESV_FOR_RESULT, true);
|
||||
curRequestCode_ = (curRequestCode_ == INT_MAX) ? 0 : (curRequestCode_ + 1);
|
||||
(unwrapArgc == 1) ? context->StartAbilityForResult(want, curRequestCode_, std::move(task)) :
|
||||
(unwrapArgc == ARGC_ONE) ? context->StartAbilityForResult(want, curRequestCode_, std::move(task)) :
|
||||
context->StartAbilityForResult(want, startOptions, curRequestCode_, std::move(task));
|
||||
}
|
||||
HILOG_DEBUG("OnStartAbilityForResult is called end");
|
||||
@ -636,15 +642,15 @@ napi_value JsAbilityContext::OnStartAbilityForResultWithAccount(napi_env env, Na
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
AAFwk::Want want;
|
||||
if (!AppExecFwk::UnwrapWant(env, info.argv[0], want)) {
|
||||
if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want)) {
|
||||
HILOG_ERROR("Failed to parse want!");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
InheritWindowMode(want);
|
||||
decltype(info.argc) unwrapArgc = 1;
|
||||
decltype(info.argc) unwrapArgc = ARGC_ONE;
|
||||
int32_t accountId = 0;
|
||||
if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[1], accountId)) {
|
||||
if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[INDEX_ONE], accountId)) {
|
||||
HILOG_ERROR("the second parameter is invalid.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
@ -670,6 +676,7 @@ napi_value JsAbilityContext::OnStartAbilityForResultWithAccount(napi_env env, Na
|
||||
RuntimeTask task = [env, asyncTask, &observer = freeInstallObserver_](int resultCode, const AAFwk::Want& want,
|
||||
bool isInner) {
|
||||
HILOG_DEBUG("async callback is called");
|
||||
HandleScope handleScope(env);
|
||||
napi_value abilityResult = AppExecFwk::WrapAbilityResult(env, resultCode, want);
|
||||
if (abilityResult == nullptr) {
|
||||
HILOG_WARN("wrap abilityResult failed");
|
||||
@ -713,7 +720,7 @@ napi_value JsAbilityContext::OnStartExtensionAbility(napi_env env, NapiCallbackI
|
||||
}
|
||||
|
||||
AAFwk::Want want;
|
||||
if (!AppExecFwk::UnwrapWant(env, info.argv[0], want)) {
|
||||
if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want)) {
|
||||
HILOG_ERROR("Failed to parse want!");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
@ -735,7 +742,7 @@ napi_value JsAbilityContext::OnStartExtensionAbility(napi_env env, NapiCallbackI
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr;
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnStartExtensionAbility",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
@ -753,8 +760,8 @@ napi_value JsAbilityContext::OnStartExtensionAbilityWithAccount(napi_env env, Na
|
||||
|
||||
AAFwk::Want want;
|
||||
int32_t accountId = -1;
|
||||
if (!AppExecFwk::UnwrapWant(env, info.argv[0], want) ||
|
||||
!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[1], accountId)) {
|
||||
if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want) ||
|
||||
!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[INDEX_ONE], accountId)) {
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
@ -775,7 +782,7 @@ napi_value JsAbilityContext::OnStartExtensionAbilityWithAccount(napi_env env, Na
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (info.argc > ARGC_TWO) ? info.argv[ARGC_TWO] : nullptr;
|
||||
napi_value lastParam = (info.argc > ARGC_TWO) ? info.argv[INDEX_TWO] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnStartExtensionAbilityWithAccount",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
@ -792,7 +799,7 @@ napi_value JsAbilityContext::OnStopExtensionAbility(napi_env env, NapiCallbackIn
|
||||
}
|
||||
|
||||
AAFwk::Want want;
|
||||
if (!AppExecFwk::UnwrapWant(env, info.argv[0], want)) {
|
||||
if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want)) {
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
@ -813,7 +820,7 @@ napi_value JsAbilityContext::OnStopExtensionAbility(napi_env env, NapiCallbackIn
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr;
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::Schedule("JsAbilityContext::OnStopExtensionAbility",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
@ -831,8 +838,8 @@ napi_value JsAbilityContext::OnStopExtensionAbilityWithAccount(napi_env env, Nap
|
||||
|
||||
int32_t accountId = -1;
|
||||
AAFwk::Want want;
|
||||
if (!AppExecFwk::UnwrapWant(env, info.argv[0], want) ||
|
||||
!AppExecFwk::UnwrapInt32FromJS2(env, info.argv[1], accountId)) {
|
||||
if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want) ||
|
||||
!AppExecFwk::UnwrapInt32FromJS2(env, info.argv[INDEX_ONE], accountId)) {
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
@ -853,7 +860,7 @@ napi_value JsAbilityContext::OnStopExtensionAbilityWithAccount(napi_env env, Nap
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (info.argc > ARGC_TWO) ? info.argv[ARGC_TWO] : nullptr;
|
||||
napi_value lastParam = (info.argc > ARGC_TWO) ? info.argv[INDEX_TWO] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::Schedule("JsAbilityContext::OnStopExtensionAbilityWithAccount",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
@ -864,7 +871,7 @@ napi_value JsAbilityContext::OnTerminateSelfWithResult(napi_env env, NapiCallbac
|
||||
{
|
||||
HILOG_INFO("TerminateSelfWithResult");
|
||||
|
||||
if (info.argc == 0) {
|
||||
if (info.argc == ARGC_ZERO) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
@ -872,7 +879,7 @@ napi_value JsAbilityContext::OnTerminateSelfWithResult(napi_env env, NapiCallbac
|
||||
|
||||
int resultCode = 0;
|
||||
AAFwk::Want want;
|
||||
if (!AppExecFwk::UnWrapAbilityResult(env, info.argv[0], resultCode, want)) {
|
||||
if (!AppExecFwk::UnWrapAbilityResult(env, info.argv[INDEX_ZERO], resultCode, want)) {
|
||||
HILOG_ERROR("%s Failed to parse ability result!", __func__);
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
@ -900,7 +907,7 @@ napi_value JsAbilityContext::OnTerminateSelfWithResult(napi_env env, NapiCallbac
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[1] : nullptr;
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnTerminateSelfWithResult",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
@ -920,14 +927,14 @@ napi_value JsAbilityContext::OnConnectAbility(napi_env env, NapiCallbackInfo& in
|
||||
|
||||
// unwrap want
|
||||
AAFwk::Want want;
|
||||
OHOS::AppExecFwk::UnwrapWant(env, info.argv[0], want);
|
||||
OHOS::AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want);
|
||||
HILOG_INFO("ConnectAbility, callee:%{public}s.%{public}s",
|
||||
want.GetBundle().c_str(),
|
||||
want.GetElement().GetAbilityName().c_str());
|
||||
|
||||
// unwarp connection
|
||||
sptr<JSAbilityConnection> connection = new JSAbilityConnection(env);
|
||||
connection->SetJsConnectionObject(info.argv[1]);
|
||||
connection->SetJsConnectionObject(info.argv[INDEX_ONE]);
|
||||
int64_t connectId = g_serialNumber;
|
||||
ConnectionKey key;
|
||||
key.id = g_serialNumber;
|
||||
@ -975,13 +982,13 @@ napi_value JsAbilityContext::OnConnectAbilityWithAccount(napi_env env, NapiCallb
|
||||
|
||||
// unwrap want
|
||||
AAFwk::Want want;
|
||||
OHOS::AppExecFwk::UnwrapWant(env, info.argv[0], want);
|
||||
OHOS::AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want);
|
||||
HILOG_INFO("ConnectAbilityWithAccount, bundlename:%{public}s abilityname:%{public}s",
|
||||
want.GetBundle().c_str(),
|
||||
want.GetElement().GetAbilityName().c_str());
|
||||
|
||||
int32_t accountId = 0;
|
||||
if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[1], accountId)) {
|
||||
if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[INDEX_ONE], accountId)) {
|
||||
HILOG_ERROR("the second parameter is invalid.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
@ -1040,7 +1047,7 @@ napi_value JsAbilityContext::OnDisconnectAbility(napi_env env, NapiCallbackInfo&
|
||||
// unwrap connectId
|
||||
int64_t connectId = -1;
|
||||
sptr<JSAbilityConnection> connection = nullptr;
|
||||
napi_get_value_int64(env, info.argv[0], &connectId);
|
||||
napi_get_value_int64(env, info.argv[INDEX_ZERO], &connectId);
|
||||
HILOG_INFO("DisconnectAbility, connection:%{public}d.", static_cast<int32_t>(connectId));
|
||||
auto item = std::find_if(g_connects.begin(),
|
||||
g_connects.end(),
|
||||
@ -1074,7 +1081,7 @@ napi_value JsAbilityContext::OnDisconnectAbility(napi_env env, NapiCallbackInfo&
|
||||
task.Resolve(env, CreateJsUndefined(env));
|
||||
};
|
||||
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[1] : nullptr;
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::Schedule("JsAbilityContext::OnDisconnectAbility",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
@ -1106,7 +1113,7 @@ napi_value JsAbilityContext::OnTerminateSelf(napi_env env, NapiCallbackInfo& inf
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (info.argc > ARGC_ZERO) ? info.argv[ARGC_ZERO] : nullptr;
|
||||
napi_value lastParam = (info.argc > ARGC_ZERO) ? info.argv[INDEX_ZERO] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnTerminateSelf",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
@ -1127,7 +1134,7 @@ napi_value JsAbilityContext::OnRestoreWindowStage(napi_env env, NapiCallbackInfo
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
auto errcode = context->RestoreWindowStage(env, info.argv[0]);
|
||||
auto errcode = context->RestoreWindowStage(env, info.argv[INDEX_ZERO]);
|
||||
if (errcode != 0) {
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
|
||||
return CreateJsError(env, errcode, "RestoreWindowStage failed.");
|
||||
@ -1144,16 +1151,17 @@ napi_value JsAbilityContext::OnRequestDialogService(napi_env env, NapiCallbackIn
|
||||
}
|
||||
|
||||
AAFwk::Want want;
|
||||
AppExecFwk::UnwrapWant(env, info.argv[0], want);
|
||||
AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want);
|
||||
HILOG_INFO("RequestDialogService, target:%{public}s.%{public}s.", want.GetBundle().c_str(),
|
||||
want.GetElement().GetAbilityName().c_str());
|
||||
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr;
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
auto uasyncTask = CreateAsyncTaskWithLastParam(env, lastParam, nullptr, nullptr, &result);
|
||||
std::shared_ptr<NapiAsyncTask> asyncTask = std::move(uasyncTask);
|
||||
RequestDialogResultTask task =
|
||||
[env, asyncTask](int32_t resultCode, const AAFwk::Want &resultWant) {
|
||||
HandleScope handleScope(env);
|
||||
napi_value requestResult = JsAbilityContext::WrapRequestDialogResult(env, resultCode, resultWant);
|
||||
if (requestResult == nullptr) {
|
||||
HILOG_WARN("wrap requestResult failed");
|
||||
@ -1212,7 +1220,7 @@ napi_value JsAbilityContext::OnReportDrawnCompleted(napi_env env, NapiCallbackIn
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = info.argv[ARGC_ZERO];
|
||||
napi_value lastParam = info.argv[INDEX_ZERO];
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnReportDrawnCompleted",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, std::move(execute), std::move(complete), &result));
|
||||
@ -1245,8 +1253,10 @@ void JsAbilityContext::InheritWindowMode(AAFwk::Want &want)
|
||||
return;
|
||||
}
|
||||
auto windowMode = context->GetCurrentWindowMode();
|
||||
if (windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY ||
|
||||
windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY) {
|
||||
auto deviceType = context->GetDeviceType();
|
||||
if (deviceType != Global::Resource::DeviceType::DEVICE_TWOINONE &&
|
||||
(windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY ||
|
||||
windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY)) {
|
||||
want.SetParam(Want::PARAM_RESV_WINDOW_MODE, windowMode);
|
||||
}
|
||||
HILOG_DEBUG("window mode is %{public}d", windowMode);
|
||||
@ -1361,6 +1371,8 @@ napi_value CreateJsAbilityContext(napi_env env, std::shared_ptr<AbilityContext>
|
||||
JsAbilityContext::SetMissionContinueState);
|
||||
BindNativeFunction(env, object, "startAbilityByType", moduleName,
|
||||
JsAbilityContext::StartAbilityByType);
|
||||
BindNativeFunction(env, object, "requestModalUIExtension", moduleName,
|
||||
JsAbilityContext::RequestModalUIExtension);
|
||||
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
BindNativeFunction(env, object, "setMissionLabel", moduleName, JsAbilityContext::SetMissionLabel);
|
||||
@ -1598,7 +1610,7 @@ napi_value JsAbilityContext::OnSetMissionContinueState(napi_env env, NapiCallbac
|
||||
}
|
||||
|
||||
AAFwk::ContinueState state;
|
||||
if (!ConvertFromJsValue(env, info.argv[0], state)) {
|
||||
if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], state)) {
|
||||
HILOG_ERROR("OnSetMissionContinueState, parse state failed.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
@ -1627,7 +1639,7 @@ napi_value JsAbilityContext::OnSetMissionContinueState(napi_env env, NapiCallbac
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr;
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JsAbilityContext::SetMissionContinueState",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
@ -1655,7 +1667,7 @@ napi_value JsAbilityContext::OnSetMissionLabel(napi_env env, NapiCallbackInfo& i
|
||||
}
|
||||
|
||||
std::string label;
|
||||
if (!ConvertFromJsValue(env, info.argv[0], label)) {
|
||||
if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], label)) {
|
||||
HILOG_ERROR("OnSetMissionLabel, parse label failed.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
@ -1678,7 +1690,7 @@ napi_value JsAbilityContext::OnSetMissionLabel(napi_env env, NapiCallbackInfo& i
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr;
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnSetMissionLabel",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
@ -1694,7 +1706,7 @@ napi_value JsAbilityContext::OnSetMissionIcon(napi_env env, NapiCallbackInfo& in
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
auto icon = OHOS::Media::PixelMapNapi::GetPixelMap(env, info.argv[0]);
|
||||
auto icon = OHOS::Media::PixelMapNapi::GetPixelMap(env, info.argv[INDEX_ZERO]);
|
||||
if (!icon) {
|
||||
HILOG_ERROR("OnSetMissionIcon, parse icon failed.");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
@ -1718,7 +1730,7 @@ napi_value JsAbilityContext::OnSetMissionIcon(napi_env env, NapiCallbackInfo& in
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[1] : nullptr;
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnSetMissionIcon",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
@ -1774,5 +1786,44 @@ napi_value JsAbilityContext::OnStartAbilityByType(napi_env env, NapiCallbackInfo
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JsAbilityContext::OnRequestModalUIExtension(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
|
||||
if (info.argc < ARGC_ONE) {
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
AAFwk::Want want;
|
||||
if (!AppExecFwk::UnwrapWant(env, info.argv[0], want)) {
|
||||
HILOG_ERROR("Failed to parse want!");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[weak = context_, want](napi_env env, NapiAsyncTask& task, int32_t status) {
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT));
|
||||
return;
|
||||
}
|
||||
auto errcode = context->RequestModalUIExtension(want);
|
||||
if (errcode == 0) {
|
||||
task.Resolve(env, CreateJsUndefined(env));
|
||||
} else {
|
||||
task.Reject(env, CreateJsErrorByNativeErr(env, errcode));
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnRequestModalUIExtension",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "js_data_struct_converter.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "js_utils.h"
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
#include "js_window_stage.h"
|
||||
#endif
|
||||
@ -53,8 +54,10 @@ namespace {
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
const std::string PAGE_STACK_PROPERTY_NAME = "pageStack";
|
||||
const std::string SUPPORT_CONTINUE_PAGE_STACK_PROPERTY_NAME = "ohos.extra.param.key.supportContinuePageStack";
|
||||
const std::string METHOD_NAME = "WindowScene::GoForeground";
|
||||
#endif
|
||||
const int32_t BASE_DISPLAY_ID_NUM (10); // Numerical base (radix) that determines the valid characters and their interpretation.
|
||||
// Numerical base (radix) that determines the valid characters and their interpretation.
|
||||
const int32_t BASE_DISPLAY_ID_NUM (10);
|
||||
|
||||
napi_value PromiseCallback(napi_env env, napi_callback_info info)
|
||||
{
|
||||
@ -68,10 +71,10 @@ napi_value PromiseCallback(napi_env env, napi_callback_info info)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
napi_value AttachJsAbilityContext(napi_env env, void *value, void *)
|
||||
napi_value AttachJsAbilityContext(napi_env env, void *value, void *extValue)
|
||||
{
|
||||
HILOG_DEBUG("Begin.");
|
||||
if (value == nullptr) {
|
||||
if (value == nullptr || extValue == nullptr) {
|
||||
HILOG_ERROR("Invalid parameter.");
|
||||
return nullptr;
|
||||
}
|
||||
@ -80,14 +83,27 @@ napi_value AttachJsAbilityContext(napi_env env, void *value, void *)
|
||||
HILOG_ERROR("Invalid context.");
|
||||
return nullptr;
|
||||
}
|
||||
napi_value object = CreateJsAbilityContext(env, ptr);
|
||||
auto systemModule = JsRuntime::LoadSystemModuleByEngine(env, "application.AbilityContext", &object, 1);
|
||||
if (systemModule == nullptr) {
|
||||
HILOG_ERROR("Invalid systemModule.");
|
||||
std::shared_ptr<NativeReference> systemModule = nullptr;
|
||||
auto screenModePtr = reinterpret_cast<std::weak_ptr<int32_t> *>(extValue)->lock();
|
||||
if (screenModePtr == nullptr) {
|
||||
HILOG_ERROR("Invalid screenModePtr.");
|
||||
return nullptr;
|
||||
}
|
||||
if (*screenModePtr == AAFwk::IDLE_SCREEN_MODE) {
|
||||
auto uiAbiObject = CreateJsAbilityContext(env, ptr);
|
||||
CHECK_POINTER_AND_RETURN(uiAbiObject, nullptr);
|
||||
systemModule = std::shared_ptr<NativeReference>(JsRuntime::LoadSystemModuleByEngine(env,
|
||||
"application.AbilityContext", &uiAbiObject, 1).release());
|
||||
} else {
|
||||
auto emUIObject = JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(env,
|
||||
ptr, nullptr, *screenModePtr);
|
||||
CHECK_POINTER_AND_RETURN(emUIObject, nullptr);
|
||||
systemModule = std::shared_ptr<NativeReference>(JsRuntime::LoadSystemModuleByEngine(env,
|
||||
"application.EmbeddableUIAbilityContext", &emUIObject, 1).release());
|
||||
}
|
||||
CHECK_POINTER_AND_RETURN(systemModule, nullptr);
|
||||
auto contextObj = systemModule->GetNapiValue();
|
||||
napi_coerce_to_native_binding_object(env, contextObj, DetachCallbackFunc, AttachJsAbilityContext, value, nullptr);
|
||||
napi_coerce_to_native_binding_object(env, contextObj, DetachCallbackFunc, AttachJsAbilityContext, value, extValue);
|
||||
auto workContext = new (std::nothrow) std::weak_ptr<AbilityRuntime::AbilityContext>(ptr);
|
||||
napi_wrap(env, contextObj, workContext,
|
||||
[](napi_env, void* data, void*) {
|
||||
@ -122,17 +138,21 @@ JsUIAbility::~JsUIAbility()
|
||||
#endif
|
||||
}
|
||||
|
||||
void JsUIAbility::Init(const std::shared_ptr<AbilityInfo> &abilityInfo,
|
||||
void JsUIAbility::Init(std::shared_ptr<AppExecFwk::AbilityLocalRecord> record,
|
||||
const std::shared_ptr<OHOSApplication> application, std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
UIAbility::Init(abilityInfo, application, handler, token);
|
||||
|
||||
if (record == nullptr) {
|
||||
HILOG_ERROR("AbilityLocalRecord is nullptr.");
|
||||
return;
|
||||
}
|
||||
auto abilityInfo = record->GetAbilityInfo();
|
||||
if (abilityInfo == nullptr) {
|
||||
HILOG_ERROR("AbilityInfo is nullptr.");
|
||||
return;
|
||||
}
|
||||
UIAbility::Init(record, application, handler, token);
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
if (abilityContext_ != nullptr) {
|
||||
AppExecFwk::AppRecovery::GetInstance().AddAbility(
|
||||
@ -162,18 +182,18 @@ void JsUIAbility::Init(const std::shared_ptr<AbilityInfo> &abilityInfo,
|
||||
std::string moduleName(abilityInfo->moduleName);
|
||||
moduleName.append("::").append(abilityInfo->name);
|
||||
|
||||
SetAbilityContext(abilityInfo, moduleName, srcPath);
|
||||
SetAbilityContext(abilityInfo, record->GetWant(), moduleName, srcPath);
|
||||
}
|
||||
|
||||
void JsUIAbility::SetAbilityContext(
|
||||
const std::shared_ptr<AbilityInfo> &abilityInfo, const std::string &moduleName, const std::string &srcPath)
|
||||
void JsUIAbility::SetAbilityContext(std::shared_ptr<AbilityInfo> abilityInfo,
|
||||
std::shared_ptr<AAFwk::Want> want, const std::string &moduleName, const std::string &srcPath)
|
||||
{
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto env = jsRuntime_.GetNapiEnv();
|
||||
jsAbilityObj_ = jsRuntime_.LoadModule(
|
||||
moduleName, srcPath, abilityInfo->hapPath, abilityInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE);
|
||||
if (jsAbilityObj_ == nullptr || abilityContext_ == nullptr) {
|
||||
HILOG_ERROR("jsAbilityObj_ or abilityContext_ is nullptr.");
|
||||
if (jsAbilityObj_ == nullptr || abilityContext_ == nullptr || want == nullptr) {
|
||||
HILOG_ERROR("jsAbilityObj_ or abilityContext_ or want is nullptr.");
|
||||
return;
|
||||
}
|
||||
napi_value obj = jsAbilityObj_->GetNapiValue();
|
||||
@ -181,10 +201,9 @@ void JsUIAbility::SetAbilityContext(
|
||||
HILOG_ERROR("Failed to check type");
|
||||
return;
|
||||
}
|
||||
|
||||
napi_value contextObj = CreateJsAbilityContext(env, abilityContext_);
|
||||
shellContextRef_ = std::shared_ptr<NativeReference>(JsRuntime::LoadSystemModuleByEngine(
|
||||
env, "application.AbilityContext", &contextObj, 1).release());
|
||||
napi_value contextObj = nullptr;
|
||||
int32_t screenMode = want->GetIntParam(AAFwk::SCREEN_MODE_KEY, AAFwk::IDLE_SCREEN_MODE);
|
||||
CreateJSContext(env, contextObj, screenMode);
|
||||
if (shellContextRef_ == nullptr) {
|
||||
HILOG_ERROR("shellContextRef_ is nullptr.");
|
||||
return;
|
||||
@ -195,16 +214,15 @@ void JsUIAbility::SetAbilityContext(
|
||||
return;
|
||||
}
|
||||
auto workContext = new (std::nothrow) std::weak_ptr<AbilityRuntime::AbilityContext>(abilityContext_);
|
||||
if (workContext == nullptr) {
|
||||
HILOG_ERROR("workContext is nullptr.");
|
||||
return;
|
||||
}
|
||||
CHECK_POINTER(workContext);
|
||||
screenModePtr_ = std::make_shared<int32_t>(screenMode);
|
||||
auto workScreenMode = new (std::nothrow) std::weak_ptr<int32_t>(screenModePtr_);
|
||||
CHECK_POINTER(workScreenMode);
|
||||
napi_coerce_to_native_binding_object(
|
||||
env, contextObj, DetachCallbackFunc, AttachJsAbilityContext, workContext, nullptr);
|
||||
env, contextObj, DetachCallbackFunc, AttachJsAbilityContext, workContext, workScreenMode);
|
||||
abilityContext_->Bind(jsRuntime_, shellContextRef_.get());
|
||||
napi_set_named_property(env, obj, "context", contextObj);
|
||||
HILOG_DEBUG("Set ability context");
|
||||
|
||||
if (abilityRecovery_ != nullptr) {
|
||||
abilityRecovery_->SetJsAbility(reinterpret_cast<uintptr_t>(workContext));
|
||||
}
|
||||
@ -212,8 +230,24 @@ void JsUIAbility::SetAbilityContext(
|
||||
[](napi_env, void *data, void *) {
|
||||
HILOG_DEBUG("Finalizer for weak_ptr ability context is called");
|
||||
delete static_cast<std::weak_ptr<AbilityRuntime::AbilityContext> *>(data);
|
||||
},
|
||||
nullptr, nullptr);
|
||||
}, nullptr, nullptr);
|
||||
HILOG_DEBUG("Init end.");
|
||||
}
|
||||
|
||||
void JsUIAbility::CreateJSContext(napi_env env, napi_value &contextObj, int32_t screenMode)
|
||||
{
|
||||
if (screenMode == AAFwk::IDLE_SCREEN_MODE) {
|
||||
contextObj = CreateJsAbilityContext(env, abilityContext_);
|
||||
CHECK_POINTER(contextObj);
|
||||
shellContextRef_ = std::shared_ptr<NativeReference>(JsRuntime::LoadSystemModuleByEngine(
|
||||
env, "application.AbilityContext", &contextObj, 1).release());
|
||||
} else {
|
||||
contextObj = JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(env,
|
||||
abilityContext_, nullptr, screenMode);
|
||||
CHECK_POINTER(contextObj);
|
||||
shellContextRef_ = std::shared_ptr<NativeReference>(JsRuntime::LoadSystemModuleByEngine(
|
||||
env, "application.EmbeddableUIAbilityContext", &contextObj, 1).release());
|
||||
}
|
||||
}
|
||||
|
||||
void JsUIAbility::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
|
||||
@ -248,10 +282,13 @@ void JsUIAbility::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo
|
||||
|
||||
napi_set_named_property(env, obj, "launchWant", jsWant);
|
||||
napi_set_named_property(env, obj, "lastRequestWant", jsWant);
|
||||
|
||||
auto launchParam = GetLaunchParam();
|
||||
if (InsightIntentExecuteParam::IsInsightIntentExecute(want)) {
|
||||
launchParam.launchReason = AAFwk::LaunchReason::LAUNCHREASON_INSIGHT_INTENT;
|
||||
}
|
||||
napi_value argv[] = {
|
||||
jsWant,
|
||||
CreateJsLaunchParam(env, GetLaunchParam()),
|
||||
CreateJsLaunchParam(env, launchParam),
|
||||
};
|
||||
std::string methodName = "OnStart";
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
@ -316,6 +353,7 @@ void JsUIAbility::OnStop()
|
||||
abilityContext_->SetTerminating(true);
|
||||
}
|
||||
UIAbility::OnStop();
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
CallObjectMethod("onDestroy");
|
||||
OnStopCallback();
|
||||
HILOG_DEBUG("End.");
|
||||
@ -425,6 +463,7 @@ void JsUIAbility::OnSceneRestored()
|
||||
{
|
||||
UIAbility::OnSceneRestored();
|
||||
HILOG_DEBUG("called.");
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto jsAppWindowStage = CreateAppWindowStage();
|
||||
if (jsAppWindowStage == nullptr) {
|
||||
HILOG_ERROR("JsAppWindowStage is nullptr.");
|
||||
@ -446,7 +485,7 @@ void JsUIAbility::onSceneDestroyed()
|
||||
{
|
||||
HILOG_DEBUG("Begin ability is %{public}s.", GetAbilityName().c_str());
|
||||
UIAbility::onSceneDestroyed();
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
CallObjectMethod("onWindowStageDestroy");
|
||||
|
||||
if (scene_ != nullptr) {
|
||||
@ -526,6 +565,7 @@ void JsUIAbility::OnBackground()
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("Begin ability is %{public}s.", GetAbilityName().c_str());
|
||||
std::string methodName = "OnBackground";
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::BACKGROUND, methodName);
|
||||
CallObjectMethod("onBackground");
|
||||
AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState::BACKGROUND, methodName);
|
||||
@ -550,7 +590,7 @@ bool JsUIAbility::OnBackPress()
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("Begin ability: %{public}s.", GetAbilityName().c_str());
|
||||
UIAbility::OnBackPress();
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto env = jsRuntime_.GetNapiEnv();
|
||||
napi_value jsValue = CallObjectMethod("onBackPressed", nullptr, 0, true);
|
||||
bool ret = false;
|
||||
@ -567,7 +607,7 @@ bool JsUIAbility::OnPrepareTerminate()
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_DEBUG("Begin ability: %{public}s.", GetAbilityName().c_str());
|
||||
UIAbility::OnPrepareTerminate();
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto env = jsRuntime_.GetNapiEnv();
|
||||
napi_value jsValue = CallObjectMethod("onPrepareToTerminate", nullptr, 0, true);
|
||||
bool ret = false;
|
||||
@ -672,6 +712,7 @@ void JsUIAbility::DoOnForeground(const Want &want)
|
||||
}
|
||||
|
||||
HILOG_INFO("Move scene to foreground, sceneFlag_: %{public}d.", UIAbility::sceneFlag_);
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::FOREGROUND, METHOD_NAME);
|
||||
scene_->GoForeground(UIAbility::sceneFlag_);
|
||||
HILOG_DEBUG("End.");
|
||||
}
|
||||
@ -679,7 +720,7 @@ void JsUIAbility::DoOnForeground(const Want &want)
|
||||
void JsUIAbility::DoOnForegroundForSceneIsNull(const Want &want)
|
||||
{
|
||||
scene_ = std::make_shared<Rosen::WindowScene>();
|
||||
int32_t displayId = Rosen::WindowScene::DEFAULT_DISPLAY_ID;
|
||||
int32_t displayId = static_cast<int32_t>(Rosen::DisplayManager::GetInstance().GetDefaultDisplayId());
|
||||
if (setting_ != nullptr) {
|
||||
std::string strDisplayId = setting_->GetProperty(OHOS::AppExecFwk::AbilityStartSetting::WINDOW_DISPLAY_ID_KEY);
|
||||
std::regex formatRegex("[0-9]{0,9}$");
|
||||
@ -694,9 +735,10 @@ void JsUIAbility::DoOnForegroundForSceneIsNull(const Want &want)
|
||||
}
|
||||
auto option = GetWindowOption(want);
|
||||
Rosen::WMError ret = Rosen::WMError::WM_OK;
|
||||
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && sessionInfo_ != nullptr) {
|
||||
abilityContext_->SetWeakSessionToken(sessionInfo_->sessionToken);
|
||||
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option, sessionInfo_->sessionToken);
|
||||
auto sessionToken = GetSessionToken();
|
||||
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && sessionToken != nullptr) {
|
||||
abilityContext_->SetWeakSessionToken(sessionToken);
|
||||
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option, sessionToken);
|
||||
} else {
|
||||
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option);
|
||||
}
|
||||
@ -732,10 +774,8 @@ void JsUIAbility::RequestFocus(const Want &want)
|
||||
window->SetWindowMode(static_cast<Rosen::WindowMode>(windowMode));
|
||||
HILOG_DEBUG("Set window mode is %{public}d.", windowMode);
|
||||
}
|
||||
std::string methodName = "RequestFocus";
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::FOREGROUND, METHOD_NAME);
|
||||
scene_->GoForeground(UIAbility::sceneFlag_);
|
||||
AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
HILOG_INFO("Lifecycle: end.");
|
||||
}
|
||||
|
||||
@ -850,13 +890,52 @@ void JsUIAbility::ExecuteInsightIntentMoveToForeground(const Want &want,
|
||||
}
|
||||
}
|
||||
|
||||
void JsUIAbility::ExecuteInsightIntentBackground(const Want &want,
|
||||
const std::shared_ptr<InsightIntentExecuteParam> &executeParam,
|
||||
std::unique_ptr<InsightIntentExecutorAsyncCallback> callback)
|
||||
{
|
||||
HILOG_DEBUG("called.");
|
||||
if (executeParam == nullptr) {
|
||||
HILOG_WARN("Intent execute param invalid.");
|
||||
InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback), ERR_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
if (abilityInfo_) {
|
||||
jsRuntime_.UpdateModuleNameAndAssetPath(abilityInfo_->moduleName);
|
||||
}
|
||||
|
||||
InsightIntentExecutorInfo executeInfo;
|
||||
auto ret = GetInsightIntentExecutorInfo(want, executeParam, executeInfo);
|
||||
if (!ret) {
|
||||
HILOG_ERROR("Get Intent executor failed.");
|
||||
InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback),
|
||||
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
|
||||
return;
|
||||
}
|
||||
|
||||
ret = DelayedSingleton<InsightIntentExecutorMgr>::GetInstance()->ExecuteInsightIntent(
|
||||
jsRuntime_, executeInfo, std::move(callback));
|
||||
if (!ret) {
|
||||
// callback has removed, release in insight intent executor.
|
||||
HILOG_ERROR("Execute insight intent failed.");
|
||||
}
|
||||
}
|
||||
|
||||
bool JsUIAbility::GetInsightIntentExecutorInfo(const Want &want,
|
||||
const std::shared_ptr<InsightIntentExecuteParam> &executeParam,
|
||||
InsightIntentExecutorInfo& executeInfo)
|
||||
{
|
||||
HILOG_DEBUG("called.");
|
||||
|
||||
auto context = GetAbilityContext();
|
||||
if (executeParam == nullptr || context == nullptr || abilityInfo_ == nullptr || jsWindowStageObj_ == nullptr) {
|
||||
if (executeParam == nullptr || context == nullptr || abilityInfo_ == nullptr) {
|
||||
HILOG_ERROR("Param invalid.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (executeParam->executeMode_ == AppExecFwk::ExecuteMode::UI_ABILITY_FOREGROUND
|
||||
&& jsWindowStageObj_ == nullptr) {
|
||||
HILOG_ERROR("Param invalid.");
|
||||
return false;
|
||||
}
|
||||
@ -867,7 +946,9 @@ bool JsUIAbility::GetInsightIntentExecutorInfo(const Want &want,
|
||||
executeInfo.esmodule = abilityInfo_->compileMode == AppExecFwk::CompileMode::ES_MODULE;
|
||||
executeInfo.windowMode = windowMode_;
|
||||
executeInfo.token = context->GetToken();
|
||||
executeInfo.pageLoader = jsWindowStageObj_;
|
||||
if (jsWindowStageObj_ != nullptr) {
|
||||
executeInfo.pageLoader = jsWindowStageObj_;
|
||||
}
|
||||
executeInfo.executeParam = executeParam;
|
||||
return true;
|
||||
}
|
||||
@ -1037,10 +1118,13 @@ void JsUIAbility::OnNewWant(const Want &want)
|
||||
}
|
||||
|
||||
napi_set_named_property(env, obj, "lastRequestWant", jsWant);
|
||||
|
||||
auto launchParam = GetLaunchParam();
|
||||
if (InsightIntentExecuteParam::IsInsightIntentExecute(want)) {
|
||||
launchParam.launchReason = AAFwk::LaunchReason::LAUNCHREASON_INSIGHT_INTENT;
|
||||
}
|
||||
napi_value argv[] = {
|
||||
jsWant,
|
||||
CreateJsLaunchParam(env, GetLaunchParam()),
|
||||
CreateJsLaunchParam(env, launchParam),
|
||||
};
|
||||
std::string methodName = "OnNewWant";
|
||||
AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
|
||||
|
@ -264,6 +264,11 @@ void AbilityThread::CallRequest()
|
||||
HILOG_DEBUG("called");
|
||||
}
|
||||
|
||||
void AbilityThread::OnExecuteIntent(const Want &want)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<AppExecFwk::DataAbilityResult>> AbilityThread::ExecuteBatch(
|
||||
const std::vector<std::shared_ptr<AppExecFwk::DataAbilityOperation>> &operations)
|
||||
{
|
||||
@ -272,6 +277,17 @@ std::vector<std::shared_ptr<AppExecFwk::DataAbilityResult>> AbilityThread::Execu
|
||||
return results;
|
||||
}
|
||||
|
||||
int AbilityThread::CreateModalUIExtension(const Want &want)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
void AbilityThread::UpdateSessionToken(sptr<IRemoteObject> sessionToken)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
}
|
||||
|
||||
#ifdef ABILITY_COMMAND_FOR_TEST
|
||||
int AbilityThread::BlockAbility()
|
||||
{
|
||||
|
@ -48,8 +48,9 @@ bool AbilityWindow::InitWindow(std::shared_ptr<AbilityRuntime::AbilityContext> &
|
||||
windowScene_ = std::make_shared<Rosen::WindowScene>();
|
||||
}
|
||||
Rosen::WMError ret = Rosen::WMError::WM_OK;
|
||||
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && sessionInfo_ != nullptr) {
|
||||
ret = windowScene_->Init(displayId, abilityContext, listener, option, sessionInfo_->sessionToken);
|
||||
auto sessionToken = GetSessionToken();
|
||||
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && sessionToken != nullptr) {
|
||||
ret = windowScene_->Init(displayId, abilityContext, listener, option, sessionToken);
|
||||
} else {
|
||||
ret = windowScene_->Init(displayId, abilityContext, listener, option);
|
||||
}
|
||||
@ -186,9 +187,16 @@ ErrCode AbilityWindow::SetMissionIcon(const std::shared_ptr<OHOS::Media::PixelMa
|
||||
}
|
||||
#endif
|
||||
|
||||
void AbilityWindow::SetSessionInfo(sptr<AAFwk::SessionInfo> &sessionInfo)
|
||||
void AbilityWindow::SetSessionToken(sptr<IRemoteObject> sessionToken)
|
||||
{
|
||||
sessionInfo_ = sessionInfo;
|
||||
std::lock_guard lock(sessionTokenMutex_);
|
||||
sessionToken_ = sessionToken;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> AbilityWindow::GetSessionToken()
|
||||
{
|
||||
std::lock_guard lock(sessionTokenMutex_);
|
||||
return sessionToken_;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -110,17 +110,17 @@ void JsActionExtension::OnCommand(const AAFwk::Want &want, bool restart, int32_t
|
||||
jsUIExtensionBase_->OnCommand(want, restart, startId);
|
||||
}
|
||||
|
||||
void JsActionExtension::OnForeground(const Want &want)
|
||||
void JsActionExtension::OnForeground(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
|
||||
{
|
||||
HILOG_DEBUG("called.");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
Extension::OnForeground(want);
|
||||
Extension::OnForeground(want, sessionInfo);
|
||||
|
||||
if (jsUIExtensionBase_ == nullptr) {
|
||||
HILOG_ERROR("jsUIExtensionBase_ is nullptr");
|
||||
return;
|
||||
}
|
||||
jsUIExtensionBase_->OnForeground(want);
|
||||
jsUIExtensionBase_->OnForeground(want, sessionInfo);
|
||||
}
|
||||
|
||||
void JsActionExtension::OnBackground()
|
||||
|
@ -18,8 +18,10 @@
|
||||
#include "module_checker_delegate.h"
|
||||
#include "utils/log.h"
|
||||
|
||||
bool AppModuleChecker::CheckModuleLoadable(const char* moduleName)
|
||||
bool AppModuleChecker::CheckModuleLoadable(const char *moduleName,
|
||||
std::unique_ptr<ApiAllowListChecker> &apiAllowListChecker)
|
||||
{
|
||||
apiAllowListChecker = nullptr;
|
||||
HILOG_INFO("check blocklist, moduleName = %{public}s, processExtensionType_ = %{public}d",
|
||||
moduleName, static_cast<int32_t>(processExtensionType_));
|
||||
const auto& blockListIter = moduleBlocklist_.find(processExtensionType_);
|
||||
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "auto_fill_extension.h"
|
||||
|
||||
#include "auto_fill_extension_context.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_auto_fill_extension.h"
|
||||
#include "runtime.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
AutoFillExtension *AutoFillExtension::Create(const std::unique_ptr<Runtime> &runtime)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (runtime == nullptr) {
|
||||
return new AutoFillExtension();
|
||||
}
|
||||
switch (runtime->GetLanguage()) {
|
||||
case Runtime::Language::JS:
|
||||
return JsAutoFillExtension::Create(runtime);
|
||||
default:
|
||||
return new AutoFillExtension();
|
||||
}
|
||||
}
|
||||
|
||||
void AutoFillExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application, std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
ExtensionBase<AutoFillExtensionContext>::Init(record, application, handler, token);
|
||||
}
|
||||
|
||||
std::shared_ptr<AutoFillExtensionContext> AutoFillExtension::CreateAndInitContext(
|
||||
const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
std::shared_ptr<AutoFillExtensionContext> context =
|
||||
ExtensionBase<AutoFillExtensionContext>::CreateAndInitContext(record, application, handler, token);
|
||||
if (context == nullptr) {
|
||||
HILOG_ERROR("UIExtension CreateAndInitContext context is nullptr.");
|
||||
return context;
|
||||
}
|
||||
return context;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "auto_fill_extension_module_loader.h"
|
||||
|
||||
#include "auto_fill_extension.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
const std::string AUTO_FILL_EXTENSION_PARAMS_NAME_KEY = "name";
|
||||
const std::string AUTO_FILL_EXTENSION_PARAMS_NAME = "AutoFillExtensionAbility";
|
||||
const std::string AUTO_FILL_EXTENSION_PARAMS_TYPE_KEY = "type";
|
||||
const std::string AUTO_FILL_EXTENSION_PARAMS_TYPE = "501";
|
||||
}
|
||||
AutoFillExtensionModuleLoader::AutoFillExtensionModuleLoader() = default;
|
||||
AutoFillExtensionModuleLoader::~AutoFillExtensionModuleLoader() = default;
|
||||
|
||||
Extension *AutoFillExtensionModuleLoader::Create(const std::unique_ptr<Runtime> &runtime) const
|
||||
{
|
||||
HILOG_DEBUG("Called");
|
||||
return AutoFillExtension::Create(runtime);
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> AutoFillExtensionModuleLoader::GetParams()
|
||||
{
|
||||
HILOG_DEBUG("Called");
|
||||
std::map<std::string, std::string> params;
|
||||
// type means extension type in ExtensionAbilityType of
|
||||
// extension_ability_info.h, 21 means autoFill/password extension.
|
||||
params.insert(
|
||||
std::pair<std::string, std::string>(AUTO_FILL_EXTENSION_PARAMS_TYPE_KEY, AUTO_FILL_EXTENSION_PARAMS_TYPE));
|
||||
params.insert(
|
||||
std::pair<std::string, std::string>(AUTO_FILL_EXTENSION_PARAMS_NAME_KEY, AUTO_FILL_EXTENSION_PARAMS_NAME));
|
||||
return params;
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) void *OHOS_EXTENSION_GetExtensionModule()
|
||||
{
|
||||
return &AutoFillExtensionModuleLoader::GetInstance();
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -0,0 +1,616 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "js_auto_fill_extension.h"
|
||||
|
||||
#include "ability_context.h"
|
||||
#include "ability_delegator_registry.h"
|
||||
#include "ability_info.h"
|
||||
#include "ability_manager_client.h"
|
||||
#include "ability_start_setting.h"
|
||||
#include "connection_manager.h"
|
||||
#include "context.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "int_wrapper.h"
|
||||
#include "js_auto_fill_extension_util.h"
|
||||
#include "js_auto_fill_extension_context.h"
|
||||
#include "js_fill_request_callback.h"
|
||||
#include "js_save_request_callback.h"
|
||||
#include "js_extension_common.h"
|
||||
#include "js_extension_context.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "js_ui_extension_content_session.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "napi_common_configuration.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "napi_remote_object.h"
|
||||
#include "want_params_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
constexpr size_t ARGC_THREE = 3;
|
||||
constexpr const char *WANT_PARAMS_AUTO_FILL_CMD_AUTOSAVE = "save";
|
||||
constexpr const char *WANT_PARAMS_AUTO_FILL_CMD_AUTOFILL = "fill";
|
||||
constexpr const char *WANT_PARAMS_AUTO_FILL_CMD = "ohos.ability.params.autoFillCmd";
|
||||
constexpr static char WANT_PARAMS_AUTO_FILL_EVENT_KEY[] = "ability.want.params.AutoFillEvent";
|
||||
}
|
||||
napi_value AttachAutoFillExtensionContext(napi_env env, void *value, void *)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("Invalid parameter.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto ptr = reinterpret_cast<std::weak_ptr<AutoFillExtensionContext> *>(value)->lock();
|
||||
if (ptr == nullptr) {
|
||||
HILOG_ERROR("Invalid context.");
|
||||
return nullptr;
|
||||
}
|
||||
napi_value object = JsAutoFillExtensionContext::CreateJsAutoFillExtensionContext(env, ptr);
|
||||
auto systemModule = JsRuntime::LoadSystemModuleByEngine(env, "application.AutoFillExtensionContext", &object, 1);
|
||||
if (systemModule == nullptr) {
|
||||
HILOG_ERROR("Load system module failed.");
|
||||
return nullptr;
|
||||
}
|
||||
auto contextObj = systemModule->GetNapiValue();
|
||||
if (contextObj == nullptr) {
|
||||
HILOG_ERROR("Load context error.");
|
||||
return nullptr;
|
||||
}
|
||||
napi_coerce_to_native_binding_object(
|
||||
env, contextObj, DetachCallbackFunc, AttachAutoFillExtensionContext, value, nullptr);
|
||||
|
||||
auto workContext = new (std::nothrow) std::weak_ptr<AutoFillExtensionContext>(ptr);
|
||||
napi_wrap(env, contextObj, workContext,
|
||||
[](napi_env, void *data, void *) {
|
||||
HILOG_DEBUG("Finalizer for weak_ptr ui extension context is called");
|
||||
delete static_cast<std::weak_ptr<AutoFillExtensionContext> *>(data);
|
||||
},
|
||||
nullptr, nullptr);
|
||||
return contextObj;
|
||||
}
|
||||
|
||||
JsAutoFillExtension *JsAutoFillExtension::Create(const std::unique_ptr<Runtime> &runtime)
|
||||
{
|
||||
return new (std::nothrow) JsAutoFillExtension(static_cast<JsRuntime&>(*runtime));
|
||||
}
|
||||
|
||||
JsAutoFillExtension::JsAutoFillExtension(JsRuntime& jsRuntime) : jsRuntime_(jsRuntime)
|
||||
{
|
||||
}
|
||||
|
||||
JsAutoFillExtension::~JsAutoFillExtension()
|
||||
{
|
||||
HILOG_DEBUG("Destructor.");
|
||||
auto context = GetContext();
|
||||
if (context) {
|
||||
context->Unbind();
|
||||
}
|
||||
|
||||
jsRuntime_.FreeNativeReference(std::move(jsObj_));
|
||||
jsRuntime_.FreeNativeReference(std::move(shellContextRef_));
|
||||
for (auto &item : contentSessions_) {
|
||||
jsRuntime_.FreeNativeReference(std::move(item.second));
|
||||
}
|
||||
contentSessions_.clear();
|
||||
callbacks_.clear();
|
||||
}
|
||||
|
||||
void JsAutoFillExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application, std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
AutoFillExtension::Init(record, application, handler, token);
|
||||
if (abilityInfo_ == nullptr || abilityInfo_->srcEntrance.empty()) {
|
||||
HILOG_ERROR("Init ability info failed.");
|
||||
return;
|
||||
}
|
||||
std::string srcPath(abilityInfo_->moduleName + "/");
|
||||
srcPath.append(abilityInfo_->srcEntrance);
|
||||
srcPath.erase(srcPath.rfind('.'));
|
||||
srcPath.append(".abc");
|
||||
|
||||
std::string moduleName(abilityInfo_->moduleName);
|
||||
moduleName.append("::").append(abilityInfo_->name);
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto env = jsRuntime_.GetNapiEnv();
|
||||
|
||||
jsObj_ = jsRuntime_.LoadModule(
|
||||
moduleName, srcPath, abilityInfo_->hapPath, abilityInfo_->compileMode == CompileMode::ES_MODULE);
|
||||
HILOG_DEBUG("LoadModule moduleName:%{public}s, srcPath:%{public}s, hapPath:%{public}s",
|
||||
moduleName.c_str(), srcPath.c_str(), abilityInfo_->hapPath.c_str());
|
||||
if (jsObj_ == nullptr) {
|
||||
HILOG_ERROR("Js object is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
napi_value obj = jsObj_->GetNapiValue();
|
||||
if (!CheckTypeForNapiValue(env, obj, napi_object)) {
|
||||
HILOG_ERROR("Failed to get js auto fill extension object.");
|
||||
return;
|
||||
}
|
||||
|
||||
BindContext(env, obj);
|
||||
|
||||
SetExtensionCommon(
|
||||
JsExtensionCommon::Create(jsRuntime_, static_cast<NativeReference&>(*jsObj_), shellContextRef_));
|
||||
}
|
||||
|
||||
void JsAutoFillExtension::BindContext(napi_env env, napi_value obj)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
auto context = GetContext();
|
||||
if (context == nullptr) {
|
||||
HILOG_ERROR("Failed to get context.");
|
||||
return;
|
||||
}
|
||||
HILOG_DEBUG("Create js auto fill extension context.");
|
||||
napi_value contextObj = JsAutoFillExtensionContext::CreateJsAutoFillExtensionContext(env, context);
|
||||
if (contextObj == nullptr) {
|
||||
HILOG_ERROR("Create js ui extension context failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
shellContextRef_ = JsRuntime::LoadSystemModuleByEngine(
|
||||
env, "application.AutoFillExtensionContext", &contextObj, ARGC_ONE);
|
||||
if (shellContextRef_ == nullptr) {
|
||||
HILOG_ERROR("Load system module by engine failed.");
|
||||
return;
|
||||
}
|
||||
contextObj = shellContextRef_->GetNapiValue();
|
||||
if (!CheckTypeForNapiValue(env, contextObj, napi_object)) {
|
||||
HILOG_ERROR("Failed to get context native object.");
|
||||
return;
|
||||
}
|
||||
auto workContext = new (std::nothrow) std::weak_ptr<AutoFillExtensionContext>(context);
|
||||
if (workContext == nullptr) {
|
||||
HILOG_ERROR("workContext is nullptr.");
|
||||
return;
|
||||
}
|
||||
napi_coerce_to_native_binding_object(
|
||||
env, contextObj, DetachCallbackFunc, AttachAutoFillExtensionContext, workContext, nullptr);
|
||||
context->Bind(jsRuntime_, shellContextRef_.get());
|
||||
napi_set_named_property(env, obj, "context", contextObj);
|
||||
napi_wrap(env, contextObj, workContext,
|
||||
[](napi_env, void* data, void*) {
|
||||
HILOG_DEBUG("Finalizer for weak_ptr ui extension context is called");
|
||||
delete static_cast<std::weak_ptr<AutoFillExtensionContext>*>(data);
|
||||
},
|
||||
nullptr, nullptr);
|
||||
}
|
||||
|
||||
void JsAutoFillExtension::OnStart(const AAFwk::Want &want)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
Extension::OnStart(want);
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
napi_env env = jsRuntime_.GetNapiEnv();
|
||||
napi_value napiWant = OHOS::AppExecFwk::WrapWant(env, want);
|
||||
napi_value argv[] = { napiWant };
|
||||
CallObjectMethod("onCreate", argv, ARGC_ONE);
|
||||
}
|
||||
|
||||
void JsAutoFillExtension::OnStop()
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
AutoFillExtension::OnStop();
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
CallObjectMethod("onDestroy");
|
||||
OnStopCallBack();
|
||||
}
|
||||
|
||||
void JsAutoFillExtension::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, bool &isAsyncCallback)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (callbackInfo == nullptr) {
|
||||
isAsyncCallback = false;
|
||||
OnStop();
|
||||
return;
|
||||
}
|
||||
|
||||
AutoFillExtension::OnStop();
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
napi_value result = CallObjectMethod("onDestroy", nullptr, 0, true);
|
||||
if (!CheckPromise(result)) {
|
||||
OnStopCallBack();
|
||||
isAsyncCallback = false;
|
||||
return;
|
||||
}
|
||||
|
||||
std::weak_ptr<Extension> weakPtr = shared_from_this();
|
||||
auto asyncCallback = [extensionWeakPtr = weakPtr]() {
|
||||
auto JsAutoFillExtension = extensionWeakPtr.lock();
|
||||
if (JsAutoFillExtension == nullptr) {
|
||||
HILOG_ERROR("Extension is nullptr.");
|
||||
return;
|
||||
}
|
||||
JsAutoFillExtension->OnStopCallBack();
|
||||
};
|
||||
callbackInfo->Push(asyncCallback);
|
||||
isAsyncCallback = CallPromise(result, callbackInfo);
|
||||
if (!isAsyncCallback) {
|
||||
HILOG_ERROR("Failed to call promise.");
|
||||
OnStopCallBack();
|
||||
}
|
||||
}
|
||||
|
||||
void JsAutoFillExtension::OnStopCallBack()
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
auto context = GetContext();
|
||||
if (context == nullptr) {
|
||||
HILOG_ERROR("Failed to get context.");
|
||||
return;
|
||||
}
|
||||
|
||||
bool ret = ConnectionManager::GetInstance().DisconnectCaller(context->GetToken());
|
||||
if (ret) {
|
||||
ConnectionManager::GetInstance().ReportConnectionLeakEvent(getpid(), gettid());
|
||||
HILOG_DEBUG("The service connection is not disconnected.");
|
||||
}
|
||||
|
||||
auto applicationContext = Context::GetApplicationContext();
|
||||
if (applicationContext != nullptr) {
|
||||
std::shared_ptr<NativeReference> sharedJsObj = std::move(jsObj_);
|
||||
applicationContext->DispatchOnAbilityDestroy(sharedJsObj);
|
||||
}
|
||||
}
|
||||
|
||||
bool JsAutoFillExtension::CheckPromise(napi_value result)
|
||||
{
|
||||
if (result == nullptr) {
|
||||
HILOG_DEBUG("Result is null, no need to call promise.");
|
||||
return false;
|
||||
}
|
||||
|
||||
napi_env env = jsRuntime_.GetNapiEnv();
|
||||
bool isPromise = false;
|
||||
napi_is_promise(env, result, &isPromise);
|
||||
if (!isPromise) {
|
||||
HILOG_DEBUG("Result is not promise, no need to call promise.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
napi_value PromiseCallback(napi_env env, napi_callback_info info)
|
||||
{
|
||||
void *data = nullptr;
|
||||
NAPI_CALL_NO_THROW(napi_get_cb_info(env, info, nullptr, nullptr, nullptr, &data), nullptr);
|
||||
auto *callbackInfo = static_cast<AppExecFwk::AbilityTransactionCallbackInfo<> *>(data);
|
||||
if (callbackInfo == nullptr) {
|
||||
HILOG_DEBUG("Invalid input info.");
|
||||
return nullptr;
|
||||
}
|
||||
callbackInfo->Call();
|
||||
AppExecFwk::AbilityTransactionCallbackInfo<>::Destroy(callbackInfo);
|
||||
data = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool JsAutoFillExtension::CallPromise(napi_value result, AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo)
|
||||
{
|
||||
auto env = jsRuntime_.GetNapiEnv();
|
||||
if (!CheckTypeForNapiValue(env, result, napi_object)) {
|
||||
HILOG_ERROR("Failed to convert native value to NativeObject.");
|
||||
return false;
|
||||
}
|
||||
napi_value then = nullptr;
|
||||
napi_get_named_property(env, result, "then", &then);
|
||||
if (then == nullptr) {
|
||||
HILOG_ERROR("Failed to get property: then.");
|
||||
return false;
|
||||
}
|
||||
bool isCallable = false;
|
||||
napi_is_callable(env, then, &isCallable);
|
||||
if (!isCallable) {
|
||||
HILOG_ERROR("Property then is not callable.");
|
||||
return false;
|
||||
}
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
napi_value promiseCallback = nullptr;
|
||||
napi_create_function(env, "promiseCallback", strlen("promiseCallback"), PromiseCallback,
|
||||
callbackInfo, &promiseCallback);
|
||||
napi_value argv[1] = { promiseCallback };
|
||||
napi_call_function(env, result, then, 1, argv, nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
void JsAutoFillExtension::OnCommandWindow(
|
||||
const AAFwk::Want &want, const sptr<AAFwk::SessionInfo> &sessionInfo, AAFwk::WindowCommand winCmd)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (sessionInfo == nullptr) {
|
||||
HILOG_ERROR("Session info is nullptr.");
|
||||
return;
|
||||
}
|
||||
HILOG_DEBUG("Begin. persistentId: %{private}d, winCmd: %{public}d", sessionInfo->persistentId, winCmd);
|
||||
Extension::OnCommandWindow(want, sessionInfo, winCmd);
|
||||
switch (winCmd) {
|
||||
case AAFwk::WIN_CMD_FOREGROUND:
|
||||
ForegroundWindow(want, sessionInfo);
|
||||
break;
|
||||
case AAFwk::WIN_CMD_BACKGROUND:
|
||||
BackgroundWindow(sessionInfo);
|
||||
break;
|
||||
case AAFwk::WIN_CMD_DESTROY:
|
||||
DestroyWindow(sessionInfo);
|
||||
break;
|
||||
default:
|
||||
HILOG_DEBUG("Unsupported cmd.");
|
||||
break;
|
||||
}
|
||||
OnCommandWindowDone(sessionInfo, winCmd);
|
||||
}
|
||||
|
||||
void JsAutoFillExtension::OnCommandWindowDone(const sptr<AAFwk::SessionInfo> &sessionInfo, AAFwk::WindowCommand winCmd)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
auto context = GetContext();
|
||||
if (context == nullptr) {
|
||||
HILOG_ERROR("Failed to get context.");
|
||||
return;
|
||||
}
|
||||
AAFwk::AbilityCommand abilityCmd;
|
||||
if (uiWindowMap_.empty()) {
|
||||
abilityCmd = AAFwk::ABILITY_CMD_DESTROY;
|
||||
} else if (foregroundWindows_.empty()) {
|
||||
abilityCmd = AAFwk::ABILITY_CMD_BACKGROUND;
|
||||
} else {
|
||||
abilityCmd = AAFwk::ABILITY_CMD_FOREGROUND;
|
||||
}
|
||||
AAFwk::AbilityManagerClient::GetInstance()->ScheduleCommandAbilityWindowDone(
|
||||
context->GetToken(), sessionInfo, winCmd, abilityCmd);
|
||||
HILOG_DEBUG("End.");
|
||||
}
|
||||
|
||||
void JsAutoFillExtension::OnCommand(const AAFwk::Want &want, bool restart, int startId)
|
||||
{
|
||||
HILOG_DEBUG("Begin.");
|
||||
Extension::OnCommand(want, restart, startId);
|
||||
HILOG_DEBUG("JsAutoFillExtension OnCommand begin restart= %{public}s, startId= %{public}d.",
|
||||
restart ? "true" : "false", startId);
|
||||
// wrap want
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
napi_env env = jsRuntime_.GetNapiEnv();
|
||||
napi_value napiWant = OHOS::AppExecFwk::WrapWant(env, want);
|
||||
// wrap startId
|
||||
napi_value napiStartId = nullptr;
|
||||
napi_create_int32(env, startId, &napiStartId);
|
||||
napi_value argv[] = {napiWant, napiStartId};
|
||||
CallObjectMethod("onRequest", argv, ARGC_TWO);
|
||||
HILOG_DEBUG("End.");
|
||||
}
|
||||
|
||||
void JsAutoFillExtension::OnForeground(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
Extension::OnForeground(want, sessionInfo);
|
||||
ForegroundWindow(want, sessionInfo);
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
CallObjectMethod("onForeground");
|
||||
}
|
||||
|
||||
void JsAutoFillExtension::OnBackground()
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
CallObjectMethod("onBackground");
|
||||
Extension::OnBackground();
|
||||
}
|
||||
|
||||
bool JsAutoFillExtension::HandleAutoFillCreate(const AAFwk::Want &want, const sptr<AAFwk::SessionInfo> &sessionInfo)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (sessionInfo == nullptr || sessionInfo->sessionToken == nullptr) {
|
||||
HILOG_ERROR("Invalid session info.");
|
||||
return false;
|
||||
}
|
||||
auto obj = sessionInfo->sessionToken;
|
||||
if (uiWindowMap_.find(obj) == uiWindowMap_.end()) {
|
||||
sptr<Rosen::WindowOption> option = new Rosen::WindowOption();
|
||||
auto context = GetContext();
|
||||
if (context == nullptr || context->GetAbilityInfo() == nullptr) {
|
||||
HILOG_ERROR("Failed to get context.");
|
||||
return false;
|
||||
}
|
||||
option->SetWindowName(context->GetBundleName() + context->GetAbilityInfo()->name);
|
||||
option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_UI_EXTENSION);
|
||||
option->SetWindowSessionType(Rosen::WindowSessionType::EXTENSION_SESSION);
|
||||
option->SetParentId(sessionInfo->hostWindowId);
|
||||
auto uiWindow = Rosen::Window::Create(option, GetContext(), sessionInfo->sessionToken);
|
||||
if (uiWindow == nullptr) {
|
||||
HILOG_ERROR("Create ui window error.");
|
||||
return false;
|
||||
}
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
napi_env env = jsRuntime_.GetNapiEnv();
|
||||
napi_value nativeContentSession =
|
||||
JsUIExtensionContentSession::CreateJsUIExtensionContentSession(env, sessionInfo, uiWindow);
|
||||
napi_ref ref = nullptr;
|
||||
napi_create_reference(env, nativeContentSession, 1, &ref);
|
||||
contentSessions_.emplace(
|
||||
obj, std::shared_ptr<NativeReference>(reinterpret_cast<NativeReference*>(ref)));
|
||||
CallJsOnRequest(want, sessionInfo, uiWindow);
|
||||
uiWindowMap_[obj] = uiWindow;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void JsAutoFillExtension::ForegroundWindow(const AAFwk::Want &want, const sptr<AAFwk::SessionInfo> &sessionInfo)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (sessionInfo == nullptr) {
|
||||
HILOG_ERROR("sessionInfo is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!HandleAutoFillCreate(want, sessionInfo)) {
|
||||
HILOG_ERROR("Handle auto fill create failed.");
|
||||
return;
|
||||
}
|
||||
auto obj = sessionInfo->sessionToken;
|
||||
auto& uiWindow = uiWindowMap_[obj];
|
||||
if (uiWindow) {
|
||||
uiWindow->Show();
|
||||
HILOG_DEBUG("UI window show.");
|
||||
foregroundWindows_.emplace(obj);
|
||||
|
||||
AAFwk::WantParams wantParams;
|
||||
wantParams.SetParam(WANT_PARAMS_AUTO_FILL_EVENT_KEY, AAFwk::Integer::Box(
|
||||
static_cast<int32_t>(JsAutoFillExtensionUtil::AutoFillResultCode::CALLBACK_REMOVE_TIME_OUT)));
|
||||
uiWindow->TransferExtensionData(wantParams);
|
||||
}
|
||||
}
|
||||
|
||||
void JsAutoFillExtension::BackgroundWindow(const sptr<AAFwk::SessionInfo> &sessionInfo)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (sessionInfo == nullptr || sessionInfo->sessionToken == nullptr) {
|
||||
HILOG_ERROR("Invalid sessionInfo.");
|
||||
return;
|
||||
}
|
||||
auto obj = sessionInfo->sessionToken;
|
||||
if (uiWindowMap_.find(obj) == uiWindowMap_.end()) {
|
||||
HILOG_ERROR("Fail to find ui window.");
|
||||
return;
|
||||
}
|
||||
auto& uiWindow = uiWindowMap_[obj];
|
||||
if (uiWindow) {
|
||||
uiWindow->Hide();
|
||||
foregroundWindows_.erase(obj);
|
||||
}
|
||||
}
|
||||
|
||||
void JsAutoFillExtension::DestroyWindow(const sptr<AAFwk::SessionInfo> &sessionInfo)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (sessionInfo == nullptr || sessionInfo->sessionToken == nullptr) {
|
||||
HILOG_ERROR("Invalid sessionInfo.");
|
||||
return;
|
||||
}
|
||||
auto obj = sessionInfo->sessionToken;
|
||||
if (uiWindowMap_.find(obj) == uiWindowMap_.end()) {
|
||||
HILOG_ERROR("Wrong to find uiWindow");
|
||||
return;
|
||||
}
|
||||
if (contentSessions_.find(obj) != contentSessions_.end() && contentSessions_[obj] != nullptr) {
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
napi_value argv[] = {contentSessions_[obj]->GetNapiValue()};
|
||||
CallObjectMethod("onSessionDestroy", argv, ARGC_ONE);
|
||||
}
|
||||
auto& uiWindow = uiWindowMap_[obj];
|
||||
if (uiWindow) {
|
||||
uiWindow->Destroy();
|
||||
}
|
||||
uiWindowMap_.erase(obj);
|
||||
foregroundWindows_.erase(obj);
|
||||
contentSessions_.erase(obj);
|
||||
callbacks_.erase(obj);
|
||||
}
|
||||
|
||||
napi_value JsAutoFillExtension::CallObjectMethod(const char *name, napi_value const *argv, size_t argc, bool withResult)
|
||||
{
|
||||
HILOG_DEBUG("Called, name is (%{public}s)", name);
|
||||
if (!jsObj_) {
|
||||
HILOG_ERROR("Not found AutoFillExtension.js.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HandleEscape handleEscape(jsRuntime_);
|
||||
napi_env env = jsRuntime_.GetNapiEnv();
|
||||
|
||||
napi_value obj = jsObj_->GetNapiValue();
|
||||
if (!CheckTypeForNapiValue(env, obj, napi_object)) {
|
||||
HILOG_ERROR("Failed to get auto fill extension object.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value method = nullptr;
|
||||
napi_get_named_property(env, obj, name, &method);
|
||||
if (!CheckTypeForNapiValue(env, method, napi_function)) {
|
||||
HILOG_ERROR("Failed to get '%{public}s' from auto fill extension object.", name);
|
||||
return nullptr;
|
||||
}
|
||||
if (withResult) {
|
||||
napi_value result = nullptr;
|
||||
napi_call_function(env, obj, method, argc, argv, &result);
|
||||
return handleEscape.Escape(result);
|
||||
}
|
||||
HILOG_DEBUG("Call function: (%{public}s) success.", name);
|
||||
napi_call_function(env, obj, method, argc, argv, nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void JsAutoFillExtension::CallJsOnRequest(
|
||||
const AAFwk::Want &want, const sptr<AAFwk::SessionInfo> &sessionInfo, const sptr<Rosen::Window> &uiWindow)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (sessionInfo == nullptr) {
|
||||
HILOG_ERROR("sessionInfo is nullptr.");
|
||||
return;
|
||||
}
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
napi_env env = jsRuntime_.GetNapiEnv();
|
||||
if (env == nullptr) {
|
||||
HILOG_ERROR("Env is nullptr.");
|
||||
return;
|
||||
}
|
||||
napi_value nativeContentSession =
|
||||
JsUIExtensionContentSession::CreateJsUIExtensionContentSession(env, sessionInfo, uiWindow);
|
||||
if (nativeContentSession == nullptr) {
|
||||
HILOG_ERROR("Failed to create session.");
|
||||
return;
|
||||
}
|
||||
napi_ref ref = nullptr;
|
||||
napi_create_reference(env, nativeContentSession, 1, &ref);
|
||||
contentSessions_.emplace(
|
||||
sessionInfo->sessionToken, std::shared_ptr<NativeReference>(reinterpret_cast<NativeReference*>(ref)));
|
||||
|
||||
napi_value fillrequest = JsAutoFillExtensionUtil::WrapFillRequest(want, env);
|
||||
if (fillrequest == nullptr) {
|
||||
HILOG_ERROR("Fill request is nullptr.");
|
||||
}
|
||||
|
||||
napi_value callback = nullptr;
|
||||
auto cmdValue = want.GetStringParam(WANT_PARAMS_AUTO_FILL_CMD);
|
||||
if (cmdValue == WANT_PARAMS_AUTO_FILL_CMD_AUTOSAVE) {
|
||||
callback = JsSaveRequestCallback::CreateJsSaveRequestCallback(env, sessionInfo, uiWindow);
|
||||
napi_value argv[] = { nativeContentSession, fillrequest, callback };
|
||||
CallObjectMethod("onSaveRequest", argv, ARGC_THREE);
|
||||
} else if (cmdValue == WANT_PARAMS_AUTO_FILL_CMD_AUTOFILL) {
|
||||
callback = JsFillRequestCallback::CreateJsFillRequestCallback(env, sessionInfo, uiWindow);
|
||||
napi_value argv[] = { nativeContentSession, fillrequest, callback };
|
||||
CallObjectMethod("onFillRequest", argv, ARGC_THREE);
|
||||
} else {
|
||||
HILOG_DEBUG("Invalid auto fill request type.");
|
||||
}
|
||||
|
||||
napi_ref callbackRef = nullptr;
|
||||
napi_create_reference(env, callback, 1, &callbackRef);
|
||||
callbacks_.emplace(sessionInfo->sessionToken,
|
||||
std::shared_ptr<NativeReference>(reinterpret_cast<NativeReference*>(callbackRef)));
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "js_auto_fill_extension_context.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_extension_context.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "napi_common_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
void JsAutoFillExtensionContext::Finalizer(napi_env env, void *data, void *hint)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
std::unique_ptr<JsAutoFillExtensionContext>(static_cast<JsAutoFillExtensionContext*>(data));
|
||||
}
|
||||
|
||||
napi_value JsAutoFillExtensionContext::CreateJsAutoFillExtensionContext(
|
||||
napi_env env, const std::shared_ptr<AutoFillExtensionContext> &context)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
std::shared_ptr<OHOS::AppExecFwk::AbilityInfo> abilityInfo = nullptr;
|
||||
if (context != nullptr) {
|
||||
abilityInfo = context->GetAbilityInfo();
|
||||
}
|
||||
napi_value objValue = CreateJsExtensionContext(env, context, abilityInfo);
|
||||
|
||||
auto jsContext = std::make_unique<JsAutoFillExtensionContext>();
|
||||
napi_wrap(env, objValue, jsContext.release(), Finalizer, nullptr, nullptr);
|
||||
|
||||
return objValue;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "js_auto_fill_extension_util.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "napi_common_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr const char *VIEW_DATA_BUNDLE_NAME = "bundleName";
|
||||
constexpr const char *VIEW_DATA_MODULE_NAME = "moduleName";
|
||||
constexpr const char *VIEW_DATA_ABILITY_NAME = "abilityName";
|
||||
constexpr const char *VIEW_DATA_PAGEURL = "pageUrl";
|
||||
constexpr const char *VIEW_DATA_PAGE_NODE_INFOS = "pageNodeInfos";
|
||||
constexpr const char *VIEW_DATA_VIEW_DATA = "viewData";
|
||||
constexpr const char *VIEW_DATA_TYPE = "type";
|
||||
constexpr const char *PAGE_INFO_ID = "id";
|
||||
constexpr const char *PAGE_INFO_DEPTH = "depth";
|
||||
constexpr const char *PAGE_INFO_AUTOFILLTYPE = "autoFillType";
|
||||
constexpr const char *PAGE_INFO_TAG = "tag";
|
||||
constexpr const char *PAGE_INFO_VALUE = "value";
|
||||
constexpr const char *PAGE_INFO_PLACEHOLDER = "placeholder";
|
||||
constexpr const char *PAGE_INFO_PASSWORDRULES = "passwordRules";
|
||||
constexpr const char *PAGE_INFO_ENABLEAUTOFILL = "enableAutoFill";
|
||||
constexpr const char *WANT_PARAMS_VIEW_DATA = "ohos.ability.params.viewData";
|
||||
constexpr const char *WANT_PARAMS_AUTO_FILL_TYPE_KEY = "ability.want.params.AutoFillType";
|
||||
constexpr uint32_t PAGE_NODE_COUNT_MAX = 100;
|
||||
} // namespace
|
||||
|
||||
napi_value JsAutoFillExtensionUtil::WrapViewData(const napi_env env, const AbilityBase::ViewData &viewData)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
napi_value jsObject = nullptr;
|
||||
NAPI_CALL(env, napi_create_object(env, &jsObject));
|
||||
napi_value jsValue = nullptr;
|
||||
jsValue = WrapStringToJS(env, viewData.bundleName);
|
||||
SetPropertyValueByPropertyName(env, jsObject, VIEW_DATA_BUNDLE_NAME, jsValue);
|
||||
|
||||
jsValue = WrapStringToJS(env, viewData.abilityName);
|
||||
SetPropertyValueByPropertyName(env, jsObject, VIEW_DATA_ABILITY_NAME, jsValue);
|
||||
|
||||
jsValue = WrapStringToJS(env, viewData.moduleName);
|
||||
SetPropertyValueByPropertyName(env, jsObject, VIEW_DATA_MODULE_NAME, jsValue);
|
||||
|
||||
jsValue = WrapStringToJS(env, viewData.pageUrl);
|
||||
SetPropertyValueByPropertyName(env, jsObject, VIEW_DATA_PAGEURL, jsValue);
|
||||
|
||||
napi_value jsArray = nullptr;
|
||||
NAPI_CALL(env, napi_create_array(env, &jsArray));
|
||||
napi_value jsSubValue = nullptr;
|
||||
uint32_t index = 0;
|
||||
for (auto element : viewData.nodes) {
|
||||
jsSubValue = WrapPageNodeInfo(env, element);
|
||||
if (jsSubValue != nullptr && napi_set_element(env, jsArray, index, jsSubValue) == napi_ok) {
|
||||
index++;
|
||||
} else {
|
||||
HILOG_ERROR("Set element fail.");
|
||||
}
|
||||
}
|
||||
|
||||
SetPropertyValueByPropertyName(env, jsObject, VIEW_DATA_PAGE_NODE_INFOS, jsArray);
|
||||
return jsObject;
|
||||
}
|
||||
|
||||
napi_value JsAutoFillExtensionUtil::WrapPageNodeInfo(const napi_env env, const AbilityBase::PageNodeInfo &pageNodeInfo)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
napi_value jsObject = nullptr;
|
||||
NAPI_CALL(env, napi_create_object(env, &jsObject));
|
||||
napi_value jsValue = nullptr;
|
||||
jsValue = AppExecFwk::WrapInt32ToJS(env, pageNodeInfo.id);
|
||||
SetPropertyValueByPropertyName(env, jsObject, PAGE_INFO_ID, jsValue);
|
||||
|
||||
jsValue = AppExecFwk::WrapInt32ToJS(env, pageNodeInfo.depth);
|
||||
SetPropertyValueByPropertyName(env, jsObject, PAGE_INFO_DEPTH, jsValue);
|
||||
|
||||
jsValue = AppExecFwk::WrapInt32ToJS(env, static_cast<int32_t>(pageNodeInfo.autoFillType));
|
||||
SetPropertyValueByPropertyName(env, jsObject, PAGE_INFO_AUTOFILLTYPE, jsValue);
|
||||
|
||||
jsValue = WrapStringToJS(env, pageNodeInfo.tag);
|
||||
SetPropertyValueByPropertyName(env, jsObject, PAGE_INFO_TAG, jsValue);
|
||||
|
||||
jsValue = WrapStringToJS(env, pageNodeInfo.value);
|
||||
SetPropertyValueByPropertyName(env, jsObject, PAGE_INFO_VALUE, jsValue);
|
||||
|
||||
jsValue = WrapStringToJS(env, pageNodeInfo.passwordRules);
|
||||
SetPropertyValueByPropertyName(env, jsObject, PAGE_INFO_PASSWORDRULES, jsValue);
|
||||
|
||||
jsValue = WrapStringToJS(env, pageNodeInfo.placeholder);
|
||||
SetPropertyValueByPropertyName(env, jsObject, PAGE_INFO_PLACEHOLDER, jsValue);
|
||||
|
||||
jsValue = WrapBoolToJS(env, pageNodeInfo.enableAutoFill);
|
||||
SetPropertyValueByPropertyName(env, jsObject, PAGE_INFO_ENABLEAUTOFILL, jsValue);
|
||||
|
||||
return jsObject;
|
||||
}
|
||||
|
||||
void JsAutoFillExtensionUtil::UnwrapViewData(
|
||||
const napi_env env, const napi_value value, AbilityBase::ViewData &viewData)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
napi_value jsViewData = GetPropertyValueByPropertyName(env, value, VIEW_DATA_VIEW_DATA, napi_object);
|
||||
if (jsViewData == nullptr) {
|
||||
HILOG_ERROR("Get ViewData from JS failed");
|
||||
return;
|
||||
}
|
||||
|
||||
napi_value jsValue = nullptr;
|
||||
jsValue = GetPropertyValueByPropertyName(env, jsViewData, VIEW_DATA_BUNDLE_NAME, napi_string);
|
||||
viewData.bundleName = UnwrapStringFromJS(env, jsValue, "");
|
||||
jsValue = GetPropertyValueByPropertyName(env, jsViewData, VIEW_DATA_MODULE_NAME, napi_string);
|
||||
viewData.moduleName = UnwrapStringFromJS(env, jsValue, "");
|
||||
jsValue = GetPropertyValueByPropertyName(env, jsViewData, VIEW_DATA_ABILITY_NAME, napi_string);
|
||||
viewData.abilityName = UnwrapStringFromJS(env, jsValue, "");
|
||||
jsValue = GetPropertyValueByPropertyName(env, jsViewData, VIEW_DATA_PAGEURL, napi_string);
|
||||
viewData.pageUrl = UnwrapStringFromJS(env, jsValue, "");
|
||||
jsValue = GetPropertyValueByPropertyName(env, jsViewData, VIEW_DATA_PAGE_NODE_INFOS, napi_object);
|
||||
if (jsValue != nullptr) {
|
||||
uint32_t jsProCount = 0;
|
||||
if (!IsArrayForNapiValue(env, jsValue, jsProCount)) {
|
||||
HILOG_ERROR("Get PAGE_NODE_INFOS from JS failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint32_t index = 0; index < jsProCount && index < PAGE_NODE_COUNT_MAX; index++) {
|
||||
napi_value jsNode = nullptr;
|
||||
napi_get_element(env, jsValue, index, &jsNode);
|
||||
AbilityBase::PageNodeInfo node;
|
||||
UnwrapPageNodeInfo(env, jsNode, node);
|
||||
viewData.nodes.emplace_back(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JsAutoFillExtensionUtil::UnwrapPageNodeInfo(
|
||||
const napi_env env, const napi_value jsNode, AbilityBase::PageNodeInfo &node)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
UnwrapInt32ByPropertyName(env, jsNode, PAGE_INFO_ID, node.id);
|
||||
UnwrapInt32ByPropertyName(env, jsNode, PAGE_INFO_DEPTH, node.depth);
|
||||
int32_t type;
|
||||
UnwrapInt32ByPropertyName(env, jsNode, PAGE_INFO_AUTOFILLTYPE, type);
|
||||
node.autoFillType = static_cast<AbilityBase::AutoFillType>(type);
|
||||
UnwrapStringByPropertyName(env, jsNode, PAGE_INFO_TAG, node.tag);
|
||||
UnwrapStringByPropertyName(env, jsNode, PAGE_INFO_VALUE, node.value);
|
||||
UnwrapStringByPropertyName(env, jsNode, PAGE_INFO_PASSWORDRULES, node.passwordRules);
|
||||
UnwrapStringByPropertyName(env, jsNode, PAGE_INFO_PLACEHOLDER, node.placeholder);
|
||||
UnwrapBooleanByPropertyName(env, jsNode, PAGE_INFO_ENABLEAUTOFILL, node.enableAutoFill);
|
||||
}
|
||||
|
||||
napi_value JsAutoFillExtensionUtil::WrapFillRequest(const AAFwk::Want &want, const napi_env env)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
napi_value jsObject = nullptr;
|
||||
NAPI_CALL(env, napi_create_object(env, &jsObject));
|
||||
if (jsObject == nullptr) {
|
||||
HILOG_ERROR("Failed to create jsObject.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (want.HasParameter(WANT_PARAMS_AUTO_FILL_TYPE_KEY)) {
|
||||
auto type = want.GetIntParam(WANT_PARAMS_AUTO_FILL_TYPE_KEY, -1);
|
||||
HILOG_DEBUG("Auto fill request type: %{public}d", type);
|
||||
|
||||
napi_value jsValue = AppExecFwk::WrapInt32ToJS(env, type);
|
||||
SetPropertyValueByPropertyName(env, jsObject, VIEW_DATA_TYPE, jsValue);
|
||||
}
|
||||
|
||||
if (want.HasParameter(WANT_PARAMS_VIEW_DATA)) {
|
||||
std::string viewDataString = want.GetStringParam(WANT_PARAMS_VIEW_DATA);
|
||||
if (viewDataString.empty()) {
|
||||
HILOG_ERROR("View data is empty.");
|
||||
return jsObject;
|
||||
}
|
||||
|
||||
AbilityBase::ViewData viewData;
|
||||
viewData.FromJsonString(viewDataString);
|
||||
napi_value viewDataValue = WrapViewData(env, viewData);
|
||||
SetPropertyValueByPropertyName(env, jsObject, VIEW_DATA_VIEW_DATA, viewDataValue);
|
||||
}
|
||||
return jsObject;
|
||||
}
|
||||
|
||||
void JsAutoFillExtensionUtil::UnwrapFillResponse(const napi_env env, const napi_value value, FillResponse &response)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
UnwrapViewData(env, value, response.viewData);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "js_fill_request_callback.h"
|
||||
|
||||
#include "ability_manager_client.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_error_utils.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "native_engine.h"
|
||||
#include "native_value.h"
|
||||
#include "ui_content.h"
|
||||
#include "view_data.h"
|
||||
#include "want.h"
|
||||
#include "window.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr int32_t INDEX_ZERO = 0;
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
constexpr const char *WANT_PARAMS_VIEW_DATA = "ohos.ability.params.viewData";
|
||||
constexpr const char *WANT_PARAMS_AUTO_FILL_CMD = "ohos.ability.params.autoFillCmd";
|
||||
constexpr const char *WANT_PARAMS_AUTO_FILL_CMD_AUTOFILL = "autofill";
|
||||
} // namespace
|
||||
|
||||
JsFillRequestCallback::JsFillRequestCallback(
|
||||
const sptr<AAFwk::SessionInfo> &sessionInfo, const sptr<Rosen::Window> &uiWindow)
|
||||
: sessionInfo_(sessionInfo), uiWindow_(uiWindow)
|
||||
{}
|
||||
|
||||
void JsFillRequestCallback::Finalizer(napi_env env, void* data, void *hint)
|
||||
{
|
||||
HILOG_DEBUG("JsFillRequestCallback Finalizer is called");
|
||||
std::unique_ptr<JsFillRequestCallback>(static_cast<JsFillRequestCallback*>(data));
|
||||
}
|
||||
|
||||
napi_value JsFillRequestCallback::FillRequestSuccess(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsFillRequestCallback, OnFillRequestSuccess);
|
||||
}
|
||||
|
||||
napi_value JsFillRequestCallback::FillRequestFailed(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsFillRequestCallback, OnFillRequestFailed);
|
||||
}
|
||||
|
||||
napi_value JsFillRequestCallback::FillRequestCanceled(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsFillRequestCallback, OnFillRequestCanceled);
|
||||
}
|
||||
|
||||
napi_value JsFillRequestCallback::OnFillRequestSuccess(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (info.argc < ARGC_ONE || !IsTypeForNapiValue(env, info.argv[INDEX_ZERO], napi_object)) {
|
||||
HILOG_ERROR("Failed to parse viewData JsonString!");
|
||||
SendResultCodeAndViewData(
|
||||
JsAutoFillExtensionUtil::AutoFillResultCode::CALLBACK_FAILED_INVALID_PARAM, "");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
FillResponse response;
|
||||
JsAutoFillExtensionUtil::UnwrapFillResponse(env, info.argv[INDEX_ZERO], response);
|
||||
std::string jsonString = response.viewData.ToJsonString();
|
||||
if (jsonString.empty()) {
|
||||
HILOG_ERROR("JsonString is empty");
|
||||
SendResultCodeAndViewData(
|
||||
JsAutoFillExtensionUtil::AutoFillResultCode::CALLBACK_FAILED_INVALID_PARAM, "");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
SendResultCodeAndViewData(JsAutoFillExtensionUtil::AutoFillResultCode::CALLBACK_SUCESS, jsonString);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
napi_value JsFillRequestCallback::OnFillRequestFailed(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
SendResultCodeAndViewData(JsAutoFillExtensionUtil::AutoFillResultCode::CALLBACK_FAILED, "");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
napi_value JsFillRequestCallback::OnFillRequestCanceled(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
SendResultCodeAndViewData(JsAutoFillExtensionUtil::AutoFillResultCode::CALLBACK_CANCEL, "");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
void JsFillRequestCallback::SendResultCodeAndViewData(
|
||||
const JsAutoFillExtensionUtil::AutoFillResultCode &resultCode, const std::string &jsString)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (uiWindow_ == nullptr) {
|
||||
HILOG_ERROR("UiWindow is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
AAFwk::Want want;
|
||||
if (resultCode == JsAutoFillExtensionUtil::AutoFillResultCode::CALLBACK_SUCESS) {
|
||||
want.SetParam(WANT_PARAMS_VIEW_DATA, jsString);
|
||||
want.SetParam(WANT_PARAMS_AUTO_FILL_CMD, WANT_PARAMS_AUTO_FILL_CMD_AUTOFILL);
|
||||
}
|
||||
|
||||
auto ret = uiWindow_->TransferAbilityResult(resultCode, want);
|
||||
if (ret != Rosen::WMError::WM_OK) {
|
||||
HILOG_ERROR("Transfer ability result failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto errorCode = AAFwk::AbilityManagerClient::GetInstance()->TerminateUIExtensionAbility(sessionInfo_);
|
||||
if (errorCode != ERR_OK) {
|
||||
HILOG_ERROR("Terminate ui extension ability failed, errorCode: %{public}d", errorCode);
|
||||
}
|
||||
}
|
||||
|
||||
napi_value JsFillRequestCallback::CreateJsFillRequestCallback(napi_env env,
|
||||
const sptr<AAFwk::SessionInfo> &sessionInfo, const sptr<Rosen::Window> &uiWindow)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
napi_value object = nullptr;
|
||||
napi_create_object(env, &object);
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("Object is null");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
std::unique_ptr<JsFillRequestCallback> jsSession =
|
||||
std::make_unique<JsFillRequestCallback>(sessionInfo, uiWindow);
|
||||
napi_wrap(env, object, jsSession.release(), Finalizer, nullptr, nullptr);
|
||||
|
||||
const char *moduleName = "JsFillRequestCallback";
|
||||
BindNativeFunction(env, object, "onSuccess", moduleName, FillRequestSuccess);
|
||||
BindNativeFunction(env, object, "onFailure", moduleName, FillRequestFailed);
|
||||
BindNativeFunction(env, object, "onCancel", moduleName, FillRequestCanceled);
|
||||
return object;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "js_save_request_callback.h"
|
||||
|
||||
#include "ability_manager_client.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_auto_fill_extension_util.h"
|
||||
#include "js_error_utils.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "native_engine.h"
|
||||
#include "native_value.h"
|
||||
#include "ui_content.h"
|
||||
#include "view_data.h"
|
||||
#include "want.h"
|
||||
#include "window.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
JsSaveRequestCallback::JsSaveRequestCallback(
|
||||
const sptr<AAFwk::SessionInfo> &sessionInfo, const sptr<Rosen::Window> &uiWindow)
|
||||
: sessionInfo_(sessionInfo), uiWindow_(uiWindow)
|
||||
{}
|
||||
|
||||
void JsSaveRequestCallback::Finalizer(napi_env env, void *data, void *hint)
|
||||
{
|
||||
HILOG_DEBUG("Finalizer is called.");
|
||||
std::unique_ptr<JsSaveRequestCallback>(static_cast<JsSaveRequestCallback*>(data));
|
||||
}
|
||||
|
||||
napi_value JsSaveRequestCallback::SaveRequestSuccess(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsSaveRequestCallback, OnSaveRequestSuccess);
|
||||
}
|
||||
|
||||
napi_value JsSaveRequestCallback::SaveRequestFailed(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsSaveRequestCallback, OnSaveRequestFailed);
|
||||
}
|
||||
|
||||
napi_value JsSaveRequestCallback::OnSaveRequestSuccess(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
SendResultCodeAndViewData(JsAutoFillExtensionUtil::AutoFillResultCode::CALLBACK_SUCESS);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
napi_value JsSaveRequestCallback::OnSaveRequestFailed(napi_env env, NapiCallbackInfo &info)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
SendResultCodeAndViewData(JsAutoFillExtensionUtil::AutoFillResultCode::CALLBACK_FAILED);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
void JsSaveRequestCallback::SendResultCodeAndViewData(const JsAutoFillExtensionUtil::AutoFillResultCode &resultCode)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
if (uiWindow_ == nullptr) {
|
||||
HILOG_ERROR("UI window is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
AAFwk::Want want;
|
||||
auto ret = uiWindow_->TransferAbilityResult(resultCode, want);
|
||||
if (ret != Rosen::WMError::WM_OK) {
|
||||
HILOG_ERROR("Transfer ability result failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto errorCode = AAFwk::AbilityManagerClient::GetInstance()->TerminateUIExtensionAbility(sessionInfo_);
|
||||
if (errorCode != ERR_OK) {
|
||||
HILOG_ERROR("Terminate ui extension ability failed, errorCode: %{public}d", errorCode);
|
||||
}
|
||||
}
|
||||
|
||||
napi_value JsSaveRequestCallback::CreateJsSaveRequestCallback(napi_env env,
|
||||
const sptr<AAFwk::SessionInfo> &sessionInfo, const sptr<Rosen::Window> &uiWindow)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
napi_value object = nullptr;
|
||||
napi_create_object(env, &object);
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("Object is null");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
std::unique_ptr<JsSaveRequestCallback> jsSession =
|
||||
std::make_unique<JsSaveRequestCallback>(sessionInfo, uiWindow);
|
||||
napi_wrap(env, object, jsSession.release(), Finalizer, nullptr, nullptr);
|
||||
|
||||
const char *moduleName = "JsSaveRequestCallback";
|
||||
BindNativeFunction(env, object, "onSuccess", moduleName, SaveRequestSuccess);
|
||||
BindNativeFunction(env, object, "onFailure", moduleName, SaveRequestFailed);
|
||||
return object;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -75,16 +75,14 @@ int32_t AutoStartupCallBackStub::OnAutoStartupOnInner(MessageParcel &data, Messa
|
||||
std::shared_ptr<AppExecFwk::EventHandler> handler =
|
||||
std::make_shared<AppExecFwk::EventHandler>(AppExecFwk::EventRunner::GetMainEventRunner());
|
||||
wptr<AutoStartupCallBackStub> weak = this;
|
||||
if (handler) {
|
||||
handler->PostSyncTask([weak, info]() {
|
||||
auto autoStartUpCallBackStub = weak.promote();
|
||||
if (autoStartUpCallBackStub == nullptr) {
|
||||
HILOG_ERROR("autoStartUpCallBackStub is nullptr.");
|
||||
return;
|
||||
}
|
||||
autoStartUpCallBackStub->OnAutoStartupOn(*info);
|
||||
});
|
||||
}
|
||||
handler->PostSyncTask([weak, info]() {
|
||||
auto autoStartUpCallBackStub = weak.promote();
|
||||
if (autoStartUpCallBackStub == nullptr) {
|
||||
HILOG_ERROR("autoStartUpCallBackStub is nullptr.");
|
||||
return;
|
||||
}
|
||||
autoStartUpCallBackStub->OnAutoStartupOn(*info);
|
||||
});
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
@ -100,16 +98,14 @@ int32_t AutoStartupCallBackStub::OnAutoStartupOffInner(MessageParcel &data, Mess
|
||||
std::shared_ptr<AppExecFwk::EventHandler> handler =
|
||||
std::make_shared<AppExecFwk::EventHandler>(AppExecFwk::EventRunner::GetMainEventRunner());
|
||||
wptr<AutoStartupCallBackStub> weak = this;
|
||||
if (handler) {
|
||||
handler->PostSyncTask([weak, info]() {
|
||||
auto autoStartUpCallBackStub = weak.promote();
|
||||
if (autoStartUpCallBackStub == nullptr) {
|
||||
HILOG_ERROR("autoStartUpCallBackStub is nullptr.");
|
||||
return;
|
||||
}
|
||||
autoStartUpCallBackStub->OnAutoStartupOff(*info);
|
||||
});
|
||||
}
|
||||
handler->PostSyncTask([weak, info]() {
|
||||
auto autoStartUpCallBackStub = weak.promote();
|
||||
if (autoStartUpCallBackStub == nullptr) {
|
||||
HILOG_ERROR("autoStartUpCallBackStub is nullptr.");
|
||||
return;
|
||||
}
|
||||
autoStartUpCallBackStub->OnAutoStartupOff(*info);
|
||||
});
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user