Catch IllegalArgumentException to avoid SyncManager crash
When SyncManager's scheduling races with an app with a sync
adapter being uninstalled, it can get an IAE from PackageManager.
Catch this exception and skip over the job.
Bug: 36658118
Test: Manual
Change-Id: I0a63a3e0aa19cb5685aa18c7c6c9d6dd6ccfd60a
diff --git a/core/java/android/content/pm/PackageManagerInternal.java b/core/java/android/content/pm/PackageManagerInternal.java
index 6272822..b3e25d1 100644
--- a/core/java/android/content/pm/PackageManagerInternal.java
+++ b/core/java/android/content/pm/PackageManagerInternal.java
@@ -172,6 +172,7 @@
* @param packageName The package name.
* @param userId The user for which to check.
* @return Whether was launched.
+ * @throws IllegalArgumentException if the package is not found
*/
public abstract boolean wasPackageEverLaunched(String packageName, int userId);
diff --git a/services/core/java/com/android/server/content/SyncManager.java b/services/core/java/com/android/server/content/SyncManager.java
index bbad493..1a27a39 100644
--- a/services/core/java/com/android/server/content/SyncManager.java
+++ b/services/core/java/com/android/server/content/SyncManager.java
@@ -907,7 +907,12 @@
Bundle finalExtras = new Bundle(extras);
String packageName = syncAdapterInfo.componentName.getPackageName();
// If the app did not run and has no account access, done
- if (!mPackageManagerInternal.wasPackageEverLaunched(packageName, userId)) {
+ try {
+ if (!mPackageManagerInternal.wasPackageEverLaunched(packageName, userId)) {
+ continue;
+ }
+ } catch (IllegalArgumentException e) {
+ // Package not found, race with an uninstall
continue;
}
mAccountManagerInternal.requestAccountAccess(account.account,