Loading core/tests/coretests/src/android/app/activity/ServiceTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -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( Loading services/core/java/com/android/server/am/ActiveServices.java +2 −1 Original line number Diff line number Diff line Loading @@ -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)) { Loading Loading
core/tests/coretests/src/android/app/activity/ServiceTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -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( Loading
services/core/java/com/android/server/am/ActiveServices.java +2 −1 Original line number Diff line number Diff line Loading @@ -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)) { Loading