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 "form_ecological_rule_param.h"
17 
18 #include <string>
19 #include <vector>
20 
21 #include "iremote_broker.h"
22 #include "iremote_object.h"
23 
24 #include "fms_log_wrapper.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 
ReadFromParcel(Parcel & parcel)29 bool FormErmsCallerInfo::ReadFromParcel(Parcel &parcel)
30 {
31     HILOG_DEBUG("read from parcel");
32     return true;
33 }
34 
Unmarshalling(Parcel & in)35 FormErmsCallerInfo *FormErmsCallerInfo::Unmarshalling(Parcel &in)
36 {
37     auto *info = new (std::nothrow) FormErmsCallerInfo();
38     if (info == nullptr) {
39         HILOG_ERROR("new callerInfo failed,return nullptr");
40         return nullptr;
41     }
42 
43     info->packageName = in.ReadString();
44     HILOG_DEBUG("read packageName result:%{public}s", info->packageName.c_str());
45 
46     if (!in.ReadInt32(info->uid)) {
47         HILOG_ERROR("read uid failed");
48         delete info;
49         return nullptr;
50     }
51 
52     if (!in.ReadInt32(info->pid)) {
53         HILOG_ERROR("read pid failed");
54         delete info;
55         return nullptr;
56     }
57 
58     if (!in.ReadInt32(info->callerAppType)) {
59         HILOG_ERROR("read callerAppType failed");
60         delete info;
61         return nullptr;
62     }
63 
64     if (!in.ReadInt32(info->targetAppType)) {
65         HILOG_ERROR("read targetAppType failed");
66         delete info;
67         return nullptr;
68     }
69 
70     return info;
71 }
72 
Marshalling(Parcel & parcel) const73 bool FormErmsCallerInfo::Marshalling(Parcel &parcel) const
74 {
75     if (!parcel.WriteString(packageName)) {
76         HILOG_ERROR("write packageName failed");
77         return false;
78     }
79 
80     if (!parcel.WriteInt32(uid)) {
81         HILOG_ERROR("write uid failed");
82         return false;
83     }
84 
85     if (!parcel.WriteInt32(pid)) {
86         HILOG_ERROR("write pid failed");
87         return false;
88     }
89 
90     if (!parcel.WriteInt32(callerAppType)) {
91         HILOG_ERROR("write callerAppType failed");
92         return false;
93     }
94 
95     if (!parcel.WriteInt32(targetAppType)) {
96         HILOG_ERROR("write targetAppType failed");
97         return false;
98     }
99     return true;
100 }
101 
ToString() const102 std::string FormErmsCallerInfo::ToString() const
103 {
104     std::string str = "CallerInfo{packageName:" + packageName + ",uid:" + std::to_string(uid) +
105         ",pid:" + std::to_string(pid) + ",callerAppType:" + std::to_string(callerAppType) +
106         ",targetAppType:" + std::to_string(targetAppType) + "}";
107     return str;
108 }
109 } // namespace EcologicalRuleMgrService
110 } // namespace OHOS
111