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

Commit 10598561 authored by Adam Bookatz's avatar Adam Bookatz
Browse files

Handle SSM thread failures better

If a thread dies, we need to make sure it
* doesn't break Trace
* outputs something to logcat

Bug: 217246676
Test: manual (purposefully crash a service on boot)
Change-Id: Ic463818599ebbf22a6895c0197cfc7fac049f9b6
parent d707ebcd
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -576,19 +576,20 @@ public final class SystemServiceManager implements Dumpable {
        return () -> {
            final TimingsTraceAndSlog t = new TimingsTraceAndSlog(oldTrace);
            final String serviceName = service.getClass().getName();
            try {
            final int curUserId = curUser.getUserIdentifier();
            t.traceBegin("ssm.on" + USER_STARTING + "User-" + curUserId + "_" + serviceName);
            try {
                long time = SystemClock.elapsedRealtime();
                service.onUserStarting(curUser);
                warnIfTooLong(SystemClock.elapsedRealtime() - time, service,
                        "on" + USER_STARTING + "User-" + curUserId);
                t.traceEnd();
            } catch (Exception e) {
                Slog.wtf(TAG, "Failure reporting " + USER_STARTING + " of user " + curUser
                        + " to service " + serviceName, e);
                Slog.e(TAG, "Disabling thread pool - please capture a bug report.");
                sUseLifecycleThreadPool = false;
            } finally {
                t.traceEnd();
            }
        };
    }
@@ -601,11 +602,18 @@ public final class SystemServiceManager implements Dumpable {
            final int curUserId = curUser.getUserIdentifier();
            t.traceBegin("ssm.on" + USER_COMPLETED_EVENT + "User-" + curUserId
                    + "_" + eventType + "_" + serviceName);
            try {
                long time = SystemClock.elapsedRealtime();
                service.onUserCompletedEvent(curUser, eventType);
                warnIfTooLong(SystemClock.elapsedRealtime() - time, service,
                        "on" + USER_COMPLETED_EVENT + "User-" + curUserId);
            } catch (Exception e) {
                Slog.wtf(TAG, "Failure reporting " + USER_COMPLETED_EVENT + " of user " + curUser
                        + " to service " + serviceName, e);
                throw e;
            } finally {
                t.traceEnd();
            }
        };
    }