这是indexloc提供的服务,不要输入任何密码
Skip to content

Commit 11eff56

Browse files
Fixed: Fix termux-call-log api IllegalArgumentException: Invalid token LIMIT on Android 11+ since limit and offset are being passed as sort parameters instead of query parameters
Closes #434
1 parent c31cace commit 11eff56

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

app/src/main/java/com/termux/api/apis/CallLogAPI.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ public void writeJson(JsonWriter out) throws Exception {
3838
}
3939

4040
private static void getCallLogs(Context context, JsonWriter out, int offset, int limit) throws IOException {
41-
ContentResolver cr = context.getContentResolver();
42-
String sortOrder = "date DESC LIMIT + " + limit + " OFFSET " + offset;
41+
ContentResolver contentResolver = context.getContentResolver();
4342

44-
try (Cursor cur = cr.query(CallLog.Calls.CONTENT_URI, null, null, null, sortOrder)) {
43+
try (Cursor cur = contentResolver.query(CallLog.Calls.CONTENT_URI.buildUpon().
44+
appendQueryParameter(CallLog.Calls.LIMIT_PARAM_KEY, String.valueOf(limit)).
45+
appendQueryParameter(CallLog.Calls.OFFSET_PARAM_KEY, String.valueOf(offset))
46+
.build(), null, null, null, "date DESC")) {
4547
cur.moveToLast();
4648

4749
int nameIndex = cur.getColumnIndex(CallLog.Calls.CACHED_NAME);
@@ -62,7 +64,7 @@ private static void getCallLogs(Context context, JsonWriter out, int offset, int
6264
out.name("type").value(getCallTypeString(cur.getInt(callTypeIndex)));
6365
out.name("date").value(getDateString(cur.getLong(dateIndex), dateFormat));
6466
out.name("duration").value(getTimeString(cur.getInt(durationIndex)));
65-
out.name("sim_id").value(cur.getString(simTypeIndex));
67+
out.name("sim_id").value(cur.getString(simTypeIndex));
6668

6769
cur.moveToPrevious();
6870
out.endObject();

0 commit comments

Comments
 (0)