diff options
author | Ashwini Munigala <AshwiniM@codeaurora.org> | 2014-10-16 17:27:36 +0530 |
---|---|---|
committer | Linux Build Service Account <lnxbuild@localhost> | 2014-11-04 08:26:29 -0700 |
commit | c5409061deff70381b75681beed3c90c6dac6670 (patch) | |
tree | 7c1bf051d919d29677a9494b27ed2d3261faa735 /src/com/android/bluetooth/map | |
parent | aac988ce6f02bbb3f34ac59acc36b386a45ac8e5 (diff) | |
download | android_packages_apps_Bluetooth-c5409061deff70381b75681beed3c90c6dac6670.tar.gz android_packages_apps_Bluetooth-c5409061deff70381b75681beed3c90c6dac6670.tar.bz2 android_packages_apps_Bluetooth-c5409061deff70381b75681beed3c90c6dac6670.zip |
MAP: Fix KW Issues for MAP.
Modifications to fix KW P1 or
critical issues captured from KlocWork.
Change-Id: Ie7100907513147f0d743b579998a16880ebf734f
CRs-fixed: 739477
Diffstat (limited to 'src/com/android/bluetooth/map')
8 files changed, 104 insertions, 44 deletions
diff --git a/src/com/android/bluetooth/map/BluetoothMapContent.java b/src/com/android/bluetooth/map/BluetoothMapContent.java index d60fb4af0..63ac86ee5 100644 --- a/src/com/android/bluetooth/map/BluetoothMapContent.java +++ b/src/com/android/bluetooth/map/BluetoothMapContent.java @@ -291,6 +291,7 @@ public class BluetoothMapContent { } } while(c.moveToNext()); + c.close(); } } @@ -355,6 +356,7 @@ public class BluetoothMapContent { /* printMmsPartImage(partid); */ /* } */ } while(c.moveToNext()); + c.close(); } } @@ -460,22 +462,30 @@ public class BluetoothMapContent { dumpMmsTable(); BluetoothMapAppParams ap = buildAppParams(); - if (D) Log.d(TAG, "message listing size = " + msgListingSize("inbox", ap)); - BluetoothMapMessageListing mList = msgListing("inbox", ap); - try { - mList.encode(); - } catch (UnsupportedEncodingException ex) { - /* do nothing */ - } - mList = msgListing("sent", ap); - try { - mList.encode(); - } catch (UnsupportedEncodingException ex) { - /* do nothing */ + if(ap != null ){ + if (D) Log.d(TAG, "message listing size = " + msgListingSize("inbox", ap)); + BluetoothMapMessageListing mList = msgListing("inbox", ap); + try { + mList.encode(); + } catch (UnsupportedEncodingException ex) { + /* do nothing */ + } + mList = msgListing("sent", ap); + try { + mList.encode(); + } catch (UnsupportedEncodingException ex) { + /* do nothing */ + } + } else { + if (D) Log.d(TAG, "dumPMessage AppParams not available "); } } public static String decodeEncodedWord(String checkEncoded) { + if (checkEncoded == null) { + if(V) Log.v(TAG, " Decode Invalid Input"); + return null; + } if (checkEncoded != null && (checkEncoded.contains("=?") == false)) { if(V) Log.v(TAG, " Decode NotRequired" + checkEncoded); return checkEncoded; @@ -1047,7 +1057,8 @@ public class BluetoothMapContent { } else { type = TYPE.EMAIL; } - if (D) Log.d(TAG, "setHandle: " + handle + " - Type: " + type.name()); + if (D && type != null) + Log.d(TAG, "setHandle: " + handle + " - Type: " + type.name()); e.setHandle(handle, type); } @@ -1905,11 +1916,11 @@ public class BluetoothMapContent { Log.v(TAG, " recepientStr[1] " + recepientStr[1].trim()); Log.v(TAG, " recepientStr[0] " + recepientStr[0].trim()); } - } else if(recipientName.contains("")){ - multiRecepients = recipientName.replace('', ';'); setVCardFromEmailAddress(message, recepientStr[1].trim(), false); message.addCc(recepientStr[1].trim(), recepientStr[0].trim()); } + } else if(recipientName.contains("")){ + multiRecepients = recipientName.replace('', ';'); if(multiRecepients != null){ if (V){ Log.v(TAG, " Setting ::Recepient name :: " + multiRecepients.trim()); @@ -1950,6 +1961,7 @@ public class BluetoothMapContent { } } } + c.close(); } } @@ -1970,8 +1982,10 @@ public class BluetoothMapContent { try { is = mResolver.openInputStream(uriAddress); int len = 0; - while ((len = is.read(buffer)) != -1) { - os.write(buffer, 0, len); // We need to specify the len, as it can be != bufferSize + if ((is != null) && (os != null)) { + while ((len = is.read(buffer)) != -1) { + os.write(buffer, 0, len); // We need to specify the len, as it can be != bufferSize + } } retVal = os.toByteArray(); } catch (IOException e) { @@ -1980,7 +1994,8 @@ public class BluetoothMapContent { } finally { try { os.close(); - is.close(); + if(is != null) + is.close(); } catch (IOException e) { } } @@ -2065,7 +2080,12 @@ public class BluetoothMapContent { } catch (NullPointerException e) { if(V) Log.w(TAG, e); } - String msgBody = readEmailBodyForMessageFd(fd); + String msgBody = null ; + if(fd != null ) { + msgBody = readEmailBodyForMessageFd(fd); + } else { + Log.w(TAG, " FETCH Email BODY File HTML URI FAILED"); + } if (msgBody != null) { msgBody = msgBody.replaceAll("(?s)(<title>)(.*?)(</title>)", ""); msgBody = msgBody.replaceAll("(?s)(<style type=\"text/css\".*?>)(.*?)(</style>)", ""); @@ -2469,6 +2489,9 @@ public class BluetoothMapContent { public byte[] getMessage(String handle, BluetoothMapAppParams appParams) throws UnsupportedEncodingException{ TYPE type = BluetoothMapUtils.getMsgTypeFromHandle(handle); long id = BluetoothMapUtils.getCpHandle(handle); + if(appParams == null){ + throw new IllegalArgumentException("Invalid No appParams Charset"); + } switch(type) { case SMS_GSM: case SMS_CDMA: @@ -2599,6 +2622,9 @@ public class BluetoothMapContent { message.setType(TYPE.SMS_GSM); } else if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) { message.setType(TYPE.SMS_CDMA); + } else { + // set SMS_GSM by default + message.setType(TYPE.SMS_GSM); } String read = c.getString(c.getColumnIndex(Sms.READ)); @@ -2672,6 +2698,7 @@ public class BluetoothMapContent { break; } } while(c.moveToNext()); + c.close(); } } @@ -2709,9 +2736,9 @@ public class BluetoothMapContent { } finally { try { if (os !=null) - os.close(); + os.close(); if (is!=null) - is.close(); + is.close(); } catch (IOException e) { } } @@ -2791,6 +2818,7 @@ public class BluetoothMapContent { } part.fileName = filename; } while(c.moveToNext()); + c.close(); } message.updateCharset(); } diff --git a/src/com/android/bluetooth/map/BluetoothMapContentEmailObserver.java b/src/com/android/bluetooth/map/BluetoothMapContentEmailObserver.java index 42208f634..f0e73dcc8 100644 --- a/src/com/android/bluetooth/map/BluetoothMapContentEmailObserver.java +++ b/src/com/android/bluetooth/map/BluetoothMapContentEmailObserver.java @@ -172,8 +172,9 @@ public class BluetoothMapContentEmailObserver extends BluetoothMapContentObserve @Override public void onChange(boolean selfChange, Uri uri) { - if (V) Log.v(TAG, "onChange on thread: " + Thread.currentThread().getId() - + " Uri: " + uri.toString() + " selfchange: " + selfChange); + if (V && uri!= null) + Log.v(TAG, "onChange on thread: " + Thread.currentThread().getId() + + " Uri: " + uri.toString() + " selfchange: " + selfChange); if (mHandler.hasMessages(UPDATE)) { mHandler.removeMessages(UPDATE); diff --git a/src/com/android/bluetooth/map/BluetoothMapContentObserver.java b/src/com/android/bluetooth/map/BluetoothMapContentObserver.java index 2c4f2cbb3..3186f27ee 100644 --- a/src/com/android/bluetooth/map/BluetoothMapContentObserver.java +++ b/src/com/android/bluetooth/map/BluetoothMapContentObserver.java @@ -140,8 +140,9 @@ public class BluetoothMapContentObserver { @Override public void onChange(boolean selfChange, Uri uri) { - if (V) Log.d(TAG, "onChange on thread: " + Thread.currentThread().getId() - + " Uri: " + uri.toString() + " selfchange: " + selfChange); + if (V && uri!= null) + Log.d(TAG, "onChange on thread: " + Thread.currentThread().getId() + + " Uri: " + uri.toString() + " selfchange: " + selfChange); handleMsgListChanges(); } @@ -676,6 +677,7 @@ public class BluetoothMapContentObserver { public boolean setMessageStatusRead(long handle, TYPE type, int statusValue) { boolean res = true; + Cursor c = null; if (D) Log.d(TAG, "setMessageStatusRead: handle " + handle + " type " + type + " value " + statusValue); @@ -684,20 +686,22 @@ public class BluetoothMapContentObserver { if (type == TYPE.SMS_GSM || type == TYPE.SMS_CDMA) { Uri uri = ContentUris.withAppendedId(Sms.CONTENT_URI, handle); - Cursor c = mResolver.query(uri, null, null, null, null); + c = mResolver.query(uri, null, null, null, null); ContentValues contentValues = new ContentValues(); contentValues.put(Sms.READ, statusValue); mResolver.update(uri, contentValues, null, null); } else if (type == TYPE.MMS) { Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, handle); - Cursor c = mResolver.query(uri, null, null, null, null); + c = mResolver.query(uri, null, null, null, null); ContentValues contentValues = new ContentValues(); contentValues.put(Mms.READ, statusValue); mResolver.update(uri, contentValues, null, null); } + if (c !=null) + c.close(); return res; } diff --git a/src/com/android/bluetooth/map/BluetoothMapMessageListing.java b/src/com/android/bluetooth/map/BluetoothMapMessageListing.java index c81ad69e0..6b501b76b 100644 --- a/src/com/android/bluetooth/map/BluetoothMapMessageListing.java +++ b/src/com/android/bluetooth/map/BluetoothMapMessageListing.java @@ -124,7 +124,7 @@ public class BluetoothMapMessageListing { int line1 = 0; line1 = str1.indexOf("\n"); str2 += str1.substring(line1 + 1); - if (list.size() > 0) { + if (list != null && list.size() > 0) { int indxHandle = str2.indexOf("msg handle"); str1 = "<" + str2.substring(indxHandle); str2 = str2.substring(0, (indxHandle - 1)) + str1; diff --git a/src/com/android/bluetooth/map/BluetoothMapObexServer.java b/src/com/android/bluetooth/map/BluetoothMapObexServer.java index 040b4b646..644191f80 100755 --- a/src/com/android/bluetooth/map/BluetoothMapObexServer.java +++ b/src/com/android/bluetooth/map/BluetoothMapObexServer.java @@ -257,17 +257,17 @@ public class BluetoothMapObexServer extends ServerRequestHandler { return ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED; } }else if(type.equals(TYPE_SET_NOTIFICATION_REGISTRATION)) { - if(V) { + if(V && appParams != null) { Log.d(TAG,"TYPE_SET_NOTIFICATION_REGISTRATION: NotificationStatus: " + appParams.getNotificationStatus()); } return setNotificationRegistration(appParams); }else if(type.equals(TYPE_SET_MESSAGE_STATUS)) { - if(V) { + if(V && appParams != null) { Log.d(TAG,"TYPE_SET_MESSAGE_STATUS: StatusIndicator: " + appParams.getStatusIndicator() + ", StatusValue: " + appParams.getStatusValue()); } return setMessageStatus(name, appParams); } else if (type.equals(TYPE_MESSAGE)) { - if(V) { + if(V && appParams != null) { Log.d(TAG,"TYPE_MESSAGE: Transparet: " + appParams.getTransparent() + ", Retry: " + appParams.getRetry()); Log.d(TAG," charset: " + appParams.getCharset()); } @@ -279,6 +279,10 @@ public class BluetoothMapObexServer extends ServerRequestHandler { } private int setNotificationRegistration(BluetoothMapAppParams appParams) { + if(appParams == null ){ + if(D) Log.d(TAG, "Missing mandatory appParams charset - "); + return ResponseCodes.OBEX_HTTP_PRECON_FAILED; + } // Forward the request to the MNS thread as a message - including the MAS instance ID. Handler mns = mMnsClient.getMessageHandler(); if(mns != null) { @@ -295,6 +299,10 @@ public class BluetoothMapObexServer extends ServerRequestHandler { } private int pushMessage(final Operation op, String folderName, BluetoothMapAppParams appParams) { + if(appParams == null ){ + if(D) Log.d(TAG, "Missing mandatory appParams charset - "); + return ResponseCodes.OBEX_HTTP_PRECON_FAILED; + } if(appParams.getCharset() == BluetoothMapAppParams.INVALID_VALUE_PARAMETER) { if(D) Log.d(TAG, "Missing charset - unable to decode message content. appParams.getCharset() = " + appParams.getCharset()); return ResponseCodes.OBEX_HTTP_PRECON_FAILED; @@ -346,6 +354,10 @@ public class BluetoothMapObexServer extends ServerRequestHandler { } private int setMessageStatus(String msgHandle, BluetoothMapAppParams appParams) { + if(appParams == null ){ + if(D) Log.d(TAG, "Missing mandatory appParams "); + return ResponseCodes.OBEX_HTTP_PRECON_FAILED; + } int indicator = appParams.getStatusIndicator(); int value = appParams.getStatusValue(); long handle; diff --git a/src/com/android/bluetooth/map/BluetoothMapService.java b/src/com/android/bluetooth/map/BluetoothMapService.java index 6d7579b3f..413cd51d1 100644 --- a/src/com/android/bluetooth/map/BluetoothMapService.java +++ b/src/com/android/bluetooth/map/BluetoothMapService.java @@ -662,14 +662,16 @@ public class BluetoothMapService extends ProfileService { if (VERBOSE) Log.v(TAG, "Allow Connection request from " +remoteAddress + "when no other device is connected"); return true; - } else if(MapClientList.get((masId^1)).equalsIgnoreCase(remoteAddress)) { + } else { + if(MapClientList.get((masId^1)).equalsIgnoreCase(remoteAddress)) { Log.d(TAG, "Allow Connection request from " +remoteAddress); Log.d(TAG, "when mas" +(masId^1) +"is connected to " +MapClientList.get((masId^1))); return true; - } else { + } else { Log.d(TAG, "Dont Allow Connection request from " +remoteAddress + "when mas" +(masId^1) +"is connected to" +MapClientList.get((masId^1))); return false; + } } } Log.d(TAG,"connection not allowed from " + remoteAddress); @@ -1134,7 +1136,7 @@ public class BluetoothMapService extends ProfileService { if (VERBOSE) Log.v(TAG, "getState()"); BluetoothMapService service = getService(); if (service == null) return BluetoothMap.STATE_DISCONNECTED; - return getService().getState(); + return service.getState(); } public BluetoothDevice getClient() { diff --git a/src/com/android/bluetooth/map/BluetoothMapbMessage.java b/src/com/android/bluetooth/map/BluetoothMapbMessage.java index 152439496..21d96f13d 100644 --- a/src/com/android/bluetooth/map/BluetoothMapbMessage.java +++ b/src/com/android/bluetooth/map/BluetoothMapbMessage.java @@ -323,10 +323,13 @@ public abstract class BluetoothMapbMessage { public String getLineTerminator() { try { byte[] line = getLineTerminatorAsBytes(); - if (line.length == 0) + if (line == null) { return null; - else + } else if (line.length == 0){ + return null; + } else { return new String(line, "UTF-8"); + } } catch (UnsupportedEncodingException e) { Log.w(TAG, e); return null; @@ -339,10 +342,13 @@ public abstract class BluetoothMapbMessage { public String getLine() { try { byte[] line = getLineAsBytes(); - if (line.length == 0) - return null; - else - return new String(line, "UTF-8"); + if (line == null) { + return null; + } else if (line.length == 0) { + return null; + } else { + return new String(line, "UTF-8"); + } } catch (UnsupportedEncodingException e) { Log.w(TAG, e); return null; @@ -389,9 +395,13 @@ public abstract class BluetoothMapbMessage { */ public void expect(String subString, String subString2) throws IllegalArgumentException{ String line = getLine(); - if(!line.toUpperCase().contains(subString.toUpperCase())) + if(line == null || subString == null) { + throw new IllegalArgumentException("Line or substring is null"); + } else if(!line.toUpperCase().contains(subString.toUpperCase())) throw new IllegalArgumentException("Expected \"" + subString + "\" in: \"" + line + "\""); - if(!line.toUpperCase().contains(subString2.toUpperCase())) + if(line == null || subString2 == null) { + throw new IllegalArgumentException("Line or substring is null"); + } else if(!line.toUpperCase().contains(subString2.toUpperCase())) throw new IllegalArgumentException("Expected \"" + subString + "\" in: \"" + line + "\""); } diff --git a/src/com/android/bluetooth/map/BluetoothMapbMessageMmsEmail.java b/src/com/android/bluetooth/map/BluetoothMapbMessageMmsEmail.java index abc57829d..394c45991 100644 --- a/src/com/android/bluetooth/map/BluetoothMapbMessageMmsEmail.java +++ b/src/com/android/bluetooth/map/BluetoothMapbMessageMmsEmail.java @@ -648,7 +648,8 @@ public class BluetoothMapbMessageMmsEmail extends BluetoothMapbMessage { } } // Now for the body - newPart.data = decodeBody(body, partEncoding); + if (newPart != null) + newPart.data = decodeBody(body, partEncoding); } private static String parseSubjectEmail(String body) { int pos = body.indexOf("Subject:"); @@ -663,7 +664,9 @@ public class BluetoothMapbMessageMmsEmail extends BluetoothMapbMessage { private void parseMmsMimeBody(String body) { MimePart newPart = addMimePart(); - newPart.data = decodeBody(body, encoding); + if(newPart != null) { + newPart.data = decodeBody(body, encoding); + } } private byte[] decodeBody(String body, String encoding) { |