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

Commit 2503bdd7 authored by Songchun Fan's avatar Songchun Fan Committed by Android (Google) Code Review
Browse files

Merge changes from topic "anr-add-loading-info"

* changes:
  [am/incremental] add package loading info in main logcat for crash/ANRs
  [metrics/incremental] add package loading info in ANR and crash metrics
parents 28559fe0 7e32be5b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -3609,6 +3609,8 @@ message AppCrashOccurred {
    optional ForegroundState foreground_state = 7;

    optional android.server.ErrorSource error_source = 8;

    optional bool is_package_loading = 9;
}

/**
@@ -3670,6 +3672,8 @@ message ANROccurred {
    optional android.server.ErrorSource error_source = 7;

    optional string package_name = 8;

    optional bool is_package_loading = 9;
}

/**
+17 −5
Original line number Diff line number Diff line
@@ -194,6 +194,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.ApplicationInfo.HiddenApiEnforcementPolicy;
import android.content.pm.IPackageDataObserver;
import android.content.pm.IPackageManager;
import android.content.pm.IncrementalStatesInfo;
import android.content.pm.InstrumentationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
@@ -7574,6 +7575,20 @@ public class ActivityManagerService extends IActivityManager.Stub
     */
    void handleApplicationCrashInner(String eventType, ProcessRecord r, String processName,
            ApplicationErrorReport.CrashInfo crashInfo) {
        boolean isPackageLoading = false;
        // Notify package manager service to possibly update package state
        if (r != null && r.info != null && r.info.packageName != null) {
            mPackageManagerInt.notifyPackageCrashOrAnr(r.info.packageName);
            IncrementalStatesInfo incrementalStatesInfo =
                    mPackageManagerInt.getIncrementalStatesInfo(r.info.packageName, r.uid,
                            r.userId);
            isPackageLoading = incrementalStatesInfo.isLoading();
            if (isPackageLoading) {
                // Report in the main log that the package is still loading
                Slog.e(TAG, "App crashed when package " + r.info.packageName + " is "
                        + ((int) (incrementalStatesInfo.getProgress() * 100)) + "% loaded.");
            }
        }
        EventLogTags.writeAmCrash(Binder.getCallingPid(),
                UserHandle.getUserId(Binder.getCallingUid()), processName,
@@ -7599,7 +7614,8 @@ public class ActivityManagerService extends IActivityManager.Stub
                        : FrameworkStatsLog.APP_CRASH_OCCURRED__FOREGROUND_STATE__UNKNOWN,
                processName.equals("system_server") ? ServerProtoEnums.SYSTEM_SERVER
                        : (r != null) ? r.getProcessClassEnum()
                                      : ServerProtoEnums.ERROR_SOURCE_UNKNOWN
                                      : ServerProtoEnums.ERROR_SOURCE_UNKNOWN,
                isPackageLoading
        );
        final int relaunchReason = r == null ? RELAUNCH_REASON_NONE
@@ -7615,10 +7631,6 @@ public class ActivityManagerService extends IActivityManager.Stub
                eventType, r, processName, null, null, null, null, null, null, crashInfo);
        mAppErrors.crashApplication(r, crashInfo);
        // Notify package manager service to possibly update package state
        if (r != null && r.info != null && r.info.packageName != null) {
            mPackageManagerInt.notifyPackageCrashOrAnr(r.info.packageName);
        }
    }
    public void handleApplicationStrictModeViolation(
+24 −3
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ import android.app.IApplicationThread;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.IncrementalStatesInfo;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ProcessInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.VersionedPackage;
@@ -1652,6 +1654,19 @@ class ProcessRecord implements WindowProcessListener {
            }
        }

        // Check if package is still being loaded
        boolean isPackageLoading = false;
        final PackageManagerInternal packageManagerInternal =
                mService.getPackageManagerInternalLocked();
        if (aInfo != null && aInfo.packageName != null) {
            IncrementalStatesInfo incrementalStatesInfo =
                    packageManagerInternal.getIncrementalStatesInfo(
                            aInfo.packageName, uid, userId);
            if (incrementalStatesInfo != null) {
                isPackageLoading = incrementalStatesInfo.isLoading();
            }
        }

        // Log the ANR to the main log.
        StringBuilder info = new StringBuilder();
        info.setLength(0);
@@ -1669,6 +1684,13 @@ class ProcessRecord implements WindowProcessListener {
            info.append("Parent: ").append(parentShortComponentName).append("\n");
        }

        if (isPackageLoading) {
            // Report in the main log that the package is still loading
            final float loadingProgress = packageManagerInternal.getIncrementalStatesInfo(
                    aInfo.packageName, uid, userId).getProgress();
            info.append("Package is ").append((int) (loadingProgress * 100)).append("% loaded.\n");
        }

        StringBuilder report = new StringBuilder();
        report.append(MemoryPressureUtil.currentPsiState());
        ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true);
@@ -1736,7 +1758,7 @@ class ProcessRecord implements WindowProcessListener {
                        ? FrameworkStatsLog.ANROCCURRED__FOREGROUND_STATE__FOREGROUND
                        : FrameworkStatsLog.ANROCCURRED__FOREGROUND_STATE__BACKGROUND,
                getProcessClassEnum(),
                (this.info != null) ? this.info.packageName : "");
                (this.info != null) ? this.info.packageName : "", isPackageLoading);
        final ProcessRecord parentPr = parentProcess != null
                ? (ProcessRecord) parentProcess.mOwner : null;
        mService.addErrorToDropBox("anr", this, processName, activityShortComponentName,
@@ -1771,8 +1793,7 @@ class ProcessRecord implements WindowProcessListener {

            // Notify package manager service to possibly update package state
            if (aInfo != null && aInfo.packageName != null) {
                mService.getPackageManagerInternalLocked().notifyPackageCrashOrAnr(
                        aInfo.packageName);
                packageManagerInternal.notifyPackageCrashOrAnr(aInfo.packageName);
            }

            // mUiHandler can be null if the AMS is constructed with injector only. This will only