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 "hilog_wrapper.h" 19 #include "nlohmann/json.hpp" 20 #include "string_ex.h" 21 22 namespace OHOS { 23 namespace AAFwk { ReadFromParcel(Parcel & parcel)24bool CallerInfo::ReadFromParcel(Parcel &parcel) 25 { 26 requestCode = parcel.ReadInt32(); 27 deviceId = Str16ToStr8(parcel.ReadString16()); 28 bundleName = Str16ToStr8(parcel.ReadString16()); 29 abilityName = Str16ToStr8(parcel.ReadString16()); 30 moduleName = 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 HILOG_DEBUG("Failed to write str deviceId"); 53 return false; 54 } 55 // write bundleName 56 if (!parcel.WriteString16(Str8ToStr16(bundleName))) { 57 HILOG_DEBUG("Failed to write str bundleName"); 58 return false; 59 } 60 // write abilityName 61 if (!parcel.WriteString16(Str8ToStr16(abilityName))) { 62 HILOG_DEBUG("Failed to write str abilityName"); 63 return false; 64 } 65 // write moduleName 66 if (!parcel.WriteString16(Str8ToStr16(moduleName))) { 67 HILOG_DEBUG("Failed to write str moduleName"); 68 return false; 69 } 70 return true; 71 } 72 } // namespace AAFwk 73 } // namespace OHOS 74