From c499174641f1eecd07b87bde346dd1ef060f4de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez?= Date: Tue, 30 Jul 2013 00:50:21 +0200 Subject: [PATCH] Bug 816564 - Silent SMS to Authenticate Device for Mobile Billing. Part 0: WebSMS. sr=vicamo --- .../interfaces/nsIMobileMessageCallback.idl | 2 +- .../interfaces/nsISmsService.idl | 7 ++- dom/mobilemessage/src/Constants.cpp | 1 + dom/mobilemessage/src/Constants.h | 6 +- .../src/MobileMessageManager.cpp | 3 +- dom/mobilemessage/src/android/SmsService.cpp | 26 ++++++++- dom/mobilemessage/src/fallback/SmsService.cpp | 25 +++++++- dom/mobilemessage/src/gonk/SmsService.cpp | 33 ++++++++++- dom/mobilemessage/src/gonk/SmsService.h | 3 + dom/mobilemessage/src/ipc/PSms.ipdl | 6 ++ dom/mobilemessage/src/ipc/SmsChild.cpp | 7 +++ dom/mobilemessage/src/ipc/SmsChild.h | 3 + dom/mobilemessage/src/ipc/SmsIPCService.cpp | 32 +++++++++- dom/mobilemessage/src/ipc/SmsParent.cpp | 58 ++++++++++++++++++- dom/mobilemessage/src/ipc/SmsParent.h | 9 +++ 15 files changed, 208 insertions(+), 13 deletions(-) diff --git a/dom/mobilemessage/interfaces/nsIMobileMessageCallback.idl b/dom/mobilemessage/interfaces/nsIMobileMessageCallback.idl index 92cce6b8391..478c5cedc8f 100644 --- a/dom/mobilemessage/interfaces/nsIMobileMessageCallback.idl +++ b/dom/mobilemessage/interfaces/nsIMobileMessageCallback.idl @@ -13,7 +13,7 @@ dictionary SmsThreadListItem unsigned long long unreadCount; }; -[scriptable, builtinclass, uuid(a22d9aae-ee0a-11e2-949e-e770d0d3883f)] +[scriptable, uuid(ea5fb581-bee7-40a6-b2dc-c98b99a2dc49)] interface nsIMobileMessageCallback : nsISupports { /** diff --git a/dom/mobilemessage/interfaces/nsISmsService.idl b/dom/mobilemessage/interfaces/nsISmsService.idl index d50014d999d..0623d62ef78 100644 --- a/dom/mobilemessage/interfaces/nsISmsService.idl +++ b/dom/mobilemessage/interfaces/nsISmsService.idl @@ -13,7 +13,7 @@ interface nsIMobileMessageCallback; #define SMS_SERVICE_CONTRACTID "@mozilla.org/sms/smsservice;1" %} -[scriptable, builtinclass, uuid(c4b2ed2a-8714-11e2-bd2b-13f1a0759342)] +[scriptable, builtinclass, uuid(f0d5d11b-0326-4cb1-bb76-a3f912212287)] interface nsISmsService : nsISupports { boolean hasSupport(); @@ -22,5 +22,10 @@ interface nsISmsService : nsISupports void send(in DOMString number, in DOMString message, + in boolean silent, in nsIMobileMessageCallback request); + + boolean isSilentNumber(in DOMString number); + void addSilentNumber(in DOMString number); + void removeSilentNumber(in DOMString number); }; diff --git a/dom/mobilemessage/src/Constants.cpp b/dom/mobilemessage/src/Constants.cpp index 47a5c607f91..18de5bf7e89 100644 --- a/dom/mobilemessage/src/Constants.cpp +++ b/dom/mobilemessage/src/Constants.cpp @@ -14,6 +14,7 @@ const char* kSmsSentObserverTopic = "sms-sent"; const char* kSmsFailedObserverTopic = "sms-failed"; const char* kSmsDeliverySuccessObserverTopic = "sms-delivery-success"; const char* kSmsDeliveryErrorObserverTopic = "sms-delivery-error"; +const char* kSilentSmsReceivedObserverTopic = "silent-sms-received"; } // namespace mobilemessage } // namespace dom diff --git a/dom/mobilemessage/src/Constants.h b/dom/mobilemessage/src/Constants.h index 063bd66a353..c53b83fc24a 100644 --- a/dom/mobilemessage/src/Constants.h +++ b/dom/mobilemessage/src/Constants.h @@ -18,11 +18,7 @@ extern const char* kSmsSentObserverTopic; extern const char* kSmsFailedObserverTopic; extern const char* kSmsDeliverySuccessObserverTopic; extern const char* kSmsDeliveryErrorObserverTopic; - -extern const char* kMmsSendingObserverTopic; -extern const char* kMmsSentObserverTopic; -extern const char* kMmsFailedObserverTopic; -extern const char* kMmsReceivedObserverTopic; +extern const char* kSilentSmsReceivedObserverTopic; #define DELIVERY_RECEIVED NS_LITERAL_STRING("received") #define DELIVERY_SENDING NS_LITERAL_STRING("sending") diff --git a/dom/mobilemessage/src/MobileMessageManager.cpp b/dom/mobilemessage/src/MobileMessageManager.cpp index 572035312e8..ae4c12fa285 100644 --- a/dom/mobilemessage/src/MobileMessageManager.cpp +++ b/dom/mobilemessage/src/MobileMessageManager.cpp @@ -124,7 +124,8 @@ MobileMessageManager::Send(JSContext* aCx, JS::Handle aGlobal, nsCOMPtr msgCallback = new MobileMessageCallback(request); - nsresult rv = smsService->Send(number, aMessage, msgCallback); + // By default, we don't send silent messages via MobileMessageManager. + nsresult rv = smsService->Send(number, aMessage, false, msgCallback); NS_ENSURE_SUCCESS(rv, rv); JS::Rooted global(aCx, aGlobal); diff --git a/dom/mobilemessage/src/android/SmsService.cpp b/dom/mobilemessage/src/android/SmsService.cpp index 7affaa025b5..146190766fa 100644 --- a/dom/mobilemessage/src/android/SmsService.cpp +++ b/dom/mobilemessage/src/android/SmsService.cpp @@ -40,7 +40,9 @@ SmsService::GetSegmentInfoForText(const nsAString & aText, } NS_IMETHODIMP -SmsService::Send(const nsAString& aNumber, const nsAString& aMessage, +SmsService::Send(const nsAString& aNumber, + const nsAString& aMessage, + const bool aSilent, nsIMobileMessageCallback* aRequest) { if (!AndroidBridge::Bridge()) { @@ -51,6 +53,28 @@ SmsService::Send(const nsAString& aNumber, const nsAString& aMessage, return NS_OK; } +NS_IMETHODIMP +SmsService::IsSilentNumber(const nsAString& aNumber, + bool* aIsSilent) +{ + NS_NOTYETIMPLEMENTED("Implement me!"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +SmsService::AddSilentNumber(const nsAString& aNumber) +{ + NS_NOTYETIMPLEMENTED("Implement me!"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +SmsService::RemoveSilentNumber(const nsAString& aNumber) +{ + NS_NOTYETIMPLEMENTED("Implement me!"); + return NS_ERROR_NOT_IMPLEMENTED; +} + } // namespace mobilemessage } // namespace dom } // namespace mozilla diff --git a/dom/mobilemessage/src/fallback/SmsService.cpp b/dom/mobilemessage/src/fallback/SmsService.cpp index 37a68bb8871..5df3504226b 100644 --- a/dom/mobilemessage/src/fallback/SmsService.cpp +++ b/dom/mobilemessage/src/fallback/SmsService.cpp @@ -32,10 +32,33 @@ SmsService::GetSegmentInfoForText(const nsAString & aText, NS_IMETHODIMP SmsService::Send(const nsAString& aNumber, const nsAString& aMessage, + const bool aSilent, nsIMobileMessageCallback* aRequest) { NS_ERROR("We should not be here!"); - return NS_OK; + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +SmsService::IsSilentNumber(const nsAString& aNumber, + bool* aIsSilent) +{ + NS_ERROR("We should not be here!"); + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +SmsService::AddSilentNumber(const nsAString& aNumber) +{ + NS_ERROR("We should not be here!"); + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +SmsService::RemoveSilentNumber(const nsAString& aNumber) +{ + NS_ERROR("We should not be here!"); + return NS_ERROR_FAILURE; } } // namespace mobilemessage diff --git a/dom/mobilemessage/src/gonk/SmsService.cpp b/dom/mobilemessage/src/gonk/SmsService.cpp index 7e9546fbaf7..484dd94091a 100644 --- a/dom/mobilemessage/src/gonk/SmsService.cpp +++ b/dom/mobilemessage/src/gonk/SmsService.cpp @@ -42,11 +42,42 @@ SmsService::GetSegmentInfoForText(const nsAString & aText, NS_IMETHODIMP SmsService::Send(const nsAString& aNumber, const nsAString& aMessage, + const bool aSilent, nsIMobileMessageCallback* aRequest) { NS_ENSURE_TRUE(mRadioInterface, NS_ERROR_FAILURE); - return mRadioInterface->SendSMS(aNumber, aMessage, aRequest); + return mRadioInterface->SendSMS(aNumber, aMessage, aSilent, aRequest); +} + +NS_IMETHODIMP +SmsService::IsSilentNumber(const nsAString& aNumber, + bool* aIsSilent) +{ + *aIsSilent = mSilentNumbers.Contains(aNumber); + return NS_OK; +} + +NS_IMETHODIMP +SmsService::AddSilentNumber(const nsAString& aNumber) +{ + if (mSilentNumbers.Contains(aNumber)) { + return NS_ERROR_UNEXPECTED; + } + + NS_ENSURE_TRUE(mSilentNumbers.AppendElement(aNumber), NS_ERROR_FAILURE); + return NS_OK; +} + +NS_IMETHODIMP +SmsService::RemoveSilentNumber(const nsAString& aNumber) +{ + if (!mSilentNumbers.Contains(aNumber)) { + return NS_ERROR_INVALID_ARG; + } + + NS_ENSURE_TRUE(mSilentNumbers.RemoveElement(aNumber), NS_ERROR_FAILURE); + return NS_OK; } } // namespace mobilemessage diff --git a/dom/mobilemessage/src/gonk/SmsService.h b/dom/mobilemessage/src/gonk/SmsService.h index 7cacae2d0cb..940cbf2fa81 100644 --- a/dom/mobilemessage/src/gonk/SmsService.h +++ b/dom/mobilemessage/src/gonk/SmsService.h @@ -8,6 +8,8 @@ #include "nsISmsService.h" #include "nsCOMPtr.h" #include "nsIRadioInterfaceLayer.h" +#include "nsTArray.h" +#include "nsString.h" namespace mozilla { namespace dom { @@ -23,6 +25,7 @@ public: protected: // TODO: Bug 854326 - B2G Multi-SIM: support multiple SIM cards for SMS/MMS nsCOMPtr mRadioInterface; + nsTArray mSilentNumbers; }; } // namespace mobilemessage diff --git a/dom/mobilemessage/src/ipc/PSms.ipdl b/dom/mobilemessage/src/ipc/PSms.ipdl index c792efc341f..57bb49e70ad 100644 --- a/dom/mobilemessage/src/ipc/PSms.ipdl +++ b/dom/mobilemessage/src/ipc/PSms.ipdl @@ -26,6 +26,7 @@ struct SendSmsMessageRequest { nsString number; nsString message; + bool silent; }; union SendMessageRequest @@ -100,6 +101,8 @@ child: NotifyDeliveryErrorMessage(MobileMessageData aMessageData); + NotifyReceivedSilentMessage(MobileMessageData aMessageData); + parent: /** * Sent when the child no longer needs to use sms. @@ -121,6 +124,9 @@ parent: sync GetSegmentInfoForText(nsString aText) returns (SmsSegmentInfoData aResult); + + AddSilentNumber(nsString aNumber); + RemoveSilentNumber(nsString aNumber); }; } // namespace mobilemessage diff --git a/dom/mobilemessage/src/ipc/SmsChild.cpp b/dom/mobilemessage/src/ipc/SmsChild.cpp index 27396ba0890..3b90b5092aa 100644 --- a/dom/mobilemessage/src/ipc/SmsChild.cpp +++ b/dom/mobilemessage/src/ipc/SmsChild.cpp @@ -109,6 +109,13 @@ SmsChild::RecvNotifyDeliveryErrorMessage(const MobileMessageData& aData) return true; } +bool +SmsChild::RecvNotifyReceivedSilentMessage(const MobileMessageData& aData) +{ + NotifyObserversWithMobileMessage(kSilentSmsReceivedObserverTopic, aData); + return true; +} + PSmsRequestChild* SmsChild::AllocPSmsRequestChild(const IPCSmsRequest& aRequest) { diff --git a/dom/mobilemessage/src/ipc/SmsChild.h b/dom/mobilemessage/src/ipc/SmsChild.h index 667a9bbdd20..af799f0b83c 100644 --- a/dom/mobilemessage/src/ipc/SmsChild.h +++ b/dom/mobilemessage/src/ipc/SmsChild.h @@ -55,6 +55,9 @@ protected: virtual bool RecvNotifyDeliveryErrorMessage(const MobileMessageData& aMessage) MOZ_OVERRIDE; + virtual bool + RecvNotifyReceivedSilentMessage(const MobileMessageData& aMessage) MOZ_OVERRIDE; + virtual PSmsRequestChild* AllocPSmsRequestChild(const IPCSmsRequest& aRequest) MOZ_OVERRIDE; diff --git a/dom/mobilemessage/src/ipc/SmsIPCService.cpp b/dom/mobilemessage/src/ipc/SmsIPCService.cpp index 14eb23d60af..1dcce42e96d 100644 --- a/dom/mobilemessage/src/ipc/SmsIPCService.cpp +++ b/dom/mobilemessage/src/ipc/SmsIPCService.cpp @@ -115,13 +115,43 @@ SmsIPCService::GetSegmentInfoForText(const nsAString & aText, NS_IMETHODIMP SmsIPCService::Send(const nsAString& aNumber, const nsAString& aMessage, + const bool aSilent, nsIMobileMessageCallback* aRequest) { return SendRequest(SendMessageRequest(SendSmsMessageRequest(nsString(aNumber), - nsString(aMessage))), + nsString(aMessage), + aSilent)), aRequest); } +NS_IMETHODIMP +SmsIPCService::IsSilentNumber(const nsAString& aNumber, + bool* aIsSilent) +{ + NS_ERROR("We should not be here!"); + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +SmsIPCService::AddSilentNumber(const nsAString& aNumber) +{ + PSmsChild* smsChild = GetSmsChild(); + NS_ENSURE_TRUE(smsChild, NS_ERROR_FAILURE); + + smsChild->SendAddSilentNumber(nsString(aNumber)); + return NS_OK; +} + +NS_IMETHODIMP +SmsIPCService::RemoveSilentNumber(const nsAString& aNumber) +{ + PSmsChild* smsChild = GetSmsChild(); + NS_ENSURE_TRUE(smsChild, NS_ERROR_FAILURE); + + smsChild->SendRemoveSilentNumber(nsString(aNumber)); + return NS_OK; +} + /* * Implementation of nsIMobileMessageDatabaseService. */ diff --git a/dom/mobilemessage/src/ipc/SmsParent.cpp b/dom/mobilemessage/src/ipc/SmsParent.cpp index f44dfb52e78..3d84e381e1d 100644 --- a/dom/mobilemessage/src/ipc/SmsParent.cpp +++ b/dom/mobilemessage/src/ipc/SmsParent.cpp @@ -151,6 +151,7 @@ SmsParent::SmsParent() obs->AddObserver(this, kSmsFailedObserverTopic, false); obs->AddObserver(this, kSmsDeliverySuccessObserverTopic, false); obs->AddObserver(this, kSmsDeliveryErrorObserverTopic, false); + obs->AddObserver(this, kSilentSmsReceivedObserverTopic, false); } void @@ -168,6 +169,7 @@ SmsParent::ActorDestroy(ActorDestroyReason why) obs->RemoveObserver(this, kSmsFailedObserverTopic); obs->RemoveObserver(this, kSmsDeliverySuccessObserverTopic); obs->RemoveObserver(this, kSmsDeliveryErrorObserverTopic); + obs->RemoveObserver(this, kSilentSmsReceivedObserverTopic); } NS_IMETHODIMP @@ -251,6 +253,24 @@ SmsParent::Observe(nsISupports* aSubject, const char* aTopic, return NS_OK; } + if (!strcmp(aTopic, kSilentSmsReceivedObserverTopic)) { + nsCOMPtr smsMsg = do_QueryInterface(aSubject); + if (!smsMsg) { + return NS_OK; + } + + nsString sender; + if (NS_FAILED(smsMsg->GetSender(sender)) || + !mSilentNumbers.Contains(sender)) { + return NS_OK; + } + + MobileMessageData msgData = + static_cast(smsMsg.get())->GetData(); + unused << SendNotifyReceivedSilentMessage(msgData); + return NS_OK; + } + return NS_OK; } @@ -320,6 +340,42 @@ SmsParent::RecvGetSegmentInfoForText(const nsString& aText, return true; } +bool +SmsParent::RecvAddSilentNumber(const nsString& aNumber) +{ + if (mSilentNumbers.Contains(aNumber)) { + return true; + } + + nsCOMPtr smsService = do_GetService(SMS_SERVICE_CONTRACTID); + NS_ENSURE_TRUE(smsService, true); + + nsresult rv = smsService->AddSilentNumber(aNumber); + if (NS_SUCCEEDED(rv)) { + mSilentNumbers.AppendElement(aNumber); + } + + return true; +} + +bool +SmsParent::RecvRemoveSilentNumber(const nsString& aNumber) +{ + if (!mSilentNumbers.Contains(aNumber)) { + return true; + } + + nsCOMPtr smsService = do_GetService(SMS_SERVICE_CONTRACTID); + NS_ENSURE_TRUE(smsService, true); + + nsresult rv = smsService->RemoveSilentNumber(aNumber); + if (NS_SUCCEEDED(rv)) { + mSilentNumbers.RemoveElement(aNumber); + } + + return true; +} + bool SmsParent::RecvPSmsRequestConstructor(PSmsRequestParent* aActor, const IPCSmsRequest& aRequest) @@ -422,7 +478,7 @@ SmsRequestParent::DoRequest(const SendMessageRequest& aRequest) NS_ENSURE_TRUE(smsService, true); const SendSmsMessageRequest &data = aRequest.get_SendSmsMessageRequest(); - smsService->Send(data.number(), data.message(), this); + smsService->Send(data.number(), data.message(), data.silent(), this); } break; case SendMessageRequest::TSendMmsMessageRequest: { diff --git a/dom/mobilemessage/src/ipc/SmsParent.h b/dom/mobilemessage/src/ipc/SmsParent.h index 05dc921c6c4..c5757e6fc00 100644 --- a/dom/mobilemessage/src/ipc/SmsParent.h +++ b/dom/mobilemessage/src/ipc/SmsParent.h @@ -37,6 +37,12 @@ protected: virtual bool RecvGetSegmentInfoForText(const nsString& aText, SmsSegmentInfoData* aResult) MOZ_OVERRIDE; + virtual bool + RecvAddSilentNumber(const nsString& aNumber) MOZ_OVERRIDE; + + virtual bool + RecvRemoveSilentNumber(const nsString& aNumber) MOZ_OVERRIDE; + SmsParent(); virtual ~SmsParent() { @@ -68,6 +74,9 @@ protected: bool GetMobileMessageDataFromMessage(nsISupports* aMsg, MobileMessageData& aData); + +private: + nsTArray mSilentNumbers; }; class SmsRequestParent : public PSmsRequestParent