Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75876a2c authored by Felipe Leme's avatar Felipe Leme
Browse files

Created a dumpstate service.

For now this is still a limited service:

- It's only created when running an interactive bugreport.
- It only provides a listener to get updates.
- It will be just used by Shell to get updates.

Test: dumpstate_test passes
BUG: 31636879

Change-Id: Iae820261d220523c979bf905030456fcf0b2b618
parent 08c3dfde
Loading
Loading
Loading
Loading
+27 −1
Original line number Diff line number Diff line
@@ -15,10 +15,13 @@ COMMON_SRC_FILES := \
        utils.cpp
COMMON_SHARED_LIBRARIES := \
        libbase \
        libbinder \
        libcutils \
        libdumpstateaidl \
        libhardware_legacy \
        liblog \
        libselinux
        libselinux \
        libutils

# ====================#
# libdumpstateheaders #
@@ -39,6 +42,27 @@ LOCAL_STATIC_LIBRARIES := $(LOCAL_EXPORT_STATIC_LIBRARY_HEADERS)

include $(BUILD_STATIC_LIBRARY)

# ================ #
# libdumpstateaidl #
# =================#
include $(CLEAR_VARS)

LOCAL_MODULE := libdumpstateaidl

LOCAL_CFLAGS := $(COMMON_LOCAL_CFLAGS)

LOCAL_SHARED_LIBRARIES := \
        libbinder \
        libutils
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/binder
LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/binder
LOCAL_C_INCLUDES := $(LOCAL_PATH)/binder
LOCAL_SRC_FILES := \
        binder/android/os/IDumpstateListener.aidl \
        binder/android/os/IDumpstate.aidl

include $(BUILD_SHARED_LIBRARY)

# ==========#
# dumpstate #
# ==========#
@@ -49,6 +73,7 @@ LOCAL_CFLAGS := -DFWDUMP_$(BOARD_WLAN_DEVICE)
endif

LOCAL_SRC_FILES := $(COMMON_SRC_FILES) \
        DumpstateService.cpp \
        dumpstate.cpp

LOCAL_MODULE := dumpstate
@@ -77,6 +102,7 @@ LOCAL_MODULE_TAGS := tests
LOCAL_CFLAGS := $(COMMON_LOCAL_CFLAGS)

LOCAL_SRC_FILES := $(COMMON_SRC_FILES) \
        DumpstateService.cpp \
        tests/dumpstate_test.cpp

LOCAL_STATIC_LIBRARIES := $(COMMON_ZIP_LIBRARIES) \
+92 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2016, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "dumpstate"

#include "DumpstateService.h"

#include <android-base/stringprintf.h>

#include "android/os/BnDumpstate.h"

namespace android {
namespace os {

DumpstateService::DumpstateService() : ds_(Dumpstate::GetInstance()) {
}

char const* DumpstateService::getServiceName() {
    return "dumpstate";
}

status_t DumpstateService::Start() {
    IPCThreadState::self()->disableBackgroundScheduling(true);
    status_t ret = BinderService<DumpstateService>::publish();
    if (ret != android::OK) {
        return ret;
    }
    sp<ProcessState> ps(ProcessState::self());
    ps->startThreadPool();
    ps->giveThreadPoolName();
    return android::OK;
}

binder::Status DumpstateService::setListener(const std::string& name,
                                             const sp<IDumpstateListener>& listener, bool* set) {
    if (name.empty()) {
        MYLOGE("setListener(): name not set\n");
        *set = false;
        return binder::Status::ok();
    }
    if (listener == nullptr) {
        MYLOGE("setListener(): listener not set\n");
        *set = false;
        return binder::Status::ok();
    }
    std::lock_guard<std::mutex> lock(lock_);
    if (ds_.listener_ != nullptr) {
        MYLOGE("setListener(%s): already set (%s)\n", name.c_str(), ds_.listener_name_.c_str());
        *set = false;
        return binder::Status::ok();
    }
    ds_.listener_name_ = name;
    ds_.listener_ = listener;
    *set = true;
    return binder::Status::ok();
}

status_t DumpstateService::dump(int fd, const Vector<String16>&) {
    dprintf(fd, "id: %lu\n", ds_.id_);
    dprintf(fd, "pid: %d\n", ds_.pid_);
    dprintf(fd, "progress: %d / %d\n", ds_.progress_, ds_.weight_total_);
    dprintf(fd, "args: %s\n", ds_.args_.c_str());
    dprintf(fd, "extra_options: %s\n", ds_.extra_options_.c_str());
    dprintf(fd, "version: %s\n", ds_.version_.c_str());
    dprintf(fd, "bugreport_dir: %s\n", ds_.bugreport_dir_.c_str());
    dprintf(fd, "screenshot_path: %s\n", ds_.screenshot_path_.c_str());
    dprintf(fd, "log_path: %s\n", ds_.log_path_.c_str());
    dprintf(fd, "tmp_path: %s\n", ds_.tmp_path_.c_str());
    dprintf(fd, "path: %s\n", ds_.extra_options_.c_str());
    dprintf(fd, "base_name: %s\n", ds_.base_name_.c_str());
    dprintf(fd, "name: %s\n", ds_.name_.c_str());
    dprintf(fd, "now: %ld\n", ds_.now_);
    dprintf(fd, "is_zipping: %s\n", ds_.IsZipping() ? "true" : "false");
    dprintf(fd, "listener: %s\n", ds_.listener_name_.c_str());

    return NO_ERROR;
}
}  // namespace os
}  // namespace android
+50 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2016, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_OS_DUMPSTATE_H_
#define ANDROID_OS_DUMPSTATE_H_

#include <mutex>
#include <vector>

#include <binder/BinderService.h>

#include "android/os/BnDumpstate.h"
#include "dumpstate.h"

namespace android {
namespace os {

class DumpstateService : public BinderService<DumpstateService>, public BnDumpstate {
  public:
    DumpstateService();

    static status_t Start();
    static char const* getServiceName();

    status_t dump(int fd, const Vector<String16>& args) override;
    binder::Status setListener(const std::string& name, const sp<IDumpstateListener>& listener,
                               bool* set) override;

  private:
    Dumpstate& ds_;
    std::mutex lock_;
};

}  // namespace os
}  // namespace android

#endif  // ANDROID_OS_DUMPSTATE_H_
+33 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2016, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.os;

import android.os.IDumpstateListener;

/**
  * Binder interface for the currently running dumpstate process.
  * {@hide}
  */
interface IDumpstate {

    /*
     * Sets the listener for dumpstate progress.
     *
     * Returns true if the listener was set (it's like a Highlander: There Can be Only One).
     */
    boolean setListener(@utf8InCpp String name, IDumpstateListener listener);
}
+27 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2016, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.os;

/**
  * Listener for dumpstate events.
  *
  * {@hide}
  */
interface IDumpstateListener {
    void onProgressUpdated(int progress);
    void onMaxProgressUpdated(int maxProgress);
}
Loading