add delay send mms. add group send to individual recipients - sms and mms. add immediate show messages in convo, not wait for sent. new qktransaction that replaces android/smsmms transaction with mods for quik. lots of code cleanups and removing superfluous code. some bug fixes.

This commit is contained in:
gavine99
2025-04-10 16:59:35 +10:00
parent 6f70c8e932
commit 2810b56cd0
375 changed files with 20297 additions and 3161 deletions
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.collect;
import java.util.*;
/**
* Provides static methods for creating mutable {@code Set} instances easily and
* other static methods for working with Sets.
*/
public class Sets {
/**
* Creates an empty {@code HashSet} instance.
* <p/>
* <p><b>Note:</b> if {@code E} is an {@link Enum} type, use {@link
* EnumSet#noneOf} instead.
* <p/>
* <p><b>Note:</b> if you only need an <i>immutable</i> empty Set,
* use {@link Collections#emptySet} instead.
*
* @return a newly-created, initially-empty {@code HashSet}
*/
public static <K> HashSet<K> newHashSet() {
return new HashSet<K>();
}
/**
* Creates a {@code HashSet} instance containing the given elements.
* <p/>
* <p><b>Note:</b> due to a bug in javac 1.5.0_06, we cannot support the
* following:
* <p/>
* <p>{@code Set<Base> set = Sets.newHashSet(sub1, sub2);}
* <p/>
* <p>where {@code sub1} and {@code sub2} are references to subtypes of {@code
* Base}, not of {@code Base} itself. To get around this, you must use:
* <p/>
* <p>{@code Set<Base> set = Sets.<Base>newHashSet(sub1, sub2);}
*
* @param elements the elements that the set should contain
* @return a newly-created {@code HashSet} containing those elements (minus
* duplicates)
*/
public static <E> HashSet<E> newHashSet(E... elements) {
int capacity = elements.length * 4 / 3 + 1;
HashSet<E> set = new HashSet<E>(capacity);
Collections.addAll(set, elements);
return set;
}
/**
* Creates an empty {@code SortedSet} instance.
*
* @return a newly-created, initially-empty {@code SortedSet}.
*/
public static <E> SortedSet<E> newSortedSet() {
return new TreeSet<E>();
}
/**
* Creates a {@code SortedSet} instance containing the given elements.
*
* @param elements the elements that the set should contain
* @return a newly-created {@code SortedSet} containing those elements (minus
* duplicates)
*/
public static <E> SortedSet<E> newSortedSet(E... elements) {
SortedSet<E> set = new TreeSet<E>();
Collections.addAll(set, elements);
return set;
}
}
@@ -0,0 +1,17 @@
package com.google.android.mms;
public class APN {
public String MMSCenterUrl = "";
public String MMSPort = "";
public String MMSProxy = "";
public APN(String MMSCenterUrl, String MMSPort, String MMSProxy) {
this.MMSCenterUrl = MMSCenterUrl;
this.MMSPort = MMSPort;
this.MMSProxy = MMSProxy;
}
public APN() {
}
}
@@ -0,0 +1,54 @@
package com.google.android.mms;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.text.TextUtils;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class APNHelper {
public APNHelper(final Context context) {
this.context = context;
}
@SuppressWarnings("unchecked")
public List<APN> getMMSApns() {
try {
final Cursor apnCursor = this.context.getContentResolver().query(Uri.withAppendedPath(Uri.parse("content://telephony/carriers"), "current"), null, null, null, null);
if (apnCursor == null) {
return Collections.EMPTY_LIST;
} else {
final List<APN> results = new ArrayList<APN>();
if (apnCursor.moveToFirst()) {
do {
final String type = apnCursor.getString(apnCursor.getColumnIndex("type"));
if (!TextUtils.isEmpty(type) && (type.equalsIgnoreCase("*") || type.equalsIgnoreCase("mms"))) {
final String mmsc = apnCursor.getString(apnCursor.getColumnIndex("mmsc"));
final String mmsProxy = apnCursor.getString(apnCursor.getColumnIndex("mmsproxy"));
final String port = apnCursor.getString(apnCursor.getColumnIndex("mmsport"));
final APN apn = new APN();
apn.MMSCenterUrl = mmsc;
apn.MMSProxy = mmsProxy;
apn.MMSPort = port;
results.add(apn);
Toast.makeText(context, mmsc + " " + mmsProxy + " " + port, Toast.LENGTH_LONG).show();
}
} while (apnCursor.moveToNext());
}
apnCursor.close();
return results;
}
} catch (Exception e) {
// insignificant permissions
return Collections.EMPTY_LIST;
}
}
private Context context;
}
View File
@@ -0,0 +1,10 @@
package com.google.android.mms;
import android.net.Uri;
public class MMSPart {
public String Name = "";
public String MimeType = "";
public byte[] Data;
public Uri Path;
}
@@ -1,7 +0,0 @@
package com.google.android.mms
class MMSPart @JvmOverloads constructor(
var name: String = "",
var mimeType: String = "",
var data: ByteArray? = null
)
View File
@@ -27,6 +27,8 @@ import java.util.ArrayList;
* Encoded-string-value = Text-string | Value-length Char-set Text-string
*/
public class EncodedStringValue implements Cloneable {
private static final String TAG = "EncodedStringValue";
private static final boolean DEBUG = false;
private static final boolean LOCAL_LOGV = false;
/**
@@ -72,7 +74,7 @@ public class EncodedStringValue implements Cloneable {
mData = data.getBytes(CharacterSets.DEFAULT_CHARSET_NAME);
mCharacterSet = CharacterSets.DEFAULT_CHARSET;
} catch (UnsupportedEncodingException e) {
Timber.e(e, "Default encoding must be supported.");
Timber.e("Default encoding must be supported.", e);
}
}
@@ -138,7 +140,7 @@ public class EncodedStringValue implements Cloneable {
return new String(mData, name);
} catch (UnsupportedEncodingException e) {
if (LOCAL_LOGV) {
Timber.v(e, e.getMessage());
Timber.v(e.getMessage(), e);
}
try {
return new String(mData, CharacterSets.MIMENAME_ISO_8859_1);
@@ -170,7 +172,7 @@ public class EncodedStringValue implements Cloneable {
newTextString.write(mData);
newTextString.write(textString);
} catch (IOException e) {
Timber.e(e, "logging error");
Timber.e("logging error", e);
e.printStackTrace();
throw new NullPointerException(
"appendTextString: failed when write a new Text-string");
@@ -194,7 +196,7 @@ public class EncodedStringValue implements Cloneable {
try {
return new EncodedStringValue(mCharacterSet, dstBytes);
} catch (Exception e) {
Timber.e(e, "logging error");
Timber.e("logging error", e);
e.printStackTrace();
throw new CloneNotSupportedException(e.getMessage());
}
+10 -10
View File
@@ -21,23 +21,23 @@ import java.util.Map;
import java.util.Vector;
public class PduBody {
private Vector<PduPart> mParts;
private Vector<PduPart> mParts = null;
private Map<String, PduPart> mPartMapByContentId;
private Map<String, PduPart> mPartMapByContentLocation;
private Map<String, PduPart> mPartMapByName;
private Map<String, PduPart> mPartMapByFileName;
private Map<String, PduPart> mPartMapByContentId = null;
private Map<String, PduPart> mPartMapByContentLocation = null;
private Map<String, PduPart> mPartMapByName = null;
private Map<String, PduPart> mPartMapByFileName = null;
/**
* Constructor.
*/
public PduBody() {
mParts = new Vector<>();
mParts = new Vector<PduPart>();
mPartMapByContentId = new HashMap<>();
mPartMapByContentLocation = new HashMap<>();
mPartMapByName = new HashMap<>();
mPartMapByFileName = new HashMap<>();
mPartMapByContentId = new HashMap<String, PduPart>();
mPartMapByContentLocation = new HashMap<String, PduPart>();
mPartMapByName = new HashMap<String, PduPart>();
mPartMapByFileName = new HashMap<String, PduPart>();
}
private void putPartToMaps(PduPart part) {
+2 -1
View File
@@ -80,6 +80,7 @@ public class PduComposer {
* Block size when read data from InputStream.
*/
static private final int PDU_COMPOSER_BLOCK_SIZE = 1024;
private static final String TAG = "PduComposer";
/**
* The output message.
@@ -885,7 +886,7 @@ public class PduComposer {
appendTextString(part.getContentType());
}
catch (ArrayIndexOutOfBoundsException e){
Timber.e(e, "logging error");
Timber.e("logging error", e);
e.printStackTrace();
}
+48 -42
View File
@@ -16,9 +16,11 @@
package com.google.android.mms.pdu_alt;
import com.android.mms.util.ExternalLogger;
import com.google.android.mms.ContentType;
import com.google.android.mms.InvalidHeaderValueException;
import timber.log.Timber;
import android.util.Log;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -79,6 +81,8 @@ public class PduParser {
/**
* The log tag.
*/
private static final String LOG_TAG = "PduParser";
private static final boolean DEBUG = false;
private static final boolean LOCAL_LOGV = false;
/**
@@ -146,33 +150,33 @@ public class PduParser {
switch (messageType) {
case PduHeaders.MESSAGE_TYPE_SEND_REQ:
if (LOCAL_LOGV) {
Timber.v("parse: MESSAGE_TYPE_SEND_REQ");
Log.v(LOG_TAG, "parse: MESSAGE_TYPE_SEND_REQ");
}
SendReq sendReq = new SendReq(mHeaders, mBody);
return sendReq;
case PduHeaders.MESSAGE_TYPE_SEND_CONF:
if (LOCAL_LOGV) {
Timber.v("parse: MESSAGE_TYPE_SEND_CONF");
Log.v(LOG_TAG, "parse: MESSAGE_TYPE_SEND_CONF");
}
SendConf sendConf = new SendConf(mHeaders);
return sendConf;
case PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND:
if (LOCAL_LOGV) {
Timber.v("parse: MESSAGE_TYPE_NOTIFICATION_IND");
Log.v(LOG_TAG, "parse: MESSAGE_TYPE_NOTIFICATION_IND");
}
NotificationInd notificationInd =
new NotificationInd(mHeaders);
return notificationInd;
case PduHeaders.MESSAGE_TYPE_NOTIFYRESP_IND:
if (LOCAL_LOGV) {
Timber.v("parse: MESSAGE_TYPE_NOTIFYRESP_IND");
Log.v(LOG_TAG, "parse: MESSAGE_TYPE_NOTIFYRESP_IND");
}
NotifyRespInd notifyRespInd =
new NotifyRespInd(mHeaders);
return notifyRespInd;
case PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF:
if (LOCAL_LOGV) {
Timber.v("parse: MESSAGE_TYPE_RETRIEVE_CONF");
Log.v(LOG_TAG, "parse: MESSAGE_TYPE_RETRIEVE_CONF");
}
RetrieveConf retrieveConf =
new RetrieveConf(mHeaders, mBody);
@@ -200,33 +204,33 @@ public class PduParser {
// multipart/signed
return retrieveConf;
} else {
Timber.v("Unsupported ContentType: " + ctTypeStr);
ExternalLogger.logMessage(LOG_TAG, "Unsupported ContentType: " + ctTypeStr);
}
return null;
case PduHeaders.MESSAGE_TYPE_DELIVERY_IND:
if (LOCAL_LOGV) {
Timber.v("parse: MESSAGE_TYPE_DELIVERY_IND");
Log.v(LOG_TAG, "parse: MESSAGE_TYPE_DELIVERY_IND");
}
DeliveryInd deliveryInd =
new DeliveryInd(mHeaders);
return deliveryInd;
case PduHeaders.MESSAGE_TYPE_ACKNOWLEDGE_IND:
if (LOCAL_LOGV) {
Timber.v("parse: MESSAGE_TYPE_ACKNOWLEDGE_IND");
Log.v(LOG_TAG, "parse: MESSAGE_TYPE_ACKNOWLEDGE_IND");
}
AcknowledgeInd acknowledgeInd =
new AcknowledgeInd(mHeaders);
return acknowledgeInd;
case PduHeaders.MESSAGE_TYPE_READ_ORIG_IND:
if (LOCAL_LOGV) {
Timber.v("parse: MESSAGE_TYPE_READ_ORIG_IND");
Log.v(LOG_TAG, "parse: MESSAGE_TYPE_READ_ORIG_IND");
}
ReadOrigInd readOrigInd =
new ReadOrigInd(mHeaders);
return readOrigInd;
case PduHeaders.MESSAGE_TYPE_READ_REC_IND:
if (LOCAL_LOGV) {
Timber.v("parse: MESSAGE_TYPE_READ_REC_IND");
Log.v(LOG_TAG, "parse: MESSAGE_TYPE_READ_REC_IND");
}
ReadRecInd readRecInd =
new ReadRecInd(mHeaders);
@@ -258,7 +262,7 @@ public class PduParser {
pduDataStream.reset();
byte [] bVal = parseWapString(pduDataStream, TYPE_TEXT_STRING);
if (LOCAL_LOGV) {
Timber.v("TextHeader: " + new String(bVal));
Log.v(LOG_TAG, "TextHeader: " + new String(bVal));
}
/* we should ignore it at the moment */
continue;
@@ -268,7 +272,7 @@ public class PduParser {
{
int messageType = extractByteValue(pduDataStream);
if (LOCAL_LOGV) {
Timber.v("parseHeaders: messageType: " + messageType);
Log.v(LOG_TAG, "parseHeaders: messageType: " + messageType);
}
switch (messageType) {
// We don't support these kind of messages now.
@@ -332,7 +336,8 @@ public class PduParser {
{
int value = extractByteValue(pduDataStream);
if (LOCAL_LOGV) {
Timber.v("parseHeaders: byte: " + headerField + " value: " + value);
Log.v(LOG_TAG, "parseHeaders: byte: " + headerField + " value: " +
value);
}
try {
@@ -356,7 +361,7 @@ public class PduParser {
try {
long value = parseLongInteger(pduDataStream);
if (LOCAL_LOGV) {
Timber.v("parseHeaders: longint: " + headerField + " value: " +
Log.v(LOG_TAG, "parseHeaders: longint: " + headerField + " value: " +
value);
}
headers.setLongInteger(value, headerField);
@@ -375,7 +380,7 @@ public class PduParser {
try {
long value = parseIntegerValue(pduDataStream);
if (LOCAL_LOGV) {
Timber.v("parseHeaders: int: " + headerField + " value: " +
Log.v(LOG_TAG, "parseHeaders: int: " + headerField + " value: " +
value);
}
headers.setLongInteger(value, headerField);
@@ -411,7 +416,7 @@ public class PduParser {
if (null != value) {
try {
if (LOCAL_LOGV) {
Timber.v("parseHeaders: string: " + headerField + " value: " +
Log.v(LOG_TAG, "parseHeaders: string: " + headerField + " value: " +
new String(value));
}
headers.setTextString(value, headerField);
@@ -440,7 +445,7 @@ public class PduParser {
if (null != value) {
try {
if (LOCAL_LOGV) {
Timber.v("parseHeaders: encoded string: " + headerField
Log.v(LOG_TAG, "parseHeaders: encoded string: " + headerField
+ " value: " + value.getString());
}
headers.setEncodedStringValue(value, headerField);
@@ -466,7 +471,7 @@ public class PduParser {
if (null != address) {
String str = new String(address);
if (LOCAL_LOGV) {
Timber.v("parseHeaders: (to/cc/bcc) address: " + headerField
Log.v(LOG_TAG, "parseHeaders: (to/cc/bcc) address: " + headerField
+ " value: " + str);
}
int endIndex = str.indexOf("/");
@@ -521,7 +526,7 @@ public class PduParser {
try {
if (LOCAL_LOGV) {
Timber.v("parseHeaders: time value: " + headerField
Log.v(LOG_TAG, "parseHeaders: time value: " + headerField
+ " value: " + timeValue);
}
headers.setLongInteger(timeValue, headerField);
@@ -575,7 +580,7 @@ public class PduParser {
try {
if (LOCAL_LOGV) {
Timber.v("parseHeaders: from address: " + headerField
Log.v(LOG_TAG, "parseHeaders: from address: " + headerField
+ " value: " + from.getString());
}
headers.setEncodedStringValue(from, PduHeaders.FROM);
@@ -593,7 +598,7 @@ public class PduParser {
pduDataStream.mark(1);
int messageClass = extractByteValue(pduDataStream);
if (LOCAL_LOGV) {
Timber.v("parseHeaders: MESSAGE_CLASS: " + headerField
Log.v(LOG_TAG, "parseHeaders: MESSAGE_CLASS: " + headerField
+ " value: " + messageClass);
}
@@ -646,7 +651,7 @@ public class PduParser {
try {
if (LOCAL_LOGV) {
Timber.v("parseHeaders: MMS_VERSION: " + headerField
Log.v(LOG_TAG, "parseHeaders: MMS_VERSION: " + headerField
+ " value: " + version);
}
headers.setOctet(version, PduHeaders.MMS_VERSION);
@@ -681,7 +686,7 @@ public class PduParser {
if (null != previouslySentBy) {
try {
if (LOCAL_LOGV) {
Timber.v("parseHeaders: PREVIOUSLY_SENT_BY: " + headerField
Log.v(LOG_TAG, "parseHeaders: PREVIOUSLY_SENT_BY: " + headerField
+ " value: " + previouslySentBy.getString());
}
headers.setEncodedStringValue(previouslySentBy,
@@ -714,7 +719,7 @@ public class PduParser {
try {
long perviouslySentDate = parseLongInteger(pduDataStream);
if (LOCAL_LOGV) {
Timber.v("parseHeaders: PREVIOUSLY_SENT_DATE: " + headerField
Log.v(LOG_TAG, "parseHeaders: PREVIOUSLY_SENT_DATE: " + headerField
+ " value: " + perviouslySentDate);
}
headers.setLongInteger(perviouslySentDate,
@@ -733,7 +738,7 @@ public class PduParser {
* Encoded-string-value
*/
if (LOCAL_LOGV) {
Timber.v("parseHeaders: MM_FLAGS: " + headerField
Log.v(LOG_TAG, "parseHeaders: MM_FLAGS: " + headerField
+ " NOT REALLY SUPPORTED");
}
@@ -757,7 +762,7 @@ public class PduParser {
case PduHeaders.MBOX_QUOTAS:
{
if (LOCAL_LOGV) {
Timber.v("parseHeaders: MBOX_TOTALS: " + headerField);
Log.v(LOG_TAG, "parseHeaders: MBOX_TOTALS: " + headerField);
}
/* Value-length */
parseValueLength(pduDataStream);
@@ -780,7 +785,7 @@ public class PduParser {
case PduHeaders.ELEMENT_DESCRIPTOR: {
if (LOCAL_LOGV) {
Timber.v("parseHeaders: ELEMENT_DESCRIPTOR: " + headerField);
Log.v(LOG_TAG, "parseHeaders: ELEMENT_DESCRIPTOR: " + headerField);
}
parseContentType(pduDataStream, null);
@@ -798,7 +803,8 @@ public class PduParser {
if (null != contentType) {
try {
if (LOCAL_LOGV) {
Timber.v("parseHeaders: CONTENT_TYPE: " + headerField + contentType.toString());
Log.v(LOG_TAG, "parseHeaders: CONTENT_TYPE: " + headerField +
contentType.toString());
}
headers.setTextString(contentType, PduHeaders.CONTENT_TYPE);
} catch(NullPointerException e) {
@@ -824,7 +830,7 @@ public class PduParser {
case PduHeaders.ATTRIBUTES:
default: {
if (LOCAL_LOGV) {
Timber.v("parseHeaders: Unknown header: " + headerField);
Log.v(LOG_TAG, "parseHeaders: Unknown header: " + headerField);
}
log("Unknown header");
}
@@ -956,7 +962,7 @@ public class PduParser {
*/
private static void log(String text) {
if (LOCAL_LOGV) {
Timber.v(text);
Log.v(LOG_TAG, text);
}
}
@@ -1470,7 +1476,7 @@ public class PduParser {
map.put(PduPart.P_CHARSET, charsetInt);
} catch (UnsupportedEncodingException e) {
// Not a well-known charset, use "*".
Timber.e(e, Arrays.toString(charsetStr));
Log.e(LOG_TAG, Arrays.toString(charsetStr), e);
map.put(PduPart.P_CHARSET, CharacterSets.ANY_CHARSET);
}
} else {
@@ -1505,10 +1511,10 @@ public class PduParser {
break;
default:
if (LOCAL_LOGV) {
Timber.v("Not supported Content-Type parameter");
Log.v(LOG_TAG, "Not supported Content-Type parameter");
}
if (-1 == skipWapValue(pduDataStream, lastLen)) {
Timber.e("Corrupt Content-Type");
Log.e(LOG_TAG, "Corrupt Content-Type");
} else {
lastLen = 0;
}
@@ -1517,7 +1523,7 @@ public class PduParser {
}
if (0 != lastLen) {
Timber.e("Corrupt Content-Type");
Log.e(LOG_TAG, "Corrupt Content-Type");
}
}
@@ -1567,7 +1573,7 @@ public class PduParser {
contentType = parseWapString(pduDataStream, TYPE_TEXT_STRING);
}
} else {
Timber.e("Corrupt content-type");
Log.e(LOG_TAG, "Corrupt content-type");
return (PduContentTypes.contentTypes[0]).getBytes(); //"*/*"
}
@@ -1578,7 +1584,7 @@ public class PduParser {
}
if (parameterLen < 0) {
Timber.e("Corrupt MMS message");
Log.e(LOG_TAG, "Corrupt MMS message");
return (PduContentTypes.contentTypes[0]).getBytes(); //"*/*"
}
} else if (cur <= TEXT_MAX) {
@@ -1717,10 +1723,10 @@ public class PduParser {
break;
default:
if (LOCAL_LOGV) {
Timber.v("Not supported Part headers: " + header);
Log.v(LOG_TAG, "Not supported Part headers: " + header);
}
if (-1 == skipWapValue(pduDataStream, lastLen)) {
Timber.e("Corrupt Part headers");
Log.e(LOG_TAG, "Corrupt Part headers");
return false;
}
lastLen = 0;
@@ -1741,11 +1747,11 @@ public class PduParser {
lastLen = length - (startPos - tempPos);
} else {
if (LOCAL_LOGV) {
Timber.v("Not supported Part headers: " + header);
Log.v(LOG_TAG, "Not supported Part headers: " + header);
}
// Skip all headers of this part.
if (-1 == skipWapValue(pduDataStream, lastLen)) {
Timber.e("Corrupt Part headers");
Log.e(LOG_TAG, "Corrupt Part headers");
return false;
}
lastLen = 0;
@@ -1753,7 +1759,7 @@ public class PduParser {
}
if (0 != lastLen) {
Timber.e("Corrupt Part headers");
Log.e(LOG_TAG, "Corrupt Part headers");
return false;
}
+2
View File
@@ -118,6 +118,8 @@ public class PduPart {
*/
private byte[] mPartData = null;
private static final String TAG = "PduPart";
/**
* Empty Constructor.
*/
+252 -215
View File
@@ -27,8 +27,8 @@ import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteException;
import android.drm.DrmManagerClient;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.provider.Telephony;
import android.provider.Telephony.Mms;
import android.provider.Telephony.Mms.Addr;
import android.provider.Telephony.Mms.Part;
@@ -38,6 +38,8 @@ import android.provider.Telephony.Threads;
import android.telephony.PhoneNumberUtils;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import com.android.mms.service_alt.SubscriptionIdChecker;
import com.google.android.mms.ContentType;
import com.google.android.mms.InvalidHeaderValueException;
import com.google.android.mms.MmsException;
@@ -48,6 +50,8 @@ import com.google.android.mms.util_alt.PduCacheEntry;
import com.google.android.mms.util_alt.SqliteWrapper;
import timber.log.Timber;
import com.klinker.android.send_message.Settings;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
@@ -65,9 +69,11 @@ import java.util.Set;
* This class is the high-level manager of PDU storage.
*/
public class PduPersister {
private static final String TAG = "PduPersister";
private static final boolean DEBUG = false;
private static final boolean LOCAL_LOGV = false;
public static final long DUMMY_THREAD_ID = Long.MAX_VALUE;
private static final long DUMMY_THREAD_ID = Long.MAX_VALUE;
private static final int DEFAULT_SUBSCRIPTION = 0;
private static final int MAX_TEXT_BODY_SIZE = 300 * 1024;
@@ -75,11 +81,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.
*/
@@ -87,97 +93,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().
@@ -194,9 +200,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>();
@@ -272,7 +278,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;
@@ -283,13 +289,11 @@ 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);
@@ -439,8 +443,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 {
@@ -454,7 +458,7 @@ public class PduPersister {
len = is.read(buffer);
}
} catch (IOException e) {
Timber.e(e, "Failed to load part data");
Timber.e("Failed to load part data", e);
c.close();
throw new MmsException(e);
} finally {
@@ -462,7 +466,7 @@ public class PduPersister {
try {
is.close();
} catch (IOException e) {
Timber.e(e, "Failed to close stream");
Timber.e("Failed to close stream", e);
} // Ignore
}
}
@@ -483,7 +487,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) {
@@ -530,7 +534,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) {
Timber.v("load: " + uri + " blocked by isUpdating()");
@@ -538,13 +542,15 @@ public class PduPersister {
try {
PDU_CACHE_INSTANCE.wait();
} catch (InterruptedException e) {
Timber.e(e, "load: ");
}
cacheEntry = PDU_CACHE_INSTANCE.get(uri);
if (cacheEntry != null) {
return cacheEntry.getPdu();
Timber.e("load: ", e);
}
}
cacheEntry = PDU_CACHE_INSTANCE.get(uri);
if (cacheEntry != null) {
return cacheEntry.getPdu();
}
// Tell the cache to indicate to other callers that this item
// is currently being updated.
PDU_CACHE_INSTANCE.setUpdating(uri, true);
@@ -618,57 +624,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);
@@ -680,7 +686,8 @@ public class PduPersister {
return pdu;
}
private void persistAddress(long msgId, int type, EncodedStringValue[] array) {
private void persistAddress(
long msgId, int type, EncodedStringValue[] array) {
ContentValues values = new ContentValues(3);
for (EncodedStringValue addr : array) {
@@ -704,7 +711,7 @@ public class PduPersister {
ContentValues values = new ContentValues(8);
int charset = part.getCharset();
if (charset != 0) {
if (charset != 0 ) {
values.put(Part.CHARSET, charset);
}
@@ -798,15 +805,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;
@@ -856,7 +863,7 @@ public class PduPersister {
return;
}
} catch (Exception e) {
Timber.e(e, "Can't get file info for: " + part.getDataUri());
Timber.e("Can't get file info for: " + part.getDataUri(), e);
}
}
// We haven't converted the file yet, start the conversion
@@ -919,24 +926,24 @@ public class PduPersister {
}
}
} catch (FileNotFoundException e) {
Timber.e(e, "Failed to open Input/Output stream.");
Timber.e("Failed to open Input/Output stream.", e);
throw new MmsException(e);
} catch (IOException e) {
Timber.e(e, "Failed to read/write data.");
Timber.e("Failed to read/write data.", e);
throw new MmsException(e);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
Timber.e(e, "IOException while closing: " + os);
Timber.e("IOException while closing: " + os, e);
} // Ignore
}
if (is != null) {
try {
is.close();
} catch (IOException e) {
Timber.e(e, "IOException while closing: " + is);
Timber.e("IOException while closing: " + is, e);
} // Ignore
}
if (drmConvertSession != null) {
@@ -947,18 +954,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
* <p>
* content://media/<table_name>/<row_index> (or)
* file://sdcard/test.mp4
* http://test.com/test.mp4
*
* Here <table_name> shall be "video" or "audio" or "images"
* <row_index> the index of the content in given table
*/
@@ -974,7 +981,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,
@@ -1013,12 +1020,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)) {
@@ -1028,7 +1035,7 @@ public class PduPersister {
try {
PDU_CACHE_INSTANCE.wait();
} catch (InterruptedException e) {
Timber.e(e, "updateHeaders: ");
Timber.e("updateHeaders: ", e);
}
}
}
@@ -1127,7 +1134,7 @@ public class PduPersister {
ContentValues values = new ContentValues(7);
int charset = part.getCharset();
if (charset != 0) {
if (charset != 0 ) {
values.put(Part.CHARSET, charset);
}
@@ -1179,8 +1186,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.
*/
@@ -1188,7 +1195,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) {
Timber.v("updateParts: " + uri + " blocked by isUpdating()");
@@ -1196,7 +1203,7 @@ public class PduPersister {
try {
PDU_CACHE_INSTANCE.wait();
} catch (InterruptedException e) {
Timber.e(e, "updateParts: ");
Timber.e("updateParts: ", e);
}
cacheEntry = PDU_CACHE_INSTANCE.get(uri);
if (cacheEntry != null) {
@@ -1251,51 +1258,52 @@ 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();
}
}
}
public String getContentLocationFromPduHeader(GenericPdu pdu) {
return toIsoString(pdu.getPduHeaders().getTextString(PduHeaders.CONTENT_LOCATION));
}
/**
* 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 threadId
* @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, long threadId, boolean createThreadId, boolean groupMmsEnabled,
HashMap<Uri, InputStream> preOpenedFiles) throws MmsException {
public Uri persist(GenericPdu pdu, Uri uri, boolean createThreadId, boolean groupMmsEnabled,
HashMap<Uri, InputStream> preOpenedFiles, int subscriptionId)
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)) {
@@ -1305,7 +1313,7 @@ public class PduPersister {
try {
PDU_CACHE_INSTANCE.wait();
} catch (InterruptedException e) {
Timber.e(e, "persist1: ");
Timber.e("persist1: ", e);
}
}
}
@@ -1328,7 +1336,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));
@@ -1336,7 +1344,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);
@@ -1344,7 +1352,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);
@@ -1401,7 +1409,8 @@ public class PduPersister {
loadRecipients(PduHeaders.TO, recipients, addressMap, false);
break;
}
if (threadId == DUMMY_THREAD_ID && createThreadId && !recipients.isEmpty()) {
long threadId = DUMMY_THREAD_ID;
if (createThreadId && !recipients.isEmpty()) {
// Given all the recipients associated with this message, find (or create) the
// correct thread.
threadId = Threads.getOrCreateThreadId(mContext, recipients);
@@ -1413,6 +1422,9 @@ public class PduPersister {
// while saving the parts.
long dummyId = System.currentTimeMillis(); // Dummy ID of the msg.
// Figure out if this PDU is a text-only message
boolean textOnly = true;
// Sum up the total message size
int messageSize = 0;
@@ -1421,20 +1433,43 @@ public class PduPersister {
body = ((MultimediaMessagePdu) pdu).getBody();
// Start saving parts if necessary.
if (body != null) {
for (int i = 0; i < body.getPartsNum(); i++) {
int partsNum = body.getPartsNum();
if (partsNum > 2) {
// For a text-only message there will be two parts: 1-the SMIL, 2-the text.
// Down a few lines below we're checking to make sure we've only got SMIL or
// text. We also have to check then we don't have more than two parts.
// Otherwise, a slideshow with two text slides would be marked as textOnly.
textOnly = false;
}
for (int i = 0; i < partsNum; i++) {
PduPart part = body.getPart(i);
messageSize += part.getDataLength();
persistPart(part, dummyId, preOpenedFiles);
// If we've got anything besides text/plain or SMIL part, then we've got
// an mms message with some other type of attachment.
String contentType = getPartContentType(part);
if (contentType != null && !ContentType.APP_SMIL.equals(contentType)
&& !ContentType.TEXT_PLAIN.equals(contentType)) {
textOnly = false;
}
}
}
}
// Record whether this mms message is a simple plain text or not. This is a hint for the
// UI.
// values.put(Mms.TEXT_ONLY, textOnly ? 1 : 0);
// The message-size might already have been inserted when parsing the
// PDU header. If not, then we insert the message size as well.
if (values.getAsInteger(Mms.MESSAGE_SIZE) == null) {
values.put(Mms.MESSAGE_SIZE, messageSize);
}
// insert only if it is a valid subscription id.
if (Settings.DEFAULT_SUBSCRIPTION_ID != subscriptionId && SubscriptionIdChecker.getInstance(mContext).canUseSubscriptionId()) {
values.put(Telephony.Mms.SUBSCRIPTION_ID, subscriptionId);
}
Uri res = null;
if (existingUri) {
res = uri;
@@ -1452,8 +1487,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"
@@ -1477,13 +1512,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;
@@ -1512,10 +1547,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.
*/
@@ -1531,9 +1566,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);
@@ -1550,7 +1585,7 @@ public class PduPersister {
return new String(bytes, CharacterSets.MIMENAME_ISO_8859_1);
} catch (UnsupportedEncodingException e) {
// Impossible to reach here!
Timber.e(e, "ISO_8859_1 must be supported!");
Timber.e("ISO_8859_1 must be supported!", e);
return "";
}
}
@@ -1563,7 +1598,7 @@ public class PduPersister {
return data.getBytes(CharacterSets.MIMENAME_ISO_8859_1);
} catch (UnsupportedEncodingException e) {
// Impossible to reach here!
Timber.e(e, "ISO_8859_1 must be supported!");
Timber.e("ISO_8859_1 must be supported!", e);
return new byte[0];
}
}
@@ -1581,8 +1616,8 @@ public class PduPersister {
*/
public Cursor getPendingMessages(long dueTime) {
if (!checkReadSmsPermissions()) {
Timber.w("No read sms permissions have been granted");
return null;
Timber.w("No read sms permissions have been granted");
return null;
}
Uri.Builder uriBuilder = PendingMessages.CONTENT_URI.buildUpon();
uriBuilder.appendQueryParameter("protocol", "mms");
@@ -1590,7 +1625,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)
};
@@ -1604,6 +1639,8 @@ public class PduPersister {
* Check if read permissions for SMS have been granted
*/
private boolean checkReadSmsPermissions() {
return mContext.checkSelfPermission(Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED;
return // Build.VERSION.SDK_INT < Build.VERSION_CODES.M ||
mContext.checkSelfPermission(Manifest.permission.READ_SMS) ==
PackageManager.PERMISSION_GRANTED;
}
}
+24 -2
View File
@@ -16,10 +16,16 @@
package com.google.android.mms.pdu_alt;
import com.google.android.mms.InvalidHeaderValueException;
import android.content.Context;
import android.text.TextUtils;
import timber.log.Timber;
import com.google.android.mms.InvalidHeaderValueException;
import com.klinker.android.send_message.Utils;
public class SendReq extends MultimediaMessagePdu {
private static final String TAG = "SendReq";
public SendReq() {
super();
@@ -34,7 +40,7 @@ public class SendReq extends MultimediaMessagePdu {
setTransactionId(generateTransactionId());
} catch (InvalidHeaderValueException e) {
// Impossible to reach here since all headers we set above are valid.
Timber.e(e, "Unexpected InvalidHeaderValueException.");
Timber.e("Unexpected InvalidHeaderValueException.", e);
throw new RuntimeException(e);
}
}
@@ -291,6 +297,22 @@ public class SendReq extends MultimediaMessagePdu {
mPduHeaders.setTextString(value, PduHeaders.TRANSACTION_ID);
}
/**
* prepares and sets from address info in the request.
*
* @param context context
* @param fromAddress from address info from client
* @param subscriptionId subscription id to use
*/
public void prepareFromAddress(Context context, String fromAddress, int subscriptionId) {
String phoneNumber = Utils.getMyPhoneNumberFromSubscription(context, subscriptionId);
if (!TextUtils.isEmpty(phoneNumber)) {
setFrom(new EncodedStringValue(phoneNumber));
} else if (!TextUtils.isEmpty(fromAddress)) {
setFrom(new EncodedStringValue(fromAddress));
}
}
/*
* Optional, not supported header fields:
*
+4 -7
View File
@@ -1,15 +1,12 @@
package com.google.android.mms.smil;
import android.util.Log;
import com.android.mms.dom.smil.SmilDocumentImpl;
import com.google.android.mms.ContentType;
import com.google.android.mms.pdu_alt.PduBody;
import com.google.android.mms.pdu_alt.PduPart;
import org.w3c.dom.smil.SMILDocument;
import org.w3c.dom.smil.SMILElement;
import org.w3c.dom.smil.SMILLayoutElement;
import org.w3c.dom.smil.SMILMediaElement;
import org.w3c.dom.smil.SMILParElement;
import timber.log.Timber;
import org.w3c.dom.smil.*;
public class SmilHelper {
@@ -88,7 +85,7 @@ public class SmilHelper {
par.appendChild(textElement);
hasMedia = true;
} else {
Timber.e("creating_smil_document", "unknown mimetype");
Log.e("creating_smil_document", "unknown mimetype");
}
}
+4 -2
View File
@@ -16,11 +16,12 @@
package com.google.android.mms.util_alt;
import timber.log.Timber;
import timber.log.Timber; import android.util.Log; import static com.klinker.android.timberworkarounds.TimberExtensionsKt.Timber_isLoggable; // inserted with sed
import java.util.HashMap;
public abstract class AbstractCache<K, V> {
private static final String TAG = "AbstractCache";
private static final boolean DEBUG = false;
private static final boolean LOCAL_LOGV = false;
@@ -93,7 +94,8 @@ public abstract class AbstractCache<K, V> {
public void purgeAll() {
if (LOCAL_LOGV) {
Timber.v("Purging cache, " + mCacheMap.size() + " items dropped.");
Timber.v("Purging cache, " + mCacheMap.size()
+ " items dropped.");
}
mCacheMap.clear();
}
@@ -18,10 +18,10 @@ package com.google.android.mms.util_alt;
import android.content.Context;
import android.drm.DrmManagerClient;
import timber.log.Timber;
import timber.log.Timber; import android.util.Log;
public class DownloadDrmHelper {
private static final String TAG = "DownloadDrmHelper";
/** The MIME type of special DRM files */
public static final String MIMETYPE_DRM_MESSAGE = "application/vnd.oma.drm.message";
@@ -46,7 +46,8 @@ public class DownloadDrmHelper {
result = drmClient.canHandle("", mimetype);
}
} catch (IllegalArgumentException e) {
Timber.w("DrmManagerClient instance could not be created, context is Illegal.");
Log.w(TAG,
"DrmManagerClient instance could not be created, context is Illegal.");
} catch (IllegalStateException e) {
Timber.w("DrmManagerClient didn't initialize properly.");
}
@@ -98,7 +99,8 @@ public class DownloadDrmHelper {
result = drmClient.getOriginalMimeType(path);
}
} catch (IllegalArgumentException ex) {
Timber.w("Can't get original mime type since path is null or empty string.");
Log.w(TAG,
"Can't get original mime type since path is null or empty string.");
} catch (IllegalStateException ex) {
Timber.w("DrmManagerClient didn't initialize properly.");
}
@@ -18,7 +18,8 @@ package com.google.android.mms.util_alt;
import android.content.Context;
import android.drm.DrmConvertedStatus;
import android.drm.DrmManagerClient;
import timber.log.Timber;
import timber.log.Timber; import android.util.Log;
import android.provider.Downloads;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -28,11 +29,7 @@ import java.io.RandomAccessFile;
public class DrmConvertSession {
private DrmManagerClient mDrmClient;
private int mConvertSessionId;
private static final int STATUS_UNKNOWN_ERROR = 491;
private static final int STATUS_NOT_ACCEPTABLE = 406;
private static final int STATUS_SUCCESS = 200;
private static final int STATUS_FILE_ERROR = 492;
private static final String TAG = "DrmConvertSession";
private DrmConvertSession(DrmManagerClient drmClient, int convertSessionId) {
mDrmClient = drmClient;
@@ -58,10 +55,11 @@ public class DrmConvertSession {
Timber.w("Conversion of Mimetype: " + mimeType
+ " is not supported.", e);
} catch (IllegalStateException e) {
Timber.w(e, "Could not access Open DrmFramework.");
Timber.w("Could not access Open DrmFramework.", e);
}
} catch (IllegalArgumentException e) {
Timber.w("DrmManagerClient instance could not be created, context is Illegal.");
Log.w(TAG,
"DrmManagerClient instance could not be created, context is Illegal.");
} catch (IllegalStateException e) {
Timber.w("DrmManagerClient didn't initialize properly.");
}
@@ -116,38 +114,38 @@ public class DrmConvertSession {
* Ends a conversion session of a file.
*
* @param filename The filename of the converted file.
* @return STATUS_SUCCESS if execution is ok.
* STATUS_FILE_ERROR in case converted file can not
* be accessed. STATUS_NOT_ACCEPTABLE if a problem
* @return Downloads.Impl.STATUS_SUCCESS if execution is ok.
* Downloads.Impl.STATUS_FILE_ERROR in case converted file can not
* be accessed. Downloads.Impl.STATUS_NOT_ACCEPTABLE if a problem
* occurs when accessing drm framework.
* STATUS_UNKNOWN_ERROR if a general error occurred.
* Downloads.Impl.STATUS_UNKNOWN_ERROR if a general error occurred.
*/
public int close(String filename) {
DrmConvertedStatus convertedStatus = null;
int result = STATUS_UNKNOWN_ERROR;
int result = Downloads.Impl.STATUS_UNKNOWN_ERROR;
if (mDrmClient != null && mConvertSessionId >= 0) {
try {
convertedStatus = mDrmClient.closeConvertSession(mConvertSessionId);
if (convertedStatus == null ||
convertedStatus.statusCode != DrmConvertedStatus.STATUS_OK ||
convertedStatus.convertedData == null) {
result = STATUS_NOT_ACCEPTABLE;
result = Downloads.Impl.STATUS_NOT_ACCEPTABLE;
} else {
RandomAccessFile rndAccessFile = null;
try {
rndAccessFile = new RandomAccessFile(filename, "rw");
rndAccessFile.seek(convertedStatus.offset);
rndAccessFile.write(convertedStatus.convertedData);
result = STATUS_SUCCESS;
result = Downloads.Impl.STATUS_SUCCESS;
} catch (FileNotFoundException e) {
result = STATUS_FILE_ERROR;
Timber.w(e, "File: " + filename + " could not be found.");
result = Downloads.Impl.STATUS_FILE_ERROR;
Timber.w("File: " + filename + " could not be found.", e);
} catch (IOException e) {
result = STATUS_FILE_ERROR;
Timber.w(e, "Could not access File: " + filename + " .");
result = Downloads.Impl.STATUS_FILE_ERROR;
Timber.w("Could not access File: " + filename + " .", e);
} catch (IllegalArgumentException e) {
result = STATUS_FILE_ERROR;
Timber.w(e, "Could not open file in mode: rw");
result = Downloads.Impl.STATUS_FILE_ERROR;
Timber.w("Could not open file in mode: rw", e);
} catch (SecurityException e) {
Timber.w("Access to File: " + filename +
" was denied denied by SecurityManager.", e);
@@ -156,7 +154,7 @@ public class DrmConvertSession {
try {
rndAccessFile.close();
} catch (IOException e) {
result = STATUS_FILE_ERROR;
result = Downloads.Impl.STATUS_FILE_ERROR;
Timber.w("Failed to close File:" + filename
+ ".", e);
}
+2 -1
View File
@@ -26,7 +26,8 @@ import java.util.HashMap;
import java.util.HashSet;
public final class PduCache extends AbstractCache<Uri, PduCacheEntry> {
private static final String TAG = "PduCache";
private static final boolean DEBUG = false;
private static final boolean LOCAL_LOGV = false;
private static final int MMS_ALL = 0;
+8 -6
View File
@@ -23,10 +23,12 @@ import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.widget.Toast;
import timber.log.Timber;
import android.widget.Toast;
public final class SqliteWrapper {
private static final String TAG = "SqliteWrapper";
private static final String SQLITE_EXCEPTION_DETAIL_MESSAGE
= "unable to open database file";
@@ -68,7 +70,7 @@ public final class SqliteWrapper {
try {
return resolver.query(uri, projection, selection, selectionArgs, sortOrder);
} catch (SQLiteException e) {
Timber.e(e, "Catch a SQLiteException when query: ");
Timber.e("Catch a SQLiteException when query: ", e);
checkSQLiteException(context, e);
return null;
}
@@ -78,7 +80,7 @@ public final class SqliteWrapper {
try {
return cursor.requery();
} catch (SQLiteException e) {
Timber.e(e, "Catch a SQLiteException when requery: ");
Timber.e("Catch a SQLiteException when requery: ", e);
checkSQLiteException(context, e);
return false;
}
@@ -88,7 +90,7 @@ public final class SqliteWrapper {
try {
return resolver.update(uri, values, where, selectionArgs);
} catch (SQLiteException e) {
Timber.e(e, "Catch a SQLiteException when update: ");
Timber.e("Catch a SQLiteException when update: ", e);
checkSQLiteException(context, e);
return -1;
}
@@ -99,7 +101,7 @@ public final class SqliteWrapper {
try {
return resolver.delete(uri, where, selectionArgs);
} catch (SQLiteException e) {
Timber.e(e, "Catch a SQLiteException when delete: ");
Timber.e("Catch a SQLiteException when delete: ", e);
checkSQLiteException(context, e);
return -1;
}
@@ -110,7 +112,7 @@ public final class SqliteWrapper {
try {
return resolver.insert(uri, values);
} catch (SQLiteException e) {
Timber.e(e, "Catch a SQLiteException when insert: ");
Timber.e("Catch a SQLiteException when insert: ", e);
checkSQLiteException(context, e);
return null;
}