diff --git a/src/org/thoughtcrime/securesms/service/DirectShareService.java b/src/org/thoughtcrime/securesms/service/DirectShareService.java index ae5b86a683..e4b9bbfee3 100644 --- a/src/org/thoughtcrime/securesms/service/DirectShareService.java +++ b/src/org/thoughtcrime/securesms/service/DirectShareService.java @@ -11,7 +11,9 @@ import android.os.Bundle; import android.os.Parcel; import android.service.chooser.ChooserTarget; import android.service.chooser.ChooserTargetService; +import android.support.annotation.NonNull; import android.support.annotation.RequiresApi; +import android.util.Log; import org.thoughtcrime.securesms.ShareActivity; import org.thoughtcrime.securesms.database.DatabaseFactory; @@ -27,6 +29,9 @@ import java.util.concurrent.ExecutionException; @RequiresApi(api = Build.VERSION_CODES.M) public class DirectShareService extends ChooserTargetService { + + private static final String TAG = DirectShareService.class.getSimpleName(); + @Override public List onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) @@ -41,24 +46,26 @@ public class DirectShareService extends ChooserTargetService { ThreadRecord record; while ((record = reader.getNext()) != null && results.size() < 10) { - try { Recipient recipient = Recipient.from(this, record.getRecipient().getAddress(), false); String name = recipient.toShortString(); Bitmap avatar; if (recipient.getContactPhoto() != null) { - avatar = GlideApp.with(this) - .asBitmap() - .load(recipient.getContactPhoto()) - .circleCrop() - .submit(getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width), - getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width)) - .get(); + try { + avatar = GlideApp.with(this) + .asBitmap() + .load(recipient.getContactPhoto()) + .circleCrop() + .submit(getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width), + getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width)) + .get(); + } catch (InterruptedException | ExecutionException e) { + Log.w(TAG, e); + avatar = getFallbackDrawable(recipient); + } } else { - avatar = BitmapUtil.createFromDrawable(recipient.getFallbackContactPhotoDrawable(this, false), - getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width), - getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height)); + avatar = getFallbackDrawable(recipient); } Parcel parcel = Parcel.obtain(); @@ -72,9 +79,7 @@ public class DirectShareService extends ChooserTargetService { results.add(new ChooserTarget(name, Icon.createWithBitmap(avatar), 1.0f, componentName, bundle)); parcel.recycle(); - } catch (InterruptedException | ExecutionException e) { - throw new AssertionError(e); - } + } return results; @@ -82,4 +87,10 @@ public class DirectShareService extends ChooserTargetService { if (cursor != null) cursor.close(); } } + + private Bitmap getFallbackDrawable(@NonNull Recipient recipient) { + return BitmapUtil.createFromDrawable(recipient.getFallbackContactPhotoDrawable(this, false), + getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width), + getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height)); + } }