Bug 1114938 - Part 2.1: (Gonk) Refactor Stk Proactive Commands from IccProvider to IccService. r=echen

This commit is contained in:
Bevis Tseng 2015-04-27 16:01:56 +08:00
parent e89472499d
commit 4dc1a2216d
13 changed files with 52 additions and 79 deletions

View File

@ -38,7 +38,7 @@ IccListener::NotifyIccInfoChanged()
}
NS_IMETHODIMP
IccListener::NotifyStkCommand(const nsAString & aMessage)
IccListener::NotifyStkCommand(nsIStkProactiveCmd *aStkProactiveCmd)
{
return NS_OK;
}

View File

@ -37,7 +37,7 @@ IccListener::NotifyIccInfoChanged()
}
NS_IMETHODIMP
IccListener::NotifyStkCommand(const nsAString & aMessage)
IccListener::NotifyStkCommand(nsIStkProactiveCmd *aStkProactiveCmd)
{
return NS_OK;
}

View File

@ -15,7 +15,8 @@
#include "nsIIccInfo.h"
#include "nsIIccProvider.h"
#include "nsIIccService.h"
#include "nsJSON.h"
#include "nsIStkCmdFactory.h"
#include "nsIStkProactiveCmd.h"
#include "nsRadioInterfaceLayer.h"
#include "nsServiceManagerUtils.h"
@ -99,7 +100,7 @@ Icc::NotifyEvent(const nsAString& aName)
}
nsresult
Icc::NotifyStkEvent(const nsAString& aName, const nsAString& aMessage)
Icc::NotifyStkEvent(const nsAString& aName, nsIStkProactiveCmd* aStkProactiveCmd)
{
AutoJSAPI jsapi;
if (NS_WARN_IF(!jsapi.InitWithLegacyErrorReporting(GetOwner()))) {
@ -108,13 +109,12 @@ Icc::NotifyStkEvent(const nsAString& aName, const nsAString& aMessage)
JSContext* cx = jsapi.cx();
JS::Rooted<JS::Value> value(cx);
if (!aMessage.IsEmpty()) {
nsCOMPtr<nsIJSON> json(new nsJSON());
nsresult rv = json->DecodeToJSVal(aMessage, cx, &value);
NS_ENSURE_SUCCESS(rv, rv);
} else {
value = JS::NullValue();
}
nsCOMPtr<nsIStkCmdFactory> cmdFactory =
do_GetService(ICC_STK_CMD_FACTORY_CONTRACTID);
NS_ENSURE_TRUE(cmdFactory, NS_ERROR_UNEXPECTED);
cmdFactory->CreateCommandMessage(aStkProactiveCmd, &value);
NS_ENSURE_TRUE(value.isObject(), NS_ERROR_UNEXPECTED);
MozStkCommandEventInit init;
init.mBubbles = false;

View File

@ -13,6 +13,7 @@
class nsIIcc;
class nsIIccInfo;
class nsIIccProvider;
class nsIStkProactiveCmd;
namespace mozilla {
namespace dom {
@ -38,7 +39,7 @@ public:
NotifyEvent(const nsAString& aName);
nsresult
NotifyStkEvent(const nsAString& aName, const nsAString& aMessage);
NotifyStkEvent(const nsAString& aName, nsIStkProactiveCmd* aStkProactiveCmd);
nsString
GetIccId()

View File

@ -22,15 +22,6 @@ IccListener::IccListener(IccManager* aIccManager, uint32_t aClientId)
{
MOZ_ASSERT(mIccManager);
// TODO: Bug 1114938, Refactor STK in MozIcc.webidl with IPDL.
// Remove the registration to IccProvider.
mProvider = do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
if (!mProvider) {
NS_WARNING("Could not acquire nsIIccProvider!");
return;
}
nsCOMPtr<nsIIccService> iccService = do_GetService(ICC_SERVICE_CONTRACTID);
if (!iccService) {
@ -57,10 +48,6 @@ IccListener::IccListener(IccManager* aIccManager, uint32_t aClientId)
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);
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Failed registering icc messages with provider");
}
IccListener::~IccListener()
@ -71,13 +58,6 @@ IccListener::~IccListener()
void
IccListener::Shutdown()
{
// TODO: Bug 1114938, Refactor STK in MozIcc.webidl with IPDL.
// Remove the unregistration to IccProvider.
if (mProvider) {
mProvider->UnregisterIccMsg(mClientId, this);
mProvider = nullptr;
}
if (mHandler) {
mHandler->UnregisterListener(this);
mHandler = nullptr;
@ -94,13 +74,13 @@ IccListener::Shutdown()
// nsIIccListener
NS_IMETHODIMP
IccListener::NotifyStkCommand(const nsAString& aMessage)
IccListener::NotifyStkCommand(nsIStkProactiveCmd *aStkProactiveCmd)
{
if (!mIcc) {
return NS_OK;
}
return mIcc->NotifyStkEvent(NS_LITERAL_STRING("stkcommand"), aMessage);
return mIcc->NotifyStkEvent(NS_LITERAL_STRING("stkcommand"), aStkProactiveCmd);
}
NS_IMETHODIMP

View File

@ -45,9 +45,6 @@ private:
// IccListener, this will release the reference and break the cycle.
nsRefPtr<Icc> mIcc;
nsRefPtr<IccManager> mIccManager;
// mProvider is a xpcom service and will be released at Shutdown(), so it
// doesn't need to be cycle collected.
nsCOMPtr<nsIIccProvider> mProvider;
// mHandler will be released at Shutdown(), there is no need to join cycle
// collection.
nsCOMPtr<nsIIcc> mHandler;

View File

@ -29,6 +29,10 @@ XPCOMUtils.defineLazyServiceGetter(this, "gMobileConnectionService",
"@mozilla.org/mobileconnection/mobileconnectionservice;1",
"nsIGonkMobileConnectionService");
XPCOMUtils.defineLazyServiceGetter(this, "gIccMessenger",
"@mozilla.org/ril/system-messenger-helper;1",
"nsIIccMessenger");
let DEBUG = RIL.DEBUG_RIL;
function debug(s) {
dump("IccService: " + s);
@ -124,6 +128,27 @@ IccService.prototype = {
/**
* nsIGonkIccService interface.
*/
notifyStkCommand: function(aServiceId, aStkcommand) {
if (DEBUG) {
debug("notifyStkCommand for service Id: " + aServiceId);
}
let icc = this.getIccByServiceId(aServiceId);
gIccMessenger.notifyStkProactiveCommand(icc.iccInfo.iccid, aStkcommand);
icc._deliverListenerEvent("notifyStkCommand", [aStkcommand]);
},
notifyStkSessionEnd: function(aServiceId) {
if (DEBUG) {
debug("notifyStkSessionEnd for service Id: " + aServiceId);
}
this.getIccByServiceId(aServiceId)
._deliverListenerEvent("notifyStkSessionEnd");
},
notifyCardStateChanged: function(aServiceId, aCardState) {
if (DEBUG) {
debug("notifyCardStateChanged for service Id: " + aServiceId +

View File

@ -9,12 +9,11 @@
"@mozilla.org/icc/gonkiccservice;1"
%}
[scriptable, uuid(a037b8a2-b027-11e4-9496-c3b7af59a512)]
[scriptable, uuid(cdcdd800-ef24-11e4-99e7-1f0f5f2576c5)]
interface nsIGonkIccService : nsIIccService
{
// TODO: Bug 1114938 - Refactor STK in MozIcc.webidl with IPDL:
// void notifyStkCommand(in unsigned long aServiceId, in jsval aStkcommand);
// void notifyStkSessionEnd(in unsigned long aServiceId);
void notifyStkCommand(in unsigned long aServiceId, in nsIStkProactiveCmd aStkcommand);
void notifyStkSessionEnd(in unsigned long aServiceId);
void notifyCardStateChanged(in unsigned long aServiceId, in unsigned long aCardState);
void notifyIccInfoChanged(in unsigned long aServiceId, in jsval aIccInfo);
void notifyImsiChanged(in unsigned long aServiceId, in DOMString aImsi);

View File

@ -6,22 +6,13 @@
interface nsIDOMDOMRequest;
interface nsIDOMWindow;
interface nsIIccListener;
/**
* XPCOM component (in the content process) that provides the ICC information.
*/
[scriptable, uuid(2fbacfc4-f52d-11e4-9667-33b72f279d14)]
[scriptable, uuid(b331eb34-006e-11e5-aabc-1341ac30c5f9)]
interface nsIIccProvider : nsISupports
{
/**
* Called when a content process registers receiving unsolicited messages from
* RadioInterfaceLayer in the chrome process. Only a content process that has
* the 'mobileconnection' permission is allowed to register.
*/
void registerIccMsg(in unsigned long clientId, in nsIIccListener listener);
void unregisterIccMsg(in unsigned long clientId, in nsIIccListener listener);
/**
* STK interfaces.
*/

View File

@ -6,11 +6,12 @@
interface nsIIcc;
interface nsIIccInfo;
interface nsIStkProactiveCmd;
[scriptable, uuid(7c0ada3d-d8d4-493e-9243-fa3df39855e4)]
[scriptable, uuid(71b33012-eca2-11e4-a40d-9ff040a6fe2a)]
interface nsIIccListener : nsISupports
{
void notifyStkCommand(in DOMString aMessage);
void notifyStkCommand(in nsIStkProactiveCmd aStkProactiveCmd);
void notifyStkSessionEnd();
void notifyCardStateChanged();
void notifyIccInfoChanged();

View File

@ -154,7 +154,7 @@ IccParent::RecvPIccRequestConstructor(PIccRequestParent* aActor,
NS_IMPL_ISUPPORTS(IccParent, nsIIccListener)
NS_IMETHODIMP
IccParent::NotifyStkCommand(const nsAString & aMessage)
IccParent::NotifyStkCommand(nsIStkProactiveCmd *aStkProactiveCmd)
{
// Bug 1114938 - [B2G][ICC] Refactor STK in MozIcc.webidl with IPDL.
return NS_ERROR_NOT_IMPLEMENTED;

View File

@ -1129,7 +1129,7 @@ MobileConnection::NotifyNetworkSelectionModeChanged()
// nsIIccListener
NS_IMETHODIMP
MobileConnection::NotifyStkCommand(const nsAString& aMessage)
MobileConnection::NotifyStkCommand(nsIStkProactiveCmd *aStkProactiveCmd)
{
return NS_OK;
}

View File

@ -157,10 +157,6 @@ XPCOMUtils.defineLazyServiceGetter(this, "gCellBroadcastService",
"@mozilla.org/cellbroadcast/cellbroadcastservice;1",
"nsIGonkCellBroadcastService");
XPCOMUtils.defineLazyServiceGetter(this, "gIccMessenger",
"@mozilla.org/ril/system-messenger-helper;1",
"nsIIccMessenger");
XPCOMUtils.defineLazyServiceGetter(this, "gDataCallManager",
"@mozilla.org/datacall/manager;1",
"nsIDataCallManager");
@ -966,11 +962,6 @@ RadioInterface.prototype = {
Services.obs.removeObserver(this, kNetworkConnStateChangedTopic);
},
getIccInfo: function() {
let icc = gIccService.getIccByServiceId(this.clientId);
return icc ? icc.iccInfo : null;
},
isCardPresent: function() {
let icc = gIccService.getIccByServiceId(this.clientId);
let cardState = icc ? icc.cardState : Ci.nsIIcc.CARD_STATE_UNKNOWN;
@ -1097,11 +1088,11 @@ RadioInterface.prototype = {
this.handleIccMwis(message.mwi);
break;
case "stkcommand":
this.handleStkProactiveCommand(message);
gIccService.notifyStkCommand(this.clientId,
gStkCmdFactory.createCommand(message));
break;
case "stksessionend":
// TODO: Bug 815526, deprecate RILContentHelper.
gMessageManager.sendIccMessage("RIL:StkSessionEnd", this.clientId, null);
gIccService.notifyStkSessionEnd(this.clientId);
break;
case "cdma-info-rec-received":
this.handleCdmaInformationRecords(message.records);
@ -1290,18 +1281,6 @@ RadioInterface.prototype = {
null, null);
},
handleStkProactiveCommand: function(message) {
if (DEBUG) this.debug("handleStkProactiveCommand " + JSON.stringify(message));
let iccInfo = this.getIccInfo();
if (iccInfo && iccInfo.iccid) {
gIccMessenger
.notifyStkProactiveCommand(iccInfo.iccid,
gStkCmdFactory.createCommand(message));
}
// TODO: Bug 815526, deprecate RILContentHelper.
gMessageManager.sendIccMessage("RIL:StkCommand", this.clientId, message);
},
_convertCbGsmGeographicalScope: function(aGeographicalScope) {
return (aGeographicalScope != null)
? aGeographicalScope