• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "ani_common_execute_param.h"
17 
18 #include "hilog_tag_wrapper.h"
19 #include "ani_common_util.h"
20 #include "ani_common_want.h"
21 #include "ani_enum_convert.h"
22 
23 namespace OHOS {
24 namespace AbilityRuntime {
25 using namespace OHOS::AppExecFwk;
26 
UnwrapExecuteParam(ani_env * env,ani_object param,AppExecFwk::InsightIntentExecuteParam & executeParam)27 bool UnwrapExecuteParam(ani_env *env, ani_object param, AppExecFwk::InsightIntentExecuteParam &executeParam)
28 {
29     if (env == nullptr) {
30         TAG_LOGE(AAFwkTag::INTENT, "null env");
31         return false;
32     }
33     if (param == nullptr) {
34         TAG_LOGE(AAFwkTag::INTENT, "null param");
35         return false;
36     }
37 
38     std::string bundleName {""};
39     if (!GetStringProperty(env, param, "bundleName", bundleName)) {
40         TAG_LOGE(AAFwkTag::INTENT, "Wrong argument type bundleName");
41         return false;
42     }
43     executeParam.bundleName_ = bundleName;
44 
45     std::string moduleName {""};
46     if (!GetStringProperty(env, param, "moduleName", moduleName)) {
47         TAG_LOGE(AAFwkTag::INTENT, "Wrong argument type moduleName");
48         return false;
49     }
50     executeParam.moduleName_ = moduleName;
51 
52     std::string abilityName {""};
53     if (!GetStringProperty(env, param, "abilityName", abilityName)) {
54         TAG_LOGE(AAFwkTag::INTENT, "Wrong argument type abilityName");
55         return false;
56     }
57     executeParam.abilityName_ = abilityName;
58 
59     std::string insightIntentName {""};
60     if (!GetStringProperty(env, param, "insightIntentName", insightIntentName)) {
61         TAG_LOGE(AAFwkTag::INTENT, "Wrong argument type insightIntentName");
62         return false;
63     }
64     executeParam.insightIntentName_ = insightIntentName;
65 
66     ani_ref aniIntentParam = nullptr;
67     if (!GetRefProperty(env, param, "insightIntentParam", aniIntentParam)) {
68         TAG_LOGE(AAFwkTag::INTENT, "null aniIntentParam");
69         return false;
70     }
71     auto wp = std::make_shared<WantParams>();
72     if (!UnwrapWantParams(env, aniIntentParam, *wp)) {
73         TAG_LOGE(AAFwkTag::INTENT, "unwrap want fail");
74         return false;
75     }
76     executeParam.insightIntentParam_ = wp;
77 
78     int32_t executeMode = 0;
79     ani_ref executeModeRef = nullptr;
80     if (!GetRefProperty(env, param, "executeMode", executeModeRef) != ANI_OK) {
81         TAG_LOGE(AAFwkTag::INTENT, "Wrong argument type executeMode");
82         return false;
83     }
84     AAFwk::AniEnumConvertUtil::EnumConvert_EtsToNative(env,
85         static_cast<ani_enum_item>(executeModeRef), executeMode);
86     executeParam.executeMode_ = executeMode;
87 
88     double displayIdD = 0.0;
89     int32_t displayId = INVALID_DISPLAY_ID;
90     if (executeMode == ExecuteMode::UI_ABILITY_FOREGROUND &&
91         IsExistsProperty(env, param, "displayId")) {
92         if (GetDoublePropertyObject(env, param, "displayId", displayIdD)) {
93             displayId = static_cast<int32_t>(displayIdD);
94             if (displayId < 0) {
95                 TAG_LOGE(AAFwkTag::INTENT, "invalid displayId");
96                 return false;
97             }
98             TAG_LOGI(AAFwkTag::INTENT, "displayId %{public}d", displayId);
99             executeParam.displayId_ = displayId;
100         }
101     }
102     if (IsExistsProperty(env, param, "uris")) {
103         std::vector<std::string> uris;
104         if (!GetStringArrayProperty(env, param, "uris", uris)) {
105             TAG_LOGE(AAFwkTag::INTENT, "Wrong argument uris fail");
106             return false;
107         }
108         executeParam.uris_ = uris;
109     }
110     if (IsExistsProperty(env, param, "flags")) {
111         double flags = 0.0;
112         if (!GetDoublePropertyObject(env, param, "flags", flags)) {
113             TAG_LOGE(AAFwkTag::INTENT, "Wrong argument flags fail");
114             return false;
115         }
116         executeParam.flags_ = static_cast<int32_t>(flags);
117     }
118 
119     return true;
120 }
121 } // namespace AbilityRuntime
122 } // namespace OHOS
123