Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 1 | /** |
| 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 | |
Felipe Leme | f029297 | 2016-11-22 13:57:05 -0800 | [diff] [blame] | 25 | #include "DumpstateInternal.h" |
| 26 | |
Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 27 | namespace android { |
| 28 | namespace os { |
| 29 | |
Felipe Leme | 009ecbb | 2016-11-07 10:18:44 -0800 | [diff] [blame] | 30 | namespace { |
| 31 | class DumpstateToken : public BnDumpstateToken {}; |
| 32 | } |
| 33 | |
Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 34 | DumpstateService::DumpstateService() : ds_(Dumpstate::GetInstance()) { |
| 35 | } |
| 36 | |
| 37 | char const* DumpstateService::getServiceName() { |
| 38 | return "dumpstate"; |
| 39 | } |
| 40 | |
| 41 | status_t DumpstateService::Start() { |
| 42 | IPCThreadState::self()->disableBackgroundScheduling(true); |
| 43 | status_t ret = BinderService<DumpstateService>::publish(); |
| 44 | if (ret != android::OK) { |
| 45 | return ret; |
| 46 | } |
| 47 | sp<ProcessState> ps(ProcessState::self()); |
| 48 | ps->startThreadPool(); |
| 49 | ps->giveThreadPoolName(); |
| 50 | return android::OK; |
| 51 | } |
| 52 | |
| 53 | binder::Status DumpstateService::setListener(const std::string& name, |
Felipe Leme | 009ecbb | 2016-11-07 10:18:44 -0800 | [diff] [blame] | 54 | const sp<IDumpstateListener>& listener, |
Vishnu Nair | 20cf503 | 2018-01-05 13:15:49 -0800 | [diff] [blame^] | 55 | bool getSectionDetails, |
Felipe Leme | 009ecbb | 2016-11-07 10:18:44 -0800 | [diff] [blame] | 56 | sp<IDumpstateToken>* returned_token) { |
| 57 | *returned_token = nullptr; |
Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 58 | if (name.empty()) { |
| 59 | MYLOGE("setListener(): name not set\n"); |
Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 60 | return binder::Status::ok(); |
| 61 | } |
| 62 | if (listener == nullptr) { |
| 63 | MYLOGE("setListener(): listener not set\n"); |
Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 64 | return binder::Status::ok(); |
| 65 | } |
| 66 | std::lock_guard<std::mutex> lock(lock_); |
| 67 | if (ds_.listener_ != nullptr) { |
| 68 | MYLOGE("setListener(%s): already set (%s)\n", name.c_str(), ds_.listener_name_.c_str()); |
Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 69 | return binder::Status::ok(); |
| 70 | } |
Felipe Leme | 009ecbb | 2016-11-07 10:18:44 -0800 | [diff] [blame] | 71 | |
Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 72 | ds_.listener_name_ = name; |
| 73 | ds_.listener_ = listener; |
Vishnu Nair | 20cf503 | 2018-01-05 13:15:49 -0800 | [diff] [blame^] | 74 | ds_.report_section_ = getSectionDetails; |
Felipe Leme | 009ecbb | 2016-11-07 10:18:44 -0800 | [diff] [blame] | 75 | *returned_token = new DumpstateToken(); |
| 76 | |
Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 77 | return binder::Status::ok(); |
| 78 | } |
| 79 | |
| 80 | status_t DumpstateService::dump(int fd, const Vector<String16>&) { |
Felipe Leme | 7447d7c | 2016-11-03 18:12:22 -0700 | [diff] [blame] | 81 | dprintf(fd, "id: %d\n", ds_.id_); |
Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 82 | dprintf(fd, "pid: %d\n", ds_.pid_); |
Felipe Leme | 009ecbb | 2016-11-07 10:18:44 -0800 | [diff] [blame] | 83 | dprintf(fd, "update_progress: %s\n", ds_.update_progress_ ? "true" : "false"); |
| 84 | dprintf(fd, "update_progress_threshold: %d\n", ds_.update_progress_threshold_); |
| 85 | dprintf(fd, "last_updated_progress: %d\n", ds_.last_updated_progress_); |
Felipe Leme | 7447d7c | 2016-11-03 18:12:22 -0700 | [diff] [blame] | 86 | dprintf(fd, "progress:\n"); |
| 87 | ds_.progress_->Dump(fd, " "); |
Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 88 | dprintf(fd, "args: %s\n", ds_.args_.c_str()); |
| 89 | dprintf(fd, "extra_options: %s\n", ds_.extra_options_.c_str()); |
| 90 | dprintf(fd, "version: %s\n", ds_.version_.c_str()); |
| 91 | dprintf(fd, "bugreport_dir: %s\n", ds_.bugreport_dir_.c_str()); |
| 92 | dprintf(fd, "screenshot_path: %s\n", ds_.screenshot_path_.c_str()); |
| 93 | dprintf(fd, "log_path: %s\n", ds_.log_path_.c_str()); |
| 94 | dprintf(fd, "tmp_path: %s\n", ds_.tmp_path_.c_str()); |
Felipe Leme | 7447d7c | 2016-11-03 18:12:22 -0700 | [diff] [blame] | 95 | dprintf(fd, "path: %s\n", ds_.path_.c_str()); |
| 96 | dprintf(fd, "extra_options: %s\n", ds_.extra_options_.c_str()); |
Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 97 | dprintf(fd, "base_name: %s\n", ds_.base_name_.c_str()); |
| 98 | dprintf(fd, "name: %s\n", ds_.name_.c_str()); |
| 99 | dprintf(fd, "now: %ld\n", ds_.now_); |
| 100 | dprintf(fd, "is_zipping: %s\n", ds_.IsZipping() ? "true" : "false"); |
| 101 | dprintf(fd, "listener: %s\n", ds_.listener_name_.c_str()); |
Naveen Kalla | b53a1c9 | 2017-03-16 18:17:25 -0700 | [diff] [blame] | 102 | dprintf(fd, "notification title: %s\n", ds_.notification_title.c_str()); |
| 103 | dprintf(fd, "notification description: %s\n", ds_.notification_description.c_str()); |
Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 104 | |
| 105 | return NO_ERROR; |
| 106 | } |
| 107 | } // namespace os |
| 108 | } // namespace android |