Bug 816564 - Silent SMS to Authenticate Device for Mobile Billing. Part 0: WebSMS. sr=vicamo

This commit is contained in:
Fernando Jiménez 2013-07-30 00:50:21 +02:00
parent 90a77457f3
commit c499174641
15 changed files with 208 additions and 13 deletions

View File

@ -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
{
/**

View File

@ -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);
};

View File

@ -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

View File

@ -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")

View File

@ -124,7 +124,8 @@ MobileMessageManager::Send(JSContext* aCx, JS::Handle<JSObject*> aGlobal,
nsCOMPtr<nsIMobileMessageCallback> 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<JSObject*> global(aCx, aGlobal);

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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<nsIRadioInterface> mRadioInterface;
nsTArray<nsString> mSilentNumbers;
};
} // namespace mobilemessage

View File

@ -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

View File

@ -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)
{

View File

@ -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;

View File

@ -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.
*/

View File

@ -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<nsIDOMMozSmsMessage> 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<SmsMessage*>(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<nsISmsService> 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<nsISmsService> 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: {

View File

@ -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<nsString> mSilentNumbers;
};
class SmsRequestParent : public PSmsRequestParent