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/. */
|
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
#include "IccManager.h"
|
2014-04-16 00:30:28 -07:00
|
|
|
#include "mozilla/dom/MozIccManagerBinding.h"
|
2013-10-09 02:40:12 -07:00
|
|
|
#include "Icc.h"
|
|
|
|
#include "IccListener.h"
|
|
|
|
#include "mozilla/dom/IccChangeEvent.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2014-09-19 00:53:05 -07:00
|
|
|
#include "nsIIccInfo.h"
|
2012-04-10 05:04:27 -07:00
|
|
|
|
2013-10-22 04:23:00 -07:00
|
|
|
using namespace mozilla::dom;
|
2012-06-11 04:28:16 -07:00
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IccManager)
|
2013-03-06 01:53:27 -08:00
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IccManager,
|
2014-03-31 23:13:50 -07:00
|
|
|
DOMEventTargetHelper)
|
2013-10-09 02:40:12 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IccManager,
|
2014-03-31 23:13:50 -07:00
|
|
|
DOMEventTargetHelper)
|
2013-10-09 02:40:12 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2014-04-16 00:30:28 -07:00
|
|
|
// QueryInterface implementation for IccManager
|
2013-10-09 02:40:12 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IccManager)
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(IccManager, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(IccManager, DOMEventTargetHelper)
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
IccManager::IccManager(nsPIDOMWindow* aWindow)
|
2014-04-16 00:30:28 -07:00
|
|
|
: DOMEventTargetHelper(aWindow)
|
2012-06-28 07:21:48 -07:00
|
|
|
{
|
2013-10-09 02:40:12 -07:00
|
|
|
uint32_t numberOfServices =
|
|
|
|
mozilla::Preferences::GetUint("ril.numRadioInterfaces", 1);
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
for (uint32_t i = 0; i < numberOfServices; i++) {
|
|
|
|
nsRefPtr<IccListener> iccListener = new IccListener(this, i);
|
|
|
|
mIccListeners.AppendElement(iccListener);
|
2012-04-10 05:04:27 -07:00
|
|
|
}
|
2012-06-28 07:21:48 -07:00
|
|
|
}
|
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
IccManager::~IccManager()
|
2012-06-28 07:21:48 -07:00
|
|
|
{
|
2013-10-09 02:40:12 -07:00
|
|
|
Shutdown();
|
2014-04-16 00:30:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
IccManager::WrapObject(JSContext* aCx)
|
|
|
|
{
|
|
|
|
return MozIccManagerBinding::Wrap(aCx, this);
|
2012-09-12 00:24:58 -07:00
|
|
|
}
|
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
void
|
|
|
|
IccManager::Shutdown()
|
2013-05-30 03:36:10 -07:00
|
|
|
{
|
2013-10-09 02:40:12 -07:00
|
|
|
for (uint32_t i = 0; i < mIccListeners.Length(); i++) {
|
|
|
|
mIccListeners[i]->Shutdown();
|
|
|
|
mIccListeners[i] = nullptr;
|
2013-05-30 03:36:10 -07:00
|
|
|
}
|
2013-10-09 02:40:12 -07:00
|
|
|
mIccListeners.Clear();
|
2013-05-30 03:36:10 -07:00
|
|
|
}
|
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
nsresult
|
|
|
|
IccManager::NotifyIccAdd(const nsAString& aIccId)
|
2013-05-22 01:58:44 -07:00
|
|
|
{
|
2014-04-16 00:30:28 -07:00
|
|
|
MozIccManagerBinding::ClearCachedIccIdsValue(this);
|
2013-05-22 01:58:44 -07:00
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
IccChangeEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mIccId = aIccId;
|
2013-10-14 21:21:36 -07:00
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
nsRefPtr<IccChangeEvent> event =
|
|
|
|
IccChangeEvent::Constructor(this, NS_LITERAL_STRING("iccdetected"), init);
|
2013-05-22 01:58:44 -07:00
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
return DispatchTrustedEvent(event);
|
2013-04-10 20:45:39 -07:00
|
|
|
}
|
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
nsresult
|
|
|
|
IccManager::NotifyIccRemove(const nsAString& aIccId)
|
2013-04-10 20:45:39 -07:00
|
|
|
{
|
2014-04-16 00:30:28 -07:00
|
|
|
MozIccManagerBinding::ClearCachedIccIdsValue(this);
|
2013-04-10 20:45:39 -07:00
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
IccChangeEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mIccId = aIccId;
|
2013-04-10 20:45:39 -07:00
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
nsRefPtr<IccChangeEvent> event =
|
|
|
|
IccChangeEvent::Constructor(this, NS_LITERAL_STRING("iccundetected"), init);
|
2013-04-10 20:45:39 -07:00
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
return DispatchTrustedEvent(event);
|
2013-04-10 20:45:39 -07:00
|
|
|
}
|
|
|
|
|
2014-04-16 00:30:28 -07:00
|
|
|
// MozIccManager
|
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
|
|
|
|
2013-10-09 02:40:12 -07:00
|
|
|
void
|
2014-04-16 00:30:28 -07:00
|
|
|
IccManager::GetIccIds(nsTArray<nsString>& aIccIds)
|
2013-02-25 01:27:23 -08:00
|
|
|
{
|
2014-04-16 00:30:28 -07:00
|
|
|
nsTArray<nsRefPtr<IccListener>>::size_type i;
|
|
|
|
for (i = 0; i < mIccListeners.Length(); ++i) {
|
2014-05-19 10:20:21 -07:00
|
|
|
Icc* icc = mIccListeners[i]->GetIcc();
|
2014-04-16 00:30:28 -07:00
|
|
|
if (icc) {
|
|
|
|
aIccIds.AppendElement(icc->GetIccId());
|
2013-10-09 02:40:12 -07:00
|
|
|
}
|
2012-12-24 02:38:49 -08:00
|
|
|
}
|
|
|
|
}
|
2013-02-25 01:27:23 -08:00
|
|
|
|
2014-05-19 10:20:21 -07:00
|
|
|
Icc*
|
2014-04-16 00:30:28 -07:00
|
|
|
IccManager::GetIccById(const nsAString& aIccId) const
|
2013-03-06 01:53:27 -08:00
|
|
|
{
|
2014-04-16 00:30:28 -07:00
|
|
|
nsTArray<nsRefPtr<IccListener>>::size_type i;
|
|
|
|
for (i = 0; i < mIccListeners.Length(); ++i) {
|
2014-05-19 10:20:21 -07:00
|
|
|
Icc* icc = mIccListeners[i]->GetIcc();
|
2013-10-09 02:40:12 -07:00
|
|
|
if (icc && aIccId == icc->GetIccId()) {
|
2014-05-19 10:20:21 -07:00
|
|
|
return icc;
|
2013-10-09 02:40:12 -07:00
|
|
|
}
|
2013-07-17 16:18:00 -07:00
|
|
|
}
|
2014-04-16 00:30:28 -07:00
|
|
|
return nullptr;
|
2013-05-30 03:36:10 -07:00
|
|
|
}
|