• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "want_manager.h"
17 
18 #include <map>
19 #include <string>
20 #include "ability_base_log_wrapper.h"
21 #include "int_wrapper.h"
22 #include "string_wrapper.h"
23 #include "want_params_wrapper.h"
24 
25 namespace OHOS {
26 namespace AAFwk {
27 
TransformToWant(AbilityBase_Want cwant,bool isDup,Want & want)28 [[maybe_unused]] AbilityBase_ErrorCode CWantManager::TransformToWant(AbilityBase_Want cwant, bool isDup,
29     Want &want)
30 {
31     want.SetElementName("", cwant.element.bundleName, cwant.element.abilityName, cwant.element.moduleName);
32     WantParams wantParams;
33     wantParams.SetParam(Want::PARAM_MODULE_NAME, String::Box(cwant.element.moduleName));
34     for (auto it : cwant.params) {
35         ABILITYBASE_LOGI("params key: %{public}s, value: %{public}s",
36             it.first.c_str(), it.second.c_str());
37         wantParams.SetParam(it.first, String::Box(it.second));
38     }
39 
40     for (auto it : cwant.fds) {
41         ABILITYBASE_LOGI("fd key: %{public}s, value: %{public}d", it.first.c_str(), it.second);
42         WantParams wp;
43         wp.SetParam(TYPE_PROPERTY, String::Box(FD));
44         int32_t new_fd = isDup ? dup(it.second) : it.second;
45         wp.SetParam(VALUE_PROPERTY, Integer::Box(new_fd));
46         OHOS::sptr<IWantParams> pWantParams = WantParamWrapper::Box(wp);
47         if (pWantParams != nullptr) {
48             wantParams.SetParam(it.first, pWantParams);
49         }
50     }
51     want.SetParams(wantParams);
52     return ABILITY_BASE_ERROR_CODE_NO_ERROR;
53 }
54 } // namespace AAFwk
55 } // namespace OHOS