1 /* 2 * Copyright (c) 2021 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 "string_ex.h" 19 #include "nlohmann/json.hpp" 20 #include "hilog_wrapper.h" 21 22 namespace OHOS { 23 namespace AAFwk { 24 ReadFromParcel(Parcel & parcel)25bool CallerInfo::ReadFromParcel(Parcel &parcel) 26 { 27 requestCode = parcel.ReadInt32(); 28 deviceId = Str16ToStr8(parcel.ReadString16()); 29 bundleName = Str16ToStr8(parcel.ReadString16()); 30 abilityName = Str16ToStr8(parcel.ReadString16()); 31 return true; 32 } 33 Unmarshalling(Parcel & parcel)34CallerInfo *CallerInfo::Unmarshalling(Parcel &parcel) 35 { 36 CallerInfo *info = new (std::nothrow) CallerInfo(); 37 if (info && !info->ReadFromParcel(parcel)) { 38 delete info; 39 info = nullptr; 40 } 41 return info; 42 } 43 Marshalling(Parcel & parcel) const44bool CallerInfo::Marshalling(Parcel &parcel) const 45 { 46 // write requestCode 47 if (!parcel.WriteInt32(requestCode)) { 48 return false; 49 } 50 // write deviceId 51 if (!parcel.WriteString16(Str8ToStr16(deviceId))) { 52 return false; 53 } 54 // write bundleName 55 if (!parcel.WriteString16(Str8ToStr16(bundleName))) { 56 return false; 57 } 58 // write abilityName 59 if (!parcel.WriteString16(Str8ToStr16(abilityName))) { 60 return false; 61 } 62 return true; 63 } 64 65 } // namespace AAFwk 66 } // namespace OHOS