Messaging: Remove unused code
Change-Id: I8093bb3e305ae323f7069bf42f9e83f8c8647cc7
This commit is contained in:
@@ -23,7 +23,6 @@ import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.DatabaseUtils;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.net.Uri;
|
||||
import android.provider.MediaStore;
|
||||
@@ -77,21 +76,6 @@ public class PduPersister {
|
||||
public static final String TEMPORARY_DRM_OBJECT_URI =
|
||||
"content://mms/" + Long.MAX_VALUE + "/part";
|
||||
|
||||
/**
|
||||
* Indicate that we transiently failed to process a MM.
|
||||
*/
|
||||
public static final int PROC_STATUS_TRANSIENT_FAILURE = 1;
|
||||
|
||||
/**
|
||||
* Indicate that we permanently failed to process a MM.
|
||||
*/
|
||||
public static final int PROC_STATUS_PERMANENTLY_FAILURE = 2;
|
||||
|
||||
/**
|
||||
* Indicate that we have successfully processed a MM.
|
||||
*/
|
||||
public static final int PROC_STATUS_COMPLETED = 3;
|
||||
|
||||
public static final String BEGIN_VCARD = "BEGIN:VCARD";
|
||||
|
||||
private static PduPersister sPersister;
|
||||
@@ -1046,244 +1030,6 @@ public class PduPersister {
|
||||
return path;
|
||||
}
|
||||
|
||||
private void updateAddress(
|
||||
final long msgId, final int type, final EncodedStringValue[] array) {
|
||||
// Delete old address information and then insert new ones.
|
||||
SqliteWrapper.delete(mContext, mContentResolver,
|
||||
Uri.parse("content://mms/" + msgId + "/addr"),
|
||||
Addr.TYPE + "=" + type, null);
|
||||
|
||||
persistAddress(msgId, type, array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update headers of a SendReq.
|
||||
*
|
||||
* @param uri The PDU which need to be updated.
|
||||
* @param pdu New headers.
|
||||
* @throws MmsException Bad URI or updating failed.
|
||||
*/
|
||||
public void updateHeaders(final Uri uri, final SendReq sendReq) {
|
||||
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)) {
|
||||
if (LOCAL_LOGV) {
|
||||
LogUtil.v(TAG, "updateHeaders: " + uri + " blocked by isUpdating()");
|
||||
}
|
||||
try {
|
||||
PDU_CACHE_INSTANCE.wait();
|
||||
} catch (final InterruptedException e) {
|
||||
Log.e(TAG, "updateHeaders: ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
PDU_CACHE_INSTANCE.purge(uri);
|
||||
|
||||
final ContentValues values = new ContentValues(10);
|
||||
final byte[] contentType = sendReq.getContentType();
|
||||
if (contentType != null) {
|
||||
values.put(Mms.CONTENT_TYPE, toIsoString(contentType));
|
||||
}
|
||||
|
||||
final long date = sendReq.getDate();
|
||||
if (date != -1) {
|
||||
values.put(Mms.DATE, date);
|
||||
}
|
||||
|
||||
final int deliveryReport = sendReq.getDeliveryReport();
|
||||
if (deliveryReport != 0) {
|
||||
values.put(Mms.DELIVERY_REPORT, deliveryReport);
|
||||
}
|
||||
|
||||
final long expiry = sendReq.getExpiry();
|
||||
if (expiry != -1) {
|
||||
values.put(Mms.EXPIRY, expiry);
|
||||
}
|
||||
|
||||
final byte[] msgClass = sendReq.getMessageClass();
|
||||
if (msgClass != null) {
|
||||
values.put(Mms.MESSAGE_CLASS, toIsoString(msgClass));
|
||||
}
|
||||
|
||||
final int priority = sendReq.getPriority();
|
||||
if (priority != 0) {
|
||||
values.put(Mms.PRIORITY, priority);
|
||||
}
|
||||
|
||||
final int readReport = sendReq.getReadReport();
|
||||
if (readReport != 0) {
|
||||
values.put(Mms.READ_REPORT, readReport);
|
||||
}
|
||||
|
||||
final byte[] transId = sendReq.getTransactionId();
|
||||
if (transId != null) {
|
||||
values.put(Mms.TRANSACTION_ID, toIsoString(transId));
|
||||
}
|
||||
|
||||
final EncodedStringValue subject = sendReq.getSubject();
|
||||
if (subject != null) {
|
||||
values.put(Mms.SUBJECT, toIsoString(subject.getTextString()));
|
||||
values.put(Mms.SUBJECT_CHARSET, subject.getCharacterSet());
|
||||
} else {
|
||||
values.put(Mms.SUBJECT, "");
|
||||
}
|
||||
|
||||
final long messageSize = sendReq.getMessageSize();
|
||||
if (messageSize > 0) {
|
||||
values.put(Mms.MESSAGE_SIZE, messageSize);
|
||||
}
|
||||
|
||||
final PduHeaders headers = sendReq.getPduHeaders();
|
||||
final HashSet<String> recipients = new HashSet<>();
|
||||
for (final int addrType : ADDRESS_FIELDS) {
|
||||
EncodedStringValue[] array = null;
|
||||
if (addrType == PduHeaders.FROM) {
|
||||
final EncodedStringValue v = headers.getEncodedStringValue(addrType);
|
||||
if (v != null) {
|
||||
array = new EncodedStringValue[1];
|
||||
array[0] = v;
|
||||
}
|
||||
} else {
|
||||
array = headers.getEncodedStringValues(addrType);
|
||||
}
|
||||
|
||||
if (array != null) {
|
||||
final long msgId = ContentUris.parseId(uri);
|
||||
updateAddress(msgId, addrType, array);
|
||||
if (addrType == PduHeaders.TO) {
|
||||
for (final EncodedStringValue v : array) {
|
||||
if (v != null) {
|
||||
recipients.add(v.getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!recipients.isEmpty()) {
|
||||
final long threadId = MmsSmsUtils.Threads.getOrCreateThreadId(mContext, recipients);
|
||||
values.put(Mms.THREAD_ID, threadId);
|
||||
}
|
||||
|
||||
SqliteWrapper.update(mContext, mContentResolver, uri, values, null, null);
|
||||
}
|
||||
|
||||
|
||||
private void updatePart(final Uri uri, final PduPart part,
|
||||
final Map<Uri, InputStream> preOpenedFiles)
|
||||
throws MmsException {
|
||||
final ContentValues values = new ContentValues(7);
|
||||
|
||||
final int charset = part.getCharset();
|
||||
if (charset != 0) {
|
||||
values.put(Part.CHARSET, charset);
|
||||
}
|
||||
|
||||
String contentType = null;
|
||||
if (part.getContentType() != null) {
|
||||
contentType = toIsoString(part.getContentType());
|
||||
values.put(Part.CONTENT_TYPE, contentType);
|
||||
} else {
|
||||
throw new MmsException("MIME type of the part must be set.");
|
||||
}
|
||||
|
||||
getValues(part, values);
|
||||
|
||||
SqliteWrapper.update(mContext, mContentResolver, uri, values, null, null);
|
||||
|
||||
// Only update the data when:
|
||||
// 1. New binary data supplied or
|
||||
// 2. The Uri of the part is different from the current one.
|
||||
if ((part.getData() != null)
|
||||
|| (!uri.equals(part.getDataUri()))) {
|
||||
persistData(part, uri, contentType, preOpenedFiles);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all parts of a 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.
|
||||
*/
|
||||
public void updateParts(final Uri uri, final PduBody body,
|
||||
final Map<Uri, InputStream> preOpenedFiles)
|
||||
throws MmsException {
|
||||
try {
|
||||
PduCacheEntry cacheEntry;
|
||||
synchronized (PDU_CACHE_INSTANCE) {
|
||||
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
||||
if (LOCAL_LOGV) {
|
||||
LogUtil.v(TAG, "updateParts: " + uri + " blocked by isUpdating()");
|
||||
}
|
||||
try {
|
||||
PDU_CACHE_INSTANCE.wait();
|
||||
} catch (final InterruptedException e) {
|
||||
Log.e(TAG, "updateParts: ", e);
|
||||
}
|
||||
cacheEntry = PDU_CACHE_INSTANCE.get(uri);
|
||||
if (cacheEntry != null) {
|
||||
((MultimediaMessagePdu) cacheEntry.getPdu()).setBody(body);
|
||||
}
|
||||
}
|
||||
// Tell the cache to indicate to other callers that this item
|
||||
// is currently being updated.
|
||||
PDU_CACHE_INSTANCE.setUpdating(uri, true);
|
||||
}
|
||||
|
||||
final ArrayList<PduPart> toBeCreated = new ArrayList<>();
|
||||
final ArrayMap<Uri, PduPart> toBeUpdated = new ArrayMap<>();
|
||||
|
||||
final int partsNum = body.getPartsNum();
|
||||
final StringBuilder filter = new StringBuilder().append('(');
|
||||
for (int i = 0; i < partsNum; i++) {
|
||||
final PduPart part = body.getPart(i);
|
||||
final Uri partUri = part.getDataUri();
|
||||
if ((partUri == null) || TextUtils.isEmpty(partUri.getAuthority())
|
||||
|| !partUri.getAuthority().startsWith("mms")) {
|
||||
toBeCreated.add(part);
|
||||
} else {
|
||||
toBeUpdated.put(partUri, part);
|
||||
|
||||
// Don't use 'i > 0' to determine whether we should append
|
||||
// 'AND' since 'i = 0' may be skipped in another branch.
|
||||
if (filter.length() > 1) {
|
||||
filter.append(" AND ");
|
||||
}
|
||||
|
||||
filter.append(Part._ID);
|
||||
filter.append("!=");
|
||||
DatabaseUtils.appendEscapedSQLString(filter, partUri.getLastPathSegment());
|
||||
}
|
||||
}
|
||||
filter.append(')');
|
||||
|
||||
final long msgId = ContentUris.parseId(uri);
|
||||
|
||||
// Remove the parts which doesn't exist anymore.
|
||||
SqliteWrapper.delete(mContext, mContentResolver,
|
||||
Uri.parse(Mms.CONTENT_URI + "/" + msgId + "/part"),
|
||||
filter.length() > 2 ? filter.toString() : null, null);
|
||||
|
||||
// Create new parts which didn't exist before.
|
||||
for (final PduPart part : toBeCreated) {
|
||||
persistPart(part, msgId, preOpenedFiles);
|
||||
}
|
||||
|
||||
// Update the modified parts.
|
||||
for (final Map.Entry<Uri, PduPart> e : toBeUpdated.entrySet()) {
|
||||
updatePart(e.getKey(), e.getValue(), preOpenedFiles);
|
||||
}
|
||||
} finally {
|
||||
synchronized (PDU_CACHE_INSTANCE) {
|
||||
PDU_CACHE_INSTANCE.setUpdating(uri, false);
|
||||
PDU_CACHE_INSTANCE.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist a PDU object to specific location in the storage.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user