From 29d06af0e5436b51213b297e76d8b13399f6e55f Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sat, 13 Jan 2018 18:45:26 -0500 Subject: [PATCH] Strip out unused logic in android-smsmms --- .../android/mms/service_alt/MmsConfig.java | 15 +- .../mms/transaction/DownloadManager.java | 6 - .../transaction/MmsSystemEventReceiver.java | 7 - .../android/mms/transaction/PushReceiver.java | 86 ++-------- .../mms/transaction/TransactionService.java | 151 ++---------------- .../android/send_message/Settings.java | 21 --- .../android/send_message/Transaction.java | 22 +-- .../klinker/android/send_message/Utils.java | 5 +- qksms/src/main/java/interactor/SendMessage.kt | 1 - 9 files changed, 36 insertions(+), 278 deletions(-) diff --git a/android-smsmms/src/main/java/com/android/mms/service_alt/MmsConfig.java b/android-smsmms/src/main/java/com/android/mms/service_alt/MmsConfig.java index faa30c9e..03d9a24f 100755 --- a/android-smsmms/src/main/java/com/android/mms/service_alt/MmsConfig.java +++ b/android-smsmms/src/main/java/com/android/mms/service_alt/MmsConfig.java @@ -338,16 +338,11 @@ public class MmsConfig { final TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - mUserAgent = telephonyManager.getMmsUserAgent(); - mUaProfUrl = telephonyManager.getMmsUAProfUrl(); - // defaults for nexus 6, seems to work well. - //mUserAgent = "nexus6"; - //mUaProfUrl = "http://uaprof.motorola.com/phoneconfig/nexus6/Profile/nexus6.rdf"; - } else { - mUserAgent = "Android Messaging"; - mUaProfUrl = "http://www.gstatic.com/android/hangouts/hangouts_mms_ua_profile.xml"; - } + mUserAgent = telephonyManager.getMmsUserAgent(); + mUaProfUrl = telephonyManager.getMmsUAProfUrl(); + // defaults for nexus 6, seems to work well. + //mUserAgent = "nexus6"; + //mUaProfUrl = "http://uaprof.motorola.com/phoneconfig/nexus6/Profile/nexus6.rdf"; } private void loadFromResources(Context context) { diff --git a/android-smsmms/src/main/java/com/android/mms/transaction/DownloadManager.java b/android-smsmms/src/main/java/com/android/mms/transaction/DownloadManager.java index 36c5fac2..9c7c229b 100755 --- a/android-smsmms/src/main/java/com/android/mms/transaction/DownloadManager.java +++ b/android-smsmms/src/main/java/com/android/mms/transaction/DownloadManager.java @@ -10,13 +10,11 @@ import android.content.IntentFilter; import android.database.Cursor; import android.database.sqlite.SqliteWrapper; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.os.PowerManager; import android.provider.Telephony; import android.telephony.SmsManager; import android.text.TextUtils; - import com.android.mms.MmsConfig; import com.klinker.android.logger.Log; import com.klinker.android.send_message.BroadcastUtils; @@ -122,10 +120,6 @@ public class DownloadManager { } private static boolean isNotificationExist(Context context, String location) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - return true; - } - String selection = Telephony.Mms.CONTENT_LOCATION + " = ?"; String[] selectionArgs = new String[] { location }; Cursor c = SqliteWrapper.query( diff --git a/android-smsmms/src/main/java/com/android/mms/transaction/MmsSystemEventReceiver.java b/android-smsmms/src/main/java/com/android/mms/transaction/MmsSystemEventReceiver.java index b7c4efb9..2b237657 100755 --- a/android-smsmms/src/main/java/com/android/mms/transaction/MmsSystemEventReceiver.java +++ b/android-smsmms/src/main/java/com/android/mms/transaction/MmsSystemEventReceiver.java @@ -43,13 +43,6 @@ public class MmsSystemEventReceiver extends BroadcastReceiver { private static ConnectivityManager mConnMgr = null; public static void wakeUpService(Context context) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) { - Log.v(TAG, "wakeUpService: start transaction service ..."); - } - - context.startService(new Intent(context, TransactionService.class)); - } } @Override diff --git a/android-smsmms/src/main/java/com/android/mms/transaction/PushReceiver.java b/android-smsmms/src/main/java/com/android/mms/transaction/PushReceiver.java index 9e4d28c2..27d17785 100755 --- a/android-smsmms/src/main/java/com/android/mms/transaction/PushReceiver.java +++ b/android-smsmms/src/main/java/com/android/mms/transaction/PushReceiver.java @@ -27,17 +27,12 @@ import android.database.DatabaseUtils; import android.database.sqlite.SqliteWrapper; import android.net.Uri; import android.os.AsyncTask; -import android.os.Build; import android.os.PowerManager; import android.preference.PreferenceManager; import android.provider.Telephony.Mms; import android.provider.Telephony.Mms.Inbox; - -import com.android.mms.logs.LogTag; import com.android.mms.MmsConfig; -import com.android.mms.service_alt.DownloadRequest; -import com.android.mms.service_alt.MmsNetworkManager; -import com.android.mms.service_alt.MmsRequestManager; +import com.android.mms.logs.LogTag; import com.google.android.mms.ContentType; import com.google.android.mms.MmsException; import com.google.android.mms.pdu_alt.DeliveryInd; @@ -48,8 +43,6 @@ 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.klinker.android.logger.Log; -import com.klinker.android.send_message.BroadcastUtils; -import com.klinker.android.send_message.Utils; import java.util.HashSet; import java.util.Set; @@ -176,49 +169,9 @@ public class PushReceiver extends BroadcastReceiver { downloadedUrls.add(location); } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - Log.v(TAG, "receiving on a lollipop+ device"); - boolean useSystem = true; + Log.v(TAG, "receiving on a lollipop+ device"); - if (com.klinker.android.send_message.Transaction.settings != null) { - useSystem = com.klinker.android.send_message.Transaction.settings - .getUseSystemSending(); - } else { - useSystem = PreferenceManager.getDefaultSharedPreferences(mContext) - .getBoolean("system_mms_sending", useSystem); - } - - if (useSystem) { - DownloadManager.getInstance().downloadMultimediaMessage(mContext, location, uri, true); - } else { - Log.v(TAG, "receiving with lollipop method"); - MmsRequestManager requestManager = new MmsRequestManager(mContext); - DownloadRequest request = new DownloadRequest(requestManager, - Utils.getDefaultSubscriptionId(), - location, uri, null, null, - null, mContext); - MmsNetworkManager manager = new MmsNetworkManager(mContext, Utils.getDefaultSubscriptionId()); - request.execute(mContext, manager); - } - } else { - if (NotificationTransaction.allowAutoDownload(mContext)) { - // Start service to finish the notification transaction. - Intent svc = new Intent(mContext, TransactionService.class); - svc.putExtra(TransactionBundle.URI, uri.toString()); - svc.putExtra(TransactionBundle.TRANSACTION_TYPE, - Transaction.NOTIFICATION_TRANSACTION); - svc.putExtra(TransactionBundle.LOLLIPOP_RECEIVING, - Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP); - mContext.startService(svc); - } else { - Intent notificationBroadcast = new Intent(com.klinker.android.send_message.Transaction.NOTIFY_OF_MMS); - notificationBroadcast.putExtra("receive_through_stock", true); - BroadcastUtils.sendExplicitBroadcast( - mContext, - notificationBroadcast, - com.klinker.android.send_message.Transaction.NOTIFY_OF_MMS); - } - } + DownloadManager.getInstance().downloadMultimediaMessage(mContext, location, uri, true); } else if (LOCAL_LOGV) { Log.v(TAG, "Skip downloading duplicate message: " + new String(nInd.getContentLocation())); @@ -252,31 +205,18 @@ public class PushReceiver extends BroadcastReceiver { } SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); - if ((!sharedPrefs.getBoolean("receive_with_stock", false) && Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT && sharedPrefs.getBoolean("override", true)) - || Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - // Hold a wake lock for 5 seconds, enough to give any - // services we start time to take their own wake locks. - PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); - PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, - "MMS PushReceiver"); - wl.acquire(5000); - MmsConfig.init(context); - new ReceivePushTask(context).executeOnExecutor(PUSH_RECEIVER_EXECUTOR, intent); + // Hold a wake lock for 5 seconds, enough to give any + // services we start time to take their own wake locks. + PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); + PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, + "MMS PushReceiver"); + wl.acquire(5000); + MmsConfig.init(context); + new ReceivePushTask(context).executeOnExecutor(PUSH_RECEIVER_EXECUTOR, intent); - Log.v("mms_receiver", context.getPackageName() + " received and aborted"); + Log.v("mms_receiver", context.getPackageName() + " received and aborted"); - abortBroadcast(); - } else { - clearAbortBroadcast(); - Intent notificationBroadcast = new Intent(com.klinker.android.send_message.Transaction.NOTIFY_OF_MMS); - notificationBroadcast.putExtra("receive_through_stock", true); - BroadcastUtils.sendExplicitBroadcast( - context, - notificationBroadcast, - com.klinker.android.send_message.Transaction.NOTIFY_OF_MMS); - - Log.v("mms_receiver", context.getPackageName() + " received and not aborted"); - } + abortBroadcast(); } } diff --git a/android-smsmms/src/main/java/com/android/mms/transaction/TransactionService.java b/android-smsmms/src/main/java/com/android/mms/transaction/TransactionService.java index 2177f74f..fb3cc07b 100755 --- a/android-smsmms/src/main/java/com/android/mms/transaction/TransactionService.java +++ b/android-smsmms/src/main/java/com/android/mms/transaction/TransactionService.java @@ -309,121 +309,16 @@ public class TransactionService extends Service implements Observer { int msgType = cursor.getInt(columnIndexOfMsgType); int transactionType = getTransactionType(msgType); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - boolean useSystem = true; - if (com.klinker.android.send_message.Transaction.settings != null) { - useSystem = com.klinker.android.send_message.Transaction.settings - .getUseSystemSending(); - } else { - useSystem = PreferenceManager.getDefaultSharedPreferences(this) - .getBoolean("system_mms_sending", useSystem); - } + try { + Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, + cursor.getLong(columnIndexOfMsgId)); + com.android.mms.transaction.DownloadManager.getInstance(). + downloadMultimediaMessage(this, PushReceiver.getContentLocation(this, uri), uri, false); - if (useSystem) { - try { - Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, - cursor.getLong(columnIndexOfMsgId)); - com.android.mms.transaction.DownloadManager.getInstance(). - downloadMultimediaMessage(this, PushReceiver.getContentLocation(this, uri), uri, false); - - // can't handle many messages at once. - break; - } catch (MmsException e) { - e.printStackTrace(); - } - } else { - try { - Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, - cursor.getLong(columnIndexOfMsgId)); - MmsRequestManager requestManager = new MmsRequestManager(this); - DownloadRequest request = new DownloadRequest(requestManager, - Utils.getDefaultSubscriptionId(), - PushReceiver.getContentLocation(this, uri), uri, null, null, - null, this); - MmsNetworkManager manager = new MmsNetworkManager(this, Utils.getDefaultSubscriptionId()); - request.execute(this, manager); - - // can't handle many messages at once. - break; - } catch (Exception e) { - e.printStackTrace(); - } - } - continue; - } - - if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) { - Log.v(TAG, "onNewIntent: msgType=" + msgType + " transactionType=" + - transactionType); - } - if (noNetwork) { - onNetworkUnavailable(serviceId, transactionType); - return; - } - switch (transactionType) { - case -1: - break; - case Transaction.RETRIEVE_TRANSACTION: - // If it's a transiently failed transaction, - // we should retry it in spite of current - // downloading mode. If the user just turned on the auto-retrieve - // option, we also retry those messages that don't have any errors. - int failureType = cursor.getInt( - cursor.getColumnIndexOrThrow( - PendingMessages.ERROR_TYPE)); - try { - DownloadManager.init(this); - DownloadManager downloadManager = DownloadManager.getInstance(); - boolean autoDownload = downloadManager.isAuto(); - if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) { - Log.v(TAG, "onNewIntent: failureType=" + failureType + - " action=" + action + " isTransientFailure:" + - isTransientFailure(failureType) + " autoDownload=" + - autoDownload); - } - if (!autoDownload) { - // If autodownload is turned off, don't process the - // transaction. - if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) { - Log.v(TAG, "onNewIntent: skipping - autodownload off"); - } - // Re-enable "download" button if auto-download is off - Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, - cursor.getLong(columnIndexOfMsgId)); - downloadManager.markState(uri, - DownloadManager.STATE_SKIP_RETRYING); - break; - } - } catch (Exception e) { - e.printStackTrace(); - } - - // Logic is twisty. If there's no failure or the failure - // is a non-permanent failure, we want to process the transaction. - // Otherwise, break out and skip processing this transaction. - if (!(failureType == MmsSms.NO_ERROR || - isTransientFailure(failureType))) { - if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) { - Log.v(TAG, "onNewIntent: skipping - permanent error"); - } - break; - } - if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) { - Log.v(TAG, "onNewIntent: falling through and processing"); - } - // fall-through - default: - Uri uri = ContentUris.withAppendedId( - Mms.CONTENT_URI, - cursor.getLong(columnIndexOfMsgId)); - TransactionBundle args = new TransactionBundle( - transactionType, uri.toString()); - // FIXME: We use the same startId for all MMs. - if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) { - Log.v(TAG, "onNewIntent: launchTransaction uri=" + uri); - } - launchTransaction(serviceId, args, false); - break; + // can't handle many messages at once. + break; + } catch (MmsException e) { + e.printStackTrace(); } } } finally { @@ -847,29 +742,13 @@ public class TransactionService extends Service implements Observer { TransactionService.this, serviceId, transactionSettings, args.getUri()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - Uri u = Uri.parse(args.getUri()); - com.android.mms.transaction.DownloadManager.getInstance(). - downloadMultimediaMessage(TransactionService.this, - ((RetrieveTransaction) transaction).getContentLocation(TransactionService.this, u), u, false); - return; - } - - break; - case Transaction.SEND_TRANSACTION: - transaction = new SendTransaction( - TransactionService.this, serviceId, - transactionSettings, args.getUri()); - break; - case Transaction.READREC_TRANSACTION: - transaction = new ReadRecTransaction( - TransactionService.this, serviceId, - transactionSettings, args.getUri()); - break; - default: - Log.w(TAG, "Invalid transaction type: " + serviceId); - transaction = null; + Uri u = Uri.parse(args.getUri()); + com.android.mms.transaction.DownloadManager.getInstance(). + downloadMultimediaMessage(TransactionService.this, + ((RetrieveTransaction) transaction).getContentLocation(TransactionService.this, u), u, false); return; + + } if (!processTransaction(transaction)) { diff --git a/android-smsmms/src/main/java/com/klinker/android/send_message/Settings.java b/android-smsmms/src/main/java/com/klinker/android/send_message/Settings.java index 95637cba..e852e4bf 100755 --- a/android-smsmms/src/main/java/com/klinker/android/send_message/Settings.java +++ b/android-smsmms/src/main/java/com/klinker/android/send_message/Settings.java @@ -36,7 +36,6 @@ public class Settings { private String uaProfUrl; private String uaProfTagName; private boolean group; - private boolean useSystemSending; // SMS options private boolean deliveryReports; @@ -114,7 +113,6 @@ public class Settings { this.preText = preText; this.sendLongAsMms = sendLongAsMms; this.sendLongAsMmsAfter = sendLongAsMmsAfter; - setUseSystemSending(useSystemSending); this.subscriptionId = subscriptionId != null ? subscriptionId : DEFAULT_SUBSCRIPTION_ID; } @@ -248,18 +246,6 @@ public class Settings { this.sendLongAsMmsAfter = sendLongAsMmsAfter; } - /** - * @param useSystemSending whether or not to use the system sending method on Lollipop+ devices - */ - public void setUseSystemSending(boolean useSystemSending) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - this.useSystemSending = useSystemSending; - } else { - this.useSystemSending = false; - Log.e("Settings", "System sending only available on Lollipop+ devices"); - } - } - /** * Set the subscription ID that should be used for sending. It isn't applied to receiving at this time. * @@ -373,13 +359,6 @@ public class Settings { return this.sendLongAsMmsAfter; } - /** - * @return whether or not to use the system sending method on Lollipop+ devices - */ - public boolean getUseSystemSending() { - return useSystemSending; - } - /** * @return the subscription ID or the default if one isn't set. */ diff --git a/android-smsmms/src/main/java/com/klinker/android/send_message/Transaction.java b/android-smsmms/src/main/java/com/klinker/android/send_message/Transaction.java index 45efda4c..b531bc4d 100755 --- a/android-smsmms/src/main/java/com/klinker/android/send_message/Transaction.java +++ b/android-smsmms/src/main/java/com/klinker/android/send_message/Transaction.java @@ -33,9 +33,6 @@ import android.text.TextUtils; import android.widget.Toast; import com.android.mms.MmsConfig; import com.android.mms.dom.smil.parser.SmilXmlSerializer; -import com.android.mms.service_alt.MmsNetworkManager; -import com.android.mms.service_alt.MmsRequestManager; -import com.android.mms.service_alt.SendRequest; import com.android.mms.util.DownloadManager; import com.android.mms.util.RateController; import com.google.android.mms.ContentType; @@ -393,23 +390,8 @@ public class Transaction { } Log.v(TAG, "using lollipop method for sending sms"); - - if (settings.getUseSystemSending()) { - Log.v(TAG, "using system method for sending"); - sendMmsThroughSystem(context, subject, data, addresses, explicitSentMmsReceiver); - } else { - try { - MessageInfo info = getBytes(context, saveMessage, address.toString().split(" "), - data.toArray(new MMSPart[data.size()]), subject); - MmsRequestManager requestManager = new MmsRequestManager(context, info.bytes); - SendRequest request = new SendRequest(requestManager, Utils.getDefaultSubscriptionId(), - info.location, null, null, null, null); - MmsNetworkManager manager = new MmsNetworkManager(context, Utils.getDefaultSubscriptionId()); - request.execute(context, manager); - } catch (Exception e) { - Log.e(TAG, "error sending mms", e); - } - } + Log.v(TAG, "using system method for sending"); + sendMmsThroughSystem(context, subject, data, addresses, explicitSentMmsReceiver); } public static MessageInfo getBytes(Context context, boolean saveMessage, String[] recipients, diff --git a/android-smsmms/src/main/java/com/klinker/android/send_message/Utils.java b/android-smsmms/src/main/java/com/klinker/android/send_message/Utils.java index cf85c4e6..e05265c7 100755 --- a/android-smsmms/src/main/java/com/klinker/android/send_message/Utils.java +++ b/android-smsmms/src/main/java/com/klinker/android/send_message/Utils.java @@ -64,11 +64,8 @@ public class Utils { public static T ensureRouteToMmsNetwork(Context context, String url, String proxy, Task task) throws IOException { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return ensureRouteToMmsNetworkMarshmallow(context, task); - } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - return ensureRouteToMmsNetworkLollipop(context, task); } else { - ensureRouteToHost(context, url, proxy); - return task.run(); + return ensureRouteToMmsNetworkLollipop(context, task); } } diff --git a/qksms/src/main/java/interactor/SendMessage.kt b/qksms/src/main/java/interactor/SendMessage.kt index a4b8868b..a951e93a 100644 --- a/qksms/src/main/java/interactor/SendMessage.kt +++ b/qksms/src/main/java/interactor/SendMessage.kt @@ -75,7 +75,6 @@ class SendMessage @Inject constructor( private fun sendMms(threadId: Long, addresses: List, body: String, attachments: List) { val settings = Settings().apply { - useSystemSending = true group = true }