From 9c1e56741ea0fc925dbef6ddfee280f093a9c555 Mon Sep 17 00:00:00 2001 From: "zhangyafei.echo" Date: Mon, 29 Jan 2024 20:03:46 +0800 Subject: [PATCH] Description: Support displayId when execute. Sig:SIG_ApplicationFramework Feature or BugFix: Feature Binary Source: No Signed-off-by: zhangyafei.echo Change-Id: I91414659dc45cd0e992eac7d60c7355c5580a159 --- .../napi_common/napi_common_execute_param.cpp | 14 ++- .../include/insight_intent_execute_param.h | 5 +- .../src/insight_intent_execute_manager.cpp | 6 +- .../src/insight_intent_execute_param.cpp | 4 +- test/unittest/BUILD.gn | 3 +- test/unittest/insight_intent/BUILD.gn | 18 ++++ .../BUILD.gn | 66 ++++++++++++ .../insight_intent_execute_manager_test.cpp | 101 ++++++++++++++++++ .../insight_intent_utils_mock.cpp | 26 +++++ 9 files changed, 238 insertions(+), 5 deletions(-) create mode 100644 test/unittest/insight_intent/BUILD.gn create mode 100644 test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn create mode 100644 test/unittest/insight_intent/insight_intent_execute_manager_test/insight_intent_execute_manager_test.cpp create mode 100644 test/unittest/insight_intent/insight_intent_execute_manager_test/insight_intent_utils_mock.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 index 7a26ff2461e..e32ae878f58 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 766380d504d..6636a16a929 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 f70c2535913..9330cde5525 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 8cd4e6d5b48..a9e6243765d 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 ed3e4de426b..fc7b430dea0 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 00000000000..72ccc839cbb --- /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 00000000000..39741fa9ad7 --- /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 00000000000..0a94485764e --- /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 00000000000..f13b3df75fc --- /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 -- Gitee