Move failed message to failed state

When we try and send a message and the telephony layer throws an
exception, move that message to the failed state. Otherwise, it
perpetually remains in the outbox and shows as "Sending..." to the
user. Bug 2885780.

Change-Id: Ic2ba789c24a9ed0842c51102c2e424ce1a2d9905
diff --git a/src/com/android/mms/transaction/SmsReceiverService.java b/src/com/android/mms/transaction/SmsReceiverService.java
index 3e2dd61..4cc86cb 100755
--- a/src/com/android/mms/transaction/SmsReceiverService.java
+++ b/src/com/android/mms/transaction/SmsReceiverService.java
@@ -235,6 +235,8 @@
                     } catch (MmsException e) {
                         Log.e(TAG, "sendFirstQueuedMessage: failed to send message " + msgUri
                                 + ", caught ", e);
+                        mSending = false;
+                        messageFailedToSend(msgUri, SmsManager.RESULT_ERROR_GENERIC_FAILURE);
                         success = false;
                     }
                 }
@@ -292,17 +294,21 @@
                 }
             });
         } else {
-            if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
-                Log.v(TAG, "handleSmsSent msg failed uri: " + uri);
-            }
-            Sms.moveMessageToFolder(this, uri, Sms.MESSAGE_TYPE_FAILED, error);
-            MessagingNotification.notifySendFailed(getApplicationContext(), true);
+            messageFailedToSend(uri, error);
             if (sendNextMsg) {
                 sendFirstQueuedMessage();
             }
         }
     }
 
+    private void messageFailedToSend(Uri uri, int error) {
+        if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
+            Log.v(TAG, "messageFailedToSend msg failed uri: " + uri);
+        }
+        Sms.moveMessageToFolder(this, uri, Sms.MESSAGE_TYPE_FAILED, error);
+        MessagingNotification.notifySendFailed(getApplicationContext(), true);
+    }
+
     private void handleSmsReceived(Intent intent, int error) {
         SmsMessage[] msgs = Intents.getMessagesFromIntent(intent);
         Uri messageUri = insertMessage(this, msgs, error);