Skip to content
Commit 60a494ae authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Make the disconnecting list from activity up-to-date

After the holder has enqueued the runnable to disconnect, the
connections may be removed by other paths, e.g.
 ActivityThread#handleDestroyActivity
  -> ContextImpl#scheduleFinalCleanup
  -> LoadedApk#removeContextRegistrations
  -> unbindService
Then when executing the runnable, it will remove the removed
connection again and try to bind down the service. If a new service
instance has been started again, it will cause IllegalStateException.

This change keeps the reference of connections, so removeConnection
from ActiveServices still updates the exact list. The original
double-disconnect is protected by null out the holder and a new
flag to indicate disconnecting.

Bug: 146825978
Test: atest CtsAppTestCases:ServiceTest
Test: 1. Add sleep 5s in the disconnect-runnable to delay calling
         ActivityManagerInternal#disconnectActivityFromServices.
      2. Launch an activity which binds a service.
      3. Finish the activity without unbind (so the
         disconnect-runnable is enqueued and unbindService from
         final-cleanup will be called. If DEBUG_CLEANUP is enabled,
         the log in removeConnection should appear).
      4. After the activity is destroyed for 2s, start the service
         again (previous service is destroyed by unbind, so a new
         service record is created).
      5. The 5s delayed disconnect-runnable executes, and system
         is still alive without any exception logs (originally
         it will always crash the system).

Change-Id: I3ae85927da1c11b2560524b6642401741b5beae2
parent 749e585a
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment