diff options
author | Hemant Gupta <hemantg@codeaurora.org> | 2015-05-13 13:19:18 +0530 |
---|---|---|
committer | Andre Eisenbach <eisenbach@google.com> | 2015-05-14 17:21:15 -0700 |
commit | 4231be1e03b7c5e563fea1fa7c56abfe2a1e61dd (patch) | |
tree | ac23149457b50acbfb0448e844ec80577f5480fb | |
parent | 501fc972ed07c56eceb1309dbee6bc84dbf4c1c1 (diff) | |
download | android_frameworks_opt_bluetooth-4231be1e03b7c5e563fea1fa7c56abfe2a1e61dd.tar.gz android_frameworks_opt_bluetooth-4231be1e03b7c5e563fea1fa7c56abfe2a1e61dd.tar.bz2 android_frameworks_opt_bluetooth-4231be1e03b7c5e563fea1fa7c56abfe2a1e61dd.zip |
MAPC: Fix following issues in map client code
- Fix NPE for ObexTime and dateTimeformat.
Handle possible NullPointerException while accessing
map client ObexTime constructor utility.
Send all parameters event, status and notification state to
Test Client for setNotifcationRegistration event both success
and failure case.
- Fix GetMessagelisting Request for maxlistcount value 0.
Include maxlistcount for value 0 in application parameters header
while composing obex GetMessageListing Request to MAP Server.
- Add maxListCount param in getfolderlisting.
A special case, where MCE APP send the folderlisting
with maxlistcount=0, startoffset=5, As DUT(MCE role)
does not include maxListcount param in folderlsiting,
when it's value set to 0 by MCE APP. So as per the spec,
MSE assume maxListCount = 1024 for folderlsiting & MSE
response as the bad request, when startoffset is Out of
range. Adding MaxListCount in folderListing to
solve this issue, when it's value set to 0.
- Handle exception for incorrect length value from MSE
Handle possible exception while parsing GET Message response
with incorrect LENGTH value fetched from MSE.
- Include ParameterMask Header in GET only when specified.
Include ParmaterMask in GET MessageLising Request only when
specific values are selected from TestClient.
ParameterMask is not a mandatory feild as per MAP1.1 Spec.
excluding ParameterMask for default or value '0' fix MSE IOT
issues that doesnot support ParameterMask Header.
Change-Id: I1bee3f512f877974bb8fd63f3b27dc3ce3ff8a13
6 files changed, 43 insertions, 19 deletions
diff --git a/src/android/bluetooth/client/map/BluetoothMapBmessageParser.java b/src/android/bluetooth/client/map/BluetoothMapBmessageParser.java index fa3d817..ef75e7b 100644 --- a/src/android/bluetooth/client/map/BluetoothMapBmessageParser.java +++ b/src/android/bluetooth/client/map/BluetoothMapBmessageParser.java @@ -312,8 +312,16 @@ class BluetoothMapBmessageParser { prop = mParser.next(true); - if (prop != null && prop.equals(END_MSG)) { - mBmsg.mMessage = new String(data, 0, messageLen); + if (prop != null) { + if (prop.equals(END_MSG)) { + mBmsg.mMessage = new String(data, 0, messageLen); + } else { + /* Handle possible exception for incorrect LENGTH value + * from MSE while parsing GET Message response */ + Log.e(TAG, "Prop Invalid: "+ prop.toString()); + Log.e(TAG, "Possible Invalid LENGTH value"); + throw expected(END_MSG); + } } else { data = null; @@ -322,6 +330,11 @@ class BluetoothMapBmessageParser { * now we check if bMessage can be parsed if LENGTH is handled as * number of characters instead of number of bytes */ + if (offset < 0 || offset > remng.length()) { + /* Handle possible exception for incorrect LENGTH value + * from MSE while parsing GET Message response */ + throw new ParseException("Invalid LENGTH value", mParser.pos()); + } Log.w(TAG, "byte LENGTH seems to be invalid, trying with char length"); diff --git a/src/android/bluetooth/client/map/BluetoothMapMessage.java b/src/android/bluetooth/client/map/BluetoothMapMessage.java index 6c76bbe..5ce6c4b 100644 --- a/src/android/bluetooth/client/map/BluetoothMapMessage.java +++ b/src/android/bluetooth/client/map/BluetoothMapMessage.java @@ -91,8 +91,14 @@ public class BluetoothMapMessage { } mSubject = attrs.get("subject"); + String dateTime = attrs.get("datetime"); + //Handle possible NPE when not able to retreive datetime attribute + if(dateTime != null){ + mDateTime = (new ObexTime(dateTime)).getTime(); + } else { + mDateTime = null; + } - mDateTime = (new ObexTime(attrs.get("datetime"))).getTime(); mSenderName = attrs.get("sender_name"); diff --git a/src/android/bluetooth/client/map/BluetoothMasClient.java b/src/android/bluetooth/client/map/BluetoothMasClient.java index d6d2a1c..7f71693 100644 --- a/src/android/bluetooth/client/map/BluetoothMasClient.java +++ b/src/android/bluetooth/client/map/BluetoothMasClient.java @@ -453,13 +453,9 @@ public class BluetoothMasClient { } private void sendToClient(int event, boolean success, Object param) { - if (success) { - mCallback.obtainMessage(event, STATUS_OK, mMas.getMasInstanceId(), param) - .sendToTarget(); - } else { - mCallback.obtainMessage(event, STATUS_FAILED, mMas.getMasInstanceId(), null) - .sendToTarget(); - } + // Send event, status and notification state for both sucess and failure case. + mCallback.obtainMessage(event, success ? STATUS_OK : STATUS_FAILED, mMas.getMasInstanceId(), + param).sendToTarget(); } private class SocketConnectThread extends Thread { @@ -547,8 +543,11 @@ public class BluetoothMasClient { } public void setPeriod(Date filterBegin, Date filterEnd) { - periodBegin = (new ObexTime(filterBegin)).toString(); - periodEnd = (new ObexTime(filterEnd)).toString(); + //Handle possible NPE for obexTime constructor utility + if(filterBegin != null ) + periodBegin = (new ObexTime(filterBegin)).toString(); + if(filterEnd != null) + periodEnd = (new ObexTime(filterEnd)).toString(); } public void setReadStatus(byte readfilter) { diff --git a/src/android/bluetooth/client/map/BluetoothMasRequest.java b/src/android/bluetooth/client/map/BluetoothMasRequest.java index 658a344..0c9c29c 100644 --- a/src/android/bluetooth/client/map/BluetoothMasRequest.java +++ b/src/android/bluetooth/client/map/BluetoothMasRequest.java @@ -43,6 +43,7 @@ abstract class BluetoothMasRequest { protected static final byte OAP_TAGID_NEW_MESSAGE = 0x0d; protected static final byte OAP_TAGID_NOTIFICATION_STATUS = 0x0e; protected static final byte OAP_TAGID_MAS_INSTANCE_ID = 0x0f; + protected static final byte OAP_TAGID_PARAMETER_MASK = 0x10; protected static final byte OAP_TAGID_FOLDER_LISTING_SIZE = 0x11; protected static final byte OAP_TAGID_MESSAGES_LISTING_SIZE = 0x12; protected static final byte OAP_TAGID_SUBJECT_LENGTH = 0x13; diff --git a/src/android/bluetooth/client/map/BluetoothMasRequestGetFolderListing.java b/src/android/bluetooth/client/map/BluetoothMasRequestGetFolderListing.java index bd5a2dd..db22ada 100644 --- a/src/android/bluetooth/client/map/BluetoothMasRequestGetFolderListing.java +++ b/src/android/bluetooth/client/map/BluetoothMasRequestGetFolderListing.java @@ -43,8 +43,8 @@ final class BluetoothMasRequestGetFolderListing extends BluetoothMasRequest { mHeaderSet.setHeader(HeaderSet.TYPE, TYPE); ObexAppParameters oap = new ObexAppParameters(); - - if (maxListCount > 0) { + // Allow GetFolderListing for maxListCount value 0 also. + if (maxListCount >= 0) { oap.add(OAP_TAGID_MAX_LIST_COUNT, (short) maxListCount); } diff --git a/src/android/bluetooth/client/map/BluetoothMasRequestGetMessagesListing.java b/src/android/bluetooth/client/map/BluetoothMasRequestGetMessagesListing.java index d5460f9..2ad167d 100644 --- a/src/android/bluetooth/client/map/BluetoothMasRequestGetMessagesListing.java +++ b/src/android/bluetooth/client/map/BluetoothMasRequestGetMessagesListing.java @@ -41,7 +41,6 @@ final class BluetoothMasRequestGetMessagesListing extends BluetoothMasRequest { public BluetoothMasRequestGetMessagesListing(String folderName, int parameters, BluetoothMasClient.MessagesFilter filter, int subjectLength, int maxListCount, int listStartOffset) { - if (subjectLength < 0 || subjectLength > 255) { throw new IllegalArgumentException("subjectLength should be [0..255]"); } @@ -97,8 +96,14 @@ final class BluetoothMasRequestGetMessagesListing extends BluetoothMasRequest { if (subjectLength != 0) { oap.add(OAP_TAGID_SUBJECT_LENGTH, (byte) subjectLength); } - - if (maxListCount != 0) { + /* Include parameterMask only when specific values are selected, + * to avoid IOT specific issue with no paramterMask header support. + */ + if (parameters > 0 ) { + oap.add(OAP_TAGID_PARAMETER_MASK, parameters); + } + // Allow GetMessageListing for maxlistcount value 0 also. + if (maxListCount >= 0) { oap.add(OAP_TAGID_MAX_LIST_COUNT, (short) maxListCount); } @@ -122,8 +127,8 @@ final class BluetoothMasRequestGetMessagesListing extends BluetoothMasRequest { if (oap.exists(OAP_TAGID_MSE_TIME)) { String mseTime = oap.getString(OAP_TAGID_MSE_TIME); - - mServerTime = (new ObexTime(mseTime)).getTime(); + if(mseTime != null ) + mServerTime = (new ObexTime(mseTime)).getTime(); } } |