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 #include "faultlogger_service_proxy.h"
16
17
18 #include "ipc_types.h"
19 #include "message_parcel.h"
20
21 #include "faultlog_info_ohos.h"
22 #include "faultlog_query_result_proxy.h"
23 #include "hilog/log_cpp.h"
24
25 namespace OHOS {
26 namespace HiviewDFX {
27 static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, 0xD002D10, "FaultLoggerProxy"};
AddFaultLog(const FaultLogInfoOhos & info)28 void FaultLoggerServiceProxy::AddFaultLog(const FaultLogInfoOhos& info)
29 {
30 sptr<IRemoteObject> remote = Remote();
31 if (remote == nullptr) {
32 return;
33 }
34
35 MessageParcel data;
36 MessageParcel reply;
37 MessageOption option;
38 if (!data.WriteInterfaceToken(FaultLoggerServiceProxy::GetDescriptor())) {
39 return;
40 }
41
42 if (!info.Marshalling(data)) {
43 return;
44 }
45
46 auto flags = option.GetFlags();
47 option.SetFlags(flags | 0x01); // 0X01 return immediately
48 if (remote->SendRequest(static_cast<int>(IFaultLoggerService::IFaultLoggerService_ADD_FAULTLOG),
49 data, reply, option) != ERR_OK) {
50 return;
51 }
52 }
53
QuerySelfFaultLog(int32_t faultType,int32_t maxNum)54 sptr<IRemoteObject> FaultLoggerServiceProxy::QuerySelfFaultLog(int32_t faultType, int32_t maxNum)
55 {
56 sptr<IRemoteObject> remote = Remote();
57 if (remote == nullptr) {
58 return nullptr;
59 }
60
61 MessageParcel data;
62 MessageParcel reply;
63 MessageOption option;
64 if (!data.WriteInterfaceToken(FaultLoggerServiceProxy::GetDescriptor())) {
65 return nullptr;
66 }
67
68 if (!data.WriteInt32(faultType)) {
69 return nullptr;
70 }
71
72 if (!data.WriteInt32(maxNum)) {
73 return nullptr;
74 }
75
76 if (remote->SendRequest(static_cast<int>(IFaultLoggerService::IFaultLoggerService_QUERY_SELF_FAULTLOG),
77 data, reply, option) != ERR_OK) {
78 return nullptr;
79 }
80
81 sptr<IRemoteObject> remoteObject = reply.ReadRemoteObject();
82 if (remoteObject == nullptr) {
83 OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, "Failed to transfer Result.");
84 }
85 return remoteObject;
86 }
87
Destroy()88 void FaultLoggerServiceProxy::Destroy()
89 {
90 sptr<IRemoteObject> remote = Remote();
91 if (remote == nullptr) {
92 return;
93 }
94
95 MessageParcel data;
96 MessageParcel reply;
97 MessageOption option;
98 if (!data.WriteInterfaceToken(FaultLoggerServiceProxy::GetDescriptor())) {
99 return;
100 }
101
102 if (remote->SendRequest(static_cast<int>(IFaultLoggerService::IFaultLoggerService_DESTROY),
103 data, reply, option) != ERR_OK) {
104 return;
105 }
106 }
107 } // namespace HiviewDFX
108 } // namespace OHOS
109