|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : strtdevlockcheck.cpp |
|
15 // Part of : System Startup / StrtDevLockPlg |
|
16 // Implementation of CStrtDevLockCheck class. |
|
17 // Version : %version: 1 % |
|
18 // This material, including documentation and any related computer |
|
19 // programs, is protected by copyright controlled by Nokia. All |
|
20 // rights are reserved. Copying, including reproducing, storing, |
|
21 // adapting or translating, any or all of this material requires the |
|
22 // prior written consent of Nokia. This material also contains |
|
23 // confidential information which may not be disclosed to others |
|
24 // without the prior written consent of Nokia. |
|
25 // Template version: 4.1.1 |
|
26 // Nokia Core OS * |
|
27 // File renamed from strtdevlockcheck.cpp to cmddevicesecuritycheck.cpp as part of Core OS transfer. |
|
28 // |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 /** |
|
34 @file |
|
35 @internalComponent |
|
36 @released |
|
37 */ |
|
38 |
|
39 #include "ssmsecuritychecknotifier.h" |
|
40 #include "cmddevicesecuritycheck.h" |
|
41 #include "ssmuiproviderdll.h" |
|
42 #include "ssmrefcustomcmdcommon.h" |
|
43 #include "ssmdebug.h" |
|
44 |
|
45 CCustomCmdDeviceSecurityCheck* CCustomCmdDeviceSecurityCheck::NewL() |
|
46 { |
|
47 CCustomCmdDeviceSecurityCheck* self = new (ELeave) CCustomCmdDeviceSecurityCheck(); |
|
48 CleanupStack::PushL(self); |
|
49 self->ConstructL(); |
|
50 CleanupStack::Pop(self); |
|
51 return self; |
|
52 } |
|
53 |
|
54 void CCustomCmdDeviceSecurityCheck::ConstructL() |
|
55 { |
|
56 TInt errorCode = iServer.Connect(); |
|
57 |
|
58 if(KErrNone != errorCode) |
|
59 { |
|
60 DEBUGPRINT2A("Failed to connect to TelServer with error %d", errorCode); |
|
61 User::Leave(errorCode); |
|
62 } |
|
63 |
|
64 iTsyModuleName = CSsmUiSpecific::GetTsyModuleNameL(); |
|
65 errorCode = iServer.LoadPhoneModule(*iTsyModuleName); |
|
66 |
|
67 if (KErrNone != errorCode && KErrAlreadyExists != errorCode) |
|
68 { |
|
69 // KErrAlreadyExists may be returned if some other has already loaded |
|
70 // the TSY module. |
|
71 DEBUGPRINT2A("Failed to load phone module with error %d", errorCode); |
|
72 User::Leave(errorCode); |
|
73 } |
|
74 |
|
75 HBufC* tsyPhoneName = CSsmUiSpecific::PhoneTsyNameL(); |
|
76 errorCode = iPhone.Open(iServer, *tsyPhoneName); |
|
77 delete tsyPhoneName; |
|
78 |
|
79 if(KErrNone != errorCode) |
|
80 { |
|
81 DEBUGPRINT2A("Failed to open phone subsession with error %d", errorCode); |
|
82 User::Leave(errorCode); |
|
83 } |
|
84 |
|
85 //Add active object to active scheduler |
|
86 CActiveScheduler::Add(this); |
|
87 } |
|
88 |
|
89 CCustomCmdDeviceSecurityCheck::CCustomCmdDeviceSecurityCheck() |
|
90 : CActive(EPriorityStandard), |
|
91 iState(EGetLockPhoneDevice), |
|
92 iLockInfoPckg(iLockInfo) |
|
93 { |
|
94 } |
|
95 |
|
96 CCustomCmdDeviceSecurityCheck::~CCustomCmdDeviceSecurityCheck() |
|
97 { |
|
98 ExecuteCancel(); |
|
99 delete iSsmSecurityCheckNotifier; |
|
100 |
|
101 iPhone.Close(); |
|
102 if (iServer.Handle()) |
|
103 { |
|
104 iServer.UnloadPhoneModule(*iTsyModuleName); |
|
105 iServer.Close(); |
|
106 } |
|
107 delete iTsyModuleName; |
|
108 } |
|
109 |
|
110 TInt CCustomCmdDeviceSecurityCheck::Initialize(CSsmCustomCommandEnv* /*aCmdEnv*/) |
|
111 { |
|
112 return KErrNone; |
|
113 } |
|
114 |
|
115 void CCustomCmdDeviceSecurityCheck::Close() |
|
116 { |
|
117 } |
|
118 |
|
119 void CCustomCmdDeviceSecurityCheck::Release() |
|
120 { |
|
121 delete this; |
|
122 } |
|
123 |
|
124 void CCustomCmdDeviceSecurityCheck::Execute(const TDesC8& /*aParams*/, TRequestStatus& aStatus) |
|
125 { |
|
126 //Set the user request to pending |
|
127 aStatus = KRequestPending; |
|
128 iExecuteRequest = &aStatus; |
|
129 |
|
130 #ifdef __WINS__ |
|
131 #ifdef TEST_CUSTCMD_MACRO |
|
132 TRequestStatus* status = &iStatus; |
|
133 User::RequestComplete(status, KErrNone); |
|
134 SetActive(); |
|
135 #else |
|
136 // The device lock status can not be read in the emulator. |
|
137 // Just pretend the lock is not enabled. |
|
138 TInt errorCode = RProperty::Set(CSsmUiSpecific::StarterPSUid(), KStarterSecurityPhase, EStarterSecurityPhaseSimOk); |
|
139 CompleteClientRequest(errorCode); |
|
140 #endif //TEST_CUSTCMD_MACRO |
|
141 |
|
142 #else |
|
143 if (CSsmUiSpecific::IsNormalBoot() || CSsmUiSpecific::IsSimChangedReset()) |
|
144 { |
|
145 iPhone.GetLockInfo( iStatus, RMobilePhone::ELockPhoneDevice, iLockInfoPckg ); |
|
146 SetActive(); |
|
147 } |
|
148 else |
|
149 { |
|
150 TInt errorCode = RProperty::Set( |
|
151 CSsmUiSpecific::StarterPSUid(), KStarterSecurityPhase, EStarterSecurityPhaseSecOk ); |
|
152 CompleteClientRequest( errorCode ); |
|
153 } |
|
154 #endif //__WINS__ |
|
155 } |
|
156 |
|
157 void CCustomCmdDeviceSecurityCheck::ExecuteCancel() |
|
158 { |
|
159 //Call cancel method of CActive |
|
160 Cancel(); |
|
161 } |
|
162 |
|
163 void CCustomCmdDeviceSecurityCheck::RunL() |
|
164 { |
|
165 switch (iState) |
|
166 { |
|
167 case EGetLockPhoneDevice: |
|
168 LockPhoneDeviceRespReceivedL(); |
|
169 break; |
|
170 case EGetLockPhoneToIcc: |
|
171 LockPhoneToIccRespReceivedL(); |
|
172 break; |
|
173 case EQuerySecCode: |
|
174 SecCodeQueryRespReceivedL(); |
|
175 break; |
|
176 default: |
|
177 __ASSERT_ALWAYS((iState <= EDeviceSecurityCheckNone) || (iState >= EDeviceSecurityCheckMaxState), |
|
178 PanicNow(KPanicCustomCmdDeviceSecurityCheck, EInvalidDeviceSecurityState)); |
|
179 break; |
|
180 } |
|
181 } |
|
182 |
|
183 void CCustomCmdDeviceSecurityCheck::LockPhoneDeviceRespReceivedL() |
|
184 { |
|
185 if (iStatus.Int() == KErrNone) |
|
186 { |
|
187 DEBUGPRINT3A("ELockPhoneDevice: status: %d, setting: %d", |
|
188 iLockInfo.iStatus, iLockInfo.iSetting); |
|
189 |
|
190 DEBUGPRINT3A("ELockPhoneDevice: RMobilePhone::EStatusLocked: %d, RMobilePhone::ELockSetEnabled: %d", |
|
191 RMobilePhone::EStatusLocked, RMobilePhone::ELockSetEnabled); |
|
192 |
|
193 //Ask for security code if status is locked and lock is enabled |
|
194 if (iLockInfo.iStatus == RMobilePhone::EStatusLocked && |
|
195 iLockInfo.iSetting == RMobilePhone::ELockSetEnabled) |
|
196 { |
|
197 QuerySecCodeL(); |
|
198 } |
|
199 else |
|
200 { |
|
201 DEBUGPRINT2A("ELockPhoneDevice: Check ELockPhoneToICC while SimPresent = %d", CSsmUiSpecific::IsSimPresent()); |
|
202 iState = EGetLockPhoneToIcc; |
|
203 iPhone.GetLockInfo( |
|
204 iStatus, RMobilePhone::ELockPhoneToICC, iLockInfoPckg ); |
|
205 SetActive(); |
|
206 } |
|
207 } |
|
208 else |
|
209 { |
|
210 CompleteClientRequest(iStatus.Int()); |
|
211 } |
|
212 } |
|
213 |
|
214 void CCustomCmdDeviceSecurityCheck::LockPhoneToIccRespReceivedL() |
|
215 { |
|
216 if (iStatus.Int() == KErrNone) |
|
217 { |
|
218 DEBUGPRINT4A("1ELockPhoneDevice: status: %d, setting: %d, IsSimPresent: %d", |
|
219 iLockInfo.iStatus, iLockInfo.iSetting, CSsmUiSpecific::IsSimPresent()); |
|
220 |
|
221 DEBUGPRINT3A("1ELockPhoneDevice: RMobilePhone::EStatusLocked: %d, RMobilePhone::ELockSetEnabled: %d", |
|
222 RMobilePhone::EStatusLocked, RMobilePhone::ELockSetEnabled); |
|
223 |
|
224 if (iLockInfo.iSetting == RMobilePhone::ELockSetEnabled && |
|
225 (EFalse == CSsmUiSpecific::IsSimPresent() || ( iLockInfo.iStatus == RMobilePhone::EStatusLocked))) |
|
226 { |
|
227 QuerySecCodeL(); |
|
228 } |
|
229 else |
|
230 { |
|
231 CompleteClientRequest(iStatus.Int()); |
|
232 } |
|
233 } |
|
234 else |
|
235 { |
|
236 CompleteClientRequest(iStatus.Int()); |
|
237 } |
|
238 } |
|
239 |
|
240 void CCustomCmdDeviceSecurityCheck::SecCodeQueryRespReceivedL() |
|
241 { |
|
242 __ASSERT_DEBUG(NULL != iSsmSecurityCheckNotifier, PanicNow(KPanicCustomCmdDeviceSecurityCheck, ECmdNullPtr)); |
|
243 if (iStatus.Int() == KErrNone && iSsmSecurityCheckNotifier->SecurityCheckResult() == KErrNone) |
|
244 { |
|
245 CompleteClientRequest(KErrNone); |
|
246 } |
|
247 else if (iStatus.Int() != KErrNone) |
|
248 { |
|
249 // Fatal error |
|
250 CompleteClientRequest(iStatus.Int()); |
|
251 } |
|
252 else |
|
253 { |
|
254 // Wrong code, try again |
|
255 QuerySecCodeL(); |
|
256 } |
|
257 } |
|
258 |
|
259 void CCustomCmdDeviceSecurityCheck::QuerySecCodeL() |
|
260 { |
|
261 iState = EQuerySecCode; |
|
262 TInt errorCode = KErrNone; |
|
263 |
|
264 if (!iSsmSecurityCheckNotifier) |
|
265 { |
|
266 TRAP(errorCode, iSsmSecurityCheckNotifier = CSsmSecurityCheckNotifier::NewL(ESecCodePasswd)); |
|
267 } |
|
268 |
|
269 if (KErrNone == errorCode) |
|
270 { |
|
271 iSsmSecurityCheckNotifier->ShowNoteL(iStatus); |
|
272 SetActive(); |
|
273 } |
|
274 else |
|
275 { |
|
276 DEBUGPRINT2A("Failed to create CSsmSecurityCheckNotifier with error %d", errorCode); |
|
277 CompleteClientRequest(errorCode); |
|
278 } |
|
279 } |
|
280 |
|
281 void CCustomCmdDeviceSecurityCheck::DoCancel() |
|
282 { |
|
283 if (iSsmSecurityCheckNotifier) |
|
284 { |
|
285 iSsmSecurityCheckNotifier->Cancel(); |
|
286 } |
|
287 iPhone.CancelAsyncRequest(EMobilePhoneGetLockInfo); |
|
288 CompleteClientRequest(KErrCancel); |
|
289 } |
|
290 |
|
291 TInt CCustomCmdDeviceSecurityCheck::RunError(TInt aError) |
|
292 { |
|
293 //Call cancel method of CActive |
|
294 Cancel(); |
|
295 CompleteClientRequest(aError); |
|
296 return KErrNone; |
|
297 } |
|
298 |
|
299 void CCustomCmdDeviceSecurityCheck::CompleteClientRequest(TInt aReason) |
|
300 { |
|
301 //Complete client request with reason code |
|
302 if (iExecuteRequest) |
|
303 { |
|
304 TInt errorCode = RProperty::Set(CSsmUiSpecific::StarterPSUid(), KStarterSecurityPhase, |
|
305 aReason == KErrNone ? EStarterSecurityPhaseSecOk : EStarterSecurityPhaseSecNok ); |
|
306 User::RequestComplete(iExecuteRequest, aReason); |
|
307 } |
|
308 } |