From 0730a5a9ca2d52c1899ed750c97acfeddc453289 Mon Sep 17 00:00:00 2001 From: Michael W Date: Wed, 12 Jul 2017 14:16:42 +0200 Subject: Gallery2: Fix potential crash Author: Michael W Date: Wed Jul 12 14:16:42 2017 +0200 Gallery2: Fix potential crash * A race between deleting and displaying videos seems to report a higher count of videos available than actually accessible. BUGBASH-489 Change-Id: Iac24002feb8701cc4182c3834f663be017b625d5 Author: KhabarlakKonstantin Date: Tue Oct 3 11:22:40 2017 +0300 Fix crash after deleting a video on Albums tab getMediaItem can return empty list if no more media items available, break folder processing then Number of items returned by getMediaItem can be inconsistent with getMediaItemCount Change-Id: I7f2abce5d3832a1b2c1fe068b629a3474ed742e2 Change-Id: Ibcaeff698da118f484a6f38528b4a2111a009fdd --- src/com/android/gallery3d/app/AlbumPage.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java index 7f947d8f3..c3ef4c326 100644 --- a/src/com/android/gallery3d/app/AlbumPage.java +++ b/src/com/android/gallery3d/app/AlbumPage.java @@ -652,9 +652,17 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster if (mMediaSet == null) return false; int count = mMediaSet.getMediaItemCount(); + ArrayList list; MediaItem item; for (int i = 0; i < count; i++) { - item = mMediaSet.getMediaItem(i, 1).get(0); + list = mMediaSet.getMediaItem(i, 1); + if (list == null) { + continue; + } + if (list.isEmpty()) { + break; + } + item = list.get(0); if (item == null) { continue; } -- cgit v1.2.3