#945 - Fix MMS reception for MIUI devices

This commit is contained in:
moezbhatti
2019-07-27 22:54:50 -04:00
parent da28edc782
commit b8fb429dda
3 changed files with 27 additions and 35 deletions
@@ -167,16 +167,12 @@ public class DownloadRequest extends MmsRequest {
// } // }
// Store the downloaded message // Store the downloaded message
final PduPersister persister = PduPersister.getPduPersister(context); final PduPersister persister = PduPersister.getPduPersister(context);
final Uri messageUri = persister.persist( final Uri messageUri = persister.persist(pdu, Telephony.Mms.Inbox.CONTENT_URI, true, true, null);
pdu,
Telephony.Mms.Inbox.CONTENT_URI,
true/*createThreadId*/,
true/*groupMmsEnabled*/,
null/*preOpenedFiles*/);
if (messageUri == null) { if (messageUri == null) {
Timber.e("DownloadRequest.persistIfRequired: can not persist message"); Timber.e("DownloadRequest.persistIfRequired: can not persist message");
return null; return null;
} }
// Update some of the properties of the message // Update some of the properties of the message
final ContentValues values = new ContentValues(); final ContentValues values = new ContentValues();
values.put(Telephony.Mms.DATE, System.currentTimeMillis() / 1000L); values.put(Telephony.Mms.DATE, System.currentTimeMillis() / 1000L);
@@ -190,24 +186,23 @@ public class DownloadRequest extends MmsRequest {
values.put(Telephony.Mms.SUBSCRIPTION_ID, subId); values.put(Telephony.Mms.SUBSCRIPTION_ID, subId);
} }
if (SqliteWrapper.update( try {
context, context.getContentResolver().update(messageUri, values, null, null);
context.getContentResolver(), } catch (SQLiteException e) {
messageUri, // On MIUI and a couple other devices, the above call will fail and say `no such column: sub_id`
values, // If before making that call, we check to see if the sub_id column is available for messageUri, we will
null/*where*/, // find that it is available, and yet the update call will still fail. So - there's no way we can know
null/*selectionArg*/) != 1) { // in advance that it will fail, and we have to just try again
Timber.e("DownloadRequest.persistIfRequired: can not update message"); if (values.containsKey(Telephony.Mms.SUBSCRIPTION_ID)) {
values.remove(Telephony.Mms.SUBSCRIPTION_ID);
context.getContentResolver().update(messageUri, values, null, null);
} else {
throw e;
}
} }
// Delete the corresponding NotificationInd // Delete the corresponding NotificationInd
SqliteWrapper.delete(context, SqliteWrapper.delete(context, context.getContentResolver(), Telephony.Mms.CONTENT_URI, LOCATION_SELECTION,
context.getContentResolver(), new String[]{Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND), locationUrl});
Telephony.Mms.CONTENT_URI,
LOCATION_SELECTION,
new String[]{
Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND),
locationUrl
});
return messageUri; return messageUri;
} catch (MmsException e) { } catch (MmsException e) {
@@ -131,10 +131,7 @@ public class PushReceiver extends BroadcastReceiver {
// Save the pdu. If we can start downloading the real pdu immediately, // Save the pdu. If we can start downloading the real pdu immediately,
// don't allow persist() to create a thread for the notificationInd // don't allow persist() to create a thread for the notificationInd
// because it causes UI jank. // because it causes UI jank.
Uri uri = p.persist(pdu, Inbox.CONTENT_URI, Uri uri = p.persist(pdu, Inbox.CONTENT_URI, true, true, null);
!NotificationTransaction.allowAutoDownload(mContext),
true,
null);
String location = getContentLocation(mContext, uri); String location = getContentLocation(mContext, uri);
if (downloadedUrls.contains(location)) { if (downloadedUrls.contains(location)) {