blob: 8d1d42b28e53e19a72f205e498b413b610bf806e [file] [log] [blame]
Yifan Hongb84fb572019-03-15 14:19:08 -07001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <limits>
18#include <sstream>
19#include <string>
20#include <vector>
21
22#include <android-base/logging.h>
David Andersonb694b1d2023-07-14 09:02:55 -070023#include <android-base/properties.h>
Yifan Hongb84fb572019-03-15 14:19:08 -070024#include <android-base/strings.h>
25#include <android/lpdump/BnLpdump.h>
26#include <android/lpdump/ILpdump.h>
27#include <binder/IPCThreadState.h>
28#include <binder/IServiceManager.h>
29#include <binder/ProcessState.h>
30
31int LpdumpMain(int argc, char* argv[], std::ostream&, std::ostream&);
32
33namespace android {
34namespace lpdump {
35
36using binder::Status;
37
38class Lpdump : public BnLpdump {
39 public:
40 Lpdump() = default;
41 virtual ~Lpdump() = default;
42
43 Status run(const std::vector<std::string>& args, std::string* aidl_return) override {
David Anderson6b7a5822019-11-19 17:04:39 -080044 std::vector<char*> local_argv;
45 std::vector<std::string> local_args = args;
46 for (auto& arg : local_args) {
47 local_argv.push_back(arg.data());
Yifan Hongb84fb572019-03-15 14:19:08 -070048 }
49 LOG(DEBUG) << "Dumping with args: " << base::Join(args, " ");
50 std::stringstream output;
Yifan Hong9960b982019-03-28 10:42:05 -070051 std::stringstream error;
David Anderson6b7a5822019-11-19 17:04:39 -080052 int ret = LpdumpMain((int)local_argv.size(), local_argv.data(), output, error);
Yifan Hong9960b982019-03-28 10:42:05 -070053 std::string error_str = error.str();
Sandeep Dhavaleacb75462024-08-19 13:56:40 -070054 if (ret == 0) {
55 if (!error_str.empty()) {
56 LOG(WARNING) << error_str;
57 }
58 *aidl_return = output.str();
59 return Status::ok();
60 } else {
Yifan Hong9960b982019-03-28 10:42:05 -070061 return Status::fromServiceSpecificError(ret, error_str.c_str());
Yifan Hongb84fb572019-03-15 14:19:08 -070062 }
Yifan Hongb84fb572019-03-15 14:19:08 -070063 }
64};
65
66} // namespace lpdump
67} // namespace android
68
69int main(int, char**) {
70 using namespace android;
71
72 sp<lpdump::Lpdump> service = new lpdump::Lpdump();
73 defaultServiceManager()->addService(String16("lpdump_service"), service);
74 LOG(VERBOSE) << "lpdumpd starting";
75 ProcessState::self()->startThreadPool();
76 IPCThreadState::self()->joinThreadPool();
77 return 0;
78}