diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index 1e76eaa2de09a1e579ab846595c0ea7c480e8825..24068816149d8bb51050cf42300e1c8e56044b3f 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -52,6 +52,8 @@ group("napi_packages") { "${ability_runtime_napi_path}/feature_ability:featureability_napi", "${ability_runtime_napi_path}/inner/napi_ability_common:napi_ability_common", "${ability_runtime_napi_path}/inner/napi_common:napi_common", + "${ability_runtime_napi_path}/insight_intent/insight_intent:insightintent_napi", + "${ability_runtime_napi_path}/insight_intent/insight_intent_driver:insightintentdriver_napi", "${ability_runtime_napi_path}/insight_intent_context:insightintentcontext_napi", "${ability_runtime_napi_path}/js_child_process:childprocess_napi", "${ability_runtime_napi_path}/js_child_process_manager:childprocessmanager_napi", diff --git a/frameworks/js/napi/inner/napi_common/BUILD.gn b/frameworks/js/napi/inner/napi_common/BUILD.gn index 58f14dbffc2b95f5480358838bf1887358901234..29324cd15e2cb1976d8859757a64b30627706b4c 100644 --- a/frameworks/js/napi/inner/napi_common/BUILD.gn +++ b/frameworks/js/napi/inner/napi_common/BUILD.gn @@ -32,6 +32,8 @@ ohos_shared_library("napi_common") { sources = [ "napi_common_configuration.cpp", + "napi_common_execute_param.cpp", + "napi_common_execute_result.cpp", "napi_common_start_options.cpp", "napi_common_util.cpp", "napi_common_want.cpp", diff --git a/frameworks/js/napi/inner/napi_common/napi_common_execute_param.cpp b/frameworks/js/napi/inner/napi_common/napi_common_execute_param.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d349854f33b7c76724088eb962293ec44d3bbf0a --- /dev/null +++ b/frameworks/js/napi/inner/napi_common/napi_common_execute_param.cpp @@ -0,0 +1,89 @@ +/* + * 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 "napi_common_execute_param.h" + +#include "hilog_wrapper.h" +#include "napi_common_util.h" +#include "napi_common_want.h" + +namespace OHOS { +namespace AbilityRuntime { +using namespace OHOS::AppExecFwk; +bool UnwrapExecuteParam(napi_env env, napi_value param, InsightIntentExecuteParam &executeParam) +{ + if (!IsTypeForNapiValue(env, param, napi_object)) { + HILOG_ERROR("Params is invalid."); + return false; + } + + std::string bundleName {""}; + if (!UnwrapStringByPropertyName(env, param, "bundleName", bundleName)) { + HILOG_ERROR("Wrong argument type bundleName."); + return false; + } + executeParam.bundleName_ = bundleName; + + std::string moduleName {""}; + if (!UnwrapStringByPropertyName(env, param, "moduleName", moduleName)) { + HILOG_ERROR("Wrong argument type moduleName."); + return false; + } + executeParam.moduleName_ = moduleName; + + std::string abilityName {""}; + if (!UnwrapStringByPropertyName(env, param, "abilityName", abilityName)) { + HILOG_ERROR("Wrong argument type abilityName."); + return false; + } + executeParam.abilityName_ = abilityName; + + std::string insightIntentName {""}; + if (!UnwrapStringByPropertyName(env, param, "insightIntentName", insightIntentName)) { + HILOG_ERROR("Wrong argument type insightIntentName."); + return false; + } + executeParam.insightIntentName_ = insightIntentName; + + napi_value napiIntentParam = nullptr; + napi_get_named_property(env, param, "insightIntentParam", &napiIntentParam); + if (napiIntentParam != nullptr) { + HILOG_ERROR("Wrong argument type insightIntentParam."); + return false; + } + + napi_valuetype valueType = napi_undefined; + napi_typeof(env, napiIntentParam, &valueType); + if (valueType != napi_object) { + HILOG_ERROR("Wrong argument type intentParam."); + return false; + } + auto wp = std::make_shared(); + if (!AppExecFwk::UnwrapWantParams(env, napiIntentParam, *wp)) { + HILOG_ERROR("Wrong argument type intentParam."); + return false; + } + executeParam.insightIntentParam_ = wp; + + int32_t executeMode = 0; + if (!UnwrapInt32ByPropertyName(env, param, "executeMode", executeMode)) { + HILOG_ERROR("Wrong argument type executeMode."); + return false; + } + executeParam.executeMode_ = executeMode; + return true; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/frameworks/js/napi/inner/napi_common/napi_common_execute_param.h b/frameworks/js/napi/inner/napi_common/napi_common_execute_param.h new file mode 100644 index 0000000000000000000000000000000000000000..cd99e871946bcc7dd6e2eeac21bcce3ce1e50541 --- /dev/null +++ b/frameworks/js/napi/inner/napi_common/napi_common_execute_param.h @@ -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. + */ + +#ifndef OHOS_ABILITY_RUNTIME_NAPI_EXECUTE_PARAM_H +#define OHOS_ABILITY_RUNTIME_NAPI_EXECUTE_PARAM_H + +#include "napi_common_data.h" +#include "insight_intent_execute_param.h" + +namespace OHOS { +namespace AbilityRuntime { + +bool UnwrapExecuteParam(napi_env env, napi_value param, AppExecFwk::InsightIntentExecuteParam &executeParam); + +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_NAPI_EXECUTE_PARAM_H diff --git a/frameworks/js/napi/inner/napi_common/napi_common_execute_result.cpp b/frameworks/js/napi/inner/napi_common/napi_common_execute_result.cpp new file mode 100644 index 0000000000000000000000000000000000000000..529a9d005b9537425e1738d75f1a53498afb3e23 --- /dev/null +++ b/frameworks/js/napi/inner/napi_common/napi_common_execute_result.cpp @@ -0,0 +1,63 @@ +/* + * 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 "napi_common_execute_result.h" + +#include "hilog_wrapper.h" +#include "insight_intent_execute_result.h" +#include "napi_common_util.h" +#include "napi_common_want.h" +#include "want_params.h" +#include + +namespace OHOS { +namespace AbilityRuntime { +using namespace OHOS::AppExecFwk; +bool UnwrapExecuteResult(napi_env env, napi_value param, InsightIntentExecuteResult &executeResult) +{ + HILOG_DEBUG("called."); + + int32_t code = 0; + if (!UnwrapInt32ByPropertyName(env, param, "code", code)) { + HILOG_ERROR("Intent result must contian a code."); + return false; + } + executeResult.code = code; + + napi_value result = nullptr; + napi_get_named_property(env, param, "result", &result); + if (result != nullptr) { + napi_valuetype valueType = napi_undefined; + napi_typeof(env, result, &valueType); + if (valueType != napi_object) { + HILOG_ERROR("Wrong argument type result."); + return false; + } + auto wp = std::make_shared(); + if (!AppExecFwk::UnwrapWantParams(env, result, *wp)) { + HILOG_ERROR("Wrong argument type result."); + return false; + } + if (!executeResult.CheckResult(wp)) { + HILOG_ERROR("Invalid intent result."); + return false; + } + executeResult.result = wp; + } + + return true; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/frameworks/js/napi/inner/napi_common/napi_common_execute_result.h b/frameworks/js/napi/inner/napi_common/napi_common_execute_result.h new file mode 100644 index 0000000000000000000000000000000000000000..99742382e1265aa37dabfb6c02c1205cc40aab12 --- /dev/null +++ b/frameworks/js/napi/inner/napi_common/napi_common_execute_result.h @@ -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. + */ + +#ifndef OHOS_ABILITY_RUNTIME_NAPI_EXECUTE_RESULT_H +#define OHOS_ABILITY_RUNTIME_NAPI_EXECUTE_RESULT_H + +#include "napi_common_data.h" +#include "insight_intent_execute_result.h" + +namespace OHOS { +namespace AbilityRuntime { + +bool UnwrapExecuteResult(napi_env env, napi_value param, AppExecFwk::InsightIntentExecuteResult &executeResult); + +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_NAPI_EXECUTE_RESULT_H diff --git a/frameworks/js/napi/insight_intent/insight_intent/BUILD.gn b/frameworks/js/napi/insight_intent/insight_intent/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..da5b5c5db4a3807739ee85a383aef58af3b30fba --- /dev/null +++ b/frameworks/js/napi/insight_intent/insight_intent/BUILD.gn @@ -0,0 +1,45 @@ +# 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("insightintent_napi") { + sources = [ + "js_insight_intent.cpp", + "native_module.cpp", + ] + + configs = [ "${ability_runtime_services_path}/common:common_config" ] + + deps = [ + "${ability_runtime_innerkits_path}/runtime:runtime", + "${ability_runtime_napi_path}/inner/napi_common:napi_common", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "hilog:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + ] + + relative_install_dir = "module/app/ability" + + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/frameworks/js/napi/insight_intent/insight_intent/js_insight_intent.cpp b/frameworks/js/napi/insight_intent/insight_intent/js_insight_intent.cpp new file mode 100644 index 0000000000000000000000000000000000000000..10690fac3ebc27222bead4d3d405c46a2374cda6 --- /dev/null +++ b/frameworks/js/napi/insight_intent/insight_intent/js_insight_intent.cpp @@ -0,0 +1,65 @@ +/* + * 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_insight_intent.h" + +#include "hilog_wrapper.h" +#include "js_error_utils.h" +#include "js_runtime_utils.h" +#include "native_engine/native_value.h" + +#include + +namespace OHOS { +namespace AbilityRuntime { +const uint8_t NUMBER_OF_PARAMETERS_ZERO = 0; +const uint8_t NUMBER_OF_PARAMETERS_ONE = 1; +const uint8_t NUMBER_OF_PARAMETERS_TWO = 2; +const uint8_t NUMBER_OF_PARAMETERS_THREE = 3; + +napi_value ExecuteModeInit(napi_env env) +{ + if (env == nullptr) { + HILOG_ERROR("Invalid input parameters"); + return nullptr; + } + napi_value objValue = nullptr; + napi_create_object(env, &objValue); + + napi_set_named_property(env, objValue, "UI_ABILITY_FOREGROUND", + CreateJsValue(env, static_cast(NUMBER_OF_PARAMETERS_ZERO))); + napi_set_named_property(env, objValue, "UI_ABILITY_BACKGROUND", + CreateJsValue(env, static_cast(NUMBER_OF_PARAMETERS_ONE))); + napi_set_named_property(env, objValue, "UI_EXTENSIONABILITY", + CreateJsValue(env, static_cast(NUMBER_OF_PARAMETERS_TWO))); + napi_set_named_property(env, objValue, "SERVICE_EXTENSION_ABILITY", + CreateJsValue(env, static_cast(NUMBER_OF_PARAMETERS_THREE))); + + return objValue; +} + +napi_value JsInsightIntentInit(napi_env env, napi_value exportObj) +{ + HILOG_DEBUG("called"); + if (env == nullptr || exportObj == nullptr) { + HILOG_ERROR("Invalid input parameters"); + return nullptr; + } + + napi_set_named_property(env, exportObj, "ExecuteMode", ExecuteModeInit(env)); + return exportObj; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/frameworks/js/napi/insight_intent/insight_intent/js_insight_intent.h b/frameworks/js/napi/insight_intent/insight_intent/js_insight_intent.h new file mode 100644 index 0000000000000000000000000000000000000000..1a345c3797aa76ae9871ca40a2dd8f0da48ca88d --- /dev/null +++ b/frameworks/js/napi/insight_intent/insight_intent/js_insight_intent.h @@ -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_INSIGHT_INTENT_H +#define OHOS_ABILITY_RUNTIME_JS_INSIGHT_INTENT_H + +#include "native_engine/native_engine.h" + +namespace OHOS { +namespace AbilityRuntime { + +napi_value ExecuteModeInit(napi_env env); +napi_value JsInsightIntentInit(napi_env env, napi_value exportObj); +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_JS_INSIGHT_INTENT_H diff --git a/frameworks/js/napi/insight_intent/insight_intent/native_module.cpp b/frameworks/js/napi/insight_intent/insight_intent/native_module.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3d965d1b3b0b7f99b87c1a9dc58d7f7a2c189b4d --- /dev/null +++ b/frameworks/js/napi/insight_intent/insight_intent/native_module.cpp @@ -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. + */ + +#include "native_engine/native_engine.h" +#include "js_insight_intent.h" + +/* + * The module definition. + */ +static napi_module _module = { + .nm_version = 0, + .nm_modname = "app.ability.insightintent", + .nm_filename = nullptr, + .nm_register_func = OHOS::AbilityRuntime::JsInsightIntentInit, +}; + +/* + * The module registration. + */ +extern "C" __attribute__((constructor)) void NAPI_application_InsightIntent_AutoRegister(void) +{ + napi_module_register(&_module); +} diff --git a/frameworks/js/napi/insight_intent/insight_intent_driver/BUILD.gn b/frameworks/js/napi/insight_intent/insight_intent_driver/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d7c8410cac7ed759a50f1672502659e5b6334f84 --- /dev/null +++ b/frameworks/js/napi/insight_intent/insight_intent_driver/BUILD.gn @@ -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. + +import("//build/ohos.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_shared_library("insightintentdriver_napi") { + sources = [ + "js_insight_intent_driver.cpp", + "js_insight_intent_driver_utils.cpp", + "native_module.cpp", + ] + + configs = [ "${ability_runtime_services_path}/common:common_config" ] + + 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}/ability/native:ability_business_error", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + ] + + relative_install_dir = "module/app/ability" + + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver.cpp b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver.cpp new file mode 100644 index 0000000000000000000000000000000000000000..55f6510e57026565f823849f2af7a39f3f9a92c9 --- /dev/null +++ b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver.cpp @@ -0,0 +1,153 @@ +/* + * 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_insight_intent_driver.h" + +#include "ability_business_error.h" +#include "ability_manager_client.h" +#include "event_handler.h" +#include "event_runner.h" +#include "hilog_wrapper.h" +#include "insight_intent_callback_interface.h" +#include "insight_intent_host_client.h" +#include "insight_intent_execute_result.h" +#include "js_error_utils.h" +#include "js_insight_intent_driver_utils.h" +#include "js_runtime_utils.h" +#include "napi_common_execute_param.h" +#include "napi_common_util.h" +#include "native_engine/native_value.h" + +#include + +namespace OHOS { +namespace AbilityRuntime { +using namespace OHOS::AppExecFwk; +namespace { +constexpr int32_t INDEX_ZERO = 0; +constexpr int32_t INDEX_ONE = 1; +constexpr size_t ARGC_ONE = 1; +} +class JsInsightIntentExecuteCallbackClient : public InsightIntentExecuteCallbackInterface, + public std::enable_shared_from_this { +public: + using InsightIntentExecuteTask = std::function; + explicit JsInsightIntentExecuteCallbackClient(InsightIntentExecuteTask &&task) : task_(std::move(task)) + { + handler_ = std::make_shared(EventRunner::GetMainEventRunner()); + } + + 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); + }); + } + } +private: + InsightIntentExecuteTask task_; + std::shared_ptr handler_ = nullptr; +}; + +class JsInsightIntentDriver { +public: + JsInsightIntentDriver() = default; + ~JsInsightIntentDriver() = default; + + static void Finalizer(napi_env env, void *data, void *hint) + { + HILOG_INFO("JsInsightIntentDriver::Finalizer is called"); + std::unique_ptr(static_cast(data)); + } + + static napi_value Execute(napi_env env, napi_callback_info info) + { + GET_NAPI_INFO_AND_CALL(env, info, JsInsightIntentDriver, OnExecute); + } + +private: + napi_value OnExecute(napi_env env, NapiCallbackInfo& info) + { + HILOG_DEBUG("called"); + if (info.argc < ARGC_ONE) { + HILOG_ERROR("Params not match"); + ThrowTooFewParametersError(env); + return CreateJsUndefined(env); + } + + InsightIntentExecuteParam param; + if (!UnwrapExecuteParam(env, info.argv[INDEX_ZERO], param)) { + HILOG_ERROR("CheckOnOffType, Parse on off type failed"); + ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return CreateJsUndefined(env); + } + + napi_value lastParam = (info.argc == 1) ? nullptr : info.argv[INDEX_ONE]; + napi_value result = nullptr; + + std::unique_ptr uasyncTask = CreateAsyncTaskWithLastParam( + env, lastParam, nullptr, nullptr, &result); + std::shared_ptr 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(std::move(task)); + uint64_t key = InsightIntentHostClient::GetInstance()->AddInsightIntentExecute(client); + auto err = AbilityManagerClient::GetInstance()->ExecuteIntent(key, + InsightIntentHostClient::GetInstance(), param); + if (err != 0) { + asyncTask->Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(err))); + InsightIntentHostClient::GetInstance()->RemoveInsightIntentExecute(key); + } + return result; + } +}; + +napi_value JsInsightIntentDriverInit(napi_env env, napi_value exportObj) +{ + HILOG_DEBUG("JsInsightIntentDriverInit is called"); + if (env == nullptr || exportObj == nullptr) { + HILOG_ERROR("Invalid input parameters"); + return nullptr; + } + + std::unique_ptr jsIntentDriver = std::make_unique(); + napi_wrap(env, exportObj, jsIntentDriver.release(), JsInsightIntentDriver::Finalizer, nullptr, nullptr); + + const char *moduleName = "JsInsightIntentDriver"; + BindNativeFunction(env, exportObj, "execute", moduleName, JsInsightIntentDriver::Execute); + return CreateJsUndefined(env); +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver.h b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver.h new file mode 100644 index 0000000000000000000000000000000000000000..2696ec1e91288b3dca16cdd9214011b62eab2a8c --- /dev/null +++ b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver.h @@ -0,0 +1,25 @@ +/* + * 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_INSIGHT_INTENT_DRIVER_H +#define OHOS_ABILITY_RUNTIME_JS_INSIGHT_INTENT_DRIVER_H + +#include "native_engine/native_engine.h" + +namespace OHOS { +namespace AbilityRuntime { +napi_value JsInsightIntentDriverInit(napi_env env, napi_value exportObj); +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_JS_INSIGHT_INTENT_DRIVER_H diff --git a/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.cpp b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4d4e29a9c68e2b4445c6459a2c4a31b19e0b3ef9 --- /dev/null +++ b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.cpp @@ -0,0 +1,42 @@ +/* + * 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_insight_intent_driver_utils.h" + +#include + +#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" + +namespace OHOS { +namespace AbilityRuntime { +napi_value CreateJsExecuteResult(napi_env env, const AppExecFwk::InsightIntentExecuteResult &result) +{ + napi_value objValue = nullptr; + napi_create_object(env, &objValue); + + napi_set_named_property(env, objValue, "code", CreateJsValue(env, result.code)); + if (result.result != nullptr) { + napi_set_named_property(env, objValue, "result", + OHOS::AppExecFwk::CreateJsWantParams(env, *result.result)); + } + return objValue; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.h b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..80cd8016fce44caf0dc7535853779ef16131a01d --- /dev/null +++ b/frameworks/js/napi/insight_intent/insight_intent_driver/js_insight_intent_driver_utils.h @@ -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_INSIGHT_INTENT_DRIVER_UTILS_H +#define OHOS_ABILITY_RUNTIME_JS_INSIGHT_INTENT_DRIVER_UTILS_H + +#include "insight_intent_execute_result.h" +#include "native_engine/native_engine.h" + +namespace OHOS { +namespace AbilityRuntime { +napi_value CreateJsExecuteResult(napi_env env, const AppExecFwk::InsightIntentExecuteResult &result); +napi_value CreateJsWantParams(napi_env env, const AAFwk::WantParams &wantParams); +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_JS_INSIGHT_INTENT_DRIVER_UTILS_H diff --git a/frameworks/js/napi/insight_intent/insight_intent_driver/native_module.cpp b/frameworks/js/napi/insight_intent/insight_intent_driver/native_module.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ffc487932315ca43896b1f5a1e5222bff5a010cc --- /dev/null +++ b/frameworks/js/napi/insight_intent/insight_intent_driver/native_module.cpp @@ -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. + */ + +#include "native_engine/native_engine.h" +#include "js_insight_intent_driver.h" + +/* + * The module definition. + */ +static napi_module _module = { + .nm_version = 0, + .nm_modname = "app.ability.insightIntentDriver", + .nm_filename = nullptr, + .nm_register_func = OHOS::AbilityRuntime::JsInsightIntentDriverInit, +}; + +/* + * The module registration. + */ +extern "C" __attribute__((constructor)) void NAPI_application_IntentDriver_AutoRegister(void) +{ + napi_module_register(&_module); +} diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index ca1d9bbd6f956ee5bc4d0df8addc167932a4ab7b..944ef8df58412a2ca02fffe27c5f75b213c08510 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -217,6 +217,7 @@ ohos_shared_library("abilitykit_native") { "${ability_runtime_native_path}/ability/native/distributed_ability_runtime/distributed_client.cpp", "${ability_runtime_native_path}/ability/native/free_install_observer_proxy.cpp", "${ability_runtime_native_path}/ability/native/free_install_observer_stub.cpp", + "${ability_runtime_native_path}/ability/native/insight_intent_host_client.cpp", "${ability_runtime_native_path}/ability/native/js_free_install_observer.cpp", "${ability_runtime_native_path}/ability/native/new_ability_impl.cpp", "${ability_runtime_native_path}/ability/native/recovery/ability_recovery.cpp", diff --git a/frameworks/native/ability/native/insight_intent_host_client.cpp b/frameworks/native/ability/native/insight_intent_host_client.cpp new file mode 100644 index 0000000000000000000000000000000000000000..48a39ddf03f5d35dbe4756564d32e7a80513f825 --- /dev/null +++ b/frameworks/native/ability/native/insight_intent_host_client.cpp @@ -0,0 +1,72 @@ +/* + * 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 "insight_intent_host_client.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AbilityRuntime { +sptr InsightIntentHostClient::instance_ = nullptr; +std::mutex InsightIntentHostClient::instanceMutex_; + +sptr InsightIntentHostClient::GetInstance() +{ + if (instance_ == nullptr) { + std::lock_guard lock_l(instanceMutex_); + if (instance_ == nullptr) { + instance_ = new (std::nothrow) InsightIntentHostClient(); + if (instance_ == nullptr) { + HILOG_ERROR("failed to create InsightIntentHostClient."); + } + } + } + return instance_; +} + +uint64_t InsightIntentHostClient::AddInsightIntentExecute( + const std::shared_ptr &callback) +{ + HILOG_DEBUG("called."); + std::lock_guard lock(insightIntentExecutebackMutex_); + callbackMap_.emplace(++key_, callback); + return key_; +} + +void InsightIntentHostClient::RemoveInsightIntentExecute(uint64_t key) +{ + HILOG_DEBUG("called."); + std::lock_guard lock(insightIntentExecutebackMutex_); + auto iter = callbackMap_.find(key); + if (iter != callbackMap_.end()) { + callbackMap_.erase(key); + } +} + +void InsightIntentHostClient::OnExecuteDone(uint64_t key, int32_t resultCode, + AppExecFwk::InsightIntentExecuteResult &executeResult) +{ + HILOG_DEBUG("called."); + + std::lock_guard lock(insightIntentExecutebackMutex_); + auto iter = callbackMap_.find(key); + if (iter == callbackMap_.end()) { + HILOG_INFO("InsightIntent execute callback not found"); + } else { + std::shared_ptr &callback = iter->second; + callback->ProcessInsightIntentExecute(resultCode, executeResult); + callbackMap_.erase(key); + } +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/ability_manager/BUILD.gn b/interfaces/inner_api/ability_manager/BUILD.gn index 58272a6d3f05af372df6e86348b6f33c8de9e43f..05113322c183bcd4192a8e38527412d778450dd8 100644 --- a/interfaces/inner_api/ability_manager/BUILD.gn +++ b/interfaces/inner_api/ability_manager/BUILD.gn @@ -78,6 +78,10 @@ ohos_shared_library("ability_manager") { "${ability_runtime_services_path}/abilitymgr/src/caller_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/extension_running_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/image_info.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_callback_proxy.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_callback_stub.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_param.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_result.cpp", "${ability_runtime_services_path}/abilitymgr/src/launch_param.cpp", "${ability_runtime_services_path}/abilitymgr/src/lifecycle_state_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/mission_listener_proxy.cpp", diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_client.h b/interfaces/inner_api/ability_manager/include/ability_manager_client.h index 7a6400198f5694047eaa9689ba14b9bb6306bfb8..49d1aedc63a96b69dc04f7b98ecfb04db6086d25 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -1310,6 +1310,16 @@ public: */ bool IsAbilityControllerStart(const Want &want); + /** + * @brief Execute intent. + * @param key The key of intent executing client. + * @param callerToken Caller ability token. + * @param param The Intent execute param. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode ExecuteIntent(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m); + private: class AbilityMgrDeathRecipient : public IRemoteObject::DeathRecipient { public: diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index f5e040cfe13ba090674cc9f32be065df49582766..0103d2a6b36bd6e1940bb46f1a087cd5d5c84215 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -34,6 +34,8 @@ #include "iability_manager_collaborator.h" #include "iacquire_share_data_callback_interface.h" #include "icomponent_interception.h" +#include "insight_intent_execute_param.h" +#include "insight_intent_execute_result.h" #include "iprepare_terminate_callback_interface.h" #include "mission_info.h" #include "mission_listener_interface.h" @@ -59,6 +61,7 @@ namespace OHOS { namespace AAFwk { using AutoStartupInfo = AbilityRuntime::AutoStartupInfo; +using InsightIntentExecuteParam = AppExecFwk::InsightIntentExecuteParam; constexpr const char* ABILITY_MANAGER_SERVICE_NAME = "AbilityManagerService"; const int DEFAULT_INVAL_VALUE = -1; const int DELAY_LOCAL_FREE_INSTALL_TIMEOUT = 40000; @@ -1296,6 +1299,16 @@ public: */ virtual int32_t DetachAppDebug(const std::string &bundleName) = 0; + /** + * @brief Execute intent. + * @param key The key of intent executing client. + * @param callerToken Caller ability token. + * @param param The Intent execute param. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t ExecuteIntent(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m) = 0; + /** * @brief Check if ability controller can start. * @param want The want of ability to start. diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h index 5c5819812c5cb961662435b4bfdea7dd355a8807..85ea6a88c460fd022033e7355dfafe68b4714c0a 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h @@ -224,6 +224,9 @@ enum class AbilityManagerInterfaceCode { // Deatch app debug (71) DETACH_APP_DEBUG = 71, + // Execute intent (72) + EXECUTE_INTENT = 72, + // ipc id 1001-2000 for DMS // ipc id for starting ability (1001) START_ABILITY = 1001, diff --git a/interfaces/inner_api/ability_manager/include/insight_intent_execute_callback_interface.h b/interfaces/inner_api/ability_manager/include/insight_intent_execute_callback_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..21fbc468b37da3b91c4017ab3fd6e8a17cc22615 --- /dev/null +++ b/interfaces/inner_api/ability_manager/include/insight_intent_execute_callback_interface.h @@ -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_INSIGHT_INTENT_EXECUTE_CALLBACK_INTERFACE_H +#define OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_EXECUTE_CALLBACK_INTERFACE_H + +#include "insight_intent_execute_result.h" +#include "iremote_broker.h" + +namespace OHOS { +namespace AAFwk { +/** + * @class IInsightIntentExecuteCallback + * IInsightIntentExecuteCallback is used to notify caller ability that intent execute is complete. + */ +class IInsightIntentExecuteCallback : public OHOS::IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.AAFwk.IntentExecuteCallback"); + + /** + * OnExecuteDone, AbilityMs notify caller ability the result of intent execute. + * + * @param key, the execute callback key. + * @param resultCode, ERR_OK on success, others on failure. + * @param executeResult, the execute result. + */ + virtual void OnExecuteDone(uint64_t key, int32_t resultCode, + AppExecFwk::InsightIntentExecuteResult &executeResult) = 0; + + enum { + // ipc id for OnExecuteDone + ON_INSIGHT_INTENT_EXECUTE_DONE = 1, + }; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_EXECUTE_CALLBACK_INTERFACE_H diff --git a/interfaces/inner_api/ability_manager/include/insight_intent_execute_callback_proxy.h b/interfaces/inner_api/ability_manager/include/insight_intent_execute_callback_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..f491e7b3576449d13f1c5364b1f444e3967fe62b --- /dev/null +++ b/interfaces/inner_api/ability_manager/include/insight_intent_execute_callback_proxy.h @@ -0,0 +1,46 @@ +/* + * 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_INSIGHT_INTENT_EXECUTE_CALLBACK_PROXY_H +#define OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_EXECUTE_CALLBACK_PROXY_H + +#include "iremote_proxy.h" +#include "insight_intent_execute_callback_interface.h" + +namespace OHOS { +namespace AAFwk { +class InsightIntentExecuteCallbackProxy : public IRemoteProxy { +public: + explicit InsightIntentExecuteCallbackProxy + (const sptr &impl) : IRemoteProxy(impl) {} + + virtual ~InsightIntentExecuteCallbackProxy() {} + + /** + * OnExecuteDone, AbilityMs notify caller ability the result of intent execute. + * + * @param key, the execute callback key. + * @param resultCode, ERR_OK on success, others on failure. + * @param executeResult, the execute result. + */ + void OnExecuteDone(uint64_t key, int32_t resultCode, + AppExecFwk::InsightIntentExecuteResult &executeResult) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_EXECUTE_CALLBACK_PROXY_H \ No newline at end of file diff --git a/interfaces/inner_api/ability_manager/include/insight_intent_execute_callback_stub.h b/interfaces/inner_api/ability_manager/include/insight_intent_execute_callback_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..9c6e7d2768c5390360fb4d34fcd24fef7d0d6e92 --- /dev/null +++ b/interfaces/inner_api/ability_manager/include/insight_intent_execute_callback_stub.h @@ -0,0 +1,41 @@ +/* + * 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_INSIGHT_INTENT_EXECUTE_CALLBACK_STUB_H +#define OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_EXECUTE_CALLBACK_STUB_H + +#include "event_handler.h" +#include "insight_intent_execute_callback_interface.h" +#include + +namespace OHOS { +namespace AAFwk { +class InsightIntentExecuteCallbackStub : public IRemoteStub { +public: + InsightIntentExecuteCallbackStub(); + ~InsightIntentExecuteCallbackStub(); + int32_t OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + int32_t OnExecuteDoneInner(MessageParcel &data, MessageParcel &reply); + + std::shared_ptr handler_; + using StubFunc = int (InsightIntentExecuteCallbackStub::*)(MessageParcel &data, MessageParcel &reply); + std::map requestFuncMap_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_EXECUTE_CALLBACK_STUB_H \ No newline at end of file diff --git a/interfaces/inner_api/ability_manager/include/insight_intent_execute_param.h b/interfaces/inner_api/ability_manager/include/insight_intent_execute_param.h new file mode 100644 index 0000000000000000000000000000000000000000..4cf68eaa512abc2a03d2ba8bee6eab2ccfc15c79 --- /dev/null +++ b/interfaces/inner_api/ability_manager/include/insight_intent_execute_param.h @@ -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_INTENT_EXECUTE_PARAM_H +#define OHOS_ABILITY_RUNTIME_INTENT_EXECUTE_PARAM_H + +#include +#include + +#include "parcel.h" +#include "want_params.h" +namespace OHOS { +namespace AppExecFwk { +using WantParams = OHOS::AAFwk::WantParams; +/** + * @enum ExecuteMode + * ExecuteMode defines the supported execute mode. + */ +enum ExecuteMode { + UIABLITY_FOREGROUND = 0, + UIABLITY_BACKGROUND, + UIEXTENSIONABLITY +}; + +class InsightIntentExecuteParam : public Parcelable { +public: + InsightIntentExecuteParam() = default; + ~InsightIntentExecuteParam() = default; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static InsightIntentExecuteParam *Unmarshalling(Parcel &parcel); + + std::string bundleName_; + std::string moduleName_; + std::string abilityName_; + std::string insightIntentName_; + std::shared_ptr insightIntentParam_; + int32_t executeMode_ = -1; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_INTENT_EXECUTE_PARAM_H diff --git a/interfaces/inner_api/ability_manager/include/insight_intent_execute_result.h b/interfaces/inner_api/ability_manager/include/insight_intent_execute_result.h new file mode 100644 index 0000000000000000000000000000000000000000..12553c9ab93193dc817e9d54de2a2a3fb1f8af62 --- /dev/null +++ b/interfaces/inner_api/ability_manager/include/insight_intent_execute_result.h @@ -0,0 +1,42 @@ +/* + * 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_INSIGHT_INTENT_EXECUTE_RESULT_H +#define OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_EXECUTE_RESULT_H + +#include "parcel.h" +#include "want_params.h" + +namespace OHOS { +namespace AppExecFwk { +using WantParams = OHOS::AAFwk::WantParams; +/** + * @struct InsightIntentExecuteResult + * InsightIntentExecuteResult is used to save information about execute result. + */ +struct InsightIntentExecuteResult : public Parcelable { +public: + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static InsightIntentExecuteResult *Unmarshalling(Parcel &parcel); + // Check result returned by intent executor + static bool CheckResult(std::shared_ptr result); + + int32_t code = 0; + std::shared_ptr result = nullptr; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_EXECUTE_RESULT_H diff --git a/interfaces/kits/native/ability/native/insight_intent_callback_interface.h b/interfaces/kits/native/ability/native/insight_intent_callback_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..48bc82d39589429aa65808afb4e1facbeee71d3a --- /dev/null +++ b/interfaces/kits/native/ability/native/insight_intent_callback_interface.h @@ -0,0 +1,34 @@ +/* + * 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_INSIGHT_INTENT_CALLBACK_INTERFACE_H +#define OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_CALLBACK_INTERFACE_H + +#include "insight_intent_execute_result.h" + +namespace OHOS { +namespace AbilityRuntime { + +class InsightIntentExecuteCallbackInterface { +public: +/** + * @brief Process the InsightIntent execute. + * @param resultCode, ERR_OK on success, others on failure. + * @param executeResult, the execute result. + */ +virtual void ProcessInsightIntentExecute(int32_t resultCode, AppExecFwk::InsightIntentExecuteResult executeResult) = 0; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_CALLBACK_INTERFACE_H diff --git a/interfaces/kits/native/ability/native/insight_intent_host_client.h b/interfaces/kits/native/ability/native/insight_intent_host_client.h new file mode 100644 index 0000000000000000000000000000000000000000..33193250c3b248940fd1b43b377e0150f91e5cf6 --- /dev/null +++ b/interfaces/kits/native/ability/native/insight_intent_host_client.h @@ -0,0 +1,70 @@ +/* + * 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_INSIGHT_INTENT_HOST_CLIENT_H +#define OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_HOST_CLIENT_H + +#include +#include +#include +#include "insight_intent_callback_interface.h" +#include "insight_intent_execute_callback_stub.h" + +namespace OHOS { +namespace AbilityRuntime { +class InsightIntentHostClient : public AAFwk::InsightIntentExecuteCallbackStub { +public: + InsightIntentHostClient() = default; + virtual ~InsightIntentHostClient() = default; + + /** + * @brief Get InsightIntentHostClient instance. + * @return InsightIntentHostClient instance. + */ + static sptr GetInstance(); + + /** + * @brief Add InsightIntent host. + * @param callback the host of the InsightIntent executing. + * @return Returns the execute callback key. + */ + uint64_t AddInsightIntentExecute(const std::shared_ptr &callback); + + /** + * @brief Remove InsightIntent host. + * @param key, the execute callback key. + */ + void RemoveInsightIntentExecute(uint64_t key); + + /** + * @brief Indicates that the InsightIntent executing is complete + * @param key, the execute callback key. + * @param resultCode, ERR_OK on success, others on failure. + * @param executeResult, the execute result. + */ + void OnExecuteDone(uint64_t key, int32_t resultCode, + AppExecFwk::InsightIntentExecuteResult &executeResult) override; + +private: + static std::mutex instanceMutex_; + uint64_t key_ = 0; + static sptr instance_; + mutable std::mutex insightIntentExecutebackMutex_; + std::map> callbackMap_; + DISALLOW_COPY_AND_MOVE(InsightIntentHostClient); +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_HOST_CLIENT_H \ No newline at end of file diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index fbd1b9a41d9f74cee06fb299938575eec6ec0fe7..c125099d5af08065b22d55fd02bf3c301417f55e 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -103,6 +103,8 @@ abilityms_files = [ "src/ability_auto_startup_data_manager.cpp", "src/ability_auto_startup_service.cpp", "src/auto_startup_info.cpp", + "src/insight_intent_execute_param.cpp", + "src/insight_intent_execute_result.cpp", ] if (ability_runtime_graphics) { diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 5ffea34d7f092f697c410152b272b861de0c81aa..3e8a72e5ec978a49c4144d3f1ecefd2a6c8fd8b1 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -1035,6 +1035,16 @@ public: */ int32_t DetachAppDebug(const std::string &bundleName) override; + /** + * @brief Execute intent. + * @param key The key of intent executing client. + * @param callerToken Caller ability token. + * @param param The Intent execute param. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t ExecuteIntent(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m) override; + /** * @brief Check if ability controller can start. * @param want The want of ability to start. diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index b242e60d656ed97e5cc7b3705e2d5623b379f52a..9e2f0e6f89a25dc3057fbea8764e080630d28ab4 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1344,6 +1344,16 @@ public: */ int32_t DetachAppDebug(const std::string &bundleName) override; + /** + * @brief Execute intent. + * @param key The key of intent executing client. + * @param callerToken Caller ability token. + * @param param The Intent execute param. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t ExecuteIntent(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m) override; + /** * @brief Check if ability controller can start. * @param want The want of ability to start. diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index 1795e86c4a74205fe96b942ac3965b9e51165d09..644d50cf96b4222bde8bdf5287e9cc7a86ec6676 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -264,6 +264,7 @@ private: int32_t UnregisterAppDebugListenerInner(MessageParcel &data, MessageParcel &reply); int32_t AttachAppDebugInner(MessageParcel &data, MessageParcel &reply); int32_t DetachAppDebugInner(MessageParcel &data, MessageParcel &reply); + int32_t ExecuteIntentInner(MessageParcel &data, MessageParcel &reply); int32_t IsAbilityControllerStartInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 90f2ff8c483a877a5c6c5553bd2bfb7541b328ba..035efce95fb24a1faf782a4b53f0646873db1b49 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -1608,6 +1608,15 @@ ErrCode AbilityManagerClient::DetachAppDebug(const std::string &bundleName) return abms->DetachAppDebug(bundleName); } +ErrCode AbilityManagerClient::ExecuteIntent(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m) +{ + HILOG_DEBUG("Called."); + auto abms = GetAbilityManager(); + CHECK_POINTER_RETURN_NOT_CONNECTED(abms); + return abms->ExecuteIntent(key, callerToken, param); +} + bool AbilityManagerClient::IsAbilityControllerStart(const Want &want) { HILOG_DEBUG("call"); diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 7704ea25ee329cb5403af4c84b12a8db16c06100..36970217fc1bd649f1e2c75c541506dba29ce513 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -4489,6 +4489,42 @@ int32_t AbilityManagerProxy::DetachAppDebug(const std::string &bundleName) return reply.ReadInt32(); } +int32_t AbilityManagerProxy::ExecuteIntent(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m) +{ + HILOG_DEBUG("Called."); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("Write interface token failed."); + return INNER_ERR; + } + + if (!data.WriteUint64(key)) { + HILOG_ERROR("Write key failed."); + return INNER_ERR; + } + + if (!data.WriteRemoteObject(callerToken)) { + HILOG_ERROR("failed to write callerToken."); + return INNER_ERR; + } + + if (!data.WriteParcelable(¶m)) { + HILOG_ERROR("Write param failed."); + return INNER_ERR; + } + + int32_t error = SendRequest(AbilityManagerInterfaceCode::EXECUTE_INTENT, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request failed, err: %{public}d", error); + return error; + } + + return reply.ReadInt32(); +} + bool AbilityManagerProxy::IsAbilityControllerStart(const Want &want) { MessageParcel data; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index e63787eb989271c2b730612454391abdb3962fe2..a2456aea839ccf5777e3172e845f50f378948c63 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -49,6 +49,7 @@ #include "hitrace_meter.h" #include "if_system_ability_manager.h" #include "in_process_call_wrapper.h" +#include "insight_intent_execute_callback_proxy.h" #include "ipc_skeleton.h" #include "ipc_types.h" #include "iservice_registry.h" @@ -8653,6 +8654,13 @@ int32_t AbilityManagerService::DetachAppDebug(const std::string &bundleName) return DelayedSingleton::GetInstance()->DetachAppDebug(bundleName); } +int32_t AbilityManagerService::ExecuteIntent(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m) +{ + HILOG_DEBUG("Called."); + return ERR_OK; +} + bool AbilityManagerService::IsAbilityControllerStart(const Want &want) { auto callingUid = IPCSkeleton::GetCallingUid(); diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 36f170987239e2079ffe1f92a251e817e3c54171..039e6a22f5666f15f9b82626f4d93028ac58f2c8 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -161,6 +161,8 @@ void AbilityManagerStub::FirstStepInit() &AbilityManagerStub::DetachAppDebugInner; requestFuncMap_[static_cast(AbilityManagerInterfaceCode::IS_ABILITY_CONTROLLER_START)] = &AbilityManagerStub::IsAbilityControllerStartInner; + requestFuncMap_[static_cast(AbilityManagerInterfaceCode::EXECUTE_INTENT)] = + &AbilityManagerStub::ExecuteIntentInner; } void AbilityManagerStub::SecondStepInit() @@ -2794,6 +2796,27 @@ int32_t AbilityManagerStub::IsAbilityControllerStartInner(MessageParcel &data, M return NO_ERROR; } +int32_t AbilityManagerStub::ExecuteIntentInner(MessageParcel &data, MessageParcel &reply) +{ + uint64_t key = data.ReadUint64(); + sptr callerToken = data.ReadRemoteObject(); + if (callerToken == nullptr) { + HILOG_ERROR("failed to get remote object."); + return ERR_INVALID_VALUE; + } + std::unique_ptr param(data.ReadParcelable()); + if (param == nullptr) { + HILOG_ERROR("param is nullptr"); + return ERR_INVALID_VALUE; + } + auto result = ExecuteIntent(key, callerToken, *param); + if (result != NO_ERROR) { + HILOG_ERROR("ExecuteIntent is failed"); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int32_t AbilityManagerStub::StartAbilityByInsightIntentInner(MessageParcel &data, MessageParcel &reply) { std::unique_ptr want(data.ReadParcelable()); diff --git a/services/abilitymgr/src/insight_intent_execute_callback_proxy.cpp b/services/abilitymgr/src/insight_intent_execute_callback_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c93ee22124529829eb7c936fdd65aec64c27a542 --- /dev/null +++ b/services/abilitymgr/src/insight_intent_execute_callback_proxy.cpp @@ -0,0 +1,59 @@ +/* + * 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 "ability_manager_errors.h" +#include "insight_intent_execute_callback_proxy.h" +#include "hilog_wrapper.h" +#include "iremote_object.h" +#include "message_parcel.h" + +namespace OHOS { +namespace AAFwk { +void InsightIntentExecuteCallbackProxy::OnExecuteDone(uint64_t key, int32_t resultCode, + AppExecFwk::InsightIntentExecuteResult &executeResult) +{ + HILOG_DEBUG("call"); + MessageParcel data; + if (!data.WriteInterfaceToken(IInsightIntentExecuteCallback::GetDescriptor())) { + HILOG_ERROR("Write interface token failed."); + return; + } + if (!data.WriteUint64(key)) { + HILOG_ERROR("key write failed."); + return; + } + if (!data.WriteInt32(resultCode)) { + HILOG_ERROR("resultCode write failed."); + return; + } + if (!data.WriteParcelable(&executeResult)) { + HILOG_ERROR("executeResult write failed."); + return; + } + sptr remote = Remote(); + if (remote == nullptr) { + HILOG_ERROR("Remote() is NULL"); + return; + } + + MessageParcel reply; + MessageOption option; + int error = remote->SendRequest(ON_INSIGHT_INTENT_EXECUTE_DONE, data, reply, option); + if (error != ERR_OK) { + HILOG_ERROR("SendRequest fail, error: %{public}d", error); + } +} +} // namespace AAFwk +} // namespace OHOS diff --git a/services/abilitymgr/src/insight_intent_execute_callback_stub.cpp b/services/abilitymgr/src/insight_intent_execute_callback_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cbdd85dc733d537c748eef4c1e4d0669f1857ab6 --- /dev/null +++ b/services/abilitymgr/src/insight_intent_execute_callback_stub.cpp @@ -0,0 +1,68 @@ +/* + * 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 "insight_intent_execute_callback_stub.h" +#include "insight_intent_host_client.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AAFwk { + +InsightIntentExecuteCallbackStub::InsightIntentExecuteCallbackStub() +{ + requestFuncMap_[ON_INSIGHT_INTENT_EXECUTE_DONE] = &InsightIntentExecuteCallbackStub::OnExecuteDoneInner; +} + +InsightIntentExecuteCallbackStub::~InsightIntentExecuteCallbackStub() +{ + HILOG_DEBUG("call"); + requestFuncMap_.clear(); +} + +int32_t InsightIntentExecuteCallbackStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + if (data.ReadInterfaceToken() != IInsightIntentExecuteCallback::GetDescriptor()) { + HILOG_ERROR("InterfaceToken not equal IInsightIntentExecuteCallback's descriptor."); + return ERR_INVALID_STATE; + } + + auto itFunc = requestFuncMap_.find(code); + if (itFunc != requestFuncMap_.end()) { + auto requestFunc = itFunc->second; + if (requestFunc != nullptr) { + return (this->*requestFunc)(data, reply); + } + } + HILOG_WARN("default case, need check."); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +int32_t InsightIntentExecuteCallbackStub::OnExecuteDoneInner(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("call"); + uint64_t key = data.ReadUint64(); + int32_t resultCode = data.ReadInt32(); + std::shared_ptr executeResult( + data.ReadParcelable()); + if (executeResult == nullptr) { + HILOG_ERROR("executeResult is nullptr"); + return ERR_INVALID_VALUE; + } + OnExecuteDone(key, resultCode, *executeResult); + return ERR_OK; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/services/abilitymgr/src/insight_intent_execute_param.cpp b/services/abilitymgr/src/insight_intent_execute_param.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b621bf4167574222cd9cdbd36364239811e246a6 --- /dev/null +++ b/services/abilitymgr/src/insight_intent_execute_param.cpp @@ -0,0 +1,61 @@ +/* + * 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 "insight_intent_execute_param.h" + +namespace OHOS { +namespace AppExecFwk { +using WantParams = OHOS::AAFwk::WantParams; +bool InsightIntentExecuteParam::ReadFromParcel(Parcel &parcel) +{ + bundleName_ = Str16ToStr8(parcel.ReadString16()); + moduleName_ = Str16ToStr8(parcel.ReadString16()); + abilityName_ = Str16ToStr8(parcel.ReadString16()); + insightIntentName_ = Str16ToStr8(parcel.ReadString16()); + std::shared_ptr wantParams(parcel.ReadParcelable()); + if (wantParams == nullptr) { + return false; + } + insightIntentParam_ = wantParams; + executeMode_ = parcel.ReadInt32(); + return true; +} + +InsightIntentExecuteParam *InsightIntentExecuteParam::Unmarshalling(Parcel &parcel) +{ + InsightIntentExecuteParam *param = new (std::nothrow) InsightIntentExecuteParam(); + if (param == nullptr) { + return nullptr; + } + + if (!param->ReadFromParcel(parcel)) { + delete param; + param = nullptr; + } + return param; +} + +bool InsightIntentExecuteParam::Marshalling(Parcel &parcel) const +{ + parcel.WriteString16(Str8ToStr16(bundleName_)); + parcel.WriteString16(Str8ToStr16(moduleName_)); + parcel.WriteString16(Str8ToStr16(abilityName_)); + parcel.WriteString16(Str8ToStr16(insightIntentName_)); + parcel.WriteParcelable(insightIntentParam_.get()); + parcel.WriteInt32(executeMode_); + return true; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/services/abilitymgr/src/insight_intent_execute_result.cpp b/services/abilitymgr/src/insight_intent_execute_result.cpp new file mode 100644 index 0000000000000000000000000000000000000000..474df54c9d0fb8b02a555db2a3f2a5e3cccbbac3 --- /dev/null +++ b/services/abilitymgr/src/insight_intent_execute_result.cpp @@ -0,0 +1,58 @@ +/* + * 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 "insight_intent_execute_result.h" + +namespace OHOS { +namespace AppExecFwk { +using WantParams = OHOS::AAFwk::WantParams; +bool InsightIntentExecuteResult::ReadFromParcel(Parcel &parcel) +{ + code = parcel.ReadInt32(); + result = std::shared_ptr(parcel.ReadParcelable()); + return true; +} + +bool InsightIntentExecuteResult::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteInt32(code)) { + return false; + } + if (!parcel.WriteParcelable(result.get())) { + return false; + } + return true; +} + +InsightIntentExecuteResult *InsightIntentExecuteResult::Unmarshalling(Parcel &parcel) +{ + auto res = new (std::nothrow) InsightIntentExecuteResult(); + if (res == nullptr) { + return nullptr; + } + + if (!res->ReadFromParcel(parcel)) { + delete res; + res = nullptr; + } + return res; +} + +bool InsightIntentExecuteResult::CheckResult(std::shared_ptr result) +{ + return true; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h index 2779315ca00a8f4891ef831db22430b770be8263..752fc8ce764bf4928d69892c14b5a008681f9340 100644 --- a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h @@ -321,6 +321,8 @@ public: MOCK_METHOD1(UnregisterAppDebugListener, int32_t(const sptr &listener)); MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName)); + MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m)); sptr abilityScheduler_ = nullptr; // kit interface used to schedule ability life Want want_; diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h index 9e4b539ce13130e68bcf70fe24a9ccd7d76d6a8a..1b3ce0cb41b3132ab65573937d6167e6f192e5fc 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h @@ -289,6 +289,8 @@ public: MOCK_METHOD1(UnregisterAppDebugListener, int32_t(const sptr &listener)); MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName)); + MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m)); enum class RequestCode { E_STATE_INITIAL = 0, diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h index a694ae215c244c5a553bc1409aab944c02119bcd..31afaa4f2ae86f00699bc11df90aabced7f5ed8b 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h @@ -176,6 +176,8 @@ public: MOCK_METHOD1(UnregisterAppDebugListener, int32_t(const sptr &listener)); MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName)); + MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m)); public: std::string powerState_; static bool finishFlag_; @@ -338,6 +340,8 @@ public: MOCK_METHOD1(UnregisterAppDebugListener, int32_t(const sptr &listener)); MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName)); + MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m)); public: std::string powerState_; static bool finishFlag_; diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h index 5f00122a005f93fc351e6583e5fdaf0cb1632eab..b3822553f99ab990b0443d194b5cc0078a7060a1 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h @@ -128,6 +128,8 @@ public: MOCK_METHOD1(UnregisterAppDebugListener, int32_t(const sptr &listener)); MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName)); + MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m)); private: bool DumpStateCalled_ = false; diff --git a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h index b523c29e55626d7eee7f57e60e7b05187983b28f..7d27d095793811f133f27f21f0eb8956341ebddd 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h @@ -278,6 +278,8 @@ public: MOCK_METHOD1(UnregisterAppDebugListener, int32_t(const sptr &listener)); MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName)); + MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m)); AbilityLifeCycleState curstate_ = AbilityLifeCycleState::ABILITY_STATE_INITIAL; sptr abilityScheduler_; // kit interface used to schedule ability life diff --git a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h index eb2759894fe490462456177b36bb83ab08d4495b..306222254b7b92949bad36cd063ecc61ae8c45b7 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h @@ -293,6 +293,8 @@ public: MOCK_METHOD1(UnregisterAppDebugListener, int32_t(const sptr &listener)); MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName)); + MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m)); sptr abilityScheduler_ = nullptr; // kit interface used to schedule ability life Want want_; diff --git a/test/moduletest/mock/include/mock_ability_mgr_service.h b/test/moduletest/mock/include/mock_ability_mgr_service.h index c420df86b545d3050fdc4a9c35695f426ca8ece5..50d5a59391e7016e352d46838e99737da9a47b82 100644 --- a/test/moduletest/mock/include/mock_ability_mgr_service.h +++ b/test/moduletest/mock/include/mock_ability_mgr_service.h @@ -260,6 +260,8 @@ public: MOCK_METHOD1(UnregisterAppDebugListener, int32_t(const sptr &listener)); MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName)); + MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m)); private: Semaphore sem_; diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h index ec03acf464139823070214cf60e6dd481b090e3d..35e0059f2940f8e7b9aed06813d32fccd68a7473 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h @@ -416,6 +416,8 @@ public: MOCK_METHOD1(UnregisterAppDebugListener, int32_t(const sptr &listener)); MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName)); + MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m)); }; } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h index 1468164e5da624e8d5a4558e594783cf3d3b0e72..79e78fd55d650eeff4a47dbf071b70d9c0393840 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -400,6 +400,8 @@ public: MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(IsAbilityControllerStart, bool(const Want& want)); + MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m)); }; } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 0ca7150ec95d09421be1f77f2daaf9cb09917b82..3efdae4600124e8b082a4344702b234b330e4d5c 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -400,6 +400,8 @@ public: MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(IsAbilityControllerStart, bool(const Want& want)); + MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m)); }; } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_manager_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_test/ability_manager_stub_mock.h index 062670334876f95dc5c8524df08af64675e62be2..b4fd794ff19cb1bb67213a9ce98569f01585ee5b 100644 --- a/test/unittest/ability_manager_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_test/ability_manager_stub_mock.h @@ -400,6 +400,8 @@ public: MOCK_METHOD1(UnregisterAppDebugListener, int32_t(const sptr &listener)); MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName)); + MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m)); }; } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h index b4ca5f2c0ca3c3649308e0e11098a81badb9d486..4a90256f5000b3ae95cc9dc8f95fb1dcff42cf76 100644 --- a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h +++ b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h @@ -391,6 +391,8 @@ public: MOCK_METHOD1(UnregisterAppDebugListener, int32_t(const sptr &listener)); MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName)); + MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m)); }; } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h index f537df56f47838e7baa09f7cb137e64c01b9857e..38a0a58979f714ea8edbdced903228f5534adb8c 100644 --- a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h +++ b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h @@ -269,6 +269,8 @@ public: MOCK_METHOD1(UnregisterAppDebugListener, int32_t(const sptr &listener)); MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName)); + MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m)); AbilityLifeCycleState curstate_ = AbilityLifeCycleState::ABILITY_STATE_INITIAL; sptr abilityScheduler_; // kit interface used to schedule ability life diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index b89487c5100e44819c298d4cb8caa2b5d0c3d8b3..5a75704d31a0e7586d5681d7bcf29d3f145c6337 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -270,6 +270,8 @@ public: MOCK_METHOD1(UnregisterAppDebugListener, int32_t(const sptr &listener)); MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName)); MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName)); + MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr &callerToken, + const InsightIntentExecuteParam ¶m)); public: std::string powerState_;