Strip out unused logic in android-smsmms

This commit is contained in:
Moez Bhatti
2018-01-13 18:45:26 -05:00
parent a6d5aa54a5
commit 29d06af0e5
9 changed files with 36 additions and 278 deletions
@@ -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) {
@@ -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(
@@ -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
@@ -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();
}
}
@@ -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)) {