Wake up TransactService when MMS data is available

In 2G network, mobile data is suspend during voice
call. MMS data will be notified as unavailable.
After voice call is end, It may notify Default data
connection before MMS data connection. When it
notify Default connection, it is unavailable in
MMS networkInfo and TransactionService will not
launch transaction; When it nofity MMS connection,
it is not connected so it will not wake up
Transaction Service.

How to reproduce:
1) Make a voice call in 2G network;
2) Try to send a MMS during voice call;
3) MMS is sending and waiting for data connection;
4) Hang up the voice call;
5) MMS stays in Sending state.

Change-Id: Ia719e8736cc6ccfcd236bceea4cb94f7c4dd94e5
Signed-off-by: Bin Li <libin@marvell.com>
diff --git a/src/com/android/mms/transaction/MmsSystemEventReceiver.java b/src/com/android/mms/transaction/MmsSystemEventReceiver.java
index b8eb917..0913105 100644
--- a/src/com/android/mms/transaction/MmsSystemEventReceiver.java
+++ b/src/com/android/mms/transaction/MmsSystemEventReceiver.java
@@ -64,13 +64,17 @@
             Uri changed = (Uri) intent.getParcelableExtra(Mms.Intents.DELETED_CONTENTS);
             MmsApp.getApplication().getPduLoaderManager().removePdu(changed);
         } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
-            String state = intent.getStringExtra(PhoneConstants.STATE_KEY);
+            String apnType = intent.getStringExtra(PhoneConstants.DATA_APN_TYPE_KEY);
+            boolean available = !(intent.getBooleanExtra(
+                                      PhoneConstants.NETWORK_UNAVAILABLE_KEY, false));
 
             if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
-                Log.v(TAG, "ANY_DATA_STATE event received: " + state);
+                Log.v(TAG, "ANY_DATA_STATE event received: apnType = " + apnType +
+                           ", available = " + available);
             }
 
-            if (state.equals("CONNECTED")) {
+            // Wake up transact service when MMS data is available.
+            if (apnType.equals(PhoneConstants.APN_TYPE_MMS) && available) {
                 wakeUpService(context);
             }
         } else if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
diff --git a/src/com/android/mms/transaction/TransactionService.java b/src/com/android/mms/transaction/TransactionService.java
index 7fd2715..4230b16 100644
--- a/src/com/android/mms/transaction/TransactionService.java
+++ b/src/com/android/mms/transaction/TransactionService.java
@@ -236,6 +236,10 @@
                         }
                         MmsSystemEventReceiver.registerForConnectionStateChanges(
                                 getApplicationContext());
+                    } else {
+                        // MMS data is available now, do not need listen to state change.
+                        MmsSystemEventReceiver.unRegisterForConnectionStateChanges(
+                                getApplicationContext());
                     }
 
                     while (cursor.moveToNext()) {