2012-06-28 07:21:48 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-06-11 04:28:16 -07:00
|
|
|
#include "mozilla/Services.h"
|
2012-06-28 07:21:48 -07:00
|
|
|
#include "nsIDOMClassInfo.h"
|
2013-04-10 20:45:39 -07:00
|
|
|
#include "nsIDOMIccCardLockErrorEvent.h"
|
|
|
|
#include "GeneratedEvents.h"
|
2012-06-28 07:21:48 -07:00
|
|
|
#include "IccManager.h"
|
|
|
|
#include "SimToolKit.h"
|
2012-06-11 04:28:16 -07:00
|
|
|
#include "StkCommandEvent.h"
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2012-04-10 05:04:27 -07:00
|
|
|
#define NS_RILCONTENTHELPER_CONTRACTID "@mozilla.org/ril/content-helper;1"
|
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
using namespace mozilla::dom::icc;
|
2012-06-11 04:28:16 -07:00
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
class IccManager::Listener : public nsIIccListener
|
|
|
|
{
|
|
|
|
IccManager* mIccManager;
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_FORWARD_SAFE_NSIICCLISTENER(mIccManager)
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
Listener(IccManager* aIccManager)
|
|
|
|
: mIccManager(aIccManager)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIccManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Disconnect()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIccManager);
|
|
|
|
mIccManager = nullptr;
|
|
|
|
}
|
|
|
|
};
|
2012-06-11 04:28:16 -07:00
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
NS_IMPL_ISUPPORTS1(IccManager::Listener, nsIIccListener)
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
DOMCI_DATA(MozIccManager, mozilla::dom::icc::IccManager)
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN(IccManager)
|
2012-06-28 07:21:48 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozIccManager)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozIccManager)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(IccManager, nsDOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(IccManager, nsDOMEventTargetHelper)
|
|
|
|
|
|
|
|
IccManager::IccManager()
|
|
|
|
{
|
2012-04-10 05:04:27 -07:00
|
|
|
mProvider = do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
|
|
|
|
|
|
|
|
// Not being able to acquire the provider isn't fatal since we check
|
|
|
|
// for it explicitly below.
|
|
|
|
if (!mProvider) {
|
2013-03-06 01:53:27 -08:00
|
|
|
NS_WARNING("Could not acquire nsIIccProvider!");
|
|
|
|
return;
|
2012-04-10 05:04:27 -07:00
|
|
|
}
|
2013-03-06 01:53:27 -08:00
|
|
|
|
|
|
|
mListener = new Listener(this);
|
|
|
|
DebugOnly<nsresult> rv = mProvider->RegisterIccMsg(mListener);
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
|
|
|
|
"Failed registering icc messages with provider");
|
2012-06-28 07:21:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IccManager::Init(nsPIDOMWindow* aWindow)
|
|
|
|
{
|
|
|
|
BindToOwner(aWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IccManager::Shutdown()
|
|
|
|
{
|
2013-03-06 01:53:27 -08:00
|
|
|
if (mProvider && mListener) {
|
|
|
|
mListener->Disconnect();
|
|
|
|
mProvider->UnregisterIccMsg(mListener);
|
|
|
|
mProvider = nullptr;
|
|
|
|
mListener = nullptr;
|
2012-06-11 04:28:16 -07:00
|
|
|
}
|
2012-06-28 07:21:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMMozIccManager
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-29 14:39:20 -07:00
|
|
|
IccManager::SendStkResponse(const JS::Value& aCommand,
|
|
|
|
const JS::Value& aResponse)
|
2012-06-28 07:21:48 -07:00
|
|
|
{
|
2012-04-10 05:04:27 -07:00
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-08-29 14:39:20 -07:00
|
|
|
mProvider->SendStkResponse(GetOwner(), aCommand, aResponse);
|
2012-04-10 05:04:27 -07:00
|
|
|
return NS_OK;
|
2012-06-28 07:21:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-29 07:56:51 -07:00
|
|
|
IccManager::SendStkMenuSelection(uint16_t aItemIdentifier, bool aHelpRequested)
|
2012-06-28 07:21:48 -07:00
|
|
|
{
|
2012-04-10 05:04:27 -07:00
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mProvider->SendStkMenuSelection(GetOwner(), aItemIdentifier, aHelpRequested);
|
|
|
|
return NS_OK;
|
2012-06-28 07:21:48 -07:00
|
|
|
}
|
|
|
|
|
2012-12-04 03:19:17 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::SendStkTimerExpiration(const JS::Value& aTimer)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mProvider->SendStkTimerExpiration(GetOwner(), aTimer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-12 00:24:58 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::SendStkEventDownload(const JS::Value& aEvent)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mProvider->SendStkEventDownload(GetOwner(), aEvent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-22 01:58:44 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::GetCardState(nsAString& cardState)
|
|
|
|
{
|
|
|
|
cardState.SetIsVoid(true);
|
|
|
|
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return mProvider->GetCardState(cardState);
|
|
|
|
}
|
|
|
|
|
2013-04-10 20:45:39 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::GetCardLock(const nsAString& aLockType, nsIDOMDOMRequest** aDomRequest)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mProvider->GetCardLockState(GetOwner(), aLockType, aDomRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::SetCardLock(const JS::Value& aInfo, nsIDOMDOMRequest** aDomRequest)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mProvider->SetCardLock(GetOwner(), aInfo, aDomRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::UnlockCardLock(const JS::Value& aInfo, nsIDOMDOMRequest** aDomRequest)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mProvider->UnlockCardLock(GetOwner(), aInfo, aDomRequest);
|
|
|
|
}
|
|
|
|
|
Bug 875710: Added getCardLockRetryCount to nsIIccProvider, r=vyang, sr=mounir
This patch adds getCardLockRetryCount to nsIIccProvider and its
implementations. This method allows callers to query the number
of remaining tries for unlocking a SIM-card lock. Supported locks
are 'pin', 'puk', 'pin2', 'puk2', 'nck', 'cck', and 'spck'. The
call returns a DOM request that returns the retry count in its
success handler, or signals an appropriate error.
Reading the retry count is an optional feature and may not be
supported for all lock types. In this case the DOM request receives
and error with the name GECKO_ERROR_NOT_SUPPORTED. For an invalid
lock type, the error name is GECKO_ERROR_GENERIC_FAILURE.
getCardLockRetryCount replaces retryCount in nsIDOMMobileConnection,
which is now deprecated.
--HG--
extra : rebase_source : d1d11612f836652dca85f7c701f09e7af962e3b7
2013-07-09 07:06:05 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::GetCardLockRetryCount(const nsAString& aLockType, nsIDOMDOMRequest** aDomRequest)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mProvider->GetCardLockRetryCount(GetOwner(), aLockType, aDomRequest);
|
|
|
|
}
|
|
|
|
|
2013-02-25 01:27:23 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::IccOpenChannel(const nsAString& aAid, nsIDOMDOMRequest** aRequest)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-02-25 01:36:05 -08:00
|
|
|
return mProvider->IccOpenChannel(GetOwner(), aAid, aRequest);
|
2013-02-25 01:27:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-25 01:36:05 -08:00
|
|
|
IccManager::IccExchangeAPDU(int32_t aChannel, const jsval& aApdu, nsIDOMDOMRequest** aRequest)
|
2013-02-25 01:27:23 -08:00
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-02-25 01:36:05 -08:00
|
|
|
return mProvider->IccExchangeAPDU(GetOwner(), aChannel, aApdu, aRequest);
|
2013-02-25 01:27:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-25 01:36:05 -08:00
|
|
|
IccManager::IccCloseChannel(int32_t aChannel, nsIDOMDOMRequest** aRequest)
|
2013-02-25 01:27:23 -08:00
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-02-25 01:36:05 -08:00
|
|
|
return mProvider->IccCloseChannel(GetOwner(), aChannel, aRequest);
|
2013-02-25 01:27:23 -08:00
|
|
|
}
|
|
|
|
|
2013-03-05 22:09:50 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::ReadContacts(const nsAString& aContactType, nsIDOMDOMRequest** aRequest)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mProvider->ReadContacts(GetOwner(), aContactType, aRequest);
|
|
|
|
}
|
|
|
|
|
2012-12-24 02:38:49 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::UpdateContact(const nsAString& aContactType,
|
|
|
|
nsIDOMContact* aContact,
|
|
|
|
const nsAString& aPin2,
|
|
|
|
nsIDOMDOMRequest** aRequest)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mProvider->UpdateContact(GetOwner(), aContactType, aContact, aPin2, aRequest);
|
|
|
|
}
|
2013-02-25 01:27:23 -08:00
|
|
|
|
2012-06-28 07:21:48 -07:00
|
|
|
NS_IMPL_EVENT_HANDLER(IccManager, stkcommand)
|
|
|
|
NS_IMPL_EVENT_HANDLER(IccManager, stksessionend)
|
2013-04-10 20:45:39 -07:00
|
|
|
NS_IMPL_EVENT_HANDLER(IccManager, icccardlockerror)
|
2013-05-22 01:58:44 -07:00
|
|
|
NS_IMPL_EVENT_HANDLER(IccManager, cardstatechange)
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
// nsIIccListener
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::NotifyStkCommand(const nsAString& aMessage)
|
|
|
|
{
|
2013-03-09 03:34:29 -08:00
|
|
|
nsRefPtr<StkCommandEvent> event = StkCommandEvent::Create(this, aMessage);
|
2013-03-06 01:53:27 -08:00
|
|
|
NS_ASSERTION(event, "This should never fail!");
|
|
|
|
|
2013-04-19 15:18:33 -07:00
|
|
|
return event->Dispatch(this, NS_LITERAL_STRING("stkcommand"));
|
2013-03-06 01:53:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::NotifyStkSessionEnd()
|
|
|
|
{
|
|
|
|
return DispatchTrustedEvent(NS_LITERAL_STRING("stksessionend"));
|
|
|
|
}
|
2013-04-10 20:45:39 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::NotifyIccCardLockError(const nsAString& aLockType, uint32_t aRetryCount)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
|
|
|
NS_NewDOMIccCardLockErrorEvent(getter_AddRefs(event), this, nullptr, nullptr);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMIccCardLockErrorEvent> ce = do_QueryInterface(event);
|
|
|
|
nsresult rv =
|
|
|
|
ce->InitIccCardLockErrorEvent(NS_LITERAL_STRING("icccardlockerror"),
|
|
|
|
false, false, aLockType, aRetryCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return DispatchTrustedEvent(ce);
|
|
|
|
}
|
2013-05-22 01:58:44 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::NotifyCardStateChanged()
|
|
|
|
{
|
|
|
|
return DispatchTrustedEvent(NS_LITERAL_STRING("cardstatechange"));
|
|
|
|
}
|