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 "bms_ecological_rule_mgr_service_param.h"
17 
18 #include <string>
19 #include <vector>
20 #include "app_log_tag_wrapper.h"
21 #include "app_log_wrapper.h"
22 #include "iremote_broker.h"
23 #include "iremote_object.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 #define TAG "ERMS_PARAM"
28 
Unmarshalling(Parcel & in)29 BmsExperienceRule *BmsExperienceRule::Unmarshalling(Parcel &in)
30 {
31     auto *rule = new (std::nothrow) BmsExperienceRule();
32     if (rule == nullptr) {
33         LOG_E(BMS_TAG_DEFAULT, "rule is nullptr");
34         return nullptr;
35     }
36 
37     if (!in.ReadBool(rule->isAllow)) {
38         LOG_E(BMS_TAG_DEFAULT, "read isAllow failed");
39         delete rule;
40         return nullptr;
41     }
42 
43     if (!in.ReadString(rule->sceneCode)) {
44         LOG_E(BMS_TAG_DEFAULT, "read sceneCode failed");
45         delete rule;
46         return nullptr;
47     }
48 
49     rule->replaceWant = in.ReadParcelable<Want>();
50 
51     return rule;
52 }
53 
Marshalling(Parcel & parcel) const54 bool BmsExperienceRule::Marshalling(Parcel &parcel) const
55 {
56     if (!parcel.WriteBool(isAllow)) {
57         LOG_E(BMS_TAG_DEFAULT, "write isAllow failed");
58         return false;
59     }
60 
61     if (!parcel.WriteString(sceneCode)) {
62         LOG_E(BMS_TAG_DEFAULT, "write sceneCode failed");
63         return false;
64     }
65     if (!parcel.WriteParcelable(replaceWant)) {
66         LOG_E(BMS_TAG_DEFAULT, "write replaceWant failed");
67         return false;
68     }
69 
70     return true;
71 }
72 
ReadFromParcel(Parcel & parcel)73 bool BmsCallerInfo::ReadFromParcel(Parcel &parcel)
74 {
75     LOG_I(BMS_TAG_DEFAULT, "read from parcel");
76     return true;
77 }
78 
Unmarshalling(Parcel & in)79 BmsCallerInfo *BmsCallerInfo::Unmarshalling(Parcel &in)
80 {
81     auto *info = new (std::nothrow) BmsCallerInfo();
82     if (info == nullptr) {
83         LOG_E(BMS_TAG_DEFAULT, "new callerInfo failed, return nullptr");
84         return nullptr;
85     }
86     info->packageName = in.ReadString();
87     LOG_I(BMS_TAG_DEFAULT, "read packageName result: %{public}s", info->packageName.c_str());
88 
89     if (!in.ReadInt32(info->uid)) {
90         LOG_E(BMS_TAG_DEFAULT, "read uid failed");
91         delete info;
92         return nullptr;
93     }
94     if (!in.ReadInt32(info->pid)) {
95         LOG_E(BMS_TAG_DEFAULT, "read pid failed");
96         delete info;
97         return nullptr;
98     }
99     if (!in.ReadInt32(info->callerAppType)) {
100         LOG_E(BMS_TAG_DEFAULT, "read callerAppType failed");
101         delete info;
102         return nullptr;
103     }
104     if (!in.ReadInt32(info->targetAppType)) {
105         LOG_E(BMS_TAG_DEFAULT, "read targetAppType failed");
106         delete info;
107         return nullptr;
108     }
109     if (!in.ReadInt32(info->callerModelType)) {
110         delete info;
111         return nullptr;
112     }
113     info->targetAppDistType = in.ReadString();
114     info->targetLinkFeature = in.ReadString();
115     if (!in.ReadInt32(info->targetLinkType)) {
116         delete info;
117         return nullptr;
118     }
119     if (!in.ReadInt32(info->callerAbilityType)) {
120         delete info;
121         return nullptr;
122     }
123     if (!in.ReadInt32(info->embedded)) {
124         delete info;
125         return nullptr;
126     }
127     info->callerAppProvisionType = in.ReadString();
128     info->targetAppProvisionType = in.ReadString();
129     return info;
130 }
131 
Marshalling(Parcel & parcel) const132 bool BmsCallerInfo::Marshalling(Parcel &parcel) const
133 {
134     if (!parcel.WriteString(packageName)) {
135         LOG_E(BMS_TAG_DEFAULT, "write packageName failed");
136         return false;
137     }
138     if (!parcel.WriteInt32(uid)) {
139         LOG_E(BMS_TAG_DEFAULT, "write uid failed");
140         return false;
141     }
142     if (!parcel.WriteInt32(pid)) {
143         LOG_E(BMS_TAG_DEFAULT, "write pid failed");
144         return false;
145     }
146     if (!parcel.WriteInt32(callerAppType)) {
147         LOG_E(BMS_TAG_DEFAULT, "write callerAppType failed");
148         return false;
149     }
150     if (!parcel.WriteInt32(targetAppType)) {
151         LOG_E(BMS_TAG_DEFAULT, "write targetAppType failed");
152         return false;
153     }
154     if (!parcel.WriteInt32(callerModelType)) {
155         APP_LOGE("write callerModelType failed");
156         return false;
157     }
158     if (!parcel.WriteString(targetAppDistType)) {
159         return false;
160     }
161     if (!parcel.WriteString(targetLinkFeature)) {
162         return false;
163     }
164     if (!parcel.WriteInt32(targetLinkType)) {
165         return false;
166     }
167     if (!parcel.WriteInt32(callerAbilityType)) {
168         return false;
169     }
170     if (!parcel.WriteInt32(embedded)) {
171         return false;
172     }
173     if (!parcel.WriteString(callerAppProvisionType)) {
174         return false;
175     }
176     if (!parcel.WriteString(targetAppProvisionType)) {
177         return false;
178     }
179     return true;
180 }
181 
ToString() const182 std::string BmsCallerInfo::ToString() const
183 {
184     std::string str = "BmsCallerInfo{packageName:" + packageName + ",uid:" + std::to_string(uid) +
185         ",pid:" + std::to_string(pid) + ",callerAppType:" + std::to_string(callerAppType) +
186         ",targetAppType:" + std::to_string(targetAppType) + ",callerModelType:" + std::to_string(callerModelType) +
187         ",targetAppDistType:" + targetAppDistType + ",targetLinkFeature:" + targetLinkFeature + ",targetLinkType:" +
188         std::to_string(targetLinkType) + ",callerAbilityType:" + std::to_string(callerAbilityType) + ",embedded:" +
189         std::to_string(embedded) + ",callerAppProvisionType:" + callerAppProvisionType + ",targetAppProvisionType:" +
190         targetAppProvisionType + "}";
191     return str;
192 }
193 } // namespace AppExecFwk
194 } // namespace OHOS
195