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

Commit f67b5b5f authored by Jing Ji's avatar Jing Ji
Browse files

Use the processName from ProcessRecord instead of ApplicationInfo

... in the AppError

The processName could be different in case the crashing component
specifies a different one other than the global process name.

Bug: 161165487
Test: atest android.jobscheduler.cts
Test: Manual - induce a crash in a receiver w/ different proc name \
               verify the proc name is showing up in dumpsys
Change-Id: Ied1658091edbd16d75a61e15e3501a92b222ab42
parent d6132e2a
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -2287,7 +2287,8 @@ public class JobSchedulerService extends com.android.server.SystemService
        }
        }


        // Everything else checked out so far, so this is the final yes/no check
        // Everything else checked out so far, so this is the final yes/no check
        final boolean appIsBad = mActivityManagerInternal.isAppBad(service.applicationInfo);
        final boolean appIsBad = mActivityManagerInternal.isAppBad(
                service.processName, service.applicationInfo.uid);
        if (DEBUG && appIsBad) {
        if (DEBUG && appIsBad) {
            Slog.i(TAG, "App is bad for " + job.toShortString() + " so not runnable");
            Slog.i(TAG, "App is bad for " + job.toShortString() + " so not runnable");
        }
        }
+2 −2
Original line number Original line Diff line number Diff line
@@ -387,8 +387,8 @@ public abstract class ActivityManagerInternal {
    /** Returns true if the given uid is the app in the foreground. */
    /** Returns true if the given uid is the app in the foreground. */
    public abstract boolean isAppForeground(int uid);
    public abstract boolean isAppForeground(int uid);


    /** Returns true if the given uid is currently marked 'bad' */
    /** Returns true if the given process name and uid is currently marked 'bad' */
    public abstract boolean isAppBad(ApplicationInfo info);
    public abstract boolean isAppBad(String processName, int uid);


    /** Remove pending backup for the given userId. */
    /** Remove pending backup for the given userId. */
    public abstract void clearPendingBackup(@UserIdInt int userId);
    public abstract void clearPendingBackup(@UserIdInt int userId);
+4 −4
Original line number Original line Diff line number Diff line
@@ -6012,9 +6012,9 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        }
    }
    }
    private boolean isAppBad(ApplicationInfo info) {
    private boolean isAppBad(final String processName, final int uid) {
        synchronized (this) {
        synchronized (this) {
            return mAppErrors.isBadProcessLocked(info);
            return mAppErrors.isBadProcessLocked(processName, uid);
        }
        }
    }
    }
@@ -19713,8 +19713,8 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        }
        @Override
        @Override
        public boolean isAppBad(ApplicationInfo info) {
        public boolean isAppBad(final String processName, final int uid) {
            return ActivityManagerService.this.isAppBad(info);
            return ActivityManagerService.this.isAppBad(processName, uid);
        }
        }
        @Override
        @Override
+18 −19
Original line number Original line Diff line number Diff line
@@ -33,7 +33,6 @@ import android.app.ApplicationExitInfo;
import android.content.ActivityNotFoundException;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.VersionedPackage;
import android.content.pm.VersionedPackage;
import android.net.Uri;
import android.net.Uri;
import android.os.Binder;
import android.os.Binder;
@@ -263,16 +262,16 @@ class AppErrors {
        return needSep;
        return needSep;
    }
    }


    boolean isBadProcessLocked(ApplicationInfo info) {
    boolean isBadProcessLocked(final String processName, final int uid) {
        return mBadProcesses.get(info.processName, info.uid) != null;
        return mBadProcesses.get(processName, uid) != null;
    }
    }


    void clearBadProcessLocked(ApplicationInfo info) {
    void clearBadProcessLocked(final String processName, final int uid) {
        mBadProcesses.remove(info.processName, info.uid);
        mBadProcesses.remove(processName, uid);
    }
    }


    void resetProcessCrashTimeLocked(ApplicationInfo info) {
    void resetProcessCrashTimeLocked(final String processName, final int uid) {
        mProcessCrashTimes.remove(info.processName, info.uid);
        mProcessCrashTimes.remove(processName, uid);
    }
    }


    void resetProcessCrashTimeLocked(boolean resetEntireUser, int appId, int userId) {
    void resetProcessCrashTimeLocked(boolean resetEntireUser, int appId, int userId) {
@@ -548,7 +547,7 @@ class AppErrors {
            if (r != null && !r.isolated && res != AppErrorDialog.RESTART) {
            if (r != null && !r.isolated && res != AppErrorDialog.RESTART) {
                // XXX Can't keep track of crash time for isolated processes,
                // XXX Can't keep track of crash time for isolated processes,
                // since they don't have a persistent identity.
                // since they don't have a persistent identity.
                mProcessCrashTimes.put(r.info.processName, r.uid,
                mProcessCrashTimes.put(r.processName, r.uid,
                        SystemClock.uptimeMillis());
                        SystemClock.uptimeMillis());
            }
            }
        }
        }
@@ -695,8 +694,8 @@ class AppErrors {
        boolean tryAgain = false;
        boolean tryAgain = false;


        if (!app.isolated) {
        if (!app.isolated) {
            crashTime = mProcessCrashTimes.get(app.info.processName, app.uid);
            crashTime = mProcessCrashTimes.get(app.processName, app.uid);
            crashTimePersistent = mProcessCrashTimesPersistent.get(app.info.processName, app.uid);
            crashTimePersistent = mProcessCrashTimesPersistent.get(app.processName, app.uid);
        } else {
        } else {
            crashTime = crashTimePersistent = null;
            crashTime = crashTimePersistent = null;
        }
        }
@@ -723,10 +722,10 @@ class AppErrors {
        if (crashTime != null && now < crashTime + ProcessList.MIN_CRASH_INTERVAL) {
        if (crashTime != null && now < crashTime + ProcessList.MIN_CRASH_INTERVAL) {
            // The process crashed again very quickly. If it was a bound foreground service, let's
            // The process crashed again very quickly. If it was a bound foreground service, let's
            // try to restart again in a while, otherwise the process loses!
            // try to restart again in a while, otherwise the process loses!
            Slog.w(TAG, "Process " + app.info.processName
            Slog.w(TAG, "Process " + app.processName
                    + " has crashed too many times: killing!");
                    + " has crashed too many times: killing!");
            EventLog.writeEvent(EventLogTags.AM_PROCESS_CRASHED_TOO_MUCH,
            EventLog.writeEvent(EventLogTags.AM_PROCESS_CRASHED_TOO_MUCH,
                    app.userId, app.info.processName, app.uid);
                    app.userId, app.processName, app.uid);
            mService.mAtmInternal.onHandleAppCrash(app.getWindowProcessController());
            mService.mAtmInternal.onHandleAppCrash(app.getWindowProcessController());
            if (!app.isPersistent()) {
            if (!app.isPersistent()) {
                // We don't want to start this process again until the user
                // We don't want to start this process again until the user
@@ -734,13 +733,13 @@ class AppErrors {
                // need to keep it running.  If a persistent process is actually
                // need to keep it running.  If a persistent process is actually
                // repeatedly crashing, then badness for everyone.
                // repeatedly crashing, then badness for everyone.
                EventLog.writeEvent(EventLogTags.AM_PROC_BAD, app.userId, app.uid,
                EventLog.writeEvent(EventLogTags.AM_PROC_BAD, app.userId, app.uid,
                        app.info.processName);
                        app.processName);
                if (!app.isolated) {
                if (!app.isolated) {
                    // XXX We don't have a way to mark isolated processes
                    // XXX We don't have a way to mark isolated processes
                    // as bad, since they don't have a peristent identity.
                    // as bad, since they don't have a peristent identity.
                    mBadProcesses.put(app.info.processName, app.uid,
                    mBadProcesses.put(app.processName, app.uid,
                            new BadProcessInfo(now, shortMsg, longMsg, stackTrace));
                            new BadProcessInfo(now, shortMsg, longMsg, stackTrace));
                    mProcessCrashTimes.remove(app.info.processName, app.uid);
                    mProcessCrashTimes.remove(app.processName, app.uid);
                }
                }
                app.bad = true;
                app.bad = true;
                app.removed = true;
                app.removed = true;
@@ -785,8 +784,8 @@ class AppErrors {
        if (!app.isolated) {
        if (!app.isolated) {
            // XXX Can't keep track of crash times for isolated processes,
            // XXX Can't keep track of crash times for isolated processes,
            // because they don't have a persistent identity.
            // because they don't have a persistent identity.
            mProcessCrashTimes.put(app.info.processName, app.uid, now);
            mProcessCrashTimes.put(app.processName, app.uid, now);
            mProcessCrashTimesPersistent.put(app.info.processName, app.uid, now);
            mProcessCrashTimesPersistent.put(app.processName, app.uid, now);
        }
        }


        if (app.crashHandler != null) mService.mHandler.post(app.crashHandler);
        if (app.crashHandler != null) mService.mHandler.post(app.crashHandler);
@@ -829,7 +828,7 @@ class AppErrors {
            }
            }
            Long crashShowErrorTime = null;
            Long crashShowErrorTime = null;
            if (!proc.isolated) {
            if (!proc.isolated) {
                crashShowErrorTime = mProcessCrashShowDialogTimes.get(proc.info.processName,
                crashShowErrorTime = mProcessCrashShowDialogTimes.get(proc.processName,
                        proc.uid);
                        proc.uid);
            }
            }
            final boolean showFirstCrash = Settings.Global.getInt(
            final boolean showFirstCrash = Settings.Global.getInt(
@@ -850,7 +849,7 @@ class AppErrors {
                    && (showFirstCrash || showFirstCrashDevOption || data.repeating)) {
                    && (showFirstCrash || showFirstCrashDevOption || data.repeating)) {
                proc.getDialogController().showCrashDialogs(data);
                proc.getDialogController().showCrashDialogs(data);
                if (!proc.isolated) {
                if (!proc.isolated) {
                    mProcessCrashShowDialogTimes.put(proc.info.processName, proc.uid, now);
                    mProcessCrashShowDialogTimes.put(proc.processName, proc.uid, now);
                }
                }
            } else {
            } else {
                // The device is asleep, so just pretend that the user
                // The device is asleep, so just pretend that the user
+6 −6
Original line number Original line Diff line number Diff line
@@ -2359,9 +2359,9 @@ public final class ProcessList {
            if ((intentFlags & Intent.FLAG_FROM_BACKGROUND) != 0) {
            if ((intentFlags & Intent.FLAG_FROM_BACKGROUND) != 0) {
                // If we are in the background, then check to see if this process
                // If we are in the background, then check to see if this process
                // is bad.  If so, we will just silently fail.
                // is bad.  If so, we will just silently fail.
                if (mService.mAppErrors.isBadProcessLocked(info)) {
                if (mService.mAppErrors.isBadProcessLocked(processName, info.uid)) {
                    if (DEBUG_PROCESSES) Slog.v(TAG, "Bad process: " + info.uid
                    if (DEBUG_PROCESSES) Slog.v(TAG, "Bad process: " + info.uid
                            + "/" + info.processName);
                            + "/" + processName);
                    return null;
                    return null;
                }
                }
            } else {
            } else {
@@ -2370,13 +2370,13 @@ public final class ProcessList {
                // least one crash dialog again, and make the process good again
                // least one crash dialog again, and make the process good again
                // if it had been bad.
                // if it had been bad.
                if (DEBUG_PROCESSES) Slog.v(TAG, "Clearing bad process: " + info.uid
                if (DEBUG_PROCESSES) Slog.v(TAG, "Clearing bad process: " + info.uid
                        + "/" + info.processName);
                        + "/" + processName);
                mService.mAppErrors.resetProcessCrashTimeLocked(info);
                mService.mAppErrors.resetProcessCrashTimeLocked(processName, info.uid);
                if (mService.mAppErrors.isBadProcessLocked(info)) {
                if (mService.mAppErrors.isBadProcessLocked(processName, info.uid)) {
                    EventLog.writeEvent(EventLogTags.AM_PROC_GOOD,
                    EventLog.writeEvent(EventLogTags.AM_PROC_GOOD,
                            UserHandle.getUserId(info.uid), info.uid,
                            UserHandle.getUserId(info.uid), info.uid,
                            info.processName);
                            info.processName);
                    mService.mAppErrors.clearBadProcessLocked(info);
                    mService.mAppErrors.clearBadProcessLocked(processName, info.uid);
                    if (app != null) {
                    if (app != null) {
                        app.bad = false;
                        app.bad = false;
                    }
                    }