Skip to content

Commit 5e0a928

Browse files
committed
Fix a bug where tapping on a bugreport mailed the wrong one,
and don't crash if /sdcard/bugreports doesn't exist.
1 parent dbe3611 commit 5e0a928

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

apps/BugReportSender/src/com/android/bugreportsender/BugReportListActivity.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030

3131
import java.io.File;
3232
import java.util.ArrayList;
33-
import java.util.Comparator;
33+
import java.util.Arrays;
34+
import java.util.Collections;
3435

3536
/**
3637
* Shows a list of bug reports currently in /sdcard/bugreports
@@ -95,9 +96,14 @@ protected void onListItemClick(ListView l, View v, int position, long id) {
9596
}
9697

9798
private void scanDirectory() {
98-
File[] files = REPORT_DIR.listFiles();
9999
mAdapter.clear();
100100
mFiles.clear();
101+
102+
File[] files = REPORT_DIR.listFiles();
103+
if (files == null) return;
104+
105+
// Sort in reverse order: newest bug reports first
106+
Arrays.sort(files, Collections.reverseOrder());
101107
for (int i = 0; i < files.length; i++) {
102108
String name = files[i].getName();
103109
if (name.endsWith(".gz")) name = name.substring(0, name.length() - 3);
@@ -106,13 +112,9 @@ private void scanDirectory() {
106112
continue;
107113
}
108114

115+
// Make sure to keep the parallel arrays in sync
109116
mAdapter.add(name.substring(10, name.length() - 4));
110117
mFiles.add(files[i]);
111118
}
112-
113-
// Reverse sort order: newest first.
114-
mAdapter.sort(new Comparator<String>() {
115-
public int compare(String a, String b) { return b.compareTo(a); }
116-
});
117119
}
118120
}

0 commit comments

Comments
 (0)