diff --git a/android-smsmms/src/main/java/com/android/mms/service_alt/DownloadRequest.java b/android-smsmms/src/main/java/com/android/mms/service_alt/DownloadRequest.java index 4ed6de7e7..8a556aee2 100755 --- a/android-smsmms/src/main/java/com/android/mms/service_alt/DownloadRequest.java +++ b/android-smsmms/src/main/java/com/android/mms/service_alt/DownloadRequest.java @@ -47,20 +47,20 @@ public class DownloadRequest extends MmsRequest { private static final String LOCATION_SELECTION = Telephony.Mms.MESSAGE_TYPE + "=? AND " + Telephony.Mms.CONTENT_LOCATION + " =?"; - static final String[] PROJECTION = new String[] { + static final String[] PROJECTION = new String[]{ Telephony.Mms.CONTENT_LOCATION }; // The indexes of the columns which must be consistent with above PROJECTION. - static final int COLUMN_CONTENT_LOCATION = 0; + static final int COLUMN_CONTENT_LOCATION = 0; private final String mLocationUrl; private final PendingIntent mDownloadedIntent; private final Uri mContentUri; public DownloadRequest(RequestManager manager, int subId, String locationUrl, - Uri contentUri, PendingIntent downloadedIntent, String creator, - Bundle configOverrides, Context context) throws MmsException { + Uri contentUri, PendingIntent downloadedIntent, String creator, + Bundle configOverrides, Context context) throws MmsException { super(manager, subId, creator, configOverrides); if (locationUrl == null) { @@ -167,16 +167,12 @@ public static Uri persist(Context context, byte[] response, MmsConfig.Overridden // } // Store the downloaded message final PduPersister persister = PduPersister.getPduPersister(context); - final Uri messageUri = persister.persist( - pdu, - Telephony.Mms.Inbox.CONTENT_URI, - true/*createThreadId*/, - true/*groupMmsEnabled*/, - null/*preOpenedFiles*/); + final Uri messageUri = persister.persist(pdu, Telephony.Mms.Inbox.CONTENT_URI, true, true, null); if (messageUri == null) { Timber.e("DownloadRequest.persistIfRequired: can not persist message"); return null; } + // Update some of the properties of the message final ContentValues values = new ContentValues(); values.put(Telephony.Mms.DATE, System.currentTimeMillis() / 1000L); @@ -190,24 +186,23 @@ public static Uri persist(Context context, byte[] response, MmsConfig.Overridden values.put(Telephony.Mms.SUBSCRIPTION_ID, subId); } - if (SqliteWrapper.update( - context, - context.getContentResolver(), - messageUri, - values, - null/*where*/, - null/*selectionArg*/) != 1) { - Timber.e("DownloadRequest.persistIfRequired: can not update message"); + try { + context.getContentResolver().update(messageUri, values, null, null); + } catch (SQLiteException e) { + // On MIUI and a couple other devices, the above call will fail and say `no such column: sub_id` + // If before making that call, we check to see if the sub_id column is available for messageUri, we will + // find that it is available, and yet the update call will still fail. So - there's no way we can know + // in advance that it will fail, and we have to just try again + 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 - SqliteWrapper.delete(context, - context.getContentResolver(), - Telephony.Mms.CONTENT_URI, - LOCATION_SELECTION, - new String[]{ - Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND), - locationUrl - }); + SqliteWrapper.delete(context, context.getContentResolver(), Telephony.Mms.CONTENT_URI, LOCATION_SELECTION, + new String[]{Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND), locationUrl}); return messageUri; } catch (MmsException e) { @@ -268,7 +263,7 @@ private static void notifyOfDownload(Context context) { /** * Transfer the received response to the caller (for download requests write to content uri) * - * @param fillIn the intent that will be returned to the caller + * @param fillIn the intent that will be returned to the caller * @param response the pdu to transfer */ @Override @@ -284,7 +279,7 @@ protected boolean prepareForHttpRequest() { /** * Try downloading via the carrier app. * - * @param context The context + * @param context The context * @param carrierMessagingServicePackage The carrier messaging service handling the download */ public void tryDownloadingByCarrierApp(Context context, String carrierMessagingServicePackage) { @@ -322,10 +317,10 @@ private String getContentLocation(Context context, Uri uri) private static Long getId(Context context, String location) { String selection = Telephony.Mms.CONTENT_LOCATION + " = ?"; - String[] selectionArgs = new String[] { location }; + String[] selectionArgs = new String[]{location}; Cursor c = android.database.sqlite.SqliteWrapper.query( context, context.getContentResolver(), - Telephony.Mms.CONTENT_URI, new String[] { Telephony.Mms._ID }, + Telephony.Mms.CONTENT_URI, new String[]{Telephony.Mms._ID}, selection, selectionArgs, null); if (c != null) { try { diff --git a/android-smsmms/src/main/java/com/android/mms/transaction/PushReceiver.java b/android-smsmms/src/main/java/com/android/mms/transaction/PushReceiver.java index aaf964e2f..f8edc5aa7 100755 --- a/android-smsmms/src/main/java/com/android/mms/transaction/PushReceiver.java +++ b/android-smsmms/src/main/java/com/android/mms/transaction/PushReceiver.java @@ -131,10 +131,7 @@ protected Void doInBackground(Intent... intents) { // Save the pdu. If we can start downloading the real pdu immediately, // don't allow persist() to create a thread for the notificationInd // because it causes UI jank. - Uri uri = p.persist(pdu, Inbox.CONTENT_URI, - !NotificationTransaction.allowAutoDownload(mContext), - true, - null); + Uri uri = p.persist(pdu, Inbox.CONTENT_URI, true, true, null); String location = getContentLocation(mContext, uri); if (downloadedUrls.contains(location)) { diff --git a/data/src/main/java/com/moez/QKSMS/receiver/MmsReceivedReceiver.kt b/data/src/main/java/com/moez/QKSMS/receiver/MmsReceivedReceiver.kt index fecf096a6..9e340b084 100644 --- a/data/src/main/java/com/moez/QKSMS/receiver/MmsReceivedReceiver.kt +++ b/data/src/main/java/com/moez/QKSMS/receiver/MmsReceivedReceiver.kt @@ -42,4 +42,4 @@ class MmsReceivedReceiver : MmsReceivedReceiver() { } } -} \ No newline at end of file +}