|
20 | 20 | import java.io.FileNotFoundException; |
21 | 21 | import java.security.NoSuchAlgorithmException; |
22 | 22 | import java.security.SecureRandom; |
| 23 | +import java.util.ArrayList; |
| 24 | +import java.util.List; |
23 | 25 | import java.util.concurrent.ConcurrentHashMap; |
24 | 26 |
|
25 | 27 | import org.strongswan.android.logic.CharonVpnService; |
@@ -85,28 +87,33 @@ public Cursor query(Uri uri, String[] projection, String selection, |
85 | 87 | { |
86 | 88 | /* this is called by apps to find out the name and size of the file. |
87 | 89 | * since we only provide a single file this is simple to implement */ |
88 | | - if (projection == null || projection.length < 1) |
| 90 | + if (projection == null) |
89 | 91 | { |
90 | | - return null; |
| 92 | + projection = new String[]{ OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE }; |
91 | 93 | } |
92 | 94 | Long timestamp = mUris.get(uri); |
93 | 95 | if (timestamp == null) |
94 | 96 | { /* don't check the validity as this information is not really private */ |
95 | 97 | return null; |
96 | 98 | } |
97 | | - MatrixCursor cursor = new MatrixCursor(projection, 1); |
98 | | - if (OpenableColumns.DISPLAY_NAME.equals(cursor.getColumnName(0))) |
99 | | - { |
100 | | - cursor.newRow().add(CharonVpnService.LOG_FILE); |
101 | | - } |
102 | | - else if (OpenableColumns.SIZE.equals(cursor.getColumnName(0))) |
103 | | - { |
104 | | - cursor.newRow().add(mLogFile.length()); |
105 | | - } |
106 | | - else |
| 99 | + List<String> cols = new ArrayList<>(); |
| 100 | + List<Object> vals = new ArrayList<>(); |
| 101 | + for (String col : projection) |
107 | 102 | { |
108 | | - return null; |
| 103 | + if (OpenableColumns.DISPLAY_NAME.equals(col)) |
| 104 | + { |
| 105 | + cols.add(OpenableColumns.DISPLAY_NAME); |
| 106 | + vals.add(CharonVpnService.LOG_FILE); |
| 107 | + } |
| 108 | + else if (OpenableColumns.SIZE.equals(col)) |
| 109 | + { |
| 110 | + cols.add(OpenableColumns.SIZE); |
| 111 | + vals.add(mLogFile.length()); |
| 112 | + } |
109 | 113 | } |
| 114 | + |
| 115 | + MatrixCursor cursor = new MatrixCursor(cols.toArray(new String[0]), 1); |
| 116 | + cursor.addRow(vals.toArray()); |
110 | 117 | return cursor; |
111 | 118 | } |
112 | 119 |
|
|
0 commit comments