This repository has been archived by the owner on Apr 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 305
/
BluetoothRilListener.cpp
101 lines (83 loc) · 2.86 KB
/
BluetoothRilListener.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* -*- 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
BluetoothRILTelephonyCallback::CallStateChanged(uint32_t aCallIndex,
uint16_t aCallState,
const nsAString& aNumber,
bool aIsActive)
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->CallStateChanged(aCallIndex, aCallState,
NS_ConvertUTF16toUTF8(aNumber).get(), aIsActive);
return NS_OK;
}
NS_IMETHODIMP
BluetoothRILTelephonyCallback::EnumerateCallState(uint32_t aCallIndex,
uint16_t aCallState,
const nsAString_internal& aNumber,
bool aIsActive,
bool* aResult)
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->EnumerateCallState(aCallIndex, aCallState,
NS_ConvertUTF16toUTF8(aNumber).get(), aIsActive);
*aResult = true;
return NS_OK;
}
NS_IMETHODIMP
BluetoothRILTelephonyCallback::NotifyError(int32_t aCallIndex,
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);
NS_ENSURE_SUCCESS(rv, false);
rv = ril->RegisterTelephonyMsg();
NS_ENSURE_SUCCESS(rv, false);
return true;
}
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;
}
nsIRILTelephonyCallback*
BluetoothRilListener::GetCallback()
{
return mRILTelephonyCallback;
}