175876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme/**
275876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme * Copyright (c) 2016, The Android Open Source Project
375876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme *
475876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme * Licensed under the Apache License, Version 2.0 (the "License");
575876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme * you may not use this file except in compliance with the License.
675876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme * You may obtain a copy of the License at
775876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme *
875876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme *     http://www.apache.org/licenses/LICENSE-2.0
975876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme *
1075876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme * Unless required by applicable law or agreed to in writing, software
1175876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme * distributed under the License is distributed on an "AS IS" BASIS,
1275876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1375876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme * See the License for the specific language governing permissions and
1475876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme * limitations under the License.
1575876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme */
1675876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme
1775876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme#define LOG_TAG "dumpstate"
1875876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme
1975876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme#include "DumpstateService.h"
2075876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme
2175876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme#include <android-base/stringprintf.h>
2275876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme
2375876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme#include "android/os/BnDumpstate.h"
2475876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme
25f029297f673ae06d219bd727a318a48b885db6fdFelipe Leme#include "DumpstateInternal.h"
26f029297f673ae06d219bd727a318a48b885db6fdFelipe Leme
2775876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Lemenamespace android {
2875876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Lemenamespace os {
2975876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme
30009ecbbd3fcfd06735b0102f0342fc7e60166d9bFelipe Lemenamespace {
31009ecbbd3fcfd06735b0102f0342fc7e60166d9bFelipe Lemeclass DumpstateToken : public BnDumpstateToken {};
32009ecbbd3fcfd06735b0102f0342fc7e60166d9bFelipe Leme}
33009ecbbd3fcfd06735b0102f0342fc7e60166d9bFelipe Leme
3475876a2c0649b8cde36329ca0a1dc6e349af6493Felipe LemeDumpstateService::DumpstateService() : ds_(Dumpstate::GetInstance()) {
3575876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme}
3675876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme
3775876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Lemechar const* DumpstateService::getServiceName() {
3875876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    return "dumpstate";
3975876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme}
4075876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme
4175876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Lemestatus_t DumpstateService::Start() {
4275876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    IPCThreadState::self()->disableBackgroundScheduling(true);
4375876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    status_t ret = BinderService<DumpstateService>::publish();
4475876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    if (ret != android::OK) {
4575876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme        return ret;
4675876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    }
4775876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    sp<ProcessState> ps(ProcessState::self());
4875876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    ps->startThreadPool();
4975876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    ps->giveThreadPoolName();
5075876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    return android::OK;
5175876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme}
5275876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme
5375876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Lemebinder::Status DumpstateService::setListener(const std::string& name,
54009ecbbd3fcfd06735b0102f0342fc7e60166d9bFelipe Leme                                             const sp<IDumpstateListener>& listener,
55009ecbbd3fcfd06735b0102f0342fc7e60166d9bFelipe Leme                                             sp<IDumpstateToken>* returned_token) {
56009ecbbd3fcfd06735b0102f0342fc7e60166d9bFelipe Leme    *returned_token = nullptr;
5775876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    if (name.empty()) {
5875876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme        MYLOGE("setListener(): name not set\n");
5975876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme        return binder::Status::ok();
6075876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    }
6175876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    if (listener == nullptr) {
6275876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme        MYLOGE("setListener(): listener not set\n");
6375876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme        return binder::Status::ok();
6475876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    }
6575876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    std::lock_guard<std::mutex> lock(lock_);
6675876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    if (ds_.listener_ != nullptr) {
6775876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme        MYLOGE("setListener(%s): already set (%s)\n", name.c_str(), ds_.listener_name_.c_str());
6875876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme        return binder::Status::ok();
6975876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    }
70009ecbbd3fcfd06735b0102f0342fc7e60166d9bFelipe Leme
7175876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    ds_.listener_name_ = name;
7275876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    ds_.listener_ = listener;
73009ecbbd3fcfd06735b0102f0342fc7e60166d9bFelipe Leme    *returned_token = new DumpstateToken();
74009ecbbd3fcfd06735b0102f0342fc7e60166d9bFelipe Leme
7575876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    return binder::Status::ok();
7675876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme}
7775876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme
7875876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Lemestatus_t DumpstateService::dump(int fd, const Vector<String16>&) {
797447d7c3d74b28f1a071b1d3503212cc8ad08d68Felipe Leme    dprintf(fd, "id: %d\n", ds_.id_);
8075876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    dprintf(fd, "pid: %d\n", ds_.pid_);
81009ecbbd3fcfd06735b0102f0342fc7e60166d9bFelipe Leme    dprintf(fd, "update_progress: %s\n", ds_.update_progress_ ? "true" : "false");
82009ecbbd3fcfd06735b0102f0342fc7e60166d9bFelipe Leme    dprintf(fd, "update_progress_threshold: %d\n", ds_.update_progress_threshold_);
83009ecbbd3fcfd06735b0102f0342fc7e60166d9bFelipe Leme    dprintf(fd, "last_updated_progress: %d\n", ds_.last_updated_progress_);
847447d7c3d74b28f1a071b1d3503212cc8ad08d68Felipe Leme    dprintf(fd, "progress:\n");
857447d7c3d74b28f1a071b1d3503212cc8ad08d68Felipe Leme    ds_.progress_->Dump(fd, "  ");
8675876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    dprintf(fd, "args: %s\n", ds_.args_.c_str());
8775876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    dprintf(fd, "extra_options: %s\n", ds_.extra_options_.c_str());
8875876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    dprintf(fd, "version: %s\n", ds_.version_.c_str());
8975876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    dprintf(fd, "bugreport_dir: %s\n", ds_.bugreport_dir_.c_str());
9075876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    dprintf(fd, "screenshot_path: %s\n", ds_.screenshot_path_.c_str());
9175876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    dprintf(fd, "log_path: %s\n", ds_.log_path_.c_str());
9275876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    dprintf(fd, "tmp_path: %s\n", ds_.tmp_path_.c_str());
937447d7c3d74b28f1a071b1d3503212cc8ad08d68Felipe Leme    dprintf(fd, "path: %s\n", ds_.path_.c_str());
947447d7c3d74b28f1a071b1d3503212cc8ad08d68Felipe Leme    dprintf(fd, "extra_options: %s\n", ds_.extra_options_.c_str());
9575876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    dprintf(fd, "base_name: %s\n", ds_.base_name_.c_str());
9675876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    dprintf(fd, "name: %s\n", ds_.name_.c_str());
9775876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    dprintf(fd, "now: %ld\n", ds_.now_);
9875876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    dprintf(fd, "is_zipping: %s\n", ds_.IsZipping() ? "true" : "false");
9975876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    dprintf(fd, "listener: %s\n", ds_.listener_name_.c_str());
100b53a1c9b4df27a7a66c9448778eace166a0ce14cNaveen Kalla    dprintf(fd, "notification title: %s\n", ds_.notification_title.c_str());
101b53a1c9b4df27a7a66c9448778eace166a0ce14cNaveen Kalla    dprintf(fd, "notification description: %s\n", ds_.notification_description.c_str());
10275876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme
10375876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme    return NO_ERROR;
10475876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme}
10575876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme}  // namespace os
10675876a2c0649b8cde36329ca0a1dc6e349af6493Felipe Leme}  // namespace android
107