Fix loading call log on Android 11+

This commit is contained in:
xynngh 2020-12-14 18:01:47 +04:00
parent 5a290cdc37
commit ee4aa39ad5
2 changed files with 18 additions and 3 deletions

View File

@ -20,6 +20,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Updated Portuguese (Brazil) translation thanks to APL ([@APL](https://hosted.weblate.org/user/APL/)). - Updated Portuguese (Brazil) translation thanks to APL ([@APL](https://hosted.weblate.org/user/APL/)).
- Updated Croatian translation thanks to Milo Ivir (@milotype). - Updated Croatian translation thanks to Milo Ivir (@milotype).
### Fixed
- Fixed a startup crash on Android 11+ (introduced in [0.5.7](#057-2020-10-02)).
## [0.5.11] - 2020-11-08 ## [0.5.11] - 2020-11-08

View File

@ -2,6 +2,8 @@ package dummydomain.yetanothercallblocker.data;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.CallLog; import android.provider.CallLog;
import java.util.ArrayList; import java.util.ArrayList;
@ -40,14 +42,23 @@ public class CallLogHelper {
selectionArgs = null; selectionArgs = null;
} }
Uri uri = CallLog.Calls.CONTENT_URI;
String sortOrder = CallLog.Calls.DATE + " " + (reverseOrder ? "ASC" : "DESC"); String sortOrder = CallLog.Calls.DATE + " " + (reverseOrder ? "ASC" : "DESC");
// should probably work since JELLY_BEAN_MR1
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
uri = uri.buildUpon()
.appendQueryParameter(CallLog.Calls.LIMIT_PARAM_KEY, String.valueOf(limit))
.build();
} else {
sortOrder += " limit " + limit; sortOrder += " limit " + limit;
}
List<CallLogItem> items = new ArrayList<>(limit); List<CallLogItem> items = new ArrayList<>(limit);
try (Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI, try (Cursor cursor = context.getContentResolver()
QUERY_PROJECTION, selection, selectionArgs, sortOrder)) { .query(uri, QUERY_PROJECTION, selection, selectionArgs, sortOrder)) {
if (cursor != null) { if (cursor != null) {
int idIndex = cursor.getColumnIndex(CallLog.Calls._ID); int idIndex = cursor.getColumnIndex(CallLog.Calls._ID);
int typeIndex = cursor.getColumnIndex(CallLog.Calls.TYPE); int typeIndex = cursor.getColumnIndex(CallLog.Calls.TYPE);