forked from upstream-mirrors/quik
Formatting for PduPersister
This commit is contained in:
@@ -38,7 +38,6 @@ import android.provider.Telephony.Threads;
|
|||||||
import android.telephony.PhoneNumberUtils;
|
import android.telephony.PhoneNumberUtils;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.google.android.mms.ContentType;
|
import com.google.android.mms.ContentType;
|
||||||
import com.google.android.mms.InvalidHeaderValueException;
|
import com.google.android.mms.InvalidHeaderValueException;
|
||||||
import com.google.android.mms.MmsException;
|
import com.google.android.mms.MmsException;
|
||||||
@@ -78,11 +77,11 @@ public class PduPersister {
|
|||||||
* The uri of temporary drm objects.
|
* The uri of temporary drm objects.
|
||||||
*/
|
*/
|
||||||
public static final String TEMPORARY_DRM_OBJECT_URI =
|
public static final String TEMPORARY_DRM_OBJECT_URI =
|
||||||
"content://mms/" + Long.MAX_VALUE + "/part";
|
"content://mms/" + Long.MAX_VALUE + "/part";
|
||||||
/**
|
/**
|
||||||
* Indicate that we transiently failed to process a MM.
|
* Indicate that we transiently failed to process a MM.
|
||||||
*/
|
*/
|
||||||
public static final int PROC_STATUS_TRANSIENT_FAILURE = 1;
|
public static final int PROC_STATUS_TRANSIENT_FAILURE = 1;
|
||||||
/**
|
/**
|
||||||
* Indicate that we permanently failed to process a MM.
|
* Indicate that we permanently failed to process a MM.
|
||||||
*/
|
*/
|
||||||
@@ -90,97 +89,97 @@ public class PduPersister {
|
|||||||
/**
|
/**
|
||||||
* Indicate that we have successfully processed a MM.
|
* Indicate that we have successfully processed a MM.
|
||||||
*/
|
*/
|
||||||
public static final int PROC_STATUS_COMPLETED = 3;
|
public static final int PROC_STATUS_COMPLETED = 3;
|
||||||
|
|
||||||
private static PduPersister sPersister;
|
private static PduPersister sPersister;
|
||||||
private static final PduCache PDU_CACHE_INSTANCE;
|
private static final PduCache PDU_CACHE_INSTANCE;
|
||||||
|
|
||||||
private static final int[] ADDRESS_FIELDS = new int[] {
|
private static final int[] ADDRESS_FIELDS = new int[]{
|
||||||
PduHeaders.BCC,
|
PduHeaders.BCC,
|
||||||
PduHeaders.CC,
|
PduHeaders.CC,
|
||||||
PduHeaders.FROM,
|
PduHeaders.FROM,
|
||||||
PduHeaders.TO
|
PduHeaders.TO
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final String[] PDU_PROJECTION = new String[] {
|
private static final String[] PDU_PROJECTION = new String[]{
|
||||||
Mms._ID,
|
Mms._ID,
|
||||||
Mms.MESSAGE_BOX,
|
Mms.MESSAGE_BOX,
|
||||||
Mms.THREAD_ID,
|
Mms.THREAD_ID,
|
||||||
Mms.RETRIEVE_TEXT,
|
Mms.RETRIEVE_TEXT,
|
||||||
Mms.SUBJECT,
|
Mms.SUBJECT,
|
||||||
Mms.CONTENT_LOCATION,
|
Mms.CONTENT_LOCATION,
|
||||||
Mms.CONTENT_TYPE,
|
Mms.CONTENT_TYPE,
|
||||||
Mms.MESSAGE_CLASS,
|
Mms.MESSAGE_CLASS,
|
||||||
Mms.MESSAGE_ID,
|
Mms.MESSAGE_ID,
|
||||||
Mms.RESPONSE_TEXT,
|
Mms.RESPONSE_TEXT,
|
||||||
Mms.TRANSACTION_ID,
|
Mms.TRANSACTION_ID,
|
||||||
Mms.CONTENT_CLASS,
|
Mms.CONTENT_CLASS,
|
||||||
Mms.DELIVERY_REPORT,
|
Mms.DELIVERY_REPORT,
|
||||||
Mms.MESSAGE_TYPE,
|
Mms.MESSAGE_TYPE,
|
||||||
Mms.MMS_VERSION,
|
Mms.MMS_VERSION,
|
||||||
Mms.PRIORITY,
|
Mms.PRIORITY,
|
||||||
Mms.READ_REPORT,
|
Mms.READ_REPORT,
|
||||||
Mms.READ_STATUS,
|
Mms.READ_STATUS,
|
||||||
Mms.REPORT_ALLOWED,
|
Mms.REPORT_ALLOWED,
|
||||||
Mms.RETRIEVE_STATUS,
|
Mms.RETRIEVE_STATUS,
|
||||||
Mms.STATUS,
|
Mms.STATUS,
|
||||||
Mms.DATE,
|
Mms.DATE,
|
||||||
Mms.DELIVERY_TIME,
|
Mms.DELIVERY_TIME,
|
||||||
Mms.EXPIRY,
|
Mms.EXPIRY,
|
||||||
Mms.MESSAGE_SIZE,
|
Mms.MESSAGE_SIZE,
|
||||||
Mms.SUBJECT_CHARSET,
|
Mms.SUBJECT_CHARSET,
|
||||||
Mms.RETRIEVE_TEXT_CHARSET,
|
Mms.RETRIEVE_TEXT_CHARSET,
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final int PDU_COLUMN_ID = 0;
|
private static final int PDU_COLUMN_ID = 0;
|
||||||
private static final int PDU_COLUMN_MESSAGE_BOX = 1;
|
private static final int PDU_COLUMN_MESSAGE_BOX = 1;
|
||||||
private static final int PDU_COLUMN_THREAD_ID = 2;
|
private static final int PDU_COLUMN_THREAD_ID = 2;
|
||||||
private static final int PDU_COLUMN_RETRIEVE_TEXT = 3;
|
private static final int PDU_COLUMN_RETRIEVE_TEXT = 3;
|
||||||
private static final int PDU_COLUMN_SUBJECT = 4;
|
private static final int PDU_COLUMN_SUBJECT = 4;
|
||||||
private static final int PDU_COLUMN_CONTENT_LOCATION = 5;
|
private static final int PDU_COLUMN_CONTENT_LOCATION = 5;
|
||||||
private static final int PDU_COLUMN_CONTENT_TYPE = 6;
|
private static final int PDU_COLUMN_CONTENT_TYPE = 6;
|
||||||
private static final int PDU_COLUMN_MESSAGE_CLASS = 7;
|
private static final int PDU_COLUMN_MESSAGE_CLASS = 7;
|
||||||
private static final int PDU_COLUMN_MESSAGE_ID = 8;
|
private static final int PDU_COLUMN_MESSAGE_ID = 8;
|
||||||
private static final int PDU_COLUMN_RESPONSE_TEXT = 9;
|
private static final int PDU_COLUMN_RESPONSE_TEXT = 9;
|
||||||
private static final int PDU_COLUMN_TRANSACTION_ID = 10;
|
private static final int PDU_COLUMN_TRANSACTION_ID = 10;
|
||||||
private static final int PDU_COLUMN_CONTENT_CLASS = 11;
|
private static final int PDU_COLUMN_CONTENT_CLASS = 11;
|
||||||
private static final int PDU_COLUMN_DELIVERY_REPORT = 12;
|
private static final int PDU_COLUMN_DELIVERY_REPORT = 12;
|
||||||
private static final int PDU_COLUMN_MESSAGE_TYPE = 13;
|
private static final int PDU_COLUMN_MESSAGE_TYPE = 13;
|
||||||
private static final int PDU_COLUMN_MMS_VERSION = 14;
|
private static final int PDU_COLUMN_MMS_VERSION = 14;
|
||||||
private static final int PDU_COLUMN_PRIORITY = 15;
|
private static final int PDU_COLUMN_PRIORITY = 15;
|
||||||
private static final int PDU_COLUMN_READ_REPORT = 16;
|
private static final int PDU_COLUMN_READ_REPORT = 16;
|
||||||
private static final int PDU_COLUMN_READ_STATUS = 17;
|
private static final int PDU_COLUMN_READ_STATUS = 17;
|
||||||
private static final int PDU_COLUMN_REPORT_ALLOWED = 18;
|
private static final int PDU_COLUMN_REPORT_ALLOWED = 18;
|
||||||
private static final int PDU_COLUMN_RETRIEVE_STATUS = 19;
|
private static final int PDU_COLUMN_RETRIEVE_STATUS = 19;
|
||||||
private static final int PDU_COLUMN_STATUS = 20;
|
private static final int PDU_COLUMN_STATUS = 20;
|
||||||
private static final int PDU_COLUMN_DATE = 21;
|
private static final int PDU_COLUMN_DATE = 21;
|
||||||
private static final int PDU_COLUMN_DELIVERY_TIME = 22;
|
private static final int PDU_COLUMN_DELIVERY_TIME = 22;
|
||||||
private static final int PDU_COLUMN_EXPIRY = 23;
|
private static final int PDU_COLUMN_EXPIRY = 23;
|
||||||
private static final int PDU_COLUMN_MESSAGE_SIZE = 24;
|
private static final int PDU_COLUMN_MESSAGE_SIZE = 24;
|
||||||
private static final int PDU_COLUMN_SUBJECT_CHARSET = 25;
|
private static final int PDU_COLUMN_SUBJECT_CHARSET = 25;
|
||||||
private static final int PDU_COLUMN_RETRIEVE_TEXT_CHARSET = 26;
|
private static final int PDU_COLUMN_RETRIEVE_TEXT_CHARSET = 26;
|
||||||
|
|
||||||
private static final String[] PART_PROJECTION = new String[] {
|
private static final String[] PART_PROJECTION = new String[]{
|
||||||
Part._ID,
|
Part._ID,
|
||||||
Part.CHARSET,
|
Part.CHARSET,
|
||||||
Part.CONTENT_DISPOSITION,
|
Part.CONTENT_DISPOSITION,
|
||||||
Part.CONTENT_ID,
|
Part.CONTENT_ID,
|
||||||
Part.CONTENT_LOCATION,
|
Part.CONTENT_LOCATION,
|
||||||
Part.CONTENT_TYPE,
|
Part.CONTENT_TYPE,
|
||||||
Part.FILENAME,
|
Part.FILENAME,
|
||||||
Part.NAME,
|
Part.NAME,
|
||||||
Part.TEXT
|
Part.TEXT
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final int PART_COLUMN_ID = 0;
|
private static final int PART_COLUMN_ID = 0;
|
||||||
private static final int PART_COLUMN_CHARSET = 1;
|
private static final int PART_COLUMN_CHARSET = 1;
|
||||||
private static final int PART_COLUMN_CONTENT_DISPOSITION = 2;
|
private static final int PART_COLUMN_CONTENT_DISPOSITION = 2;
|
||||||
private static final int PART_COLUMN_CONTENT_ID = 3;
|
private static final int PART_COLUMN_CONTENT_ID = 3;
|
||||||
private static final int PART_COLUMN_CONTENT_LOCATION = 4;
|
private static final int PART_COLUMN_CONTENT_LOCATION = 4;
|
||||||
private static final int PART_COLUMN_CONTENT_TYPE = 5;
|
private static final int PART_COLUMN_CONTENT_TYPE = 5;
|
||||||
private static final int PART_COLUMN_FILENAME = 6;
|
private static final int PART_COLUMN_FILENAME = 6;
|
||||||
private static final int PART_COLUMN_NAME = 7;
|
private static final int PART_COLUMN_NAME = 7;
|
||||||
private static final int PART_COLUMN_TEXT = 8;
|
private static final int PART_COLUMN_TEXT = 8;
|
||||||
|
|
||||||
private static final HashMap<Uri, Integer> MESSAGE_BOX_MAP;
|
private static final HashMap<Uri, Integer> MESSAGE_BOX_MAP;
|
||||||
// These map are used for convenience in persist() and load().
|
// These map are used for convenience in persist() and load().
|
||||||
@@ -197,9 +196,9 @@ public class PduPersister {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
MESSAGE_BOX_MAP = new HashMap<Uri, Integer>();
|
MESSAGE_BOX_MAP = new HashMap<Uri, Integer>();
|
||||||
MESSAGE_BOX_MAP.put(Mms.Inbox.CONTENT_URI, Mms.MESSAGE_BOX_INBOX);
|
MESSAGE_BOX_MAP.put(Mms.Inbox.CONTENT_URI, Mms.MESSAGE_BOX_INBOX);
|
||||||
MESSAGE_BOX_MAP.put(Mms.Sent.CONTENT_URI, Mms.MESSAGE_BOX_SENT);
|
MESSAGE_BOX_MAP.put(Mms.Sent.CONTENT_URI, Mms.MESSAGE_BOX_SENT);
|
||||||
MESSAGE_BOX_MAP.put(Mms.Draft.CONTENT_URI, Mms.MESSAGE_BOX_DRAFTS);
|
MESSAGE_BOX_MAP.put(Mms.Draft.CONTENT_URI, Mms.MESSAGE_BOX_DRAFTS);
|
||||||
MESSAGE_BOX_MAP.put(Mms.Outbox.CONTENT_URI, Mms.MESSAGE_BOX_OUTBOX);
|
MESSAGE_BOX_MAP.put(Mms.Outbox.CONTENT_URI, Mms.MESSAGE_BOX_OUTBOX);
|
||||||
|
|
||||||
CHARSET_COLUMN_INDEX_MAP = new HashMap<Integer, Integer>();
|
CHARSET_COLUMN_INDEX_MAP = new HashMap<Integer, Integer>();
|
||||||
@@ -275,7 +274,7 @@ public class PduPersister {
|
|||||||
LONG_COLUMN_NAME_MAP.put(PduHeaders.MESSAGE_SIZE, Mms.MESSAGE_SIZE);
|
LONG_COLUMN_NAME_MAP.put(PduHeaders.MESSAGE_SIZE, Mms.MESSAGE_SIZE);
|
||||||
|
|
||||||
PDU_CACHE_INSTANCE = PduCache.getInstance();
|
PDU_CACHE_INSTANCE = PduCache.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final ContentResolver mContentResolver;
|
private final ContentResolver mContentResolver;
|
||||||
@@ -286,11 +285,13 @@ public class PduPersister {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mContentResolver = context.getContentResolver();
|
mContentResolver = context.getContentResolver();
|
||||||
mDrmManagerClient = new DrmManagerClient(context);
|
mDrmManagerClient = new DrmManagerClient(context);
|
||||||
mTelephonyManager = (TelephonyManager)context
|
mTelephonyManager = (TelephonyManager) context
|
||||||
.getSystemService(Context.TELEPHONY_SERVICE);
|
.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get(or create if not exist) an instance of PduPersister */
|
/**
|
||||||
|
* Get(or create if not exist) an instance of PduPersister
|
||||||
|
*/
|
||||||
public static PduPersister getPduPersister(Context context) {
|
public static PduPersister getPduPersister(Context context) {
|
||||||
if ((sPersister == null)) {
|
if ((sPersister == null)) {
|
||||||
sPersister = new PduPersister(context);
|
sPersister = new PduPersister(context);
|
||||||
@@ -440,8 +441,8 @@ public class PduPersister {
|
|||||||
if (ContentType.TEXT_PLAIN.equals(type) || ContentType.APP_SMIL.equals(type)
|
if (ContentType.TEXT_PLAIN.equals(type) || ContentType.APP_SMIL.equals(type)
|
||||||
|| ContentType.TEXT_HTML.equals(type)) {
|
|| ContentType.TEXT_HTML.equals(type)) {
|
||||||
String text = c.getString(PART_COLUMN_TEXT);
|
String text = c.getString(PART_COLUMN_TEXT);
|
||||||
byte [] blob = new EncodedStringValue(text != null ? text : "")
|
byte[] blob = new EncodedStringValue(text != null ? text : "")
|
||||||
.getTextString();
|
.getTextString();
|
||||||
baos.write(blob, 0, blob.length);
|
baos.write(blob, 0, blob.length);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -484,7 +485,7 @@ public class PduPersister {
|
|||||||
private void loadAddress(long msgId, PduHeaders headers) {
|
private void loadAddress(long msgId, PduHeaders headers) {
|
||||||
Cursor c = SqliteWrapper.query(mContext, mContentResolver,
|
Cursor c = SqliteWrapper.query(mContext, mContentResolver,
|
||||||
Uri.parse("content://mms/" + msgId + "/addr"),
|
Uri.parse("content://mms/" + msgId + "/addr"),
|
||||||
new String[] { Addr.ADDRESS, Addr.CHARSET, Addr.TYPE },
|
new String[]{Addr.ADDRESS, Addr.CHARSET, Addr.TYPE},
|
||||||
null, null, null);
|
null, null, null);
|
||||||
|
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
@@ -531,7 +532,7 @@ public class PduPersister {
|
|||||||
int msgBox = 0;
|
int msgBox = 0;
|
||||||
long threadId = DUMMY_THREAD_ID;
|
long threadId = DUMMY_THREAD_ID;
|
||||||
try {
|
try {
|
||||||
synchronized(PDU_CACHE_INSTANCE) {
|
synchronized (PDU_CACHE_INSTANCE) {
|
||||||
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
||||||
if (LOCAL_LOGV) {
|
if (LOCAL_LOGV) {
|
||||||
Log.v(TAG, "load: " + uri + " blocked by isUpdating()");
|
Log.v(TAG, "load: " + uri + " blocked by isUpdating()");
|
||||||
@@ -619,57 +620,57 @@ public class PduPersister {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (msgType) {
|
switch (msgType) {
|
||||||
case PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND:
|
case PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND:
|
||||||
pdu = new NotificationInd(headers);
|
pdu = new NotificationInd(headers);
|
||||||
break;
|
break;
|
||||||
case PduHeaders.MESSAGE_TYPE_DELIVERY_IND:
|
case PduHeaders.MESSAGE_TYPE_DELIVERY_IND:
|
||||||
pdu = new DeliveryInd(headers);
|
pdu = new DeliveryInd(headers);
|
||||||
break;
|
break;
|
||||||
case PduHeaders.MESSAGE_TYPE_READ_ORIG_IND:
|
case PduHeaders.MESSAGE_TYPE_READ_ORIG_IND:
|
||||||
pdu = new ReadOrigInd(headers);
|
pdu = new ReadOrigInd(headers);
|
||||||
break;
|
break;
|
||||||
case PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF:
|
case PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF:
|
||||||
pdu = new RetrieveConf(headers, body);
|
pdu = new RetrieveConf(headers, body);
|
||||||
break;
|
break;
|
||||||
case PduHeaders.MESSAGE_TYPE_SEND_REQ:
|
case PduHeaders.MESSAGE_TYPE_SEND_REQ:
|
||||||
pdu = new SendReq(headers, body);
|
pdu = new SendReq(headers, body);
|
||||||
break;
|
break;
|
||||||
case PduHeaders.MESSAGE_TYPE_ACKNOWLEDGE_IND:
|
case PduHeaders.MESSAGE_TYPE_ACKNOWLEDGE_IND:
|
||||||
pdu = new AcknowledgeInd(headers);
|
pdu = new AcknowledgeInd(headers);
|
||||||
break;
|
break;
|
||||||
case PduHeaders.MESSAGE_TYPE_NOTIFYRESP_IND:
|
case PduHeaders.MESSAGE_TYPE_NOTIFYRESP_IND:
|
||||||
pdu = new NotifyRespInd(headers);
|
pdu = new NotifyRespInd(headers);
|
||||||
break;
|
break;
|
||||||
case PduHeaders.MESSAGE_TYPE_READ_REC_IND:
|
case PduHeaders.MESSAGE_TYPE_READ_REC_IND:
|
||||||
pdu = new ReadRecInd(headers);
|
pdu = new ReadRecInd(headers);
|
||||||
break;
|
break;
|
||||||
case PduHeaders.MESSAGE_TYPE_SEND_CONF:
|
case PduHeaders.MESSAGE_TYPE_SEND_CONF:
|
||||||
case PduHeaders.MESSAGE_TYPE_FORWARD_REQ:
|
case PduHeaders.MESSAGE_TYPE_FORWARD_REQ:
|
||||||
case PduHeaders.MESSAGE_TYPE_FORWARD_CONF:
|
case PduHeaders.MESSAGE_TYPE_FORWARD_CONF:
|
||||||
case PduHeaders.MESSAGE_TYPE_MBOX_STORE_REQ:
|
case PduHeaders.MESSAGE_TYPE_MBOX_STORE_REQ:
|
||||||
case PduHeaders.MESSAGE_TYPE_MBOX_STORE_CONF:
|
case PduHeaders.MESSAGE_TYPE_MBOX_STORE_CONF:
|
||||||
case PduHeaders.MESSAGE_TYPE_MBOX_VIEW_REQ:
|
case PduHeaders.MESSAGE_TYPE_MBOX_VIEW_REQ:
|
||||||
case PduHeaders.MESSAGE_TYPE_MBOX_VIEW_CONF:
|
case PduHeaders.MESSAGE_TYPE_MBOX_VIEW_CONF:
|
||||||
case PduHeaders.MESSAGE_TYPE_MBOX_UPLOAD_REQ:
|
case PduHeaders.MESSAGE_TYPE_MBOX_UPLOAD_REQ:
|
||||||
case PduHeaders.MESSAGE_TYPE_MBOX_UPLOAD_CONF:
|
case PduHeaders.MESSAGE_TYPE_MBOX_UPLOAD_CONF:
|
||||||
case PduHeaders.MESSAGE_TYPE_MBOX_DELETE_REQ:
|
case PduHeaders.MESSAGE_TYPE_MBOX_DELETE_REQ:
|
||||||
case PduHeaders.MESSAGE_TYPE_MBOX_DELETE_CONF:
|
case PduHeaders.MESSAGE_TYPE_MBOX_DELETE_CONF:
|
||||||
case PduHeaders.MESSAGE_TYPE_MBOX_DESCR:
|
case PduHeaders.MESSAGE_TYPE_MBOX_DESCR:
|
||||||
case PduHeaders.MESSAGE_TYPE_DELETE_REQ:
|
case PduHeaders.MESSAGE_TYPE_DELETE_REQ:
|
||||||
case PduHeaders.MESSAGE_TYPE_DELETE_CONF:
|
case PduHeaders.MESSAGE_TYPE_DELETE_CONF:
|
||||||
case PduHeaders.MESSAGE_TYPE_CANCEL_REQ:
|
case PduHeaders.MESSAGE_TYPE_CANCEL_REQ:
|
||||||
case PduHeaders.MESSAGE_TYPE_CANCEL_CONF:
|
case PduHeaders.MESSAGE_TYPE_CANCEL_CONF:
|
||||||
throw new MmsException(
|
throw new MmsException(
|
||||||
"Unsupported PDU type: " + Integer.toHexString(msgType));
|
"Unsupported PDU type: " + Integer.toHexString(msgType));
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new MmsException(
|
throw new MmsException(
|
||||||
"Unrecognized PDU type: " + Integer.toHexString(msgType));
|
"Unrecognized PDU type: " + Integer.toHexString(msgType));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
synchronized(PDU_CACHE_INSTANCE) {
|
synchronized (PDU_CACHE_INSTANCE) {
|
||||||
if (pdu != null) {
|
if (pdu != null) {
|
||||||
assert(PDU_CACHE_INSTANCE.get(uri) == null);
|
assert (PDU_CACHE_INSTANCE.get(uri) == null);
|
||||||
// Update the cache entry with the real info
|
// Update the cache entry with the real info
|
||||||
cacheEntry = new PduCacheEntry(pdu, msgBox, threadId);
|
cacheEntry = new PduCacheEntry(pdu, msgBox, threadId);
|
||||||
PDU_CACHE_INSTANCE.put(uri, cacheEntry);
|
PDU_CACHE_INSTANCE.put(uri, cacheEntry);
|
||||||
@@ -706,7 +707,7 @@ public class PduPersister {
|
|||||||
ContentValues values = new ContentValues(8);
|
ContentValues values = new ContentValues(8);
|
||||||
|
|
||||||
int charset = part.getCharset();
|
int charset = part.getCharset();
|
||||||
if (charset != 0 ) {
|
if (charset != 0) {
|
||||||
values.put(Part.CHARSET, charset);
|
values.put(Part.CHARSET, charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -800,15 +801,15 @@ public class PduPersister {
|
|||||||
* save it. If the data is an image, we may scale down it according
|
* save it. If the data is an image, we may scale down it according
|
||||||
* to user preference.
|
* to user preference.
|
||||||
*
|
*
|
||||||
* @param part The PDU part which contains data to be saved.
|
* @param part The PDU part which contains data to be saved.
|
||||||
* @param uri The URI of the part.
|
* @param uri The URI of the part.
|
||||||
* @param contentType The MIME type of the part.
|
* @param contentType The MIME type of the part.
|
||||||
* @param preOpenedFiles if not null, a map of preopened InputStreams for the parts.
|
* @param preOpenedFiles if not null, a map of preopened InputStreams for the parts.
|
||||||
* @throws MmsException Cannot find source data or error occurred
|
* @throws MmsException Cannot find source data or error occurred
|
||||||
* while saving the data.
|
* while saving the data.
|
||||||
*/
|
*/
|
||||||
private void persistData(PduPart part, Uri uri,
|
private void persistData(PduPart part, Uri uri,
|
||||||
String contentType, HashMap<Uri, InputStream> preOpenedFiles)
|
String contentType, HashMap<Uri, InputStream> preOpenedFiles)
|
||||||
throws MmsException {
|
throws MmsException {
|
||||||
OutputStream os = null;
|
OutputStream os = null;
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
@@ -949,18 +950,18 @@ public class PduPersister {
|
|||||||
File f = new File(path);
|
File f = new File(path);
|
||||||
ContentValues values = new ContentValues(0);
|
ContentValues values = new ContentValues(0);
|
||||||
SqliteWrapper.update(mContext, mContentResolver,
|
SqliteWrapper.update(mContext, mContentResolver,
|
||||||
Uri.parse("content://mms/resetFilePerm/" + f.getName()),
|
Uri.parse("content://mms/resetFilePerm/" + f.getName()),
|
||||||
values, null, null);
|
values, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method expects uri in the following format
|
* This method expects uri in the following format
|
||||||
* content://media/<table_name>/<row_index> (or)
|
* content://media/<table_name>/<row_index> (or)
|
||||||
* file://sdcard/test.mp4
|
* file://sdcard/test.mp4
|
||||||
* http://test.com/test.mp4
|
* http://test.com/test.mp4
|
||||||
*
|
* <p>
|
||||||
* Here <table_name> shall be "video" or "audio" or "images"
|
* Here <table_name> shall be "video" or "audio" or "images"
|
||||||
* <row_index> the index of the content in given table
|
* <row_index> the index of the content in given table
|
||||||
*/
|
*/
|
||||||
@@ -976,7 +977,7 @@ public class PduPersister {
|
|||||||
path = uri.toString();
|
path = uri.toString();
|
||||||
|
|
||||||
} else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
|
} else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
|
||||||
String[] projection = new String[] {MediaStore.MediaColumns.DATA};
|
String[] projection = new String[]{MediaStore.MediaColumns.DATA};
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
cursor = context.getContentResolver().query(uri, projection, null,
|
cursor = context.getContentResolver().query(uri, projection, null,
|
||||||
@@ -1015,12 +1016,12 @@ public class PduPersister {
|
|||||||
/**
|
/**
|
||||||
* Update headers of a SendReq.
|
* Update headers of a SendReq.
|
||||||
*
|
*
|
||||||
* @param uri The PDU which need to be updated.
|
* @param uri The PDU which need to be updated.
|
||||||
* @param sendReq New headers.
|
* @param sendReq New headers.
|
||||||
* @throws MmsException Bad URI or updating failed.
|
* @throws MmsException Bad URI or updating failed.
|
||||||
*/
|
*/
|
||||||
public void updateHeaders(Uri uri, SendReq sendReq) {
|
public void updateHeaders(Uri uri, SendReq sendReq) {
|
||||||
synchronized(PDU_CACHE_INSTANCE) {
|
synchronized (PDU_CACHE_INSTANCE) {
|
||||||
// If the cache item is getting updated, wait until it's done updating before
|
// If the cache item is getting updated, wait until it's done updating before
|
||||||
// purging it.
|
// purging it.
|
||||||
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
||||||
@@ -1129,7 +1130,7 @@ public class PduPersister {
|
|||||||
ContentValues values = new ContentValues(7);
|
ContentValues values = new ContentValues(7);
|
||||||
|
|
||||||
int charset = part.getCharset();
|
int charset = part.getCharset();
|
||||||
if (charset != 0 ) {
|
if (charset != 0) {
|
||||||
values.put(Part.CHARSET, charset);
|
values.put(Part.CHARSET, charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1181,8 +1182,8 @@ public class PduPersister {
|
|||||||
/**
|
/**
|
||||||
* Update all parts of a PDU.
|
* Update all parts of a PDU.
|
||||||
*
|
*
|
||||||
* @param uri The PDU which need to be updated.
|
* @param uri The PDU which need to be updated.
|
||||||
* @param body New message body of the PDU.
|
* @param body New message body of the PDU.
|
||||||
* @param preOpenedFiles if not null, a map of preopened InputStreams for the parts.
|
* @param preOpenedFiles if not null, a map of preopened InputStreams for the parts.
|
||||||
* @throws MmsException Bad URI or updating failed.
|
* @throws MmsException Bad URI or updating failed.
|
||||||
*/
|
*/
|
||||||
@@ -1190,7 +1191,7 @@ public class PduPersister {
|
|||||||
throws MmsException {
|
throws MmsException {
|
||||||
try {
|
try {
|
||||||
PduCacheEntry cacheEntry;
|
PduCacheEntry cacheEntry;
|
||||||
synchronized(PDU_CACHE_INSTANCE) {
|
synchronized (PDU_CACHE_INSTANCE) {
|
||||||
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
||||||
if (LOCAL_LOGV) {
|
if (LOCAL_LOGV) {
|
||||||
Log.v(TAG, "updateParts: " + uri + " blocked by isUpdating()");
|
Log.v(TAG, "updateParts: " + uri + " blocked by isUpdating()");
|
||||||
@@ -1253,7 +1254,7 @@ public class PduPersister {
|
|||||||
updatePart(e.getKey(), e.getValue(), preOpenedFiles);
|
updatePart(e.getKey(), e.getValue(), preOpenedFiles);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
synchronized(PDU_CACHE_INSTANCE) {
|
synchronized (PDU_CACHE_INSTANCE) {
|
||||||
PDU_CACHE_INSTANCE.setUpdating(uri, false);
|
PDU_CACHE_INSTANCE.setUpdating(uri, false);
|
||||||
PDU_CACHE_INSTANCE.notifyAll();
|
PDU_CACHE_INSTANCE.notifyAll();
|
||||||
}
|
}
|
||||||
@@ -1263,38 +1264,40 @@ public class PduPersister {
|
|||||||
/**
|
/**
|
||||||
* Persist a PDU object to specific location in the storage.
|
* Persist a PDU object to specific location in the storage.
|
||||||
*
|
*
|
||||||
* @param pdu The PDU object to be stored.
|
* @param pdu The PDU object to be stored.
|
||||||
* @param uri Where to store the given PDU object.
|
* @param uri Where to store the given PDU object.
|
||||||
* @param createThreadId if true, this function may create a thread id for the recipients
|
* @param createThreadId if true, this function may create a thread id for the recipients
|
||||||
* @param groupMmsEnabled if true, all of the recipients addressed in the PDU will be used
|
* @param groupMmsEnabled if true, all of the recipients addressed in the PDU will be used
|
||||||
* to create the associated thread. When false, only the sender will be used in finding or
|
* to create the associated thread. When false, only the sender will be used in finding or
|
||||||
* creating the appropriate thread or conversation.
|
* creating the appropriate thread or conversation.
|
||||||
* @param preOpenedFiles if not null, a map of preopened InputStreams for the parts.
|
* @param preOpenedFiles if not null, a map of preopened InputStreams for the parts.
|
||||||
* @return A Uri which can be used to access the stored PDU.
|
* @return A Uri which can be used to access the stored PDU.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Uri persist(GenericPdu pdu, Uri uri, boolean createThreadId, boolean groupMmsEnabled,
|
public Uri persist(GenericPdu pdu, Uri uri, boolean createThreadId, boolean groupMmsEnabled,
|
||||||
HashMap<Uri, InputStream> preOpenedFiles)
|
HashMap<Uri, InputStream> preOpenedFiles) throws MmsException {
|
||||||
throws MmsException {
|
|
||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
throw new MmsException("Uri may not be null.");
|
throw new MmsException("Uri may not be null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
long msgId = -1;
|
long msgId = -1;
|
||||||
try {
|
try {
|
||||||
msgId = ContentUris.parseId(uri);
|
msgId = ContentUris.parseId(uri);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
// the uri ends with "inbox" or something else like that
|
// the uri ends with "inbox" or something else like that
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean existingUri = msgId != -1;
|
boolean existingUri = msgId != -1;
|
||||||
|
|
||||||
if (!existingUri && MESSAGE_BOX_MAP.get(uri) == null) {
|
if (!existingUri && MESSAGE_BOX_MAP.get(uri) == null) {
|
||||||
throw new MmsException(
|
throw new MmsException(
|
||||||
"Bad destination, must be one of "
|
"Bad destination, must be one of "
|
||||||
+ "content://mms/inbox, content://mms/sent, "
|
+ "content://mms/inbox, content://mms/sent, "
|
||||||
+ "content://mms/drafts, content://mms/outbox, "
|
+ "content://mms/drafts, content://mms/outbox, "
|
||||||
+ "content://mms/temp.");
|
+ "content://mms/temp.");
|
||||||
}
|
}
|
||||||
synchronized(PDU_CACHE_INSTANCE) {
|
synchronized (PDU_CACHE_INSTANCE) {
|
||||||
// If the cache item is getting updated, wait until it's done updating before
|
// If the cache item is getting updated, wait until it's done updating before
|
||||||
// purging it.
|
// purging it.
|
||||||
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
||||||
@@ -1327,7 +1330,7 @@ public class PduPersister {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set = TEXT_STRING_COLUMN_NAME_MAP.entrySet();
|
set = TEXT_STRING_COLUMN_NAME_MAP.entrySet();
|
||||||
for (Entry<Integer, String> e : set){
|
for (Entry<Integer, String> e : set) {
|
||||||
byte[] text = header.getTextString(e.getKey());
|
byte[] text = header.getTextString(e.getKey());
|
||||||
if (text != null) {
|
if (text != null) {
|
||||||
values.put(e.getValue(), toIsoString(text));
|
values.put(e.getValue(), toIsoString(text));
|
||||||
@@ -1335,7 +1338,7 @@ public class PduPersister {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set = OCTET_COLUMN_NAME_MAP.entrySet();
|
set = OCTET_COLUMN_NAME_MAP.entrySet();
|
||||||
for (Entry<Integer, String> e : set){
|
for (Entry<Integer, String> e : set) {
|
||||||
int b = header.getOctet(e.getKey());
|
int b = header.getOctet(e.getKey());
|
||||||
if (b != 0) {
|
if (b != 0) {
|
||||||
values.put(e.getValue(), b);
|
values.put(e.getValue(), b);
|
||||||
@@ -1343,7 +1346,7 @@ public class PduPersister {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set = LONG_COLUMN_NAME_MAP.entrySet();
|
set = LONG_COLUMN_NAME_MAP.entrySet();
|
||||||
for (Entry<Integer, String> e : set){
|
for (Entry<Integer, String> e : set) {
|
||||||
long l = header.getLongInteger(e.getKey());
|
long l = header.getLongInteger(e.getKey());
|
||||||
if (l != -1L) {
|
if (l != -1L) {
|
||||||
values.put(e.getValue(), l);
|
values.put(e.getValue(), l);
|
||||||
@@ -1473,8 +1476,8 @@ public class PduPersister {
|
|||||||
values = new ContentValues(1);
|
values = new ContentValues(1);
|
||||||
values.put(Part.MSG_ID, msgId);
|
values.put(Part.MSG_ID, msgId);
|
||||||
SqliteWrapper.update(mContext, mContentResolver,
|
SqliteWrapper.update(mContext, mContentResolver,
|
||||||
Uri.parse("content://mms/" + dummyId + "/part"),
|
Uri.parse("content://mms/" + dummyId + "/part"),
|
||||||
values, null, null);
|
values, null, null);
|
||||||
// We should return the longest URI of the persisted PDU, for
|
// We should return the longest URI of the persisted PDU, for
|
||||||
// example, if input URI is "content://mms/inbox" and the _ID of
|
// example, if input URI is "content://mms/inbox" and the _ID of
|
||||||
// persisted PDU is '8', we should return "content://mms/inbox/8"
|
// persisted PDU is '8', we should return "content://mms/inbox/8"
|
||||||
@@ -1498,13 +1501,13 @@ public class PduPersister {
|
|||||||
/**
|
/**
|
||||||
* For a given address type, extract the recipients from the headers.
|
* For a given address type, extract the recipients from the headers.
|
||||||
*
|
*
|
||||||
* @param addressType can be PduHeaders.FROM, PduHeaders.TO or PduHeaders.CC
|
* @param addressType can be PduHeaders.FROM, PduHeaders.TO or PduHeaders.CC
|
||||||
* @param recipients a HashSet that is loaded with the recipients from the FROM, TO or CC headers
|
* @param recipients a HashSet that is loaded with the recipients from the FROM, TO or CC headers
|
||||||
* @param addressMap a HashMap of the addresses from the ADDRESS_FIELDS header
|
* @param addressMap a HashMap of the addresses from the ADDRESS_FIELDS header
|
||||||
* @param excludeMyNumber if true, the number of this phone will be excluded from recipients
|
* @param excludeMyNumber if true, the number of this phone will be excluded from recipients
|
||||||
*/
|
*/
|
||||||
private void loadRecipients(int addressType, HashSet<String> recipients,
|
private void loadRecipients(int addressType, HashSet<String> recipients,
|
||||||
HashMap<Integer, EncodedStringValue[]> addressMap, boolean excludeMyNumber) {
|
HashMap<Integer, EncodedStringValue[]> addressMap, boolean excludeMyNumber) {
|
||||||
EncodedStringValue[] array = addressMap.get(addressType);
|
EncodedStringValue[] array = addressMap.get(addressType);
|
||||||
if (array == null) {
|
if (array == null) {
|
||||||
return;
|
return;
|
||||||
@@ -1533,10 +1536,10 @@ public class PduPersister {
|
|||||||
* Move a PDU object from one location to another.
|
* Move a PDU object from one location to another.
|
||||||
*
|
*
|
||||||
* @param from Specify the PDU object to be moved.
|
* @param from Specify the PDU object to be moved.
|
||||||
* @param to The destination location, should be one of the following:
|
* @param to The destination location, should be one of the following:
|
||||||
* "content://mms/inbox", "content://mms/sent",
|
* "content://mms/inbox", "content://mms/sent",
|
||||||
* "content://mms/drafts", "content://mms/outbox",
|
* "content://mms/drafts", "content://mms/outbox",
|
||||||
* "content://mms/trash".
|
* "content://mms/trash".
|
||||||
* @return New Uri of the moved PDU.
|
* @return New Uri of the moved PDU.
|
||||||
* @throws MmsException Error occurred while moving the message.
|
* @throws MmsException Error occurred while moving the message.
|
||||||
*/
|
*/
|
||||||
@@ -1552,9 +1555,9 @@ public class PduPersister {
|
|||||||
if (msgBox == null) {
|
if (msgBox == null) {
|
||||||
throw new MmsException(
|
throw new MmsException(
|
||||||
"Bad destination, must be one of "
|
"Bad destination, must be one of "
|
||||||
+ "content://mms/inbox, content://mms/sent, "
|
+ "content://mms/inbox, content://mms/sent, "
|
||||||
+ "content://mms/drafts, content://mms/outbox, "
|
+ "content://mms/drafts, content://mms/outbox, "
|
||||||
+ "content://mms/temp.");
|
+ "content://mms/temp.");
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentValues values = new ContentValues(1);
|
ContentValues values = new ContentValues(1);
|
||||||
@@ -1602,8 +1605,8 @@ public class PduPersister {
|
|||||||
*/
|
*/
|
||||||
public Cursor getPendingMessages(long dueTime) {
|
public Cursor getPendingMessages(long dueTime) {
|
||||||
if (!checkReadSmsPermissions()) {
|
if (!checkReadSmsPermissions()) {
|
||||||
Log.w(TAG, "No read sms permissions have been granted");
|
Log.w(TAG, "No read sms permissions have been granted");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Uri.Builder uriBuilder = PendingMessages.CONTENT_URI.buildUpon();
|
Uri.Builder uriBuilder = PendingMessages.CONTENT_URI.buildUpon();
|
||||||
uriBuilder.appendQueryParameter("protocol", "mms");
|
uriBuilder.appendQueryParameter("protocol", "mms");
|
||||||
@@ -1611,7 +1614,7 @@ public class PduPersister {
|
|||||||
String selection = PendingMessages.ERROR_TYPE + " < ?"
|
String selection = PendingMessages.ERROR_TYPE + " < ?"
|
||||||
+ " AND " + PendingMessages.DUE_TIME + " <= ?";
|
+ " AND " + PendingMessages.DUE_TIME + " <= ?";
|
||||||
|
|
||||||
String[] selectionArgs = new String[] {
|
String[] selectionArgs = new String[]{
|
||||||
String.valueOf(MmsSms.ERR_TYPE_GENERIC_PERMANENT),
|
String.valueOf(MmsSms.ERR_TYPE_GENERIC_PERMANENT),
|
||||||
String.valueOf(dueTime)
|
String.valueOf(dueTime)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -75,8 +75,6 @@ public class Transaction {
|
|||||||
public static Settings settings;
|
public static Settings settings;
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
private Intent explicitSentMmsReceiver;
|
|
||||||
|
|
||||||
private boolean saveMessage = true;
|
private boolean saveMessage = true;
|
||||||
|
|
||||||
public String SMS_SENT = ".SMS_SENT";
|
public String SMS_SENT = ".SMS_SENT";
|
||||||
@@ -381,9 +379,8 @@ public class Transaction {
|
|||||||
data.add(part);
|
data.add(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.v(TAG, "using lollipop method for sending sms");
|
Log.v(TAG, "sending mms");
|
||||||
Log.v(TAG, "using system method for sending");
|
sendMmsThroughSystem(context, subject, data, addresses);
|
||||||
sendMmsThroughSystem(context, subject, data, addresses, explicitSentMmsReceiver);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MessageInfo getBytes(Context context, boolean saveMessage, String[] recipients, MMSPart[] parts,
|
public static MessageInfo getBytes(Context context, boolean saveMessage, String[] recipients, MMSPart[] parts,
|
||||||
@@ -509,8 +506,7 @@ public class Transaction {
|
|||||||
public static final long DEFAULT_EXPIRY_TIME = 7 * 24 * 60 * 60;
|
public static final long DEFAULT_EXPIRY_TIME = 7 * 24 * 60 * 60;
|
||||||
public static final int DEFAULT_PRIORITY = PduHeaders.PRIORITY_NORMAL;
|
public static final int DEFAULT_PRIORITY = PduHeaders.PRIORITY_NORMAL;
|
||||||
|
|
||||||
private static void sendMmsThroughSystem(Context context, String subject, List<MMSPart> parts, String[] addresses,
|
private static void sendMmsThroughSystem(Context context, String subject, List<MMSPart> parts, String[] addresses) {
|
||||||
Intent explicitSentMmsReceiver) {
|
|
||||||
try {
|
try {
|
||||||
final String fileName = "send." + String.valueOf(Math.abs(new Random().nextLong())) + ".dat";
|
final String fileName = "send." + String.valueOf(Math.abs(new Random().nextLong())) + ".dat";
|
||||||
File mSendFile = new File(context.getCacheDir(), fileName);
|
File mSendFile = new File(context.getCacheDir(), fileName);
|
||||||
@@ -520,13 +516,8 @@ public class Transaction {
|
|||||||
Uri messageUri = persister.persist(sendReq, Uri.parse("content://mms/outbox"),
|
Uri messageUri = persister.persist(sendReq, Uri.parse("content://mms/outbox"),
|
||||||
true, true, null);
|
true, true, null);
|
||||||
|
|
||||||
Intent intent;
|
Intent intent = new Intent(MmsSentReceiver.MMS_SENT);
|
||||||
if (explicitSentMmsReceiver == null) {
|
BroadcastUtils.addClassName(context, intent, MmsSentReceiver.MMS_SENT);
|
||||||
intent = new Intent(MmsSentReceiver.MMS_SENT);
|
|
||||||
BroadcastUtils.addClassName(context, intent, MmsSentReceiver.MMS_SENT);
|
|
||||||
} else {
|
|
||||||
intent = explicitSentMmsReceiver;
|
|
||||||
}
|
|
||||||
|
|
||||||
intent.putExtra(MmsSentReceiver.EXTRA_CONTENT_URI, messageUri.toString());
|
intent.putExtra(MmsSentReceiver.EXTRA_CONTENT_URI, messageUri.toString());
|
||||||
intent.putExtra(MmsSentReceiver.EXTRA_FILE_PATH, mSendFile.getPath());
|
intent.putExtra(MmsSentReceiver.EXTRA_FILE_PATH, mSendFile.getPath());
|
||||||
|
|||||||
Reference in New Issue
Block a user