|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * SecurityNotifier implementation. Notifier calls appropriate |
|
16 * dialog to be opened from SecUi. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include "SecurityNotifier.h" |
|
22 #include <e32std.h> |
|
23 #include <secui.h> |
|
24 #include <secuisecurityhandler.h> |
|
25 #include <e32property.h> |
|
26 #include <securityuisprivatepskeys.h> |
|
27 #include <eikenv.h> |
|
28 #include <startupdomainpskeys.h> |
|
29 #include <mmtsy_names.h> |
|
30 #include <securitynotification.h> |
|
31 #include <AknQueryDialog.h> |
|
32 #include <featmgr.h> |
|
33 #include <SCPClient.h> |
|
34 |
|
35 // LOCAL CONSTANTS AND MACROS |
|
36 /***************************************************** |
|
37 * Series 60 Customer / TSY |
|
38 * Needs customer TSY implementation |
|
39 *****************************************************/ |
|
40 |
|
41 const TInt KTriesToConnectServer( 2 ); |
|
42 const TInt KTimeBeforeRetryingServerConnection( 50000 ); |
|
43 const TInt PhoneIndex( 0 ); |
|
44 const TInt KDelayPeriod(200000); |
|
45 |
|
46 |
|
47 // ================= EXPORTED FUNCTIONS ==================== |
|
48 |
|
49 // --------------------------------------------------------- |
|
50 // |
|
51 // Lib main entry point: Creates an notifiers array. |
|
52 // |
|
53 // --------------------------------------------------------- |
|
54 EXPORT_C CArrayPtr<MEikSrvNotifierBase2>* NotifierArray() |
|
55 { |
|
56 CArrayPtrFlat<MEikSrvNotifierBase2>* array = new CArrayPtrFlat<MEikSrvNotifierBase2>(1); |
|
57 |
|
58 if (array) |
|
59 { |
|
60 TRAPD(err, |
|
61 { |
|
62 MEikSrvNotifierBase2* securityNotifier = CSecurityNotifier::NewL(); |
|
63 CleanupStack::PushL(securityNotifier); |
|
64 array->AppendL(securityNotifier); |
|
65 CleanupStack::Pop(securityNotifier); |
|
66 }); |
|
67 |
|
68 if (err) |
|
69 { |
|
70 TInt count = array->Count(); |
|
71 while (count--) |
|
72 (*array)[count]->Release(); |
|
73 delete array; |
|
74 array = NULL; |
|
75 } |
|
76 } |
|
77 |
|
78 return (array); |
|
79 } |
|
80 |
|
81 // ================= LOCAL FUNCTIONS ======================= |
|
82 |
|
83 TBool IsAdminCall() |
|
84 { |
|
85 TBool isAdminCall = EFalse; |
|
86 if(FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw )) |
|
87 { |
|
88 RSCPClient scpClient; |
|
89 if ( scpClient.Connect() == KErrNone ) |
|
90 { |
|
91 if ( scpClient.QueryAdminCmd( ESCPCommandLockPhone ) ) |
|
92 { |
|
93 #if defined(_DEBUG) |
|
94 RDebug::Print(_L("CSecObsNotify::SCP admin command, no action required")); |
|
95 #endif |
|
96 |
|
97 isAdminCall = ETrue; |
|
98 } |
|
99 |
|
100 scpClient.Close(); |
|
101 } |
|
102 } |
|
103 return isAdminCall; |
|
104 } |
|
105 |
|
106 |
|
107 // ================= CSecurityNotifier ======================= |
|
108 // |
|
109 // ---------------------------------------------------------- |
|
110 // CSecurityNotifier::NewL() |
|
111 // Create new CSecurityNotifier object. |
|
112 // ---------------------------------------------------------- |
|
113 // |
|
114 MEikSrvNotifierBase2* CSecurityNotifier::NewL() |
|
115 { |
|
116 MEikSrvNotifierBase2* self = new(ELeave) CSecurityNotifier; |
|
117 return self; |
|
118 } |
|
119 // |
|
120 // ---------------------------------------------------------- |
|
121 // CSecurityNotifier::CSecurityNotifier() |
|
122 // Default constructor: Sets the active object's priority and |
|
123 // puts itself to the active scheduler stack. |
|
124 // ---------------------------------------------------------- |
|
125 // |
|
126 CSecurityNotifier::CSecurityNotifier(): CActive(EPriorityStandard) |
|
127 { |
|
128 CActiveScheduler::Add(this); |
|
129 TRAP_IGNORE( FeatureManager::InitializeLibL() ); |
|
130 } |
|
131 // |
|
132 // ---------------------------------------------------------- |
|
133 // CSecurityNotifier::~CSecurityNotifier() |
|
134 // Destructor |
|
135 // ---------------------------------------------------------- |
|
136 // |
|
137 CSecurityNotifier::~CSecurityNotifier() |
|
138 { |
|
139 FeatureManager::UnInitializeLib(); |
|
140 } |
|
141 // |
|
142 // ---------------------------------------------------------- |
|
143 // CSecurityNotifier::Release() |
|
144 // Called when all resources allocated by notifiers should be freed. |
|
145 // ---------------------------------------------------------- |
|
146 // |
|
147 void CSecurityNotifier::Release() |
|
148 { |
|
149 delete this; |
|
150 } |
|
151 // |
|
152 // ---------------------------------------------------------- |
|
153 // CSecurityNotifier::Release() |
|
154 // This function is called once when DLL is loaded. |
|
155 // Adds CSecurityNotifier resource file to the list maintained by CCoeEnv. |
|
156 // ---------------------------------------------------------- |
|
157 // |
|
158 MEikSrvNotifierBase2::TNotifierInfo CSecurityNotifier::RegisterL() |
|
159 { |
|
160 #if defined(_DEBUG) |
|
161 RDebug::Print(_L("(SECURITYNOTIFIER)CSecurityNotifier::RegisterL()")); |
|
162 #endif |
|
163 iInfo.iUid = KSecurityNotifierUid; |
|
164 iInfo.iChannel = KSecurityNotifierChannel; |
|
165 iInfo.iPriority = ENotifierPriorityHigh; |
|
166 return iInfo; |
|
167 } |
|
168 // |
|
169 // ---------------------------------------------------------- |
|
170 // CSecurityNotifier::Info() |
|
171 // Info |
|
172 // ---------------------------------------------------------- |
|
173 // |
|
174 MEikSrvNotifierBase2::TNotifierInfo CSecurityNotifier::Info() const |
|
175 { |
|
176 #if defined(_DEBUG) |
|
177 RDebug::Print(_L("(SECURITYNOTIFIER)CSecurityNotifier::Info()")); |
|
178 #endif |
|
179 return iInfo; |
|
180 } |
|
181 |
|
182 // |
|
183 // ---------------------------------------------------------- |
|
184 // CSecurityNotifier::StartL() |
|
185 // Will be called by the manager to start the notifier. The contents of |
|
186 // the buffer are passed unchanged from the RNotifier call, and can be used |
|
187 // by the notifier implementation. |
|
188 // ---------------------------------------------------------- |
|
189 // |
|
190 TPtrC8 CSecurityNotifier::StartL(const TDesC8& /*aBuffer*/) |
|
191 { |
|
192 #if defined(_DEBUG) |
|
193 RDebug::Print(_L("(SECURITYNOTIFIER)CSecurityNotifier::StartL()")); |
|
194 #endif |
|
195 TPtrC8 ret(KNullDesC8); |
|
196 return (ret); |
|
197 } |
|
198 // |
|
199 // ---------------------------------------------------------- |
|
200 // CSecurityNotifier::StartL() |
|
201 // Asynchronic notifier launch. |
|
202 // ---------------------------------------------------------- |
|
203 // |
|
204 void CSecurityNotifier::StartL(const TDesC8& aBuffer, TInt aReturnVal,const RMessagePtr2& aMessage) |
|
205 { |
|
206 #if defined(_DEBUG) |
|
207 RDebug::Print(_L("(SECURITYNOTIFIER)CSecurityNotifier::StartL2()")); |
|
208 #endif |
|
209 TRAPD(err, GetParamsL(aBuffer, aReturnVal, aMessage)); |
|
210 if (err) |
|
211 { |
|
212 aMessage.Complete(err); |
|
213 User::Leave(err); |
|
214 } |
|
215 #if defined(_DEBUG) |
|
216 RDebug::Print(_L("(SECURITYNOTIFIER)CSecurityNotifier::StartL2() Start BEGIN")); |
|
217 #endif |
|
218 } |
|
219 // |
|
220 // ---------------------------------------------------------- |
|
221 // CSecurityNotifier::GetParamsL() |
|
222 // Initialize parameters and jump to RunL |
|
223 // ---------------------------------------------------------- |
|
224 // |
|
225 void CSecurityNotifier::GetParamsL(const TDesC8& aBuffer, TInt aReturnVal, const RMessagePtr2& aMessage) |
|
226 { |
|
227 /***************************************************** |
|
228 * Series 60 Customer / ETel |
|
229 * Series 60 ETel API |
|
230 *****************************************************/ |
|
231 iMessage = aMessage; |
|
232 iReturnVal = aReturnVal; |
|
233 TBool skipQuery = EFalse; // In some cases the query is handled by some other entity and SecurityNotifier should skip it. |
|
234 |
|
235 #if defined(_DEBUG) |
|
236 RDebug::Print(_L("(SECURITYNOTIFIER)CSecurityNotifier::GetParamsL() Start BEGIN")); |
|
237 #endif |
|
238 |
|
239 |
|
240 TSecurityNotificationPckg pckg; |
|
241 pckg.Copy( aBuffer ); |
|
242 iStartup = pckg().iStartup; |
|
243 iEvent = static_cast<RMobilePhone::TMobilePhoneSecurityEvent>(pckg().iEvent); |
|
244 |
|
245 |
|
246 if(FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw )) |
|
247 { |
|
248 if(iEvent == RMobilePhone::EPhonePasswordRequired) |
|
249 { |
|
250 skipQuery = IsAdminCall(); // SCP handles the call. |
|
251 } |
|
252 } |
|
253 |
|
254 if ( skipQuery ) |
|
255 { |
|
256 iMessage.Write( iReturnVal, TPckgBuf<TInt>( KErrNone ) ); |
|
257 iMessage.Complete( KErrNone ); |
|
258 } |
|
259 else |
|
260 { |
|
261 // Call SetActive() so RunL() will be called by the active scheduler |
|
262 SetActive(); |
|
263 iStatus = KRequestPending; |
|
264 TRequestStatus* stat = &iStatus; |
|
265 #if defined(_DEBUG) |
|
266 RDebug::Print(_L("CSecurityNotifier::GetParamsL() End")); |
|
267 #endif |
|
268 User::RequestComplete(stat, KErrNone); // jump to RunL |
|
269 } |
|
270 } |
|
271 // |
|
272 // ---------------------------------------------------------- |
|
273 // CSecurityNotifier::RunL() |
|
274 // Show query |
|
275 // ---------------------------------------------------------- |
|
276 void CSecurityNotifier::RunL() |
|
277 { |
|
278 /***************************************************** |
|
279 * Series 60 Customer / ETel |
|
280 * Series 60 ETel API |
|
281 *****************************************************/ |
|
282 /***************************************************** |
|
283 * Series 60 Customer / TSY |
|
284 * Needs customer TSY implementation |
|
285 *****************************************************/ |
|
286 |
|
287 TInt err( KErrGeneral ); |
|
288 TInt thisTry( 0 ); |
|
289 RTelServer::TPhoneInfo PhoneInfo; |
|
290 #if defined(_DEBUG) |
|
291 RDebug::Print(_L("CSecurityNotifier::RunL() Start")); |
|
292 #endif |
|
293 /*All server connections are tried to be made KTriesToConnectServer times because occasional |
|
294 fails on connections are possible, at least on some servers*/ |
|
295 |
|
296 // connect to ETel server |
|
297 #if defined(_DEBUG) |
|
298 RDebug::Print(_L("CSecurityNotifier::RunL() connect to ETel server")); |
|
299 #endif |
|
300 while ( ( err = iServer.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer ) |
|
301 { |
|
302 User::After( KTimeBeforeRetryingServerConnection ); |
|
303 } |
|
304 User::LeaveIfError( err ); |
|
305 |
|
306 thisTry = 0; |
|
307 |
|
308 // load TSY |
|
309 #if defined(_DEBUG) |
|
310 RDebug::Print(_L("CSecurityNotifier::RunL() load TSY")); |
|
311 #endif |
|
312 err = iServer.LoadPhoneModule( KMmTsyModuleName ); |
|
313 if ( err != KErrAlreadyExists ) |
|
314 { |
|
315 // may also return KErrAlreadyExists if something |
|
316 // else has already loaded the TSY module. And that is |
|
317 // not an error. |
|
318 User::LeaveIfError( err ); |
|
319 } |
|
320 |
|
321 // open phones |
|
322 #if defined(_DEBUG) |
|
323 RDebug::Print(_L("CSecurityNotifier::RunL() open phones")); |
|
324 #endif |
|
325 User::LeaveIfError(iServer.SetExtendedErrorGranularity(RTelServer::EErrorExtended)); |
|
326 User::LeaveIfError(iServer.GetPhoneInfo(PhoneIndex, PhoneInfo)); |
|
327 User::LeaveIfError(iPhone.Open(iServer,PhoneInfo.iName)); |
|
328 RProperty Property; |
|
329 CleanupClosePushL( Property ); |
|
330 err = Property.Set(KPSUidStartup, KStartupSecurityCodeQueryStatus, ESecurityQueryActive); |
|
331 User::LeaveIfError( err ); |
|
332 |
|
333 // initialize security ui |
|
334 #if defined(_DEBUG) |
|
335 RDebug::Print(_L("CSecurityNotifier::RunL() initialize security ui")); |
|
336 #endif |
|
337 CSecurityHandler* handler = new(ELeave) CSecurityHandler(iPhone); |
|
338 CleanupStack::PushL(handler); |
|
339 TSecUi::InitializeLibL(); |
|
340 |
|
341 TBool StartUp = iStartup; |
|
342 |
|
343 TInt secUiOriginatedQuery(ESecurityUIsSecUIOriginated); |
|
344 err = KErrNone; |
|
345 if(!StartUp) |
|
346 { |
|
347 err = Property.Get(KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, secUiOriginatedQuery); |
|
348 } |
|
349 |
|
350 // handle event |
|
351 TInt result = KErrNone; |
|
352 //Bring the window group to foreground |
|
353 ( CEikonEnv::Static() )->BringForwards(ETrue); |
|
354 |
|
355 TRAPD( error, handler->HandleEventL( iEvent, iStartup, result ) ); |
|
356 |
|
357 |
|
358 // if something went wrong cancel the code request |
|
359 if (error) |
|
360 { |
|
361 #if defined(_DEBUG) |
|
362 RDebug::Print(_L("CSecurityNotifier::RunL() ERROR: %d"), error); |
|
363 #endif |
|
364 TBool wcdmaSupported(FeatureManager::FeatureSupported( KFeatureIdProtocolWcdma )); |
|
365 TBool upinSupported(FeatureManager::FeatureSupported( KFeatureIdUpin )); |
|
366 switch (iEvent) |
|
367 { |
|
368 case RMobilePhone::EUniversalPinRequired: |
|
369 if(wcdmaSupported || upinSupported) |
|
370 { |
|
371 iPhone.AbortSecurityCode(RMobilePhone::ESecurityUniversalPin); |
|
372 } |
|
373 break; |
|
374 case RMobilePhone::EUniversalPukRequired: |
|
375 if(wcdmaSupported || upinSupported) |
|
376 { |
|
377 iPhone.AbortSecurityCode(RMobilePhone::ESecurityUniversalPuk); |
|
378 } |
|
379 break; |
|
380 case RMobilePhone::EPin1Required: |
|
381 iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePin1); |
|
382 break; |
|
383 case RMobilePhone::EPuk1Required: |
|
384 iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePuk1); |
|
385 break; |
|
386 case RMobilePhone::EPin2Required: |
|
387 iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePin2); |
|
388 break; |
|
389 case RMobilePhone::EPuk2Required: |
|
390 iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePuk2); |
|
391 break; |
|
392 case RMobilePhone::EPhonePasswordRequired: |
|
393 iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePhonePassword); |
|
394 break; |
|
395 default: |
|
396 break; |
|
397 } |
|
398 } |
|
399 |
|
400 // uninitialize security ui |
|
401 CleanupStack::PopAndDestroy(handler); // handler |
|
402 TSecUi::UnInitializeLib(); |
|
403 Property.Set(KPSUidStartup, KStartupSecurityCodeQueryStatus, ESecurityQueryNotActive); |
|
404 CleanupStack::PopAndDestroy( &Property ); |
|
405 |
|
406 //close ETel connection |
|
407 if (iServer.Handle()) |
|
408 { |
|
409 iPhone.Close(); |
|
410 iServer.UnloadPhoneModule(KMmTsyModuleName); |
|
411 iServer.Close(); |
|
412 } |
|
413 |
|
414 User::LeaveIfError(error); |
|
415 |
|
416 // Complete message and free resources |
|
417 iMessage.Write( iReturnVal, TPckgBuf<TInt>( result ) ); |
|
418 iMessage.Complete(KErrNone); |
|
419 iReturnVal = KErrNone; |
|
420 //Leave the window group to foreground for a short time to absorb key presses so that autolock has time to activate. |
|
421 if(!StartUp) |
|
422 User::After(KDelayPeriod); |
|
423 ( CEikonEnv::Static() )->BringForwards(EFalse); |
|
424 #if defined(_DEBUG) |
|
425 RDebug::Print(_L("CSecurityNotifier::RunL() End")); |
|
426 #endif |
|
427 } |
|
428 |
|
429 // ---------------------------------------------------------- |
|
430 // This method will be called by framework (CActive) |
|
431 // if active object is still active. |
|
432 // Does nothing here. |
|
433 // ---------------------------------------------------------- |
|
434 // |
|
435 void CSecurityNotifier::DoCancel() |
|
436 { |
|
437 } |
|
438 // |
|
439 // ---------------------------------------------------------- |
|
440 // CSecurityNotifier::Cancel() |
|
441 // Will be called by the manager to stop the notifier. Nothing happens when |
|
442 // a call to cancel is made on a notifier that hasn't started. |
|
443 // ---------------------------------------------------------- |
|
444 // |
|
445 void CSecurityNotifier::Cancel() |
|
446 { |
|
447 } |
|
448 // |
|
449 // ---------------------------------------------------------- |
|
450 // CSecurityNotifier::UpdateL() |
|
451 // Will be called by the manager to update an already started notifier. |
|
452 // The contents of the buffer are passed unchanged from the RNotifier call, |
|
453 // and can be used by the notifier implementation |
|
454 // Nothing happens when a call to update is made on a notifier that hasn't started. |
|
455 // ---------------------------------------------------------- |
|
456 // |
|
457 TPtrC8 CSecurityNotifier::UpdateL(const TDesC8& /*aBuffer*/) |
|
458 { |
|
459 return TPtrC8(); |
|
460 } |
|
461 // |
|
462 // ---------------------------------------------------------- |
|
463 // CE32Dll() |
|
464 // DLL entry point |
|
465 // ---------------------------------------------------------- |
|
466 // |
|
467 |
|
468 #ifndef EKA2 |
|
469 |
|
470 GLDEF_C TInt E32Dll( TDllReason /*aReason*/) |
|
471 { |
|
472 return KErrNone; |
|
473 } |
|
474 |
|
475 #endif |
|
476 |
|
477 // end of file |