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

Commit f3a77c8f authored by Songchun Fan's avatar Songchun Fan
Browse files

[incremental] add incremental info to crash/anr reports in dropbox

Play uses the DropBox error reports for their Crashes/ANRs UI. Adding
incremental info into the dropbox reports.

Test: builds
BUG: 180951530
Change-Id: Id3e5575efdb8304c78d41dcedb9a53d8289a775e
parent e2895024
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -35,11 +35,11 @@ import android.os.ServiceDebugInfo;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.sysprop.WatchdogProperties;
import android.util.EventLog;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
import android.sysprop.WatchdogProperties;

import com.android.internal.os.ProcessCpuTracker;
import com.android.internal.os.ZygoteConnectionConstants;
@@ -56,9 +56,9 @@ import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.TimeUnit;

/** This class calls its monitor every minute. Killing this process if they don't return **/
public class Watchdog {
@@ -688,7 +688,7 @@ public class Watchdog {
                        if (mActivity != null) {
                            mActivity.addErrorToDropBox(
                                    "watchdog", null, "system_server", null, null, null,
                                    subject, report.toString(), stack, null);
                                    subject, report.toString(), stack, null, null, null);
                        }
                        FrameworkStatsLog.write(FrameworkStatsLog.SYSTEM_SERVER_WATCHDOG_OCCURRED,
                                subject);
+27 −11
Original line number Diff line number Diff line
@@ -7703,9 +7703,8 @@ public class ActivityManagerService extends IActivityManager.Stub
     */
    void handleApplicationCrashInner(String eventType, ProcessRecord r, String processName,
            ApplicationErrorReport.CrashInfo crashInfo) {
        boolean isIncremental = false;
        float loadingProgress = 1;
        long millisSinceOldestPendingRead = 0;
        IncrementalMetrics incrementalMetrics = null;
        // Notify package manager service to possibly update package state
        if (r != null && r.info != null && r.info.packageName != null) {
            final String codePath = r.info.getCodePath();
@@ -7716,8 +7715,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            if (incrementalStatesInfo != null) {
                loadingProgress = incrementalStatesInfo.getProgress();
            }
            isIncremental = IncrementalManager.isIncrementalPath(codePath);
            if (isIncremental) {
            if (IncrementalManager.isIncrementalPath(codePath)) {
                // Report in the main log about the incremental package
                Slog.e(TAG, "App crashed on incremental package " + r.info.packageName
                        + " which is " + ((int) (loadingProgress * 100)) + "% loaded.");
@@ -7726,8 +7724,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                if (incrementalService != null) {
                    final IncrementalManager incrementalManager = new IncrementalManager(
                            IIncrementalService.Stub.asInterface(incrementalService));
                    IncrementalMetrics metrics = incrementalManager.getMetrics(codePath);
                    millisSinceOldestPendingRead = metrics.getMillisSinceOldestPendingRead();
                    incrementalMetrics = incrementalManager.getMetrics(codePath);
                }
            }
        }
@@ -7757,7 +7754,9 @@ public class ActivityManagerService extends IActivityManager.Stub
                processName.equals("system_server") ? ServerProtoEnums.SYSTEM_SERVER
                        : (r != null) ? r.getProcessClassEnum()
                                      : ServerProtoEnums.ERROR_SOURCE_UNKNOWN,
                isIncremental, loadingProgress, millisSinceOldestPendingRead
                incrementalMetrics != null /* isIncremental */, loadingProgress,
                incrementalMetrics != null ? incrementalMetrics.getMillisSinceOldestPendingRead()
                        : -1
        );
        final int relaunchReason = r == null ? RELAUNCH_REASON_NONE
@@ -7770,7 +7769,8 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        addErrorToDropBox(
                eventType, r, processName, null, null, null, null, null, null, crashInfo);
                eventType, r, processName, null, null, null, null, null, null, crashInfo,
                new Float(loadingProgress), incrementalMetrics);
        mAppErrors.crashApplication(r, crashInfo);
    }
@@ -7952,7 +7952,8 @@ public class ActivityManagerService extends IActivityManager.Stub
        FrameworkStatsLog.write(FrameworkStatsLog.WTF_OCCURRED, callingUid, tag, processName,
                callingPid, (r != null) ? r.getProcessClassEnum() : 0);
        addErrorToDropBox("wtf", r, processName, null, null, null, tag, null, null, crashInfo);
        addErrorToDropBox("wtf", r, processName, null, null, null, tag, null, null, crashInfo,
                null, null);
        return r;
    }
@@ -7977,7 +7978,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        for (Pair<String, ApplicationErrorReport.CrashInfo> p = list.poll();
                p != null; p = list.poll()) {
            addErrorToDropBox("wtf", proc, "system_server", null, null, null, p.first, null, null,
                    p.second);
                    p.second, null, null);
        }
    }
@@ -8066,12 +8067,15 @@ public class ActivityManagerService extends IActivityManager.Stub
     * @param report in long form describing the error, null if absent
     * @param dataFile text file to include in the report, null if none
     * @param crashInfo giving an application stack trace, null if absent
     * @param loadingProgress the loading progress of an installed package, range in [0, 1].
     * @param incrementalMetrics metrics for apps installed on Incremental.
     */
    public void addErrorToDropBox(String eventType,
            ProcessRecord process, String processName, String activityShortComponentName,
            String parentShortComponentName, ProcessRecord parentProcess,
            String subject, final String report, final File dataFile,
            final ApplicationErrorReport.CrashInfo crashInfo) {
            final ApplicationErrorReport.CrashInfo crashInfo,
            @Nullable Float loadingProgress, @Nullable IncrementalMetrics incrementalMetrics) {
        // NOTE -- this must never acquire the ActivityManagerService lock,
        // otherwise the watchdog may be prevented from resetting the system.
@@ -8132,6 +8136,18 @@ public class ActivityManagerService extends IActivityManager.Stub
        if (crashInfo != null && crashInfo.crashTag != null && !crashInfo.crashTag.isEmpty()) {
            sb.append("Crash-Tag: ").append(crashInfo.crashTag).append("\n");
        }
        if (loadingProgress != null) {
            sb.append("Loading-Progress: ").append(loadingProgress.floatValue()).append("\n");
        }
        if (incrementalMetrics != null) {
            sb.append("Incremental: Yes").append("\n");
            final long millisSinceOldestPendingRead =
                    incrementalMetrics.getMillisSinceOldestPendingRead();
            if (millisSinceOldestPendingRead > 0) {
                sb.append("Millis-Since-Oldest-Pending-Read: ").append(
                        millisSinceOldestPendingRead).append("\n");
            }
        }
        sb.append("\n");
        // Do the rest in a worker thread to avoid blocking the caller on I/O
+1 −1
Original line number Diff line number Diff line
@@ -1627,7 +1627,7 @@ public class AppProfiler {
        dropBuilder.append(catSw.toString());
        FrameworkStatsLog.write(FrameworkStatsLog.LOW_MEM_REPORTED);
        mService.addErrorToDropBox("lowmem", null, "system_server", null,
                null, null, tag.toString(), dropBuilder.toString(), null, null);
                null, null, tag.toString(), dropBuilder.toString(), null, null, null, null);
        synchronized (mService) {
            long now = SystemClock.uptimeMillis();
            if (mLastMemUsageReportTime < now) {
+8 −9
Original line number Diff line number Diff line
@@ -300,9 +300,8 @@ class ProcessErrorStateRecord {
        }

        // Check if package is still being loaded
        boolean isIncremental = false;
        float loadingProgress = 1;
        long millisSinceOldestPendingRead = 0;
        IncrementalMetrics incrementalMetrics = null;
        final PackageManagerInternal packageManagerInternal = mService.getPackageManagerInternal();
        if (aInfo != null && aInfo.packageName != null) {
            IncrementalStatesInfo incrementalStatesInfo =
@@ -312,8 +311,7 @@ class ProcessErrorStateRecord {
                loadingProgress = incrementalStatesInfo.getProgress();
            }
            final String codePath = aInfo.getCodePath();
            isIncremental = IncrementalManager.isIncrementalPath(codePath);
            if (isIncremental) {
            if (IncrementalManager.isIncrementalPath(codePath)) {
                // Report in the main log that the incremental package is still loading
                Slog.e(TAG, "App crashed on incremental package " + aInfo.packageName
                        + " which is " + ((int) (loadingProgress * 100)) + "% loaded.");
@@ -322,8 +320,7 @@ class ProcessErrorStateRecord {
                if (incrementalService != null) {
                    final IncrementalManager incrementalManager = new IncrementalManager(
                            IIncrementalService.Stub.asInterface(incrementalService));
                    IncrementalMetrics metrics = incrementalManager.getMetrics(codePath);
                    millisSinceOldestPendingRead = metrics.getMillisSinceOldestPendingRead();
                    incrementalMetrics = incrementalManager.getMetrics(codePath);
                }
            }
        }
@@ -345,7 +342,7 @@ class ProcessErrorStateRecord {
            info.append("Parent: ").append(parentShortComponentName).append("\n");
        }

        if (isIncremental) {
        if (incrementalMetrics != null) {
            // Report in the main log about the incremental package
            info.append("Package is ").append((int) (loadingProgress * 100)).append("% loaded.\n");
        }
@@ -434,12 +431,14 @@ class ProcessErrorStateRecord {
                        : FrameworkStatsLog.ANROCCURRED__FOREGROUND_STATE__BACKGROUND,
                mApp.getProcessClassEnum(),
                (mApp.info != null) ? mApp.info.packageName : "",
                isIncremental, loadingProgress, millisSinceOldestPendingRead);
                incrementalMetrics != null /* isIncremental */, loadingProgress,
                incrementalMetrics != null ? incrementalMetrics.getMillisSinceOldestPendingRead()
                        : -1);
        final ProcessRecord parentPr = parentProcess != null
                ? (ProcessRecord) parentProcess.mOwner : null;
        mService.addErrorToDropBox("anr", mApp, mApp.processName, activityShortComponentName,
                parentShortComponentName, parentPr, annotation, report.toString(), tracesFile,
                null);
                null, new Float(loadingProgress), incrementalMetrics);

        if (mApp.getWindowProcessController().appNotResponding(info.toString(),
                () -> {