OSDN Git Service

MAP: Fix possible NullPointerException while GetMessagesListing
authorHemant Gupta <hemantg@codeaurora.org>
Wed, 22 Apr 2015 12:38:10 +0000 (18:08 +0530)
committerHemant Gupta <hemantg@codeaurora.org>
Wed, 29 Apr 2015 10:31:50 +0000 (16:01 +0530)
Fix possible NullPointerException while processing GetMessagesListing
on a MSE without a valid SIM , case wherein invalid  messageType value
occurs on MAP SMS/MMS Instance. Now by default SMS type is set to GSM.

Following basic PTS test cases and also other PTS cases dependent on
GetMessagesListing functionality fail without this fix:
TC_MSE_MMB_BV_11_I
TC_MSE_MMB_BV_20_I
TC_MSE_MMU_BV_02_I

Change-Id: I8ed0a2787534159342af88ec413a1c0407961d91

src/com/android/bluetooth/map/BluetoothMapContent.java
src/com/android/bluetooth/map/BluetoothMapContentObserver.java
src/com/android/bluetooth/map/BluetoothMapMessageListingElement.java
src/com/android/bluetooth/map/BluetoothMapUtils.java [changed mode: 0644->0755]

index dfc10f0..4970254 100644 (file)
@@ -712,11 +712,13 @@ public class BluetoothMapContent {
 
     private TYPE getType(Cursor c, FilterInfo fi) {
         TYPE type = null;
+        if (V) Log.d(TAG, "getType: for filterMsgType" + fi.mMsgType);
         if (fi.mMsgType == FilterInfo.TYPE_SMS) {
-            if (fi.mPhoneType == TelephonyManager.PHONE_TYPE_GSM) {
-                type = TYPE.SMS_GSM;
-            } else if (fi.mPhoneType == TelephonyManager.PHONE_TYPE_CDMA) {
+            if (V) Log.d(TAG, "getType: phoneType for SMS " + fi.mPhoneType);
+            if (fi.mPhoneType == TelephonyManager.PHONE_TYPE_CDMA) {
                 type = TYPE.SMS_CDMA;
+            } else {
+                type = TYPE.SMS_GSM;
             }
         } else if (fi.mMsgType == FilterInfo.TYPE_MMS) {
             type = TYPE.MMS;
@@ -2175,17 +2177,21 @@ public class BluetoothMapContent {
             Cursor tmpCursor = null;
             for(int x=0;x<listSize;x++){
                 BluetoothMapMessageListingElement ele = list.get(x);
-                if((ele.getType().equals(TYPE.SMS_GSM)||ele.getType().equals(TYPE.SMS_CDMA))
-                        && smsCursor != null){
+                /* If OBEX "GET" request header includes "ParameterMask" with 'Type' NOT set,
+                 * then ele.getType() returns "null" even for a valid cursor.
+                 * Avoid NullPointerException in equals() check when 'mType' value is "null" */
+                TYPE tmpType = ele.getType();
+                if (smsCursor!= null &&
+                        ((TYPE.SMS_GSM).equals(tmpType) || (TYPE.SMS_CDMA).equals(tmpType))) {
                     tmpCursor = smsCursor;
                     fi.mMsgType = FilterInfo.TYPE_SMS;
-                }else if(ele.getType().equals(TYPE.MMS) && mmsCursor != null){
+                } else if(mmsCursor != null && (TYPE.MMS).equals(tmpType)) {
                     tmpCursor = mmsCursor;
                     fi.mMsgType = FilterInfo.TYPE_MMS;
-                }else if(ele.getType().equals(TYPE.EMAIL) && emailCursor != null){
+                } else if(emailCursor != null && ((TYPE.EMAIL).equals(tmpType))) {
                     tmpCursor = emailCursor;
                     fi.mMsgType = FilterInfo.TYPE_EMAIL;
-                }else if(ele.getType().equals(TYPE.IM) && imCursor != null){
+                } else if(imCursor != null && ((TYPE.IM).equals(tmpType))) {
                     tmpCursor = imCursor;
                     fi.mMsgType = FilterInfo.TYPE_IM;
                 }
index 5ad1b55..6a2b0a9 100644 (file)
@@ -435,10 +435,10 @@ public class BluetoothMapContentObserver {
         TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
                 Context.TELEPHONY_SERVICE);
 
-        if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
-            smsType = TYPE.SMS_GSM;
-        } else if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
+        if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
             smsType = TYPE.SMS_CDMA;
+        } else {
+            smsType = TYPE.SMS_GSM;
         }
 
         return smsType;
@@ -729,8 +729,12 @@ public class BluetoothMapContentObserver {
                 if (oldFolder != null) {
                     xmlEvtReport.attribute("", "old_folder", oldFolder);
                 }
-                xmlEvtReport.attribute("", "msg_type", msgType.name());
-
+                /* Avoid possible NPE for "msgType" "null" value. "msgType"
+                 * is a implied attribute and will be set "null" for events
+                 * like "memory full" or "memory available" */
+                if (msgType != null) {
+                    xmlEvtReport.attribute("", "msg_type", msgType.name());
+                }
                 /* If MAP event report version is above 1.0 send
                  * extended event report parameters */
                 if (datetime != null) {
index ec4005b..2d234d5 100644 (file)
@@ -294,7 +294,8 @@ public class BluetoothMapMessageListingElement
                         BluetoothMapUtils.stripInvalidChars(mRecipientName));
             if(mRecipientAddressing != null)
                 xmlMsgElement.attribute(null, "recipient_addressing", mRecipientAddressing);
-            if(mMsgTypeAppParamSet == true)
+            /* Avoid NPE for possible "null" value of mType */
+            if(mMsgTypeAppParamSet == true && mType != null)
                 xmlMsgElement.attribute(null, "type", mType.name());
             if(mSize != -1)
                 xmlMsgElement.attribute(null, "size", Integer.toString(mSize));
old mode 100644 (file)
new mode 100755 (executable)
index f76831e..66ceecc
@@ -251,25 +251,32 @@ public class BluetoothMapUtils {
      */
     public static String getMapHandle(long cpHandle, TYPE messageType){
         String mapHandle = "-1";
-        switch(messageType)
-        {
-            case MMS:
-                mapHandle = getLongAsString(cpHandle | HANDLE_TYPE_MMS_MASK);
-                break;
-            case SMS_GSM:
-                mapHandle = getLongAsString(cpHandle | HANDLE_TYPE_SMS_GSM_MASK);
-                break;
-            case SMS_CDMA:
-                mapHandle = getLongAsString(cpHandle | HANDLE_TYPE_SMS_CDMA_MASK);
-                break;
-            case EMAIL:
-                mapHandle = getLongAsString(cpHandle | HANDLE_TYPE_EMAIL_MASK);
-                break;
-            case IM:
-                mapHandle = getLongAsString(cpHandle | HANDLE_TYPE_IM_MASK);
-                break;
-            default:
-                throw new IllegalArgumentException("Message type not supported");
+        /* Avoid NPE for possible "null" value of messageType */
+        if(messageType != null) {
+            switch(messageType)
+            {
+                case MMS:
+                    mapHandle = getLongAsString(cpHandle | HANDLE_TYPE_MMS_MASK);
+                    break;
+                case SMS_GSM:
+                    mapHandle = getLongAsString(cpHandle | HANDLE_TYPE_SMS_GSM_MASK);
+                    break;
+                case SMS_CDMA:
+                    mapHandle = getLongAsString(cpHandle | HANDLE_TYPE_SMS_CDMA_MASK);
+                    break;
+                case EMAIL:
+                    mapHandle = getLongAsString(cpHandle | HANDLE_TYPE_EMAIL_MASK);
+                    break;
+                case IM:
+                    mapHandle = getLongAsString(cpHandle | HANDLE_TYPE_IM_MASK);
+                    break;
+                case NONE:
+                    break;
+                default:
+                    throw new IllegalArgumentException("Message type not supported");
+            }
+        } else {
+            if(D)Log.e(TAG," Invalid messageType input");
         }
         return mapHandle;