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