forked from upstream-mirrors/quik
#945 - Fix MMS reception for MIUI devices
This commit is contained in:
@@ -47,20 +47,20 @@ public class DownloadRequest extends MmsRequest {
|
|||||||
private static final String LOCATION_SELECTION =
|
private static final String LOCATION_SELECTION =
|
||||||
Telephony.Mms.MESSAGE_TYPE + "=? AND " + Telephony.Mms.CONTENT_LOCATION + " =?";
|
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
|
Telephony.Mms.CONTENT_LOCATION
|
||||||
};
|
};
|
||||||
|
|
||||||
// The indexes of the columns which must be consistent with above PROJECTION.
|
// 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 String mLocationUrl;
|
||||||
private final PendingIntent mDownloadedIntent;
|
private final PendingIntent mDownloadedIntent;
|
||||||
private final Uri mContentUri;
|
private final Uri mContentUri;
|
||||||
|
|
||||||
public DownloadRequest(RequestManager manager, int subId, String locationUrl,
|
public DownloadRequest(RequestManager manager, int subId, String locationUrl,
|
||||||
Uri contentUri, PendingIntent downloadedIntent, String creator,
|
Uri contentUri, PendingIntent downloadedIntent, String creator,
|
||||||
Bundle configOverrides, Context context) throws MmsException {
|
Bundle configOverrides, Context context) throws MmsException {
|
||||||
super(manager, subId, creator, configOverrides);
|
super(manager, subId, creator, configOverrides);
|
||||||
|
|
||||||
if (locationUrl == null) {
|
if (locationUrl == null) {
|
||||||
@@ -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) {
|
||||||
@@ -268,7 +263,7 @@ public class DownloadRequest extends MmsRequest {
|
|||||||
/**
|
/**
|
||||||
* Transfer the received response to the caller (for download requests write to content uri)
|
* 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
|
* @param response the pdu to transfer
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -284,7 +279,7 @@ public class DownloadRequest extends MmsRequest {
|
|||||||
/**
|
/**
|
||||||
* Try downloading via the carrier app.
|
* Try downloading via the carrier app.
|
||||||
*
|
*
|
||||||
* @param context The context
|
* @param context The context
|
||||||
* @param carrierMessagingServicePackage The carrier messaging service handling the download
|
* @param carrierMessagingServicePackage The carrier messaging service handling the download
|
||||||
*/
|
*/
|
||||||
public void tryDownloadingByCarrierApp(Context context, String carrierMessagingServicePackage) {
|
public void tryDownloadingByCarrierApp(Context context, String carrierMessagingServicePackage) {
|
||||||
@@ -322,10 +317,10 @@ public class DownloadRequest extends MmsRequest {
|
|||||||
|
|
||||||
private static Long getId(Context context, String location) {
|
private static Long getId(Context context, String location) {
|
||||||
String selection = Telephony.Mms.CONTENT_LOCATION + " = ?";
|
String selection = Telephony.Mms.CONTENT_LOCATION + " = ?";
|
||||||
String[] selectionArgs = new String[] { location };
|
String[] selectionArgs = new String[]{location};
|
||||||
Cursor c = android.database.sqlite.SqliteWrapper.query(
|
Cursor c = android.database.sqlite.SqliteWrapper.query(
|
||||||
context, context.getContentResolver(),
|
context, context.getContentResolver(),
|
||||||
Telephony.Mms.CONTENT_URI, new String[] { Telephony.Mms._ID },
|
Telephony.Mms.CONTENT_URI, new String[]{Telephony.Mms._ID},
|
||||||
selection, selectionArgs, null);
|
selection, selectionArgs, null);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -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)) {
|
||||||
|
|||||||
@@ -42,4 +42,4 @@ class MmsReceivedReceiver : MmsReceivedReceiver() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user