From 5ed21bd9aca01f01e2b27e2bfa031d31c775eec7 Mon Sep 17 00:00:00 2001 From: riddle_hsu Date: Sat, 15 Nov 2014 18:07:26 +0800 Subject: [PATCH] [ActivityManager] Avoid orphan ContentProviderRecord. Binder threads wait forever results ANR/system hang. 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. 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". 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 --- .../android/server/am/ActivityManagerService.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) mode change 100755 => 100644 services/core/java/com/android/server/am/ActivityManagerService.java diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java old mode 100755 new mode 100644 index 8dfb3217c0af1..25237a91bf3c9 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -5958,17 +5958,20 @@ public final class ActivityManagerService extends ActivityManagerNative if (app.isolated) { mBatteryStatsService.removeIsolatedUid(app.uid, app.info.uid); } - app.kill(reason, true); - handleAppDiedLocked(app, true, allowRestart); - removeLruProcessLocked(app); - + boolean willRestart = false; if (app.persistent && !app.isolated) { if (!callerWillRestart) { - addAppLocked(app.info, false, null /* ABI override */); + willRestart = true; } else { needRestart = true; } } + app.kill(reason, true); + handleAppDiedLocked(app, willRestart, allowRestart); + if (willRestart) { + removeLruProcessLocked(app); + addAppLocked(app.info, false, null /* ABI override */); + } } else { mRemovedProcesses.add(app); }