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).
This commit is contained in:
Tobias Brunner
2025-10-27 14:39:55 +01:00
parent 69381576d7
commit 5d98463eed
@@ -20,6 +20,8 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.strongswan.android.logic.CharonVpnService; import org.strongswan.android.logic.CharonVpnService;
@@ -85,28 +87,33 @@ public class LogContentProvider extends ContentProvider
{ {
/* this is called by apps to find out the name and size of the file. /* this is called by apps to find out the name and size of the file.
* since we only provide a single file this is simple to implement */ * since we only provide a single file this is simple to implement */
if (projection == null || projection.length < 1) if (projection == null)
{ {
return null; projection = new String[]{ OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE };
} }
Long timestamp = mUris.get(uri); Long timestamp = mUris.get(uri);
if (timestamp == null) if (timestamp == null)
{ /* don't check the validity as this information is not really private */ { /* don't check the validity as this information is not really private */
return null; return null;
} }
MatrixCursor cursor = new MatrixCursor(projection, 1); List<String> cols = new ArrayList<>();
if (OpenableColumns.DISPLAY_NAME.equals(cursor.getColumnName(0))) List<Object> vals = new ArrayList<>();
for (String col : projection)
{ {
cursor.newRow().add(CharonVpnService.LOG_FILE); if (OpenableColumns.DISPLAY_NAME.equals(col))
} {
else if (OpenableColumns.SIZE.equals(cursor.getColumnName(0))) cols.add(OpenableColumns.DISPLAY_NAME);
{ vals.add(CharonVpnService.LOG_FILE);
cursor.newRow().add(mLogFile.length()); }
} else if (OpenableColumns.SIZE.equals(col))
else {
{ cols.add(OpenableColumns.SIZE);
return null; vals.add(mLogFile.length());
}
} }
MatrixCursor cursor = new MatrixCursor(cols.toArray(new String[0]), 1);
cursor.addRow(vals.toArray());
return cursor; return cursor;
} }