From 652c5ad5167b36735bd04b38b9b904d7bdf8033e Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Wed, 5 Oct 2016 14:45:46 -0700 Subject: [PATCH] Fix job scheduler crash due to uninstall race It's possible to get a PACKAGE_CHANGED broadcast well after the package has actually been uninstalled outright because of broadcast delivery latencies. Understand the exception that might be thrown when asking for package info in such cases, so we don't crash the Android runtime. Bug 31865735 Change-Id: I69b2678f0f724fc731aa48fed7af58ce60d3c21c --- .../com/android/server/job/JobSchedulerService.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/job/JobSchedulerService.java b/services/core/java/com/android/server/job/JobSchedulerService.java index ba39772681904..ef6720040a430 100644 --- a/services/core/java/com/android/server/job/JobSchedulerService.java +++ b/services/core/java/com/android/server/job/JobSchedulerService.java @@ -429,7 +429,18 @@ public final class JobSchedulerService extends com.android.server.SystemService } cancelJobsForUid(pkgUid, true); } - } catch (RemoteException e) { /* cannot happen */ } + } catch (RemoteException|IllegalArgumentException e) { + /* + * IllegalArgumentException means that the package doesn't exist. + * This arises when PACKAGE_CHANGED broadcast delivery has lagged + * behind outright uninstall, so by the time we try to act it's gone. + * We don't need to act on this PACKAGE_CHANGED when this happens; + * we'll get a PACKAGE_REMOVED later and clean up then. + * + * RemoteException can't actually happen; the package manager is + * running in this same process. + */ + } break; } }