Avoid system server crash due to package removed

Cherry-picked from aosp.

Fixes bug 18593178.

Symptom:
When application is not responding, an ANR dialog will shown.
In certain timing, user uninstall the application when the ANR
occurs, but before ANR dialog shown. The system server will crash
when looking up the errorReportReceiver because the package is removed.

Here shows how the exception occurs.
java.lang.IllegalArgumentException: Unknown package: app.package.name
 at com.android.server.pm.Settings.getInstallerPackageNameLPr
 at com.android.server.pm.PackageManagerService.getInstallerPackageName
 at android.app.ApplicationPackageManager.getInstallerPackageName
 at android.app.ApplicationErrorReport.getErrorReportReceiver
 at com.android.server.am.ActivityManagerService.startAppProblemLocked
 at com.android.server.am.ActivityManagerService.makeAppNotRespondingLocked
 at com.android.server.am.ActivityManagerService.appNotResponding

Change-Id: Iced4287bd44dc25b1db2c1e3a583892eb6c041a2
This commit is contained in:
louis_chang
2014-07-31 10:47:45 +08:00
committed by Craig Mautner
parent 932c332147
commit dfa34cd517

View File

@@ -168,10 +168,20 @@ public class ApplicationErrorReport implements Parcelable {
PackageManager pm = context.getPackageManager();
// look for receiver in the installer package
String candidate = pm.getInstallerPackageName(packageName);
ComponentName result = getErrorReportReceiver(pm, packageName, candidate);
if (result != null) {
return result;
String candidate = null;
ComponentName result = null;
try {
candidate = pm.getInstallerPackageName(packageName);
} catch (IllegalArgumentException e) {
// the package could already removed
}
if (candidate != null) {
result = getErrorReportReceiver(pm, packageName, candidate);
if (result != null) {
return result;
}
}
// if the error app is on the system image, look for system apps