1 /* 2 * Copyright (C) 2025 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::UDMF; 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 (UdmfMessageParcel::messageParcel == nullptr) { 33 return false; 34 } 35 return UdmfMessageParcel::messageParcel->WriteInterfaceToken(name); 36 } 37 ReadInterfaceToken()38std::u16string MessageParcel::ReadInterfaceToken() 39 { 40 if (UdmfMessageParcel::messageParcel == nullptr) { 41 return std::u16string(); 42 } 43 return UdmfMessageParcel::messageParcel->ReadInterfaceToken(); 44 } 45 WriteParcelable(const Parcelable * object)46bool Parcel::WriteParcelable(const Parcelable *object) 47 { 48 if (UdmfMessageParcel::messageParcel == nullptr) { 49 return false; 50 } 51 return UdmfMessageParcel::messageParcel->WriteParcelable(object); 52 } 53 WriteInt32(int32_t value)54bool Parcel::WriteInt32(int32_t value) 55 { 56 if (UdmfMessageParcel::messageParcel == nullptr) { 57 return false; 58 } 59 return UdmfMessageParcel::messageParcel->WriteInt32(value); 60 } 61 ReadInt32()62int32_t Parcel::ReadInt32() 63 { 64 if (UdmfMessageParcel::messageParcel == nullptr) { 65 return -1; // -1: default err 66 } 67 return UdmfMessageParcel::messageParcel->ReadInt32(); 68 } 69 ReadInt32(int32_t & value)70bool Parcel::ReadInt32(int32_t &value) 71 { 72 if (UdmfMessageParcel::messageParcel == nullptr) { 73 return false; 74 } 75 return UdmfMessageParcel::messageParcel->ReadInt32(value); 76 } 77 WriteRemoteObject(const Parcelable * object)78bool Parcel::WriteRemoteObject(const Parcelable *object) 79 { 80 if (UdmfMessageParcel::messageParcel == nullptr) { 81 return false; 82 } 83 return UdmfMessageParcel::messageParcel->WriteRemoteObject(object); 84 } 85 WriteRemoteObject(const sptr<IRemoteObject> & object)86bool MessageParcel::WriteRemoteObject(const sptr<IRemoteObject> &object) 87 { 88 if (UdmfMessageParcel::messageParcel == nullptr) { 89 return false; 90 } 91 return UdmfMessageParcel::messageParcel->WriteRemoteObject(object); 92 } 93 ReadRemoteObject()94sptr<IRemoteObject> MessageParcel::ReadRemoteObject() 95 { 96 if (UdmfMessageParcel::messageParcel == nullptr) { 97 return nullptr; 98 } 99 return UdmfMessageParcel::messageParcel->ReadRemoteObject(); 100 } 101 ReadBool()102bool Parcel::ReadBool() 103 { 104 if (UdmfMessageParcel::messageParcel == nullptr) { 105 return false; 106 } 107 return UdmfMessageParcel::messageParcel->ReadBool(); 108 } 109 ReadBool(bool & value)110bool Parcel::ReadBool(bool &value) 111 { 112 if (UdmfMessageParcel::messageParcel == nullptr) { 113 return false; 114 } 115 return UdmfMessageParcel::messageParcel->ReadBool(value); 116 } 117 WriteBool(bool value)118bool Parcel::WriteBool(bool value) 119 { 120 if (UdmfMessageParcel::messageParcel == nullptr) { 121 return false; 122 } 123 return UdmfMessageParcel::messageParcel->WriteBool(value); 124 } 125 WriteString(const std::string & value)126bool Parcel::WriteString(const std::string &value) 127 { 128 if (UdmfMessageParcel::messageParcel == nullptr) { 129 return false; 130 } 131 return UdmfMessageParcel::messageParcel->WriteString(value); 132 } 133 WriteCString(const char * value)134bool Parcel::WriteCString(const char *value) 135 { 136 if (UdmfMessageParcel::messageParcel == nullptr) { 137 return false; 138 } 139 return UdmfMessageParcel::messageParcel->WriteCString(value); 140 } 141 ReadString(std::string & value)142bool Parcel::ReadString(std::string &value) 143 { 144 if (UdmfMessageParcel::messageParcel == nullptr) { 145 return false; 146 } 147 return UdmfMessageParcel::messageParcel->ReadString(value); 148 } 149 ReadStringVector(std::vector<std::string> * value)150bool Parcel::ReadStringVector(std::vector<std::string> *value) 151 { 152 if (UdmfMessageParcel::messageParcel == nullptr) { 153 return false; 154 } 155 return UdmfMessageParcel::messageParcel->ReadStringVector(value); 156 } 157 WriteFileDescriptor(int fd)158bool MessageParcel::WriteFileDescriptor(int fd) 159 { 160 if (UdmfMessageParcel::messageParcel == nullptr) { 161 return false; 162 } 163 return UdmfMessageParcel::messageParcel->WriteFileDescriptor(fd); 164 } 165 ReadFileDescriptor()166int MessageParcel::ReadFileDescriptor() 167 { 168 if (UdmfMessageParcel::messageParcel == nullptr) { 169 return -1; // -1: default err 170 } 171 return UdmfMessageParcel::messageParcel->ReadFileDescriptor(); 172 } 173 ReadUint32(uint32_t & value)174bool Parcel::ReadUint32(uint32_t &value) 175 { 176 if (UdmfMessageParcel::messageParcel == nullptr) { 177 return false; 178 } 179 return UdmfMessageParcel::messageParcel->ReadUint32(value); 180 } 181 WriteUint64(uint64_t value)182bool Parcel::WriteUint64(uint64_t value) 183 { 184 if (UdmfMessageParcel::messageParcel == nullptr) { 185 return false; 186 } 187 return UdmfMessageParcel::messageParcel->WriteUint64(value); 188 } 189 WriteUint16(uint16_t value)190bool Parcel::WriteUint16(uint16_t value) 191 { 192 if (UdmfMessageParcel::messageParcel == nullptr) { 193 return false; 194 } 195 return UdmfMessageParcel::messageParcel->WriteUint16(value); 196 } 197 ReadUint64(uint64_t & value)198bool Parcel::ReadUint64(uint64_t &value) 199 { 200 if (UdmfMessageParcel::messageParcel == nullptr) { 201 return false; 202 } 203 return UdmfMessageParcel::messageParcel->ReadUint64(value); 204 } 205 WriteStringVector(const std::vector<std::string> & val)206bool Parcel::WriteStringVector(const std::vector<std::string> &val) 207 { 208 if (UdmfMessageParcel::messageParcel == nullptr) { 209 return false; 210 } 211 return UdmfMessageParcel::messageParcel->WriteStringVector(val); 212 } 213 WriteUint32(uint32_t value)214bool Parcel::WriteUint32(uint32_t value) 215 { 216 if (UdmfMessageParcel::messageParcel) { 217 return UdmfMessageParcel::messageParcel->WriteUint32(value); 218 } 219 return false; 220 } 221 WriteRawData(const void * data,size_t size)222bool MessageParcel::WriteRawData(const void *data, size_t size) 223 { 224 if (UdmfMessageParcel::messageParcel) { 225 return UdmfMessageParcel::messageParcel->WriteRawData(data, size); 226 } 227 return false; 228 } 229 ReadRawData(size_t size)230const void *MessageParcel::ReadRawData(size_t size) 231 { 232 if (UdmfMessageParcel::messageParcel) { 233 return UdmfMessageParcel::messageParcel->ReadRawData(size); 234 } 235 return nullptr; 236 } 237 ReadUint32()238uint32_t Parcel::ReadUint32() 239 { 240 if (UdmfMessageParcel::messageParcel) { 241 return UdmfMessageParcel::messageParcel->ReadUint32(); 242 } 243 return 1; // : default value 244 } 245 GetDataSize() const246size_t Parcel::GetDataSize() const 247 { 248 if (UdmfMessageParcel::messageParcel) { 249 return UdmfMessageParcel::messageParcel->GetDataSize(); 250 } 251 return 1; // : default value 252 } 253 } // namespace OHOS