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

Commit 6968f552 authored by Gavin Corkery's avatar Gavin Corkery
Browse files

Reduce duplicate calls for restricted dump options

The existing logic makes several identical calls for each
restriced bugreport type (telephony, wifi and limited). Instead,
handle logic for the default case so that the critical dumpsys
can be collected before running common logic for all bugreport
types.

Test: atest BugreportManagerTest
Test: atest dumpstate_test
Bug: 1587370896
Change-Id: I1784e53a526c02e488232f43d764ec3c398a9a1a
parent 5702b485
Loading
Loading
Loading
Loading
+10 −18
Original line number Diff line number Diff line
@@ -2890,31 +2890,23 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid,
    // duration is logged into MYLOG instead.
    PrintHeader();

    // TODO(b/158737089) reduce code repetition in if branches
    if (options_->telephony_only) {
    bool is_dumpstate_restricted = options_->telephony_only
                                   || options_->wifi_only
                                   || options_->limited_only;
    if (!is_dumpstate_restricted) {
        // Invoke critical dumpsys first to preserve system state, before doing anything else.
        RunDumpsysCritical();
    }
    MaybeTakeEarlyScreenshot();
    onUiIntensiveBugreportDumpsFinished(calling_uid);
    MaybeCheckUserConsent(calling_uid, calling_package);
    if (options_->telephony_only) {
        DumpstateTelephonyOnly(calling_package);
    } else if (options_->wifi_only) {
        MaybeTakeEarlyScreenshot();
        onUiIntensiveBugreportDumpsFinished(calling_uid);
        MaybeCheckUserConsent(calling_uid, calling_package);
        DumpstateWifiOnly();
    } else if (options_->limited_only) {
        MaybeTakeEarlyScreenshot();
        onUiIntensiveBugreportDumpsFinished(calling_uid);
        MaybeCheckUserConsent(calling_uid, calling_package);
        DumpstateLimitedOnly();
    } else {
        // Invoke critical dumpsys first to preserve system state, before doing anything else.
        RunDumpsysCritical();

        // Take screenshot and get consent only after critical dumpsys has finished.
        MaybeTakeEarlyScreenshot();
        onUiIntensiveBugreportDumpsFinished(calling_uid);
        MaybeCheckUserConsent(calling_uid, calling_package);

        // Dump state for the default case. This also drops root.
        RunStatus s = DumpstateDefaultAfterCritical();
        if (s != RunStatus::OK) {