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 "ecological_rule_mgr_service_param.h"
17 #include "iremote_broker.h"
18 #include "iremote_object.h"
19
20 #include "ecological_rule_mgr_service_logger.h"
21
22 namespace OHOS {
23 namespace EcologicalRuleMgrService {
24 #define TAG "ERMS_PARAM"
25
Unmarshalling(Parcel & in)26 ExperienceRule *ExperienceRule::Unmarshalling(Parcel &in)
27 {
28 return nullptr;
29 }
30
Marshalling(Parcel & parcel) const31 bool ExperienceRule::Marshalling(Parcel &parcel) const
32 {
33 return true;
34 }
35
Unmarshalling(Parcel & in)36 AmsExperienceRule *AmsExperienceRule::Unmarshalling(Parcel &in)
37 {
38 auto *rule = new (std::nothrow) AmsExperienceRule();
39 if (rule == nullptr) {
40 return nullptr;
41 }
42 if (!in.ReadInt32(rule->resultCode)) {
43 delete rule;
44 return nullptr;
45 }
46 rule->replaceWant = in.ReadParcelable<Want>();
47 return rule;
48 }
49
Marshalling(Parcel & parcel) const50 bool AmsExperienceRule::Marshalling(Parcel &parcel) const
51 {
52 bool res = parcel.WriteInt32(resultCode) && parcel.WriteParcelable(replaceWant);
53 if (!res) {
54 LOG_ERROR("AmsExperienceRule Marshalling failed");
55 return false;
56 }
57 return true;
58 }
59
Unmarshalling(Parcel & in)60 BmsExperienceRule *BmsExperienceRule::Unmarshalling(Parcel &in)
61 {
62 auto *rule = new (std::nothrow) BmsExperienceRule();
63 if (rule == nullptr) {
64 return nullptr;
65 }
66 if (!in.ReadBool(rule->isAllow)) {
67 delete rule;
68 return nullptr;
69 }
70 rule->replaceWant = in.ReadParcelable<Want>();
71 return rule;
72 }
73
Marshalling(Parcel & parcel) const74 bool BmsExperienceRule::Marshalling(Parcel &parcel) const
75 {
76 bool res = parcel.WriteBool(isAllow) && parcel.WriteParcelable(replaceWant);
77 if (!res) {
78 LOG_ERROR("BmsExperienceRule Marshalling failed");
79 return false;
80 }
81 return true;
82 }
83
ReadFromParcel(Parcel & parcel)84 bool CallerInfo::ReadFromParcel(Parcel &parcel)
85 {
86 LOG_INFO("read from parcel");
87 return true;
88 }
89
Unmarshalling(Parcel & in)90 CallerInfo *CallerInfo::Unmarshalling(Parcel &in)
91 {
92 auto *info = new (std::nothrow) CallerInfo();
93 if (info == nullptr) {
94 LOG_ERROR("new callerInfo failed, return nullptr");
95 return nullptr;
96 }
97 info->packageName = in.ReadString();
98 LOG_INFO("read packageName result: %{public}s", info->packageName.c_str());
99 bool res = in.ReadInt32(info->uid) && in.ReadInt32(info->pid) && in.ReadInt32(info->callerAppType) &&
100 in.ReadInt32(info->targetAppType);
101 if (!in.ReadInt32(info->callerModeType)) {
102 LOG_DEBUG("read callerModeType failed");
103 info->callerModeType = 0;
104 } else {
105 LOG_DEBUG("read callerModeType is %{public}d", info->callerModeType);
106 }
107 info->targetAppDistType = in.ReadString();
108 info->targetLinkFeature = in.ReadString();
109 if (!in.ReadInt32(info->targetLinkType)) {
110 LOG_DEBUG("read targetLinkType failed");
111 info->targetLinkType = 0;
112 } else {
113 LOG_DEBUG("read targetLinkType is %{public}d", info->targetLinkType);
114 }
115 int callerAbilityType = 0;
116 if (in.ReadInt32(callerAbilityType)) {
117 info->callerAbilityType = static_cast<AppExecFwk::AbilityType>(callerAbilityType);
118 }
119 if (!in.ReadInt32(info->embedded)) {
120 LOG_DEBUG("read embedded failed");
121 info->embedded = 0;
122 } else {
123 LOG_DEBUG("read embedded is %{public}d", info->embedded);
124 }
125 info->callerAppProvisionType = in.ReadString();
126 info->targetAppProvisionType = in.ReadString();
127 int32_t callerExtensionAbilityType = 0;
128 if (in.ReadInt32(callerExtensionAbilityType)) {
129 info->callerExtensionAbilityType = static_cast<AppExecFwk::ExtensionAbilityType>(callerExtensionAbilityType);
130 }
131 info->targetAbilityType = static_cast<AppExecFwk::AbilityType>(in.ReadInt32());
132 info->targetExtensionAbilityType = static_cast<AppExecFwk::ExtensionAbilityType>(in.ReadInt32());
133 if (!res) {
134 LOG_ERROR("read callerInfo information failed");
135 delete info;
136 return nullptr;
137 }
138 return info;
139 }
140
Marshalling(Parcel & parcel) const141 bool CallerInfo::Marshalling(Parcel &parcel) const
142 {
143 bool res = parcel.WriteString(packageName) && parcel.WriteInt32(uid) && parcel.WriteInt32(pid) &&
144 parcel.WriteInt32(callerAppType) && parcel.WriteInt32(targetAppType);
145 if (!res) {
146 LOG_ERROR("write CallerInfo failed");
147 return false;
148 }
149 return true;
150 }
151
ToString() const152 std::string CallerInfo::ToString() const
153 {
154 std::string str = "CallerInfo{packageName:" + packageName + ",uid:" + std::to_string(uid) +
155 ",pid:" + std::to_string(pid) + ",callerAppType:" + std::to_string(callerAppType) +
156 ",targetAppType:" + std::to_string(targetAppType) + ",callerModeType:" + std::to_string(callerModeType) +
157 ",targetAppDistType:" + targetAppDistType + ",targetLinkFeature:" + targetLinkFeature + ",targetLinkType:" +
158 std::to_string(targetLinkType) + ",callerAbilityType:" +
159 std::to_string(static_cast<int32_t>(callerAbilityType)) + ",callerExtensionAbilityType:" +
160 std::to_string(static_cast<int32_t>(callerExtensionAbilityType)) + ",embedded:" +
161 std::to_string(embedded) + ",callerAppProvisionType:" + callerAppProvisionType +
162 ",targetAppProvisionType:" + targetAppProvisionType + ",targetAbilityType:" +
163 std::to_string(static_cast<int32_t>(targetAbilityType)) + ",targetExtensionAbilityType:" +
164 std::to_string(static_cast<int32_t>(targetExtensionAbilityType)) + "}";
165 return str;
166 }
167 } // namespace EcologicalRuleMgrService
168 } // namespace OHOS
169