1 /* 2 * Copyright (C) 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 #include "iremote_broker.h" 16 #include "message_parcel_mock.h" 17 18 namespace OHOS { 19 using namespace OHOS::FileAccessFwk; 20 Parcelable()21Parcelable::Parcelable() : Parcelable(false) 22 {} 23 Parcelable(bool asRemote)24Parcelable::Parcelable(bool asRemote) 25 { 26 asRemote_ = asRemote; 27 behavior_ = 0; 28 } 29 WriteInterfaceToken(std::u16string name)30bool MessageParcel::WriteInterfaceToken(std::u16string name) 31 { 32 if (UMessageParcel::messageParcel == nullptr) { 33 return false; 34 } 35 return UMessageParcel::messageParcel->WriteInterfaceToken(name); 36 } 37 ReadInterfaceToken()38std::u16string MessageParcel::ReadInterfaceToken() 39 { 40 if (UMessageParcel::messageParcel == nullptr) { 41 return {}; 42 } 43 return UMessageParcel::messageParcel->ReadInterfaceToken(); 44 } 45 WriteParcelable(const Parcelable * object)46bool Parcel::WriteParcelable(const Parcelable *object) 47 { 48 if (UMessageParcel::messageParcel == nullptr) { 49 return false; 50 } 51 return UMessageParcel::messageParcel->WriteParcelable(object); 52 } 53 WriteInt32(int32_t value)54bool Parcel::WriteInt32(int32_t value) 55 { 56 if (UMessageParcel::messageParcel == nullptr) { 57 return false; 58 } 59 return UMessageParcel::messageParcel->WriteInt32(value); 60 } 61 ReadInt32()62int32_t Parcel::ReadInt32() 63 { 64 if (UMessageParcel::messageParcel == nullptr) { 65 return -1; 66 } 67 return UMessageParcel::messageParcel->ReadInt32(); 68 } 69 ReadInt32(int32_t & value)70bool Parcel::ReadInt32(int32_t &value) 71 { 72 if (UMessageParcel::messageParcel == nullptr) { 73 return false; 74 } 75 return UMessageParcel::messageParcel->ReadInt32(value); 76 } 77 WriteRemoteObject(const Parcelable * object)78bool Parcel::WriteRemoteObject(const Parcelable *object) 79 { 80 if (UMessageParcel::messageParcel == nullptr) { 81 return false; 82 } 83 return UMessageParcel::messageParcel->WriteRemoteObject(object); 84 } 85 WriteRemoteObject(const sptr<IRemoteObject> & object)86bool MessageParcel::WriteRemoteObject(const sptr<IRemoteObject> &object) 87 { 88 if (UMessageParcel::messageParcel == nullptr) { 89 return false; 90 } 91 return UMessageParcel::messageParcel->WriteRemoteObject(object); 92 } 93 ReadRemoteObject()94sptr<IRemoteObject> MessageParcel::ReadRemoteObject() 95 { 96 if (UMessageParcel::messageParcel == nullptr) { 97 return nullptr; 98 } 99 return UMessageParcel::messageParcel->ReadRemoteObject(); 100 } 101 ReadBool()102bool Parcel::ReadBool() 103 { 104 if (UMessageParcel::messageParcel == nullptr) { 105 return false; 106 } 107 return UMessageParcel::messageParcel->ReadBool(); 108 } 109 ReadBool(bool & value)110bool Parcel::ReadBool(bool &value) 111 { 112 if (UMessageParcel::messageParcel == nullptr) { 113 return false; 114 } 115 return UMessageParcel::messageParcel->ReadBool(value); 116 } 117 WriteBool(bool value)118bool Parcel::WriteBool(bool value) 119 { 120 if (UMessageParcel::messageParcel == nullptr) { 121 return false; 122 } 123 return UMessageParcel::messageParcel->WriteBool(value); 124 } 125 WriteString(const std::string & value)126bool Parcel::WriteString(const std::string &value) 127 { 128 if (UMessageParcel::messageParcel == nullptr) { 129 return false; 130 } 131 return UMessageParcel::messageParcel->WriteString(value); 132 } 133 ReadString(std::string & value)134bool Parcel::ReadString(std::string &value) 135 { 136 if (UMessageParcel::messageParcel == nullptr) { 137 return false; 138 } 139 return UMessageParcel::messageParcel->ReadString(value); 140 } 141 ReadStringVector(std::vector<std::string> * value)142bool Parcel::ReadStringVector(std::vector<std::string> *value) 143 { 144 if (UMessageParcel::messageParcel == nullptr) { 145 return false; 146 } 147 return UMessageParcel::messageParcel->ReadStringVector(value); 148 } 149 WriteFileDescriptor(int fd)150bool MessageParcel::WriteFileDescriptor(int fd) 151 { 152 if (UMessageParcel::messageParcel == nullptr) { 153 return false; 154 } 155 return UMessageParcel::messageParcel->WriteFileDescriptor(fd); 156 } 157 ReadFileDescriptor()158int MessageParcel::ReadFileDescriptor() 159 { 160 if (UMessageParcel::messageParcel == nullptr) { 161 return -1; 162 } 163 return UMessageParcel::messageParcel->ReadFileDescriptor(); 164 } 165 ReadUint32(uint32_t & value)166bool Parcel::ReadUint32(uint32_t &value) 167 { 168 if (UMessageParcel::messageParcel == nullptr) { 169 return false; 170 } 171 return UMessageParcel::messageParcel->ReadUint32(value); 172 } 173 } // namespace OHOS