blob: f2dcf2ba3043cf789a52f782a07925aace11059c [file] [log] [blame]
Felipe Leme75876a22016-10-27 16:31:27 -07001/**
2 * Copyright (c) 2016, 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#define LOG_TAG "dumpstate"
18
19#include "DumpstateService.h"
20
21#include <android-base/stringprintf.h>
22
23#include "android/os/BnDumpstate.h"
24
25namespace android {
26namespace os {
27
Felipe Leme009ecbb2016-11-07 10:18:44 -080028namespace {
29class DumpstateToken : public BnDumpstateToken {};
30}
31
Felipe Leme75876a22016-10-27 16:31:27 -070032DumpstateService::DumpstateService() : ds_(Dumpstate::GetInstance()) {
33}
34
35char const* DumpstateService::getServiceName() {
36 return "dumpstate";
37}
38
39status_t DumpstateService::Start() {
40 IPCThreadState::self()->disableBackgroundScheduling(true);
41 status_t ret = BinderService<DumpstateService>::publish();
42 if (ret != android::OK) {
43 return ret;
44 }
45 sp<ProcessState> ps(ProcessState::self());
46 ps->startThreadPool();
47 ps->giveThreadPoolName();
48 return android::OK;
49}
50
51binder::Status DumpstateService::setListener(const std::string& name,
Felipe Leme009ecbb2016-11-07 10:18:44 -080052 const sp<IDumpstateListener>& listener,
53 sp<IDumpstateToken>* returned_token) {
54 *returned_token = nullptr;
Felipe Leme75876a22016-10-27 16:31:27 -070055 if (name.empty()) {
56 MYLOGE("setListener(): name not set\n");
Felipe Leme75876a22016-10-27 16:31:27 -070057 return binder::Status::ok();
58 }
59 if (listener == nullptr) {
60 MYLOGE("setListener(): listener not set\n");
Felipe Leme75876a22016-10-27 16:31:27 -070061 return binder::Status::ok();
62 }
63 std::lock_guard<std::mutex> lock(lock_);
64 if (ds_.listener_ != nullptr) {
65 MYLOGE("setListener(%s): already set (%s)\n", name.c_str(), ds_.listener_name_.c_str());
Felipe Leme75876a22016-10-27 16:31:27 -070066 return binder::Status::ok();
67 }
Felipe Leme009ecbb2016-11-07 10:18:44 -080068
Felipe Leme75876a22016-10-27 16:31:27 -070069 ds_.listener_name_ = name;
70 ds_.listener_ = listener;
Felipe Leme009ecbb2016-11-07 10:18:44 -080071 *returned_token = new DumpstateToken();
72
Felipe Leme75876a22016-10-27 16:31:27 -070073 return binder::Status::ok();
74}
75
76status_t DumpstateService::dump(int fd, const Vector<String16>&) {
Felipe Leme7447d7c2016-11-03 18:12:22 -070077 dprintf(fd, "id: %d\n", ds_.id_);
Felipe Leme75876a22016-10-27 16:31:27 -070078 dprintf(fd, "pid: %d\n", ds_.pid_);
Felipe Leme009ecbb2016-11-07 10:18:44 -080079 dprintf(fd, "update_progress: %s\n", ds_.update_progress_ ? "true" : "false");
80 dprintf(fd, "update_progress_threshold: %d\n", ds_.update_progress_threshold_);
81 dprintf(fd, "last_updated_progress: %d\n", ds_.last_updated_progress_);
Felipe Leme7447d7c2016-11-03 18:12:22 -070082 dprintf(fd, "progress:\n");
83 ds_.progress_->Dump(fd, " ");
Felipe Leme75876a22016-10-27 16:31:27 -070084 dprintf(fd, "args: %s\n", ds_.args_.c_str());
85 dprintf(fd, "extra_options: %s\n", ds_.extra_options_.c_str());
86 dprintf(fd, "version: %s\n", ds_.version_.c_str());
87 dprintf(fd, "bugreport_dir: %s\n", ds_.bugreport_dir_.c_str());
88 dprintf(fd, "screenshot_path: %s\n", ds_.screenshot_path_.c_str());
89 dprintf(fd, "log_path: %s\n", ds_.log_path_.c_str());
90 dprintf(fd, "tmp_path: %s\n", ds_.tmp_path_.c_str());
Felipe Leme7447d7c2016-11-03 18:12:22 -070091 dprintf(fd, "path: %s\n", ds_.path_.c_str());
92 dprintf(fd, "extra_options: %s\n", ds_.extra_options_.c_str());
Felipe Leme75876a22016-10-27 16:31:27 -070093 dprintf(fd, "base_name: %s\n", ds_.base_name_.c_str());
94 dprintf(fd, "name: %s\n", ds_.name_.c_str());
95 dprintf(fd, "now: %ld\n", ds_.now_);
96 dprintf(fd, "is_zipping: %s\n", ds_.IsZipping() ? "true" : "false");
97 dprintf(fd, "listener: %s\n", ds_.listener_name_.c_str());
98
99 return NO_ERROR;
100}
101} // namespace os
102} // namespace android