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

Commit 98ab6d9d authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Add shell command to clear bad processes." into main

parents 804e0eb4 3b31dce7
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -29,6 +29,11 @@ public class ProcessMap<E> {
        return uids.get(uid);
    }

    public SparseArray<E> get(String name) {
        SparseArray<E> uids = mMap.get(name);
        return uids;
    }
    
    public E put(String name, int uid, E value) {
        SparseArray<E> uids = mMap.get(name);
        if (uids == null) {
+25 −0
Original line number Diff line number Diff line
@@ -449,6 +449,8 @@ final class ActivityManagerShellCommand extends ShellCommand {
                    return runSetAppZygotePreloadTimeout(pw);
                case "set-media-foreground-service":
                    return runSetMediaForegroundService(pw);
                case "clear-bad-process":
                    return runClearBadProcess(pw);
                default:
                    return handleDefaultCommands(cmd);
            }
@@ -4276,6 +4278,27 @@ final class ActivityManagerShellCommand extends ShellCommand {
        return 0;
    }

    int runClearBadProcess(PrintWriter pw) throws RemoteException {
        final String processName = getNextArgRequired();
        int userId = UserHandle.USER_CURRENT;
        String opt;
        while ((opt = getNextOption()) != null) {
            if ("--user".equals(opt)) {
                userId = UserHandle.parseUserArg(getNextArgRequired());
            } else {
                getErrPrintWriter().println("Error: unknown option " + opt);
                return -1;
            }
        }
        if (userId == UserHandle.USER_CURRENT) {
            userId = mInternal.getCurrentUserId();
        }

        pw.println("Clearing '" + processName + "' in u" + userId + " from bad processes list");
        mInternal.mAppErrors.clearBadProcessForUser(processName, userId);
        return 0;
    }

    private Resources getResources(PrintWriter pw) throws RemoteException {
        // system resources does not contain all the device configuration, construct it manually.
        Configuration config = mInterface.getConfiguration();
@@ -4717,6 +4740,8 @@ final class ActivityManagerShellCommand extends ShellCommand {
            pw.println("  set-media-foreground-service inactive|active [--user USER_ID] <PACKAGE>"
                            + " <NOTIFICATION_ID>");
            pw.println("         Set an app's media service inactive or active.");
            pw.println("  clear-bad-process [--user USER_ID] <PROCESS_NAME>");
            pw.println("         Clears a process from the bad processes list.");
            Intent.printIntentArgsHelp(pw, "");
        }
    }
+18 −0
Original line number Diff line number Diff line
@@ -373,6 +373,24 @@ class AppErrors {
        }
    }

    void clearBadProcessForUser(final String processName, final int userId) {
        synchronized (mBadProcessLock) {
            final ProcessMap<BadProcessInfo> badProcesses = new ProcessMap<>();
            badProcesses.putAll(mBadProcesses);
            final SparseArray<BadProcessInfo> uids = badProcesses.get(processName);
            if (uids == null) {
                return;
            }
            for (int i = uids.size() - 1; i >= 0; --i) {
                final int uid = uids.keyAt(i);
                if (userId == UserHandle.USER_ALL || userId == UserHandle.getUserId(uid)) {
                    badProcesses.remove(processName, uid);
                }
            }
            mBadProcesses = badProcesses;
        }
    }

    void markBadProcess(final String processName, final int uid, BadProcessInfo info) {
        synchronized (mBadProcessLock) {
            final ProcessMap<BadProcessInfo> badProcesses = new ProcessMap<>();