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 auto *rule = new (std::nothrow) ExperienceRule();
29 if (rule == nullptr) {
30 return nullptr;
31 }
32 if (!in.ReadBool(rule->isAllow)) {
33 delete rule;
34 return nullptr;
35 }
36 rule->replaceWant = in.ReadParcelable<Want>();
37 return rule;
38 }
39
Marshalling(Parcel & parcel) const40 bool ExperienceRule::Marshalling(Parcel &parcel) const
41 {
42 bool res = parcel.WriteBool(isAllow) && parcel.WriteParcelable(replaceWant);
43 if (!res) {
44 LOG_ERROR("ExperienceRule Marshalling failed");
45 return false;
46 }
47 return true;
48 }
49
ReadFromParcel(Parcel & parcel)50 bool CallerInfo::ReadFromParcel(Parcel &parcel)
51 {
52 LOG_INFO("read from parcel");
53 return true;
54 }
55
Unmarshalling(Parcel & in)56 CallerInfo *CallerInfo::Unmarshalling(Parcel &in)
57 {
58 auto *info = new (std::nothrow) CallerInfo();
59 if (info == nullptr) {
60 LOG_ERROR("new callerInfo failed, return nullptr");
61 return nullptr;
62 }
63 info->packageName = in.ReadString();
64 LOG_INFO("read packageName result: %{public}s", info->packageName.c_str());
65 bool res = in.ReadInt32(info->uid) && in.ReadInt32(info->pid) && in.ReadInt32(info->callerAppType) &&
66 in.ReadInt32(info->targetAppType);
67 if (!in.ReadInt32(info->callerModeType)) {
68 LOG_DEBUG("read callerModeType failed");
69 info->callerModeType = 0;
70 } else {
71 LOG_DEBUG("read callerModeType is %{public}d", info->callerModeType);
72 }
73 info->targetAppDistType = in.ReadString();
74 info->targetLinkFeature = in.ReadString();
75 if (!in.ReadInt32(info->targetLinkType)) {
76 LOG_DEBUG("read targetLinkType failed");
77 info->targetLinkType = 0;
78 } else {
79 LOG_DEBUG("read targetLinkType is %{public}d", info->targetLinkType);
80 }
81 int callerAbilityType = 0;
82 if (in.ReadInt32(callerAbilityType)) {
83 info->callerAbilityType = static_cast<AppExecFwk::AbilityType>(callerAbilityType);
84 }
85 if (!in.ReadInt32(info->embedded)) {
86 LOG_DEBUG("read embedded failed");
87 info->embedded = 0;
88 } else {
89 LOG_DEBUG("read embedded is %{public}d", info->embedded);
90 }
91 info->callerAppProvisionType = in.ReadString();
92 info->targetAppProvisionType = in.ReadString();
93 int32_t callerExtensionAbilityType = 0;
94 if (in.ReadInt32(callerExtensionAbilityType)) {
95 info->callerExtensionAbilityType = static_cast<AppExecFwk::ExtensionAbilityType>(callerExtensionAbilityType);
96 }
97 if (!res) {
98 LOG_ERROR("read callerInfo information failed");
99 delete info;
100 return nullptr;
101 }
102 return info;
103 }
104
Marshalling(Parcel & parcel) const105 bool CallerInfo::Marshalling(Parcel &parcel) const
106 {
107 bool res = parcel.WriteString(packageName) && parcel.WriteInt32(uid) && parcel.WriteInt32(pid) &&
108 parcel.WriteInt32(callerAppType) && parcel.WriteInt32(targetAppType);
109 if (!res) {
110 LOG_ERROR("write CallerInfo failed");
111 return false;
112 }
113 return true;
114 }
115
ToString() const116 std::string CallerInfo::ToString() const
117 {
118 std::string str = "CallerInfo{packageName:" + packageName + ",uid:" + std::to_string(uid) +
119 ",pid:" + std::to_string(pid) + ",callerAppType:" + std::to_string(callerAppType) +
120 ",targetAppType:" + std::to_string(targetAppType) + ",callerModeType:" + std::to_string(callerModeType) +
121 ",targetAppDistType:" + targetAppDistType + ",targetLinkFeature:" + targetLinkFeature + ",targetLinkType:" +
122 std::to_string(targetLinkType) + ",callerAbilityType:" +
123 std::to_string(static_cast<int32_t>(callerAbilityType)) + ",callerExtensionAbilityType:" +
124 std::to_string(static_cast<int32_t>(callerExtensionAbilityType)) + ",embedded:" +
125 std::to_string(embedded) + ",callerAppProvisionType:" + callerAppProvisionType +
126 ",targetAppProvisionType:" + targetAppProvisionType + "}";
127 return str;
128 }
129 } // namespace EcologicalRuleMgrService
130 } // namespace OHOS
131