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

Commit 2887b273 authored by Nathan Harold's avatar Nathan Harold
Browse files

Allow startBugreport to run async

The startBugreport call uses a listener interface to
provide return status for bug report generation;
however, for convenience the method would previously
block until the underlying service was successfully
launched. But, the underlying call is slow, so it would
block the caller for hundreds of millis or for up to
30 seconds. This patch allows the startBugreport() call
to run asynchronously instead of blocking the caller.

Bug: 180123623
Test: atest BugreportManagerTest; (cts, and unit test)
Test: manual test
Change-Id: Ibbc0de76a1c12c979772222208704ad0e466b1a5
parent c09575bb
Loading
Loading
Loading
Loading
+47 −3
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.AtomicFile;
import android.util.LocalLog;
import android.util.MutableBoolean;
import android.util.Pair;
import android.util.Slog;
import android.util.Xml;
@@ -102,6 +103,7 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
    private final TelephonyManager mTelephonyManager;
    private final ArraySet<String> mBugreportAllowlistedPackages;
    private final BugreportFileManager mBugreportFileManager;
    private static final FeatureFlags sFeatureFlags = new FeatureFlagsImpl();


    @GuardedBy("mLock")
@@ -415,9 +417,51 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
        ensureUserCanTakeBugReport(bugreportMode);

        Slogf.i(TAG, "Starting bugreport for %s / %d", callingPackage, callingUid);
        final MutableBoolean handoffLock = new MutableBoolean(false);
        if (sFeatureFlags.asyncStartBugreport()) {
            synchronized (handoffLock) {
                new Thread(()-> {
                    try {
                        synchronized (mLock) {
                            synchronized (handoffLock) {
                                handoffLock.value = true;
                                handoffLock.notifyAll();
                            }
                            startBugreportLocked(
                                    callingUid,
                                    callingPackage,
                                    bugreportFd,
                                    screenshotFd,
                                    bugreportMode,
                                    bugreportFlags,
                                    listener,
                                    isScreenshotRequested);
                        }
                    } catch (Exception e) {
                        Slog.e(TAG, "Cannot start a new bugreport due to an unknown error", e);
                        reportError(listener, IDumpstateListener.BUGREPORT_ERROR_RUNTIME_ERROR);
                    }
                }, "BugreportManagerServiceThread").start();
                try {
                    while (!handoffLock.value) { // handle the rare case of a spurious wakeup
                        handoffLock.wait(DEFAULT_BUGREPORT_SERVICE_TIMEOUT_MILLIS);
                    }
                } catch (InterruptedException e) {
                    Slog.e(TAG, "Unexpectedly interrupted waiting for startBugreportLocked", e);
                }
            }
        } else {
            synchronized (mLock) {
            startBugreportLocked(callingUid, callingPackage, bugreportFd, screenshotFd,
                    bugreportMode, bugreportFlags, listener, isScreenshotRequested);
                startBugreportLocked(
                        callingUid,
                        callingPackage,
                        bugreportFd,
                        screenshotFd,
                        bugreportMode,
                        bugreportFlags,
                        listener,
                        isScreenshotRequested);
            }
        }
    }

+10 −0
Original line number Diff line number Diff line
@@ -7,3 +7,13 @@ flag {
    description: "Use proto tombstones as source of truth for adding to dropbox"
    bug: "323857385"
}

flag {
    name: "async_start_bugreport"
    namespace: "crumpet"
    description: "Don't block callers on the start of dumpsys service"
    bug: "180123623"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}