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.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.google.android.mms.ContentType;
|
||||
import com.google.android.mms.InvalidHeaderValueException;
|
||||
import com.google.android.mms.MmsException;
|
||||
@@ -78,11 +77,11 @@ public class PduPersister {
|
||||
* The uri of temporary drm objects.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@@ -90,97 +89,97 @@ public class PduPersister {
|
||||
/**
|
||||
* 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 final PduCache PDU_CACHE_INSTANCE;
|
||||
|
||||
private static final int[] ADDRESS_FIELDS = new int[] {
|
||||
private static final int[] ADDRESS_FIELDS = new int[]{
|
||||
PduHeaders.BCC,
|
||||
PduHeaders.CC,
|
||||
PduHeaders.FROM,
|
||||
PduHeaders.TO
|
||||
};
|
||||
|
||||
private static final String[] PDU_PROJECTION = new String[] {
|
||||
Mms._ID,
|
||||
Mms.MESSAGE_BOX,
|
||||
Mms.THREAD_ID,
|
||||
Mms.RETRIEVE_TEXT,
|
||||
Mms.SUBJECT,
|
||||
Mms.CONTENT_LOCATION,
|
||||
Mms.CONTENT_TYPE,
|
||||
Mms.MESSAGE_CLASS,
|
||||
Mms.MESSAGE_ID,
|
||||
Mms.RESPONSE_TEXT,
|
||||
Mms.TRANSACTION_ID,
|
||||
Mms.CONTENT_CLASS,
|
||||
Mms.DELIVERY_REPORT,
|
||||
Mms.MESSAGE_TYPE,
|
||||
Mms.MMS_VERSION,
|
||||
Mms.PRIORITY,
|
||||
Mms.READ_REPORT,
|
||||
Mms.READ_STATUS,
|
||||
Mms.REPORT_ALLOWED,
|
||||
Mms.RETRIEVE_STATUS,
|
||||
Mms.STATUS,
|
||||
Mms.DATE,
|
||||
Mms.DELIVERY_TIME,
|
||||
Mms.EXPIRY,
|
||||
Mms.MESSAGE_SIZE,
|
||||
Mms.SUBJECT_CHARSET,
|
||||
Mms.RETRIEVE_TEXT_CHARSET,
|
||||
private static final String[] PDU_PROJECTION = new String[]{
|
||||
Mms._ID,
|
||||
Mms.MESSAGE_BOX,
|
||||
Mms.THREAD_ID,
|
||||
Mms.RETRIEVE_TEXT,
|
||||
Mms.SUBJECT,
|
||||
Mms.CONTENT_LOCATION,
|
||||
Mms.CONTENT_TYPE,
|
||||
Mms.MESSAGE_CLASS,
|
||||
Mms.MESSAGE_ID,
|
||||
Mms.RESPONSE_TEXT,
|
||||
Mms.TRANSACTION_ID,
|
||||
Mms.CONTENT_CLASS,
|
||||
Mms.DELIVERY_REPORT,
|
||||
Mms.MESSAGE_TYPE,
|
||||
Mms.MMS_VERSION,
|
||||
Mms.PRIORITY,
|
||||
Mms.READ_REPORT,
|
||||
Mms.READ_STATUS,
|
||||
Mms.REPORT_ALLOWED,
|
||||
Mms.RETRIEVE_STATUS,
|
||||
Mms.STATUS,
|
||||
Mms.DATE,
|
||||
Mms.DELIVERY_TIME,
|
||||
Mms.EXPIRY,
|
||||
Mms.MESSAGE_SIZE,
|
||||
Mms.SUBJECT_CHARSET,
|
||||
Mms.RETRIEVE_TEXT_CHARSET,
|
||||
};
|
||||
|
||||
private static final int PDU_COLUMN_ID = 0;
|
||||
private static final int PDU_COLUMN_MESSAGE_BOX = 1;
|
||||
private static final int PDU_COLUMN_THREAD_ID = 2;
|
||||
private static final int PDU_COLUMN_RETRIEVE_TEXT = 3;
|
||||
private static final int PDU_COLUMN_SUBJECT = 4;
|
||||
private static final int PDU_COLUMN_CONTENT_LOCATION = 5;
|
||||
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_ID = 8;
|
||||
private static final int PDU_COLUMN_RESPONSE_TEXT = 9;
|
||||
private static final int PDU_COLUMN_TRANSACTION_ID = 10;
|
||||
private static final int PDU_COLUMN_CONTENT_CLASS = 11;
|
||||
private static final int PDU_COLUMN_DELIVERY_REPORT = 12;
|
||||
private static final int PDU_COLUMN_MESSAGE_TYPE = 13;
|
||||
private static final int PDU_COLUMN_MMS_VERSION = 14;
|
||||
private static final int PDU_COLUMN_PRIORITY = 15;
|
||||
private static final int PDU_COLUMN_READ_REPORT = 16;
|
||||
private static final int PDU_COLUMN_READ_STATUS = 17;
|
||||
private static final int PDU_COLUMN_REPORT_ALLOWED = 18;
|
||||
private static final int PDU_COLUMN_RETRIEVE_STATUS = 19;
|
||||
private static final int PDU_COLUMN_STATUS = 20;
|
||||
private static final int PDU_COLUMN_DATE = 21;
|
||||
private static final int PDU_COLUMN_DELIVERY_TIME = 22;
|
||||
private static final int PDU_COLUMN_EXPIRY = 23;
|
||||
private static final int PDU_COLUMN_MESSAGE_SIZE = 24;
|
||||
private static final int PDU_COLUMN_SUBJECT_CHARSET = 25;
|
||||
private static final int PDU_COLUMN_ID = 0;
|
||||
private static final int PDU_COLUMN_MESSAGE_BOX = 1;
|
||||
private static final int PDU_COLUMN_THREAD_ID = 2;
|
||||
private static final int PDU_COLUMN_RETRIEVE_TEXT = 3;
|
||||
private static final int PDU_COLUMN_SUBJECT = 4;
|
||||
private static final int PDU_COLUMN_CONTENT_LOCATION = 5;
|
||||
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_ID = 8;
|
||||
private static final int PDU_COLUMN_RESPONSE_TEXT = 9;
|
||||
private static final int PDU_COLUMN_TRANSACTION_ID = 10;
|
||||
private static final int PDU_COLUMN_CONTENT_CLASS = 11;
|
||||
private static final int PDU_COLUMN_DELIVERY_REPORT = 12;
|
||||
private static final int PDU_COLUMN_MESSAGE_TYPE = 13;
|
||||
private static final int PDU_COLUMN_MMS_VERSION = 14;
|
||||
private static final int PDU_COLUMN_PRIORITY = 15;
|
||||
private static final int PDU_COLUMN_READ_REPORT = 16;
|
||||
private static final int PDU_COLUMN_READ_STATUS = 17;
|
||||
private static final int PDU_COLUMN_REPORT_ALLOWED = 18;
|
||||
private static final int PDU_COLUMN_RETRIEVE_STATUS = 19;
|
||||
private static final int PDU_COLUMN_STATUS = 20;
|
||||
private static final int PDU_COLUMN_DATE = 21;
|
||||
private static final int PDU_COLUMN_DELIVERY_TIME = 22;
|
||||
private static final int PDU_COLUMN_EXPIRY = 23;
|
||||
private static final int PDU_COLUMN_MESSAGE_SIZE = 24;
|
||||
private static final int PDU_COLUMN_SUBJECT_CHARSET = 25;
|
||||
private static final int PDU_COLUMN_RETRIEVE_TEXT_CHARSET = 26;
|
||||
|
||||
private static final String[] PART_PROJECTION = new String[] {
|
||||
Part._ID,
|
||||
Part.CHARSET,
|
||||
Part.CONTENT_DISPOSITION,
|
||||
Part.CONTENT_ID,
|
||||
Part.CONTENT_LOCATION,
|
||||
Part.CONTENT_TYPE,
|
||||
Part.FILENAME,
|
||||
Part.NAME,
|
||||
Part.TEXT
|
||||
private static final String[] PART_PROJECTION = new String[]{
|
||||
Part._ID,
|
||||
Part.CHARSET,
|
||||
Part.CONTENT_DISPOSITION,
|
||||
Part.CONTENT_ID,
|
||||
Part.CONTENT_LOCATION,
|
||||
Part.CONTENT_TYPE,
|
||||
Part.FILENAME,
|
||||
Part.NAME,
|
||||
Part.TEXT
|
||||
};
|
||||
|
||||
private static final int PART_COLUMN_ID = 0;
|
||||
private static final int PART_COLUMN_CHARSET = 1;
|
||||
private static final int PART_COLUMN_ID = 0;
|
||||
private static final int PART_COLUMN_CHARSET = 1;
|
||||
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_LOCATION = 4;
|
||||
private static final int PART_COLUMN_CONTENT_TYPE = 5;
|
||||
private static final int PART_COLUMN_FILENAME = 6;
|
||||
private static final int PART_COLUMN_NAME = 7;
|
||||
private static final int PART_COLUMN_TEXT = 8;
|
||||
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_TYPE = 5;
|
||||
private static final int PART_COLUMN_FILENAME = 6;
|
||||
private static final int PART_COLUMN_NAME = 7;
|
||||
private static final int PART_COLUMN_TEXT = 8;
|
||||
|
||||
private static final HashMap<Uri, Integer> MESSAGE_BOX_MAP;
|
||||
// These map are used for convenience in persist() and load().
|
||||
@@ -197,9 +196,9 @@ public class PduPersister {
|
||||
|
||||
static {
|
||||
MESSAGE_BOX_MAP = new HashMap<Uri, Integer>();
|
||||
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.Draft.CONTENT_URI, Mms.MESSAGE_BOX_DRAFTS);
|
||||
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.Draft.CONTENT_URI, Mms.MESSAGE_BOX_DRAFTS);
|
||||
MESSAGE_BOX_MAP.put(Mms.Outbox.CONTENT_URI, Mms.MESSAGE_BOX_OUTBOX);
|
||||
|
||||
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);
|
||||
|
||||
PDU_CACHE_INSTANCE = PduCache.getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
private final Context mContext;
|
||||
private final ContentResolver mContentResolver;
|
||||
@@ -286,11 +285,13 @@ public class PduPersister {
|
||||
mContext = context;
|
||||
mContentResolver = context.getContentResolver();
|
||||
mDrmManagerClient = new DrmManagerClient(context);
|
||||
mTelephonyManager = (TelephonyManager)context
|
||||
mTelephonyManager = (TelephonyManager) context
|
||||
.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) {
|
||||
if ((sPersister == null)) {
|
||||
sPersister = new PduPersister(context);
|
||||
@@ -440,8 +441,8 @@ public class PduPersister {
|
||||
if (ContentType.TEXT_PLAIN.equals(type) || ContentType.APP_SMIL.equals(type)
|
||||
|| ContentType.TEXT_HTML.equals(type)) {
|
||||
String text = c.getString(PART_COLUMN_TEXT);
|
||||
byte [] blob = new EncodedStringValue(text != null ? text : "")
|
||||
.getTextString();
|
||||
byte[] blob = new EncodedStringValue(text != null ? text : "")
|
||||
.getTextString();
|
||||
baos.write(blob, 0, blob.length);
|
||||
} else {
|
||||
|
||||
@@ -484,7 +485,7 @@ public class PduPersister {
|
||||
private void loadAddress(long msgId, PduHeaders headers) {
|
||||
Cursor c = SqliteWrapper.query(mContext, mContentResolver,
|
||||
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);
|
||||
|
||||
if (c != null) {
|
||||
@@ -531,7 +532,7 @@ public class PduPersister {
|
||||
int msgBox = 0;
|
||||
long threadId = DUMMY_THREAD_ID;
|
||||
try {
|
||||
synchronized(PDU_CACHE_INSTANCE) {
|
||||
synchronized (PDU_CACHE_INSTANCE) {
|
||||
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, "load: " + uri + " blocked by isUpdating()");
|
||||
@@ -619,57 +620,57 @@ public class PduPersister {
|
||||
}
|
||||
|
||||
switch (msgType) {
|
||||
case PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND:
|
||||
pdu = new NotificationInd(headers);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_DELIVERY_IND:
|
||||
pdu = new DeliveryInd(headers);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_READ_ORIG_IND:
|
||||
pdu = new ReadOrigInd(headers);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF:
|
||||
pdu = new RetrieveConf(headers, body);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_SEND_REQ:
|
||||
pdu = new SendReq(headers, body);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_ACKNOWLEDGE_IND:
|
||||
pdu = new AcknowledgeInd(headers);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_NOTIFYRESP_IND:
|
||||
pdu = new NotifyRespInd(headers);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_READ_REC_IND:
|
||||
pdu = new ReadRecInd(headers);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_SEND_CONF:
|
||||
case PduHeaders.MESSAGE_TYPE_FORWARD_REQ:
|
||||
case PduHeaders.MESSAGE_TYPE_FORWARD_CONF:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_STORE_REQ:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_STORE_CONF:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_VIEW_REQ:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_VIEW_CONF:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_UPLOAD_REQ:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_UPLOAD_CONF:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_DELETE_REQ:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_DELETE_CONF:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_DESCR:
|
||||
case PduHeaders.MESSAGE_TYPE_DELETE_REQ:
|
||||
case PduHeaders.MESSAGE_TYPE_DELETE_CONF:
|
||||
case PduHeaders.MESSAGE_TYPE_CANCEL_REQ:
|
||||
case PduHeaders.MESSAGE_TYPE_CANCEL_CONF:
|
||||
throw new MmsException(
|
||||
"Unsupported PDU type: " + Integer.toHexString(msgType));
|
||||
case PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND:
|
||||
pdu = new NotificationInd(headers);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_DELIVERY_IND:
|
||||
pdu = new DeliveryInd(headers);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_READ_ORIG_IND:
|
||||
pdu = new ReadOrigInd(headers);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF:
|
||||
pdu = new RetrieveConf(headers, body);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_SEND_REQ:
|
||||
pdu = new SendReq(headers, body);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_ACKNOWLEDGE_IND:
|
||||
pdu = new AcknowledgeInd(headers);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_NOTIFYRESP_IND:
|
||||
pdu = new NotifyRespInd(headers);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_READ_REC_IND:
|
||||
pdu = new ReadRecInd(headers);
|
||||
break;
|
||||
case PduHeaders.MESSAGE_TYPE_SEND_CONF:
|
||||
case PduHeaders.MESSAGE_TYPE_FORWARD_REQ:
|
||||
case PduHeaders.MESSAGE_TYPE_FORWARD_CONF:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_STORE_REQ:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_STORE_CONF:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_VIEW_REQ:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_VIEW_CONF:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_UPLOAD_REQ:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_UPLOAD_CONF:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_DELETE_REQ:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_DELETE_CONF:
|
||||
case PduHeaders.MESSAGE_TYPE_MBOX_DESCR:
|
||||
case PduHeaders.MESSAGE_TYPE_DELETE_REQ:
|
||||
case PduHeaders.MESSAGE_TYPE_DELETE_CONF:
|
||||
case PduHeaders.MESSAGE_TYPE_CANCEL_REQ:
|
||||
case PduHeaders.MESSAGE_TYPE_CANCEL_CONF:
|
||||
throw new MmsException(
|
||||
"Unsupported PDU type: " + Integer.toHexString(msgType));
|
||||
|
||||
default:
|
||||
throw new MmsException(
|
||||
"Unrecognized PDU type: " + Integer.toHexString(msgType));
|
||||
default:
|
||||
throw new MmsException(
|
||||
"Unrecognized PDU type: " + Integer.toHexString(msgType));
|
||||
}
|
||||
} finally {
|
||||
synchronized(PDU_CACHE_INSTANCE) {
|
||||
synchronized (PDU_CACHE_INSTANCE) {
|
||||
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
|
||||
cacheEntry = new PduCacheEntry(pdu, msgBox, threadId);
|
||||
PDU_CACHE_INSTANCE.put(uri, cacheEntry);
|
||||
@@ -706,7 +707,7 @@ public class PduPersister {
|
||||
ContentValues values = new ContentValues(8);
|
||||
|
||||
int charset = part.getCharset();
|
||||
if (charset != 0 ) {
|
||||
if (charset != 0) {
|
||||
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
|
||||
* to user preference.
|
||||
*
|
||||
* @param part The PDU part which contains data to be saved.
|
||||
* @param uri The URI of the part.
|
||||
* @param contentType The MIME type of the part.
|
||||
* @param part The PDU part which contains data to be saved.
|
||||
* @param uri The URI of the part.
|
||||
* @param contentType The MIME type of the part.
|
||||
* @param preOpenedFiles if not null, a map of preopened InputStreams for the parts.
|
||||
* @throws MmsException Cannot find source data or error occurred
|
||||
* while saving the data.
|
||||
* while saving the data.
|
||||
*/
|
||||
private void persistData(PduPart part, Uri uri,
|
||||
String contentType, HashMap<Uri, InputStream> preOpenedFiles)
|
||||
String contentType, HashMap<Uri, InputStream> preOpenedFiles)
|
||||
throws MmsException {
|
||||
OutputStream os = null;
|
||||
InputStream is = null;
|
||||
@@ -949,18 +950,18 @@ public class PduPersister {
|
||||
File f = new File(path);
|
||||
ContentValues values = new ContentValues(0);
|
||||
SqliteWrapper.update(mContext, mContentResolver,
|
||||
Uri.parse("content://mms/resetFilePerm/" + f.getName()),
|
||||
values, null, null);
|
||||
Uri.parse("content://mms/resetFilePerm/" + f.getName()),
|
||||
values, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method expects uri in the following format
|
||||
* content://media/<table_name>/<row_index> (or)
|
||||
* file://sdcard/test.mp4
|
||||
* http://test.com/test.mp4
|
||||
*
|
||||
* content://media/<table_name>/<row_index> (or)
|
||||
* file://sdcard/test.mp4
|
||||
* http://test.com/test.mp4
|
||||
* <p>
|
||||
* Here <table_name> shall be "video" or "audio" or "images"
|
||||
* <row_index> the index of the content in given table
|
||||
*/
|
||||
@@ -976,7 +977,7 @@ public class PduPersister {
|
||||
path = uri.toString();
|
||||
|
||||
} else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
|
||||
String[] projection = new String[] {MediaStore.MediaColumns.DATA};
|
||||
String[] projection = new String[]{MediaStore.MediaColumns.DATA};
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = context.getContentResolver().query(uri, projection, null,
|
||||
@@ -1015,12 +1016,12 @@ public class PduPersister {
|
||||
/**
|
||||
* 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.
|
||||
* @throws MmsException Bad URI or updating failed.
|
||||
*/
|
||||
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
|
||||
// purging it.
|
||||
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
||||
@@ -1129,7 +1130,7 @@ public class PduPersister {
|
||||
ContentValues values = new ContentValues(7);
|
||||
|
||||
int charset = part.getCharset();
|
||||
if (charset != 0 ) {
|
||||
if (charset != 0) {
|
||||
values.put(Part.CHARSET, charset);
|
||||
}
|
||||
|
||||
@@ -1181,8 +1182,8 @@ public class PduPersister {
|
||||
/**
|
||||
* Update all parts of a PDU.
|
||||
*
|
||||
* @param uri The PDU which need to be updated.
|
||||
* @param body New message body of the PDU.
|
||||
* @param uri The PDU which need to be updated.
|
||||
* @param body New message body of the PDU.
|
||||
* @param preOpenedFiles if not null, a map of preopened InputStreams for the parts.
|
||||
* @throws MmsException Bad URI or updating failed.
|
||||
*/
|
||||
@@ -1190,7 +1191,7 @@ public class PduPersister {
|
||||
throws MmsException {
|
||||
try {
|
||||
PduCacheEntry cacheEntry;
|
||||
synchronized(PDU_CACHE_INSTANCE) {
|
||||
synchronized (PDU_CACHE_INSTANCE) {
|
||||
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, "updateParts: " + uri + " blocked by isUpdating()");
|
||||
@@ -1253,7 +1254,7 @@ public class PduPersister {
|
||||
updatePart(e.getKey(), e.getValue(), preOpenedFiles);
|
||||
}
|
||||
} finally {
|
||||
synchronized(PDU_CACHE_INSTANCE) {
|
||||
synchronized (PDU_CACHE_INSTANCE) {
|
||||
PDU_CACHE_INSTANCE.setUpdating(uri, false);
|
||||
PDU_CACHE_INSTANCE.notifyAll();
|
||||
}
|
||||
@@ -1263,38 +1264,40 @@ public class PduPersister {
|
||||
/**
|
||||
* Persist a PDU object to specific location in the storage.
|
||||
*
|
||||
* @param pdu The PDU object to be stored.
|
||||
* @param uri Where to store the given PDU object.
|
||||
* @param createThreadId if true, this function may create a thread id for the recipients
|
||||
* @param pdu The PDU object to be stored.
|
||||
* @param uri Where to store the given PDU object.
|
||||
* @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
|
||||
* to create the associated thread. When false, only the sender will be used in finding or
|
||||
* creating the appropriate thread or conversation.
|
||||
* @param preOpenedFiles if not null, a map of preopened InputStreams for the parts.
|
||||
* to create the associated thread. When false, only the sender will be used in finding or
|
||||
* creating the appropriate thread or conversation.
|
||||
* @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.
|
||||
*/
|
||||
|
||||
public Uri persist(GenericPdu pdu, Uri uri, boolean createThreadId, boolean groupMmsEnabled,
|
||||
HashMap<Uri, InputStream> preOpenedFiles)
|
||||
throws MmsException {
|
||||
HashMap<Uri, InputStream> preOpenedFiles) throws MmsException {
|
||||
|
||||
if (uri == null) {
|
||||
throw new MmsException("Uri may not be null.");
|
||||
}
|
||||
|
||||
long msgId = -1;
|
||||
try {
|
||||
msgId = ContentUris.parseId(uri);
|
||||
} catch (NumberFormatException e) {
|
||||
// the uri ends with "inbox" or something else like that
|
||||
}
|
||||
|
||||
boolean existingUri = msgId != -1;
|
||||
|
||||
if (!existingUri && MESSAGE_BOX_MAP.get(uri) == null) {
|
||||
throw new MmsException(
|
||||
"Bad destination, must be one of "
|
||||
+ "content://mms/inbox, content://mms/sent, "
|
||||
+ "content://mms/drafts, content://mms/outbox, "
|
||||
+ "content://mms/temp.");
|
||||
+ "content://mms/inbox, content://mms/sent, "
|
||||
+ "content://mms/drafts, content://mms/outbox, "
|
||||
+ "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
|
||||
// purging it.
|
||||
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
||||
@@ -1327,7 +1330,7 @@ public class PduPersister {
|
||||
}
|
||||
|
||||
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());
|
||||
if (text != null) {
|
||||
values.put(e.getValue(), toIsoString(text));
|
||||
@@ -1335,7 +1338,7 @@ public class PduPersister {
|
||||
}
|
||||
|
||||
set = OCTET_COLUMN_NAME_MAP.entrySet();
|
||||
for (Entry<Integer, String> e : set){
|
||||
for (Entry<Integer, String> e : set) {
|
||||
int b = header.getOctet(e.getKey());
|
||||
if (b != 0) {
|
||||
values.put(e.getValue(), b);
|
||||
@@ -1343,7 +1346,7 @@ public class PduPersister {
|
||||
}
|
||||
|
||||
set = LONG_COLUMN_NAME_MAP.entrySet();
|
||||
for (Entry<Integer, String> e : set){
|
||||
for (Entry<Integer, String> e : set) {
|
||||
long l = header.getLongInteger(e.getKey());
|
||||
if (l != -1L) {
|
||||
values.put(e.getValue(), l);
|
||||
@@ -1473,8 +1476,8 @@ public class PduPersister {
|
||||
values = new ContentValues(1);
|
||||
values.put(Part.MSG_ID, msgId);
|
||||
SqliteWrapper.update(mContext, mContentResolver,
|
||||
Uri.parse("content://mms/" + dummyId + "/part"),
|
||||
values, null, null);
|
||||
Uri.parse("content://mms/" + dummyId + "/part"),
|
||||
values, null, null);
|
||||
// We should return the longest URI of the persisted PDU, for
|
||||
// example, if input URI is "content://mms/inbox" and the _ID of
|
||||
// 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.
|
||||
*
|
||||
* @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 addressMap a HashMap of the addresses from the ADDRESS_FIELDS header
|
||||
* @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 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
|
||||
*/
|
||||
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);
|
||||
if (array == null) {
|
||||
return;
|
||||
@@ -1533,10 +1536,10 @@ public class PduPersister {
|
||||
* Move a PDU object from one location to another.
|
||||
*
|
||||
* @param from Specify the PDU object to be moved.
|
||||
* @param to The destination location, should be one of the following:
|
||||
* "content://mms/inbox", "content://mms/sent",
|
||||
* "content://mms/drafts", "content://mms/outbox",
|
||||
* "content://mms/trash".
|
||||
* @param to The destination location, should be one of the following:
|
||||
* "content://mms/inbox", "content://mms/sent",
|
||||
* "content://mms/drafts", "content://mms/outbox",
|
||||
* "content://mms/trash".
|
||||
* @return New Uri of the moved PDU.
|
||||
* @throws MmsException Error occurred while moving the message.
|
||||
*/
|
||||
@@ -1552,9 +1555,9 @@ public class PduPersister {
|
||||
if (msgBox == null) {
|
||||
throw new MmsException(
|
||||
"Bad destination, must be one of "
|
||||
+ "content://mms/inbox, content://mms/sent, "
|
||||
+ "content://mms/drafts, content://mms/outbox, "
|
||||
+ "content://mms/temp.");
|
||||
+ "content://mms/inbox, content://mms/sent, "
|
||||
+ "content://mms/drafts, content://mms/outbox, "
|
||||
+ "content://mms/temp.");
|
||||
}
|
||||
|
||||
ContentValues values = new ContentValues(1);
|
||||
@@ -1602,8 +1605,8 @@ public class PduPersister {
|
||||
*/
|
||||
public Cursor getPendingMessages(long dueTime) {
|
||||
if (!checkReadSmsPermissions()) {
|
||||
Log.w(TAG, "No read sms permissions have been granted");
|
||||
return null;
|
||||
Log.w(TAG, "No read sms permissions have been granted");
|
||||
return null;
|
||||
}
|
||||
Uri.Builder uriBuilder = PendingMessages.CONTENT_URI.buildUpon();
|
||||
uriBuilder.appendQueryParameter("protocol", "mms");
|
||||
@@ -1611,7 +1614,7 @@ public class PduPersister {
|
||||
String selection = PendingMessages.ERROR_TYPE + " < ?"
|
||||
+ " AND " + PendingMessages.DUE_TIME + " <= ?";
|
||||
|
||||
String[] selectionArgs = new String[] {
|
||||
String[] selectionArgs = new String[]{
|
||||
String.valueOf(MmsSms.ERR_TYPE_GENERIC_PERMANENT),
|
||||
String.valueOf(dueTime)
|
||||
};
|
||||
@@ -1620,7 +1623,7 @@ public class PduPersister {
|
||||
uriBuilder.build(), null, selection, selectionArgs,
|
||||
PendingMessages.DUE_TIME);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if read permissions for SMS have been granted
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user