Skip to content

Commit 5d98463

Browse files
committed
android: Fix querying display name of the log file
The previous code did not necessarily provide it (in particular if the size, or anything else, was queried as first column).
1 parent 6938157 commit 5d98463

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/frontends/android/app/src/main/java/org/strongswan/android/data/LogContentProvider.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.io.FileNotFoundException;
2121
import java.security.NoSuchAlgorithmException;
2222
import java.security.SecureRandom;
23+
import java.util.ArrayList;
24+
import java.util.List;
2325
import java.util.concurrent.ConcurrentHashMap;
2426

2527
import org.strongswan.android.logic.CharonVpnService;
@@ -85,28 +87,33 @@ public Cursor query(Uri uri, String[] projection, String selection,
8587
{
8688
/* this is called by apps to find out the name and size of the file.
8789
* since we only provide a single file this is simple to implement */
88-
if (projection == null || projection.length < 1)
90+
if (projection == null)
8991
{
90-
return null;
92+
projection = new String[]{ OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE };
9193
}
9294
Long timestamp = mUris.get(uri);
9395
if (timestamp == null)
9496
{ /* don't check the validity as this information is not really private */
9597
return null;
9698
}
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)
107102
{
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+
}
109113
}
114+
115+
MatrixCursor cursor = new MatrixCursor(cols.toArray(new String[0]), 1);
116+
cursor.addRow(vals.toArray());
110117
return cursor;
111118
}
112119

0 commit comments

Comments
 (0)