1 /*
2  * Copyright (c) 2021-2024 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 "caller_info.h"
17 
18 #include "hilog_tag_wrapper.h"
19 
20 namespace OHOS {
21 namespace AAFwk {
ReadFromParcel(Parcel & parcel)22 bool CallerInfo::ReadFromParcel(Parcel &parcel)
23 {
24     requestCode = parcel.ReadInt32();
25     deviceId = Str16ToStr8(parcel.ReadString16());
26     bundleName = Str16ToStr8(parcel.ReadString16());
27     abilityName = Str16ToStr8(parcel.ReadString16());
28     moduleName = Str16ToStr8(parcel.ReadString16());
29     return true;
30 }
31 
Unmarshalling(Parcel & parcel)32 CallerInfo *CallerInfo::Unmarshalling(Parcel &parcel)
33 {
34     CallerInfo *info = new (std::nothrow) CallerInfo();
35     if (info && !info->ReadFromParcel(parcel)) {
36         delete info;
37         info = nullptr;
38     }
39     return info;
40 }
41 
Marshalling(Parcel & parcel) const42 bool CallerInfo::Marshalling(Parcel &parcel) const
43 {
44     // write requestCode
45     if (!parcel.WriteInt32(requestCode)) {
46         return false;
47     }
48     // write deviceId
49     if (!parcel.WriteString16(Str8ToStr16(deviceId))) {
50         TAG_LOGD(AAFwkTag::ABILITYMGR, "Failed to write str deviceId");
51         return false;
52     }
53     // write bundleName
54     if (!parcel.WriteString16(Str8ToStr16(bundleName))) {
55         TAG_LOGD(AAFwkTag::ABILITYMGR, "Failed to write str bundleName");
56         return false;
57     }
58     // write abilityName
59     if (!parcel.WriteString16(Str8ToStr16(abilityName))) {
60         TAG_LOGD(AAFwkTag::ABILITYMGR, "Failed to write str abilityName");
61         return false;
62     }
63     // write moduleName
64     if (!parcel.WriteString16(Str8ToStr16(moduleName))) {
65         TAG_LOGD(AAFwkTag::ABILITYMGR, "Failed to write str moduleName");
66         return false;
67     }
68     return true;
69 }
70 }  // namespace AAFwk
71 }  // namespace OHOS
72