/* * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "faultlogger_service_proxy.h" #include #include "ipc_types.h" #include "message_parcel.h" #include "hiview_logger.h" #include "faultlog_info_ohos.h" #include "faultlog_query_result_proxy.h" #include "hiview_logger.h" #include "hiviewfaultlogger_ipc_interface_code.h" namespace OHOS { namespace HiviewDFX { DEFINE_LOG_LABEL(0xD002D11, "FaultLoggerProxy"); void FaultLoggerServiceProxy::AddFaultLog(const FaultLogInfoOhos& info) { sptr remote = Remote(); if (remote == nullptr) { return; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(FaultLoggerServiceProxy::GetDescriptor())) { return; } if (!info.Marshalling(data)) { return; } if (info.pipeFd != -1) { if (!data.WriteFileDescriptor(info.pipeFd)) { HIVIEW_LOGE("failed to write file descriptor."); } close(info.pipeFd); } auto flags = option.GetFlags(); option.SetFlags(flags | 0x01); // 0X01 return immediately if (remote->SendRequest(static_cast(FaultLoggerServiceInterfaceCode::ADD_FAULTLOG), data, reply, option) != ERR_OK) { return; } } sptr FaultLoggerServiceProxy::QuerySelfFaultLog(int32_t faultType, int32_t maxNum) { sptr remote = Remote(); if (remote == nullptr) { return nullptr; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(FaultLoggerServiceProxy::GetDescriptor())) { return nullptr; } if (!data.WriteInt32(faultType)) { return nullptr; } if (!data.WriteInt32(maxNum)) { return nullptr; } if (remote->SendRequest(static_cast(FaultLoggerServiceInterfaceCode::QUERY_SELF_FAULTLOG), data, reply, option) != ERR_OK) { return nullptr; } sptr remoteObject = reply.ReadRemoteObject(); if (remoteObject == nullptr) { HIVIEW_LOGE("Failed to transfer Result."); } return remoteObject; } void FaultLoggerServiceProxy::Destroy() { sptr remote = Remote(); if (remote == nullptr) { return; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(FaultLoggerServiceProxy::GetDescriptor())) { return; } if (remote->SendRequest(static_cast(FaultLoggerServiceInterfaceCode::DESTROY), data, reply, option) != ERR_OK) { return; } } } // namespace HiviewDFX } // namespace OHOS