Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 96e6ddb2 authored by John Hoford's avatar John Hoford
Browse files

fix Gallery crashes with empty PTP device

bug:11152999
Change-Id: I70e4787dc46c0e948712ea4530b8110c36603dfa
parent fb1884f6
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -267,6 +267,9 @@ public class MtpDeviceIndex {
                break;
            }
        }
        if (mBuckets.length == 0 || mUnifiedLookupIndex.length == 0) {
            return -1;
        }
        int mappedPos = mBuckets[bucketNumber].unifiedStartIndex
                + position - mBuckets[bucketNumber].itemsStartIndex;
        if (order == SortOrder.Descending) {
@@ -283,6 +286,9 @@ public class MtpDeviceIndex {
            return bucket.itemsStartIndex + position - 1 - bucket.unifiedStartIndex;
        } else {
            int zeroIndex = mUnifiedLookupIndex.length - 1 - position;
            if (mBuckets.length == 0 || mUnifiedLookupIndex.length == 0) {
                return -1;
            }
            DateBucket bucket = mBuckets[mUnifiedLookupIndex[zeroIndex]];
            if (bucket.unifiedEndIndex == zeroIndex) zeroIndex--;
            return mMtpObjects.length - 1 - bucket.itemsStartIndex