author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 21:37:10 +0300 | |
branch | RCL_3 |
changeset 24 | 269724087bed |
parent 23 | 9386f31cc85b |
permissions | -rw-r--r-- |
23 | 1 |
/* |
2 |
* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: Declares Bluetooth notifiers base class. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
// INCLUDE FILES |
|
20 |
#include <centralrepository.h> |
|
21 |
#include <CoreApplicationUIsSDKCRKeys.h> |
|
22 |
||
23 |
#include <settingsinternalcrkeys.h> |
|
24 |
#include <e32property.h> |
|
25 |
||
26 |
#include <btengsettings.h> |
|
27 |
#include <btengprivatecrkeys.h> |
|
28 |
#include <btengconnman.h> |
|
29 |
#include <btengutil.h> |
|
30 |
#include <StringLoader.h> // Localisation stringloader |
|
31 |
#include <BTNotif.rsg> // Own resources |
|
32 |
#include <featmgr.h> // Feature Manager API |
|
33 |
#include <utf.h> // CnvUtfConverter |
|
34 |
#include <bluetoothuiutil.h> |
|
35 |
#include "btnotifier.h" // Own class definition |
|
36 |
#include "btNotifDebug.h" // Debugging macros |
|
37 |
#include "btnotiflock.h" |
|
38 |
#include "btnotif.hrh" // define MaxNameLength |
|
39 |
#include "btnotifpanic.h" |
|
40 |
#include "btnotifnameutils.h" |
|
41 |
||
42 |
#ifdef __SERIES60_HELP |
|
43 |
#include <hlplch.h> |
|
44 |
#include <csxhelp/bt.hlp.hrh> // The bt hrh info is needed, for help launching |
|
45 |
#endif |
|
46 |
||
47 |
// CONSTANTS |
|
48 |
const TInt KBTNAutolockEnabled = 1; |
|
49 |
||
50 |
// The following definitions are used to implement checking of connection/pairing |
|
51 |
// request frequency |
|
52 |
||
53 |
// if a new connection is made quicker than CONNECT_ADD_TIME after the old one, |
|
54 |
// then the saved time is added with CONNECT_ADD_TIME. |
|
55 |
#define CONNECT_ADD_TIME TTimeIntervalSeconds(10) |
|
56 |
||
57 |
// if the saved time is later than now+DENY_THRESHOLD, start rejecting incoming connections |
|
58 |
// from unpaired devices. |
|
59 |
#define DENY_THRESHOLD TTimeIntervalSeconds(30) |
|
60 |
||
61 |
// if the user denies incoming connection the saved time goes this much in the future. |
|
62 |
#define REJECT_ADD_TIME TTimeIntervalSeconds(31) |
|
63 |
||
64 |
||
65 |
// ================= MEMBER FUNCTIONS ======================= |
|
66 |
||
67 |
// ---------------------------------------------------------- |
|
68 |
// CBTNotifierBase::CBTNotifierBase |
|
69 |
// C++ default constructor can NOT contain any code, that |
|
70 |
// might leave. Sets the AOs priority and puts |
|
71 |
// itself to the active scheduler stack. |
|
72 |
// ---------------------------------------------------------- |
|
73 |
// |
|
74 |
CBTNotifierBase::CBTNotifierBase() |
|
75 |
{ |
|
76 |
} |
|
77 |
||
78 |
// ---------------------------------------------------------- |
|
79 |
// CBTNotifierBase::ConstructL |
|
80 |
// Symbian 2nd phase constructor can leave. |
|
81 |
// Create registry object and open resource file. |
|
82 |
// ---------------------------------------------------------- |
|
83 |
// |
|
84 |
void CBTNotifierBase::ConstructL() |
|
85 |
{ |
|
86 |
// Sets up TLS, must be done before FeatureManager is used. |
|
87 |
FeatureManager::InitializeLibL(); |
|
88 |
iIsCoverUI = ( FeatureManager::FeatureSupported( KFeatureIdCoverDisplay ) ) |
|
89 |
? ETrue : EFalse; |
|
90 |
// Frees the TLS. Must be done after FeatureManager is used. |
|
91 |
FeatureManager::UnInitializeLib(); |
|
92 |
||
93 |
iBTEngSettings = CBTEngSettings::NewL(); |
|
94 |
iDevMan = CBTEngDevMan::NewL( this ); |
|
95 |
iNotifUiUtil = CBTNotifUIUtil::NewL( iIsCoverUI ); |
|
24
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
96 |
iAuthoriseDialog = CBTNotifUIUtil::NewL( iIsCoverUI ); |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
97 |
|
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
98 |
TCallBack processParamsCb(ProcessStartParamsCallBack, this); |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
99 |
iProcessStartParamsCallBack = new (ELeave) CAsyncCallBack(processParamsCb, CActive::EPriorityHigh); |
23 | 100 |
} |
101 |
||
102 |
// ---------------------------------------------------------- |
|
103 |
// Destructor. |
|
104 |
// ---------------------------------------------------------- |
|
105 |
// |
|
106 |
CBTNotifierBase::~CBTNotifierBase() |
|
107 |
{ |
|
108 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::~CBTNotifierBase()")); |
|
109 |
Cancel(); |
|
24
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
110 |
|
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
111 |
delete iProcessStartParamsCallBack; |
23 | 112 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::~CBTNotifierBase() -- Done")); |
113 |
} |
|
114 |
||
115 |
// ---------------------------------------------------------- |
|
116 |
// CBTNotifierBase::Release |
|
117 |
// Release itself. Call to destructor. |
|
118 |
// ---------------------------------------------------------- |
|
119 |
// |
|
120 |
void CBTNotifierBase::Release() |
|
121 |
{ |
|
122 |
delete this; |
|
123 |
} |
|
124 |
||
125 |
||
126 |
// ---------------------------------------------------------- |
|
127 |
// CBTNotifierBase::Info |
|
128 |
// Return registered information. |
|
129 |
// ---------------------------------------------------------- |
|
130 |
// |
|
131 |
CBTNotifierBase::TNotifierInfo CBTNotifierBase::Info() const |
|
132 |
{ |
|
133 |
return iInfo; |
|
134 |
} |
|
135 |
||
136 |
// ---------------------------------------------------------- |
|
137 |
// CBTNotifierBase::StartL |
|
138 |
// Synchronic notifier launch. Does nothing here. |
|
139 |
// ---------------------------------------------------------- |
|
140 |
// |
|
141 |
TPtrC8 CBTNotifierBase::StartL(const TDesC8& /*aBuffer*/) |
|
142 |
{ |
|
143 |
TPtrC8 ret(KNullDesC8); |
|
144 |
return (ret); |
|
145 |
} |
|
146 |
||
147 |
// ---------------------------------------------------------- |
|
148 |
// CBTNotifierBase::StartL |
|
149 |
// Asynchronic notifier launch. |
|
150 |
// ---------------------------------------------------------- |
|
151 |
// |
|
152 |
void CBTNotifierBase::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage) |
|
153 |
{ |
|
24
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
154 |
if (!iMessage.IsNull()) |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
155 |
{ |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
156 |
// We're already active. The notifier server will complete the message if we leave. |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
157 |
User::Leave(KErrInUse); |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
158 |
} |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
159 |
|
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
160 |
__ASSERT_DEBUG(!iParamBuffer, BTNOTIF_PANIC(EiParamBufferLeakedFromPreviousActivation)); |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
161 |
|
23 | 162 |
if( !iNotifUiUtil ) |
163 |
{ |
|
164 |
iNotifUiUtil = CBTNotifUIUtil::NewL( iIsCoverUI ); |
|
165 |
} |
|
24
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
166 |
if( !iAuthoriseDialog ) |
23 | 167 |
{ |
24
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
168 |
iNotifUiUtil = CBTNotifUIUtil::NewL( iIsCoverUI ); |
23 | 169 |
} |
24
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
170 |
|
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
171 |
iParamBuffer = aBuffer.AllocL(); // ProcessStartParamsCallBack responsible for deallocation |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
172 |
iMessage = aMessage; |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
173 |
iReplySlot = aReplySlot; |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
174 |
|
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
175 |
// Return from StartL as soon as possible - processing the parameters involves displaying |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
176 |
// waiting dialogs which would block the notifier server thus preventing other notifiers |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
177 |
// from running, were we to do it from here. |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
178 |
iProcessStartParamsCallBack->CallBack(); |
23 | 179 |
} |
180 |
||
181 |
// ---------------------------------------------------------- |
|
182 |
// CBTNotifierBase::Cancel |
|
183 |
// Cancelling method. |
|
184 |
// ---------------------------------------------------------- |
|
185 |
// |
|
186 |
void CBTNotifierBase::Cancel() |
|
187 |
{ |
|
188 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::Cancel()")); |
|
189 |
||
24
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
190 |
// In case we are being called before ProcessStartParamsCallBack |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
191 |
// had a chance to run: |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
192 |
delete iParamBuffer; |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
193 |
iParamBuffer = NULL; |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
194 |
|
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
195 |
if (iProcessStartParamsCallBack) |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
196 |
{ |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
197 |
iProcessStartParamsCallBack->Cancel(); |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
198 |
// - the callback object is deleted in the destructor. |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
199 |
} |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
200 |
|
23 | 201 |
delete iNotifUiUtil; |
202 |
iNotifUiUtil = NULL; |
|
203 |
||
24
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
204 |
delete iAuthoriseDialog; |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
205 |
iAuthoriseDialog = NULL; |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
206 |
|
23 | 207 |
delete iBTEngSettings; |
208 |
iBTEngSettings = NULL; |
|
209 |
||
210 |
delete iDevMan; |
|
211 |
iDevMan = NULL; |
|
212 |
||
213 |
delete iDevice; |
|
214 |
iDevice = NULL; |
|
215 |
||
216 |
if (iDeviceArray) |
|
217 |
{ |
|
218 |
iDeviceArray->ResetAndDestroy(); |
|
219 |
delete iDeviceArray; |
|
220 |
iDeviceArray = NULL; |
|
221 |
} |
|
222 |
||
223 |
CompleteMessage(KErrCancel); |
|
224 |
} |
|
225 |
||
226 |
// ---------------------------------------------------------- |
|
227 |
// CBTNotifierBase::UpdateL |
|
228 |
// Notifier update. Not supported. |
|
229 |
// ---------------------------------------------------------- |
|
230 |
// |
|
231 |
TPtrC8 CBTNotifierBase::UpdateL(const TDesC8& /*aBuffer*/) |
|
232 |
{ |
|
233 |
TPtrC8 ret(KNullDesC8); |
|
234 |
return (ret); |
|
235 |
} |
|
236 |
||
24
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
237 |
TInt CBTNotifierBase::ProcessStartParamsCallBack(TAny* aNotif) |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
238 |
{ |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
239 |
CBTNotifierBase* notif = static_cast<CBTNotifierBase*>(aNotif); |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
240 |
|
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
241 |
__ASSERT_DEBUG(notif->iParamBuffer, BTNOTIF_PANIC(EiParamBufferNullInProcessStartParams)); |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
242 |
__ASSERT_DEBUG(!notif->iMessage.IsNull(), BTNOTIF_PANIC(EiMessageNullInProcessStartParams)); |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
243 |
|
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
244 |
TRAPD(err, notif->ProcessStartParamsL()); |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
245 |
if (err) |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
246 |
{ |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
247 |
notif->CompleteMessage(err); |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
248 |
} |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
249 |
|
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
250 |
delete notif->iParamBuffer; |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
251 |
notif->iParamBuffer = NULL; |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
252 |
|
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
253 |
return 0; |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
254 |
} |
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
255 |
|
23 | 256 |
|
257 |
// ---------------------------------------------------------- |
|
258 |
// CBTNotifierBase::AutoLockOnL |
|
259 |
// ---------------------------------------------------------- |
|
260 |
// |
|
261 |
TBool CBTNotifierBase::AutoLockOnL() |
|
262 |
{ |
|
263 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::AutoLockOnL()")); |
|
264 |
||
265 |
TBool result = EFalse; |
|
266 |
TInt status = KBTNAutolockEnabled; |
|
267 |
||
268 |
// Connecting and initialization: |
|
269 |
CRepository* repository = CRepository::NewL(KCRUidSecuritySettings); |
|
270 |
||
271 |
repository->Get(KSettingsAutolockStatus, status); |
|
272 |
||
273 |
// Closing connection: |
|
274 |
delete repository; |
|
275 |
||
276 |
if ( status == KBTNAutolockEnabled ) |
|
277 |
{ |
|
278 |
result = ETrue; |
|
279 |
} |
|
280 |
||
281 |
FTRACE(FPrint(_L("[BTNOTIF]\t CBTNotifierBase::AutoLockOnL() completed with %d"), result )); |
|
282 |
||
283 |
return result; |
|
284 |
} |
|
285 |
||
286 |
// ---------------------------------------------------------- |
|
287 |
// CBTNotifierBase::CheckAndSetPowerOnL |
|
288 |
// The note or query to be shown depends on two SharedData flags |
|
289 |
// ---------------------------------------------------------- |
|
290 |
// |
|
291 |
TBool CBTNotifierBase::CheckAndSetPowerOnL() |
|
292 |
{ |
|
293 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::CheckAndSetPowerOnL()")); |
|
294 |
||
295 |
TBTPowerStateValue powerState( EBTPowerOff ); |
|
296 |
// Get current power status |
|
297 |
// |
|
298 |
User::LeaveIfError( iBTEngSettings->GetPowerState( powerState ) ); |
|
299 |
||
300 |
// If power is off, turn it on |
|
301 |
// |
|
302 |
if ( powerState == EBTPowerOff ) |
|
303 |
{ |
|
304 |
TInt offlineModeOff( 1 ); // possible values are 0 and 1 |
|
305 |
TInt activationEnabled( 0 ); // possible values are 0 and 1 |
|
306 |
||
307 |
// Offline mode on? |
|
308 |
CRepository* repository = CRepository::NewL(KCRUidCoreApplicationUIs); |
|
309 |
repository->Get(KCoreAppUIsNetworkConnectionAllowed, offlineModeOff); |
|
310 |
delete repository; |
|
311 |
||
312 |
// BT Activation enabled? |
|
313 |
repository = CRepository::NewL(KCRUidBluetoothEngine); |
|
314 |
repository->Get(KBTEnabledInOffline, activationEnabled); |
|
315 |
delete repository; |
|
316 |
||
317 |
// Choose user interaction |
|
318 |
// |
|
319 |
if ( !offlineModeOff && !activationEnabled ) |
|
320 |
{ |
|
321 |
// Show user that feature is disabled: |
|
322 |
iNotifUiUtil->ShowInfoNoteL( R_BT_OFFLINE_DISABLED, ECmdShowBtOfflineDisableNote ); |
|
323 |
return EFalse; // Bluetooth can't be set on. |
|
324 |
} |
|
325 |
else |
|
326 |
{ |
|
327 |
// Choose query |
|
328 |
// |
|
329 |
TInt keypress( 0 ); |
|
330 |
if ( offlineModeOff ) |
|
331 |
{ |
|
332 |
keypress = iNotifUiUtil->ShowQueryL( KErrNone, R_BT_POWER_IS_OFF_QUERY, ECmdShowBtIsOffDlg ); |
|
333 |
} |
|
334 |
else |
|
335 |
{ |
|
336 |
keypress = iNotifUiUtil->ShowQueryL( KErrNone, R_BT_ACTIVATE_IN_OFFLINE_QUERY, |
|
337 |
ECmdShowBtActivateInOfflineDlg ); |
|
338 |
} |
|
339 |
||
340 |
if( keypress ) // User answered YES |
|
341 |
{ |
|
342 |
//Check if the local name has been set. If not ask user to set name |
|
343 |
||
344 |
TBool ok = IsLocalNameModifiedL(); |
|
345 |
if( !ok ) |
|
346 |
{ |
|
347 |
ok = AskLocalBTNameQueryL(); |
|
348 |
} |
|
349 |
if ( ok ) |
|
350 |
{ |
|
351 |
ok = ( iBTEngSettings->SetPowerState( EBTPowerOn ) ) ? EFalse : ETrue; |
|
352 |
} |
|
353 |
return ok; |
|
354 |
} |
|
355 |
else // User has cancelled the dialog |
|
356 |
{ |
|
357 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::CheckAndSetPowerOnL(), dialog canceled")); |
|
358 |
return EFalse; |
|
359 |
} |
|
360 |
} |
|
361 |
} |
|
362 |
return ETrue; |
|
363 |
} |
|
364 |
||
365 |
// ---------------------------------------------------------- |
|
366 |
// CBTNotifierBase::AskLocalBTNameQueryL() |
|
367 |
// ---------------------------------------------------------- |
|
368 |
// |
|
369 |
TBool CBTNotifierBase::AskLocalBTNameQueryL() |
|
370 |
{ |
|
371 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::AskLocalBTNameQueryL() >>")); |
|
372 |
||
373 |
TBTDeviceName tempNameBuffer; |
|
374 |
// Cut the excess part of the name away. The query can handle only |
|
375 |
// KBTUIMaxNameLength characters. |
|
376 |
// |
|
377 |
if( tempNameBuffer.Length() > KBTUIMaxNameLength ) |
|
378 |
{ |
|
379 |
tempNameBuffer.SetLength( KBTUIMaxNameLength ); |
|
380 |
} |
|
381 |
||
382 |
//Get default name if given by e.g. phone product |
|
383 |
(void) RProperty::Get( KPropertyUidBluetoothCategory, |
|
384 |
KPropertyKeyBluetoothGetDeviceName, tempNameBuffer ); |
|
385 |
||
386 |
if( !tempNameBuffer.Length() ) |
|
387 |
{ |
|
388 |
(void) RProperty::Get( KPropertyUidBluetoothCategory, |
|
389 |
KPropertyKeyBluetoothGetDeviceName, tempNameBuffer ); |
|
390 |
} |
|
391 |
||
392 |
if( !tempNameBuffer.Length() ) |
|
393 |
{ |
|
394 |
RBTRegServ btRegServ; |
|
395 |
RBTLocalDevice btReg; |
|
396 |
TBTLocalDevice localDev; |
|
397 |
||
398 |
TInt err = btRegServ.Connect(); |
|
399 |
if( !err ) |
|
400 |
{ |
|
401 |
err = btReg.Open( btRegServ ); |
|
402 |
} |
|
403 |
if( !err ) |
|
404 |
{ |
|
405 |
// Read the BT local name from BT Registry. |
|
406 |
err = btReg.Get( localDev ); |
|
407 |
} |
|
408 |
if( !err ) |
|
409 |
{ |
|
410 |
// The error can be > 0 if there are unconverted characters. |
|
411 |
err = CnvUtfConverter::ConvertToUnicodeFromUtf8( tempNameBuffer, localDev.DeviceName() ); |
|
412 |
} |
|
413 |
btReg.Close(); |
|
414 |
btRegServ.Close(); |
|
415 |
} |
|
416 |
||
417 |
TInt keypress = iNotifUiUtil->ShowTextInputQueryL( tempNameBuffer, |
|
418 |
R_BT_ENTER_LOCAL_NAME_QUERY, ECmdBTnotifUnavailable ); |
|
419 |
||
420 |
if( keypress ) // User has accepted the dialog |
|
421 |
{ |
|
422 |
AknTextUtils::StripCharacters(tempNameBuffer, KAknStripListControlChars); |
|
423 |
tempNameBuffer.TrimAll(); // Remove extra spaces |
|
424 |
// If name was full of invalid chars, it becomes empty after above cleanup. |
|
425 |
if( tempNameBuffer.Length() ) |
|
426 |
{ |
|
427 |
TInt err = iBTEngSettings->SetLocalName( tempNameBuffer ); |
|
428 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::AskLocalBTNameQueryL() <<")); |
|
429 |
return (err) ? EFalse : ETrue; |
|
430 |
} |
|
431 |
else |
|
432 |
{ |
|
433 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::AskLocalBTNameQueryL() << failed")); |
|
434 |
return EFalse; |
|
435 |
} |
|
436 |
} |
|
437 |
else |
|
438 |
{ |
|
439 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::AskLocalBTNameQueryL() << cancelled")); |
|
440 |
return EFalse; |
|
441 |
} |
|
442 |
} |
|
443 |
||
444 |
// --------------------------------------------------------------------------------- |
|
445 |
// CBTNotifierBase::IsExistingConnectionToAudioL |
|
446 |
// Check if there is any existing connection to audio profiles from the same device |
|
447 |
// --------------------------------------------------------------------------------- |
|
448 |
TBool CBTNotifierBase::IsExistingConnectionToAudioL( const TBTDevAddr& aDevAddr ) |
|
449 |
{ |
|
450 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::IsExistingConnectionToAudioL()")); |
|
451 |
CBTEngConnMan* connMan = CBTEngConnMan::NewL(); |
|
452 |
TBTEngConnectionStatus conntatus( EBTEngNotConnected ); |
|
453 |
(void) connMan->IsConnected(aDevAddr,conntatus); |
|
454 |
delete connMan; |
|
455 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::IsExistingConnectionToAudioL() complete")); |
|
456 |
return ( conntatus==EBTEngConnected || conntatus==EBTEngConnecting ); |
|
457 |
} |
|
458 |
||
459 |
// --------------------------------------------------------------------------- |
|
460 |
// CBTNotifierBase::IsLocalNameModified |
|
461 |
// Checks from central repository whether the Bluetooth friendly name |
|
462 |
// has been modified . |
|
463 |
// --------------------------------------------------------------------------- |
|
464 |
// |
|
465 |
TBool CBTNotifierBase::IsLocalNameModifiedL() |
|
466 |
{ |
|
467 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::IsLocalNameModified()")); |
|
468 |
CRepository* cenRep = CRepository::NewL( KCRUidBTEngPrivateSettings ); |
|
469 |
TInt val( EBTLocalNameDefault ); |
|
470 |
(void) cenRep->Get( KBTLocalNameChanged, val ); |
|
471 |
delete cenRep; |
|
472 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::IsLocalNameModified() complete")); |
|
473 |
return val == EBTLocalNameSet; |
|
474 |
} |
|
475 |
||
476 |
||
477 |
void CBTNotifierBase::GetDeviceFromRegL(const TBTDevAddr& aAddr) |
|
478 |
{ |
|
479 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::GetDeviceFromRegL")); |
|
480 |
__ASSERT_DEBUG(iDevice, BTNOTIF_PANIC(EiDeviceNullWhenCallingGetDeviceFromRegL)); |
|
481 |
||
482 |
TBTRegistrySearch mySearch; |
|
483 |
mySearch.FindAddress( aAddr ); |
|
484 |
iDeviceArray = new (ELeave) CBTDeviceArray(1); |
|
485 |
if( !iDevMan ) |
|
486 |
{ |
|
487 |
iDevMan = CBTEngDevMan::NewL( this ); |
|
488 |
} |
|
489 |
TInt err = iDevMan->GetDevices( mySearch, iDeviceArray ); |
|
490 |
if(err) |
|
491 |
{ |
|
492 |
FTRACE(FPrint(_L("[BTNOTIF]\t CBTNotifierBase::GetDeviceFromRegL iDevMan->GetDevices error = %d"), err)); |
|
493 |
DoHandleGetDevicesCompleteL(err, NULL); |
|
494 |
} |
|
495 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::GetDeviceFromRegL done")); |
|
496 |
} |
|
497 |
||
498 |
// ---------------------------------------------------------- |
|
499 |
// CBTNotifierBase::QueryBlockDeviceL |
|
500 |
// Opens a query that returns wether or not user wants the device blocked |
|
501 |
// ---------------------------------------------------------- |
|
502 |
void CBTNotifierBase::QueryBlockDeviceL() |
|
503 |
{ |
|
504 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::QueryBlockDeviceL()")); |
|
505 |
__ASSERT_DEBUG( iNotifUiUtil->IsQueryReleased(), User::Panic( _L("CBTNotifierBase - iYesNoDlg not released!"), KErrAlreadyExists ) ); |
|
506 |
||
507 |
TBTDeviceName bName; |
|
508 |
BtNotifNameUtils::GetDeviceDisplayName(bName, iDevice); |
|
509 |
||
510 |
HBufC* header= StringLoader::LoadLC( R_BT_BLOCK_DEVICE_HEADER ); |
|
511 |
||
512 |
TInt resId = IsUserAwarePaired( iDevice->AsNamelessDevice() ) ? |
|
513 |
R_BT_BLOCK_PAIRED_DEVICE_NOHELP : R_BT_BLOCK_DEVICE_NOHELP; |
|
514 |
||
515 |
RBuf stringholder; |
|
516 |
stringholder.CleanupClosePushL(); |
|
517 |
BluetoothUiUtil::LoadResourceAndSubstringL( stringholder, resId, bName, 0 ); |
|
518 |
||
519 |
TInt keypress = iNotifUiUtil->ShowMessageQueryL( stringholder, *header, |
|
520 |
R_BT_GENERIC_MESSAGE_QUERY, CAknQueryDialog::EConfirmationTone ); |
|
521 |
||
522 |
CleanupStack::PopAndDestroy(&stringholder); |
|
523 |
CleanupStack::PopAndDestroy(header); |
|
524 |
||
525 |
if( keypress )// user replied "Yes" |
|
526 |
{ |
|
527 |
DoBlockDevice(); |
|
528 |
} |
|
529 |
else // user replied "No" |
|
530 |
{ |
|
531 |
CompleteMessage(KErrCancel); |
|
532 |
} |
|
533 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::QueryBlockDeviceL() complete")); |
|
534 |
} |
|
535 |
||
536 |
void CBTNotifierBase::DoBlockDevice() |
|
537 |
{ |
|
538 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::DoBlockDevice()")); |
|
539 |
TBTDeviceSecurity deviceSecurity = iDevice->GlobalSecurity(); |
|
540 |
deviceSecurity.SetBanned(ETrue); |
|
541 |
deviceSecurity.SetNoAuthenticate(EFalse); |
|
542 |
deviceSecurity.SetNoAuthorise(EFalse); |
|
543 |
iDevice->SetGlobalSecurity(deviceSecurity); |
|
544 |
iDevice->DeleteLinkKey(); |
|
545 |
||
546 |
iBTRegistryQueryState = ESetDeviceBlocked; |
|
547 |
TInt err = KErrNone; |
|
548 |
if( !iDevMan ) |
|
549 |
{ |
|
550 |
TRAP(err, iDevMan = CBTEngDevMan::NewL( this )); |
|
551 |
} |
|
552 |
if( !err ) |
|
553 |
{ |
|
554 |
err = iDevMan->ModifyDevice( *iDevice ); |
|
555 |
} |
|
556 |
if( err ) |
|
557 |
{ |
|
558 |
// if error, complete message, otherwise waiting for devman callback |
|
559 |
CompleteMessage(err); |
|
560 |
} |
|
561 |
} |
|
562 |
||
563 |
void CBTNotifierBase::ChangeAuthorizeState( TBool aTrust ) |
|
564 |
{ |
|
565 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::ChangeAuthorizeState()")); |
|
566 |
TBTDeviceSecurity sec = iDevice->GlobalSecurity(); |
|
567 |
sec.SetBanned(EFalse); |
|
568 |
sec.SetNoAuthorise( ( aTrust ) ? ETrue : EFalse ) ; |
|
569 |
iDevice->SetGlobalSecurity(sec); |
|
570 |
||
571 |
iBTRegistryQueryState = ESetDeviceAuthorizeState; |
|
572 |
TInt err = KErrNone; |
|
573 |
if( !iDevMan ) |
|
574 |
{ |
|
575 |
TRAP(err, iDevMan = CBTEngDevMan::NewL( this )); |
|
576 |
} |
|
577 |
if( !err ) |
|
578 |
{ |
|
579 |
err = iDevMan->ModifyDevice( *iDevice ); |
|
580 |
} |
|
581 |
if( err ) |
|
582 |
{ |
|
583 |
// if error, complete message, otherwise waiting for devman callback |
|
584 |
CompleteMessage(err); |
|
585 |
TBTNotifLockPublish::DeleteNotifLocks( |
|
586 |
EBTNotiferLockPairedDeviceSetting, iDevice->BDAddr() ); |
|
587 |
} |
|
588 |
} |
|
589 |
||
590 |
// ---------------------------------------------------------- |
|
591 |
// CBTNotifierBase::CheckAndHandleQueryIntervalL |
|
592 |
// ---------------------------------------------------------- |
|
593 |
// |
|
594 |
void CBTNotifierBase::CheckAndHandleQueryIntervalL() |
|
595 |
{ |
|
596 |
FLOG( _L( "[BTNOTIF]\t CBTNotifierBase::CheckQueryInterval start." ) ); |
|
597 |
TBool res = CheckQueryInterval(); |
|
598 |
if( res ) |
|
599 |
{ |
|
600 |
FLOG( _L( "[BTNOTIF]\t CBTNotifierBase::CheckQueryInterval check on/off query status." ) ); |
|
601 |
// Check if we're already showing Turn BT off query |
|
602 |
TInt queryValue=EBTQueryOff; |
|
603 |
RProperty::Get( KPSUidBluetoothEnginePrivateCategory, KBTTurnBTOffQueryOn, queryValue ); |
|
604 |
if( queryValue==EBTQueryOff ) |
|
605 |
{ |
|
606 |
FLOG( _L( "[BTNOTIF]\t CBTNotifierBase::CheckQueryInterval asking to turn BT off." ) ); |
|
607 |
RProperty::Set( KPSUidBluetoothEnginePrivateCategory, KBTTurnBTOffQueryOn, EBTQueryOn ); |
|
608 |
TInt keypress = iNotifUiUtil->ShowQueryL( KErrNone, R_BT_TURN_BT_OFF_NOTE, ECmdBTnotifUnavailable ); |
|
609 |
RProperty::Set( KPSUidBluetoothEnginePrivateCategory, KBTTurnBTOffQueryOn, EBTQueryOff ); |
|
610 |
if( keypress ) // User has accepted the dialog |
|
611 |
{ |
|
612 |
FLOG( _L( "[BTNOTIF]\t CBTNotifierBase::CheckQueryInterval turning BT off." ) ); |
|
613 |
(void) iBTEngSettings->SetPowerState( EBTPowerOff ); |
|
614 |
CompleteMessage( KErrAccessDenied ); |
|
615 |
} |
|
616 |
} |
|
617 |
} |
|
618 |
FLOG( _L( "[BTNOTIF]\t CBTNotifierBase::CheckAndHandleQueryIntervalL done." ) ); |
|
619 |
} |
|
620 |
||
621 |
void CBTNotifierBase::DoHandleGetDevicesCompleteL( TInt aErr, CBTDeviceArray* aDeviceArray) |
|
622 |
{ |
|
623 |
FTRACE(FPrint(_L("[BTNOTIF]\t CBTNotifierBase::DoHandleGetDevicesCompleteL(%d)"), aErr )); |
|
624 |
TBTDeviceName devName; |
|
625 |
if (!aErr && aDeviceArray && aDeviceArray->Count()) |
|
626 |
{ |
|
627 |
// Reassign so that we won't lose the device name as it is |
|
628 |
// needed if registry doesn't have the name for this device yet: |
|
629 |
CBTDevice* temp = iDevice; |
|
630 |
CleanupStack::PushL(temp); |
|
631 |
// Taking the object returned by registry so that iDevice have |
|
632 |
// all the up-to-date information except device name. |
|
633 |
iDevice = aDeviceArray->At(0); |
|
634 |
aDeviceArray->Delete( 0 ); |
|
635 |
// we show user the device name from registry if it is available; |
|
636 |
// Otherwise, the name passed in by the notifier request shall be |
|
637 |
// used. |
|
638 |
if( ( !iDevice->IsValidDeviceName() || |
|
639 |
!iDevice->DeviceName().Length() ) && |
|
640 |
temp->IsValidDeviceName() ) |
|
641 |
{ |
|
642 |
// We are using a stored device name, which will |
|
643 |
// already have been processed |
|
644 |
iDevice->SetDeviceNameL( temp->DeviceName() ); |
|
645 |
} |
|
646 |
CleanupStack::PopAndDestroy(temp); |
|
647 |
} |
|
648 |
BtNotifNameUtils::GetDeviceName(devName, iDevice); |
|
649 |
||
650 |
// It is possible that iDevice hasn't got a name so far. Use the default BT name |
|
651 |
// got from GetDeviceName(). |
|
652 |
if ( !iDevice->IsValidDeviceName() || !iDevice->DeviceName().Length() ) |
|
653 |
{ |
|
654 |
BtNotifNameUtils::SetDeviceNameL(devName, *iDevice); |
|
655 |
} |
|
656 |
HandleGetDeviceCompletedL( iDevice ); |
|
657 |
} |
|
658 |
||
659 |
// ---------------------------------------------------------- |
|
660 |
// CBTNotifierBase::CompleteMessage |
|
661 |
// ---------------------------------------------------------- |
|
662 |
// |
|
663 |
void CBTNotifierBase::CompleteMessage(TInt aErr) |
|
664 |
{ |
|
665 |
if( !iMessage.IsNull() ) |
|
666 |
{ |
|
667 |
FTRACE(FPrint(_L("[BTNOTIF]\t CBTNotifierBase::CompleteMessage(%d)"), aErr )); |
|
668 |
iMessage.Complete( aErr ); |
|
669 |
} |
|
670 |
} |
|
671 |
||
672 |
// ---------------------------------------------------------- |
|
673 |
// CBTNotifierBase::CompleteMessage |
|
674 |
// ---------------------------------------------------------- |
|
675 |
// |
|
676 |
void CBTNotifierBase::CompleteMessage(TInt aValueToReplySlot, TInt aErr) |
|
677 |
{ |
|
678 |
FTRACE(FPrint(_L("[BTNOTIF]\t CBTNotifierBase::CompleteMessage(%d, %d)"), |
|
679 |
aValueToReplySlot, aErr ) ); |
|
680 |
CompleteMessage(TPckgBuf<TInt>( aValueToReplySlot ), aErr); |
|
681 |
} |
|
682 |
||
683 |
// ---------------------------------------------------------- |
|
684 |
// CBTNotifierBase::CompleteMessage |
|
685 |
// ---------------------------------------------------------- |
|
686 |
// |
|
687 |
void CBTNotifierBase::CompleteMessage(const TDesC8& aDesToReplySlot, TInt aErr) |
|
688 |
{ |
|
689 |
if( !iMessage.IsNull() ) |
|
690 |
{ |
|
691 |
FTRACE(FPrint(_L("[BTNOTIF]\t CBTNotifierBase::CompleteMessage(TDesC8&, %d)"), aErr ) ); |
|
692 |
if ( !aErr ) |
|
693 |
{ |
|
694 |
aErr = iMessage.Write( iReplySlot, aDesToReplySlot ); |
|
695 |
} |
|
696 |
iMessage.Complete( aErr ); |
|
697 |
} |
|
698 |
} |
|
699 |
||
700 |
#ifdef __SERIES60_HELP |
|
701 |
//------------------------------------------------------------- |
|
702 |
// CBTNotifierBase::LaunchHelp |
|
703 |
//-------------------------------------------------------------- |
|
704 |
TInt CBTNotifierBase::LaunchHelp(TAny * tCoeHelpContext ) |
|
705 |
{ |
|
706 |
TCoeHelpContext hc; |
|
707 |
||
708 |
if( tCoeHelpContext==NULL) |
|
709 |
hc = TCoeHelpContext(KUidBTUI,KBT_HLP_BLOCKED); |
|
710 |
else |
|
711 |
hc = *static_cast<TCoeHelpContext*>(tCoeHelpContext); |
|
712 |
||
713 |
CArrayFix< TCoeHelpContext >* array = new CArrayFixFlat< TCoeHelpContext >(1); |
|
714 |
TRAPD(err, |
|
715 |
{ |
|
716 |
CleanupStack::PushL(array); |
|
717 |
array->AppendL(hc); |
|
718 |
HlpLauncher::LaunchHelpApplicationL( CCoeEnv::Static()->WsSession() , array ); |
|
719 |
CleanupStack::Pop(array); |
|
720 |
}); |
|
721 |
||
722 |
// the array is not deleted, since deleting it will result |
|
723 |
// to E32User-CBase 3. It is assumed that HlpLancher is taking care of it. |
|
724 |
// however this has not been documented. |
|
725 |
return err; |
|
726 |
} |
|
727 |
#endif |
|
728 |
||
729 |
void CBTNotifierBase::HandleGetDevicesComplete( TInt aErr, CBTDeviceArray* aDeviceArray) |
|
730 |
{ |
|
731 |
TRAP_IGNORE(DoHandleGetDevicesCompleteL(aErr, aDeviceArray)); |
|
732 |
} |
|
733 |
||
734 |
void CBTNotifierBase::HandleDevManComplete(TInt aErr) |
|
735 |
{ |
|
736 |
FTRACE(FPrint(_L("[BTNOTIF]\t CBTNotifierBase::HandleDevManComplete() aErr = %d"), aErr )); |
|
737 |
||
738 |
switch (iBTRegistryQueryState) |
|
739 |
{ |
|
740 |
case ESetDeviceBlocked: |
|
741 |
{ |
|
742 |
// Blocking device was demanded by user after the user |
|
743 |
// rejected incoming pairing or connect request. The message |
|
744 |
// to be completed here is the original pair or authorization request |
|
745 |
// which has been rejected by the user. |
|
746 |
CompleteMessage(KErrCancel); |
|
747 |
} |
|
748 |
case ESetDeviceAuthorizeState: |
|
749 |
{ |
|
750 |
TBTNotifLockPublish::DeleteNotifLocks( |
|
751 |
EBTNotiferLockPairedDeviceSetting, iDevice->BDAddr() ); |
|
752 |
CompleteMessage(aErr); |
|
753 |
break; |
|
754 |
} |
|
755 |
} |
|
756 |
FLOG(_L("[BTNOTIF]\t CBTNotifierBase::HandleDevManComplete() Complete")); |
|
757 |
} |
|
758 |
||
759 |
void CBTNotifierBase::HandleGetDeviceCompletedL(const CBTDevice* /*aDev*/) |
|
760 |
{ |
|
761 |
} |
|
762 |
||
763 |
// ---------------------------------------------------------- |
|
764 |
// CBTNotifierBase::CheckQueryInterval |
|
765 |
// ---------------------------------------------------------- |
|
766 |
// |
|
767 |
TBool CBTNotifierBase::CheckQueryInterval() |
|
768 |
{ |
|
769 |
FLOG( _L( "[BTNOTIF]\t CBTNotifierBase::CheckQueryInterval()" ) ); |
|
770 |
TBool result = EFalse; |
|
771 |
// Check if the user gets too many queries within a certain time interval from unpaired devices |
|
772 |
if( iDevice && !iDevice->IsValidLinkKey() ) |
|
773 |
{ |
|
774 |
TBuf8<32> buf; |
|
775 |
TTime now; |
|
776 |
now.UniversalTime(); // Get current time |
|
777 |
TInt64 writeTime = ( now + REJECT_ADD_TIME ).Int64(); |
|
778 |
||
779 |
// get last connection time |
|
780 |
TInt err = RProperty::Get( KPSUidBluetoothEnginePrivateCategory, KBTConnectionTimeStamp, buf ); |
|
781 |
if( !err ) |
|
782 |
{ |
|
783 |
FLOG( _L( "[BTNOTIF]\t CBTNotifierBase::CheckQueryInterval Checking query interval." ) ); |
|
784 |
// Parse recorded time stamp |
|
785 |
TInt64 num(0); |
|
786 |
TLex8 lex; |
|
787 |
lex = buf; |
|
788 |
lex.Val( num ); |
|
789 |
TTime lastTime( num ); |
|
790 |
||
791 |
// detection of clock adjusment |
|
792 |
TInt timetravel = 2 * REJECT_ADD_TIME.Int(); |
|
793 |
if( lastTime > now + TTimeIntervalSeconds(timetravel) ) |
|
794 |
{ |
|
795 |
FLOG( _L( "[BTNOTIF]\t CBTNotifierBase::CheckQueryInterval time travel detection." ) ); |
|
796 |
lastTime = now; |
|
797 |
} |
|
798 |
// new request too quickly, move booked time |
|
799 |
if( lastTime + CONNECT_ADD_TIME > now ) |
|
800 |
{ |
|
801 |
FLOG( _L( "[BTNOTIF]\t CBTAuthNotifier::IsDosAttack CONNECT_ADD_TIME added." ) ); |
|
802 |
writeTime = ( lastTime + CONNECT_ADD_TIME ).Int64(); |
|
803 |
} |
|
804 |
||
805 |
FTRACE( FPrint( _L( "[BTNOTIF]\t CBTNotifierBase::CheckQueryInterval() lastTime = %d" ), lastTime.Int64() ) ); |
|
806 |
FTRACE( FPrint( _L( "[BTNOTIF]\t CBTNotifierBase::CheckQueryInterval now + treshold: %d" ), (now + DENY_THRESHOLD).Int64() ) ); |
|
807 |
// If threshold is exceeded, ask user to turn Bluetooth OFF |
|
808 |
if( lastTime > now + DENY_THRESHOLD ) |
|
809 |
{ |
|
810 |
FLOG( _L( "[BTNOTIF]\t CBTNotifierBase::CheckQueryInterval threshold exceeded!." ) ); |
|
811 |
result = ETrue; |
|
812 |
} |
|
813 |
} |
|
814 |
else |
|
815 |
{ |
|
816 |
FLOG( _L( "[BTNOTIF]\t CBTNotifierBase::CheckQueryInterval setting connection timestamp first time." ) ); |
|
817 |
} |
|
818 |
// Write back the timestamp |
|
819 |
buf.Num( writeTime ); |
|
820 |
FTRACE( FPrint( _L( "[BTNOTIF]\t CBTNotifierBase::CheckQueryInterval updating timestamp: %d." ), writeTime ) ); |
|
821 |
RProperty::Set( KPSUidBluetoothEnginePrivateCategory,KBTConnectionTimeStamp, buf ); |
|
822 |
} // end of query interval check |
|
823 |
FLOG( _L( "[BTNOTIF]\t CBTNotifierBase::CheckQueryInterval() complete" ) ); |
|
824 |
return result; |
|
825 |
} |
|
826 |
// End of File |