[ActivityManager] Avoid orphan ContentProviderRecord.
<Symptom>
Binder threads wait forever results ANR/system hang.
<Root cause>
When X is accessing Y's provider.
Before Y publishing its provider to notify X,
someone invokes killBackgroundProcesses to kill Y.
In removeProcessLocked, it will pass restarting=true
and allowRestart=true to handleAppDiedLocked.
When the clean flow going to removeDyingProviderLocked.
The variable will be inLaunching=true always=false.
Then it will not notify the ContentProviderRecord.
And also due to the ContentProviderConnection waiting=true,
it will do nothing and just return true to
cleanUpApplicationRecordLocked to set restart as true.
But due to restarting=true, the restart flow will not execute,
then the waiting ContentProviderRecord for X will be orphan
and keep waiting.
<Reproduce step>
Service X query provider Y when X's oom adj is SERVICE_ADJ,
before Y's publish provider, invoke killBackgroundProcesses
to Y's package.
Then use command "adb shell dumpsys activity prov"
Y will always in "Launching content providers".
<Solution>
For not restarting case, pass restarting=false to
handleAppDiedLocked to let the provider process can be restarted.
A more simple way maybe just change to keep below 2 lines:
app.kill(reason, true);
handleAppDiedLocked(app, callerWillRestart, allowRestart);
Change-Id: I8992cb851fce4dbe6255da71d60390e1a33cb9c7
1 file changed