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

Commit 635a109f authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 5240105 from d231c6ad to qt-release

Change-Id: I9a5181801e5212e13259e4db0aa9d9efde25b574
parents 9b22ca97 d231c6ad
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -2262,6 +2262,28 @@ void Dumpstate::SetOptions(std::unique_ptr<DumpOptions> options) {
    options_ = std::move(options);
}

Dumpstate::RunStatus Dumpstate::Run() {
    Dumpstate::RunStatus status = RunInternal();
    if (listener_ != nullptr) {
        switch (status) {
            case Dumpstate::RunStatus::OK:
                // TODO(b/111441001): duration argument does not make sense. Remove.
                listener_->onFinished(0 /* duration */, options_->notification_title,
                                      options_->notification_description);
                break;
            case Dumpstate::RunStatus::HELP:
                break;
            case Dumpstate::RunStatus::INVALID_INPUT:
                listener_->onError(android::os::IDumpstateListener::BUGREPORT_ERROR_INVALID_INPUT);
                break;
            case Dumpstate::RunStatus::ERROR:
                listener_->onError(android::os::IDumpstateListener::BUGREPORT_ERROR_RUNTIME_ERROR);
                break;
        }
    }
    return status;
}

/*
 * Dumps relevant information to a bugreport based on the given options.
 *
@@ -2283,7 +2305,7 @@ void Dumpstate::SetOptions(std::unique_ptr<DumpOptions> options) {
 * Bugreports are first generated in a local directory and later copied to the caller's fd or
 * directory.
 */
Dumpstate::RunStatus Dumpstate::Run() {
Dumpstate::RunStatus Dumpstate::RunInternal() {
    LogDumpOptions(*options_);
    if (!options_->ValidateOptions()) {
        MYLOGE("Invalid options specified\n");
@@ -2488,6 +2510,7 @@ Dumpstate::RunStatus Dumpstate::Run() {
    /* tell activity manager we're done */
    if (options_->do_broadcast) {
        SendBugreportFinishedBroadcast();
        // Note that listener_ is notified in Run();
    }

    MYLOGD("Final progress: %d/%d (estimated %d)\n", progress_->Get(), progress_->GetMax(),
+2 −0
Original line number Diff line number Diff line
@@ -449,6 +449,8 @@ class Dumpstate {
    std::vector<DumpData> anr_data_;

  private:
    RunStatus RunInternal();

    // Used by GetInstance() only.
    explicit Dumpstate(const std::string& version = VERSION_CURRENT);

+10 −2
Original line number Diff line number Diff line
@@ -656,8 +656,9 @@ class DumpstateTest : public DumpstateBaseTest {
        }

        if (update_progress) {
            message += android::base::StringPrintf("Setting progress (%s): %d/%d\n",
                                                   listener_name.c_str(), progress, max);
            message += android::base::StringPrintf("Setting progress (%s): %d/%d (%d%%)\n",
                                                   listener_name.c_str(), progress, max,
                                                   (100 * progress / max));
        }

        return message;
@@ -816,12 +817,14 @@ TEST_F(DumpstateTest, RunCommandProgress) {
    SetProgress(0, 30);

    EXPECT_CALL(*listener, onProgressUpdated(20));
    EXPECT_CALL(*listener, onProgress(66));  // 20/30 %
    EXPECT_EQ(0, RunCommand("", {kSimpleCommand}, CommandOptions::WithTimeout(20).Build()));
    std::string progress_message = GetProgressMessage(ds.listener_name_, 20, 30);
    EXPECT_THAT(out, StrEq("stdout\n"));
    EXPECT_THAT(err, StrEq("stderr\n" + progress_message));

    EXPECT_CALL(*listener, onProgressUpdated(30));
    EXPECT_CALL(*listener, onProgress(100));  // 35/35 %
    EXPECT_EQ(0, RunCommand("", {kSimpleCommand}, CommandOptions::WithTimeout(10).Build()));
    progress_message = GetProgressMessage(ds.listener_name_, 30, 30);
    EXPECT_THAT(out, StrEq("stdout\n"));
@@ -830,6 +833,7 @@ TEST_F(DumpstateTest, RunCommandProgress) {
    // Run a command that will increase maximum timeout.
    EXPECT_CALL(*listener, onProgressUpdated(31));
    EXPECT_CALL(*listener, onMaxProgressUpdated(37));
    EXPECT_CALL(*listener, onProgress(83));  // 31/37 %
    EXPECT_EQ(0, RunCommand("", {kSimpleCommand}, CommandOptions::WithTimeout(1).Build()));
    progress_message = GetProgressMessage(ds.listener_name_, 31, 37, 30);  // 20% increase
    EXPECT_THAT(out, StrEq("stdout\n"));
@@ -838,6 +842,7 @@ TEST_F(DumpstateTest, RunCommandProgress) {
    // Make sure command ran while in dry_run is counted.
    SetDryRun(true);
    EXPECT_CALL(*listener, onProgressUpdated(35));
    EXPECT_CALL(*listener, onProgress(94));  // 35/37 %
    EXPECT_EQ(0, RunCommand("", {kSimpleCommand}, CommandOptions::WithTimeout(4).Build()));
    progress_message = GetProgressMessage(ds.listener_name_, 35, 37);
    EXPECT_THAT(out, IsEmpty());
@@ -854,6 +859,7 @@ TEST_F(DumpstateTest, RunCommandProgressIgnoreThreshold) {

    // First update should always be sent.
    EXPECT_CALL(*listener, onProgressUpdated(1));
    EXPECT_CALL(*listener, onProgress(12));  // 1/12 %
    EXPECT_EQ(0, RunCommand("", {kSimpleCommand}, CommandOptions::WithTimeout(1).Build()));
    std::string progress_message = GetProgressMessage(ds.listener_name_, 1, 8);
    EXPECT_THAT(out, StrEq("stdout\n"));
@@ -866,6 +872,7 @@ TEST_F(DumpstateTest, RunCommandProgressIgnoreThreshold) {

    // Third update should be sent because it reaches threshold (6 - 1 = 5).
    EXPECT_CALL(*listener, onProgressUpdated(6));
    EXPECT_CALL(*listener, onProgress(75));  // 6/8 %
    EXPECT_EQ(0, RunCommand("", {kSimpleCommand}, CommandOptions::WithTimeout(1).Build()));
    progress_message = GetProgressMessage(ds.listener_name_, 6, 8);
    EXPECT_THAT(out, StrEq("stdout\n"));
@@ -1105,6 +1112,7 @@ TEST_F(DumpstateTest, DumpFileUpdateProgress) {
    SetProgress(0, 30);

    EXPECT_CALL(*listener, onProgressUpdated(5));
    EXPECT_CALL(*listener, onProgress(16));  // 5/30 %
    EXPECT_EQ(0, DumpFile("", kTestDataPath + "single-line.txt"));

    std::string progress_message =
+10 −4
Original line number Diff line number Diff line
@@ -949,16 +949,22 @@ void Dumpstate::UpdateProgress(int32_t delta_sec) {
        fsync(control_socket_fd_);
    }

    int percent = 100 * progress / max;
    if (listener_ != nullptr) {
        if (progress % 100 == 0) {
            // We don't want to spam logcat, so only log multiples of 100.
            MYLOGD("Setting progress (%s): %d/%d\n", listener_name_.c_str(), progress, max);
        if (percent % 5 == 0) {
            // We don't want to spam logcat, so only log multiples of 5.
            MYLOGD("Setting progress (%s): %d/%d (%d%%)\n", listener_name_.c_str(), progress, max,
                   percent);
        } else {
            // stderr is ignored on normal invocations, but useful when calling
            // /system/bin/dumpstate directly for debuggging.
            fprintf(stderr, "Setting progress (%s): %d/%d\n", listener_name_.c_str(), progress, max);
            fprintf(stderr, "Setting progress (%s): %d/%d (%d%%)\n", listener_name_.c_str(),
                    progress, max, percent);
        }
        // TODO(b/111441001): Remove in favor of onProgress
        listener_->onProgressUpdated(progress);

        listener_->onProgress(percent);
    }
}

+17 −7
Original line number Diff line number Diff line
@@ -112,15 +112,25 @@ int android_getaddrinfofornetwork(net_handle_t network,

#if __ANDROID_API__ >= 29

/**
 * Possible values of the flags argument to android_res_nsend and android_res_nquery.
 * Values are ORed together.
 */
enum ResNsendFlags : uint32_t {
    // Send a single request to a single resolver and fail on timeout or network errors
    /**
     * Send a single request to a single resolver and fail on timeout or network errors
     */
    ANDROID_RESOLV_NO_RETRY = 1 << 0,

    // Do not cache the result of the lookup. The lookup may return a result that is already
    // in the cache, unless the ANDROID_RESOLV_NO_CACHE_LOOKUP flag is also specified.
    /**
     * Do not cache the result of the lookup. The lookup may return a result that is already
     * in the cache, unless the ANDROID_RESOLV_NO_CACHE_LOOKUP flag is also specified.
     */
    ANDROID_RESOLV_NO_CACHE_STORE = 1 << 1,

    // Don't lookup the request in cache, do not write back the response into the cache
    /**
     * Don't lookup the request in cache.
     */
    ANDROID_RESOLV_NO_CACHE_LOOKUP = 1 << 2,
};

@@ -136,8 +146,7 @@ enum ResNsendFlags : uint32_t {
 * POSIX error code (see errno.h) if an immediate error occurs.
 */
int android_res_nquery(net_handle_t network,
        const char *dname, int ns_class, int ns_type,
        enum ResNsendFlags flags) __INTRODUCED_IN(29);
        const char *dname, int ns_class, int ns_type, uint32_t flags) __INTRODUCED_IN(29);

/**
 * Issue the query |msg| on the given |network|.
@@ -148,10 +157,11 @@ int android_res_nquery(net_handle_t network,
 * POSIX error code (see errno.h) if an immediate error occurs.
 */
int android_res_nsend(net_handle_t network,
        const uint8_t *msg, size_t msglen, enum ResNsendFlags flags) __INTRODUCED_IN(29);
        const uint8_t *msg, size_t msglen, uint32_t flags) __INTRODUCED_IN(29);

/**
 * Read a result for the query associated with the |fd| descriptor.
 * Closes |fd| before returning.
 *
 * Returns:
 *     < 0: negative POSIX error code (see errno.h for possible values). |rcode| is not set.
Loading