1 /* |
|
2 * Copyright (c) 2008 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: wlanindicatorplugin implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <eikenv.h> |
|
22 #include <avkon.rsg> |
|
23 #include <avkon.hrh> |
|
24 #include <apgcli.h> |
|
25 #include <apgtask.h> |
|
26 #include <coemain.h> |
|
27 #include <bautils.h> |
|
28 #include <data_caging_path_literals.hrh> |
|
29 #include <StringLoader.h> |
|
30 #include <rconnmon.h> |
|
31 #include <cmmanager.h> |
|
32 #include <cmconnectionmethod.h> |
|
33 #include <cmpluginwlandef.h> |
|
34 #include <utf.h> |
|
35 #include <wlanindicator.rsg> |
|
36 #include "wlanindicatorpluginimplementation.h" |
|
37 |
|
38 |
|
39 // CONSTANTS |
|
40 const TUid KSnifferAppUid = { 0x10281CAA }; |
|
41 _LIT( KDriveZ, "z:" ); |
|
42 _LIT( KWlanIndicatorResourceFile, "wlanindicator.rsc" ); |
|
43 |
|
44 using namespace CMManager; |
|
45 |
|
46 // ======== MEMBER FUNCTIONS ======== |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // CWlanIndicatorPluginImplementation::CWlanIndicatorPluginImplementation |
|
50 // C++ default constructor can NOT contain any code, that |
|
51 // might leave. |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CWlanIndicatorPluginImplementation::CWlanIndicatorPluginImplementation() |
|
55 : iCoeEnv( CCoeEnv::Static() ) |
|
56 { |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CWlanIndicatorPluginImplementation::ConstructL |
|
61 // Symbian 2nd phase constructor can leave. |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 void CWlanIndicatorPluginImplementation::ConstructL() |
|
65 { |
|
66 TFileName fileName; |
|
67 |
|
68 fileName.Append( KDriveZ ); |
|
69 fileName.Append( KDC_RESOURCE_FILES_DIR ); |
|
70 fileName.Append( KWlanIndicatorResourceFile ); |
|
71 |
|
72 BaflUtils::NearestLanguageFile( iCoeEnv->FsSession(), fileName ); |
|
73 iResource = iCoeEnv->AddResourceFileL( fileName ); |
|
74 |
|
75 iConnMonitor.ConnectL(); |
|
76 |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CWlanIndicatorPluginImplementation::NewL |
|
81 // Two-phased constructor. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CWlanIndicatorPluginImplementation* CWlanIndicatorPluginImplementation::NewL() |
|
85 { |
|
86 CWlanIndicatorPluginImplementation* self = |
|
87 new( ELeave ) CWlanIndicatorPluginImplementation; |
|
88 CleanupStack::PushL( self ); |
|
89 self->ConstructL(); |
|
90 CleanupStack::Pop( self ); |
|
91 return self; |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CWlanIndicatorPluginImplementation::~CWlanIndicatorPluginImplementation |
|
96 // Destructor. |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 CWlanIndicatorPluginImplementation::~CWlanIndicatorPluginImplementation() |
|
100 { |
|
101 iCoeEnv->DeleteResourceFile( iResource ); |
|
102 |
|
103 iConnMonitor.Close(); |
|
104 |
|
105 } |
|
106 |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // CWlanIndicatorPluginImplementation::HandleIndicatorTapL |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CWlanIndicatorPluginImplementation::HandleIndicatorTapL( const TInt aUid ) |
|
113 { |
|
114 |
|
115 switch ( aUid ) |
|
116 { |
|
117 case EAknIndicatorWlanAvailable: |
|
118 case EAknIndicatorWlanActive: |
|
119 case EAknIndicatorWlanActiveSecure: |
|
120 { |
|
121 |
|
122 LaunchWlanSnifferL(); |
|
123 |
|
124 break; |
|
125 } |
|
126 |
|
127 default: |
|
128 |
|
129 break; |
|
130 |
|
131 } |
|
132 |
|
133 |
|
134 } |
|
135 |
|
136 |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // CWlanIndicatorPluginImplementation::TextL( const TInt aUid, TInt& aTextType ) |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 HBufC* CWlanIndicatorPluginImplementation::TextL( const TInt aUid, |
|
143 TInt& aTextType ) |
|
144 { |
|
145 |
|
146 HBufC* textBuf = NULL; |
|
147 |
|
148 switch ( aUid ) |
|
149 { |
|
150 case EAknIndicatorWlanAvailable: |
|
151 { |
|
152 textBuf = CreateWlanNetworksFoundTextL(); |
|
153 aTextType = EAknIndicatorPluginLinkText; |
|
154 |
|
155 break; |
|
156 } |
|
157 |
|
158 case EAknIndicatorWlanActive: |
|
159 case EAknIndicatorWlanActiveSecure: |
|
160 { |
|
161 textBuf = CreateWlanConnectedTextL(); |
|
162 aTextType = EAknIndicatorPluginLinkText; |
|
163 |
|
164 break; |
|
165 } |
|
166 |
|
167 default: |
|
168 |
|
169 break; |
|
170 |
|
171 } |
|
172 |
|
173 |
|
174 return textBuf; |
|
175 |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // CWlanIndicatorPluginImplementation::CreateWlanNetworksFoundTextL() |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 HBufC* CWlanIndicatorPluginImplementation::CreateWlanNetworksFoundTextL() |
|
183 { |
|
184 |
|
185 HBufC* dynText = NULL; |
|
186 |
|
187 // "qtn_uni_ind_wlan_avail_unknown_many WLAN networks found" |
|
188 dynText = StringLoader::LoadL ( |
|
189 R_QTN_UNI_IND_WLAN_AVAIL_UNKNOWN_MANY, iCoeEnv ); |
|
190 |
|
191 return dynText; |
|
192 } |
|
193 |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // CWlanIndicatorPluginImplementation::CreateWlanConnectedTextL() |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 HBufC* CWlanIndicatorPluginImplementation::CreateWlanConnectedTextL() |
|
200 { |
|
201 |
|
202 HBufC* dynText = NULL; |
|
203 HBufC* connectedNetworkName = NULL; |
|
204 |
|
205 connectedNetworkName = ConnectionNameL( ); |
|
206 |
|
207 CleanupStack::PushL( connectedNetworkName ); |
|
208 |
|
209 if ( connectedNetworkName ) |
|
210 { |
|
211 // "qtn_uni_ind_wlan_conn '%U' connected" |
|
212 dynText = StringLoader::LoadL ( |
|
213 R_QTN_UNI_IND_WLAN_CONN, *connectedNetworkName, iCoeEnv ); |
|
214 } |
|
215 |
|
216 CleanupStack::PopAndDestroy( connectedNetworkName ); |
|
217 |
|
218 return dynText; |
|
219 } |
|
220 |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // CWlanIndicatorPluginImplementation::ConnectionNameL() |
|
224 // --------------------------------------------------------------------------- |
|
225 // |
|
226 HBufC* CWlanIndicatorPluginImplementation::ConnectionNameL( ) |
|
227 { |
|
228 HBufC* connName = NULL; |
|
229 |
|
230 // get the connection ID |
|
231 TUint connectionId = FindWlanBearerConnectedL(); |
|
232 |
|
233 TUint connectedIapId(0); |
|
234 TRequestStatus status; |
|
235 |
|
236 // get the IAP ID |
|
237 iConnMonitor.GetUintAttribute( connectionId, 0, KIAPId, |
|
238 connectedIapId, status ); |
|
239 User::WaitForRequest( status ); |
|
240 |
|
241 // get the connection method from cmmanager |
|
242 RCmManager cmManager; |
|
243 cmManager.OpenLC(); |
|
244 |
|
245 RCmConnectionMethod connMethod = cmManager.ConnectionMethodL( connectedIapId ); |
|
246 CleanupClosePushL( connMethod ); |
|
247 |
|
248 TUint32 easyWLANIapId = cmManager.EasyWlanIdL(); |
|
249 if ( easyWLANIapId != connectedIapId ) |
|
250 { |
|
251 connName = connMethod.GetStringAttributeL( ECmName ); |
|
252 } |
|
253 else |
|
254 { |
|
255 connName = connMethod.GetStringAttributeL( EWlanUsedSSID ); |
|
256 } |
|
257 |
|
258 CleanupStack::PopAndDestroy( 2, &cmManager ); //cmManager and connMethod |
|
259 |
|
260 return connName; |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------------------------- |
|
264 // CWlanIndicatorPluginImplementation::FindWlanBearerConnectedL() |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 TUint CWlanIndicatorPluginImplementation::FindWlanBearerConnectedL( ) |
|
268 { |
|
269 TUint connectionId( 0 ); |
|
270 |
|
271 TUint connCount( 0 ); |
|
272 TUint subConnectionCount( 0 ); |
|
273 TRequestStatus status; |
|
274 |
|
275 iConnMonitor.GetConnectionCount( connCount, status ); |
|
276 User::WaitForRequest( status ); |
|
277 |
|
278 if ( status.Int() == KErrNone ) |
|
279 { |
|
280 for ( TUint i = 1; i <= connCount; ++i ) |
|
281 { |
|
282 User::LeaveIfError( iConnMonitor.GetConnectionInfo( i, connectionId, |
|
283 subConnectionCount ) ); |
|
284 if ( CheckIfWlan( connectionId ) ) |
|
285 { |
|
286 break; |
|
287 } |
|
288 } |
|
289 } |
|
290 |
|
291 return connectionId; |
|
292 } |
|
293 |
|
294 // --------------------------------------------------------------------------- |
|
295 // CWlanIndicatorPluginImplementation::CheckIfWlan() |
|
296 // --------------------------------------------------------------------------- |
|
297 // |
|
298 TBool CWlanIndicatorPluginImplementation::CheckIfWlan( TUint aConnectionId ) |
|
299 { |
|
300 TConnMonBearerType bearerType( EBearerUnknown ); |
|
301 |
|
302 TBool foundWlanBearer( EFalse ); |
|
303 |
|
304 TRequestStatus status; |
|
305 |
|
306 // Add only connections with valid id |
|
307 if ( aConnectionId > 0 ) |
|
308 { |
|
309 iConnMonitor.GetIntAttribute( aConnectionId, 0, KBearer, (TInt&)bearerType, |
|
310 status ); |
|
311 User::WaitForRequest( status ); |
|
312 |
|
313 if ( status.Int() == KErrNone ) |
|
314 { |
|
315 if ( bearerType == EBearerWLAN ) |
|
316 { |
|
317 foundWlanBearer = ETrue; |
|
318 } |
|
319 } |
|
320 |
|
321 } |
|
322 |
|
323 return foundWlanBearer; |
|
324 |
|
325 } |
|
326 |
|
327 // --------------------------------------------------------------------------- |
|
328 // CWlanIndicatorPluginImplementation::LaunchWlanSnifferL() |
|
329 // --------------------------------------------------------------------------- |
|
330 // |
|
331 void CWlanIndicatorPluginImplementation::LaunchWlanSnifferL() |
|
332 { |
|
333 |
|
334 RApaLsSession appArcSession; |
|
335 |
|
336 User::LeaveIfError( appArcSession.Connect() ); // connect to AppArc server |
|
337 CleanupClosePushL( appArcSession ); |
|
338 |
|
339 // check if the app is already running |
|
340 TApaTaskList taskList( CEikonEnv::Static()->WsSession() ); |
|
341 TApaTask task = taskList.FindApp( KSnifferAppUid ); |
|
342 |
|
343 if ( task.Exists() ) |
|
344 { |
|
345 task.BringToForeground(); |
|
346 } |
|
347 else |
|
348 { |
|
349 TThreadId threadId; |
|
350 User::LeaveIfError( appArcSession.StartDocument( KNullDesC, |
|
351 KSnifferAppUid, threadId ) ); |
|
352 |
|
353 } |
|
354 |
|
355 CleanupStack::PopAndDestroy(); // appArcSession |
|
356 |
|
357 } |
|
358 |
|
359 // End of File |
|