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

Commit 94932bd1 authored by Mehmet Murat Sevim's avatar Mehmet Murat Sevim Committed by Android (Google) Code Review
Browse files

Merge "BugreportManager takes screenshot even though screenshotFd is null" into main

parents 2cce002c 864f9abf
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -3460,6 +3460,7 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid,
    }

    MaybeTakeEarlyScreenshot();
    MaybeSavePlaceholderScreenshot();
    MaybeWaitForSnapshotSystemTrace(std::move(snapshot_system_trace));
    onUiIntensiveBugreportDumpsFinished(calling_uid);
    MaybeCheckUserConsent(calling_uid, calling_package);
@@ -3559,6 +3560,26 @@ void Dumpstate::MaybeTakeEarlyScreenshot() {
    TakeScreenshot();
}

void Dumpstate::MaybeSavePlaceholderScreenshot() {
    if (options_->do_screenshot) {
        // No need to save a placeholder screenshot if a real one will be taken.
        return;
    }
    if (!options_->is_consent_deferred) {
        return;
    }

    // When consent is deferred, a screenshot used to be taken even when one
    // was not requested. The screenshot is not taken any more but a placeholder
    // is saved for backwards compatibility.
    std::string path = ds.GetPath(ds.CalledByApi() ? "-png.tmp" : ".png");
    if (android::os::CopyFileToFile(DEFAULT_SCREENSHOT_PATH, path)) {
        MYLOGD("Saved fallback screenshot on %s\n", path.c_str());
    } else {
        MYLOGE("Failed to save fallback screenshot on %s\n", path.c_str());
    };
}

std::future<std::string> Dumpstate::MaybeSnapshotSystemTraceAsync() {
    // When capturing traces via bugreport handler (BH), this function will be invoked twice:
    // 1) When BH invokes IDumpstate::PreDumpUiData()
+1 −0
Original line number Diff line number Diff line
@@ -573,6 +573,7 @@ class Dumpstate {
    RunStatus dumpstate();

    void MaybeTakeEarlyScreenshot();
    void MaybeSavePlaceholderScreenshot();
    std::future<std::string> MaybeSnapshotSystemTraceAsync();
    void MaybeWaitForSnapshotSystemTrace(std::future<std::string> task);
    void MaybeSnapshotUiTraces();
+32 −0
Original line number Diff line number Diff line
@@ -1082,6 +1082,38 @@ TEST_F(ZippedBugReportStreamTest, DISABLED_StreamLimitedOnlyReport) {
    VerifyEntry(handle_, bugreport_txt_name, &entry);
}

TEST_F(ZippedBugReportStreamTest, ScreenShotFileCreated) {
    std::string out_path = kTestDataPath + "ScreenShotCapturedOut.zip";
    android::base::unique_fd out_fd;
    CreateFd(out_path, &out_fd);
    ds_.options_->limited_only = true;
    ds_.options_->stream_to_socket = true;
    ds_.options_->do_screenshot = false;
    ds_.options_->is_consent_deferred = true;
    RedirectOutputToFd(out_fd);

    GenerateBugreport();

    std::string screenshot = ds_.GetPath(ds_.CalledByApi() ? "-png.tmp" : ".png");
    EXPECT_TRUE(std::filesystem::exists(screenshot)) << screenshot << " was not created.";
}

TEST_F(ZippedBugReportStreamTest, ScreenShotFileIsNotCreated) {
    std::string out_path = kTestDataPath + "ScreenShotCapturedOut.zip";
    android::base::unique_fd out_fd;
    CreateFd(out_path, &out_fd);
    ds_.options_->limited_only = true;
    ds_.options_->stream_to_socket = true;
    ds_.options_->do_screenshot = false;
    ds_.options_->is_consent_deferred = false;
    RedirectOutputToFd(out_fd);

    GenerateBugreport();

    std::string screenshot = ds_.GetPath(ds_.CalledByApi() ? "-png.tmp" : ".png");
    EXPECT_FALSE(std::filesystem::exists(screenshot)) << screenshot << " was created.";
}

class ProgressTest : public DumpstateBaseTest {
  public:
    Progress GetInstance(int32_t max, double growth_factor, const std::string& path = "") {