13 * |
13 * |
14 * Description: CDevEncController definitions Part of ES System Application |
14 * Description: CDevEncController definitions Part of ES System Application |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
|
18 //System Include |
18 #include <apgcli.h> // for RApaLsSession |
19 #include <apgcli.h> // for RApaLsSession |
19 #include <apacmdln.h> // for CApaCommandLine |
20 #include <apacmdln.h> // for CApaCommandLine |
20 #include <centralrepository.h> |
21 #include <centralrepository.h> |
21 #include <featmgr.h> // for checking DE feature |
22 #include <featmgr.h> // for checking DE feature |
|
23 #include <DevEncEngineConstants.h> |
|
24 #include <DevEncSessionBase.h> //for device encryption |
|
25 #include <DevEncProtectedPSKey.h> //for device encryption |
|
26 #include <fotaserver.rsg> |
|
27 |
|
28 //User Include |
22 #include "DevEncController.h" |
29 #include "DevEncController.h" |
23 #include "FotaServer.h" |
30 #include "FotaServer.h" |
|
31 #include "DevEncProgressObserver.h" |
24 #include "FotaSrvDebug.h" |
32 #include "FotaSrvDebug.h" |
25 #include "DevEncSession.h" |
33 |
26 #include <DevEncEngineConstants.h> |
|
27 #include "DevEncProgressObserver.h" |
|
28 #include <fotaserver.rsg> |
|
29 #include <DevEncProtectedPSKey.h> |
|
30 #define __LEAVE_IF_ERROR(x) if(KErrNone!=x) {FLOG(_L("LEAVE in %s: %d"), __FILE__, __LINE__); User::Leave(x); } |
34 #define __LEAVE_IF_ERROR(x) if(KErrNone!=x) {FLOG(_L("LEAVE in %s: %d"), __FILE__, __LINE__); User::Leave(x); } |
31 |
35 |
32 // ================= MEMBER FUNCTIONS ======================= |
36 // ================= MEMBER FUNCTIONS ======================= |
33 // |
37 // |
34 // ---------------------------------------------------------- |
38 // ---------------------------------------------------------- |
72 // |
76 // |
73 void CDevEncController::ConstructL() |
77 void CDevEncController::ConstructL() |
74 { |
78 { |
75 FLOG(_L("CDevEncController::ConstructL >>")); |
79 FLOG(_L("CDevEncController::ConstructL >>")); |
76 |
80 |
77 if (!IsDeviceEncryptionSupportedL()) |
81 if (IsDeviceEncryptionSupportedL()) |
78 { |
82 { |
79 FLOG(_L("Device doesn't support encryption!!")); |
83 LoadDevEncSessionL(); |
|
84 } |
|
85 else |
|
86 { |
|
87 FLOG(_L("Device doesn't support encryption!!")); |
80 User::Leave(KErrNotSupported); |
88 User::Leave(KErrNotSupported); |
81 } |
89 } |
|
90 |
82 FLOG(_L("CDevEncController::ConstructL <<")); |
91 FLOG(_L("CDevEncController::ConstructL <<")); |
83 } |
92 } |
84 |
93 |
85 |
94 |
86 TBool CDevEncController::IsDeviceEncryptionSupportedL() |
95 TBool CDevEncController::IsDeviceEncryptionSupportedL() |
116 // |
125 // |
117 CDevEncController::~CDevEncController() |
126 CDevEncController::~CDevEncController() |
118 { |
127 { |
119 FLOG(_L("CDevEncController::~CDevEncController >>")); |
128 FLOG(_L("CDevEncController::~CDevEncController >>")); |
120 |
129 |
|
130 UnloadDevEncSession(); |
|
131 |
|
132 if (iDevEncObserver) |
|
133 { |
|
134 delete iDevEncObserver; |
|
135 iDevEncObserver = NULL; |
|
136 } |
|
137 |
|
138 FLOG(_L("CDevEncController::~CDevEncController <<")); |
|
139 } |
|
140 |
|
141 // ---------------------------------------------------------- |
|
142 // CDevEncController::LoadDevEncSessionL() |
|
143 // Loads the devenc library |
|
144 // ---------------------------------------------------------- |
|
145 // |
|
146 void CDevEncController::LoadDevEncSessionL() |
|
147 { |
|
148 FLOG(_L("CDevEncController::LoadDevEncSessionL >> ")); |
|
149 |
|
150 if (!iEncMemorySession) |
|
151 { |
|
152 TInt err = iLibrary.Load(KDevEncCommonUtils); |
|
153 if (err != KErrNone) |
|
154 { |
|
155 FLOG(_L("Error in finding the library... %d"), err); |
|
156 } |
|
157 else |
|
158 { |
|
159 TLibraryFunction entry = iLibrary.Lookup(1); |
|
160 |
|
161 if (!entry) |
|
162 { |
|
163 FLOG(_L("Error in loading the library...")); |
|
164 User::Leave(KErrBadLibraryEntryPoint); |
|
165 } |
|
166 iEncMemorySession = (CDevEncSessionBase*) entry(); |
|
167 FLOG(_L("Library is found and loaded successfully...")); |
|
168 } |
|
169 } |
|
170 FLOG(_L("CDevEncController::LoadDevEncSessionL << ")); |
|
171 } |
|
172 |
|
173 // ---------------------------------------------------------- |
|
174 // CDevEncController::UnloadDevEncSessionL() |
|
175 // Unloads the devenc library |
|
176 // ---------------------------------------------------------- |
|
177 // |
|
178 void CDevEncController::UnloadDevEncSession() |
|
179 { |
|
180 FLOG(_L("CDevEncController::UnloadDevEncSession >> ")); |
|
181 |
121 if (iEncMemorySession) |
182 if (iEncMemorySession) |
122 { |
183 { |
123 iEncMemorySession->Close(); |
|
124 delete iEncMemorySession; |
184 delete iEncMemorySession; |
125 iEncMemorySession = NULL; |
185 iEncMemorySession = NULL; |
126 } |
186 } |
127 |
187 |
128 if (iDevEncObserver) |
188 if (iLibrary.Handle()) |
129 { |
189 { |
130 delete iDevEncObserver; |
190 iLibrary.Close(); |
131 iDevEncObserver = NULL; |
191 } |
132 } |
192 FLOG(_L("CDevEncController::UnloadDevEncSession << ")); |
133 |
193 } |
134 FLOG(_L("CDevEncController::~CDevEncController <<")); |
194 |
135 } |
|
136 |
|
137 TBool CDevEncController::NeedToDecryptL(const TDriveNumber &aDrive) |
195 TBool CDevEncController::NeedToDecryptL(const TDriveNumber &aDrive) |
138 { |
196 { |
139 FLOG(_L("CDevEncController::NeedToDecryptL, drive = %d >>"), (TInt) aDrive); |
197 FLOG(_L("CDevEncController::NeedToDecryptL, drive = %d >>"), (TInt) aDrive); |
140 |
198 |
141 TBool ret (EFalse); |
199 TBool ret (EFalse); |
150 { |
208 { |
151 FLOG(_L("Some disk operation is ongoing. Hence Fota is not possible.")); |
209 FLOG(_L("Some disk operation is ongoing. Hence Fota is not possible.")); |
152 User::Leave(KErrNotReady); |
210 User::Leave(KErrNotReady); |
153 } |
211 } |
154 |
212 |
155 if (!iEncMemorySession) |
213 iEncMemorySession->SetDrive( aDrive); |
156 iEncMemorySession = new (ELeave) CDevEncSession( aDrive ); |
|
157 |
214 |
158 err = iEncMemorySession->Connect(); |
215 err = iEncMemorySession->Connect(); |
159 if (err != KErrNone) |
216 if (err != KErrNone) |
160 { |
217 { |
161 FLOG(_L("Error in connecting to devencdisk session = %d"), err); |
218 FLOG(_L("Error in connecting to devencdisk session = %d"), err); |
179 #if defined(__WINS__) |
236 #if defined(__WINS__) |
180 ret = ETrue; |
237 ret = ETrue; |
181 #endif |
238 #endif |
182 |
239 |
183 iEncMemorySession->Close(); |
240 iEncMemorySession->Close(); |
184 delete iEncMemorySession; iEncMemorySession = NULL; |
241 |
185 |
|
186 FLOG(_L("CDevEncController::NeedToDecrypt, ret = %d <<"), ret); |
242 FLOG(_L("CDevEncController::NeedToDecrypt, ret = %d <<"), ret); |
187 return ret; |
243 return ret; |
188 } |
244 } |
189 |
245 |
190 void CDevEncController::DoStartDecryptionL(const TDriveNumber &aDrive) |
246 void CDevEncController::DoStartDecryptionL(const TDriveNumber &aDrive) |
215 { |
271 { |
216 FLOG(_L("CDevEncController::StartDecryptionL >>")); |
272 FLOG(_L("CDevEncController::StartDecryptionL >>")); |
217 |
273 |
218 TInt status (KErrNone); |
274 TInt status (KErrNone); |
219 |
275 |
220 if (!iEncMemorySession) |
276 iEncMemorySession->SetDrive ( iStorageDrive ); |
221 iEncMemorySession = new (ELeave) CDevEncSession( iStorageDrive ); |
277 |
222 |
|
223 __LEAVE_IF_ERROR(iEncMemorySession->Connect()); |
278 __LEAVE_IF_ERROR(iEncMemorySession->Connect()); |
224 |
279 |
225 __LEAVE_IF_ERROR(iEncMemorySession->DiskStatus(status)); |
280 __LEAVE_IF_ERROR(iEncMemorySession->DiskStatus(status)); |
226 |
281 |
227 FLOG(_L("Status = %d"), status); |
282 FLOG(_L("Status = %d"), status); |
245 { |
300 { |
246 FLOG(_L("Battery low for performing decryption!")); |
301 FLOG(_L("Battery low for performing decryption!")); |
247 |
302 |
248 iDevEncOperation = EIdle; |
303 iDevEncOperation = EIdle; |
249 iEncMemorySession->Close(); |
304 iEncMemorySession->Close(); |
250 delete iEncMemorySession; iEncMemorySession = NULL; |
|
251 |
305 |
252 iCallback->HandleDecryptionCompleteL(KErrBadPower, EBatteryLevelLevel4); |
306 iCallback->HandleDecryptionCompleteL(KErrBadPower, EBatteryLevelLevel4); |
253 } |
307 } |
254 } |
308 } |
255 else if(status == EDecrypted) |
309 else if(status == EDecrypted) |
256 { |
310 { |
257 FLOG(_L("Device is already decrypted")); |
311 FLOG(_L("Device is already decrypted")); |
258 |
312 |
259 iDevEncOperation = EIdle; |
313 iDevEncOperation = EIdle; |
260 iEncMemorySession->Close(); |
314 iEncMemorySession->Close(); |
261 delete iEncMemorySession; iEncMemorySession = NULL; |
|
262 |
315 |
263 iCallback->HandleDecryptionCompleteL(KErrNone); |
316 iCallback->HandleDecryptionCompleteL(KErrNone); |
264 } |
317 } |
265 else |
318 else |
266 { |
319 { |
267 // status is either unmounted, encrypting, decrypting, wiping or corrupted |
320 // status is either unmounted, encrypting, decrypting, wiping or corrupted |
268 FLOG(_L("Can't proceed as disk status is %d"), status); |
321 FLOG(_L("Can't proceed as disk status is %d"), status); |
269 |
322 |
270 iDevEncOperation = EIdle; |
323 iDevEncOperation = EIdle; |
271 iEncMemorySession->Close(); |
324 iEncMemorySession->Close(); |
272 delete iEncMemorySession; iEncMemorySession = NULL; |
|
273 |
325 |
274 iCallback->HandleDecryptionCompleteL(KErrNotReady); |
326 iCallback->HandleDecryptionCompleteL(KErrNotReady); |
275 } |
327 } |
276 |
328 |
277 FLOG(_L("CDevEncController::StartDecryptionL <<")); |
329 FLOG(_L("CDevEncController::StartDecryptionL <<")); |
364 { |
415 { |
365 FLOG(_L("CDevEncController::StartEncryptionL >>")); |
416 FLOG(_L("CDevEncController::StartEncryptionL >>")); |
366 |
417 |
367 TInt status (KErrNone); |
418 TInt status (KErrNone); |
368 |
419 |
369 if (!iEncMemorySession) |
420 iEncMemorySession->SetDrive( iStorageDrive ); |
370 iEncMemorySession = new (ELeave) CDevEncSession( iStorageDrive ); |
|
371 |
421 |
372 __LEAVE_IF_ERROR(iEncMemorySession->Connect()); |
422 __LEAVE_IF_ERROR(iEncMemorySession->Connect()); |
373 |
423 |
374 __LEAVE_IF_ERROR(iEncMemorySession->DiskStatus(status)); |
424 __LEAVE_IF_ERROR(iEncMemorySession->DiskStatus(status)); |
375 |
425 |
394 { |
444 { |
395 FLOG(_L("Battery low for performing encryption!")); |
445 FLOG(_L("Battery low for performing encryption!")); |
396 |
446 |
397 iDevEncOperation = EIdle; |
447 iDevEncOperation = EIdle; |
398 iEncMemorySession->Close(); |
448 iEncMemorySession->Close(); |
399 delete iEncMemorySession; iEncMemorySession = NULL; |
|
400 |
449 |
401 iCallback->HandleEncryptionCompleteL(KErrBadPower); |
450 iCallback->HandleEncryptionCompleteL(KErrBadPower); |
402 } |
451 } |
403 } |
452 } |
404 else if (status == EEncrypted) |
453 else if (status == EEncrypted) |
405 { |
454 { |
406 FLOG(_L("Memory is already encrypted")); |
455 FLOG(_L("Memory is already encrypted")); |
407 |
456 |
408 iDevEncOperation = EIdle; |
457 iDevEncOperation = EIdle; |
409 iEncMemorySession->Close(); |
458 iEncMemorySession->Close(); |
410 delete iEncMemorySession; iEncMemorySession = NULL; |
|
411 |
459 |
412 iCallback->HandleEncryptionCompleteL(KErrNone); |
460 iCallback->HandleEncryptionCompleteL(KErrNone); |
413 } |
461 } |
414 else |
462 else |
415 { |
463 { |
416 //status is either encrypting, decrypting, wiping, corrupted |
464 //status is either encrypting, decrypting, wiping, corrupted |
417 FLOG(_L("Can't proceed as disk status is %d"), status); |
465 FLOG(_L("Can't proceed as disk status is %d"), status); |
418 |
466 |
419 iDevEncOperation = EIdle; |
467 iDevEncOperation = EIdle; |
420 iEncMemorySession->Close(); |
468 iEncMemorySession->Close(); |
421 delete iEncMemorySession; iEncMemorySession = NULL; |
|
422 |
469 |
423 iCallback->HandleEncryptionCompleteL(KErrNotReady); |
470 iCallback->HandleEncryptionCompleteL(KErrNotReady); |
424 } |
471 } |
425 FLOG(_L("CDevEncController::StartEncryptionL <<")); |
472 FLOG(_L("CDevEncController::StartEncryptionL <<")); |
426 } |
473 } |