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

Commit ecec0dca authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix race condition between service restart and unbind." into main

parents ba12cb52 ac689e23
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -157,6 +157,21 @@ public class ServiceTest extends TestCase {
        assertThat(mCurrentConnection.takePid(), is(NOT_STARTED));
    }

    @Test
    public void testRestart_stickyStartedService_unbindHappenedAfterRestart_restarted() {
        final int servicePid = startService(Service.START_STICKY);
        assertThat(servicePid, not(NOT_STARTED));
        assertThat(bindService(0 /* flags */), is(servicePid));

        final int restartedServicePid = waitForServiceStarted(
                () -> {
                    Process.killProcess(servicePid);
                    mContext.unbindService(mCurrentConnection);
                    mCurrentConnection = null;
                });
        assertThat(restartedServicePid, not(NOT_STARTED));
    }

    /** @return The pid of the started service. */
    private int startService(int code) {
        return waitForServiceStarted(
+2 −1
Original line number Diff line number Diff line
@@ -6653,9 +6653,10 @@ public final class ActiveServices {

            // If unbound while waiting to start and there is no connection left in this service,
            // remove the pending service
            if (s.getConnections().isEmpty()) {
            if (s.getConnections().isEmpty() && !s.startRequested) {
                mPendingServices.remove(s);
                mPendingBringups.remove(s);
                if (DEBUG_SERVICE) Slog.v(TAG_SERVICE, "Removed pending service: " + s);
            }

            if (c.hasFlag(Context.BIND_AUTO_CREATE)) {