Bug 797277 - Part 4/5: Android implementation, r=mounir,blassey
authorVicamo Yang <vyang@mozilla.com>
Wed, 31 Oct 2012 17:10:53 +0800
changeset 112014 9ce2043663d8
parent 112013 c02178f03fa4
child 112015 265f424378e8
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersmounir, blassey
bugs797277
milestone19.0a1
Bug 797277 - Part 4/5: Android implementation, r=mounir,blassey
dom/sms/src/android/SmsDatabaseService.cpp
dom/sms/src/android/SmsService.cpp
embedding/android/GeckoAppShell.java
embedding/android/GeckoSmsManager.java
mobile/android/base/GeckoAppShell.java
mobile/android/base/GeckoSmsManager.java
widget/android/AndroidJNI.cpp
--- a/dom/sms/src/android/SmsDatabaseService.cpp
+++ b/dom/sms/src/android/SmsDatabaseService.cpp
@@ -11,16 +11,17 @@ namespace mozilla {
 namespace dom {
 namespace sms {
 
 NS_IMPL_ISUPPORTS1(SmsDatabaseService, nsISmsDatabaseService)
 
 NS_IMETHODIMP
 SmsDatabaseService::SaveReceivedMessage(const nsAString& aSender,
                                         const nsAString& aBody,
+                                        const nsAString& aMessageClass,
                                         uint64_t aDate, int32_t* aId)
 {
   // The Android stock SMS app does this already.
   *aId = -1;
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/dom/sms/src/android/SmsService.cpp
+++ b/dom/sms/src/android/SmsService.cpp
@@ -48,22 +48,23 @@ SmsService::Send(const nsAString& aNumbe
 
 NS_IMETHODIMP
 SmsService::CreateSmsMessage(int32_t aId,
                              const nsAString& aDelivery,
                              const nsAString& aDeliveryStatus,
                              const nsAString& aSender,
                              const nsAString& aReceiver,
                              const nsAString& aBody,
+                             const nsAString& aMessageClass,
                              const jsval& aTimestamp,
                              const bool aRead,
                              JSContext* aCx,
                              nsIDOMMozSmsMessage** aMessage)
 {
   return SmsMessage::Create(aId, aDelivery, aDeliveryStatus,
                             aSender, aReceiver,
-                            aBody, aTimestamp, aRead,
+                            aBody, aMessageClass, aTimestamp, aRead,
                             aCx, aMessage);
 }
 
 } // namespace sms
 } // namespace dom
 } // namespace mozilla
--- a/embedding/android/GeckoAppShell.java
+++ b/embedding/android/GeckoAppShell.java
@@ -84,17 +84,17 @@ public class GeckoAppShell
     public static native void loadNSSLibsNative(String apkName, boolean shouldExtract);
     public static native void onChangeNetworkLinkStatus(String status);
     public static native void reportJavaCrash(String stack);
 
     public static native void processNextNativeEvent();
 
     public static native void notifyBatteryChange(double aLevel, boolean aCharging, double aRemainingTime);
 
-    public static native void notifySmsReceived(String aSender, String aBody, long aTimestamp);
+    public static native void notifySmsReceived(String aSender, String aBody, int aMessageClass, long aTimestamp);
     public static native int  saveMessageInSentbox(String aReceiver, String aBody, long aTimestamp);
     public static native void notifySmsSent(int aId, String aReceiver, String aBody, long aTimestamp, int aRequestId, long aProcessId);
     public static native void notifySmsDelivery(int aId, int aDeliveryStatus, String aReceiver, String aBody, long aTimestamp);
     public static native void notifySmsSendFailed(int aError, int aRequestId, long aProcessId);
     public static native void notifyGetSms(int aId, int aDeliveryStatus, String aReceiver, String aSender, String aBody, long aTimestamp, int aRequestId, long aProcessId);
     public static native void notifyGetSmsFailed(int aError, int aRequestId, long aProcessId);
     public static native void notifySmsDeleted(boolean aDeleted, int aRequestId, long aProcessId);
     public static native void notifySmsDeleteFailed(int aError, int aRequestId, long aProcessId);
--- a/embedding/android/GeckoSmsManager.java
+++ b/embedding/android/GeckoSmsManager.java
@@ -27,16 +27,18 @@ import android.net.Uri;
 
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
 
 import android.telephony.SmsManager;
 import android.telephony.SmsMessage;
 
+import static android.telephony.SmsMessage.MessageClass;
+
 /**
  * This class is returning unique ids for PendingIntent requestCode attribute.
  * There are only |Integer.MAX_VALUE - Integer.MIN_VALUE| unique IDs available,
  * and they wrap around.
  */
 class PendingIntentUID
 {
   static private int sUID = Integer.MIN_VALUE;
@@ -335,16 +337,26 @@ public class GeckoSmsManager
    * android.provider.Telephony.Sms.STATUS_*. Duplicated because they're not
    * part of Android public API.
    */
   private final static int kInternalDeliveryStatusNone     = -1;
   private final static int kInternalDeliveryStatusComplete = 0;
   private final static int kInternalDeliveryStatusPending  = 32;
   private final static int kInternalDeliveryStatusFailed   = 64;
 
+  /*
+   * Keep the following values in sync with |MessageClass| in:
+   * dom/sms/src/Types.h
+   */
+  private final static int kMessageClassNormal  = 0;
+  private final static int kMessageClassClass0  = 1;
+  private final static int kMessageClassClass1  = 2;
+  private final static int kMessageClassClass2  = 3;
+  private final static int kMessageClassClass3  = 4;
+
   private final static String[] kRequiredMessageRows = new String[] { "_id", "address", "body", "date", "type", "status" };
 
   public GeckoSmsManager() {
     SmsIOThread.getInstance().start();
   }
 
   public void start() {
     IntentFilter smsFilter = new IntentFilter();
@@ -372,16 +384,17 @@ public class GeckoSmsManager
 
       Object[] pdus = (Object[]) bundle.get("pdus");
 
       for (int i=0; i<pdus.length; ++i) {
         SmsMessage msg = SmsMessage.createFromPdu((byte[])pdus[i]);
 
         GeckoAppShell.notifySmsReceived(msg.getDisplayOriginatingAddress(),
                                         msg.getDisplayMessageBody(),
+                                        getGeckoMessageClass(msg.getMessageClass()),
                                         System.currentTimeMillis());
       }
 
       return;
     }
 
     if (intent.getAction().equals(ACTION_SMS_SENT) ||
         intent.getAction().equals(ACTION_SMS_DELIVERED)) {
@@ -934,16 +947,31 @@ public class GeckoSmsManager
       return kDeliveryStatusError;
     }
     if (aDeliveryStatus >= kInternalDeliveryStatusPending) {
       return kDeliveryStatusPending;
     }
     return kDeliveryStatusSuccess;
   }
 
+  private int getGeckoMessageClass(MessageClass aMessageClass) {
+    switch (aMessageClass) {
+      case UNKNOWN:
+        return kMessageClassNormal;
+      case CLASS_0:
+        return kMessageClassClass0;
+      case CLASS_1:
+        return kMessageClassClass1;
+      case CLASS_2:
+        return kMessageClassClass2;
+      case CLASS_3:
+        return kMessageClassClass3;
+    }
+  }
+
   class IdTooHighException extends Exception {
     private static final long serialVersionUID = 395697882128640L;
   }
 
   class InvalidTypeException extends Exception {
     private static final long serialVersionUID = 23359904803795434L;
   }
 
--- a/mobile/android/base/GeckoAppShell.java
+++ b/mobile/android/base/GeckoAppShell.java
@@ -226,17 +226,17 @@ public class GeckoAppShell
     public static void notifyUriVisited(String uri) {
         sendEventToGecko(GeckoEvent.createVisitedEvent(uri));
     }
 
     public static native void processNextNativeEvent();
 
     public static native void notifyBatteryChange(double aLevel, boolean aCharging, double aRemainingTime);
 
-    public static native void notifySmsReceived(String aSender, String aBody, long aTimestamp);
+    public static native void notifySmsReceived(String aSender, String aBody, int aMessageClass, long aTimestamp);
     public static native int  saveMessageInSentbox(String aReceiver, String aBody, long aTimestamp);
     public static native void notifySmsSent(int aId, String aReceiver, String aBody, long aTimestamp, int aRequestId, long aProcessId);
     public static native void notifySmsDelivery(int aId, int aDeliveryStatus, String aReceiver, String aBody, long aTimestamp);
     public static native void notifySmsSendFailed(int aError, int aRequestId, long aProcessId);
     public static native void notifyGetSms(int aId, int aDeliveryStatus, String aReceiver, String aSender, String aBody, long aTimestamp, int aRequestId, long aProcessId);
     public static native void notifyGetSmsFailed(int aError, int aRequestId, long aProcessId);
     public static native void notifySmsDeleted(boolean aDeleted, int aRequestId, long aProcessId);
     public static native void notifySmsDeleteFailed(int aError, int aRequestId, long aProcessId);
--- a/mobile/android/base/GeckoSmsManager.java
+++ b/mobile/android/base/GeckoSmsManager.java
@@ -20,16 +20,18 @@ import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
 import android.telephony.SmsManager;
 import android.telephony.SmsMessage;
 import android.util.Log;
 
 import java.util.ArrayList;
 
+import static android.telephony.SmsMessage.MessageClass;
+
 /**
  * This class is returning unique ids for PendingIntent requestCode attribute.
  * There are only |Integer.MAX_VALUE - Integer.MIN_VALUE| unique IDs available,
  * and they wrap around.
  */
 class PendingIntentUID
 {
   static private int sUID = Integer.MIN_VALUE;
@@ -328,16 +330,26 @@ public class GeckoSmsManager
    * android.provider.Telephony.Sms.STATUS_*. Duplicated because they're not
    * part of Android public API.
    */
   private final static int kInternalDeliveryStatusNone     = -1;
   private final static int kInternalDeliveryStatusComplete = 0;
   private final static int kInternalDeliveryStatusPending  = 32;
   private final static int kInternalDeliveryStatusFailed   = 64;
 
+  /*
+   * Keep the following values in sync with |MessageClass| in:
+   * dom/sms/src/Types.h
+   */
+  private final static int kMessageClassNormal  = 0;
+  private final static int kMessageClassClass0  = 1;
+  private final static int kMessageClassClass1  = 2;
+  private final static int kMessageClassClass2  = 3;
+  private final static int kMessageClassClass3  = 4;
+
   private final static String[] kRequiredMessageRows = new String[] { "_id", "address", "body", "date", "type", "status" };
 
   public GeckoSmsManager() {
     SmsIOThread.getInstance().start();
   }
 
   public void start() {
     IntentFilter smsFilter = new IntentFilter();
@@ -365,16 +377,17 @@ public class GeckoSmsManager
 
       Object[] pdus = (Object[]) bundle.get("pdus");
 
       for (int i=0; i<pdus.length; ++i) {
         SmsMessage msg = SmsMessage.createFromPdu((byte[])pdus[i]);
 
         GeckoAppShell.notifySmsReceived(msg.getDisplayOriginatingAddress(),
                                         msg.getDisplayMessageBody(),
+                                        getGeckoMessageClass(msg.getMessageClass()),
                                         System.currentTimeMillis());
       }
 
       return;
     }
 
     if (intent.getAction().equals(ACTION_SMS_SENT) ||
         intent.getAction().equals(ACTION_SMS_DELIVERED)) {
@@ -927,16 +940,31 @@ public class GeckoSmsManager
       return kDeliveryStatusError;
     }
     if (aDeliveryStatus >= kInternalDeliveryStatusPending) {
       return kDeliveryStatusPending;
     }
     return kDeliveryStatusSuccess;
   }
 
+  private int getGeckoMessageClass(MessageClass aMessageClass) {
+    switch (aMessageClass) {
+      case UNKNOWN:
+        return kMessageClassNormal;
+      case CLASS_0:
+        return kMessageClassClass0;
+      case CLASS_1:
+        return kMessageClassClass1;
+      case CLASS_2:
+        return kMessageClassClass2;
+      case CLASS_3:
+        return kMessageClassClass3;
+    }
+  }
+
   class IdTooHighException extends Exception {
     private static final long serialVersionUID = 29935575131092050L;
   }
 
   class InvalidTypeException extends Exception {
     private static final long serialVersionUID = 47436856832535912L;
   }
 
--- a/widget/android/AndroidJNI.cpp
+++ b/widget/android/AndroidJNI.cpp
@@ -181,16 +181,17 @@ Java_org_mozilla_gecko_GeckoAppShell_not
     nsCOMPtr<nsIRunnable> runnable = new NotifyBatteryChangeRunnable(aLevel, aCharging, aRemainingTime);
     NS_DispatchToMainThread(runnable);
 }
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_notifySmsReceived(JNIEnv* jenv, jclass,
                                                        jstring aSender,
                                                        jstring aBody,
+                                                       jint aMessageClass,
                                                        jlong aTimestamp)
 {
     class NotifySmsReceivedRunnable : public nsRunnable {
     public:
       NotifySmsReceivedRunnable(const SmsMessageData& aMessageData)\
         : mMessageData(aMessageData)
       {}
 
@@ -206,17 +207,19 @@ Java_org_mozilla_gecko_GeckoAppShell_not
       }
 
     private:
       SmsMessageData mMessageData;
     };
 
     SmsMessageData message(0, eDeliveryState_Received, eDeliveryStatus_Success,
                            nsJNIString(aSender, jenv), EmptyString(),
-                           nsJNIString(aBody, jenv), aTimestamp, false);
+                           nsJNIString(aBody, jenv),
+                           static_cast<MessageClass>(aMessageClass),
+                           aTimestamp, false);
 
     nsCOMPtr<nsIRunnable> runnable = new NotifySmsReceivedRunnable(message);
     NS_DispatchToMainThread(runnable);
 }
 
 NS_EXPORT int32_t JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_saveMessageInSentbox(JNIEnv* jenv, jclass,
                                                           jstring aReceiver,
@@ -290,19 +293,21 @@ Java_org_mozilla_gecko_GeckoAppShell_not
       }
 
     private:
       SmsMessageData mMessageData;
       int32_t        mRequestId;
       uint64_t       mProcessId;
     };
 
+    // TODO Need to add the message `messageClass` parameter value. Bug 804476
     SmsMessageData message(aId, eDeliveryState_Sent, eDeliveryStatus_Pending,
                            EmptyString(), nsJNIString(aReceiver, jenv),
-                           nsJNIString(aBody, jenv), aTimestamp, true);
+                           nsJNIString(aBody, jenv), eMessageClass_Normal,
+                           aTimestamp, true);
 
     nsCOMPtr<nsIRunnable> runnable = new NotifySmsSentRunnable(message, aRequestId, aProcessId);
     NS_DispatchToMainThread(runnable);
 }
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_notifySmsDelivery(JNIEnv* jenv, jclass,
                                                        jint aId,
@@ -331,20 +336,22 @@ Java_org_mozilla_gecko_GeckoAppShell_not
 
         return NS_OK;
       }
 
     private:
       SmsMessageData mMessageData;
     };
 
+    // TODO Need to add the message `messageClass` parameter value. Bug 804476
     SmsMessageData message(aId, eDeliveryState_Sent,
                            static_cast<DeliveryStatus>(aDeliveryStatus),
                            EmptyString(), nsJNIString(aReceiver, jenv),
-                           nsJNIString(aBody, jenv), aTimestamp, true);
+                           nsJNIString(aBody, jenv), eMessageClass_Normal,
+                           aTimestamp, true);
 
     nsCOMPtr<nsIRunnable> runnable = new NotifySmsDeliveredRunnable(message);
     NS_DispatchToMainThread(runnable);
 }
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_notifySmsSendFailed(JNIEnv* jenv, jclass,
                                                          jint aError,
@@ -442,20 +449,22 @@ Java_org_mozilla_gecko_GeckoAppShell_not
       uint64_t       mProcessId;
     };
 
     nsJNIString receiver = nsJNIString(aReceiver, jenv);
     DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received
                                              : eDeliveryState_Sent;
 
     // TODO Need to add the message `read` parameter value. Bug 748391
+    // TODO Need to add the message `messageClass` parameter value. Bug 804476
     SmsMessageData message(aId, state,
                            static_cast<DeliveryStatus>(aDeliveryStatus),
                            nsJNIString(aSender, jenv), receiver,
-                           nsJNIString(aBody, jenv), aTimestamp, true);
+                           nsJNIString(aBody, jenv), eMessageClass_Normal,
+                           aTimestamp, true);
 
     nsCOMPtr<nsIRunnable> runnable = new NotifyGetSmsRunnable(message, aRequestId, aProcessId);
     NS_DispatchToMainThread(runnable);
 }
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_notifyGetSmsFailed(JNIEnv* jenv, jclass,
                                                         jint aError,
@@ -701,20 +710,22 @@ Java_org_mozilla_gecko_GeckoAppShell_not
     };
 
 
     nsJNIString receiver = nsJNIString(aReceiver, jenv);
     DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received
                                              : eDeliveryState_Sent;
 
     // TODO Need to add the message `read` parameter value. Bug 748391
+    // TODO Need to add the message `messageClass` parameter value. Bug 804476
     SmsMessageData message(aMessageId, state,
                            static_cast<DeliveryStatus>(aDeliveryStatus),
                            nsJNIString(aSender, jenv), receiver,
-                           nsJNIString(aBody, jenv), aTimestamp, true);
+                           nsJNIString(aBody, jenv), eMessageClass_Normal,
+                           aTimestamp, true);
 
     nsCOMPtr<nsIRunnable> runnable =
       new NotifyCreateMessageListRunnable(aListId, message, aRequestId, aProcessId);
     NS_DispatchToMainThread(runnable);
 }
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_notifyGotNextMessage(JNIEnv* jenv, jclass,
@@ -765,20 +776,22 @@ Java_org_mozilla_gecko_GeckoAppShell_not
     };
 
 
     nsJNIString receiver = nsJNIString(aReceiver, jenv);
     DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received
                                              : eDeliveryState_Sent;
  
     // TODO Need to add the message `read` parameter value. Bug 748391
+    // TODO Need to add the message `messageClass` parameter value. Bug 804476
     SmsMessageData message(aMessageId, state,
                            static_cast<DeliveryStatus>(aDeliveryStatus),
                            nsJNIString(aSender, jenv), receiver,
-                           nsJNIString(aBody, jenv), aTimestamp, true);
+                           nsJNIString(aBody, jenv), eMessageClass_Normal,
+                           aTimestamp, true);
 
     nsCOMPtr<nsIRunnable> runnable =
       new NotifyGotNextMessageRunnable(message, aRequestId, aProcessId);
     NS_DispatchToMainThread(runnable);
 }
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_notifyReadingMessageListFailed(JNIEnv* jenv, jclass,