2013-10-09 13:40:12 +04: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/. */
|
|
|
|
|
|
|
|
#include "IccListener.h"
|
|
|
|
|
|
|
|
#include "Icc.h"
|
|
|
|
#include "IccManager.h"
|
|
|
|
#include "nsIDOMClassInfo.h"
|
2014-09-19 11:53:05 +04:00
|
|
|
#include "nsIIccInfo.h"
|
2013-10-09 13:40:12 +04:00
|
|
|
#include "nsRadioInterfaceLayer.h"
|
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(IccListener, nsIIccListener)
|
2013-10-09 13:40:12 +04:00
|
|
|
|
|
|
|
IccListener::IccListener(IccManager* aIccManager, uint32_t aClientId)
|
|
|
|
: mClientId(aClientId)
|
|
|
|
, mIccManager(aIccManager)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIccManager);
|
|
|
|
|
2015-01-13 13:03:44 +03:00
|
|
|
// TODO: Bug 1114938, Refactor STK in MozIcc.webidl with IPDL.
|
|
|
|
// Remove the registration to IccProvider.
|
2013-10-09 13:40:12 +04:00
|
|
|
mProvider = do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
|
|
|
|
|
|
|
|
if (!mProvider) {
|
|
|
|
NS_WARNING("Could not acquire nsIIccProvider!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-13 13:03:44 +03:00
|
|
|
nsCOMPtr<nsIIccService> iccService = do_GetService(ICC_SERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
if (!iccService) {
|
|
|
|
NS_WARNING("Could not acquire nsIIccService!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
iccService->GetIccByServiceId(mClientId, getter_AddRefs(mHandler));
|
|
|
|
if (!mHandler) {
|
|
|
|
NS_WARNING("Could not acquire nsIIcc!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-19 11:53:05 +04:00
|
|
|
nsCOMPtr<nsIIccInfo> iccInfo;
|
2015-01-13 13:03:44 +03:00
|
|
|
mHandler->GetIccInfo(getter_AddRefs(iccInfo));
|
2013-10-09 13:40:12 +04:00
|
|
|
if (iccInfo) {
|
|
|
|
nsString iccId;
|
|
|
|
iccInfo->GetIccid(iccId);
|
|
|
|
if (!iccId.IsEmpty()) {
|
2015-01-13 13:03:44 +03:00
|
|
|
mIcc = new Icc(mIccManager->GetOwner(), mClientId, mHandler, iccInfo);
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-13 13:03:44 +03:00
|
|
|
DebugOnly<nsresult> rv = mHandler->RegisterListener(this);
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
|
|
|
|
"Failed registering icc listener with Icc Handler");
|
|
|
|
|
|
|
|
rv = mProvider->RegisterIccMsg(mClientId, this);
|
2013-10-09 13:40:12 +04:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
|
|
|
|
"Failed registering icc messages with provider");
|
|
|
|
}
|
|
|
|
|
|
|
|
IccListener::~IccListener()
|
|
|
|
{
|
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IccListener::Shutdown()
|
|
|
|
{
|
2015-01-13 13:03:44 +03:00
|
|
|
// TODO: Bug 1114938, Refactor STK in MozIcc.webidl with IPDL.
|
|
|
|
// Remove the unregistration to IccProvider.
|
2013-10-09 13:40:12 +04:00
|
|
|
if (mProvider) {
|
|
|
|
mProvider->UnregisterIccMsg(mClientId, this);
|
|
|
|
mProvider = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 13:03:44 +03:00
|
|
|
if (mHandler) {
|
|
|
|
mHandler->UnregisterListener(this);
|
|
|
|
mHandler = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-10-09 13:40:12 +04:00
|
|
|
if (mIcc) {
|
|
|
|
mIcc->Shutdown();
|
|
|
|
mIcc = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mIccManager = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIIccListener
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IccListener::NotifyStkCommand(const nsAString& aMessage)
|
|
|
|
{
|
|
|
|
if (!mIcc) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mIcc->NotifyStkEvent(NS_LITERAL_STRING("stkcommand"), aMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IccListener::NotifyStkSessionEnd()
|
|
|
|
{
|
|
|
|
if (!mIcc) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mIcc->NotifyEvent(NS_LITERAL_STRING("stksessionend"));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IccListener::NotifyCardStateChanged()
|
|
|
|
{
|
|
|
|
if (!mIcc) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mIcc->NotifyEvent(NS_LITERAL_STRING("cardstatechange"));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IccListener::NotifyIccInfoChanged()
|
|
|
|
{
|
2015-01-13 13:03:44 +03:00
|
|
|
if (!mHandler) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-19 11:53:05 +04:00
|
|
|
nsCOMPtr<nsIIccInfo> iccInfo;
|
2015-01-13 13:03:44 +03:00
|
|
|
mHandler->GetIccInfo(getter_AddRefs(iccInfo));
|
2013-10-09 13:40:12 +04:00
|
|
|
|
|
|
|
// Create/delete icc object based on current iccInfo.
|
|
|
|
// 1. If the mIcc is nullptr and iccInfo has valid data, create icc object and
|
|
|
|
// notify mIccManager a new icc is added.
|
|
|
|
// 2. If the mIcc is not nullptr and iccInfo becomes to null, delete existed
|
|
|
|
// icc object and notify mIccManager the icc is removed.
|
|
|
|
if (!mIcc) {
|
|
|
|
if (iccInfo) {
|
|
|
|
nsString iccId;
|
|
|
|
iccInfo->GetIccid(iccId);
|
|
|
|
if (!iccId.IsEmpty()) {
|
2015-01-13 13:03:44 +03:00
|
|
|
mIcc = new Icc(mIccManager->GetOwner(), mClientId, mHandler, iccInfo);
|
2013-10-09 13:40:12 +04:00
|
|
|
mIccManager->NotifyIccAdd(iccId);
|
|
|
|
mIcc->NotifyEvent(NS_LITERAL_STRING("iccinfochange"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-09-19 11:53:05 +04:00
|
|
|
mIcc->UpdateIccInfo(iccInfo);
|
2013-10-09 13:40:12 +04:00
|
|
|
mIcc->NotifyEvent(NS_LITERAL_STRING("iccinfochange"));
|
|
|
|
if (!iccInfo) {
|
|
|
|
nsString iccId = mIcc->GetIccId();
|
|
|
|
mIcc->Shutdown();
|
|
|
|
mIcc = nullptr;
|
|
|
|
mIccManager->NotifyIccRemove(iccId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|