• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "dump_broker_stub.h"
16 #include <message_parcel.h>
17 #include "dump_errors.h"
18 #include "hidumper_service_ipc_interface_code.h"
19 #include "hilog_wrapper.h"
20 namespace OHOS {
21 namespace HiviewDFX {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)22 int DumpBrokerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
23 {
24     std::u16string descripter = DumpBrokerStub::GetDescriptor();
25     std::u16string remoteDescripter = data.ReadInterfaceToken();
26     if (descripter != remoteDescripter) {
27         return ERROR_GET_DUMPER_SERVICE;
28     }
29     int ret = ERR_OK;
30     switch (code) {
31         case static_cast<int>(HidumperServiceInterfaceCode::DUMP_REQUEST_FILEFD): {
32             DUMPER_HILOGD(MODULE_ZIDL, "debug|RequestFileFdStub");
33             ret = RequestFileFdStub(data, reply);
34             break;
35         }
36         case static_cast<int>(HidumperServiceInterfaceCode::SCAN_PID_OVER_LIMIT): {
37             DUMPER_HILOGD(MODULE_ZIDL, "debug|ScanPidOverLimitStub");
38             ret = ScanPidOverLimitStub(data, reply);
39             break;
40         }
41         case static_cast<int>(HidumperServiceInterfaceCode::COUNT_FD_NUMS): {
42             DUMPER_HILOGD(MODULE_ZIDL, "debug|CountFdNumsStub");
43             ret = CountFdNumsStub(data, reply);
44             break;
45         }
46         default: {
47             ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
48             break;
49         }
50     }
51     return ret;
52 }
53 
RequestFileFdStub(MessageParcel & data,MessageParcel & reply)54 int32_t DumpBrokerStub::RequestFileFdStub(MessageParcel& data, MessageParcel& reply)
55 {
56     int32_t ret = ERR_OK;
57     std::vector<std::u16string> args;
58     if (!data.ReadString16Vector(&args)) {
59         return ERROR_READ_PARCEL;
60     }
61     int outfd = data.ReadFileDescriptor();
62     int32_t res = Request(args, outfd);
63     if (!reply.WriteInt32(res)) {
64         return ERROR_WRITE_PARCEL;
65     }
66     return ret;
67 }
68 
ScanPidOverLimitStub(MessageParcel & data,MessageParcel & reply)69 int32_t DumpBrokerStub::ScanPidOverLimitStub(MessageParcel& data, MessageParcel& reply)
70 {
71     int32_t ret = ERR_OK;
72     std::vector<int32_t> pidList;
73     std::string requestType = data.ReadString();
74     int32_t limitSize = data.ReadInt32();
75     ret = ScanPidOverLimit(requestType, limitSize, pidList);
76     if (!reply.WriteInt32Vector(pidList)) {
77         return ERROR_WRITE_PARCEL;
78     }
79     if (!reply.WriteInt32(ret)) {
80         return ERROR_WRITE_PARCEL;
81     }
82     return ret;
83 }
84 
CountFdNumsStub(MessageParcel & data,MessageParcel & reply)85 int32_t DumpBrokerStub::CountFdNumsStub(MessageParcel& data, MessageParcel& reply)
86 {
87     int32_t ret = ERR_OK;
88     uint32_t fdNums = 0;
89     std::string detailFdInfo;
90     std::string topLeakedType;
91 
92     int32_t pid = data.ReadInt32();
93     ret = CountFdNums(pid, fdNums, detailFdInfo, topLeakedType);
94     if (!reply.WriteInt32(fdNums)) {
95         return ERROR_WRITE_PARCEL;
96     }
97     if (!reply.WriteString(detailFdInfo)) {
98         return ERROR_WRITE_PARCEL;
99     }
100     if (!reply.WriteString(topLeakedType)) {
101         return ERROR_WRITE_PARCEL;
102     }
103     if (!reply.WriteInt32(ret)) {
104         return ERROR_WRITE_PARCEL;
105     }
106     return ret;
107 }
108 } // namespace HiviewDFX
109 } // namespace OHOS
110