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

Commit 14513965 authored by Nathan Harold's avatar Nathan Harold Committed by Android (Google) Code Review
Browse files

Merge "Allow startBugreport to run async" into main

parents ef8f55ce 2887b273
Loading
Loading
Loading
Loading
+47 −3
Original line number Diff line number Diff line
@@ -46,6 +46,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;
@@ -104,6 +105,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")
@@ -429,9 +431,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
    }
}