|
1 /* |
|
2 * Copyright (c) 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: This is the class module for the Diag USB Cable Test Engine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 // Class Declaration |
|
22 #include "diagusbcabletestengine.h" |
|
23 |
|
24 // System includes |
|
25 #include <DiagFrameworkDebug.h> // LOGSTRING |
|
26 #include <DiagPluginWaitingDialogWrapper.h> // CDiagPluginWaitingDialogWrapper |
|
27 #include <devdiagusbcabletestpluginrsc.rsg> // resources |
|
28 #include <UsbWatcherInternalCRKeys.h> // KUsbWatcherChangeOnConnectionSetting |
|
29 #include <aknmessagequerydialog.h> // CAknQueryDialog |
|
30 #include <centralrepository.h> // CRepository |
|
31 |
|
32 |
|
33 // User includes |
|
34 #include "diagusbcabletestplugin.hrh" // command ids |
|
35 #include "avkon.hrh" // ADO & Platformization Changes |
|
36 |
|
37 // EXTERNAL DATA STRUCTURES |
|
38 |
|
39 // EXTERNAL FUNCTION PROTOTYPES |
|
40 |
|
41 // CONSTANTS |
|
42 |
|
43 // MACROS |
|
44 |
|
45 // LOCAL CONSTANTS AND MACROS |
|
46 |
|
47 // MODULE DATA STRUCTURES |
|
48 |
|
49 // LOCAL FUNCTION PROTOTYPES |
|
50 |
|
51 // FORWARD DECLARATIONS |
|
52 |
|
53 // ============================= LOCAL FUNCTIONS ============================== |
|
54 |
|
55 // ========================= MEMBER FUNCTIONS ================================ |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CDiagUSBCableTestEngine::NewL() |
|
59 // |
|
60 // Symbian OS default constructor |
|
61 // --------------------------------------------------------------------------- |
|
62 CDiagUSBCableTestEngine* CDiagUSBCableTestEngine::NewL( |
|
63 MDiagUSBTestCallBackInterface& aInterface, |
|
64 TBool aIsSinglePluginExecution) |
|
65 { |
|
66 LOGSTRING( "CDiagUSBCableTestEngine::NewL()" ) |
|
67 |
|
68 CDiagUSBCableTestEngine* self = |
|
69 new (ELeave)CDiagUSBCableTestEngine(aInterface, aIsSinglePluginExecution); |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(); |
|
72 CleanupStack::Pop( self ); |
|
73 return self; |
|
74 } |
|
75 |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // CDiagUSBCableTestEngine::CDiagUSBCableTestEngine() |
|
79 // |
|
80 // Constructor |
|
81 // ---------------------------------------------------------------------------- |
|
82 // |
|
83 CDiagUSBCableTestEngine::CDiagUSBCableTestEngine( |
|
84 MDiagUSBTestCallBackInterface& aInterface, |
|
85 TBool aIsSinglePluginExecution) |
|
86 : CActive( EPriorityStandard ), |
|
87 iInterface(aInterface), |
|
88 iWaitingDialogWrapper( NULL ), |
|
89 iIsSinglePluginExecution(aIsSinglePluginExecution) |
|
90 { |
|
91 LOGSTRING( "CDiagUSBCableTestEngine::CDiagUSBCableTestEngine()" ) |
|
92 CActiveScheduler::Add( this ); |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // CDiagUSBCableTestEngine::~CDiagUSBCableTestEngine |
|
97 // |
|
98 // Destructor |
|
99 // ---------------------------------------------------------------------------- |
|
100 CDiagUSBCableTestEngine::~CDiagUSBCableTestEngine() |
|
101 { |
|
102 LOGSTRING( "CDiagUSBCableTestEngine::~CDiagUSBCableTestEngine()" ) |
|
103 |
|
104 Cancel(); |
|
105 |
|
106 if(iCenRep) |
|
107 { |
|
108 // if the cenrep was modified by us , restore the settings |
|
109 if(iCenrepModified) |
|
110 { |
|
111 TInt error = iCenRep->Set( KUsbWatcherChangeOnConnectionSetting, 1); |
|
112 iCenrepModified = EFalse; |
|
113 } |
|
114 |
|
115 delete iCenRep; |
|
116 iCenRep = NULL; |
|
117 } |
|
118 |
|
119 if(iWaitingDialogWrapper) |
|
120 { |
|
121 delete iWaitingDialogWrapper; // deleting will dismiss active dialog |
|
122 iWaitingDialogWrapper = NULL; |
|
123 } |
|
124 |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CDiagUSBCableTestEngine::ConstructL() |
|
129 // |
|
130 // Symbian OS two-phased constructor |
|
131 // --------------------------------------------------------------------------- |
|
132 void CDiagUSBCableTestEngine::ConstructL() |
|
133 { |
|
134 LOGSTRING( "CDiagUSBCableTestEngine::ConstructL()" ) |
|
135 |
|
136 // check if USB's "Ask on Connection" is on |
|
137 // if ON, set if OFF, remember to turn in ON again at the end of test |
|
138 |
|
139 TInt retval; |
|
140 iCenRep = CRepository::NewL( KCRUidUsbWatcher ); |
|
141 iCenrepModified = EFalse; |
|
142 iCenRep->Get( KUsbWatcherChangeOnConnectionSetting, retval); |
|
143 if(retval) |
|
144 { |
|
145 //if setting is 1,set it to 0, and remember to reset it back when application exits. |
|
146 iCenrepModified = ETrue; |
|
147 TInt error = iCenRep->Set( KUsbWatcherChangeOnConnectionSetting, 0); |
|
148 } |
|
149 } |
|
150 |
|
151 |
|
152 // ---------------------------------------------------------------------------- |
|
153 // CDiagUSBCableTestEngine::RunUSBCableTestL |
|
154 // |
|
155 // This function starts the USB cable test |
|
156 // ---------------------------------------------------------------------------- |
|
157 void CDiagUSBCableTestEngine::RunUSBCableTestL() |
|
158 { |
|
159 TInt userResponse; |
|
160 |
|
161 if ( !ConnectAndPressOkL( userResponse ) ) |
|
162 { |
|
163 //"Connect and Press OK" dialog was dismissed internally by the framework |
|
164 // return immediately |
|
165 LOGSTRING( "CDiagUSBCableTestEngine Connect USB and confirm dialog was dismissed internally" ) |
|
166 return; |
|
167 } |
|
168 |
|
169 switch( userResponse ) |
|
170 { |
|
171 // user selects OK for "Connect and Press OK" dialog |
|
172 case EAknSoftkeyOk: |
|
173 { |
|
174 //TInt keySelect; |
|
175 // check if cable is connected |
|
176 if( CheckIfUSBCableDetectedL() ) |
|
177 { |
|
178 // USB cable is detected |
|
179 /* |
|
180 if ( !RemoveAllCablesL( keySelect ) ) |
|
181 { |
|
182 LOGSTRING( "CDiagUSBCableTestEngine : Remove All Cable dialog was dismissed internally pressed" ) |
|
183 return; |
|
184 } |
|
185 |
|
186 if ( keySelect != EAknSoftkeyOk ) |
|
187 { |
|
188 LOGSTRING( "CDiagUSBCableTestEngine : EndKey has pressed" ) |
|
189 return; |
|
190 } |
|
191 */ // ADO & Platformization Changes |
|
192 |
|
193 LOGSTRING( "CDiagUSBCableTestEngine : Report result Success" ) |
|
194 ReportResultToPluginL( CDiagResultsDatabaseItem::ESuccess ); |
|
195 } |
|
196 else |
|
197 { |
|
198 // no cable detected |
|
199 if ( !AskIfRetryL( userResponse ) ) |
|
200 { |
|
201 // Retry dialog was dimissed internally by the framework |
|
202 // return immediately |
|
203 LOGSTRING( "CDiagUSBCableTestEngine Ask for retry dialog was dismissed internally" ) |
|
204 return; |
|
205 } |
|
206 |
|
207 |
|
208 |
|
209 if( userResponse == EAknSoftkeyYes ) |
|
210 { |
|
211 // User selects Back to retry the test |
|
212 // will come here in case of Back or Cancel key |
|
213 TRequestStatus* status = &iStatus; |
|
214 SetActive(); |
|
215 User::RequestComplete( status, KErrNone ); |
|
216 } |
|
217 else |
|
218 { |
|
219 //Retry dialog was dismissed by Cancel / End key |
|
220 ReportResultToPluginL(CDiagResultsDatabaseItem::EFailed); |
|
221 LOGSTRING( "CDiagUSBCableTestEngine Retry dialog was dismissed by Cancel / End key" ) |
|
222 return; |
|
223 } |
|
224 } |
|
225 } |
|
226 break; |
|
227 |
|
228 // user selects CANCEL softkey for "Connect and Press OK" dialog |
|
229 case EUsbTestConnectUSBSkip: |
|
230 case EUsbTestConnectUSBCancel: |
|
231 { |
|
232 LOGSTRING( "CDiagUSBCableTestEngine User Cancelled the test execution" ) |
|
233 if(iIsSinglePluginExecution) |
|
234 { |
|
235 LOGSTRING( "CDiagUSBCableTestEngine User skipped the test execution" ) |
|
236 ReportResultToPluginL(CDiagResultsDatabaseItem::ESkipped); |
|
237 } |
|
238 else |
|
239 { |
|
240 TInt aOption = 1; |
|
241 if(iInterface.AskCancelExecutionL(userResponse,aOption)) |
|
242 { |
|
243 if(userResponse) |
|
244 { |
|
245 LOGSTRING( "CDiagUSBCableTestEngine Test cancelled by user" ) |
|
246 return; |
|
247 } |
|
248 else |
|
249 { |
|
250 // currently no way to distinguish between "No" and "Cancel" key |
|
251 LOGSTRING( "CDiagUSBCableTestEngine : User selected No to Cancel dialog" ) |
|
252 // do a self-trigger to start again |
|
253 TRequestStatus* status = &iStatus; |
|
254 SetActive(); |
|
255 User::RequestComplete( status, KErrNone ); |
|
256 } |
|
257 } |
|
258 else |
|
259 { |
|
260 // though the cancel dialog should not be dismissed internally, this is |
|
261 // just a safeguard to be sure we dont do anything |
|
262 LOGSTRING( "CDiagUSBCableTestEngine Test cancel dialog dismissed internally" ) |
|
263 break; |
|
264 } |
|
265 } |
|
266 |
|
267 } |
|
268 break; |
|
269 |
|
270 // user selects CANCEL End Key for "Connect and Press OK" dialog |
|
271 default: |
|
272 { |
|
273 LOGSTRING( "CDiagUSBCableTestEngine Connect USB and confirm dialog was cancelled by the end key" ) |
|
274 } |
|
275 break; |
|
276 }; |
|
277 } |
|
278 |
|
279 // ---------------------------------------------------------------------------- |
|
280 // CDiagUSBCableTestEngine::CheckIfUSBCableDetectedL |
|
281 // |
|
282 // This function reports the result to plugin |
|
283 // ---------------------------------------------------------------------------- |
|
284 TBool CDiagUSBCableTestEngine::CheckIfUSBCableDetectedL() |
|
285 { |
|
286 TBool bCableDetected = EFalse; |
|
287 TInt err = iUsbManager.Connect(); |
|
288 if(err == KErrNone) |
|
289 { |
|
290 // get the USB service state |
|
291 TUsbServiceState UsbServiceState; |
|
292 err = iUsbManager.GetServiceState(UsbServiceState); |
|
293 LOGSTRING2( "CDiagUSBCableTestEngine::USB service state: %d", UsbServiceState) |
|
294 |
|
295 if(err == KErrNone) |
|
296 { |
|
297 switch(UsbServiceState) |
|
298 { |
|
299 case EUsbServiceStarting: |
|
300 case EUsbServiceStarted: |
|
301 { |
|
302 // get the USB device state |
|
303 TUsbDeviceState UsbDeviceState; |
|
304 err = iUsbManager.GetDeviceState(UsbDeviceState); |
|
305 LOGSTRING2( "CDiagUSBCableTestEngine::USB Device state: %d", UsbDeviceState) |
|
306 if(err == KErrNone) |
|
307 { |
|
308 if(UsbDeviceState > EUsbDeviceStatePowered) |
|
309 { |
|
310 bCableDetected = ETrue; |
|
311 } |
|
312 else |
|
313 { |
|
314 bCableDetected = EFalse; |
|
315 } |
|
316 } |
|
317 else |
|
318 { |
|
319 LOGSTRING( "CDiagUSBCableTestEngine Error in obtaining USB Device state") |
|
320 bCableDetected = EFalse; |
|
321 } |
|
322 } |
|
323 break; |
|
324 |
|
325 case EUsbServiceIdle: |
|
326 case EUsbServiceStopping: |
|
327 case EUsbServiceFatalError: |
|
328 default: |
|
329 { |
|
330 bCableDetected = EFalse; |
|
331 } |
|
332 break; |
|
333 }; |
|
334 } |
|
335 else |
|
336 { |
|
337 LOGSTRING( "CDiagUSBCableTestEngine Error in obtaining USB Service state") |
|
338 bCableDetected = EFalse; |
|
339 } |
|
340 |
|
341 iUsbManager.Close(); |
|
342 } |
|
343 else |
|
344 { |
|
345 LOGSTRING( "CDiagUSBCableTestEngine::iUsbManager.Connect() failed" ) |
|
346 bCableDetected = EFalse; |
|
347 } |
|
348 |
|
349 return bCableDetected; |
|
350 } |
|
351 |
|
352 // ---------------------------------------------------------------------------- |
|
353 // CDiagUSBCableTestEngine::ReportResultToPluginL |
|
354 // |
|
355 // This function reports the result to plugin |
|
356 // ---------------------------------------------------------------------------- |
|
357 void CDiagUSBCableTestEngine::ReportResultToPluginL( |
|
358 CDiagResultsDatabaseItem::TResult aResult) |
|
359 { |
|
360 iInterface.ReportTestResultL(aResult); |
|
361 } |
|
362 |
|
363 // -------------------------------------------------------------------------------------------------------------- |
|
364 // CDiagUSBCableTestPlugin::ConnectAndPressOkL |
|
365 // This function shows the query dialog : "Connect an USB data cable from phone to the PC. Press OK when ready." |
|
366 // -------------------------------------------------------------------------------------------------------------- |
|
367 TBool CDiagUSBCableTestEngine::ConnectAndPressOkL( TInt& aUserResponse ) |
|
368 { |
|
369 ASSERT( iWaitingDialogWrapper == NULL ); |
|
370 |
|
371 CAknQueryDialog* dialog = CAknQueryDialog::NewL( CAknQueryDialog::ENoTone ); |
|
372 CleanupStack::PushL( dialog ); |
|
373 dialog->PrepareLC( R_DIAG_USB_CABLE_TEST_CONNECT_AND_PRESS_OK ); |
|
374 if( iIsSinglePluginExecution ) |
|
375 { |
|
376 CEikButtonGroupContainer& cba = dialog->ButtonGroupContainer(); |
|
377 cba.SetCommandSetL( R_CBA_SINGLE_EXECUTION ); |
|
378 } |
|
379 CleanupStack::Pop( dialog ); |
|
380 |
|
381 // dialog ownership to bepassed to iWaitingDialogWrapper |
|
382 // CDiagPluginWaitingDialogWrapper::NewL will push dialog into clean up stack |
|
383 iWaitingDialogWrapper = CDiagPluginWaitingDialogWrapper::NewL( dialog ); |
|
384 dialog = NULL; |
|
385 |
|
386 TBool isDialogDismissedByUser = iWaitingDialogWrapper->RunLD( aUserResponse ); |
|
387 if ( isDialogDismissedByUser ) |
|
388 { |
|
389 // local variable can be accessed only if it was returned due to |
|
390 // user response. iWaitingDialogWrapper self destructs. |
|
391 iWaitingDialogWrapper = NULL; |
|
392 } |
|
393 |
|
394 return isDialogDismissedByUser; |
|
395 } |
|
396 |
|
397 // --------------------------------------------------------------------------------------- |
|
398 // CDiagUSBCableTestPlugin::RemoveAllCables |
|
399 // This function shows the query dialog : Please remove all cables |
|
400 // --------------------------------------------------------------------------------------- |
|
401 TBool CDiagUSBCableTestEngine::RemoveAllCablesL( TInt& aUserResponse ) |
|
402 { |
|
403 ASSERT( iWaitingDialogWrapper == NULL ); |
|
404 |
|
405 CAknQueryDialog* dialog = CAknQueryDialog::NewL( CAknQueryDialog::ENoTone ); |
|
406 |
|
407 dialog->PrepareLC( R_DIAG_CABLE_TEST_REMOVE_ALL_CABLES ); |
|
408 |
|
409 // dialog ownership to bepassed to iWaitingDialogWrapper |
|
410 // CDiagPluginWaitingDialogWrapper::NewL will push dialog into clean up stack |
|
411 iWaitingDialogWrapper = CDiagPluginWaitingDialogWrapper::NewL( dialog ); |
|
412 dialog = NULL; |
|
413 |
|
414 TBool isDialogDismissedByUser = iWaitingDialogWrapper->RunLD( aUserResponse ); |
|
415 if ( isDialogDismissedByUser ) |
|
416 { |
|
417 // local variable can be accessed only if it was returned due to |
|
418 // user response. iWaitingDialogWrapper self destructs. |
|
419 iWaitingDialogWrapper = NULL; |
|
420 } |
|
421 |
|
422 return isDialogDismissedByUser; |
|
423 } |
|
424 |
|
425 // -------------------------------------------------------------------------------------------------------------------------- |
|
426 // CDiagUSBCableTestPlugin::AskIfRetryL |
|
427 // This function shows the query dialog : "USB data cable not detected. Press OK to continue or press Back to retry this test." |
|
428 // --------------------------------------------------------------------------------------------------------------------------- |
|
429 TBool CDiagUSBCableTestEngine::AskIfRetryL( TInt& aUserResponse ) |
|
430 { |
|
431 return DisplayQueryDialogWithHeaderL( R_DIAG_USB_CABLE_TEST_NO_CABLE_DETECTED, |
|
432 aUserResponse ); |
|
433 } |
|
434 |
|
435 // --------------------------------------------------------------------------------------- |
|
436 // CDiagUSBCableTestPlugin::DisplayQueryDialogWithHeaderL |
|
437 // This function shows the query dialog. It returns ETrue, if the dialog is dismissed by user |
|
438 // if the dialog was dismissed because of time-out, it returns EFalse. The user response (softkey) |
|
439 // is returned in the reference argument aUserResponse |
|
440 // --------------------------------------------------------------------------------------- |
|
441 TBool CDiagUSBCableTestEngine::DisplayQueryDialogWithHeaderL( |
|
442 TInt aDialogResourceId, |
|
443 TInt& aUserResponse ) |
|
444 { |
|
445 ASSERT( iWaitingDialogWrapper == NULL ); |
|
446 |
|
447 CAknMessageQueryDialog * dialog = new ( ELeave ) CAknMessageQueryDialog ( CAknQueryDialog::ENoTone ); |
|
448 CleanupStack::PushL( dialog ); |
|
449 dialog->PrepareLC( aDialogResourceId ); |
|
450 CleanupStack::Pop( dialog ); |
|
451 |
|
452 // dialog ownership to bepassed to iWaitingDialogWrapper |
|
453 // CDiagPluginWaitingDialogWrapper::NewL will push dialog into clean up stack |
|
454 iWaitingDialogWrapper = CDiagPluginWaitingDialogWrapper::NewL( dialog ); |
|
455 dialog = NULL; |
|
456 |
|
457 TBool isDialogDismissedByUser = iWaitingDialogWrapper->RunLD( aUserResponse ); |
|
458 if ( isDialogDismissedByUser ) |
|
459 { |
|
460 // local variable can be accessed only if it was returned due to |
|
461 // user response. iWaitingDialogWrapper self destructs. |
|
462 iWaitingDialogWrapper = NULL; |
|
463 } |
|
464 |
|
465 return isDialogDismissedByUser; |
|
466 } |
|
467 |
|
468 // --------------------------------------------------------------------------------------- |
|
469 // CDiagHeadsetCableTestEngine::RunL |
|
470 // RunL() function is used in this plug-in to handle internal trigger |
|
471 // --------------------------------------------------------------------------------------- |
|
472 void CDiagUSBCableTestEngine::RunL() |
|
473 { |
|
474 if(iStatus == KErrNone) |
|
475 { |
|
476 RunUSBCableTestL(); |
|
477 } |
|
478 } |
|
479 |
|
480 // --------------------------------------------------------------------------- |
|
481 // CDiagUSBCableTestEngine::RunError |
|
482 // --------------------------------------------------------------------------- |
|
483 // |
|
484 TInt CDiagUSBCableTestEngine::RunError( TInt aError ) |
|
485 { |
|
486 LOGSTRING2( "CDiagUSBCableTestEngine::RunError( %d )", aError ) |
|
487 return KErrNone; |
|
488 } |
|
489 |
|
490 // --------------------------------------------------------------------------------------- |
|
491 // CDiagHeadsetCableTestEngine::DoCancel |
|
492 // Handles cancel request |
|
493 // --------------------------------------------------------------------------------------- |
|
494 void CDiagUSBCableTestEngine::DoCancel() |
|
495 { |
|
496 // no implementation needed |
|
497 } |
|
498 |
|
499 // End of File |
|
500 |