diff --git a/interfaces/inner_api/ability_manager/BUILD.gn b/interfaces/inner_api/ability_manager/BUILD.gn index 5b4fd3db703a2cfe9b2c7922a2ef8d86640be80e..e40202a2db676a40c86b5afc43f954a7bb46de8f 100644 --- a/interfaces/inner_api/ability_manager/BUILD.gn +++ b/interfaces/inner_api/ability_manager/BUILD.gn @@ -129,6 +129,7 @@ ohos_shared_library("ability_manager") { ] external_deps = [ + "ability_base:base", "ability_base:configuration", "ability_base:want", "ability_base:zuri", 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 6636a16a92937a03a35d53d117dc3d7823a08a65..8b50703abdffdd45edba586b9c2632e15833c410 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 @@ -55,6 +55,7 @@ public: static bool IsInsightIntentExecute(const AAFwk::Want &want); static bool GenerateFromWant(const AAFwk::Want &want, InsightIntentExecuteParam &executeParam); static bool RemoveInsightIntent(AAFwk::Want &want); + static void UpdateInsightIntentCallerInfo(const WantParams &wantParams, WantParams &insightIntentParam); std::string bundleName_; std::string moduleName_; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 95e0a46a83228ad9edee179439a53e0ee855d50e..d33fdec5032908a4c569f51c3d09843978f2ab25 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -7227,8 +7227,13 @@ void AbilityManagerService::UpdateCallerInfo(Want& want, const sptrGetNameForUid(callerUid, bundleName)); + } want.RemoveParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME); - want.SetParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME, std::string("")); + want.SetParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME, bundleName); want.RemoveParam(Want::PARAM_RESV_CALLER_ABILITY_NAME); want.SetParam(Want::PARAM_RESV_CALLER_ABILITY_NAME, std::string("")); } else { diff --git a/services/abilitymgr/src/insight_intent_execute_param.cpp b/services/abilitymgr/src/insight_intent_execute_param.cpp index a9e6243765d65651b38384492e89f1b253c0ade0..51f4e48db7aa1fddba112ccc25a34b60af7f8412 100644 --- a/services/abilitymgr/src/insight_intent_execute_param.cpp +++ b/services/abilitymgr/src/insight_intent_execute_param.cpp @@ -15,6 +15,8 @@ #include "insight_intent_execute_param.h" #include "hilog_wrapper.h" +#include "int_wrapper.h" +#include "string_wrapper.h" namespace OHOS { namespace AppExecFwk { @@ -87,8 +89,11 @@ bool InsightIntentExecuteParam::GenerateFromWant(const AAFwk::Want &want, executeParam.insightIntentName_ = wantParams.GetStringParam(INSIGHT_INTENT_EXECUTE_PARAM_NAME); executeParam.insightIntentId_ = std::stoull(wantParams.GetStringParam(INSIGHT_INTENT_EXECUTE_PARAM_ID)); executeParam.executeMode_ = wantParams.GetIntParam(INSIGHT_INTENT_EXECUTE_PARAM_MODE, 0); - executeParam.insightIntentParam_ = - std::make_shared(wantParams.GetWantParams(INSIGHT_INTENT_EXECUTE_PARAM_PARAM)); + + auto insightIntentParam = wantParams.GetWantParams(INSIGHT_INTENT_EXECUTE_PARAM_PARAM); + UpdateInsightIntentCallerInfo(wantParams, insightIntentParam); + executeParam.insightIntentParam_ = std::make_shared(insightIntentParam); + return true; } @@ -108,5 +113,25 @@ bool InsightIntentExecuteParam::RemoveInsightIntent(AAFwk::Want &want) } return true; } + +void InsightIntentExecuteParam::UpdateInsightIntentCallerInfo(const WantParams &wantParams, + WantParams &insightIntentParam) +{ + insightIntentParam.Remove(AAFwk::Want::PARAM_RESV_CALLER_TOKEN); + insightIntentParam.SetParam(AAFwk::Want::PARAM_RESV_CALLER_TOKEN, + AAFwk::Integer::Box(wantParams.GetIntParam(AAFwk::Want::PARAM_RESV_CALLER_TOKEN, 0))); + + insightIntentParam.Remove(AAFwk::Want::PARAM_RESV_CALLER_UID); + insightIntentParam.SetParam(AAFwk::Want::PARAM_RESV_CALLER_UID, + AAFwk::Integer::Box(wantParams.GetIntParam(AAFwk::Want::PARAM_RESV_CALLER_UID, 0))); + + insightIntentParam.Remove(AAFwk::Want::PARAM_RESV_CALLER_PID); + insightIntentParam.SetParam(AAFwk::Want::PARAM_RESV_CALLER_PID, + AAFwk::Integer::Box(wantParams.GetIntParam(AAFwk::Want::PARAM_RESV_CALLER_PID, 0))); + + insightIntentParam.Remove(AAFwk::Want::PARAM_RESV_CALLER_BUNDLE_NAME); + insightIntentParam.SetParam(AAFwk::Want::PARAM_RESV_CALLER_BUNDLE_NAME, + AAFwk::String::Box(wantParams.GetStringParam(AAFwk::Want::PARAM_RESV_CALLER_BUNDLE_NAME))); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/insight_intent/BUILD.gn b/test/unittest/insight_intent/BUILD.gn index 72ccc839cbb183ed89c858bd5eedaa85b15755d7..bebe728ca50e5558c38171bb77325aed4eb44cfb 100644 --- a/test/unittest/insight_intent/BUILD.gn +++ b/test/unittest/insight_intent/BUILD.gn @@ -14,5 +14,8 @@ group("unittest") { testonly = true - deps = [ "insight_intent_execute_manager_test:unittest" ] + deps = [ + "insight_intent_execute_manager_test:unittest", + "insight_intent_execute_param_test:unittest", + ] } diff --git a/test/unittest/insight_intent/insight_intent_execute_param_test/BUILD.gn b/test/unittest/insight_intent/insight_intent_execute_param_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6a249ea1a0ee9e6e3aee1d0c253cb0ccf70a3e73 --- /dev/null +++ b/test/unittest/insight_intent/insight_intent_execute_param_test/BUILD.gn @@ -0,0 +1,56 @@ +# 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_param_test") { + module_out_path = "ability_runtime/insight_intent" + + cflags_cc = [] + + include_dirs = [] + + sources = [ "insight_intent_execute_param_test.cpp" ] + + configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:base", + "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", + ] +} + +group("unittest") { + testonly = true + deps = [ ":insight_intent_execute_param_test" ] +} diff --git a/test/unittest/insight_intent/insight_intent_execute_param_test/insight_intent_execute_param_test.cpp b/test/unittest/insight_intent/insight_intent_execute_param_test/insight_intent_execute_param_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..885c0fafd2a4a2d700175a804ee8fb35fcbad56c --- /dev/null +++ b/test/unittest/insight_intent/insight_intent_execute_param_test/insight_intent_execute_param_test.cpp @@ -0,0 +1,134 @@ +/* + * 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 "want_params_wrapper.h" +#include "insight_intent_execute_param.h" +#include "int_wrapper.h" +#include "string_wrapper.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AAFwk { +using InsightIntentExecuteParam = AppExecFwk::InsightIntentExecuteParam; + +namespace { +const std::string TEST_BUNDLE_NANE = "test.bundleName"; +const std::string TEST_MODULE_NANE = "test.entry"; +const std::string TEST_ABILITY_NANE = "test.abilityName"; +const std::string TEST_CALLER_BUNDLE_NANE = "test.callerBundleName"; +const std::string TEST_INSIGHT_INTENT_NANE = "PlayMusic"; +} // namespace + +class InsightIntentExecuteParamTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void InsightIntentExecuteParamTest::SetUpTestCase(void) +{} + +void InsightIntentExecuteParamTest::TearDownTestCase(void) +{} + +void InsightIntentExecuteParamTest::SetUp() +{} + +void InsightIntentExecuteParamTest::TearDown() +{} + +/** + * @tc.name: GenerateFromWant_0100 + * @tc.desc: basic function test of get caller info. + * @tc.type: FUNC + * @tc.require: issueI91RLM + */ +HWTEST_F(InsightIntentExecuteParamTest, GenerateFromWant_0100, TestSize.Level1) +{ + HILOG_INFO("begin."); + WantParams wantParams; + wantParams.SetParam(AppExecFwk::INSIGHT_INTENT_EXECUTE_PARAM_NAME, AAFwk::String::Box(TEST_INSIGHT_INTENT_NANE)); + wantParams.SetParam(AppExecFwk::INSIGHT_INTENT_EXECUTE_PARAM_ID, AAFwk::String::Box("1")); + wantParams.SetParam(Want::PARAM_RESV_CALLER_TOKEN, Integer::Box(1000)); + wantParams.SetParam(Want::PARAM_RESV_CALLER_UID, Integer::Box(1001)); + wantParams.SetParam(Want::PARAM_RESV_CALLER_PID, Integer::Box(1002)); + wantParams.SetParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME, AAFwk::String::Box(TEST_CALLER_BUNDLE_NANE)); + + WantParams insightIntentParam; + insightIntentParam.SetParam("dummy", Integer::Box(-1)); + wantParams.SetParam(AppExecFwk::INSIGHT_INTENT_EXECUTE_PARAM_PARAM, WantParamWrapper::Box(insightIntentParam)); + + Want want; + want.SetElementName("", TEST_BUNDLE_NANE, TEST_ABILITY_NANE, TEST_MODULE_NANE); + want.SetParams(wantParams); + + InsightIntentExecuteParam executeParam; + auto ret = InsightIntentExecuteParam::GenerateFromWant(want, executeParam); + EXPECT_EQ(ret, true); + + // check execute param + EXPECT_EQ(executeParam.bundleName_, TEST_BUNDLE_NANE); + EXPECT_EQ(executeParam.moduleName_, TEST_MODULE_NANE); + EXPECT_EQ(executeParam.abilityName_, TEST_ABILITY_NANE); + EXPECT_EQ(executeParam.insightIntentName_, TEST_INSIGHT_INTENT_NANE); + EXPECT_EQ(executeParam.insightIntentId_, 1); + + // check caller info + std::shared_ptr insightIntentParamGot = executeParam.insightIntentParam_; + ASSERT_NE(insightIntentParamGot, nullptr); + EXPECT_EQ(insightIntentParamGot->GetIntParam(Want::PARAM_RESV_CALLER_TOKEN, 0), 1000); + EXPECT_EQ(insightIntentParamGot->GetIntParam(Want::PARAM_RESV_CALLER_UID, 0), 1001); + EXPECT_EQ(insightIntentParamGot->GetIntParam(Want::PARAM_RESV_CALLER_PID, 0), 1002); + EXPECT_EQ(insightIntentParamGot->GetStringParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME), TEST_CALLER_BUNDLE_NANE); + + HILOG_INFO("end."); +} + +/** + * @tc.name: UpdateInsightIntentCallerInfo_0100 + * @tc.desc: basic function test of get caller info. + * @tc.type: FUNC + * @tc.require: issueI91RLM + */ +HWTEST_F(InsightIntentExecuteParamTest, UpdateInsightIntentCallerInfo_0100, TestSize.Level1) +{ + HILOG_INFO("begin."); + WantParams wantParams; + wantParams.SetParam(Want::PARAM_RESV_CALLER_TOKEN, Integer::Box(1000)); + wantParams.SetParam(Want::PARAM_RESV_CALLER_UID, Integer::Box(1001)); + wantParams.SetParam(Want::PARAM_RESV_CALLER_PID, Integer::Box(1002)); + wantParams.SetParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME, AAFwk::String::Box(TEST_CALLER_BUNDLE_NANE)); + + WantParams insightIntentParam; + InsightIntentExecuteParam::UpdateInsightIntentCallerInfo(wantParams, insightIntentParam); + + // check caller info + EXPECT_EQ(insightIntentParam.GetIntParam(Want::PARAM_RESV_CALLER_TOKEN, 0), 1000); + EXPECT_EQ(insightIntentParam.GetIntParam(Want::PARAM_RESV_CALLER_UID, 0), 1001); + EXPECT_EQ(insightIntentParam.GetIntParam(Want::PARAM_RESV_CALLER_PID, 0), 1002); + EXPECT_EQ(insightIntentParam.GetStringParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME), TEST_CALLER_BUNDLE_NANE); + + HILOG_INFO("end."); +} +} // namespace AAFwk +} // namespace OHOS