Merge branch 'LA.BF64.1.2.2_rb4.9' of git://codeaurora.org/platform/packages/apps/Bluetooth into cm-13.0
diff --git a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
index f43fc56..e315a72 100644
--- a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
+++ b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
@@ -59,6 +59,7 @@
 import android.os.ParcelUuid;
 import android.os.RemoteException;
 import android.os.ServiceManager;
+import android.os.SystemProperties;
 import android.os.PowerManager;
 import android.os.UserHandle;
 import android.os.PowerManager.WakeLock;
@@ -1759,8 +1760,15 @@
             int volumeValue = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0);
             if (mPhoneState.getSpeakerVolume() != volumeValue) {
                 mPhoneState.setSpeakerVolume(volumeValue);
-                setVolumeNative(HeadsetHalConstants.VOLUME_TYPE_SPK,
+            boolean scoVolume =
+                    SystemProperties.getBoolean("bt.pts.certification", false);
+                if (!scoVolume) {
+                    setVolumeNative(HeadsetHalConstants.VOLUME_TYPE_SPK,
                                         volumeValue, getByteAddress(device));
+                } else {
+                    setVolumeNative(HeadsetHalConstants.VOLUME_TYPE_SPK,
+                                        0, getByteAddress(device));
+                }
             }
         }
 
@@ -2316,8 +2324,15 @@
             int volumeValue = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0);
             if (mPhoneState.getSpeakerVolume() != volumeValue) {
                 mPhoneState.setSpeakerVolume(volumeValue);
-                setVolumeNative(HeadsetHalConstants.VOLUME_TYPE_SPK,
-                                    volumeValue, getByteAddress(device));
+            boolean scoVolume =
+                    SystemProperties.getBoolean("bt.pts.certification", false);
+                if (!scoVolume) {
+                    setVolumeNative(HeadsetHalConstants.VOLUME_TYPE_SPK,
+                                        volumeValue, getByteAddress(device));
+                } else {
+                    setVolumeNative(HeadsetHalConstants.VOLUME_TYPE_SPK,
+                                        0, getByteAddress(device));
+                }
             }
         }
     }
diff --git a/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java b/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java
index a4bebaa..1680199 100644
--- a/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java
+++ b/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java
@@ -984,9 +984,6 @@
                 }
                 break;
             case BluetoothHeadsetClientCall.CALL_STATE_HELD_BY_RESPONSE_AND_HOLD:
-                if (flag != BluetoothHeadsetClient.CALL_ACCEPT_NONE) {
-                    return;
-                }
                 action = HeadsetClientHalConstants.CALL_ACTION_BTRH_1;
                 break;
             case BluetoothHeadsetClientCall.CALL_STATE_ALERTING:
diff --git a/src/com/android/bluetooth/map/BluetoothMapContentEmail.java b/src/com/android/bluetooth/map/BluetoothMapContentEmail.java
index 4b25507..35bf0bb 100644
--- a/src/com/android/bluetooth/map/BluetoothMapContentEmail.java
+++ b/src/com/android/bluetooth/map/BluetoothMapContentEmail.java
@@ -1787,6 +1787,10 @@
                    message.setType(TYPE.EMAIL);
                    message.setVersionString(mMessageVersion);
                    message.setContentType("Content-Type: text/plain; charset=\"UTF-8\"");
+                   message.setDate(c.getLong(c.getColumnIndex(BluetoothMapEmailContract
+                       .ExtEmailMessageColumns.TIMESTAMP)));
+                   message.setSubject(c.getString(c.getColumnIndex(BluetoothMapContract
+                       .MessageColumns.SUBJECT)));
                    // Set folder:
                    long folderId = c.getLong( c.getColumnIndex(BluetoothMapEmailContract
                            .ExtEmailMessageColumns.MAILBOX_KEY));
diff --git a/src/com/android/bluetooth/map/BluetoothMapbMessage.java b/src/com/android/bluetooth/map/BluetoothMapbMessage.java
index 1c2e186..73c41f2 100644
--- a/src/com/android/bluetooth/map/BluetoothMapbMessage.java
+++ b/src/com/android/bluetooth/map/BluetoothMapbMessage.java
@@ -431,10 +431,13 @@
         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;
@@ -482,12 +485,18 @@
          */
         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 + "\"");
+            }
         }
 
         /**
@@ -857,24 +866,16 @@
                  * END:MSG in the actual message content, it is now safe to use the END:MSG tag
                  * as terminator, and simply ignore the length field.*/
 
-                /* 2 added to compensate for the removed \r\n */
-                byte[] rawData = reader.getDataBytes(mBMsgLength - (line.getBytes().length + 2));
-                String data;
-                try {
-                    data = new String(rawData, "UTF-8");
+                String data = reader.getStringTerminator("END:MSG");
                     if(V) {
                         Log.v(TAG,"MsgLength: " + mBMsgLength);
-                        Log.v(TAG,"line.getBytes().length: " + line.getBytes().length);
+                        Log.v(TAG,"data.getBytes().length: " + data.getBytes().length);
                         String debug = line.replaceAll("\\n", "<LF>\n");
                         debug = debug.replaceAll("\\r", "<CR>");
                         Log.v(TAG,"The line: \"" + debug + "\"");
                         debug = data.replaceAll("\\n", "<LF>\n");
                         debug = debug.replaceAll("\\r", "<CR>");
-                        Log.v(TAG,"The msgString: \"" + debug + "\"");
-                    }
-                } catch (UnsupportedEncodingException e) {
-                    Log.w(TAG,e);
-                    throw new IllegalArgumentException("Unable to convert to UTF-8");
+                        Log.v(TAG, "The msgString: \"" + data + "\"");
                 }
                 /* Decoding of MSG:
                  * 1) split on "\r\nEND:MSG\r\n"
diff --git a/src/com/android/bluetooth/sap/SapServer.java b/src/com/android/bluetooth/sap/SapServer.java
index f1d77c3..56dc4f4 100644
--- a/src/com/android/bluetooth/sap/SapServer.java
+++ b/src/com/android/bluetooth/sap/SapServer.java
@@ -215,9 +215,8 @@
         /* For PTS TC_SERVER_DCN_BV_03_I we need to expose the option to send immediate disconnect
          * without first sending a graceful disconnect.
          * To enable this option set
-         * bt.sap.pts="true" */
-        String pts_enabled = SystemProperties.get("bt.sap.pts");
-        Boolean pts_test = Boolean.parseBoolean(pts_enabled);
+         * bt.pts.certification="true" */
+        Boolean pts_test = SystemProperties.getBoolean("bt.pts.certification", false);
 
         /* put notification up for the user to be able to disconnect from the client*/
         Intent sapDisconnectIntent = new Intent(SapServer.SAP_DISCONNECT_ACTION);