• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "insight_intent_execute_param.h"
17 #include "hilog_wrapper.h"
18 
19 namespace OHOS {
20 namespace AppExecFwk {
21 using WantParams = OHOS::AAFwk::WantParams;
ReadFromParcel(Parcel & parcel)22 bool InsightIntentExecuteParam::ReadFromParcel(Parcel &parcel)
23 {
24     bundleName_ = Str16ToStr8(parcel.ReadString16());
25     moduleName_ = Str16ToStr8(parcel.ReadString16());
26     abilityName_ = Str16ToStr8(parcel.ReadString16());
27     insightIntentName_ = Str16ToStr8(parcel.ReadString16());
28     std::shared_ptr<WantParams> wantParams(parcel.ReadParcelable<WantParams>());
29     if (wantParams == nullptr) {
30         return false;
31     }
32     insightIntentParam_ = wantParams;
33     executeMode_ = parcel.ReadInt32();
34     insightIntentId_ = parcel.ReadUint64();
35     return true;
36 }
37 
Unmarshalling(Parcel & parcel)38 InsightIntentExecuteParam *InsightIntentExecuteParam::Unmarshalling(Parcel &parcel)
39 {
40     InsightIntentExecuteParam *param = new (std::nothrow) InsightIntentExecuteParam();
41     if (param == nullptr) {
42         return nullptr;
43     }
44 
45     if (!param->ReadFromParcel(parcel)) {
46         delete param;
47         param = nullptr;
48     }
49     return param;
50 }
51 
Marshalling(Parcel & parcel) const52 bool InsightIntentExecuteParam::Marshalling(Parcel &parcel) const
53 {
54     parcel.WriteString16(Str8ToStr16(bundleName_));
55     parcel.WriteString16(Str8ToStr16(moduleName_));
56     parcel.WriteString16(Str8ToStr16(abilityName_));
57     parcel.WriteString16(Str8ToStr16(insightIntentName_));
58     parcel.WriteParcelable(insightIntentParam_.get());
59     parcel.WriteInt32(executeMode_);
60     parcel.WriteUint64(insightIntentId_);
61     return true;
62 }
63 
IsInsightIntentExecute(const AAFwk::Want & want)64 bool InsightIntentExecuteParam::IsInsightIntentExecute(const AAFwk::Want &want)
65 {
66     if (want.HasParameter(INSIGHT_INTENT_EXECUTE_PARAM_NAME)) {
67         return true;
68     }
69     return false;
70 }
71 
GenerateFromWant(const AAFwk::Want & want,InsightIntentExecuteParam & executeParam)72 bool InsightIntentExecuteParam::GenerateFromWant(const AAFwk::Want &want,
73     InsightIntentExecuteParam &executeParam)
74 {
75     const WantParams &wantParams = want.GetParams();
76     if (!wantParams.HasParam(INSIGHT_INTENT_EXECUTE_PARAM_NAME)) {
77         HILOG_ERROR("The want does not contain insight intent name.");
78         return false;
79     }
80 
81     AppExecFwk::ElementName elementName = want.GetElement();
82     executeParam.bundleName_ = elementName.GetBundleName();
83     executeParam.moduleName_ = elementName.GetModuleName();
84     executeParam.abilityName_ = elementName.GetAbilityName();
85     executeParam.insightIntentName_ = wantParams.GetStringParam(INSIGHT_INTENT_EXECUTE_PARAM_NAME);
86     executeParam.insightIntentId_ = std::stoull(wantParams.GetStringParam(INSIGHT_INTENT_EXECUTE_PARAM_ID));
87     executeParam.executeMode_ = wantParams.GetIntParam(INSIGHT_INTENT_EXECUTE_PARAM_MODE, 0);
88     executeParam.insightIntentParam_ =
89         std::make_shared<WantParams>(wantParams.GetWantParams(INSIGHT_INTENT_EXECUTE_PARAM_PARAM));
90     return true;
91 }
92 
RemoveInsightIntent(AAFwk::Want & want)93 bool InsightIntentExecuteParam::RemoveInsightIntent(AAFwk::Want &want)
94 {
95     if (want.HasParameter(INSIGHT_INTENT_EXECUTE_PARAM_NAME)) {
96         want.RemoveParam(INSIGHT_INTENT_EXECUTE_PARAM_NAME);
97     }
98     if (want.HasParameter(INSIGHT_INTENT_EXECUTE_PARAM_ID)) {
99         want.RemoveParam(INSIGHT_INTENT_EXECUTE_PARAM_ID);
100     }
101     if (want.HasParameter(INSIGHT_INTENT_EXECUTE_PARAM_MODE)) {
102         want.RemoveParam(INSIGHT_INTENT_EXECUTE_PARAM_MODE);
103     }
104     if (want.HasParameter(INSIGHT_INTENT_EXECUTE_PARAM_PARAM)) {
105         want.RemoveParam(INSIGHT_INTENT_EXECUTE_PARAM_PARAM);
106     }
107     return true;
108 }
109 } // namespace AppExecFwk
110 } // namespace OHOS
111