Ignore IllegalArgumentException from MediaProvider operations
Inserting new MediaStore entries for files in app private directories
leads to IllegalArgumentException in Android S-OS and above.
DownloadProvider tries to insert MediaStore entry for files in app
external directories when doing sync after OS upgrade from Android P to
Android S. To avoid crashing DownloadProvider, we ignore the
IllegalArgumentException.
Bug: 195185812
Test: Tests will be added as part of b/196028977
Change-Id: Idf95a75c8101246a2650fe69f476f9372b9cebd7
(cherry picked from commit 7a92998a98b355b0d54fb4a146e136f26728a0b8)
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java
index f7e25d5..a9e0237 100644
--- a/src/com/android/providers/downloads/DownloadProvider.java
+++ b/src/com/android/providers/downloads/DownloadProvider.java
@@ -942,6 +942,13 @@
}
return mediaStoreUri;
}
+ } catch (IllegalArgumentException ignored) {
+ // Insert or update MediaStore failed. At this point we can't do
+ // much here. If the file belongs to MediaStore collection, it will
+ // get added to MediaStore collection during next scan, and we will
+ // obtain the uri to the file in the next MediaStore#scanFile
+ // initiated by us
+ Log.w(Constants.TAG, "Couldn't update MediaStore for " + filePath, ignored);
} catch (RemoteException e) {
// Should not happen
}