|
1 /* |
|
2 * Copyright (c) 2005 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: Implementation of CDevEncUiMainView. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDES |
|
19 |
|
20 // Class include |
|
21 #include "DevEncUiMainView.h" |
|
22 |
|
23 // System includes |
|
24 #include <aknnotewrappers.h> |
|
25 #include <aknViewAppUi.h> // CAknViewAppUi |
|
26 #include <DevEncUi.rsg> |
|
27 #include <e32cmn.h> |
|
28 #include <StringLoader.h> |
|
29 #include <DevEncExternalCRKeys.h> |
|
30 |
|
31 // User includes |
|
32 #include "DevEncLog.h" |
|
33 #include "DevEnc.hrh" |
|
34 #include "DevEncUiEncryptionOperator.h" |
|
35 |
|
36 #include "DevEncUiMainViewContainer.h" |
|
37 #include "DevEncUiMemoryEntity.h" |
|
38 |
|
39 // ================= MEMBER FUNCTIONS ======================= |
|
40 |
|
41 /** |
|
42 * Destructor. Frees up memory for the iLabel. |
|
43 */ |
|
44 CDevEncUiMainView::~CDevEncUiMainView() |
|
45 { |
|
46 for ( TInt i = 0; i < iMemEntities.Count(); i++ ) |
|
47 { |
|
48 iMemEntities[i]->RemoveObserver( iContainer ); |
|
49 } |
|
50 delete iContainer; |
|
51 delete iEncOperator; |
|
52 } |
|
53 |
|
54 /** |
|
55 * Symbian OS 2 phase constructor. |
|
56 * Constructs the CDevEncUiMainView using the NewLC method, popping |
|
57 * the constructed object from the CleanupStack before returning it. |
|
58 * |
|
59 * @param aRect The rectangle for this window |
|
60 * @return The newly constructed CDevEncUiMainView |
|
61 */ |
|
62 CDevEncUiMainView* CDevEncUiMainView::NewL( |
|
63 RArray<CDevEncUiMemoryEntity*>& aMemEntities, |
|
64 CRepository*& aCrSettings, |
|
65 TInt& aMmcStatus ) |
|
66 { |
|
67 CDevEncUiMainView* self = CDevEncUiMainView::NewLC( aMemEntities, |
|
68 aCrSettings, |
|
69 aMmcStatus ); |
|
70 CleanupStack::Pop( self ); |
|
71 return self; |
|
72 } |
|
73 |
|
74 /** |
|
75 * Symbian OS 2 phase constructor. |
|
76 * Constructs the CDevEncUiMainView using the constructor and ConstructL |
|
77 * method, leaving the constructed object on the CleanupStack before returning it. |
|
78 * |
|
79 * @param aRect The rectangle for this window |
|
80 * @return The newly constructed CDevEncUiMainView |
|
81 */ |
|
82 CDevEncUiMainView* CDevEncUiMainView::NewLC( |
|
83 RArray<CDevEncUiMemoryEntity*>& aMemEntities, |
|
84 CRepository*& aCrSettings, |
|
85 TInt& aMmcStatus ) |
|
86 { |
|
87 CDevEncUiMainView* self = |
|
88 new ( ELeave ) CDevEncUiMainView( aMemEntities, |
|
89 aCrSettings, |
|
90 aMmcStatus ); |
|
91 CleanupStack::PushL( self ); |
|
92 self->ConstructL(); |
|
93 return self; |
|
94 } |
|
95 |
|
96 CDevEncUiMainView::CDevEncUiMainView( RArray<CDevEncUiMemoryEntity*>& aMemEntities, |
|
97 CRepository*& aCrSettings, |
|
98 TInt& aMmcStatus ) |
|
99 : iMemEntities( aMemEntities ), |
|
100 iCrSettings( aCrSettings ), |
|
101 iMmcStatus( aMmcStatus ) |
|
102 { |
|
103 } |
|
104 |
|
105 /** |
|
106 * Symbian OS 2nd phase constructor. |
|
107 * Uses the superclass constructor to construct the view |
|
108 */ |
|
109 void CDevEncUiMainView::ConstructL() |
|
110 { |
|
111 BaseConstructL( R_DEVENCUI_MAINVIEW ); |
|
112 |
|
113 iContainer = CDevEncUiMainViewContainer::NewL( AppUi()->ClientRect(), |
|
114 iMemEntities, |
|
115 *this, |
|
116 iCrSettings, |
|
117 iMmcStatus ); |
|
118 iContainer->SetMopParent( this ); |
|
119 |
|
120 for ( TInt i = 0; i < iMemEntities.Count(); i++ ) |
|
121 { |
|
122 iMemEntities[i]->AddObserverL( iContainer ); |
|
123 } |
|
124 } |
|
125 |
|
126 /** |
|
127 * Called by the framework |
|
128 * @return The Uid for this view |
|
129 */ |
|
130 TUid CDevEncUiMainView::Id() const |
|
131 { |
|
132 return TUid::Uid( EDevEncUiMainViewId ); |
|
133 } |
|
134 |
|
135 /** |
|
136 * Called by the framework when the view is activated. |
|
137 * Adds the container to the control stack. |
|
138 */ |
|
139 void CDevEncUiMainView::DoActivateL( const TVwsViewId& /*aPrevViewId*/, |
|
140 TUid /*aCustomMessageId*/, |
|
141 const TDesC8& /*aCustomMessage*/) |
|
142 { |
|
143 AppUi()->AddToStackL( *this, iContainer ); |
|
144 |
|
145 if ( iEikonEnv->StartedAsServerApp() ) |
|
146 { |
|
147 CEikButtonGroupContainer* cba = Cba(); |
|
148 cba->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK ); |
|
149 } |
|
150 } |
|
151 |
|
152 /** |
|
153 * Called by the framework when the view is deactivated. |
|
154 * Removes the container from the control stack. |
|
155 */ |
|
156 void CDevEncUiMainView::DoDeactivate() |
|
157 { |
|
158 if ( iContainer ) |
|
159 { |
|
160 AppUi()->RemoveFromStack( iContainer ); |
|
161 } |
|
162 } |
|
163 |
|
164 /** |
|
165 * From CEikAppUi, takes care of command handling for this view. |
|
166 * |
|
167 * @param aCommand command to be handled |
|
168 */ |
|
169 void CDevEncUiMainView::HandleCommandL( TInt aCommand ) |
|
170 { |
|
171 |
|
172 switch ( aCommand ) |
|
173 { |
|
174 case EDevEncUiCommandChange: |
|
175 { |
|
176 // Show the toggle popup |
|
177 if ( iContainer->ChangeSelectedItemL() ) |
|
178 { |
|
179 // The user made a new selection |
|
180 TDevEncUiMemoryType memoryType = |
|
181 static_cast<TDevEncUiMemoryType>( iContainer->SelectedItem() ); |
|
182 EncryptionStatusChangeReq( memoryType ); |
|
183 } |
|
184 break; |
|
185 } |
|
186 default: |
|
187 { |
|
188 AppUi()->HandleCommandL( aCommand ); |
|
189 break; |
|
190 } |
|
191 } |
|
192 } |
|
193 |
|
194 void CDevEncUiMainView::DynInitMenuPaneL( TInt aResourceId, |
|
195 CEikMenuPane* aMenuPane ) |
|
196 { |
|
197 if ( ! iContainer || |
|
198 iMemEntities.Count() == 0 ) |
|
199 { |
|
200 return; |
|
201 } |
|
202 |
|
203 // Disable the "Change" menu item if an encryption operation is ongoing |
|
204 if ( aResourceId == R_DEVENCUI_MENU_MAIN ) |
|
205 { |
|
206 TBool proceed( ETrue ); |
|
207 TInt dmControl( 0 ); |
|
208 TInt err = iCrSettings->Get( KDevEncUiDmControl, dmControl ); |
|
209 if ( err ) |
|
210 { |
|
211 DFLOG2( "Cenrep error %d", err ); |
|
212 User::Leave( err ); |
|
213 } |
|
214 |
|
215 // Check if phone memory encryption is controlled by dev management |
|
216 if ( ( dmControl & KDmControlsPhoneMemory ) && |
|
217 ( iContainer->SelectedItem() == EPhoneMemory ) ) |
|
218 { |
|
219 // Selected memory is controlled by DM -> disable "Change" |
|
220 aMenuPane->SetItemDimmed( EDevEncUiCommandChange, ETrue ); |
|
221 proceed = EFalse; |
|
222 } |
|
223 |
|
224 // Check if memory card encryption is controlled by dev management |
|
225 if ( ( dmControl & KDmControlsMemoryCard ) && |
|
226 ( iContainer->SelectedItem() == EMemoryCard ) ) |
|
227 { |
|
228 // Selected memory is controlled by DM -> disable "Change" |
|
229 aMenuPane->SetItemDimmed( EDevEncUiCommandChange, ETrue ); |
|
230 proceed = EFalse; |
|
231 } |
|
232 |
|
233 if ( !proceed ) |
|
234 { |
|
235 DFLOG( "Hiding Change, item is controlled by DM" ); |
|
236 return; |
|
237 } |
|
238 |
|
239 // Show the "Change" item if encryption status can be changed |
|
240 TBool allowChange( EFalse ); |
|
241 if ( ( iMemEntities[ EMemoryCard ]->State() == EUnmounted || |
|
242 iMemEntities[ EMemoryCard ]->State() == EDecrypted || |
|
243 iMemEntities[ EMemoryCard ]->State() == EEncrypted ) && |
|
244 ( iMemEntities[ EPhoneMemory ]->State() == EDecrypted || |
|
245 iMemEntities[ EPhoneMemory ]->State() == EEncrypted ) ) |
|
246 { |
|
247 allowChange = ETrue; |
|
248 } |
|
249 |
|
250 if ( allowChange ) |
|
251 { |
|
252 aMenuPane->SetItemDimmed( EDevEncUiCommandChange, EFalse ); |
|
253 } |
|
254 else |
|
255 { |
|
256 aMenuPane->SetItemDimmed( EDevEncUiCommandChange, ETrue ); |
|
257 } |
|
258 } |
|
259 } |
|
260 |
|
261 |
|
262 |
|
263 CDevEncUiAppUi& CDevEncUiMainView::GetAppUi() |
|
264 { |
|
265 CAknViewAppUi* aknViewAppUi = AppUi(); |
|
266 CDevEncUiAppUi* appUi = reinterpret_cast<CDevEncUiAppUi*>( aknViewAppUi ); |
|
267 return ( *appUi ); |
|
268 } |
|
269 |
|
270 void CDevEncUiMainView::EncryptionStatusChangeReq( TDevEncUiMemoryType aType ) |
|
271 { |
|
272 // Can't do anything about errors here |
|
273 TInt error( KErrNone ); |
|
274 TRAP( error, DoEncryptionStatusChangeReqL( aType ) ); |
|
275 if ( error ) |
|
276 { |
|
277 DFLOG2( "DoEncryptionStatusChangeReqL error %d", error ); |
|
278 } |
|
279 } |
|
280 |
|
281 // TBI: Async this function and create a subfunction with -L |
|
282 void CDevEncUiMainView::DoEncryptionStatusChangeReqL( TDevEncUiMemoryType aType ) |
|
283 { |
|
284 DFLOG( "CDevEncUiMainView::DoEncryptionStatusChangeReqL" ); |
|
285 |
|
286 // Check if we are allowed to start an encryption operation |
|
287 TInt dmControl( 0 ); |
|
288 TInt err = iCrSettings->Get( KDevEncUiDmControl, dmControl ); |
|
289 if ( err ) |
|
290 { |
|
291 DFLOG2( "Cenrep error %d", err ); |
|
292 User::Leave( err ); |
|
293 } |
|
294 if ( DmControlsMemory( aType, dmControl ) ) |
|
295 { |
|
296 // Encryption controlled by admin |
|
297 ErrorNoteL( R_DEVENCUI_NOTE_ADMIN_CONTROL ); |
|
298 return; |
|
299 } |
|
300 |
|
301 // Create the encryption operator if necessary |
|
302 if ( ! iEncOperator ) |
|
303 { |
|
304 iEncOperator = CDevEncUiEncryptionOperator::NewL( *iEikonEnv, |
|
305 *AppUi(), |
|
306 iCrSettings ); |
|
307 } |
|
308 |
|
309 // Get the currently highlighted memory type |
|
310 CDevEncUiMemoryEntity* mem = iMemEntities[ aType ]; |
|
311 |
|
312 DFLOG3( "Mem type: %d, state: %d", aType, mem->State() ); |
|
313 |
|
314 if ( aType == EPhoneMemory ) |
|
315 { |
|
316 CDevEncUiMemoryEntity* phoneMemory = iMemEntities[ EPrimaryPhoneMemory]; |
|
317 iEncOperator->HandlePhoneMemEncryptRequestL( mem, phoneMemory ); |
|
318 } |
|
319 else // aType = EMemoryCard |
|
320 { |
|
321 HandleMemoryCardEncryptRequestL( mem ); |
|
322 } |
|
323 } |
|
324 |
|
325 // -------------------------------------------------------------------------- |
|
326 // CDevEncUiMainView::ErrorNoteL() |
|
327 // TBI: Create base class and move this there |
|
328 // -------------------------------------------------------------------------- |
|
329 // |
|
330 void CDevEncUiMainView::ErrorNoteL( TInt aResourceId ) |
|
331 { |
|
332 HBufC* message = StringLoader::LoadLC( aResourceId ); |
|
333 CAknErrorNote* errorNote = new ( ELeave ) CAknErrorNote; |
|
334 errorNote->ExecuteLD( *message ); |
|
335 CleanupStack::PopAndDestroy( message ); |
|
336 } |
|
337 |
|
338 // TBI: Create base class and move this there |
|
339 TBool CDevEncUiMainView::DmControlsMemory( TDevEncUiMemoryType aType, |
|
340 TInt aDmControlSetting ) |
|
341 { |
|
342 TBool result( EFalse ); |
|
343 if ( ( aType == EPhoneMemory ) && |
|
344 ( aDmControlSetting & KDmControlsPhoneMemory ) ) |
|
345 { |
|
346 result = ETrue; |
|
347 } |
|
348 if ( ( aType == EMemoryCard ) && |
|
349 ( aDmControlSetting & KDmControlsMemoryCard ) ) |
|
350 { |
|
351 result = ETrue; |
|
352 } |
|
353 return result; |
|
354 } |
|
355 |
|
356 // -------------------------------------------------------------------------- |
|
357 // CDevEncUiMainView::HandleMemoryCardEncryptRequestL() |
|
358 // -------------------------------------------------------------------------- |
|
359 // |
|
360 void CDevEncUiMainView::HandleMemoryCardEncryptRequestL( CDevEncUiMemoryEntity* aMem ) |
|
361 { |
|
362 // Check if the driver has a known encryption key |
|
363 TInt mmcEncrOn( 0 ); |
|
364 iCrSettings->Get( KDevEncUserSettingMemoryCard, mmcEncrOn ); |
|
365 |
|
366 if ( aMem->State() == EDecrypted || |
|
367 aMem->State() == EUnmounted ) |
|
368 { |
|
369 if ( mmcEncrOn ) |
|
370 { |
|
371 // Mmc decrypted or ejected but encryption is on -> |
|
372 // suggest destruction of key |
|
373 DFLOG( "Mmc decrypted, encryption key set -> destroy key?" ); |
|
374 if ( aMem->State() == EDecrypted ) |
|
375 { |
|
376 // Mmc inserted -> indicate that it is decrypted |
|
377 // (see UI spec 2.12) |
|
378 iEncOperator->DestroyKeyQueryL( ETrue ); |
|
379 } |
|
380 else |
|
381 { |
|
382 // Mmc ejected -> no need to show note |
|
383 // (see UI spec 2.11) |
|
384 iEncOperator->DestroyKeyQueryL( EFalse ); |
|
385 } |
|
386 } |
|
387 else |
|
388 { |
|
389 // Mmc decrypted and encryption is off -> show encryption menu |
|
390 DFLOG( "Mmc decrypted, encryption key not set -> enc menu" ); |
|
391 AppUi()->ActivateLocalViewL( TUid::Uid( EDevEncUiEncrViewId ) ); |
|
392 } |
|
393 } |
|
394 else if ( aMem->State() == EEncrypted ) |
|
395 { |
|
396 // Encryption is on -> show decryption menu |
|
397 DFLOG( "Mmc encrypted -> decr menu" ); |
|
398 AppUi()->ActivateLocalViewL( TUid::Uid( EDevEncUiDecrViewId ) ); |
|
399 } |
|
400 else if ( aMem->State() == ECorrupted ) |
|
401 { |
|
402 if ( mmcEncrOn ) |
|
403 { |
|
404 // Mmc seems to be encrypted with another key. |
|
405 // Ask if the user wants to import another key. |
|
406 // (See UI spec 2.10) |
|
407 DFLOG( "CDevEncUiMainView::HandleMemoryCardEncryptRequestL => Mmc encrypted with another key, enc on -> import key" ); |
|
408 iEncOperator->SuggestMmcImportKeyL( aMem, ETrue ); |
|
409 } |
|
410 else |
|
411 { |
|
412 // Mmc is probably encrypted with another key -> show encryption |
|
413 // menu to let user choose a key |
|
414 DFLOG( "Mmc encrypted, encryption key not set -> enc menu" ); |
|
415 AppUi()->ActivateLocalViewL( TUid::Uid( EDevEncUiEncrViewId ) ); |
|
416 } |
|
417 } |
|
418 else |
|
419 { |
|
420 DFLOG2( "Mmc busy, state = %d, no action", aMem->State() ); |
|
421 } |
|
422 // Depending on the user's selection, the memory may be in the same |
|
423 // state as before or in a new state. This call will let all observers |
|
424 // know what state the memory ended up in. |
|
425 aMem->UpdateMemoryInfo(); |
|
426 |
|
427 } |
|
428 |
|
429 // -------------------------------------------------------------------------- |
|
430 // Called by the framework when the application status pane |
|
431 // size is changed. Passes the new client rectangle to the container. |
|
432 // -------------------------------------------------------------------------- |
|
433 void CDevEncUiMainView::HandleStatusPaneSizeChange() |
|
434 { |
|
435 if ( iContainer ) |
|
436 { |
|
437 iContainer->SetRect( ClientRect() ); |
|
438 } |
|
439 } |
|
440 |
|
441 // End of File |