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_stub.h"
16
17 #include "ipc_types.h"
18 #include "message_parcel.h"
19
20 #include "faultlog_info.h"
21 #include "faultlog_info_ohos.h"
22
23 #include "logger.h"
24
25 namespace OHOS {
26 namespace HiviewDFX {
27 DEFINE_LOG_TAG("FaultLoggerServiceStub");
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int FaultLoggerServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
29 MessageParcel &reply, MessageOption &option)
30 {
31 std::u16string descripter = FaultLoggerServiceStub::GetDescriptor();
32 std::u16string remoteDescripter = data.ReadInterfaceToken();
33 if (descripter != remoteDescripter) {
34 HIVIEW_LOGE("read descriptor failed.");
35 return -1;
36 }
37
38 switch (code) {
39 case IFaultLoggerService_ADD_FAULTLOG: {
40 sptr<FaultLogInfoOhos> ohosInfo = FaultLogInfoOhos::Unmarshalling(data);
41 if (ohosInfo == nullptr) {
42 HIVIEW_LOGE("failed to Unmarshalling info.");
43 return ERR_FLATTEN_OBJECT;
44 }
45
46 FaultLogInfoOhos info(*ohosInfo);
47 AddFaultLog(info);
48 return ERR_OK;
49 }
50 case IFaultLoggerService_QUERY_SELF_FAULTLOG: {
51 int32_t type = data.ReadInt32();
52 int32_t maxNum = data.ReadInt32();
53 auto result = QuerySelfFaultLog(type, maxNum);
54 if (result == nullptr) {
55 HIVIEW_LOGE("failed to query self log.");
56 return -1;
57 }
58
59 if (!reply.WriteRemoteObject(result)) {
60 HIVIEW_LOGE("failed to write query result.");
61 return ERR_FLATTEN_OBJECT;
62 }
63 return ERR_OK;
64 }
65 case IFaultLoggerService_DESTROY: {
66 Destroy();
67 return ERR_OK;
68 }
69
70 default:
71 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
72 }
73 }
74 } // namespace HiviewDFX
75 } // namespace OHOS
76