forked from upstream-mirrors/quik
Formatting for PduPersister
This commit is contained in:
@@ -38,7 +38,6 @@ import android.provider.Telephony.Threads;
|
|||||||
import android.telephony.PhoneNumberUtils;
|
import android.telephony.PhoneNumberUtils;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.google.android.mms.ContentType;
|
import com.google.android.mms.ContentType;
|
||||||
import com.google.android.mms.InvalidHeaderValueException;
|
import com.google.android.mms.InvalidHeaderValueException;
|
||||||
import com.google.android.mms.MmsException;
|
import com.google.android.mms.MmsException;
|
||||||
@@ -95,14 +94,14 @@ public class PduPersister {
|
|||||||
private static PduPersister sPersister;
|
private static PduPersister sPersister;
|
||||||
private static final PduCache PDU_CACHE_INSTANCE;
|
private static final PduCache PDU_CACHE_INSTANCE;
|
||||||
|
|
||||||
private static final int[] ADDRESS_FIELDS = new int[] {
|
private static final int[] ADDRESS_FIELDS = new int[]{
|
||||||
PduHeaders.BCC,
|
PduHeaders.BCC,
|
||||||
PduHeaders.CC,
|
PduHeaders.CC,
|
||||||
PduHeaders.FROM,
|
PduHeaders.FROM,
|
||||||
PduHeaders.TO
|
PduHeaders.TO
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final String[] PDU_PROJECTION = new String[] {
|
private static final String[] PDU_PROJECTION = new String[]{
|
||||||
Mms._ID,
|
Mms._ID,
|
||||||
Mms.MESSAGE_BOX,
|
Mms.MESSAGE_BOX,
|
||||||
Mms.THREAD_ID,
|
Mms.THREAD_ID,
|
||||||
@@ -160,7 +159,7 @@ public class PduPersister {
|
|||||||
private static final int PDU_COLUMN_SUBJECT_CHARSET = 25;
|
private static final int PDU_COLUMN_SUBJECT_CHARSET = 25;
|
||||||
private static final int PDU_COLUMN_RETRIEVE_TEXT_CHARSET = 26;
|
private static final int PDU_COLUMN_RETRIEVE_TEXT_CHARSET = 26;
|
||||||
|
|
||||||
private static final String[] PART_PROJECTION = new String[] {
|
private static final String[] PART_PROJECTION = new String[]{
|
||||||
Part._ID,
|
Part._ID,
|
||||||
Part.CHARSET,
|
Part.CHARSET,
|
||||||
Part.CONTENT_DISPOSITION,
|
Part.CONTENT_DISPOSITION,
|
||||||
@@ -286,11 +285,13 @@ public class PduPersister {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mContentResolver = context.getContentResolver();
|
mContentResolver = context.getContentResolver();
|
||||||
mDrmManagerClient = new DrmManagerClient(context);
|
mDrmManagerClient = new DrmManagerClient(context);
|
||||||
mTelephonyManager = (TelephonyManager)context
|
mTelephonyManager = (TelephonyManager) context
|
||||||
.getSystemService(Context.TELEPHONY_SERVICE);
|
.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get(or create if not exist) an instance of PduPersister */
|
/**
|
||||||
|
* Get(or create if not exist) an instance of PduPersister
|
||||||
|
*/
|
||||||
public static PduPersister getPduPersister(Context context) {
|
public static PduPersister getPduPersister(Context context) {
|
||||||
if ((sPersister == null)) {
|
if ((sPersister == null)) {
|
||||||
sPersister = new PduPersister(context);
|
sPersister = new PduPersister(context);
|
||||||
@@ -440,7 +441,7 @@ public class PduPersister {
|
|||||||
if (ContentType.TEXT_PLAIN.equals(type) || ContentType.APP_SMIL.equals(type)
|
if (ContentType.TEXT_PLAIN.equals(type) || ContentType.APP_SMIL.equals(type)
|
||||||
|| ContentType.TEXT_HTML.equals(type)) {
|
|| ContentType.TEXT_HTML.equals(type)) {
|
||||||
String text = c.getString(PART_COLUMN_TEXT);
|
String text = c.getString(PART_COLUMN_TEXT);
|
||||||
byte [] blob = new EncodedStringValue(text != null ? text : "")
|
byte[] blob = new EncodedStringValue(text != null ? text : "")
|
||||||
.getTextString();
|
.getTextString();
|
||||||
baos.write(blob, 0, blob.length);
|
baos.write(blob, 0, blob.length);
|
||||||
} else {
|
} else {
|
||||||
@@ -484,7 +485,7 @@ public class PduPersister {
|
|||||||
private void loadAddress(long msgId, PduHeaders headers) {
|
private void loadAddress(long msgId, PduHeaders headers) {
|
||||||
Cursor c = SqliteWrapper.query(mContext, mContentResolver,
|
Cursor c = SqliteWrapper.query(mContext, mContentResolver,
|
||||||
Uri.parse("content://mms/" + msgId + "/addr"),
|
Uri.parse("content://mms/" + msgId + "/addr"),
|
||||||
new String[] { Addr.ADDRESS, Addr.CHARSET, Addr.TYPE },
|
new String[]{Addr.ADDRESS, Addr.CHARSET, Addr.TYPE},
|
||||||
null, null, null);
|
null, null, null);
|
||||||
|
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
@@ -531,7 +532,7 @@ public class PduPersister {
|
|||||||
int msgBox = 0;
|
int msgBox = 0;
|
||||||
long threadId = DUMMY_THREAD_ID;
|
long threadId = DUMMY_THREAD_ID;
|
||||||
try {
|
try {
|
||||||
synchronized(PDU_CACHE_INSTANCE) {
|
synchronized (PDU_CACHE_INSTANCE) {
|
||||||
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
||||||
if (LOCAL_LOGV) {
|
if (LOCAL_LOGV) {
|
||||||
Log.v(TAG, "load: " + uri + " blocked by isUpdating()");
|
Log.v(TAG, "load: " + uri + " blocked by isUpdating()");
|
||||||
@@ -667,9 +668,9 @@ public class PduPersister {
|
|||||||
"Unrecognized PDU type: " + Integer.toHexString(msgType));
|
"Unrecognized PDU type: " + Integer.toHexString(msgType));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
synchronized(PDU_CACHE_INSTANCE) {
|
synchronized (PDU_CACHE_INSTANCE) {
|
||||||
if (pdu != null) {
|
if (pdu != null) {
|
||||||
assert(PDU_CACHE_INSTANCE.get(uri) == null);
|
assert (PDU_CACHE_INSTANCE.get(uri) == null);
|
||||||
// Update the cache entry with the real info
|
// Update the cache entry with the real info
|
||||||
cacheEntry = new PduCacheEntry(pdu, msgBox, threadId);
|
cacheEntry = new PduCacheEntry(pdu, msgBox, threadId);
|
||||||
PDU_CACHE_INSTANCE.put(uri, cacheEntry);
|
PDU_CACHE_INSTANCE.put(uri, cacheEntry);
|
||||||
@@ -706,7 +707,7 @@ public class PduPersister {
|
|||||||
ContentValues values = new ContentValues(8);
|
ContentValues values = new ContentValues(8);
|
||||||
|
|
||||||
int charset = part.getCharset();
|
int charset = part.getCharset();
|
||||||
if (charset != 0 ) {
|
if (charset != 0) {
|
||||||
values.put(Part.CHARSET, charset);
|
values.put(Part.CHARSET, charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -960,7 +961,7 @@ public class PduPersister {
|
|||||||
* content://media/<table_name>/<row_index> (or)
|
* content://media/<table_name>/<row_index> (or)
|
||||||
* file://sdcard/test.mp4
|
* file://sdcard/test.mp4
|
||||||
* http://test.com/test.mp4
|
* http://test.com/test.mp4
|
||||||
*
|
* <p>
|
||||||
* Here <table_name> shall be "video" or "audio" or "images"
|
* Here <table_name> shall be "video" or "audio" or "images"
|
||||||
* <row_index> the index of the content in given table
|
* <row_index> the index of the content in given table
|
||||||
*/
|
*/
|
||||||
@@ -976,7 +977,7 @@ public class PduPersister {
|
|||||||
path = uri.toString();
|
path = uri.toString();
|
||||||
|
|
||||||
} else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
|
} else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
|
||||||
String[] projection = new String[] {MediaStore.MediaColumns.DATA};
|
String[] projection = new String[]{MediaStore.MediaColumns.DATA};
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
cursor = context.getContentResolver().query(uri, projection, null,
|
cursor = context.getContentResolver().query(uri, projection, null,
|
||||||
@@ -1020,7 +1021,7 @@ public class PduPersister {
|
|||||||
* @throws MmsException Bad URI or updating failed.
|
* @throws MmsException Bad URI or updating failed.
|
||||||
*/
|
*/
|
||||||
public void updateHeaders(Uri uri, SendReq sendReq) {
|
public void updateHeaders(Uri uri, SendReq sendReq) {
|
||||||
synchronized(PDU_CACHE_INSTANCE) {
|
synchronized (PDU_CACHE_INSTANCE) {
|
||||||
// If the cache item is getting updated, wait until it's done updating before
|
// If the cache item is getting updated, wait until it's done updating before
|
||||||
// purging it.
|
// purging it.
|
||||||
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
||||||
@@ -1129,7 +1130,7 @@ public class PduPersister {
|
|||||||
ContentValues values = new ContentValues(7);
|
ContentValues values = new ContentValues(7);
|
||||||
|
|
||||||
int charset = part.getCharset();
|
int charset = part.getCharset();
|
||||||
if (charset != 0 ) {
|
if (charset != 0) {
|
||||||
values.put(Part.CHARSET, charset);
|
values.put(Part.CHARSET, charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1190,7 +1191,7 @@ public class PduPersister {
|
|||||||
throws MmsException {
|
throws MmsException {
|
||||||
try {
|
try {
|
||||||
PduCacheEntry cacheEntry;
|
PduCacheEntry cacheEntry;
|
||||||
synchronized(PDU_CACHE_INSTANCE) {
|
synchronized (PDU_CACHE_INSTANCE) {
|
||||||
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
||||||
if (LOCAL_LOGV) {
|
if (LOCAL_LOGV) {
|
||||||
Log.v(TAG, "updateParts: " + uri + " blocked by isUpdating()");
|
Log.v(TAG, "updateParts: " + uri + " blocked by isUpdating()");
|
||||||
@@ -1253,7 +1254,7 @@ public class PduPersister {
|
|||||||
updatePart(e.getKey(), e.getValue(), preOpenedFiles);
|
updatePart(e.getKey(), e.getValue(), preOpenedFiles);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
synchronized(PDU_CACHE_INSTANCE) {
|
synchronized (PDU_CACHE_INSTANCE) {
|
||||||
PDU_CACHE_INSTANCE.setUpdating(uri, false);
|
PDU_CACHE_INSTANCE.setUpdating(uri, false);
|
||||||
PDU_CACHE_INSTANCE.notifyAll();
|
PDU_CACHE_INSTANCE.notifyAll();
|
||||||
}
|
}
|
||||||
@@ -1274,17 +1275,19 @@ public class PduPersister {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public Uri persist(GenericPdu pdu, Uri uri, boolean createThreadId, boolean groupMmsEnabled,
|
public Uri persist(GenericPdu pdu, Uri uri, boolean createThreadId, boolean groupMmsEnabled,
|
||||||
HashMap<Uri, InputStream> preOpenedFiles)
|
HashMap<Uri, InputStream> preOpenedFiles) throws MmsException {
|
||||||
throws MmsException {
|
|
||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
throw new MmsException("Uri may not be null.");
|
throw new MmsException("Uri may not be null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
long msgId = -1;
|
long msgId = -1;
|
||||||
try {
|
try {
|
||||||
msgId = ContentUris.parseId(uri);
|
msgId = ContentUris.parseId(uri);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
// the uri ends with "inbox" or something else like that
|
// the uri ends with "inbox" or something else like that
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean existingUri = msgId != -1;
|
boolean existingUri = msgId != -1;
|
||||||
|
|
||||||
if (!existingUri && MESSAGE_BOX_MAP.get(uri) == null) {
|
if (!existingUri && MESSAGE_BOX_MAP.get(uri) == null) {
|
||||||
@@ -1294,7 +1297,7 @@ public class PduPersister {
|
|||||||
+ "content://mms/drafts, content://mms/outbox, "
|
+ "content://mms/drafts, content://mms/outbox, "
|
||||||
+ "content://mms/temp.");
|
+ "content://mms/temp.");
|
||||||
}
|
}
|
||||||
synchronized(PDU_CACHE_INSTANCE) {
|
synchronized (PDU_CACHE_INSTANCE) {
|
||||||
// If the cache item is getting updated, wait until it's done updating before
|
// If the cache item is getting updated, wait until it's done updating before
|
||||||
// purging it.
|
// purging it.
|
||||||
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
|
||||||
@@ -1327,7 +1330,7 @@ public class PduPersister {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set = TEXT_STRING_COLUMN_NAME_MAP.entrySet();
|
set = TEXT_STRING_COLUMN_NAME_MAP.entrySet();
|
||||||
for (Entry<Integer, String> e : set){
|
for (Entry<Integer, String> e : set) {
|
||||||
byte[] text = header.getTextString(e.getKey());
|
byte[] text = header.getTextString(e.getKey());
|
||||||
if (text != null) {
|
if (text != null) {
|
||||||
values.put(e.getValue(), toIsoString(text));
|
values.put(e.getValue(), toIsoString(text));
|
||||||
@@ -1335,7 +1338,7 @@ public class PduPersister {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set = OCTET_COLUMN_NAME_MAP.entrySet();
|
set = OCTET_COLUMN_NAME_MAP.entrySet();
|
||||||
for (Entry<Integer, String> e : set){
|
for (Entry<Integer, String> e : set) {
|
||||||
int b = header.getOctet(e.getKey());
|
int b = header.getOctet(e.getKey());
|
||||||
if (b != 0) {
|
if (b != 0) {
|
||||||
values.put(e.getValue(), b);
|
values.put(e.getValue(), b);
|
||||||
@@ -1343,7 +1346,7 @@ public class PduPersister {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set = LONG_COLUMN_NAME_MAP.entrySet();
|
set = LONG_COLUMN_NAME_MAP.entrySet();
|
||||||
for (Entry<Integer, String> e : set){
|
for (Entry<Integer, String> e : set) {
|
||||||
long l = header.getLongInteger(e.getKey());
|
long l = header.getLongInteger(e.getKey());
|
||||||
if (l != -1L) {
|
if (l != -1L) {
|
||||||
values.put(e.getValue(), l);
|
values.put(e.getValue(), l);
|
||||||
@@ -1611,7 +1614,7 @@ public class PduPersister {
|
|||||||
String selection = PendingMessages.ERROR_TYPE + " < ?"
|
String selection = PendingMessages.ERROR_TYPE + " < ?"
|
||||||
+ " AND " + PendingMessages.DUE_TIME + " <= ?";
|
+ " AND " + PendingMessages.DUE_TIME + " <= ?";
|
||||||
|
|
||||||
String[] selectionArgs = new String[] {
|
String[] selectionArgs = new String[]{
|
||||||
String.valueOf(MmsSms.ERR_TYPE_GENERIC_PERMANENT),
|
String.valueOf(MmsSms.ERR_TYPE_GENERIC_PERMANENT),
|
||||||
String.valueOf(dueTime)
|
String.valueOf(dueTime)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -75,8 +75,6 @@ public class Transaction {
|
|||||||
public static Settings settings;
|
public static Settings settings;
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
private Intent explicitSentMmsReceiver;
|
|
||||||
|
|
||||||
private boolean saveMessage = true;
|
private boolean saveMessage = true;
|
||||||
|
|
||||||
public String SMS_SENT = ".SMS_SENT";
|
public String SMS_SENT = ".SMS_SENT";
|
||||||
@@ -381,9 +379,8 @@ public class Transaction {
|
|||||||
data.add(part);
|
data.add(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.v(TAG, "using lollipop method for sending sms");
|
Log.v(TAG, "sending mms");
|
||||||
Log.v(TAG, "using system method for sending");
|
sendMmsThroughSystem(context, subject, data, addresses);
|
||||||
sendMmsThroughSystem(context, subject, data, addresses, explicitSentMmsReceiver);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MessageInfo getBytes(Context context, boolean saveMessage, String[] recipients, MMSPart[] parts,
|
public static MessageInfo getBytes(Context context, boolean saveMessage, String[] recipients, MMSPart[] parts,
|
||||||
@@ -509,8 +506,7 @@ public class Transaction {
|
|||||||
public static final long DEFAULT_EXPIRY_TIME = 7 * 24 * 60 * 60;
|
public static final long DEFAULT_EXPIRY_TIME = 7 * 24 * 60 * 60;
|
||||||
public static final int DEFAULT_PRIORITY = PduHeaders.PRIORITY_NORMAL;
|
public static final int DEFAULT_PRIORITY = PduHeaders.PRIORITY_NORMAL;
|
||||||
|
|
||||||
private static void sendMmsThroughSystem(Context context, String subject, List<MMSPart> parts, String[] addresses,
|
private static void sendMmsThroughSystem(Context context, String subject, List<MMSPart> parts, String[] addresses) {
|
||||||
Intent explicitSentMmsReceiver) {
|
|
||||||
try {
|
try {
|
||||||
final String fileName = "send." + String.valueOf(Math.abs(new Random().nextLong())) + ".dat";
|
final String fileName = "send." + String.valueOf(Math.abs(new Random().nextLong())) + ".dat";
|
||||||
File mSendFile = new File(context.getCacheDir(), fileName);
|
File mSendFile = new File(context.getCacheDir(), fileName);
|
||||||
@@ -520,13 +516,8 @@ public class Transaction {
|
|||||||
Uri messageUri = persister.persist(sendReq, Uri.parse("content://mms/outbox"),
|
Uri messageUri = persister.persist(sendReq, Uri.parse("content://mms/outbox"),
|
||||||
true, true, null);
|
true, true, null);
|
||||||
|
|
||||||
Intent intent;
|
Intent intent = new Intent(MmsSentReceiver.MMS_SENT);
|
||||||
if (explicitSentMmsReceiver == null) {
|
|
||||||
intent = new Intent(MmsSentReceiver.MMS_SENT);
|
|
||||||
BroadcastUtils.addClassName(context, intent, MmsSentReceiver.MMS_SENT);
|
BroadcastUtils.addClassName(context, intent, MmsSentReceiver.MMS_SENT);
|
||||||
} else {
|
|
||||||
intent = explicitSentMmsReceiver;
|
|
||||||
}
|
|
||||||
|
|
||||||
intent.putExtra(MmsSentReceiver.EXTRA_CONTENT_URI, messageUri.toString());
|
intent.putExtra(MmsSentReceiver.EXTRA_CONTENT_URI, messageUri.toString());
|
||||||
intent.putExtra(MmsSentReceiver.EXTRA_FILE_PATH, mSendFile.getPath());
|
intent.putExtra(MmsSentReceiver.EXTRA_FILE_PATH, mSendFile.getPath());
|
||||||
|
|||||||
Reference in New Issue
Block a user