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 "bool_wrapper.h"
22 #include "double_wrapper.h"
23 #include "int_wrapper.h"
24 #include "string_wrapper.h"
25 #include "want_params_wrapper.h"
26
27 namespace OHOS {
28 namespace AAFwk {
29
TransformToWant(AbilityBase_Want cwant,bool isDup,Want & want)30 [[maybe_unused]] AbilityBase_ErrorCode CWantManager::TransformToWant(AbilityBase_Want cwant, bool isDup,
31 Want &want)
32 {
33 want.SetElementName("", cwant.element.bundleName, cwant.element.abilityName, cwant.element.moduleName);
34 WantParams wantParams;
35 wantParams.SetParam(Want::PARAM_MODULE_NAME, String::Box(cwant.element.moduleName));
36 want.SetUri(cwant.uri);
37 for (auto it : cwant.params) {
38 ABILITYBASE_LOGD("params key: %{public}s, value: %{public}s",
39 it.first.c_str(), it.second.c_str());
40 wantParams.SetParam(it.first, String::Box(it.second));
41 }
42
43 for (auto it : cwant.intParams) {
44 ABILITYBASE_LOGD("int key: %{public}s, value: %{public}d", it.first.c_str(), it.second);
45 wantParams.SetParam(it.first, Integer::Box(it.second));
46 }
47
48 for (auto it : cwant.boolParams) {
49 ABILITYBASE_LOGD("bool key: %{public}s, value: %{public}d", it.first.c_str(), it.second);
50 wantParams.SetParam(it.first, Boolean::Box(it.second));
51 }
52
53 for (auto it : cwant.doubleParams) {
54 ABILITYBASE_LOGD("bool key: %{public}s, value: %{public}f", it.first.c_str(), it.second);
55 wantParams.SetParam(it.first, Double::Box(it.second));
56 }
57
58 for (auto it : cwant.fds) {
59 ABILITYBASE_LOGD("fd key: %{public}s, value: %{public}d", it.first.c_str(), it.second);
60 WantParams wp;
61 wp.SetParam(TYPE_PROPERTY, String::Box(FD));
62 int32_t new_fd = isDup ? dup(it.second) : it.second;
63 wp.SetParam(VALUE_PROPERTY, Integer::Box(new_fd));
64 OHOS::sptr<IWantParams> pWantParams = WantParamWrapper::Box(wp);
65 if (pWantParams != nullptr) {
66 wantParams.SetParam(it.first, pWantParams);
67 }
68 }
69 want.SetParams(wantParams);
70 return ABILITY_BASE_ERROR_CODE_NO_ERROR;
71 }
72 } // namespace AAFwk
73 } // namespace OHOS