problem to send SMS message by bluetooth MAP profile.

Currently SMSDispatcher will add the message to Sms.Sent database
for all non default SMS application.
This won't work for Bluetooth MAP profile.
In the bluetooth MAP spec, at 5.8 PushMessageFunction,
there are a parameter to control how to send the message by Bluetooth MAP.
Transparent:This parameter may be used to indicate to the MSE(phone)
that no copy of the message shall be kept in the 'Sent' folder
after the message was sent. This is especially useful for telematics applications,
 e.g., frequent sending of car's speed and position for traffic measurements
(floating car data).
This application parameter is optional. The value of this parameter is "OFF"
(keep messages in 'Sent' folder) and "ON" (don't keep messages in Sent' folder).
If Transparent is "ON", we shouldn't put the message in Sent folder.
SMSDispatcher always put the message in Sms.Sent
which is mapped to the Sent folder in bluetooth MAP.
Prefer to let bluetooth to decide whether put the message in Sms.Sent based
on Transparent parameter value.

bug:11454636
Change-Id: I2e6c8deb5c4ed8bc9a3d90d492f4d4eb7dac7e5c
diff --git a/src/java/com/android/internal/telephony/SMSDispatcher.java b/src/java/com/android/internal/telephony/SMSDispatcher.java
index b760d37..64af435 100644
--- a/src/java/com/android/internal/telephony/SMSDispatcher.java
+++ b/src/java/com/android/internal/telephony/SMSDispatcher.java
@@ -341,11 +341,10 @@
         if (ar.exception == null) {
             if (DBG) Rlog.d(TAG, "SMS send complete. Broadcasting intent: " + sentIntent);
 
-            String defaultSmsPackage = Sms.getDefaultSmsPackage(mContext);
-            if (defaultSmsPackage == null ||
-                    !defaultSmsPackage.equals(tracker.mAppInfo.applicationInfo.packageName)) {
-                // Someone other than the default SMS app sent this message. Persist it into the
-                // SMS database as a sent message so the user can see it in their default app.
+            if (SmsApplication.shouldWriteMessageForPackage(
+                    tracker.mAppInfo.applicationInfo.packageName, mContext)) {
+                // Persist it into the SMS database as a sent message
+                // so the user can see it in their default app.
                 tracker.writeSentMessage(mContext);
             }
 
diff --git a/src/java/com/android/internal/telephony/SmsApplication.java b/src/java/com/android/internal/telephony/SmsApplication.java
index 1c0b64a..05a12b3 100644
--- a/src/java/com/android/internal/telephony/SmsApplication.java
+++ b/src/java/com/android/internal/telephony/SmsApplication.java
@@ -488,4 +488,25 @@
         }
         return component;
     }
+
+    /**
+     * Returns whether need to write the SMS message to SMS database for this package.
+     */
+    public static boolean shouldWriteMessageForPackage(String packageName, Context context) {
+        if (packageName == null) return true;
+
+        String defaultSmsPackage = null;
+        ComponentName component = getDefaultSmsApplication(context, false);
+        if (component != null) {
+            defaultSmsPackage = component.getPackageName();
+        }
+
+        if ((defaultSmsPackage == null || !defaultSmsPackage.equals(packageName)) &&
+                !packageName.equals(BLUETOOTH_PACKAGE_NAME)) {
+            // To write the message for someone other than the default SMS and BT app
+            return true;
+        }
+
+        return false;
+    }
 }