fixed rare crash on jolla devices

This commit is contained in:
Daniel Gultsch 2018-03-12 15:59:35 +01:00
parent dac8ed6058
commit 8dc17a96ba
1 changed files with 15 additions and 31 deletions

View File

@ -3,8 +3,6 @@ package eu.siacs.conversations.utils;
import android.Manifest;
import android.content.Context;
import android.content.CursorLoader;
import android.content.Loader;
import android.content.Loader.OnLoadCompleteListener;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
@ -41,36 +39,22 @@ public class PhoneHelper {
CursorLoader mCursorLoader = new NotThrowCursorLoader(context,
ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
null);
mCursorLoader.registerListener(0, new OnLoadCompleteListener<Cursor>() {
@Override
public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) {
if (cursor != null) {
while (cursor.moveToNext()) {
Bundle contact = new Bundle();
contact.putInt("phoneid", cursor.getInt(cursor
.getColumnIndex(ContactsContract.Data._ID)));
contact.putString(
"displayname",
cursor.getString(cursor
.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)));
contact.putString("photouri", cursor.getString(cursor
.getColumnIndex(ContactsContract.Data.PHOTO_URI)));
contact.putString("lookup", cursor.getString(cursor
.getColumnIndex(ContactsContract.Data.LOOKUP_KEY)));
contact.putString(
"jid",
cursor.getString(cursor
.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
phoneContacts.add(contact);
}
cursor.close();
mCursorLoader.registerListener(0, (arg0, c) -> {
if (c != null) {
while (c.moveToNext()) {
Bundle contact = new Bundle();
contact.putInt("phoneid", c.getInt(c.getColumnIndex(ContactsContract.Data._ID)));
contact.putString("displayname", c.getString(c.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)));
contact.putString("photouri", c.getString(c.getColumnIndex(ContactsContract.Data.PHOTO_URI)));
contact.putString("lookup", c.getString(c.getColumnIndex(ContactsContract.Data.LOOKUP_KEY)));
contact.putString("jid", c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
phoneContacts.add(contact);
}
c.close();
}
if (listener != null) {
listener.onPhoneContactsLoaded(phoneContacts);
}
if (listener != null) {
listener.onPhoneContactsLoaded(phoneContacts);
}
});
try {
@ -90,7 +74,7 @@ public class PhoneHelper {
final Cursor cursor;
try {
cursor = context.getContentResolver().query(Profile.CONTENT_URI, projection, null, null, null);
} catch (SecurityException e) {
} catch (Throwable e) {
return null;
}
if (cursor == null) {