DumpstateService.cpp revision 7447d7c3d74b28f1a071b1d3503212cc8ad08d68
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 25namespace android { 26namespace os { 27 28DumpstateService::DumpstateService() : ds_(Dumpstate::GetInstance()) { 29} 30 31char const* DumpstateService::getServiceName() { 32 return "dumpstate"; 33} 34 35status_t DumpstateService::Start() { 36 IPCThreadState::self()->disableBackgroundScheduling(true); 37 status_t ret = BinderService<DumpstateService>::publish(); 38 if (ret != android::OK) { 39 return ret; 40 } 41 sp<ProcessState> ps(ProcessState::self()); 42 ps->startThreadPool(); 43 ps->giveThreadPoolName(); 44 return android::OK; 45} 46 47binder::Status DumpstateService::setListener(const std::string& name, 48 const sp<IDumpstateListener>& listener, bool* set) { 49 if (name.empty()) { 50 MYLOGE("setListener(): name not set\n"); 51 *set = false; 52 return binder::Status::ok(); 53 } 54 if (listener == nullptr) { 55 MYLOGE("setListener(): listener not set\n"); 56 *set = false; 57 return binder::Status::ok(); 58 } 59 std::lock_guard<std::mutex> lock(lock_); 60 if (ds_.listener_ != nullptr) { 61 MYLOGE("setListener(%s): already set (%s)\n", name.c_str(), ds_.listener_name_.c_str()); 62 *set = false; 63 return binder::Status::ok(); 64 } 65 ds_.listener_name_ = name; 66 ds_.listener_ = listener; 67 *set = true; 68 return binder::Status::ok(); 69} 70 71status_t DumpstateService::dump(int fd, const Vector<String16>&) { 72 dprintf(fd, "id: %d\n", ds_.id_); 73 dprintf(fd, "pid: %d\n", ds_.pid_); 74 dprintf(fd, "progress:\n"); 75 ds_.progress_->Dump(fd, " "); 76 dprintf(fd, "args: %s\n", ds_.args_.c_str()); 77 dprintf(fd, "extra_options: %s\n", ds_.extra_options_.c_str()); 78 dprintf(fd, "version: %s\n", ds_.version_.c_str()); 79 dprintf(fd, "bugreport_dir: %s\n", ds_.bugreport_dir_.c_str()); 80 dprintf(fd, "screenshot_path: %s\n", ds_.screenshot_path_.c_str()); 81 dprintf(fd, "log_path: %s\n", ds_.log_path_.c_str()); 82 dprintf(fd, "tmp_path: %s\n", ds_.tmp_path_.c_str()); 83 dprintf(fd, "path: %s\n", ds_.path_.c_str()); 84 dprintf(fd, "extra_options: %s\n", ds_.extra_options_.c_str()); 85 dprintf(fd, "base_name: %s\n", ds_.base_name_.c_str()); 86 dprintf(fd, "name: %s\n", ds_.name_.c_str()); 87 dprintf(fd, "now: %ld\n", ds_.now_); 88 dprintf(fd, "is_zipping: %s\n", ds_.IsZipping() ? "true" : "false"); 89 dprintf(fd, "listener: %s\n", ds_.listener_name_.c_str()); 90 91 return NO_ERROR; 92} 93} // namespace os 94} // namespace android 95