2012-09-26 22:15:22 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* 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 "BluetoothRilListener.h"
|
|
|
|
|
|
|
|
#include "BluetoothHfpManager.h"
|
|
|
|
#include "nsRadioInterfaceLayer.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
|
|
|
USING_BLUETOOTH_NAMESPACE
|
|
|
|
|
|
|
|
class BluetoothRILTelephonyCallback : public nsIRILTelephonyCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIRILTELEPHONYCALLBACK
|
|
|
|
|
|
|
|
BluetoothRILTelephonyCallback() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(BluetoothRILTelephonyCallback, nsIRILTelephonyCallback)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-10-01 13:04:09 -07:00
|
|
|
BluetoothRILTelephonyCallback::CallStateChanged(uint32_t aCallIndex,
|
|
|
|
uint16_t aCallState,
|
2012-09-26 22:15:22 -07:00
|
|
|
const nsAString& aNumber,
|
|
|
|
bool aIsActive)
|
|
|
|
{
|
|
|
|
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
|
|
|
|
hfp->CallStateChanged(aCallIndex, aCallState,
|
|
|
|
NS_ConvertUTF16toUTF8(aNumber).get(), aIsActive);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-10-01 13:04:09 -07:00
|
|
|
BluetoothRILTelephonyCallback::EnumerateCallState(uint32_t aCallIndex,
|
|
|
|
uint16_t aCallState,
|
2012-09-26 22:15:22 -07:00
|
|
|
const nsAString_internal& aNumber,
|
|
|
|
bool aIsActive,
|
|
|
|
bool* aResult)
|
|
|
|
{
|
2012-10-09 04:19:29 -07:00
|
|
|
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
|
|
|
|
hfp->EnumerateCallState(aCallIndex, aCallState,
|
|
|
|
NS_ConvertUTF16toUTF8(aNumber).get(), aIsActive);
|
2012-09-26 22:15:22 -07:00
|
|
|
*aResult = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-10-01 13:04:09 -07:00
|
|
|
BluetoothRILTelephonyCallback::NotifyError(int32_t aCallIndex,
|
2012-09-26 22:15:22 -07:00
|
|
|
const nsAString& aError)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
BluetoothRilListener::BluetoothRilListener()
|
|
|
|
{
|
|
|
|
mRILTelephonyCallback = new BluetoothRILTelephonyCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BluetoothRilListener::StartListening()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRILContentHelper> ril = do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
|
|
|
|
if (!ril) {
|
|
|
|
NS_ERROR("No RIL Service!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = ril->RegisterTelephonyCallback(mRILTelephonyCallback);
|
2012-11-14 03:25:19 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
rv = ril->RegisterTelephonyMsg();
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2012-09-26 22:15:22 -07:00
|
|
|
|
2012-11-14 03:25:19 -08:00
|
|
|
return true;
|
2012-09-26 22:15:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BluetoothRilListener::StopListening()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRILContentHelper> ril = do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
|
|
|
|
if (!ril) {
|
|
|
|
NS_ERROR("No RIL Service!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = ril->UnregisterTelephonyCallback(mRILTelephonyCallback);
|
|
|
|
|
|
|
|
return NS_FAILED(rv) ? false : true;
|
|
|
|
}
|
2012-10-09 04:19:29 -07:00
|
|
|
|
|
|
|
nsIRILTelephonyCallback*
|
|
|
|
BluetoothRilListener::GetCallback()
|
|
|
|
{
|
|
|
|
return mRILTelephonyCallback;
|
|
|
|
}
|