Skip to content

Commit

Permalink
Go back to using new KitKat APIs in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
klinker41 committed Jul 8, 2014
1 parent 2e8036c commit 0dfc0d0
Show file tree
Hide file tree
Showing 19 changed files with 310 additions and 379 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ module_android-smsmms.xml
build/
.gradle/
ion/build/
ion/.gradle/
ion/.gradle/
*.iml
1 change: 0 additions & 1 deletion android-smsmms.iml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 20 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
2 changes: 1 addition & 1 deletion src/com/android/mms/transaction/MessageSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ public interface MessageSender {
* sent through SMS.
* @throws MmsException Error occurred while sending the message.
*/
boolean sendMessage(long token) throws Throwable;
boolean sendMessage(long token) throws Exception;
}
6 changes: 3 additions & 3 deletions src/com/android/mms/transaction/MessageStatusService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* received.
*/
public class MessageStatusService extends IntentService {
private static final String[] ID_PROJECTION = new String[] { "_id" };
private static final String[] ID_PROJECTION = new String[] {Telephony.Sms._ID };
private static final String LOG_TAG = "MessageStatusReceiver";
private static final Uri STATUS_URI = Uri.parse("content://sms/status");

Expand Down Expand Up @@ -79,8 +79,8 @@ private SmsMessage updateMessageStatus(Context context, Uri messageUri, byte[] p
log("updateMessageStatus: msgUrl=" + messageUri + ", status=" + status +
", isStatusReport=" + isStatusReport);

contentValues.put("status", status);
contentValues.put("date_sent", System.currentTimeMillis());
contentValues.put(Telephony.Sms.STATUS, status);
contentValues.put(Telephony.Sms.Inbox.DATE_SENT, System.currentTimeMillis());
SqliteWrapper.update(context, context.getContentResolver(),
updateUri, contentValues, null, null);
} else {
Expand Down
45 changes: 16 additions & 29 deletions src/com/android/mms/transaction/MmsMessageSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,15 @@

package com.android.mms.transaction;

import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.*;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.provider.Telephony;
import android.util.Log;

import com.android.mms.util.SendingProgressTokenManager;
import com.google.android.mms.InvalidHeaderValueException;
import com.google.android.mms.MmsException;
import com.google.android.mms.pdu_alt.EncodedStringValue;
import com.google.android.mms.pdu_alt.GenericPdu;
import com.google.android.mms.pdu_alt.PduHeaders;
import com.google.android.mms.pdu_alt.PduPersister;
import com.google.android.mms.pdu_alt.ReadRecInd;
import com.google.android.mms.pdu_alt.SendReq;
import com.google.android.mms.pdu_alt.*;
import com.google.android.mms.util_alt.SqliteWrapper;

public class MmsMessageSender implements MessageSender {
Expand Down Expand Up @@ -64,7 +55,7 @@ public MmsMessageSender(Context context, Uri location, long messageSize) {
}
}

public boolean sendMessage(long token) throws Throwable {
public boolean sendMessage(long token) throws Exception {
// Load the MMS from the message uri
PduPersister p = PduPersister.getPduPersister(mContext);
GenericPdu pdu = p.load(mMessageUri);
Expand All @@ -91,31 +82,27 @@ public boolean sendMessage(long token) throws Throwable {
long messageId = ContentUris.parseId(mMessageUri);

// Move the message into MMS Outbox.
if (!mMessageUri.toString().startsWith(Uri.parse("content://mms/drafts").toString())) {
if (!mMessageUri.toString().startsWith(Telephony.Mms.Draft.CONTENT_URI.toString())) {
// If the message is already in the outbox (most likely because we created a "primed"
// message in the outbox when the user hit send), then we have to manually put an
// entry in the pending_msgs table which is where TransacationService looks for
// messages to send. Normally, the entry in pending_msgs is created by the trigger:
// insert_mms_pending_on_update, when a message is moved from drafts to the outbox.
ContentValues values = new ContentValues(7);

values.put("proto_type", 1);
values.put("msg_id", messageId);
values.put("msg_type", pdu.getMessageType());
values.put("err_type", 0);
values.put("err_code", 0);
values.put("retry_index", 0);
values.put("due_time", 0);
values.put(Telephony.MmsSms.PendingMessages.PROTO_TYPE, 1);
values.put(Telephony.MmsSms.PendingMessages.MSG_ID, messageId);
values.put(Telephony.MmsSms.PendingMessages.MSG_TYPE, pdu.getMessageType());
values.put(Telephony.MmsSms.PendingMessages.ERROR_TYPE, 0);
values.put(Telephony.MmsSms.PendingMessages.ERROR_CODE, 0);
values.put(Telephony.MmsSms.PendingMessages.RETRY_INDEX, 0);
values.put(Telephony.MmsSms.PendingMessages.DUE_TIME, 0);

Uri uri = SqliteWrapper.insert(mContext, mContext.getContentResolver(),
Uri.withAppendedPath(
Uri.parse("content://mms-sms/"), "pending"), values);
SqliteWrapper.insert(mContext, mContext.getContentResolver(),
Telephony.MmsSms.PendingMessages.CONTENT_URI, values);

if (uri == null) {
throw new Throwable("Cannot insert into correct database, fall back to old method");
}
} else {
p.move(mMessageUri, Uri.parse("content://mms/outbox"));
p.move(mMessageUri, Telephony.Mms.Outbox.CONTENT_URI);
}

// Start MMS transaction service
Expand Down Expand Up @@ -174,7 +161,7 @@ public static void sendReadRec(Context context, String to, String messageId, int
group = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("group_message", true);
}

PduPersister.getPduPersister(context).persist(readRec, Uri.parse("content://mms/outbox"), true,
PduPersister.getPduPersister(context).persist(readRec, Telephony.Mms.Outbox.CONTENT_URI, true,
group, null);
context.startService(new Intent(context, TransactionService.class));
} catch (InvalidHeaderValueException e) {
Expand Down
3 changes: 2 additions & 1 deletion src/com/android/mms/transaction/MmsSystemEventReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.provider.Telephony;
import android.util.Log;
import com.klinker.android.send_message.Utils;

Expand Down Expand Up @@ -59,7 +60,7 @@ public void onReceive(Context context, Intent intent) {

String action = intent.getAction();
if (action.equals("android.intent.action.CONTENT_CHANGED")) {
Uri changed = (Uri) intent.getParcelableExtra("deleted_contents");
Uri changed = (Uri) intent.getParcelableExtra(Telephony.Mms.Intents.DELETED_CONTENTS);
} else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
if (mConnMgr == null) {
mConnMgr = (ConnectivityManager) context
Expand Down
38 changes: 13 additions & 25 deletions src/com/android/mms/transaction/NotificationTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@

package com.android.mms.transaction;

import static com.android.mms.transaction.TransactionState.FAILED;
import static com.android.mms.transaction.TransactionState.INITIALIZED;
import static com.android.mms.transaction.TransactionState.SUCCESS;
import static com.google.android.mms.pdu_alt.PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF;
import static com.google.android.mms.pdu_alt.PduHeaders.STATUS_DEFERRED;
import static com.google.android.mms.pdu_alt.PduHeaders.STATUS_RETRIEVED;
import static com.google.android.mms.pdu_alt.PduHeaders.STATUS_UNRECOGNIZED;

import java.io.IOException;

import android.app.Service;
import android.content.ContentValues;
import android.content.Context;
Expand All @@ -38,17 +28,15 @@
import android.provider.Telephony;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.android.mms.MmsConfig;
import com.android.mms.util.DownloadManager;
import com.google.android.mms.MmsException;
import com.google.android.mms.pdu_alt.GenericPdu;
import com.google.android.mms.pdu_alt.NotificationInd;
import com.google.android.mms.pdu_alt.NotifyRespInd;
import com.google.android.mms.pdu_alt.PduComposer;
import com.google.android.mms.pdu_alt.PduHeaders;
import com.google.android.mms.pdu_alt.PduParser;
import com.google.android.mms.pdu_alt.PduPersister;
import com.google.android.mms.pdu_alt.*;

import java.io.IOException;

import static com.android.mms.transaction.TransactionState.*;
import static com.google.android.mms.pdu_alt.PduHeaders.*;

/**
* The NotificationTransaction is responsible for handling multimedia
Expand Down Expand Up @@ -121,7 +109,7 @@ public NotificationTransaction(
}

mUri = PduPersister.getPduPersister(context).persist(
ind, Uri.parse("content://mms/inbox"), !allowAutoDownload(context),
ind, Telephony.Mms.Inbox.CONTENT_URI, !allowAutoDownload(context),
group, null);
} catch (MmsException e) {
Log.e(TAG, "Failed to save NotificationInd in constructor.", e);
Expand All @@ -143,7 +131,9 @@ public void process() {

public static boolean allowAutoDownload(Context context) {
try { Looper.prepare(); } catch (Exception e) { }
boolean autoDownload = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("auto_download_mms", true);
DownloadManager.init(context);
DownloadManager downloadManager = DownloadManager.getInstance();
boolean autoDownload = downloadManager.isAuto();
boolean dataSuspended = (((TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE)).getDataState() ==
TelephonyManager.DATA_SUSPENDED);
return autoDownload && !dataSuspended;
Expand Down Expand Up @@ -200,12 +190,12 @@ public void run() {
} else {
// Save the received PDU (must be a M-RETRIEVE.CONF).
PduPersister p = PduPersister.getPduPersister(mContext);
Uri uri = p.persist(pdu, Uri.parse("content://mms/inbox"), true,
Uri uri = p.persist(pdu, Telephony.Mms.Inbox.CONTENT_URI, true,
com.klinker.android.send_message.Transaction.settings.getGroup(), null);

// Use local time instead of PDU time
ContentValues values = new ContentValues(1);
values.put("date", System.currentTimeMillis() / 1000L);
values.put(Telephony.Mms.DATE, System.currentTimeMillis() / 1000L);
SqliteWrapper.update(mContext, mContext.getContentResolver(),
uri, values, null, null);

Expand All @@ -216,9 +206,7 @@ public void run() {
Log.v(TAG, "NotificationTransaction received new mms message: " + uri);
// Delete obsolete threads
SqliteWrapper.delete(mContext, mContext.getContentResolver(),
Uri.withAppendedPath(
Uri.withAppendedPath(
Uri.parse("content://mms-sms/"), "conversations"), "obsolete"), null, null);
Telephony.Threads.OBSOLETE_THREADS_URI, null, null);

// Notify observers with newly received MM.
mUri = uri;
Expand Down
26 changes: 9 additions & 17 deletions src/com/android/mms/transaction/PushReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

package com.android.mms.transaction;

import static com.google.android.mms.pdu_alt.PduHeaders.MESSAGE_TYPE_DELIVERY_IND;
import static com.google.android.mms.pdu_alt.PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND;
import static com.google.android.mms.pdu_alt.PduHeaders.MESSAGE_TYPE_READ_ORIG_IND;

import android.content.*;
import android.database.Cursor;
import android.database.DatabaseUtils;
Expand All @@ -30,18 +26,14 @@
import android.os.Build;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.provider.Telephony;
import android.util.Log;

import com.android.mms.MmsConfig;
import com.google.android.mms.ContentType;
import com.google.android.mms.MmsException;
import com.google.android.mms.pdu_alt.DeliveryInd;
import com.google.android.mms.pdu_alt.GenericPdu;
import com.google.android.mms.pdu_alt.NotificationInd;
import com.google.android.mms.pdu_alt.PduHeaders;
import com.google.android.mms.pdu_alt.PduParser;
import com.google.android.mms.pdu_alt.PduPersister;
import com.google.android.mms.pdu_alt.ReadOrigInd;
import com.google.android.mms.pdu_alt.*;

import static com.google.android.mms.pdu_alt.PduHeaders.*;

/**
* Receives Intent.WAP_PUSH_RECEIVED_ACTION intents and starts the
Expand Down Expand Up @@ -100,7 +92,7 @@ protected Void doInBackground(Intent... intents) {
group, null);
// Update thread ID for ReadOrigInd & DeliveryInd.
ContentValues values = new ContentValues(1);
values.put("thread_id", threadId);
values.put(Telephony.Mms.THREAD_ID, threadId);
SqliteWrapper.update(mContext, cr, uri, values, null, null);
break;
}
Expand Down Expand Up @@ -132,7 +124,7 @@ protected Void doInBackground(Intent... intents) {
// Save the pdu. If we can start downloading the real pdu immediately,
// don't allow persist() to create a thread for the notificationInd
// because it causes UI jank.
Uri uri = p.persist(pdu, Uri.parse("content://mms/inbox"),
Uri uri = p.persist(pdu, Telephony.Mms.Inbox.CONTENT_URI,
!NotificationTransaction.allowAutoDownload(mContext),
group,
null);
Expand Down Expand Up @@ -212,18 +204,18 @@ private static long findThreadId(Context context, GenericPdu pdu, int type) {
}

StringBuilder sb = new StringBuilder('(');
sb.append("m_id");
sb.append(Telephony.Mms.MESSAGE_ID);
sb.append('=');
sb.append(DatabaseUtils.sqlEscapeString(messageId));
sb.append(" AND ");
sb.append("m_type");
sb.append(Telephony.Mms.MESSAGE_TYPE);
sb.append('=');
sb.append(PduHeaders.MESSAGE_TYPE_SEND_REQ);
// TODO ContentResolver.query() appends closing ')' to the selection argument
// sb.append(')');

Cursor cursor = SqliteWrapper.query(context, context.getContentResolver(),
Uri.parse("content://mms"), new String[] { "thread_id" },
Telephony.Mms.CONTENT_URI, new String[] {Telephony.Mms.THREAD_ID },
sb.toString(), null, null);
if (cursor != null) {
try {
Expand Down
8 changes: 4 additions & 4 deletions src/com/android/mms/transaction/ReadRecTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@

package com.android.mms.transaction;

import java.io.IOException;

import android.content.Context;
import android.net.Uri;
import android.provider.Telephony;
import android.util.Log;

import com.google.android.mms.MmsException;
import com.google.android.mms.pdu_alt.EncodedStringValue;
import com.google.android.mms.pdu_alt.PduComposer;
import com.google.android.mms.pdu_alt.PduPersister;
import com.google.android.mms.pdu_alt.ReadRecInd;
import com.klinker.android.send_message.Utils;

import java.io.IOException;

/**
* The ReadRecTransaction is responsible for sending read report
* notifications (M-read-rec.ind) to clients that have requested them.
Expand Down Expand Up @@ -86,7 +86,7 @@ public void run() {
byte[] postingData = new PduComposer(mContext, readRecInd).make();
sendPdu(postingData);

Uri uri = persister.move(mReadReportURI, Uri.parse("content://mms/sent"));
Uri uri = persister.move(mReadReportURI, Telephony.Mms.Sent.CONTENT_URI);
mTransactionState.setState(TransactionState.SUCCESS);
mTransactionState.setContentUri(uri);
} catch (IOException e) {
Expand Down
Loading

0 comments on commit 0dfc0d0

Please sign in to comment.