2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 05:37:43 +00:00

[SMS App] Prevent assert in PduPersistor.load

This commit is contained in:
Simon Redman 2021-03-12 19:10:30 -08:00
parent ca86efa25d
commit edd9d0d8af

View File

@ -29,6 +29,8 @@ import androidx.annotation.RequiresApi;
import com.google.android.mms.pdu_alt.MultimediaMessagePdu;
import com.google.android.mms.pdu_alt.PduPersister;
import com.google.android.mms.util_alt.PduCache;
import com.google.android.mms.util_alt.PduCacheEntry;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
@ -673,12 +675,27 @@ public class SMSHelper {
private static MultimediaMessagePdu getMessagePdu(Context context, long uID) {
Uri uri = ContentUris.appendId(getMMSUri().buildUpon(), uID).build();
MultimediaMessagePdu toReturn;
try {
return (MultimediaMessagePdu) PduPersister.getPduPersister(context).load(uri);
// Work around https://bugs.kde.org/show_bug.cgi?id=434348 by querying the PduCache directly
// Most likely, this is how we should do business anyway and we will probably see a
// decent speedup...
PduCache pduCache = PduCache.getInstance();
PduCacheEntry maybePduValue;
synchronized (pduCache) {
maybePduValue = pduCache.get(uri);
}
if (maybePduValue != null) {
toReturn = (MultimediaMessagePdu) maybePduValue.getPdu();
} else {
toReturn = (MultimediaMessagePdu) PduPersister.getPduPersister(context).load(uri);
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
return toReturn;
}