|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Implement PSM plug-in and handle BT PowerState with PSM mode |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32property.h> |
|
20 #include <bt_subscribe.h> |
|
21 #include <psmtypes.h> |
|
22 #include <psmsettingsprovider.h> |
|
23 |
|
24 #include "btengpsmplugin.h" |
|
25 #include "debug.h" |
|
26 |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // CBTPsmPlugin::NewL |
|
32 // Two phased constructor |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CBTPsmPlugin* CBTPsmPlugin::NewL(TPsmPluginCTorParams& aInitParams) |
|
36 { |
|
37 CBTPsmPlugin* self = new (ELeave) CBTPsmPlugin(aInitParams); |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CBTPsmPlugin::~CBTPsmPlugin |
|
46 // Destructor |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CBTPsmPlugin::~CBTPsmPlugin() |
|
50 { |
|
51 TRACE_FUNC_ENTRY |
|
52 |
|
53 delete iBtEngSettings; |
|
54 |
|
55 TRACE_FUNC_EXIT |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // From class CPSMBase |
|
60 // CBTPsmPlugin::NotifyModeChange() |
|
61 // Handle BT power state when PowerSaveMode enables/disables. |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 void CBTPsmPlugin::NotifyModeChange( const TInt aMode ) |
|
65 { |
|
66 iMode = aMode; |
|
67 TRAP_IGNORE(NotifyModeChangeL()); |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // From class MBTEngSettingsObserver |
|
72 // CBTPsmPlugin::PowerStateChanged() |
|
73 // Save the changed power state into PSM storage as settings in Normal mode |
|
74 // if the change was caused by the user. |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 void CBTPsmPlugin::PowerStateChanged( TBTPowerStateValue aState ) |
|
78 { |
|
79 TRACE_FUNC_ENTRY |
|
80 |
|
81 if( iMode == EPsmsrvModePowerSave && iAllowToConfig) |
|
82 { |
|
83 TRAP_IGNORE( SavePsmConfigurationL( aState ) ); |
|
84 } |
|
85 |
|
86 if( !iAllowToConfig ) |
|
87 { |
|
88 iAllowToConfig = ETrue; |
|
89 } |
|
90 |
|
91 TRACE_FUNC_EXIT |
|
92 }; |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // From class MBTEngSettingsObserver |
|
96 // CBTPsmPlugin::VisibilityModeChanged() |
|
97 // Power Saving Mode change does not affect Bluetooth visibility. |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 void CBTPsmPlugin::VisibilityModeChanged( TBTVisibilityMode /*aState*/ ) |
|
101 { |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------- |
|
105 // CBTPsmPlugin::CBTPsmPlugin |
|
106 // Default C++ constructor |
|
107 // --------------------------------------------------------- |
|
108 CBTPsmPlugin::CBTPsmPlugin( TPsmPluginCTorParams& aInitParams ) |
|
109 : CPsmPluginBase( aInitParams ), iMode( KErrNotFound ), iAllowToConfig( EFalse ) |
|
110 { |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------- |
|
114 // CBTPsmPlugin::ConstructL |
|
115 // Symbian 2nd phase constructor can leave. |
|
116 // --------------------------------------------------------- |
|
117 // |
|
118 void CBTPsmPlugin::ConstructL() |
|
119 { |
|
120 TRACE_FUNC_ENTRY |
|
121 |
|
122 iBtEngSettings = CBTEngSettings::NewL(this); |
|
123 |
|
124 TRACE_FUNC_EXIT |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CBTPsmPlugin::NotifyModeChangeL() |
|
129 // Leave function called by NotifyModeChange() |
|
130 // Handle BT power state when PowerSaveMode enables/disables. |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 void CBTPsmPlugin::NotifyModeChangeL() |
|
134 { |
|
135 TRACE_FUNC_ENTRY |
|
136 TInt connNum = 0; |
|
137 TInt retVal = RProperty::Get(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothGetPHYCount, connNum); |
|
138 TRACE_INFO((_L("[BTPsmPlugin]\t GetPHYCount result: %d"), retVal)); |
|
139 |
|
140 if( iMode == EPsmsrvModePowerSave ) |
|
141 { |
|
142 if( !retVal ) |
|
143 { |
|
144 TRACE_INFO((_L("[BTPsmPlugin]\t PHYCount=: %d"), connNum)); |
|
145 |
|
146 if( connNum > 0 ) // active connection exists |
|
147 { |
|
148 iAllowToConfig = ETrue; |
|
149 } |
|
150 else //no active connections |
|
151 { |
|
152 HandlePowerStateL(); |
|
153 } |
|
154 } |
|
155 } |
|
156 |
|
157 if( iMode == EPsmsrvModeNormal ) |
|
158 { |
|
159 if( !retVal && connNum == 0 ) // active connection exists |
|
160 { |
|
161 HandlePowerStateL(); |
|
162 } |
|
163 iAllowToConfig = EFalse; |
|
164 } |
|
165 |
|
166 TRACE_FUNC_EXIT |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // CBTPsmPlugin::HandlePowerStateL() |
|
171 // Handle how to change BT power state |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 void CBTPsmPlugin::HandlePowerStateL() |
|
175 { |
|
176 TRACE_FUNC_ENTRY |
|
177 |
|
178 TBTPowerStateValue powerBeforeChange; |
|
179 iBtEngSettings->GetPowerState( powerBeforeChange ); |
|
180 if( powerBeforeChange == EBTPowerOff ) |
|
181 { |
|
182 iAllowToConfig = ETrue; |
|
183 } |
|
184 |
|
185 TBTPowerStateValue powerToChange = EBTPowerOff; |
|
186 TRAPD(err, powerToChange = GetSettingsFromPsmStorageL() ); |
|
187 TRACE_INFO((_L("[BTPsmPlugin]\t CBTPsmPlugin::GetSettingsFromPsmStorageL Leave status: %d"), err)); |
|
188 // If we can't read previous BT state information from PSM configuration, |
|
189 // BT Power is not toogled only if PSM is switching of. |
|
190 // When switching PSM On BT should be always turned Off. |
|
191 // Active connections were checked before. |
|
192 if( powerBeforeChange != powerToChange && ( !err || iMode == EPsmsrvModePowerSave ) ) |
|
193 { |
|
194 TInt errCode = iBtEngSettings->SetPowerState( powerToChange ); |
|
195 TRACE_INFO((_L("[BTPsmPlugin]\t CBTPsmPlugin::HandlePowerStateL() %d"), errCode)); |
|
196 } |
|
197 |
|
198 if( iMode == EPsmsrvModePowerSave ) |
|
199 { |
|
200 SavePsmConfigurationL( powerBeforeChange ); |
|
201 } |
|
202 |
|
203 TRACE_FUNC_EXIT |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // CBTPsmPlugin::GetSettingsFromPsmStorageL() |
|
208 // Retrive power state from PSM configuration file |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 TBTPowerStateValue CBTPsmPlugin::GetSettingsFromPsmStorageL() |
|
212 { |
|
213 TRACE_FUNC_ENTRY |
|
214 |
|
215 TPsmsrvConfigInfo info; |
|
216 info.iConfigId = 1; |
|
217 info.iConfigType = EConfigTypeInt; |
|
218 info.iIntValue = 0; |
|
219 info.iBlocked = EFalse; |
|
220 |
|
221 RConfigInfoArray configInfoArray; |
|
222 CleanupClosePushL( configInfoArray ); |
|
223 |
|
224 configInfoArray.AppendL( info ); |
|
225 iSettingsProvider.GetSettingsL(configInfoArray, KCRUidBluetoothPowerState.iUid); |
|
226 |
|
227 TBTPowerStateValue power = EBTPowerOff; |
|
228 if( configInfoArray.Count() > 0 ) |
|
229 { |
|
230 power = (TBTPowerStateValue) configInfoArray[0].iIntValue; |
|
231 } |
|
232 CleanupStack::PopAndDestroy( &configInfoArray ); |
|
233 |
|
234 TRACE_FUNC_EXIT |
|
235 return power; |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------- |
|
239 // CBTPsmPlugin::UpdatePsmConfiguration |
|
240 // Write BTPowerState into PSM Configuration file |
|
241 // --------------------------------------------------------- |
|
242 // |
|
243 void CBTPsmPlugin::SavePsmConfigurationL(TBTPowerStateValue aState) |
|
244 { |
|
245 TRACE_FUNC_ENTRY |
|
246 |
|
247 TPsmsrvConfigInfo infoForNormal; |
|
248 infoForNormal.iConfigId = 1; |
|
249 infoForNormal.iConfigType = EConfigTypeInt; |
|
250 infoForNormal.iIntValue = aState; |
|
251 infoForNormal.iBlocked = EFalse; |
|
252 |
|
253 RConfigInfoArray configInfo; |
|
254 configInfo.AppendL(infoForNormal); |
|
255 iSettingsProvider.BackupSettingsL( configInfo, KCRUidBluetoothPowerState.iUid ); |
|
256 configInfo.Close(); |
|
257 |
|
258 TRACE_FUNC_EXIT |
|
259 } |