1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "IccListener.h"
8 #include "IccManager.h"
9 #include "nsIDOMClassInfo.h"
10 #include "nsIIccInfo.h"
11 #include "nsRadioInterfaceLayer.h"
13 using namespace mozilla::dom
;
15 NS_IMPL_ISUPPORTS(IccListener
, nsIIccListener
)
17 IccListener::IccListener(IccManager
* aIccManager
, uint32_t aClientId
)
18 : mClientId(aClientId
)
19 , mIccManager(aIccManager
)
21 MOZ_ASSERT(mIccManager
);
23 mProvider
= do_GetService(NS_RILCONTENTHELPER_CONTRACTID
);
26 NS_WARNING("Could not acquire nsIIccProvider!");
30 nsCOMPtr
<nsIIccInfo
> iccInfo
;
31 mProvider
->GetIccInfo(mClientId
, getter_AddRefs(iccInfo
));
34 iccInfo
->GetIccid(iccId
);
35 if (!iccId
.IsEmpty()) {
36 mIcc
= new Icc(mIccManager
->GetOwner(), mClientId
, iccInfo
);
40 DebugOnly
<nsresult
> rv
= mProvider
->RegisterIccMsg(mClientId
, this);
41 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv
),
42 "Failed registering icc messages with provider");
45 IccListener::~IccListener()
51 IccListener::Shutdown()
54 mProvider
->UnregisterIccMsg(mClientId
, this);
63 mIccManager
= nullptr;
69 IccListener::NotifyStkCommand(const nsAString
& aMessage
)
75 return mIcc
->NotifyStkEvent(NS_LITERAL_STRING("stkcommand"), aMessage
);
79 IccListener::NotifyStkSessionEnd()
85 return mIcc
->NotifyEvent(NS_LITERAL_STRING("stksessionend"));
89 IccListener::NotifyCardStateChanged()
95 return mIcc
->NotifyEvent(NS_LITERAL_STRING("cardstatechange"));
99 IccListener::NotifyIccInfoChanged()
101 nsCOMPtr
<nsIIccInfo
> iccInfo
;
102 mProvider
->GetIccInfo(mClientId
, getter_AddRefs(iccInfo
));
104 // Create/delete icc object based on current iccInfo.
105 // 1. If the mIcc is nullptr and iccInfo has valid data, create icc object and
106 // notify mIccManager a new icc is added.
107 // 2. If the mIcc is not nullptr and iccInfo becomes to null, delete existed
108 // icc object and notify mIccManager the icc is removed.
112 iccInfo
->GetIccid(iccId
);
113 if (!iccId
.IsEmpty()) {
114 mIcc
= new Icc(mIccManager
->GetOwner(), mClientId
, iccInfo
);
115 mIccManager
->NotifyIccAdd(iccId
);
116 mIcc
->NotifyEvent(NS_LITERAL_STRING("iccinfochange"));
120 mIcc
->UpdateIccInfo(iccInfo
);
121 mIcc
->NotifyEvent(NS_LITERAL_STRING("iccinfochange"));
123 nsString iccId
= mIcc
->GetIccId();
126 mIccManager
->NotifyIccRemove(iccId
);