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

Commit 7ce98ac8 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Suppress service start timeout for services within system server,

until PHASE_THIRD_PARTY_APPS_CAN_START, to avoid TelecomService
triggering an (superficial) ANR.

Bug: 34123235
Test: 1) Boot 2) Add Thread.sleep(30_0000) before Looper.loop() in SystemServer and make sure
telecom won't trigger the ANR

Change-Id: Ic49535f3edb4225a27a708550f9e5325f03170fb
parent bb24c6b5
Loading
Loading
Loading
Loading
+24 −2
Original line number Original line Diff line number Diff line
@@ -64,6 +64,7 @@ import com.android.internal.util.DumpUtils;
import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.FastPrintWriter;
import com.android.server.AppStateTracker;
import com.android.server.AppStateTracker;
import com.android.server.LocalServices;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.am.ActivityManagerService.ItemMatcher;
import com.android.server.am.ActivityManagerService.ItemMatcher;
import com.android.server.am.ActivityManagerService.NeededUriGrants;
import com.android.server.am.ActivityManagerService.NeededUriGrants;


@@ -2001,6 +2002,25 @@ public final class ActiveServices {
                + why + " of " + r + " in app " + r.app);
                + why + " of " + r + " in app " + r.app);
        else if (DEBUG_SERVICE_EXECUTING) Slog.v(TAG_SERVICE_EXECUTING, ">>> EXECUTING "
        else if (DEBUG_SERVICE_EXECUTING) Slog.v(TAG_SERVICE_EXECUTING, ">>> EXECUTING "
                + why + " of " + r.shortName);
                + why + " of " + r.shortName);

        // For b/34123235: Services within the system server won't start until SystemServer
        // does Looper.loop(), so we shouldn't try to start/bind to them too early in the boot
        // process. However, since there's a little point of showing the ANR dialog in that case,
        // let's suppress the timeout until PHASE_THIRD_PARTY_APPS_CAN_START.
        //
        // (Note there are multiple services start at PHASE_THIRD_PARTY_APPS_CAN_START too,
        // which technically could also trigger this timeout if there's a system server
        // that takes a long time to handle PHASE_THIRD_PARTY_APPS_CAN_START, but that shouldn't
        // happen.)
        boolean timeoutNeeded = true;
        if ((mAm.mBootPhase < SystemService.PHASE_THIRD_PARTY_APPS_CAN_START)
                && (r.app != null) && (r.app.pid == android.os.Process.myPid())) {

            Slog.w(TAG, "Too early to start/bind service in system_server: Phase=" + mAm.mBootPhase
                    + " " + r.getComponentName());
            timeoutNeeded = false;
        }

        long now = SystemClock.uptimeMillis();
        long now = SystemClock.uptimeMillis();
        if (r.executeNesting == 0) {
        if (r.executeNesting == 0) {
            r.executeFg = fg;
            r.executeFg = fg;
@@ -2011,14 +2031,16 @@ public final class ActiveServices {
            if (r.app != null) {
            if (r.app != null) {
                r.app.executingServices.add(r);
                r.app.executingServices.add(r);
                r.app.execServicesFg |= fg;
                r.app.execServicesFg |= fg;
                if (r.app.executingServices.size() == 1) {
                if (timeoutNeeded && r.app.executingServices.size() == 1) {
                    scheduleServiceTimeoutLocked(r.app);
                    scheduleServiceTimeoutLocked(r.app);
                }
                }
            }
            }
        } else if (r.app != null && fg && !r.app.execServicesFg) {
        } else if (r.app != null && fg && !r.app.execServicesFg) {
            r.app.execServicesFg = true;
            r.app.execServicesFg = true;
            if (timeoutNeeded) {
                scheduleServiceTimeoutLocked(r.app);
                scheduleServiceTimeoutLocked(r.app);
            }
            }
        }
        r.executeFg |= fg;
        r.executeFg |= fg;
        r.executeNesting++;
        r.executeNesting++;
        r.executingStart = now;
        r.executingStart = now;
+6 −0
Original line number Original line Diff line number Diff line
@@ -1850,6 +1850,11 @@ public class ActivityManagerService extends IActivityManager.Stub
     */
     */
    boolean mBooted = false;
    boolean mBooted = false;
    /**
     * Current boot phase.
     */
    int mBootPhase;
    WindowManagerService mWindowManager;
    WindowManagerService mWindowManager;
    final ActivityThread mSystemThread;
    final ActivityThread mSystemThread;
@@ -2881,6 +2886,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        @Override
        @Override
        public void onBootPhase(int phase) {
        public void onBootPhase(int phase) {
            mService.mBootPhase = phase;
            if (phase == PHASE_SYSTEM_SERVICES_READY) {
            if (phase == PHASE_SYSTEM_SERVICES_READY) {
                mService.mBatteryStatsService.systemServicesReady();
                mService.mBatteryStatsService.systemServicesReady();
                mService.mServices.systemServicesReady();
                mService.mServices.systemServicesReady();