Merge "MAP: Handle GetMessageListing formatting for maxListcount 0."
diff --git a/bttestapp/src/org/codeaurora/bluetooth/bttestapp/MapTestActivity.java b/bttestapp/src/org/codeaurora/bluetooth/bttestapp/MapTestActivity.java
index 1aa5165..c35b0be 100644
--- a/bttestapp/src/org/codeaurora/bluetooth/bttestapp/MapTestActivity.java
+++ b/bttestapp/src/org/codeaurora/bluetooth/bttestapp/MapTestActivity.java
@@ -1032,13 +1032,37 @@
 
     public void onClickGetMessagesListing(View view) {
         String folder = mSpinnerFolders.getSelectedItem().toString();
-        int maxListCount = Integer.parseInt(
-                mEditTextMaxListCountMessages.getText().toString());
-        int listStartOffset = Integer.parseInt(
-                mEditTextListStartOffsetMessages.getText().toString());
-        int subjectLength = Integer.parseInt(
-                mEditTextSubjectLength.getText().toString());
 
+        int maxListCount = 0;
+        int listStartOffset = 0;
+        int subjectLength = 0;
+
+        try {
+            maxListCount = Integer.parseInt(
+                    mEditTextMaxListCountMessages.getText().toString());
+        } catch (NumberFormatException e) {
+            Toast.makeText(this,
+                   "Incorrect maxListCount. Some defaults will be used",
+                         Toast.LENGTH_LONG).show();
+        }
+
+        try {
+            listStartOffset = Integer.parseInt(
+                    mEditTextListStartOffsetMessages.getText().toString());
+        } catch (NumberFormatException e) {
+            Toast.makeText(this,
+                   "Incorrect listStartOffset. Some defaults will be used",
+                         Toast.LENGTH_LONG).show();
+        }
+
+        try {
+            subjectLength = Integer.parseInt(
+                    mEditTextSubjectLength.getText().toString());
+        } catch (NumberFormatException e) {
+            Toast.makeText(this,
+                   "Incorrect subject lenght. Some defaults will be used",
+                         Toast.LENGTH_LONG).show();
+        }
         if (folder.equals(".")) {
             folder = "";
         }
diff --git a/src/org/codeaurora/bluetooth/pbapclient/BluetoothPbapRequest.java b/src/org/codeaurora/bluetooth/pbapclient/BluetoothPbapRequest.java
index 5f73ffc..5483272 100644
--- a/src/org/codeaurora/bluetooth/pbapclient/BluetoothPbapRequest.java
+++ b/src/org/codeaurora/bluetooth/pbapclient/BluetoothPbapRequest.java
@@ -101,6 +101,8 @@
             mResponseCode = mOp.getResponseCode();
 
             Log.d(TAG, "mResponseCode=" + mResponseCode);
+
+            checkResponseCode(mResponseCode);
         } catch (IOException e) {
             Log.e(TAG, "IOException occured when processing request", e);
             mResponseCode = ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
@@ -132,4 +134,10 @@
 
         /* nothing here by dafault */
     }
+
+    protected void checkResponseCode(int responseCode) throws IOException {
+        Log.v(TAG, "checkResponseCode");
+
+        /* nothing here by dafault */
+    }
 }
diff --git a/src/org/codeaurora/bluetooth/pbapclient/BluetoothPbapRequestPullVcardEntry.java b/src/org/codeaurora/bluetooth/pbapclient/BluetoothPbapRequestPullVcardEntry.java
index 1bbe359..8499e08 100644
--- a/src/org/codeaurora/bluetooth/pbapclient/BluetoothPbapRequestPullVcardEntry.java
+++ b/src/org/codeaurora/bluetooth/pbapclient/BluetoothPbapRequestPullVcardEntry.java
@@ -37,6 +37,7 @@
 import java.io.InputStream;
 
 import javax.obex.HeaderSet;
+import javax.obex.ResponseCodes;
 
 final class BluetoothPbapRequestPullVcardEntry extends BluetoothPbapRequest {
 
@@ -76,9 +77,17 @@
         Log.v(TAG, "readResponse");
 
         mResponse = new BluetoothPbapVcardList(stream, mFormat);
+    }
+    @Override
+    protected void checkResponseCode(int responseCode) throws IOException {
+        Log.v(TAG, "checkResponseCode");
 
         if (mResponse.getCount() == 0) {
-            throw new IOException("Invalid response received");
+            if (responseCode != ResponseCodes.OBEX_HTTP_NOT_FOUND) {
+                throw new IOException("Invalid response received");
+            } else {
+                Log.v(TAG, "Vcard Entry not found");
+            }
         }
     }