23
|
1 |
/*
|
25
|
2 |
* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
|
23
|
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: Class to manage Bluetooth hardware and stack settings.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "btengsrvsettingsmgr.h"
|
|
19 |
#include <bthci.h>
|
|
20 |
#include <bt_subscribe_partner.h>
|
|
21 |
#include <btnotif.h>
|
|
22 |
#include <btengdomainpskeys.h>
|
|
23 |
#include <centralrepository.h>
|
|
24 |
#include <featmgr.h>
|
|
25 |
#include "btengserver.h"
|
|
26 |
#include "btengsrvpluginmgr.h"
|
|
27 |
#include "btengsrvbbconnectionmgr.h"
|
|
28 |
#include "btengsrvstate.h"
|
|
29 |
#include "debug.h"
|
42
|
30 |
#include <btindicatorconstants.h>
|
|
31 |
#include <hbindicatorsymbian.h>
|
|
32 |
#include <hbsymbianvariant.h>
|
23
|
33 |
|
|
34 |
/** ID of active object helper */
|
|
35 |
const TInt KBTEngSettingsActive = 30;
|
|
36 |
/** Constant for converting minutes to microseconds */
|
|
37 |
//const TInt64 KMinutesInMicroSecs = 60000000;
|
|
38 |
const TInt64 KMinutesInMicroSecs = MAKE_TINT64( 0, 60000000 );
|
|
39 |
/** Timeout for disabling Simple Pairing debug mode. The value is 30 minutes. */
|
|
40 |
//const TInt KBTEngSspDebugModeTimeout = 1800000000;
|
|
41 |
const TInt64 KBTEngSspDebugModeTimeout = MAKE_TINT64( 0, 1800000000 );
|
|
42 |
/** Timeout for turning BT off automatically. The value is 10.5 seconds. */
|
|
43 |
const TInt KBTEngBtAutoOffTimeout = 10500000;
|
26
|
44 |
|
23
|
45 |
// ======== MEMBER FUNCTIONS ========
|
|
46 |
|
|
47 |
// ---------------------------------------------------------------------------
|
|
48 |
// C++ default constructor
|
|
49 |
// ---------------------------------------------------------------------------
|
|
50 |
//
|
|
51 |
CBTEngSrvSettingsMgr::CBTEngSrvSettingsMgr( CBTEngServer* aServer )
|
42
|
52 |
: iServer( aServer ),iIndicatorState(-1)
|
23
|
53 |
{
|
|
54 |
}
|
|
55 |
|
|
56 |
|
|
57 |
// ---------------------------------------------------------------------------
|
|
58 |
// Symbian second-phase constructor
|
|
59 |
// ---------------------------------------------------------------------------
|
|
60 |
//
|
|
61 |
void CBTEngSrvSettingsMgr::ConstructL()
|
|
62 |
{
|
|
63 |
TRACE_FUNC_ENTRY
|
|
64 |
iActive = CBTEngActive::NewL( *this, KBTEngSettingsActive );
|
42
|
65 |
iBTIndicator = CHbIndicatorSymbian::NewL();
|
23
|
66 |
LoadBTPowerManagerL();
|
|
67 |
iEnterpriseEnablementMode = BluetoothFeatures::EnterpriseEnablementL();
|
|
68 |
TRACE_INFO( ( _L( "iEnterpriseEnablementMode = %d" ), iEnterpriseEnablementMode) )
|
|
69 |
if ( iEnterpriseEnablementMode == BluetoothFeatures::EDisabled )
|
|
70 |
{
|
|
71 |
SetVisibilityModeL( EBTVisibilityModeNoScans, 0 );
|
|
72 |
}
|
|
73 |
TRACE_FUNC_EXIT
|
|
74 |
}
|
|
75 |
|
|
76 |
|
|
77 |
// ---------------------------------------------------------------------------
|
|
78 |
// NewL
|
|
79 |
// ---------------------------------------------------------------------------
|
|
80 |
//
|
|
81 |
CBTEngSrvSettingsMgr* CBTEngSrvSettingsMgr::NewL( CBTEngServer* aServer )
|
|
82 |
{
|
|
83 |
CBTEngSrvSettingsMgr* self = new( ELeave ) CBTEngSrvSettingsMgr( aServer );
|
|
84 |
CleanupStack::PushL( self );
|
|
85 |
self->ConstructL();
|
|
86 |
CleanupStack::Pop( self );
|
|
87 |
return self;
|
|
88 |
}
|
|
89 |
|
|
90 |
|
|
91 |
// ---------------------------------------------------------------------------
|
|
92 |
// Destructor
|
|
93 |
// ---------------------------------------------------------------------------
|
|
94 |
//
|
|
95 |
CBTEngSrvSettingsMgr::~CBTEngSrvSettingsMgr()
|
|
96 |
{
|
|
97 |
delete iActive;
|
42
|
98 |
delete iBTIndicator;
|
23
|
99 |
iPowerMgr.Close();
|
|
100 |
}
|
|
101 |
|
|
102 |
|
|
103 |
// ---------------------------------------------------------------------------
|
|
104 |
// Power Bluetooth hardware on or off.
|
|
105 |
// ---------------------------------------------------------------------------
|
|
106 |
//
|
|
107 |
TInt CBTEngSrvSettingsMgr::SetHwPowerState( TBTPowerState aState )
|
|
108 |
{
|
|
109 |
TRACE_FUNC_ENTRY
|
|
110 |
TInt err = KErrNone;
|
|
111 |
#ifndef __WINS__
|
|
112 |
if( iActive->IsActive() )
|
|
113 |
{
|
|
114 |
// Cancel the outstanding request.
|
|
115 |
iPowerMgr.Cancel();
|
|
116 |
iActive->Cancel();
|
|
117 |
}
|
|
118 |
iPowerMgr.SetPower( aState, NULL, iActive->RequestStatus() );
|
|
119 |
iActive->GoActive();
|
|
120 |
#else //__WINS__
|
|
121 |
iPowerState = aState;
|
|
122 |
#endif //__WINS__
|
|
123 |
|
|
124 |
if( !err && aState == EBTOn )
|
|
125 |
{
|
|
126 |
TInt dutMode = EBTDutOff;
|
|
127 |
err = RProperty::Get( KPSUidBluetoothTestingMode, KBTDutEnabled, dutMode );
|
|
128 |
if( !err && dutMode == EBTDutOn )
|
|
129 |
{
|
|
130 |
// Set the DUT mode key to OFF since DUT mode is disabled at this point
|
|
131 |
err = RProperty::Set( KPSUidBluetoothTestingMode, KBTDutEnabled, EBTDutOff );
|
|
132 |
}
|
|
133 |
}
|
|
134 |
if( err )
|
|
135 |
{
|
|
136 |
// Power off if an error occurred during power on sequence.
|
|
137 |
#ifndef __WINS__
|
|
138 |
// This cannot happen in emulator environment.
|
|
139 |
iPowerMgr.Cancel();
|
|
140 |
iActive->Cancel();
|
|
141 |
iPowerMgr.SetPower( EBTOff, NULL, iActive->RequestStatus() );
|
|
142 |
User::WaitForRequest( iActive->RequestStatus() );
|
|
143 |
// Result will be communicated through the caller of this function (by leaving).
|
|
144 |
#else //__WINS__
|
|
145 |
iPowerState = EBTOff;
|
|
146 |
#endif //__WINS__
|
|
147 |
}
|
26
|
148 |
|
|
149 |
#ifdef __WINS__
|
|
150 |
TRequestStatus* status = &(iActive->RequestStatus());
|
|
151 |
iActive->GoActive();
|
|
152 |
User::RequestComplete(status,KErrNone);
|
|
153 |
#endif //__WINS__
|
|
154 |
|
23
|
155 |
TRACE_FUNC_RES( ( _L( "result: %d" ), err ) )
|
|
156 |
return err;
|
|
157 |
}
|
|
158 |
|
|
159 |
|
|
160 |
// ---------------------------------------------------------------------------
|
|
161 |
// Turn BT on or off.
|
|
162 |
// ---------------------------------------------------------------------------
|
|
163 |
//
|
|
164 |
void CBTEngSrvSettingsMgr::SetPowerStateL( TBTPowerState aState, TBool aTemporary )
|
|
165 |
{
|
|
166 |
TRACE_FUNC_ARG( ( _L( "%d (temporary=%d" ), aState, aTemporary ) )
|
|
167 |
if ( aState == EBTOn && iEnterpriseEnablementMode == BluetoothFeatures::EDisabled )
|
|
168 |
{
|
|
169 |
TRACE_INFO( ( _L( "no we're not... Bluetooth is enterprise-IT-disabled" ) ) )
|
|
170 |
User::Leave(KErrNotSupported);
|
|
171 |
}
|
|
172 |
TBool idle = ( iServer->StateMachine()->CurrentOperation() == CBTEngSrvState::ESrvOpIdle );
|
|
173 |
TBTPowerState currentState = EBTOff;
|
|
174 |
CheckTemporaryPowerStateL( currentState, aState, aTemporary );
|
|
175 |
|
|
176 |
if ( ( currentState == aState || ( aTemporary && aState == EBTOff ) ) && idle )
|
|
177 |
{
|
|
178 |
// The requested power state is already active, ignore silently.
|
|
179 |
// We don't return an error here, as there is no error situation.
|
|
180 |
TRACE_INFO( ( _L( "SetPowerStateL: nothing to do" ) ) )
|
|
181 |
if ( currentState == aState )
|
|
182 |
{
|
|
183 |
// Make sure that the CenRep key is in sync.
|
28
|
184 |
// During boot-up, the power is set from the CenRep key, so we could
|
23
|
185 |
// end up out-of-sync.
|
|
186 |
TRACE_INFO( ( _L( "SetPowerStateL: currentState == aState" ) ) )
|
28
|
187 |
HandleHwPowerChangeL( aState );
|
|
188 |
}
|
23
|
189 |
return;
|
|
190 |
}
|
|
191 |
if ( aState == EBTOn )
|
|
192 |
{
|
|
193 |
// Hardware power on is the first step.
|
|
194 |
User::LeaveIfError( SetHwPowerState( aState ) );
|
|
195 |
}
|
|
196 |
else
|
|
197 |
{
|
|
198 |
//Prevent BT visibility in the situation when we turn OFF BT Engine
|
|
199 |
//but FM Radio is still alive
|
|
200 |
SetVisibilityModeL( EBTVisibilityModeNoScans, 0 );
|
|
201 |
// Hardware power off is the last step.
|
|
202 |
// First disconnect all plug-ins.
|
|
203 |
iServer->PluginManager()->DisconnectAllPlugins();
|
|
204 |
}
|
|
205 |
// We only signal that BT is on after everything has completed (through
|
|
206 |
// the CenRep power state key), so that all services are initialized.
|
|
207 |
// We signal that BT is off immediately though, so that our clients will
|
|
208 |
// not try to use BT during power down.
|
|
209 |
iServer->StateMachine()->StartStateMachineL( aState );
|
|
210 |
TRACE_FUNC_EXIT
|
|
211 |
}
|
|
212 |
|
|
213 |
// ---------------------------------------------------------------------------
|
|
214 |
// Turn BT on or off.
|
|
215 |
// ---------------------------------------------------------------------------
|
|
216 |
//
|
|
217 |
void CBTEngSrvSettingsMgr::SetPowerStateL(const RMessage2 aMessage )
|
|
218 |
{
|
|
219 |
TRACE_FUNC_ENTRY
|
|
220 |
__ASSERT_ALWAYS( aMessage.Function() == EBTEngSetPowerState,
|
|
221 |
PanicServer( EBTEngPanicExpectSetPowerOpcode ) );
|
|
222 |
if ( !iMessage.IsNull() )
|
|
223 |
{
|
|
224 |
// A power management request from a client is outstanding.
|
|
225 |
User::Leave( KErrAlreadyExists );
|
|
226 |
}
|
|
227 |
|
|
228 |
TBTPowerStateValue arg = (TBTPowerStateValue) aMessage.Int0();
|
|
229 |
// TBTPowerState power state type is inverted from TBTPowerStateValue,
|
|
230 |
// which is used by the client to pass the parameter...
|
|
231 |
TBTPowerState reqedPowerState( EBTOff );
|
|
232 |
if ( arg == EBTPowerOn )
|
|
233 |
{
|
|
234 |
reqedPowerState = EBTOn;
|
|
235 |
}
|
|
236 |
TBool tempPowerOn = (TBool) aMessage.Int1();
|
|
237 |
|
|
238 |
SetPowerStateL( reqedPowerState, tempPowerOn );
|
|
239 |
if ( iServer->StateMachine()->CurrentOperation() == CBTEngSrvState::ESrvOpIdle )
|
|
240 |
{
|
|
241 |
// The request is accepted but the state machine is not running. This means the
|
|
242 |
// requested power state is already active. Request is done.
|
|
243 |
aMessage.Complete( KErrNone );
|
|
244 |
}
|
|
245 |
else
|
|
246 |
{
|
|
247 |
iMessage = RMessage2( aMessage );
|
|
248 |
}
|
|
249 |
TRACE_FUNC_EXIT
|
|
250 |
}
|
|
251 |
|
|
252 |
// ---------------------------------------------------------------------------
|
|
253 |
// Initialize Bluetooth stack settings.
|
|
254 |
// ---------------------------------------------------------------------------
|
|
255 |
//
|
|
256 |
void CBTEngSrvSettingsMgr::InitBTStackL()
|
|
257 |
{
|
|
258 |
TRACE_FUNC_ENTRY
|
|
259 |
iServer->BasebandConnectionManager()->Subscribe();
|
|
260 |
TBTVisibilityMode visibility = EBTVisibilityModeHidden;
|
|
261 |
CRepository* cenRep = CRepository::NewL( KCRUidBTEngPrivateSettings );
|
|
262 |
TInt err = cenRep->Get( KBTDiscoverable, (TInt&) visibility );
|
|
263 |
delete cenRep;
|
|
264 |
if (iRestoreVisibility == EFalse)
|
|
265 |
{
|
|
266 |
if( err || visibility == EBTVisibilityModeTemporary &&
|
|
267 |
!( iServer->IsTimerQueued( CBTEngServer::EScanModeTimer ) ) )
|
|
268 |
{
|
|
269 |
visibility = EBTVisibilityModeHidden;
|
|
270 |
}
|
|
271 |
SetVisibilityModeL( visibility, 0 );
|
|
272 |
}
|
|
273 |
|
|
274 |
TBool sspDebugMode = EFalse;
|
|
275 |
(void) RProperty::Get( KPropertyUidBluetoothCategory,
|
|
276 |
KPropertyKeyBluetoothGetSimplePairingDebugMode, (TInt&) sspDebugMode );
|
|
277 |
// Only set debug mode to off if it is on, to prevent a loop notifications.
|
|
278 |
if( sspDebugMode )
|
|
279 |
{
|
|
280 |
sspDebugMode = EFalse;
|
|
281 |
// Add LeaveIfError if unsuccessful
|
|
282 |
(void) RProperty::Set(KPropertyUidBluetoothCategory,
|
|
283 |
KPropertyKeyBluetoothSetSimplePairingDebugMode, (TInt) sspDebugMode );
|
|
284 |
}
|
|
285 |
TRACE_FUNC_EXIT
|
|
286 |
}
|
|
287 |
|
|
288 |
|
|
289 |
// ---------------------------------------------------------------------------
|
|
290 |
// Reset settings and disconnect all links.
|
|
291 |
// ---------------------------------------------------------------------------
|
|
292 |
//
|
|
293 |
void CBTEngSrvSettingsMgr::StopBTStackL()
|
|
294 |
{
|
|
295 |
TRACE_FUNC_ENTRY
|
|
296 |
TBTVisibilityMode visibility = EBTVisibilityModeHidden;
|
|
297 |
CRepository* cenRep = CRepository::NewL( KCRUidBTEngPrivateSettings );
|
|
298 |
// Ignore error here; if we can't read it, likely we can't set it either.
|
|
299 |
(void) cenRep->Get( KBTDiscoverable, (TInt&) visibility );
|
|
300 |
delete cenRep;
|
|
301 |
if( visibility == EBTVisibilityModeTemporary )
|
|
302 |
{
|
|
303 |
visibility = EBTVisibilityModeHidden;
|
|
304 |
SetVisibilityModeL( visibility, 0 ); // Also cancels scan mode timer.
|
|
305 |
}
|
|
306 |
|
|
307 |
// Stop listening to events
|
|
308 |
iServer->BasebandConnectionManager()->Unsubscribe();
|
|
309 |
// Disconnect all links
|
|
310 |
TCallBack cb( CBTEngServer::DisconnectAllCallBack, iServer );
|
|
311 |
iServer->BasebandConnectionManager()->DisconnectAllLinksL( cb );
|
|
312 |
// Results in a callback (which is called directly when there are no links).
|
|
313 |
TRACE_FUNC_EXIT
|
|
314 |
}
|
|
315 |
|
|
316 |
|
|
317 |
// ---------------------------------------------------------------------------
|
28
|
318 |
// Update the power state CenRep key, and start BTNotif server if BT is on.
|
23
|
319 |
// ---------------------------------------------------------------------------
|
|
320 |
//
|
28
|
321 |
void CBTEngSrvSettingsMgr::HandleHwPowerChangeL( TBTPowerState aState )
|
23
|
322 |
{
|
|
323 |
TRACE_FUNC_ENTRY
|
|
324 |
CRepository* cenrep = CRepository::NewLC( KCRUidBluetoothPowerState );
|
|
325 |
// TBTPowerState power state type is inverted from TBTPowerStateValue...
|
28
|
326 |
TBTPowerStateValue power = ( aState == EBTOn ) ? EBTPowerOn : EBTPowerOff;
|
23
|
327 |
User::LeaveIfError( cenrep->Set( KBTPowerState, (TInt) power ) );
|
|
328 |
CleanupStack::PopAndDestroy( cenrep );
|
|
329 |
TRACE_FUNC_EXIT
|
|
330 |
}
|
|
331 |
|
|
332 |
// ---------------------------------------------------------------------------
|
|
333 |
// ?implementation_description
|
|
334 |
// ---------------------------------------------------------------------------
|
|
335 |
//
|
|
336 |
void CBTEngSrvSettingsMgr::SetVisibilityModeL( TBTVisibilityMode aMode, TInt aTime )
|
|
337 |
{
|
|
338 |
TRACE_FUNC_ARG( ( _L( "[aMode: %d" ), aMode ) )
|
|
339 |
if ( aMode != EBTVisibilityModeNoScans && iEnterpriseEnablementMode == BluetoothFeatures::EDisabled )
|
|
340 |
{
|
|
341 |
TRACE_INFO( ( _L( "\tnot changing anything... Bluetooth is enterprise-IT-disabled" ) ) )
|
|
342 |
User::Leave( KErrNotSupported );
|
|
343 |
}
|
|
344 |
|
|
345 |
TInt err = KErrNone;
|
|
346 |
iServer->RemoveTimer( CBTEngServer::EScanModeTimer );
|
|
347 |
if( aMode != EBTVisibilityModeNoScans )
|
|
348 |
{
|
|
349 |
CRepository* cenRep = CRepository::NewL( KCRUidBTEngPrivateSettings );
|
|
350 |
err = cenRep->Set( KBTDiscoverable, aMode );
|
|
351 |
delete cenRep;
|
|
352 |
}
|
|
353 |
if( !err && aMode == EBTVisibilityModeTemporary )
|
|
354 |
{
|
|
355 |
// We need TInt64 here, as the max. time in microseconds for the
|
|
356 |
// max. value (1 hour) is larger than KMaxTInt32.
|
|
357 |
TInt64 timeMicroSec = MAKE_TINT64( 0, aTime );
|
|
358 |
timeMicroSec = timeMicroSec * KMinutesInMicroSecs;
|
|
359 |
// Queue callback to set the visibility back to hidden.
|
|
360 |
iServer->QueueTimer( CBTEngServer::EScanModeTimer, (TInt64) timeMicroSec );
|
|
361 |
aMode = EBTVisibilityModeGeneral;
|
|
362 |
}
|
|
363 |
else if( !err && iRestoreVisibility )
|
|
364 |
{
|
|
365 |
// The user overrides, do not restore visibility mode anymore.
|
|
366 |
iRestoreVisibility = EFalse;
|
|
367 |
}
|
|
368 |
if( !err )
|
|
369 |
{
|
|
370 |
err = RProperty::Set( KUidSystemCategory,
|
|
371 |
KPropertyKeyBluetoothSetScanningStatus, aMode );
|
|
372 |
}
|
|
373 |
TBool hiddenMode = ( aMode == EBTVisibilityModeHidden );
|
|
374 |
if( !err && aMode != EBTVisibilityModeNoScans )
|
|
375 |
{
|
|
376 |
// In hidden mode, we only accept connections from paired devices.
|
|
377 |
err = RProperty::Set( KUidSystemCategory,
|
|
378 |
KPropertyKeyBluetoothSetAcceptPairedOnlyMode,
|
|
379 |
hiddenMode );
|
|
380 |
}
|
|
381 |
|
|
382 |
User::LeaveIfError( err ); // To communicate the result to the client.
|
|
383 |
TRACE_FUNC_EXIT
|
|
384 |
}
|
|
385 |
|
|
386 |
|
|
387 |
// ---------------------------------------------------------------------------
|
|
388 |
// Timed visible mode has expired.
|
|
389 |
// ---------------------------------------------------------------------------
|
|
390 |
//
|
|
391 |
void CBTEngSrvSettingsMgr::ScanModeTimerCompletedL()
|
|
392 |
{
|
|
393 |
TRACE_FUNC_ENTRY
|
|
394 |
SetVisibilityModeL( EBTVisibilityModeHidden, 0 );
|
|
395 |
TBTPowerState power = EBTOff;
|
|
396 |
TInt err = GetHwPowerState( power );
|
25
|
397 |
// See p2.1.2.1.2 of the UI spec
|
|
398 |
// NB: Please distinguish between TBTPowerState::EBTOff (defined in hcitypes.h)
|
|
399 |
// and TBTPowerStateValue::EBTPowerOff (defined in btserversdkcrkeys.h)
|
|
400 |
// because they have the opposite values
|
|
401 |
if( !err && (power != EBTOff))
|
23
|
402 |
{
|
|
403 |
// Show a notification to the user
|
|
404 |
TBTGenericInfoNotiferParamsPckg pckg;
|
|
405 |
pckg().iMessageType = EBTVisibilityTimeout;
|
|
406 |
|
|
407 |
RNotifier notifier;
|
|
408 |
TInt err = notifier.Connect();
|
|
409 |
if( !err )
|
|
410 |
{
|
|
411 |
err = notifier.StartNotifier( KBTGenericInfoNotifierUid, pckg );
|
|
412 |
notifier.Close();
|
|
413 |
}
|
|
414 |
}
|
|
415 |
TRACE_FUNC_RES( ( _L( "result: %d" ), err ) )
|
|
416 |
}
|
|
417 |
|
|
418 |
|
|
419 |
// ---------------------------------------------------------------------------
|
|
420 |
// Check the secure simple pairing debug mode and turn it off if needed.
|
|
421 |
// ---------------------------------------------------------------------------
|
|
422 |
//
|
|
423 |
void CBTEngSrvSettingsMgr::CheckSspDebugModeL( TBool aDebugMode )
|
|
424 |
{
|
|
425 |
TRACE_FUNC_ARG( ( _L( "SSP debug mode state %d" ), (TInt) aDebugMode ) )
|
|
426 |
TBTPowerState pwr = EBTOff;
|
|
427 |
TBool currentMode = EFalse;
|
|
428 |
TInt err = RProperty::Get( KPropertyUidBluetoothCategory,
|
|
429 |
KPropertyKeyBluetoothGetSimplePairingDebugMode,
|
|
430 |
(TInt&) currentMode );
|
|
431 |
#ifndef __WINS__
|
|
432 |
err = iPowerMgr.GetPower( pwr, NULL ); // Treat error as power off.
|
|
433 |
#else //__WINS__
|
|
434 |
pwr = iPowerState;
|
|
435 |
#endif //__WINS__
|
|
436 |
if( err || pwr == EBTOff )
|
|
437 |
{
|
|
438 |
iServer->RemoveTimer( CBTEngServer::ESspDebugModeTimer );
|
|
439 |
// Only set debug mode to off if it is on, to prevent a loop notifications.
|
|
440 |
if( currentMode )
|
|
441 |
{
|
|
442 |
(void) RProperty::Set( KPropertyUidBluetoothCategory,
|
|
443 |
KPropertyKeyBluetoothSetSimplePairingDebugMode,
|
|
444 |
(TInt) aDebugMode );
|
|
445 |
}
|
|
446 |
// In case of an error in getting the power state, turn BT off.
|
|
447 |
// If BT is already off, this call will be ignored.
|
|
448 |
SetPowerStateL( EBTOff, EFalse );
|
|
449 |
}
|
|
450 |
else if( aDebugMode )
|
|
451 |
{
|
|
452 |
// Ignore if there already is a timer queued.
|
|
453 |
if( !( iServer->IsTimerQueued( CBTEngServer::ESspDebugModeTimer ) ) )
|
|
454 |
{
|
|
455 |
iServer->QueueTimer( CBTEngServer::ESspDebugModeTimer, (TInt64) KBTEngSspDebugModeTimeout );
|
|
456 |
err = RProperty::Set(KPropertyUidBluetoothCategory,
|
|
457 |
KPropertyKeyBluetoothSetSimplePairingDebugMode,
|
|
458 |
(TInt) aDebugMode );
|
|
459 |
}
|
|
460 |
}
|
|
461 |
else
|
|
462 |
{
|
|
463 |
// Power is on, and debug mode is set to off.
|
|
464 |
TInt linkCount = 0;
|
|
465 |
err = RProperty::Get( KPropertyUidBluetoothCategory,
|
|
466 |
KPropertyKeyBluetoothGetPHYCount, linkCount );
|
|
467 |
if( err || !linkCount )
|
|
468 |
{
|
|
469 |
(void) RProperty::Set(KPropertyUidBluetoothCategory,
|
|
470 |
KPropertyKeyBluetoothSetSimplePairingDebugMode,
|
|
471 |
(TInt) aDebugMode );
|
|
472 |
SetPowerStateL( EBTOff, EFalse );
|
|
473 |
}
|
|
474 |
else
|
|
475 |
{
|
|
476 |
// There are still existing connections, queue the
|
|
477 |
// timer again for half the period.
|
|
478 |
TInt64 interval = KBTEngSspDebugModeTimeout / 2;
|
|
479 |
iServer->QueueTimer( CBTEngServer::ESspDebugModeTimer, interval );
|
|
480 |
}
|
|
481 |
}
|
|
482 |
TRACE_FUNC_EXIT
|
|
483 |
}
|
|
484 |
|
|
485 |
// ---------------------------------------------------------------------------
|
|
486 |
// A session will be ended, completes the pending request for this session.
|
|
487 |
// ---------------------------------------------------------------------------
|
|
488 |
//
|
|
489 |
void CBTEngSrvSettingsMgr::SessionClosed( CSession2* aSession )
|
|
490 |
{
|
|
491 |
TRACE_FUNC_ARG( ( _L( " session %x"), aSession ) )
|
|
492 |
if ( !iMessage.IsNull() && iMessage.Session() == aSession )
|
|
493 |
{
|
|
494 |
iMessage.Complete( KErrCancel );
|
|
495 |
}
|
|
496 |
TRACE_FUNC_EXIT
|
|
497 |
}
|
|
498 |
|
|
499 |
// ---------------------------------------------------------------------------
|
|
500 |
// Check the power state and if BT gets turned off automatically.
|
|
501 |
// This method is invoked either when the timer has expired, or
|
|
502 |
// if there are no more connections while the timer was running.
|
|
503 |
// ---------------------------------------------------------------------------
|
|
504 |
//
|
|
505 |
void CBTEngSrvSettingsMgr::CheckAutoPowerOffL()
|
|
506 |
{
|
|
507 |
TRACE_FUNC_ENTRY
|
|
508 |
if ( iAutoOffClients > 0 )
|
|
509 |
{
|
|
510 |
TRACE_INFO( ( _L( "[CBTEngServer]\t iAutoOffClients %d"), iAutoOffClients ) )
|
|
511 |
return;
|
|
512 |
}
|
|
513 |
TInt linkCount = 0;
|
|
514 |
TInt err = RProperty::Get( KPropertyUidBluetoothCategory,
|
|
515 |
KPropertyKeyBluetoothGetPHYCount, linkCount );
|
|
516 |
if( !err && !linkCount )
|
|
517 |
{
|
|
518 |
TRACE_INFO( ( _L( "[CBTEngServer]\t SetPowerStateL( EBTOff, EFalse );")))
|
|
519 |
SetPowerStateL( EBTOff, EFalse );
|
|
520 |
}
|
|
521 |
else
|
|
522 |
{
|
|
523 |
if( iRestoreVisibility )
|
|
524 |
{
|
|
525 |
// Set visibility mode back to the value selected by the user.
|
|
526 |
SetVisibilityModeL( EBTVisibilityModeGeneral, 0 );
|
|
527 |
iRestoreVisibility = EFalse;
|
|
528 |
}
|
|
529 |
// show note if non-audio connection exists
|
|
530 |
if ( !iServer->PluginManager()->CheckAudioConnectionsL() )
|
|
531 |
{
|
|
532 |
RNotifier notifier;
|
|
533 |
TInt err = notifier.Connect();
|
|
534 |
if( !err )
|
|
535 |
{
|
|
536 |
TRequestStatus status;
|
|
537 |
TBTGenericInfoNotiferParamsPckg pckg;
|
|
538 |
pckg().iMessageType = EBTStayPowerOn;
|
|
539 |
TBuf8<sizeof(TInt)> result;
|
|
540 |
//notifier.StartNotifier( KBTGenericInfoNotifierUid, pckg, result );
|
|
541 |
notifier.StartNotifierAndGetResponse( status,
|
|
542 |
KBTGenericInfoNotifierUid,
|
|
543 |
pckg, result ); // Reply buffer not used.
|
|
544 |
User::WaitForRequest( status );
|
|
545 |
notifier.Close();
|
|
546 |
}
|
|
547 |
}
|
|
548 |
iAutoOffClients = 0;
|
|
549 |
iAutoSwitchOff = EFalse;
|
|
550 |
TCallBack cb;
|
|
551 |
iServer->BasebandConnectionManager()->SetAutoSwitchOff( EFalse, cb );
|
|
552 |
}
|
|
553 |
TRACE_FUNC_EXIT
|
|
554 |
}
|
|
555 |
|
|
556 |
|
|
557 |
// ---------------------------------------------------------------------------
|
|
558 |
// The method is called when BT stack scanning mode P&S key is changed
|
|
559 |
// ---------------------------------------------------------------------------
|
|
560 |
//
|
|
561 |
void CBTEngSrvSettingsMgr::UpdateVisibilityModeL( TInt aStackScanMode )
|
|
562 |
{
|
|
563 |
TRACE_FUNC_ARG( ( _L( "[aStackScanMode: %d" ), aStackScanMode ) )
|
|
564 |
TBTVisibilityMode currentMode;
|
|
565 |
|
|
566 |
CRepository* cenRep = CRepository::NewLC( KCRUidBTEngPrivateSettings );
|
|
567 |
User::LeaveIfError( cenRep->Get( KBTDiscoverable, (TInt&) currentMode ) );
|
|
568 |
|
|
569 |
// In case we are in temp visibility mode, we cannot always know whether the BT stack
|
|
570 |
// scan mode key was set by some external party or by us in SetVisibilityModeL above.
|
|
571 |
// Therefore we cannot stop the timer in case aMode is EBTVisibilityModeGeneral and
|
|
572 |
// currentmode is EBTVisibilityModeTemporary
|
|
573 |
if( !( currentMode == EBTVisibilityModeTemporary && aStackScanMode == EBTVisibilityModeGeneral ) )
|
|
574 |
{
|
|
575 |
// Cancel the timer and queue it again if needed.
|
|
576 |
iServer->RemoveTimer( CBTEngServer::EScanModeTimer );
|
|
577 |
if( currentMode != aStackScanMode )
|
|
578 |
{
|
|
579 |
if( aStackScanMode == EPageScanOnly || aStackScanMode == EInquiryAndPageScan )
|
|
580 |
{
|
|
581 |
User::LeaveIfError( cenRep->Set( KBTDiscoverable, aStackScanMode ) );
|
|
582 |
}
|
|
583 |
else if( aStackScanMode == EInquiryScanOnly )
|
|
584 |
{
|
|
585 |
// We don't support ENoScansEnabled nor EInquiryScanOnly mode
|
|
586 |
// -> Consider these as same as Hidden
|
|
587 |
User::LeaveIfError( cenRep->Set( KBTDiscoverable, EBTVisibilityModeHidden ) );
|
|
588 |
}
|
|
589 |
else if( aStackScanMode == ENoScansEnabled )
|
|
590 |
{
|
|
591 |
//We don't change KBTDiscoverable here, because ENoScansEnabled
|
|
592 |
//indicates BT/SYSTEM shutdown is happening
|
|
593 |
}
|
|
594 |
}
|
|
595 |
}
|
|
596 |
SetUiIndicatorsL();
|
|
597 |
CleanupStack::PopAndDestroy( cenRep );
|
|
598 |
TRACE_FUNC_EXIT
|
|
599 |
}
|
|
600 |
|
|
601 |
|
|
602 |
// ---------------------------------------------------------------------------
|
|
603 |
// Set Device Under Test mode.
|
|
604 |
// ---------------------------------------------------------------------------
|
|
605 |
//
|
|
606 |
void CBTEngSrvSettingsMgr::SetDutMode( TInt aDutMode )
|
|
607 |
{
|
|
608 |
TRACE_FUNC_ARG( ( _L( "DUT mode %d" ), aDutMode ) )
|
|
609 |
|
|
610 |
if (aDutMode == EBTDutOff)
|
|
611 |
{
|
|
612 |
return;
|
|
613 |
}
|
|
614 |
|
|
615 |
TInt powerState = EBTOff;
|
|
616 |
CRepository* cenrep = NULL;
|
|
617 |
|
|
618 |
TRAPD(err, cenrep = CRepository::NewL(KCRUidBluetoothPowerState));
|
|
619 |
|
|
620 |
if (!err && cenrep)
|
|
621 |
{
|
|
622 |
cenrep->Get(KBTPowerState, powerState);
|
|
623 |
delete cenrep;
|
|
624 |
cenrep = NULL;
|
|
625 |
}
|
|
626 |
else
|
|
627 |
{
|
|
628 |
return;
|
|
629 |
}
|
|
630 |
|
24
|
631 |
if (powerState == EBTPowerOn)
|
23
|
632 |
{
|
|
633 |
|
|
634 |
#ifndef __WINS__
|
|
635 |
RBluetoothDutMode dutMode;
|
|
636 |
TInt err = dutMode.Open();
|
|
637 |
TRACE_FUNC_ARG( ( _L( "Open DUT mode handle err %d" ), err) )
|
|
638 |
if(!err)
|
|
639 |
{
|
|
640 |
dutMode.ActivateDutMode();
|
|
641 |
dutMode.Close();
|
|
642 |
}
|
|
643 |
#endif //__WINS__
|
|
644 |
}
|
|
645 |
}
|
|
646 |
|
|
647 |
|
|
648 |
// ---------------------------------------------------------------------------
|
|
649 |
// From class MBTEngActiveObserver.
|
|
650 |
// Callback to notify that an outstanding request has completed.
|
|
651 |
// ---------------------------------------------------------------------------
|
|
652 |
//
|
28
|
653 |
void CBTEngSrvSettingsMgr::RequestCompletedL( CBTEngActive* aActive, TInt aStatus )
|
23
|
654 |
{
|
28
|
655 |
__ASSERT_ALWAYS( aActive->RequestId() == KBTEngSettingsActive, PanicServer( EBTEngPanicCorrupt ) );
|
23
|
656 |
TRACE_FUNC_ENTRY
|
|
657 |
(void) aActive;
|
|
658 |
if ( aStatus != KErrNone && aStatus != KErrAlreadyExists && aStatus != KErrCancel )
|
|
659 |
{
|
|
660 |
// Something went wrong, so we turn BT off again.
|
|
661 |
SetPowerStateL( EBTOff, EFalse );
|
|
662 |
}
|
|
663 |
if ( !iMessage.IsNull())
|
|
664 |
{
|
|
665 |
iMessage.Complete( aStatus );
|
|
666 |
}
|
|
667 |
TRACE_FUNC_EXIT
|
|
668 |
}
|
|
669 |
|
28
|
670 |
// ---------------------------------------------------------------------------
|
|
671 |
// From class MBTEngActiveObserver.
|
|
672 |
// Handles cancelation of an outstanding request
|
|
673 |
// ---------------------------------------------------------------------------
|
|
674 |
//
|
|
675 |
void CBTEngSrvSettingsMgr::CancelRequest( TInt aRequestId )
|
|
676 |
{
|
|
677 |
TRACE_FUNC_ARG( ( _L( "reqID %d" ), aRequestId ) );
|
|
678 |
if ( aRequestId == KBTEngSettingsActive )
|
|
679 |
{
|
|
680 |
iPowerMgr.Cancel();
|
|
681 |
}
|
|
682 |
TRACE_FUNC_EXIT
|
|
683 |
}
|
23
|
684 |
|
|
685 |
// ---------------------------------------------------------------------------
|
|
686 |
// From class MBTEngActiveObserver.
|
|
687 |
// Callback to notify that an error has occurred in RunL.
|
|
688 |
// ---------------------------------------------------------------------------
|
|
689 |
//
|
28
|
690 |
void CBTEngSrvSettingsMgr::HandleError( CBTEngActive* aActive, TInt aError )
|
23
|
691 |
{
|
|
692 |
(void) aActive;
|
|
693 |
if ( !iMessage.IsNull())
|
|
694 |
{
|
|
695 |
iMessage.Complete( aError );
|
|
696 |
}
|
|
697 |
}
|
|
698 |
|
|
699 |
|
|
700 |
// ---------------------------------------------------------------------------
|
|
701 |
// Loads the BT Power Manager; leaves if it cannot be loaded.
|
|
702 |
// ---------------------------------------------------------------------------
|
|
703 |
//
|
|
704 |
void CBTEngSrvSettingsMgr::LoadBTPowerManagerL()
|
|
705 |
{
|
|
706 |
TRACE_FUNC_ENTRY
|
|
707 |
TRACE_INFO( ( _L( "[CBTEngSrvSettingsMgr]\t Using HCI API v2 power manager" ) ) )
|
|
708 |
User::LeaveIfError( iPowerMgr.Open() );
|
|
709 |
#ifndef __WINS__
|
45
|
710 |
TRequestStatus reqStatus;
|
|
711 |
iPowerMgr.SetPower( EBTOff, NULL, reqStatus );
|
|
712 |
User::WaitForRequest( reqStatus );
|
|
713 |
TInt status = ( reqStatus.Int() == KErrAlreadyExists ? KErrNone : reqStatus.Int() );
|
23
|
714 |
User::LeaveIfError( status );
|
|
715 |
#else //__WINS__
|
|
716 |
iPowerState = EBTOff;
|
|
717 |
#endif //__WINS__
|
|
718 |
TRACE_FUNC_EXIT
|
|
719 |
}
|
|
720 |
|
|
721 |
|
|
722 |
// ---------------------------------------------------------------------------
|
|
723 |
// ?implementation_description
|
|
724 |
// ---------------------------------------------------------------------------
|
|
725 |
//
|
|
726 |
void CBTEngSrvSettingsMgr::SetUiIndicatorsL()
|
|
727 |
{
|
|
728 |
TRACE_FUNC_ENTRY
|
|
729 |
TBTPowerStateValue powerState = EBTPowerOff;
|
|
730 |
TBTVisibilityMode visibilityMode = EBTVisibilityModeHidden;
|
|
731 |
CRepository* cenrep = NULL;
|
|
732 |
TInt phys = 0;
|
42
|
733 |
// TInt connecting = 0;
|
23
|
734 |
|
|
735 |
cenrep = CRepository::NewLC( KCRUidBluetoothPowerState );
|
|
736 |
User::LeaveIfError( cenrep->Get( KBTPowerState, (TInt&) powerState ) );
|
|
737 |
CleanupStack::PopAndDestroy( cenrep );
|
|
738 |
|
|
739 |
if( powerState == EBTPowerOff )
|
|
740 |
{
|
42
|
741 |
SetIndicatorStateL(EBTIndicatorOff);
|
23
|
742 |
}
|
|
743 |
else
|
|
744 |
{
|
|
745 |
// Power is on.
|
|
746 |
RProperty::Get( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothPHYCount, phys );
|
42
|
747 |
// RProperty::Get( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothConnecting, connecting );
|
23
|
748 |
|
|
749 |
cenrep = CRepository::NewLC( KCRUidBTEngPrivateSettings );
|
|
750 |
User::LeaveIfError( cenrep->Get( KBTDiscoverable, (TInt&) visibilityMode ) );
|
|
751 |
CleanupStack::PopAndDestroy( cenrep );
|
|
752 |
|
|
753 |
if( visibilityMode == EBTVisibilityModeHidden )
|
|
754 |
{
|
42
|
755 |
if ( phys > 0 ) // BT connection active and hidden
|
23
|
756 |
{
|
42
|
757 |
SetIndicatorStateL(EBTIndicatorHiddenConnected);
|
23
|
758 |
}
|
|
759 |
else // BT connection not active and hidden
|
|
760 |
{
|
42
|
761 |
SetIndicatorStateL(EBTIndicatorOnHidden);
|
23
|
762 |
}
|
|
763 |
}
|
|
764 |
else if( visibilityMode == EBTVisibilityModeGeneral || visibilityMode == EBTVisibilityModeTemporary )
|
|
765 |
{
|
42
|
766 |
if ( phys > 0 ) // BT connection active and visible
|
23
|
767 |
{
|
42
|
768 |
SetIndicatorStateL(EBTIndicatorVisibleConnected);
|
23
|
769 |
}
|
|
770 |
else // BT connection not active and visible
|
|
771 |
{
|
42
|
772 |
SetIndicatorStateL(EBTIndicatorOnVisible);
|
23
|
773 |
}
|
|
774 |
}
|
|
775 |
}
|
|
776 |
TRACE_FUNC_EXIT
|
|
777 |
}
|
|
778 |
|
42
|
779 |
void CBTEngSrvSettingsMgr::SetIndicatorStateL( const TInt aState )
|
23
|
780 |
{
|
42
|
781 |
TBool success = EFalse;
|
|
782 |
if(iIndicatorState != aState)
|
|
783 |
{
|
|
784 |
CHbSymbianVariant* parameters = CHbSymbianVariant::NewL(&aState,CHbSymbianVariant::EInt );
|
|
785 |
success = iBTIndicator->Activate(KIndicatorType(),parameters);
|
|
786 |
delete parameters;
|
|
787 |
if(!success)
|
|
788 |
{
|
|
789 |
User::Leave(iBTIndicator->Error());
|
|
790 |
}
|
|
791 |
iIndicatorState = aState;
|
|
792 |
}
|
23
|
793 |
}
|
|
794 |
|
|
795 |
|
|
796 |
// ---------------------------------------------------------------------------
|
|
797 |
// Gets the current HW power state.
|
|
798 |
// For now this is a separate method to isolate the different variations.
|
|
799 |
// ---------------------------------------------------------------------------
|
|
800 |
//
|
|
801 |
TInt CBTEngSrvSettingsMgr::GetHwPowerState( TBTPowerState& aState )
|
|
802 |
{
|
|
803 |
TRACE_FUNC_ENTRY
|
|
804 |
TInt err = KErrNone;
|
|
805 |
|
|
806 |
#ifndef __WINS__
|
|
807 |
err = iPowerMgr.GetPower( aState, NULL );
|
|
808 |
#else //__WINS__
|
|
809 |
aState = iPowerState;
|
|
810 |
#endif //__WINS__
|
|
811 |
TRACE_FUNC_ARG( ( _L( "Power state is %d, result %d" ), (TInt) aState, err ) )
|
|
812 |
return err;
|
|
813 |
}
|
|
814 |
|
|
815 |
// ---------------------------------------------------------------------------
|
|
816 |
// Check the power state and if BT gets turned off automatically.
|
|
817 |
// ---------------------------------------------------------------------------
|
|
818 |
//
|
|
819 |
void CBTEngSrvSettingsMgr::CheckTemporaryPowerStateL( TBTPowerState& aCurrentState,
|
|
820 |
TBTPowerState aNewState, TBool aTemporary )
|
|
821 |
{
|
|
822 |
TRACE_FUNC_ENTRY
|
|
823 |
User::LeaveIfError( GetHwPowerState( aCurrentState ) );
|
|
824 |
if( !aTemporary )
|
|
825 |
{
|
|
826 |
// Force the new power state, so clear all auto switch off flags.
|
|
827 |
// If power is off, this will anyway be ignored.
|
|
828 |
iAutoOffClients = 0;
|
|
829 |
iAutoSwitchOff = EFalse;
|
|
830 |
TCallBack cb;
|
|
831 |
iServer->BasebandConnectionManager()->SetAutoSwitchOff( EFalse, cb );
|
|
832 |
if( iRestoreVisibility && aCurrentState == EBTOn )
|
|
833 |
{
|
|
834 |
// Set visibility mode back to the value selected by the user.
|
|
835 |
SetVisibilityModeL( EBTVisibilityModeGeneral, 0 );
|
|
836 |
iRestoreVisibility = EFalse;
|
|
837 |
}
|
|
838 |
}
|
|
839 |
else
|
|
840 |
{
|
|
841 |
if( aCurrentState == aNewState )
|
|
842 |
{
|
|
843 |
if( iAutoSwitchOff && aNewState == EBTOn )
|
|
844 |
{
|
|
845 |
iAutoOffClients++;
|
|
846 |
iServer->RemoveTimer( CBTEngServer::EAutoPowerOffTimer );
|
|
847 |
}
|
|
848 |
}
|
|
849 |
else if( iAutoSwitchOff || aNewState == EBTOn )
|
|
850 |
{
|
|
851 |
aNewState == EBTOff ? iAutoOffClients-- : iAutoOffClients++;
|
|
852 |
iAutoSwitchOff = ETrue;
|
|
853 |
if( aNewState == EBTOff && iAutoOffClients <= 0 )
|
|
854 |
{
|
|
855 |
TCallBack powerOffCb( CBTEngServer::AutoPowerOffCallBack, iServer );
|
|
856 |
iServer->BasebandConnectionManager()->SetAutoSwitchOff( ETrue, powerOffCb );
|
|
857 |
TInt64 interval = KBTEngBtAutoOffTimeout;
|
|
858 |
iServer->QueueTimer( CBTEngServer::EAutoPowerOffTimer, interval );
|
|
859 |
}
|
|
860 |
else if( aNewState == EBTOn )
|
|
861 |
{
|
|
862 |
CRepository* cenRep = CRepository::NewLC( KCRUidBTEngPrivateSettings );
|
|
863 |
TBTVisibilityMode visibility = EBTVisibilityModeGeneral;
|
|
864 |
TInt err = cenRep->Get( KBTDiscoverable, (TInt&) visibility );
|
|
865 |
CleanupStack::PopAndDestroy( cenRep );
|
|
866 |
if( !err && visibility == EBTVisibilityModeGeneral )
|
|
867 |
{
|
|
868 |
SetVisibilityModeL( EBTVisibilityModeHidden, 0 );
|
|
869 |
iRestoreVisibility = ETrue;
|
|
870 |
}
|
|
871 |
iServer->RemoveTimer( CBTEngServer::EAutoPowerOffTimer );
|
|
872 |
}
|
|
873 |
}
|
|
874 |
}
|
|
875 |
if( iAutoOffClients < 0 )
|
|
876 |
{
|
|
877 |
iAutoOffClients = 0;
|
|
878 |
}
|
|
879 |
TRACE_FUNC_EXIT
|
|
880 |
}
|
28
|
881 |
|