1 /* |
|
2 * ============================================================================ |
|
3 * Name : SimLockUIAppUi.cpp |
|
4 * Part of : Sim Lock UI Application |
|
5 * Description : Implementation of Sim Lock UI Application UI Methods |
|
6 * Version : |
|
7 * |
|
8 * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
9 * All rights reserved. |
|
10 * This component and the accompanying materials are made available |
|
11 * under the terms of "Eclipse Public License v1.0" |
|
12 * which accompanies this distribution, and is available |
|
13 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
14 * |
|
15 * Initial Contributors: |
|
16 * Nokia Corporation - initial contribution. |
|
17 * |
|
18 * Contributors: |
|
19 * |
|
20 * Description: Build info file for Ado domain appinstall |
|
21 * ============================================================================ |
|
22 */ |
|
23 |
|
24 // Platform Includes |
|
25 #include <avkon.hrh> |
|
26 #include <aknnotewrappers.h> // CAknNoteDialog |
|
27 #include <StringLoader.h> // StringLoader |
|
28 #include <exterror.h> // KErrGsm0707OperationNotAllowed |
|
29 #include <eikspane.h> // CEikStatusPane |
|
30 #include <aknmessagequerydialog.h> // CAknMessageQueryDialog |
|
31 #include <e32base.h> |
|
32 #include <e32property.h> //Rproperty |
|
33 #include <rmmcustomapi.h> // TSimLockPassword |
|
34 |
|
35 // Local Includes |
|
36 #include "simlockisaserverdefinitions.h" |
|
37 #include "simlockui.pan" |
|
38 #include "simlockuiappui.h" |
|
39 #include "simlockuibackgroundcontrol.h" |
|
40 #include "simlockui.hrh" |
|
41 #include "simlockdatahandlingdelegate.h" |
|
42 #include "simlocktelephonyproxy.h" |
|
43 #include "simlockuikeys.h" |
|
44 |
|
45 // Resource Includes |
|
46 #include <simlockui.rsg> |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // CSimLockUIAppUi::CSimLockUIAppUi |
|
50 // --------------------------------------------------------------------------- |
|
51 CSimLockUIAppUi::CSimLockUIAppUi( |
|
52 CSimLockDataHandlingDelegate& aSimLockDelegate) : |
|
53 iSimLockDelegate(aSimLockDelegate), iFirstRun(ETrue) |
|
54 { |
|
55 // no implementation required |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // CSimLockUIAppUi::ConstructL |
|
60 // --------------------------------------------------------------------------- |
|
61 void CSimLockUIAppUi::ConstructL() |
|
62 { |
|
63 BaseConstructL(EAknEnableSkin | EAknEnableMSK); |
|
64 |
|
65 // Used to get status of phone call |
|
66 iTelephonyProxy = CSimLockTelephonyProxy::NewL(); |
|
67 //Define RProperty to Publish Keys for SimLockUi |
|
68 TInt ret = RProperty::Define(KSimLockProperty, ESimLockActiveStatus, |
|
69 RProperty::EInt); |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // CSimLockUIAppUi::~CSimLockUIAppUi |
|
74 // --------------------------------------------------------------------------- |
|
75 CSimLockUIAppUi::~CSimLockUIAppUi() |
|
76 { |
|
77 |
|
78 delete iTelephonyProxy; |
|
79 |
|
80 if (iBackgroundControl) |
|
81 { |
|
82 RemoveFromStack(iBackgroundControl); |
|
83 delete iBackgroundControl; |
|
84 } |
|
85 //Sets SimLock Ui P&S keys to show that SimLock Ui is exiting |
|
86 RProperty::Set(KSimLockProperty, ESimLockActiveStatus, KSimLockStatusDone); |
|
87 |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CSimLockUIAppUi::HandleCommandL |
|
92 // --------------------------------------------------------------------------- |
|
93 void CSimLockUIAppUi::HandleCommandL(TInt aCommand) |
|
94 { |
|
95 switch (aCommand) |
|
96 { |
|
97 case EEikCmdExit: |
|
98 case EAknSoftkeyExit: |
|
99 Exit(); |
|
100 break; |
|
101 |
|
102 default: |
|
103 Panic(ESimLockUIBasicUi); |
|
104 break; |
|
105 } |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // CSimLockUIAppUi::HandleForegroundEventL |
|
110 // --------------------------------------------------------------------------- |
|
111 void CSimLockUIAppUi::HandleForegroundEventL(TBool aForeground) |
|
112 { |
|
113 CAknAppUi::HandleForegroundEventL(aForeground); |
|
114 |
|
115 // When the app switches to the foreground for the first time, display |
|
116 // series of dialogs. |
|
117 if (aForeground && iFirstRun) |
|
118 { |
|
119 iFirstRun = EFalse; |
|
120 ProcessSimUnlockDialogsL(); |
|
121 PrepareToExit(); |
|
122 Exit(); |
|
123 } |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // CSimLockUIAppUi::ProcessSimUnlockDialogsL |
|
128 // --------------------------------------------------------------------------- |
|
129 TBool CSimLockUIAppUi::ProcessSimUnlockDialogsL() |
|
130 { |
|
131 TBool keepLooping = ETrue; |
|
132 |
|
133 RMmCustomAPI::TSimLockPassword password; |
|
134 |
|
135 |
|
136 // Loop until flag is set |
|
137 do |
|
138 { |
|
139 // Create background if not already there |
|
140 if (!iBackgroundControl) |
|
141 { |
|
142 CreateBackgroundControlL(); |
|
143 } |
|
144 // Display Introduction Dialog/Prompt |
|
145 if (!DisplayIntroductionDialogL()) |
|
146 { |
|
147 return EFalse; |
|
148 } |
|
149 // Prompt for password and attempt to unlock Sim |
|
150 if (!PromptForPasswordL(password)) |
|
151 { |
|
152 // skip next iteration |
|
153 continue; |
|
154 } |
|
155 // Set only if no dialogs are ever dismissed |
|
156 keepLooping = AttemptToUnlockSimL(password); |
|
157 |
|
158 // Continue to loop while indicated to start over and dialog |
|
159 // has not been dismissed |
|
160 } |
|
161 while (keepLooping); |
|
162 |
|
163 return keepLooping; |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CSimLockUIAppUi::CreateBackgroundControlL |
|
168 // --------------------------------------------------------------------------- |
|
169 void CSimLockUIAppUi::CreateBackgroundControlL() |
|
170 { |
|
171 iBackgroundControl = CSimLockUIBackgroundControl::NewL(); |
|
172 AddToStackL(iBackgroundControl); |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // CSimLockUIAppUi::DisplayIntroductionDialogL |
|
177 // --------------------------------------------------------------------------- |
|
178 TBool CSimLockUIAppUi::DisplayIntroductionDialogL() |
|
179 { |
|
180 SetBackgroundTextL(EBackgroundTextEmpty); |
|
181 |
|
182 HBufC* displayText = StringLoader::LoadLC(R_SIM_INFO_WELCOME_NOTE_TEXT); |
|
183 CAknMessageQueryDialog* query = new (ELeave) CAknMessageQueryDialog( |
|
184 CAknMessageQueryDialog::ENoTone); |
|
185 CleanupStack::PushL(query); |
|
186 query->SetMessageTextL(*displayText); |
|
187 TInt executeResult = query->ExecuteLD(R_SIM_INFO_WELCOME_NOTE); |
|
188 CleanupStack::Pop(query); |
|
189 CleanupStack::PopAndDestroy(displayText); |
|
190 return executeResult; |
|
191 |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // CSimLockUIAppUi::PromptForPasswordL |
|
196 // --------------------------------------------------------------------------- |
|
197 TBool CSimLockUIAppUi::PromptForPasswordL(TDes& aPassword) |
|
198 { |
|
199 RMmCustomAPI::TSimLockPassword newPassword; |
|
200 |
|
201 // Prompt for password twice. Loop until passwords match. |
|
202 do |
|
203 { |
|
204 aPassword.Zero(); |
|
205 |
|
206 // Ask for password |
|
207 CAknTextQueryDialog* dialog = CAknTextQueryDialog::NewL(aPassword); |
|
208 if (!dialog->ExecuteLD(R_SIM_INFO_ENTER_PASSWORD)) |
|
209 { |
|
210 return EFalse; |
|
211 } |
|
212 |
|
213 // Ask to re-enter password and verify there is no call in progress |
|
214 if (!CompletePromptForPasswordL(aPassword, newPassword)) |
|
215 { |
|
216 return EFalse; |
|
217 } |
|
218 } |
|
219 while (newPassword.Compare(aPassword)); |
|
220 |
|
221 return ETrue; |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // CSimLockUIAppUi::CompletePromptForPasswordL |
|
226 // --------------------------------------------------------------------------- |
|
227 TBool CSimLockUIAppUi::CompletePromptForPasswordL(const TDesC& aPassword, |
|
228 TDes& aNewPassword) |
|
229 { |
|
230 TBool callInProgress = EFalse; |
|
231 |
|
232 aNewPassword.Zero(); |
|
233 |
|
234 do // Loop until no call in progress |
|
235 { |
|
236 // Display dialog to ask to re-enter password |
|
237 CAknTextQueryDialog* dialog = CAknTextQueryDialog::NewL(aNewPassword); |
|
238 if (!dialog->ExecuteLD(R_SIM_INFO_REENTER_PASSWORD)) |
|
239 { |
|
240 return EFalse; |
|
241 } |
|
242 |
|
243 // Check to see if passwords match |
|
244 if (aNewPassword.Compare(aPassword)) |
|
245 { |
|
246 // Create message query dialog to indicate that codes do not match |
|
247 CAknMessageQueryDialog* query = |
|
248 new (ELeave) CAknMessageQueryDialog( |
|
249 CAknMessageQueryDialog::ENoTone); |
|
250 return query->ExecuteLD(R_SIM_INFO_CODES_NOT_MATCH); |
|
251 } |
|
252 |
|
253 // If there is a call in progress, show note and return to "re-enter password" prompt |
|
254 if (!iTelephonyProxy->IsCallInProgress()) |
|
255 { |
|
256 return ETrue; |
|
257 } |
|
258 |
|
259 // Do not allow Sim unlocking, return to password prompt |
|
260 ShowInformationNoteL(R_SIM_UNLOCK_MESSAGE_END_CALL); |
|
261 callInProgress = ETrue; |
|
262 } |
|
263 while (callInProgress); |
|
264 |
|
265 return ETrue; |
|
266 } |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // CSimLockUIAppUi::AttemptToUnlockSimL |
|
270 // --------------------------------------------------------------------------- |
|
271 TBool CSimLockUIAppUi::AttemptToUnlockSimL(const TDesC& aPassword) |
|
272 { |
|
273 |
|
274 const TDesC& password = aPassword; |
|
275 |
|
276 #ifdef __WINS__ |
|
277 // In WINS (Emulator) builds, call to OpenSimLock will just time out |
|
278 TInt unlockResult = KErrGsm0707IncorrectPassword; |
|
279 #else |
|
280 // Attempt to unlock SIM |
|
281 TInt unlockResult = iSimLockDelegate.OpenSimLock( password ); |
|
282 #endif |
|
283 |
|
284 CAknMessageQueryDialog* query = new (ELeave) CAknMessageQueryDialog( |
|
285 CAknMessageQueryDialog::ENoTone); |
|
286 |
|
287 switch (unlockResult) |
|
288 { |
|
289 case KErrAlreadyExists: |
|
290 // Should not happen! This indicates that the phone was already unlocked, |
|
291 // which it shouldn't be if we got this far. |
|
292 ASSERT( 0 ); |
|
293 |
|
294 // Fall Through |
|
295 |
|
296 case KErrNone: |
|
297 SetBackgroundTextL(EBackgroundTextUnlockComplete); |
|
298 ShowInformationNoteL(R_SIM_PHONE_UNLOCKED); |
|
299 return EFalse; |
|
300 |
|
301 default: |
|
302 // Oops, we missed one. |
|
303 ASSERT( 0 ); |
|
304 case KErrGsm0707OperationNotAllowed: |
|
305 case KErrLocked: |
|
306 // Permanently locked |
|
307 SetBackgroundTextL(EBackgroundTextEmpty); |
|
308 query->ExecuteLD(R_SIM_UNLOCK_FINAL); |
|
309 return EFalse; |
|
310 case KErrTimedOut: |
|
311 case KErrGeneral: |
|
312 case KErrArgument: |
|
313 case KErrGsm0707IncorrectPassword: |
|
314 // Not permanently locked |
|
315 return HandleUnlockFailedL(); |
|
316 |
|
317 |
|
318 }//switch |
|
319 } |
|
320 // --------------------------------------------------------------------------- |
|
321 // CSimLockUIAppUi::HandleUnlockFailedL |
|
322 // --------------------------------------------------------------------------- |
|
323 TBool CSimLockUIAppUi::HandleUnlockFailedL() |
|
324 { |
|
325 RMmCustomAPI::TSimLockPassword password; |
|
326 |
|
327 // Otherwise, prompt user to try again |
|
328 SetBackgroundTextL(EBackgroundTextEmpty); |
|
329 |
|
330 // Show "Code Incorrect" and prompt user to continue or not |
|
331 CAknMessageQueryDialog* query = new (ELeave) CAknMessageQueryDialog( |
|
332 CAknMessageQueryDialog::ENoTone); |
|
333 if (query->ExecuteLD(R_SIM_INFO_CODE_INCORRECT)) |
|
334 { |
|
335 if ( PromptForPasswordL(password) ) |
|
336 { |
|
337 return AttemptToUnlockSimL(password); |
|
338 } |
|
339 else |
|
340 { |
|
341 // Set flag indicating to keep looping |
|
342 return ETrue; |
|
343 } |
|
344 } |
|
345 else |
|
346 { |
|
347 // display intro popup |
|
348 return ETrue; |
|
349 } |
|
350 } |
|
351 |
|
352 // --------------------------------------------------------------------------- |
|
353 // CSimLockUIAppUi::ShowInformationNoteL |
|
354 // --------------------------------------------------------------------------- |
|
355 TInt CSimLockUIAppUi::ShowInformationNoteL(TInt aResourceId) const |
|
356 { |
|
357 TInt executeResult; |
|
358 |
|
359 // Show note with the provided resource id |
|
360 HBufC* displayText = StringLoader::LoadLC(aResourceId); |
|
361 |
|
362 CAknInformationNote* dialog = new (ELeave) CAknInformationNote(ETrue); |
|
363 executeResult = dialog->ExecuteLD(*displayText); |
|
364 CleanupStack::PopAndDestroy(displayText); |
|
365 return executeResult; |
|
366 } |
|
367 |
|
368 // --------------------------------------------------------------------------- |
|
369 // CSimLockUIAppUi::SetBackgroundTextL |
|
370 // --------------------------------------------------------------------------- |
|
371 void CSimLockUIAppUi::SetBackgroundTextL(TBackgroundText aText) |
|
372 { |
|
373 HBufC* displayText = NULL; |
|
374 |
|
375 // Load resource and set text in background control based on provided info |
|
376 switch (aText) |
|
377 { |
|
378 case EBackgroundTextEmpty: |
|
379 displayText = KNullDesC().AllocL(); |
|
380 break; |
|
381 |
|
382 case EBackgroundTextMain: |
|
383 displayText = StringLoader::LoadL( |
|
384 R_SIMLOCK_UI_BACKGROUND_TEXT_MAIN); |
|
385 break; |
|
386 |
|
387 case EBackgroundTextUnlockComplete: |
|
388 displayText = StringLoader::LoadL( |
|
389 R_SIMLOCK_UI_BACKGROUND_TEXT_UNLOCK_COMPLETE); |
|
390 break; |
|
391 |
|
392 case EBackgroundTextUnlockFailed: |
|
393 displayText = StringLoader::LoadL( |
|
394 R_SIMLOCK_UI_BACKGROUND_TEXT_UNLOCK_FAILED); |
|
395 break; |
|
396 |
|
397 case EBackgroundTextUnlockIncorrect: |
|
398 displayText = StringLoader::LoadL( |
|
399 R_SIMLOCK_UI_BACKGROUND_TEXT_UNLOCK_INCORRECT); |
|
400 break; |
|
401 |
|
402 default: |
|
403 ASSERT( 0 ); |
|
404 break; |
|
405 } |
|
406 |
|
407 // Transfer ownership to iBackgroundControl |
|
408 iBackgroundControl->SetBackgroundText(displayText); |
|
409 } |
|
410 |
|
411 // End of file. |
|