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 index 7a26ff2461eb9f6abf7fd458d0a88c1807ad620a..e32ae878f58f19a508f94fe46ffcce97d4965a3f 100644 --- a/frameworks/js/napi/inner/napi_common/napi_common_execute_param.cpp +++ b/frameworks/js/napi/inner/napi_common/napi_common_execute_param.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -83,6 +83,18 @@ bool UnwrapExecuteParam(napi_env env, napi_value param, InsightIntentExecutePara return false; } executeParam.executeMode_ = executeMode; + + int32_t displayId = INVALID_DISPLAY_ID; + if (executeMode == ExecuteMode::UI_ABILITY_FOREGROUND && + UnwrapInt32ByPropertyName(env, param, "displayId", displayId)) { + if (displayId < 0) { + HILOG_ERROR("Wrong argument displayId."); + return false; + } + HILOG_INFO("Get displayId %{public}d.", displayId); + executeParam.displayId_ = displayId; + } + return true; } } // namespace AbilityRuntime 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 index 766380d504db3a9daf00c37a76370fd90c2ca322..6636a16a92937a03a35d53d117dc3d7823a08a65 100644 --- a/interfaces/inner_api/ability_manager/include/insight_intent_execute_param.h +++ b/interfaces/inner_api/ability_manager/include/insight_intent_execute_param.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -42,6 +42,8 @@ constexpr char INSIGHT_INTENT_EXECUTE_PARAM_MODE[] = "ohos.insightIntent.execute constexpr char INSIGHT_INTENT_EXECUTE_PARAM_ID[] = "ohos.insightIntent.executeParam.id"; constexpr char INSIGHT_INTENT_SRC_ENTRY[] = "ohos.insightIntent.srcEntry"; +constexpr int32_t INVALID_DISPLAY_ID = -1; + class InsightIntentExecuteParam : public Parcelable { public: InsightIntentExecuteParam() = default; @@ -61,6 +63,7 @@ public: std::shared_ptr insightIntentParam_; int32_t executeMode_ = -1; uint64_t insightIntentId_ = 0; + int32_t displayId_ = INVALID_DISPLAY_ID; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/abilitymgr/src/insight_intent_execute_manager.cpp b/services/abilitymgr/src/insight_intent_execute_manager.cpp index f70c2535913c6ef4582268ba7315b3af304484b8..9330cde55253de7d56d554d5b5a9ea3f7356dbab 100644 --- a/services/abilitymgr/src/insight_intent_execute_manager.cpp +++ b/services/abilitymgr/src/insight_intent_execute_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -232,6 +232,10 @@ int32_t InsightIntentExecuteManager::GenerateWant( want.SetParam(INSIGHT_INTENT_EXECUTE_PARAM_NAME, param->insightIntentName_); want.SetParam(INSIGHT_INTENT_EXECUTE_PARAM_MODE, param->executeMode_); want.SetParam(INSIGHT_INTENT_EXECUTE_PARAM_ID, std::to_string(param->insightIntentId_)); + if (param->displayId_ != INVALID_DISPLAY_ID) { + want.SetParam(Want::PARAM_RESV_DISPLAY_ID, param->displayId_); + HILOG_DEBUG("Generate want with displayId: %{public}d", param->displayId_); + } return ERR_OK; } diff --git a/services/abilitymgr/src/insight_intent_execute_param.cpp b/services/abilitymgr/src/insight_intent_execute_param.cpp index 8cd4e6d5b4830ed1998a8f9ecf288be4f56b39fe..a9e6243765d65651b38384492e89f1b253c0ade0 100644 --- a/services/abilitymgr/src/insight_intent_execute_param.cpp +++ b/services/abilitymgr/src/insight_intent_execute_param.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -32,6 +32,7 @@ bool InsightIntentExecuteParam::ReadFromParcel(Parcel &parcel) insightIntentParam_ = wantParams; executeMode_ = parcel.ReadInt32(); insightIntentId_ = parcel.ReadUint64(); + displayId_ = parcel.ReadInt32(); return true; } @@ -58,6 +59,7 @@ bool InsightIntentExecuteParam::Marshalling(Parcel &parcel) const parcel.WriteParcelable(insightIntentParam_.get()); parcel.WriteInt32(executeMode_); parcel.WriteUint64(insightIntentId_); + parcel.WriteInt32(displayId_); return true; } diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index ed3e4de426b74246d702d69e76b755b1738aca98..fc7b430dea0e860406879672fb1587ea70343a28 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -434,6 +434,7 @@ group("unittest") { "free_install_manager_test:unittest", "image_info_test:unittest", "implicit_start_processor_test:unittest", + "insight_intent:unittest", "js_auto_fill_extension_test:unittest", "js_service_extension_test:unittest", "lifecycle_deal_test:unittest", diff --git a/test/unittest/insight_intent/BUILD.gn b/test/unittest/insight_intent/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..72ccc839cbb183ed89c858bd5eedaa85b15755d7 --- /dev/null +++ b/test/unittest/insight_intent/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("unittest") { + testonly = true + + deps = [ "insight_intent_execute_manager_test:unittest" ] +} diff --git a/test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn b/test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..39741fa9ad7e3d48dc9ffa1e9f1731f766424e9a --- /dev/null +++ b/test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn @@ -0,0 +1,66 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_unittest("insight_intent_execute_manager_test") { + module_out_path = "ability_runtime/insight_intent" + + cflags_cc = [] + + include_dirs = [ + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", + "${distributedschedule_path}/samgr/adapter/interfaces/innerkits/include/", + "${ability_runtime_innerkits_path}/app_manager/include/appmgr", + ] + + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent_profile.cpp", + "insight_intent_execute_manager_test.cpp", + "insight_intent_utils_mock.cpp", + ] + + configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "${ability_runtime_native_path}/appkit:appkit_manager_helper", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_deps_wrapper", + "ability_runtime:ability_manager", + "bundle_framework:libappexecfwk_common", + "c_utils:utils", + "ffrt:libffrt", + "hilog:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + ] +} + +group("unittest") { + testonly = true + deps = [ ":insight_intent_execute_manager_test" ] +} diff --git a/test/unittest/insight_intent/insight_intent_execute_manager_test/insight_intent_execute_manager_test.cpp b/test/unittest/insight_intent/insight_intent_execute_manager_test/insight_intent_execute_manager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0a94485764ef2d6670bb74342bcf17c904da58c0 --- /dev/null +++ b/test/unittest/insight_intent/insight_intent_execute_manager_test/insight_intent_execute_manager_test.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "hilog_wrapper.h" +#include "want.h" +#include "insight_intent_execute_param.h" +#include "insight_intent_execute_manager.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AAFwk { +class InsightIntentExecuteManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void InsightIntentExecuteManagerTest::SetUpTestCase(void) +{} + +void InsightIntentExecuteManagerTest::TearDownTestCase(void) +{} + +void InsightIntentExecuteManagerTest::SetUp() +{} + +void InsightIntentExecuteManagerTest::TearDown() +{} + +/** + * @tc.name: GenerateWant_0100 + * @tc.desc: basic function test of display id. + * @tc.type: FUNC + * @tc.require: issueI8ZRAG + */ +HWTEST_F(InsightIntentExecuteManagerTest, GenerateWant_0100, TestSize.Level1) +{ + HILOG_INFO("begin."); + AppExecFwk::InsightIntentExecuteParam param; + param.bundleName_ = "test.bundleName"; + param.moduleName_ = "test.entry"; + param.abilityName_ = "test.abilityName"; + param.insightIntentName_ = "PlayMusic"; + param.insightIntentParam_ = nullptr; + // other member has default value. + auto paramPtr = std::make_shared(param); + Want want; + auto ret = InsightIntentExecuteManager::GenerateWant(paramPtr, want); + EXPECT_EQ(ret, ERR_OK); + // get display id of want, expect don't contain + auto displayId = want.GetIntParam(Want::PARAM_RESV_DISPLAY_ID, -100); + EXPECT_EQ(displayId, -100); + HILOG_INFO("end."); +} + +/** + * @tc.name: GenerateWant_0200 + * @tc.desc: basic function test of display id. + * @tc.type: FUNC + * @tc.require: issueI8ZRAG + */ +HWTEST_F(InsightIntentExecuteManagerTest, GenerateWant_0200, TestSize.Level1) +{ + HILOG_INFO("begin."); + AppExecFwk::InsightIntentExecuteParam param; + param.bundleName_ = "test.bundleName"; + param.moduleName_ = "test.entry"; + param.abilityName_ = "test.abilityName"; + param.insightIntentName_ = "PlayMusic"; + param.insightIntentParam_ = nullptr; + param.displayId_ = 2; + // other member has default value. + auto paramPtr = std::make_shared(param); + Want want; + auto ret = InsightIntentExecuteManager::GenerateWant(paramPtr, want); + EXPECT_EQ(ret, ERR_OK); + // get display id of want + auto displayId = want.GetIntParam(Want::PARAM_RESV_DISPLAY_ID, -100); + EXPECT_EQ(displayId, 2); + HILOG_INFO("end."); +} +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/insight_intent/insight_intent_execute_manager_test/insight_intent_utils_mock.cpp b/test/unittest/insight_intent/insight_intent_execute_manager_test/insight_intent_utils_mock.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f13b3df75fc7563b5f4a137f75c29525594e8519 --- /dev/null +++ b/test/unittest/insight_intent/insight_intent_execute_manager_test/insight_intent_utils_mock.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "insight_intent_utils.h" + +namespace OHOS { +namespace AbilityRuntime { +std::string InsightIntentUtils::GetSrcEntry(const std::string &bundleName, const std::string &moduleName, + const std::string &intentName) +{ + return "test.srcEntry"; +} +} // namespace AbilityRuntime +} // namespace OHOS