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

Commit 2757d757 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Throttler for incidentd based on size putting into dropbox."

parents 515f5c20 4e843106
Loading
Loading
Loading
Loading
+3 −16
Original line number Diff line number Diff line
@@ -25,16 +25,7 @@ include $(CLEAR_VARS)

LOCAL_MODULE := incidentd

LOCAL_SRC_FILES := \
        src/PrivacyBuffer.cpp \
        src/FdBuffer.cpp \
        src/IncidentService.cpp \
        src/Privacy.cpp \
        src/Reporter.cpp \
        src/Section.cpp \
        src/incidentd_util.cpp \
        src/main.cpp \
        src/report_directory.cpp
LOCAL_SRC_FILES := $(call all-cpp-files-under, src) \

LOCAL_CFLAGS += \
        -Wall -Werror -Wno-missing-field-initializers -Wno-unused-variable -Wunused-parameter
@@ -110,19 +101,15 @@ LOCAL_CFLAGS := -Werror -Wall -Wno-unused-variable -Wunused-parameter

LOCAL_C_INCLUDES += $(LOCAL_PATH)/src

LOCAL_SRC_FILES := \
LOCAL_SRC_FILES := $(call all-cpp-files-under, tests) \
    src/PrivacyBuffer.cpp \
    src/FdBuffer.cpp \
    src/Privacy.cpp \
    src/Reporter.cpp \
    src/Section.cpp \
    src/Throttler.cpp \
    src/incidentd_util.cpp \
    src/report_directory.cpp \
    tests/section_list.cpp \
    tests/PrivacyBuffer_test.cpp \
    tests/FdBuffer_test.cpp \
    tests/Reporter_test.cpp \
    tests/Section_test.cpp \

LOCAL_STATIC_LIBRARIES := \
    libgmock \
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#define DEBUG false
#include "Log.h"

#include "FdBuffer.h"
+28 −6
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#define DEBUG false
#include "Log.h"

#include "IncidentService.h"
@@ -38,9 +39,11 @@ using namespace android::base;

enum { WHAT_RUN_REPORT = 1, WHAT_SEND_BACKLOG_TO_DROPBOX = 2 };

//#define DEFAULT_BACKLOG_DELAY_NS (1000000000LL * 60 * 5)
#define DEFAULT_BACKLOG_DELAY_NS (1000000000LL)

#define DEFAULT_BYTES_SIZE_LIMIT (20 * 1024 * 1024)        // 20MB
#define DEFAULT_REFACTORY_PERIOD_MS (24 * 60 * 60 * 1000)  // 1 Day

// ================================================================================
String16 const DUMP_PERMISSION("android.permission.DUMP");
String16 const USAGE_STATS_PERMISSION("android.permission.PACKAGE_USAGE_STATS");
@@ -113,8 +116,12 @@ sp<ReportRequest> ReportRequestQueue::getNextRequest() {
}

// ================================================================================
ReportHandler::ReportHandler(const sp<Looper>& handlerLooper, const sp<ReportRequestQueue>& queue)
    : mBacklogDelay(DEFAULT_BACKLOG_DELAY_NS), mHandlerLooper(handlerLooper), mQueue(queue) {}
ReportHandler::ReportHandler(const sp<Looper>& handlerLooper, const sp<ReportRequestQueue>& queue,
                             const sp<Throttler>& throttler)
    : mBacklogDelay(DEFAULT_BACKLOG_DELAY_NS),
      mHandlerLooper(handlerLooper),
      mQueue(queue),
      mThrottler(throttler) {}

ReportHandler::~ReportHandler() {}

@@ -159,10 +166,17 @@ void ReportHandler::run_report() {
        reporter->batch.add(request);
    }

    if (mThrottler->shouldThrottle()) {
        ALOGW("RunReport got throttled.");
        return;
    }

    // Take the report, which might take a while. More requests might queue
    // up while we're doing this, and we'll handle them in their next batch.
    // TODO: We should further rate-limit the reports to no more than N per time-period.
    Reporter::run_report_status_t reportStatus = reporter->runReport();
    size_t reportByteSize = 0;
    Reporter::run_report_status_t reportStatus = reporter->runReport(&reportByteSize);
    mThrottler->addReportSize(reportByteSize);
    if (reportStatus == Reporter::REPORT_NEEDS_DROPBOX) {
        unique_lock<mutex> lock(mLock);
        schedule_send_backlog_to_dropbox_locked();
@@ -184,8 +198,9 @@ void ReportHandler::send_backlog_to_dropbox() {

// ================================================================================
IncidentService::IncidentService(const sp<Looper>& handlerLooper)
    : mQueue(new ReportRequestQueue()) {
    mHandler = new ReportHandler(handlerLooper, mQueue);
    : mQueue(new ReportRequestQueue()),
      mThrottler(new Throttler(DEFAULT_BYTES_SIZE_LIMIT, DEFAULT_REFACTORY_PERIOD_MS)) {
    mHandler = new ReportHandler(handlerLooper, mQueue, mThrottler);
}

IncidentService::~IncidentService() {}
@@ -294,6 +309,10 @@ status_t IncidentService::command(FILE* in, FILE* out, FILE* err, Vector<String8
        if (!args[0].compare(String8("privacy"))) {
            return cmd_privacy(in, out, err, args);
        }
        if (!args[0].compare(String8("throttler"))) {
            mThrottler->dump(out);
            return NO_ERROR;
        }
    }
    return cmd_help(out);
}
@@ -302,6 +321,9 @@ status_t IncidentService::cmd_help(FILE* out) {
    fprintf(out, "usage: adb shell cmd incident privacy print <section_id>\n");
    fprintf(out, "usage: adb shell cmd incident privacy parse <section_id> < proto.txt\n");
    fprintf(out, "    Prints/parses for the section id.\n");
    fprintf(out, "\n");
    fprintf(out, "usage: adb shell cmd incident throttler\n");
    fprintf(out, "    Prints the current throttler state\n");
    return NO_ERROR;
}

+6 −1
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@
#include <deque>
#include <mutex>

#include "Throttler.h"

using namespace android;
using namespace android::base;
using namespace android::binder;
@@ -49,7 +51,8 @@ private:
// ================================================================================
class ReportHandler : public MessageHandler {
public:
    ReportHandler(const sp<Looper>& handlerLooper, const sp<ReportRequestQueue>& queue);
    ReportHandler(const sp<Looper>& handlerLooper, const sp<ReportRequestQueue>& queue,
                  const sp<Throttler>& throttler);
    virtual ~ReportHandler();

    virtual void handleMessage(const Message& message);
@@ -70,6 +73,7 @@ private:
    nsecs_t mBacklogDelay;
    sp<Looper> mHandlerLooper;
    sp<ReportRequestQueue> mQueue;
    sp<Throttler> mThrottler;

    /**
     * Runs all of the reports that have been queued.
@@ -109,6 +113,7 @@ public:
private:
    sp<ReportRequestQueue> mQueue;
    sp<ReportHandler> mHandler;
    sp<Throttler> mThrottler;

    /**
     * Commands print out help.
+0 −1
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@
#pragma once

#define LOG_TAG "incidentd"
#define DEBUG false

#include <log/log.h>

Loading