|
1 /* |
|
2 * Copyright (c) 2008 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: Task monitor engine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "tsfswengine.h" |
|
20 #include "tscpsnotifier.h" |
|
21 #include "tsfswdatalist.h" |
|
22 #include "tsfsalwaysshownapplist.h" |
|
23 #include "tsfshiddenapplist.h" |
|
24 #include "tsfswidgetlist.h" |
|
25 #include "tspreviewprovider.h" |
|
26 #include "tsfswclient.h" |
|
27 #include <apgtask.h> |
|
28 #include <AknDef.h> |
|
29 #include <apgwgnam.h> |
|
30 #include <mmf/common/mmfcontrollerpluginresolver.h> // for CleanupResetAndDestroyPushL |
|
31 #include <featmgr.h> |
|
32 #include <swi/swispubsubdefs.h> |
|
33 #include <s32mem.h> |
|
34 #include <bitmaptransforms.h> |
|
35 #include "enginelogging.h" |
|
36 |
|
37 // time to wait before refreshing content |
|
38 const TInt KContentRefreshDelay = 50000; // 0.05 sec |
|
39 |
|
40 // for screenshots, they are scaled down to (screensize/this_factor). |
|
41 const TInt KScreenSizeFactor = 2; |
|
42 |
|
43 const TUid KTsCameraUid = { 0x101F857a }; |
|
44 |
|
45 //close command for widget |
|
46 const TInt KCloseWidgetCmd(9); |
|
47 //handle close cmd for s60 widgets |
|
48 _LIT(KWidgetAppName, "widgetlauncher.exe"); |
|
49 //handle close cmd for CWRT widgets |
|
50 _LIT(KWidgetAppNameWgt,"wgtwidgetlauncher.exe"); |
|
51 |
|
52 // -------------------------------------------------------------------------- |
|
53 // CTsFswEngine::NewL |
|
54 // -------------------------------------------------------------------------- |
|
55 // |
|
56 EXPORT_C CTsFswEngine* CTsFswEngine::NewL( MTsFswEngineObserver& aObserver ) |
|
57 { |
|
58 CTsFswEngine* self = NewLC( aObserver ); |
|
59 CleanupStack::Pop( self ); |
|
60 return self; |
|
61 } |
|
62 |
|
63 // -------------------------------------------------------------------------- |
|
64 // CTsFswEngine::NewLC |
|
65 // -------------------------------------------------------------------------- |
|
66 // |
|
67 EXPORT_C CTsFswEngine* CTsFswEngine::NewLC( MTsFswEngineObserver& aObserver ) |
|
68 { |
|
69 CTsFswEngine* self = new ( ELeave ) CTsFswEngine( aObserver ); |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(); |
|
72 return self; |
|
73 } |
|
74 |
|
75 // -------------------------------------------------------------------------- |
|
76 // CTsFswEngine::CTsFswEngine |
|
77 // -------------------------------------------------------------------------- |
|
78 // |
|
79 CTsFswEngine::CTsFswEngine( MTsFswEngineObserver& aObserver ) |
|
80 : CActive( EPriorityStandard ), iObserver( aObserver ) |
|
81 { |
|
82 CActiveScheduler::Add( this ); |
|
83 } |
|
84 |
|
85 // -------------------------------------------------------------------------- |
|
86 // CTsFswEngine::ConstructL |
|
87 // -------------------------------------------------------------------------- |
|
88 // |
|
89 void CTsFswEngine::ConstructL() |
|
90 { |
|
91 iEnv = CEikonEnv::Static(); |
|
92 |
|
93 User::LeaveIfError( iWsSession.Connect() ); |
|
94 User::LeaveIfError( iAppArcSession.Connect() ); |
|
95 |
|
96 iDataList = CTsFswDataList::NewL(*this); |
|
97 iWidgetsSupported = FeatureManager::FeatureSupported( KFeatureIdWebWidgets ); |
|
98 |
|
99 // get an initial list of tasks |
|
100 iDataList->SetAppDataRefreshNeeded(); |
|
101 CollectTasksL(); |
|
102 |
|
103 // listen for app screenshots |
|
104 iPreviewProvider = CTsFastSwapPreviewProvider::NewL( *this ); |
|
105 SetPreviewParams(); |
|
106 UpdatePreviewContent(); |
|
107 |
|
108 iUpdateStarter = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
109 |
|
110 // start listening for swi ps property |
|
111 if ( iSwiProp.Attach( KUidSystemCategory, |
|
112 Swi::KUidSoftwareInstallKey ) == KErrNone ) |
|
113 { |
|
114 iSwiProp.Subscribe( iStatus ); |
|
115 SetActive(); |
|
116 } |
|
117 iCpsWidgetPublisher = CTSCpsNotifier::NewL(*this); |
|
118 } |
|
119 |
|
120 // -------------------------------------------------------------------------- |
|
121 // CTsFswEngine::~CTsFswEngine |
|
122 // -------------------------------------------------------------------------- |
|
123 // |
|
124 CTsFswEngine::~CTsFswEngine() |
|
125 { |
|
126 Cancel(); |
|
127 iSwiProp.Close(); |
|
128 |
|
129 delete iUpdateStarter; |
|
130 delete iPreviewProvider; |
|
131 |
|
132 iWgIds.Close(); |
|
133 |
|
134 iAppArcSession.Close(); |
|
135 iWsSession.Close(); |
|
136 |
|
137 for ( TInt i = 0; i < iRotaTasks.Count(); i++ ) |
|
138 { |
|
139 iRotaTasks[i]->Cancel(); |
|
140 delete iRotaTasks[i]; |
|
141 } |
|
142 iRotaTasks.Close(); |
|
143 delete iDataList; |
|
144 delete iCpsWidgetPublisher; |
|
145 } |
|
146 |
|
147 // -------------------------------------------------------------------------- |
|
148 // CTsFswEngine::FswDataL |
|
149 // -------------------------------------------------------------------------- |
|
150 // |
|
151 EXPORT_C const RTsFswArray& CTsFswEngine::FswDataL() |
|
152 { |
|
153 TSLOG_CONTEXT( FswDataL, TSLOG_LOCAL ); |
|
154 TSLOG_OUT(); |
|
155 return iDataList->FswDataL(); |
|
156 } |
|
157 |
|
158 // -------------------------------------------------------------------------- |
|
159 // CTsFswEngine::CloseAppL |
|
160 // -------------------------------------------------------------------------- |
|
161 // |
|
162 EXPORT_C void CTsFswEngine::CloseAppL( TInt aWgId ) |
|
163 { |
|
164 TSLOG_CONTEXT( CloseAppL, TSLOG_LOCAL ); |
|
165 TSLOG1_IN( "aWgId = %d", aWgId ); |
|
166 |
|
167 if( iWidgetsSupported && 0 > aWgId ) |
|
168 { |
|
169 // convert aWgId to an index in the list of running widgets and close widget |
|
170 CloseWidgetL( -aWgId -1 ); |
|
171 } |
|
172 else if( !iDataList->IsAlwaysShownAppL( aWgId ) ) |
|
173 { |
|
174 // send window group event to kill the app |
|
175 TWsEvent event; |
|
176 event.SetTimeNow(); |
|
177 event.SetType( KAknShutOrHideApp ); |
|
178 iEnv->WsSession().SendEventToWindowGroup( aWgId, event ); |
|
179 TSLOG0( TSLOG_INFO, "event sent to wg" ); |
|
180 } |
|
181 TSLOG_OUT(); |
|
182 } |
|
183 |
|
184 // -------------------------------------------------------------------------- |
|
185 // CTsFswEngine::SwitchToAppL |
|
186 // -------------------------------------------------------------------------- |
|
187 // |
|
188 EXPORT_C void CTsFswEngine::SwitchToAppL( TInt aWgId ) |
|
189 { |
|
190 TSLOG_CONTEXT( SwitchToAppL, TSLOG_LOCAL ); |
|
191 TSLOG1_IN( "aWgId = %d", aWgId ); |
|
192 |
|
193 if ( iWidgetsSupported && aWgId < 0 ) |
|
194 { |
|
195 // for widgets clients see a wgid that is -1*(index+1) |
|
196 const RWidgetInfoArray& arr( iDataList->Widgets()->RunningWidgets() ); |
|
197 // convert aWgId to an index in the list of running widgets |
|
198 TInt idx = -aWgId - 1; |
|
199 // if index is valid then handle the widget specially |
|
200 if ( idx >= 0 && idx < arr.Count() ) |
|
201 { |
|
202 SwitchToWidgetL( idx ); |
|
203 TSLOG1_OUT( "switched to widget %d", idx ); |
|
204 return; |
|
205 } |
|
206 } |
|
207 |
|
208 TApaTask task( iEnv->WsSession() ); |
|
209 task.SetWgId( aWgId ); |
|
210 task.BringToForeground(); |
|
211 |
|
212 TSLOG_OUT(); |
|
213 } |
|
214 |
|
215 // -------------------------------------------------------------------------- |
|
216 // CTsFswEngine::SwitchToWidgetL |
|
217 // -------------------------------------------------------------------------- |
|
218 // |
|
219 void CTsFswEngine::SwitchToWidgetL( TInt aWidgetIndex ) |
|
220 { |
|
221 const RWidgetInfoArray& arr( iDataList->Widgets()->RunningWidgets() ); |
|
222 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); |
|
223 cmdLine->SetCommandL( EApaCommandRun ); |
|
224 TApaAppInfo info; |
|
225 iAppArcSession.GetAppInfo( info, arr[aWidgetIndex]->iUid ); // codescanner::accessArrayElementWithoutCheck2 (aWidgetIndex checked in SwitchToAppL()) |
|
226 cmdLine->SetExecutableNameL( info.iFullName ); |
|
227 iAppArcSession.StartApp( *cmdLine ); |
|
228 CleanupStack::PopAndDestroy(cmdLine); |
|
229 } |
|
230 |
|
231 // -------------------------------------------------------------------------- |
|
232 // CTsFswEngine::UpdateTaskList |
|
233 // Callback from appui |
|
234 // -------------------------------------------------------------------------- |
|
235 // |
|
236 void CTsFswEngine::UpdateTaskList() |
|
237 { |
|
238 TSLOG_CONTEXT( UpdateTaskList, TSLOG_LOCAL ); |
|
239 TSLOG_IN(); |
|
240 |
|
241 // screenshot taking support - call Register and Unregister when needed |
|
242 UpdatePreviewContent(); |
|
243 |
|
244 // get the foreground app uid and publish it to CFW if different than before |
|
245 TRAP_IGNORE( PublishFgAppUidL() ); |
|
246 |
|
247 // There can be many calls in a row, use a timer to prevent degrading |
|
248 // device performance. |
|
249 if ( !iUpdateStarter->IsActive() ) |
|
250 { |
|
251 iUpdateStarter->Start( KContentRefreshDelay, 0, |
|
252 TCallBack( UpdateStarterCallback, this ) ); |
|
253 } |
|
254 |
|
255 TSLOG_OUT(); |
|
256 } |
|
257 |
|
258 // -------------------------------------------------------------------------- |
|
259 // CTsFswEngine::ForegroundAppUidL |
|
260 // -------------------------------------------------------------------------- |
|
261 // |
|
262 EXPORT_C TUid CTsFswEngine::ForegroundAppUidL( TInt aType ) |
|
263 { |
|
264 // Do not use GetFocusWindowGroup or others. |
|
265 // We want to see only "real" application uids in FgApp, |
|
266 // i.e. stuff that would also be shown in the task swapper |
|
267 // area of Taskswitcher. |
|
268 |
|
269 TUid result = KNullUid; |
|
270 RArray<RWsSession::TWindowGroupChainInfo> allWgIds; |
|
271 CleanupClosePushL( allWgIds ); |
|
272 User::LeaveIfError( iWsSession.WindowGroupList( 0, &allWgIds ) ); |
|
273 TInt count = allWgIds.Count(); |
|
274 for ( TInt i = 0; i < count; ++i ) |
|
275 { |
|
276 // Depending on aType we may not need to bother with iParentId here. |
|
277 // If aType == EUseEmbeddedUid => embedded apps are treated as others. |
|
278 // If aType == EUseStandaloneUid => embedded apps must be ignored. |
|
279 if ( allWgIds[i].iParentId > 0 |
|
280 && aType == CTsFswClient::EUseStandaloneUid ) |
|
281 { |
|
282 continue; |
|
283 } |
|
284 |
|
285 CApaWindowGroupName* wgn = CApaWindowGroupName::NewLC( |
|
286 iWsSession, allWgIds[i].iId ); |
|
287 TUid newUid = wgn->AppUid(); |
|
288 TBool hidden = wgn->Hidden() || iDataList->HiddenApps()->IsHiddenL( |
|
289 newUid, iWsSession, allWgIds[i].iId ); |
|
290 CleanupStack::PopAndDestroy( wgn ); |
|
291 |
|
292 if ( !hidden && newUid.iUid ) |
|
293 { |
|
294 result = newUid; |
|
295 break; |
|
296 } |
|
297 } |
|
298 CleanupStack::PopAndDestroy( &allWgIds ); |
|
299 |
|
300 return result; |
|
301 } |
|
302 |
|
303 // -------------------------------------------------------------------------- |
|
304 // CTsFswEngine::PublishFgAppUidL |
|
305 // -------------------------------------------------------------------------- |
|
306 // |
|
307 void CTsFswEngine::PublishFgAppUidL() |
|
308 { |
|
309 TSLOG_CONTEXT( PublishFgAppUidL, TSLOG_LOCAL ); |
|
310 TSLOG_IN(); |
|
311 |
|
312 TUid newUid = ForegroundAppUidL( CTsFswClient::EUseEmbeddedUid ); |
|
313 TSLOG2( TSLOG_INFO, "ws says: %x we have: %x", newUid.iUid, iFgAppUid.iUid ); |
|
314 if ( iFgAppUid != newUid && newUid.iUid ) |
|
315 { |
|
316 iFgAppUid = newUid; |
|
317 iDataList->MoveEntryAtStart(newUid.iUid, EFalse); |
|
318 TBool change( iDataList->MoveEntryAtStart(newUid.iUid, EFalse) ); |
|
319 if( change ) |
|
320 { |
|
321 iObserver.FswDataChanged(); |
|
322 } |
|
323 } |
|
324 |
|
325 TSLOG_OUT(); |
|
326 } |
|
327 |
|
328 // -------------------------------------------------------------------------- |
|
329 // CTsFswEngine::UpdateStarterCallback |
|
330 // Callback for the timer |
|
331 // -------------------------------------------------------------------------- |
|
332 // |
|
333 TInt CTsFswEngine::UpdateStarterCallback( TAny* aParam ) |
|
334 { |
|
335 CTsFswEngine* self = static_cast<CTsFswEngine*>( aParam ); |
|
336 self->iUpdateStarter->Cancel(); |
|
337 // get list of tasks and notify observer if there is a change in the list |
|
338 TBool changed = EFalse; |
|
339 TRAPD( err, changed = self->CollectTasksL() ); |
|
340 if ( err == KErrNone && changed ) |
|
341 { |
|
342 self->iObserver.FswDataChanged(); |
|
343 } |
|
344 return 0; |
|
345 } |
|
346 |
|
347 // -------------------------------------------------------------------------- |
|
348 // CTsFswEngine::CollectTasksL |
|
349 // -------------------------------------------------------------------------- |
|
350 // |
|
351 TBool CTsFswEngine::CollectTasksL() |
|
352 { |
|
353 TSLOG_CONTEXT( CollectTasksL, TSLOG_LOCAL ); |
|
354 TBool changed = iDataList->CollectTasksL(); |
|
355 TSLOG1_OUT( "change flag = %d", changed ); |
|
356 return changed; |
|
357 } |
|
358 |
|
359 |
|
360 // CTsFswEngine::HiddenAppListUpdated |
|
361 // Callback from the hidden app list watcher |
|
362 // -------------------------------------------------------------------------- |
|
363 // |
|
364 void CTsFswEngine::HiddenAppListUpdated() |
|
365 { |
|
366 UpdateTaskList(); |
|
367 } |
|
368 |
|
369 // -------------------------------------------------------------------------- |
|
370 // CTsFswEngine::CopyBitmapL |
|
371 // -------------------------------------------------------------------------- |
|
372 // |
|
373 CFbsBitmap* CTsFswEngine::CopyBitmapL( TInt aFbsHandle, TBool aKeepAspectRatio ) |
|
374 { |
|
375 TSLOG_CONTEXT( CopyBitmapL, TSLOG_LOCAL ); |
|
376 |
|
377 CFbsBitmap* ret = new (ELeave) CFbsBitmap; |
|
378 CleanupStack::PushL( ret ); |
|
379 CFbsBitmap* bmp = new (ELeave) CFbsBitmap; |
|
380 CleanupStack::PushL( bmp ); |
|
381 User::LeaveIfError( bmp->Duplicate( aFbsHandle ) ); |
|
382 |
|
383 //Make bitmap width and height equal so that it will look better in FSW control. |
|
384 TSize size = bmp->SizeInPixels(); |
|
385 |
|
386 if ( !aKeepAspectRatio ) |
|
387 { |
|
388 if ( size.iHeight > size.iWidth ) |
|
389 { |
|
390 size.iHeight = size.iWidth; |
|
391 } |
|
392 else |
|
393 { |
|
394 size.iWidth = size.iHeight; |
|
395 } |
|
396 } |
|
397 |
|
398 // preserve size and mode |
|
399 User::LeaveIfError( ret->Create( size, EColor64K ) ); |
|
400 |
|
401 CFbsBitmapDevice* doubleBufferDev = CFbsBitmapDevice::NewL( ret ); |
|
402 CleanupStack::PushL( doubleBufferDev ); |
|
403 |
|
404 CFbsBitGc* doubleBufferGc = 0; |
|
405 User::LeaveIfError( doubleBufferDev->CreateContext( doubleBufferGc ) ); |
|
406 CleanupStack::PushL( doubleBufferGc ); |
|
407 |
|
408 // preserve size |
|
409 doubleBufferGc->BitBlt( TPoint( 0, 0 ), bmp, TRect(size) ); |
|
410 |
|
411 CleanupStack::PopAndDestroy( doubleBufferGc ); |
|
412 CleanupStack::PopAndDestroy( doubleBufferDev ); |
|
413 CleanupStack::PopAndDestroy( bmp ); |
|
414 CleanupStack::Pop( ret ); |
|
415 |
|
416 TSLOG_OUT(); |
|
417 return ret; |
|
418 } |
|
419 |
|
420 // -------------------------------------------------------------------------- |
|
421 // CTsFswEngine::UpdatePreviewContent |
|
422 // -------------------------------------------------------------------------- |
|
423 // |
|
424 void CTsFswEngine::UpdatePreviewContent() |
|
425 { |
|
426 TSLOG_CONTEXT( UpdatePreviewContent, TSLOG_LOCAL ); |
|
427 TSLOG_IN(); |
|
428 |
|
429 RArray<RWsSession::TWindowGroupChainInfo> allWgIds; |
|
430 if ( iWsSession.WindowGroupList( 0, &allWgIds ) == KErrNone ) |
|
431 { |
|
432 // check window groups that do not exist anymore |
|
433 for ( TInt i = 0, ie = iWgIds.Count(); i != ie; ++i ) |
|
434 { |
|
435 TInt wgid = iWgIds[i]; |
|
436 TBool present = EFalse; |
|
437 for ( TInt j = 0, je = allWgIds.Count(); j != je; ++j ) |
|
438 { |
|
439 if ( allWgIds[j].iId == wgid ) |
|
440 { |
|
441 present = ETrue; |
|
442 break; |
|
443 } |
|
444 } |
|
445 if ( !present ) |
|
446 { |
|
447 TSLOG1( TSLOG_INFO, "unregister: %d", wgid ); |
|
448 iPreviewProvider->Unregister( wgid ); |
|
449 } |
|
450 } |
|
451 // check topmost window group |
|
452 if ( allWgIds.Count() ) |
|
453 { |
|
454 if ( !iWgIds.Count() || allWgIds[0].iId != iWgIds[0] ) |
|
455 { |
|
456 TInt wgid = allWgIds[0].iId; |
|
457 TSLOG1( TSLOG_INFO, "registering %d", wgid ); |
|
458 iPreviewProvider->Register( wgid ); |
|
459 } |
|
460 } |
|
461 // store the new list |
|
462 iWgIds.Reset(); |
|
463 for ( TInt i = 0, ie = allWgIds.Count(); i != ie; ++i ) |
|
464 { |
|
465 iWgIds.Append( allWgIds[i].iId ); |
|
466 } |
|
467 } |
|
468 allWgIds.Close(); |
|
469 |
|
470 TSLOG_OUT(); |
|
471 } |
|
472 |
|
473 // -------------------------------------------------------------------------- |
|
474 // CTsFswEngine::HandleFswPpApplicationChange |
|
475 // Callback from CTsFastSwapPreviewProvider |
|
476 // Note: aWgId is for the window group for which the screenshot is taken, |
|
477 // it may not be the same as the application's wgid (in case of embedded apps) |
|
478 // -------------------------------------------------------------------------- |
|
479 // |
|
480 void CTsFswEngine::HandleFswPpApplicationChange( TInt aWgId, TInt aFbsHandle ) |
|
481 { |
|
482 TSLOG_CONTEXT( HandleFswPpApplicationChange, TSLOG_LOCAL ); |
|
483 TSLOG2_IN( "aWgId = %d aFbsHandle = %d", aWgId, aFbsHandle ); |
|
484 |
|
485 TUid appUid; |
|
486 TInt wgId = iDataList->FindMostTopParentWgId(aWgId); |
|
487 if ( wgId == KErrNotFound ) |
|
488 { |
|
489 wgId = aWgId; |
|
490 } |
|
491 TInt err = iDataList->AppUidForWgId( wgId, appUid ); |
|
492 if ( err || appUid == KTsCameraUid ) |
|
493 { |
|
494 // Dont't assign screenshot to camera app |
|
495 TSLOG0( TSLOG_LOCAL, "Screenshot for camera - ignore" ); |
|
496 iPreviewProvider->AckPreview(aFbsHandle); |
|
497 TSLOG_OUT(); |
|
498 return; |
|
499 } |
|
500 |
|
501 CFbsBitmap* bmp = 0; |
|
502 TRAP( err, bmp = CopyBitmapL( aFbsHandle, EFalse ) ); |
|
503 iPreviewProvider->AckPreview(aFbsHandle); |
|
504 if ( err == KErrNone ) |
|
505 { |
|
506 StoreScreenshot(aWgId, bmp); |
|
507 } |
|
508 |
|
509 TSLOG_OUT(); |
|
510 } |
|
511 |
|
512 // -------------------------------------------------------------------------- |
|
513 // CTsFswEngine::HandleFswPpApplicationUnregistered |
|
514 // Callback from CTsFastSwapPreviewProvider |
|
515 // -------------------------------------------------------------------------- |
|
516 // |
|
517 void CTsFswEngine::HandleFswPpApplicationUnregistered( TInt aWgId ) |
|
518 { |
|
519 TSLOG_CONTEXT( HandleFswPpApplicationUnregistered, TSLOG_LOCAL ); |
|
520 TSLOG1_IN( "aWgId = %d", aWgId ); |
|
521 |
|
522 RemoveScreenshot(aWgId); |
|
523 |
|
524 TSLOG_OUT(); |
|
525 } |
|
526 |
|
527 // -------------------------------------------------------------------------- |
|
528 // CTsFswEngine::HandleFswPpApplicationBitmapRotation |
|
529 // Callback from CTsFastSwapPreviewProvider |
|
530 // -------------------------------------------------------------------------- |
|
531 // |
|
532 void CTsFswEngine::HandleFswPpApplicationBitmapRotation( TInt aWgId, TBool aClockwise ) |
|
533 { |
|
534 TSLOG_CONTEXT( HandleFswPpApplicationBitmapRotation, TSLOG_LOCAL ); |
|
535 TSLOG1_IN( "aWgId = %d", aWgId ); |
|
536 |
|
537 CFbsBitmap** bmp = iDataList->FindScreenshot(aWgId); |
|
538 |
|
539 if ( bmp ) |
|
540 { |
|
541 // Rotate bitmap |
|
542 TRAP_IGNORE( RotateL( **bmp, aWgId, aClockwise ) ); |
|
543 // Bitmap in a array is invalid, remove it |
|
544 RemoveScreenshot(aWgId); |
|
545 } |
|
546 |
|
547 TSLOG_OUT(); |
|
548 } |
|
549 |
|
550 |
|
551 // -------------------------------------------------------------------------- |
|
552 // CTsFswEngine::RotateL |
|
553 // Callback from CTsFastSwapPreviewProvider |
|
554 // -------------------------------------------------------------------------- |
|
555 // |
|
556 void CTsFswEngine::RotateL( CFbsBitmap& aBitmap, TInt aWgId, TBool aClockwise ) |
|
557 { |
|
558 CFbsBitmap* rotaBitmap = new (ELeave) CFbsBitmap; |
|
559 CleanupStack::PushL( rotaBitmap ); |
|
560 User::LeaveIfError( rotaBitmap->Duplicate( aBitmap.Handle() ) ); |
|
561 CTsRotationTask* rotaTask = new (ELeave) CTsRotationTask( *this ); |
|
562 CleanupStack::PushL( rotaTask ); |
|
563 User::LeaveIfError( iRotaTasks.Append( rotaTask ) ); |
|
564 rotaTask->StartLD( aWgId, rotaBitmap, aClockwise ); // ownership transferred |
|
565 CleanupStack::Pop( rotaTask ); |
|
566 CleanupStack::Pop( rotaBitmap ); |
|
567 } |
|
568 |
|
569 |
|
570 // -------------------------------------------------------------------------- |
|
571 // CTsFswEngine::RotationComplete |
|
572 // Callback from CTsFastSwapPreviewProvider |
|
573 // -------------------------------------------------------------------------- |
|
574 // |
|
575 void CTsFswEngine::RotationComplete( TInt aWgId, |
|
576 CFbsBitmap* aBitmap, |
|
577 CTsRotationTask* aCompletedTask, |
|
578 TInt aError ) |
|
579 { |
|
580 TSLOG_CONTEXT( RotationComplete, TSLOG_LOCAL ); |
|
581 TSLOG_IN(); |
|
582 |
|
583 TSLOG1( TSLOG_INFO, "---> rotation completed with status: %d", aError ); |
|
584 TInt idx = iRotaTasks.Find( aCompletedTask ); |
|
585 if ( idx != KErrNotFound ) |
|
586 { |
|
587 // Update task list |
|
588 iRotaTasks.Remove(idx); |
|
589 } |
|
590 |
|
591 if ( aError == KErrNone ) |
|
592 { |
|
593 StoreScreenshot(aWgId, aBitmap); |
|
594 } |
|
595 else |
|
596 { |
|
597 // Rotation failed, cleanup bitmap |
|
598 delete aBitmap; |
|
599 } |
|
600 |
|
601 TSLOG_OUT(); |
|
602 } |
|
603 |
|
604 // -------------------------------------------------------------------------- |
|
605 // CTsFswEngine::RunL |
|
606 // -------------------------------------------------------------------------- |
|
607 // |
|
608 void CTsFswEngine::RunL() |
|
609 { |
|
610 if ( iStatus != KErrCancel ) // when cancelling the subscribe it completes with KErrCancel |
|
611 { |
|
612 TInt value = 0; |
|
613 if ( iSwiProp.Get( value ) == KErrNone ) |
|
614 { |
|
615 TInt operationStatus( value & Swi::KSwisOperationStatusMask ); |
|
616 // When an (un)installation has finished change the flag to |
|
617 // refresh the app list during the next task list update. |
|
618 if ( operationStatus == Swi::ESwisStatusSuccess ) |
|
619 { |
|
620 iDataList->SetAppDataRefreshNeeded(); |
|
621 } |
|
622 } |
|
623 iSwiProp.Subscribe( iStatus ); |
|
624 SetActive(); |
|
625 } |
|
626 } |
|
627 |
|
628 // -------------------------------------------------------------------------- |
|
629 // CTsFswEngine::DoCancel |
|
630 // -------------------------------------------------------------------------- |
|
631 // |
|
632 void CTsFswEngine::DoCancel() |
|
633 { |
|
634 iSwiProp.Cancel(); |
|
635 } |
|
636 |
|
637 // -------------------------------------------------------------------------- |
|
638 // CTsFswEngine::RunError |
|
639 // -------------------------------------------------------------------------- |
|
640 // |
|
641 TInt CTsFswEngine::RunError( TInt /*aError*/ ) |
|
642 { |
|
643 return KErrNone; |
|
644 } |
|
645 |
|
646 // -------------------------------------------------------------------------- |
|
647 // CTsFswEngine::HandleResourceChange |
|
648 // callback from appui's HandleResourceChangeL |
|
649 // -------------------------------------------------------------------------- |
|
650 // |
|
651 void CTsFswEngine::HandleResourceChange( TInt aType ) |
|
652 { |
|
653 TSLOG_CONTEXT( HandleResourceChange, TSLOG_LOCAL ); |
|
654 TSLOG_IN(); |
|
655 |
|
656 if ( iPreviewProvider && aType == KEikDynamicLayoutVariantSwitch ) |
|
657 { |
|
658 SetPreviewParams(); |
|
659 } |
|
660 |
|
661 TSLOG_OUT(); |
|
662 } |
|
663 |
|
664 // -------------------------------------------------------------------------- |
|
665 // CTsFswEngine::SetPreviewParams |
|
666 // -------------------------------------------------------------------------- |
|
667 // |
|
668 void CTsFswEngine::SetPreviewParams() |
|
669 { |
|
670 TSize screenSize = iEnv->ScreenDevice()->SizeInPixels(); |
|
671 iPreviewProvider->SetPreviewParam( |
|
672 TSize( screenSize.iWidth / KScreenSizeFactor, |
|
673 screenSize.iHeight / KScreenSizeFactor ), |
|
674 EColor64K ); // displaymode is ignored |
|
675 } |
|
676 |
|
677 // -------------------------------------------------------------------------- |
|
678 // CTsFswEngine::CloseWidgetL |
|
679 // -------------------------------------------------------------------------- |
|
680 // |
|
681 void CTsFswEngine::CloseWidgetL(TInt aOffset ) |
|
682 { |
|
683 TSLOG_CONTEXT( CloseWidgetL, TSLOG_LOCAL ); |
|
684 TSLOG1_IN( "aOffset = %d", aOffset ); |
|
685 if( iDataList->Widgets()->RunningWidgets().Count() <= aOffset ) |
|
686 { |
|
687 User::Leave(KErrArgument); |
|
688 } |
|
689 const CWidgetInfo* widgetInfo(iDataList->Widgets()->RunningWidgets()[aOffset]); |
|
690 const TPtrC bundleName(*widgetInfo->iBundleName); |
|
691 CApaCommandLine* const cmdLine = CApaCommandLine::NewLC(); |
|
692 |
|
693 HBufC8* const |
|
694 opaque( HBufC8::NewLC( bundleName.Size() + 3 * sizeof( TUint32 ) ) ); |
|
695 TPtr8 des ( opaque->Des() ); |
|
696 RDesWriteStream stream; |
|
697 stream.Open( des ); |
|
698 CleanupClosePushL( stream ); |
|
699 stream.WriteUint32L ( widgetInfo->iUid.iUid ); |
|
700 stream.WriteUint32L ( bundleName.Length() ); |
|
701 stream.WriteL ( reinterpret_cast< const TUint8* >( bundleName.Ptr() ), bundleName.Size()); |
|
702 stream.WriteInt32L ( KCloseWidgetCmd ); |
|
703 CleanupStack::PopAndDestroy( &stream ); |
|
704 cmdLine->SetCommandL( EApaCommandBackgroundAndWithoutViews ); |
|
705 cmdLine->SetOpaqueDataL( *opaque ); |
|
706 CleanupStack::PopAndDestroy( opaque ); |
|
707 |
|
708 if (iDataList->Widgets()->IsCWRTWidget(widgetInfo->iUid)) |
|
709 { |
|
710 cmdLine->SetExecutableNameL( KWidgetAppNameWgt); |
|
711 } |
|
712 else |
|
713 { |
|
714 cmdLine->SetExecutableNameL( KWidgetAppName ); |
|
715 } |
|
716 |
|
717 iAppArcSession.StartApp( *cmdLine ); |
|
718 CleanupStack::PopAndDestroy( cmdLine ); |
|
719 TSLOG_OUT(); |
|
720 } |
|
721 |
|
722 // -------------------------------------------------------------------------- |
|
723 // CTsFswEngine::StoreScreenshot |
|
724 // -------------------------------------------------------------------------- |
|
725 // |
|
726 TBool CTsFswEngine::StoreScreenshot(TInt aWgId, CFbsBitmap* aBmp) |
|
727 { |
|
728 TSLOG_CONTEXT( StoreScreenshot, TSLOG_LOCAL ); |
|
729 //iDataList would take ownership |
|
730 TBool change = EFalse; |
|
731 change = iDataList->StoreScreenshot(aWgId, aBmp); |
|
732 if(change) |
|
733 { |
|
734 iObserver.FswDataChanged(); |
|
735 } |
|
736 TSLOG1_OUT( "Screenshot for = %d", aWgId ); |
|
737 return change; |
|
738 } |
|
739 |
|
740 // -------------------------------------------------------------------------- |
|
741 // CTsFswEngine::RemoveScreenshot() |
|
742 // -------------------------------------------------------------------------- |
|
743 // |
|
744 void CTsFswEngine::RemoveScreenshot(TInt aWgId) |
|
745 { |
|
746 TBool change = EFalse; |
|
747 change = iDataList->RemoveScreenshot(aWgId); |
|
748 if( change ) |
|
749 { |
|
750 iObserver.FswDataChanged(); |
|
751 } |
|
752 } |
|
753 |
|
754 // -------------------------------------------------------------------------- |
|
755 // CTsFswEngine::HandleWidgetUpdateL() |
|
756 // -------------------------------------------------------------------------- |
|
757 // |
|
758 void CTsFswEngine::HandleWidgetUpdateL(TInt aWidgetId, TInt aBitmapHandle) |
|
759 { |
|
760 TSLOG_CONTEXT( HandleWidgetUpdateL, TSLOG_LOCAL ); |
|
761 |
|
762 TBool contentChanged( iDataList->MoveEntryAtStart(aWidgetId, ETrue) ); |
|
763 |
|
764 CFbsBitmap* bmp = 0; |
|
765 if( aBitmapHandle ) |
|
766 { |
|
767 TRAPD( err, bmp = CopyBitmapL( aBitmapHandle, EFalse ) ); |
|
768 if ( err == KErrNone ) |
|
769 { |
|
770 contentChanged = StoreScreenshot(aWidgetId, bmp); |
|
771 } |
|
772 } |
|
773 if(!contentChanged) |
|
774 { |
|
775 iObserver.FswDataChanged(); |
|
776 } |
|
777 |
|
778 TSLOG_OUT(); |
|
779 } |
|
780 |
|
781 // -------------------------------------------------------------------------- |
|
782 // CTsRotationListener::CTsRotationListener |
|
783 // -------------------------------------------------------------------------- |
|
784 // |
|
785 CTsRotationTask::CTsRotationTask(CTsFswEngine& aEngine ) |
|
786 : CActive(EPriorityStandard), |
|
787 iEngine(aEngine) |
|
788 { |
|
789 CActiveScheduler::Add( this ); |
|
790 } |
|
791 |
|
792 |
|
793 // -------------------------------------------------------------------------- |
|
794 // CTsRotationListener::~CTsRotationListener |
|
795 // -------------------------------------------------------------------------- |
|
796 // |
|
797 CTsRotationTask::~CTsRotationTask() |
|
798 { |
|
799 Cancel(); |
|
800 delete iRotator; |
|
801 delete iBitmap; |
|
802 } |
|
803 |
|
804 |
|
805 // -------------------------------------------------------------------------- |
|
806 // CTsRotationListener::Start |
|
807 // -------------------------------------------------------------------------- |
|
808 // |
|
809 void CTsRotationTask::StartLD( TInt aWgId, |
|
810 CFbsBitmap* aBitmap, |
|
811 TBool aClockwise ) |
|
812 { |
|
813 TSLOG_CONTEXT( StartLD, TSLOG_LOCAL ); |
|
814 TSLOG_IN(); |
|
815 |
|
816 iWgId = aWgId; |
|
817 iBitmap = aBitmap; |
|
818 iRotator = CBitmapRotator::NewL(); |
|
819 if ( aClockwise ) |
|
820 { |
|
821 iRotator->Rotate(&iStatus, *iBitmap, CBitmapRotator::ERotation90DegreesClockwise); |
|
822 } |
|
823 else |
|
824 { |
|
825 iRotator->Rotate(&iStatus, *iBitmap, CBitmapRotator::ERotation270DegreesClockwise); |
|
826 } |
|
827 SetActive(); |
|
828 |
|
829 TSLOG_OUT(); |
|
830 } |
|
831 |
|
832 |
|
833 // -------------------------------------------------------------------------- |
|
834 // CTsRotationListener::RunL |
|
835 // -------------------------------------------------------------------------- |
|
836 // |
|
837 void CTsRotationTask::RunL() |
|
838 { |
|
839 iEngine.RotationComplete( iWgId, iBitmap, this, iStatus.Int() ); // bitmap ownership transferred |
|
840 iBitmap = NULL; |
|
841 delete this; |
|
842 } |
|
843 |
|
844 |
|
845 // -------------------------------------------------------------------------- |
|
846 // CTsRotationListener::DoCancel |
|
847 // -------------------------------------------------------------------------- |
|
848 // |
|
849 void CTsRotationTask::DoCancel() |
|
850 { |
|
851 iRotator->Cancel(); |
|
852 } |
|
853 |
|
854 // end of file |