114
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 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: Engine for BS Engine
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <apgtask.h>
|
|
20 |
#include <apgwgnam.h>
|
|
21 |
#include <eikenv.h>
|
|
22 |
#include <e32base.h>
|
|
23 |
|
|
24 |
#include "bsengineglobals.h"
|
|
25 |
#include "bsdebug.h"
|
|
26 |
#include "bsengine.h"
|
|
27 |
#include "bsapplicationinfo.h"
|
|
28 |
#include "bsconfiguration.h"
|
|
29 |
|
|
30 |
// CONSTANTS
|
|
31 |
const TInt KSecondTaskIndex( 1);
|
|
32 |
|
|
33 |
// ================= MEMBER FUNCTIONS =======================
|
|
34 |
|
|
35 |
// -----------------------------------------------------------------------------
|
|
36 |
// C++ default constructor can NOT contain any code, that might leave.
|
|
37 |
// -----------------------------------------------------------------------------
|
|
38 |
//
|
|
39 |
CBSEngine::CBSEngine()
|
|
40 |
{
|
|
41 |
iEnv = CEikonEnv::Static( );
|
|
42 |
iSwap = EFalse;
|
|
43 |
}
|
|
44 |
|
|
45 |
// -----------------------------------------------------------------------------
|
|
46 |
// Symbian 2nd phase constructor can leave.
|
|
47 |
// -----------------------------------------------------------------------------
|
|
48 |
//
|
|
49 |
void CBSEngine::ConstructL()
|
|
50 |
{
|
|
51 |
DEBUG(("Create Engine"));
|
|
52 |
iConfiguration = CBSConfiguration::NewL( );
|
|
53 |
}
|
|
54 |
|
|
55 |
// -----------------------------------------------------------------------------
|
|
56 |
// Destructor.
|
|
57 |
// -----------------------------------------------------------------------------
|
|
58 |
//
|
|
59 |
CBSEngine::~CBSEngine()
|
|
60 |
{
|
|
61 |
DEBUG(("~CBSEngine"));
|
|
62 |
iAppsStack.ResetAndDestroy( );
|
|
63 |
iFocusHistory.Close( );
|
|
64 |
|
|
65 |
delete iConfiguration;
|
|
66 |
}
|
|
67 |
|
|
68 |
// -----------------------------------------------------------------------------
|
|
69 |
// Two-phased constructor.
|
|
70 |
// -----------------------------------------------------------------------------
|
|
71 |
//
|
|
72 |
CBSEngine* CBSEngine::NewL()
|
|
73 |
{
|
|
74 |
CBSEngine* self = CBSEngine::NewLC( );
|
|
75 |
CleanupStack::Pop( self ) ;
|
|
76 |
return self;
|
|
77 |
}
|
|
78 |
|
|
79 |
// -----------------------------------------------------------------------------
|
|
80 |
// Two-phased constructor.
|
|
81 |
// -----------------------------------------------------------------------------
|
|
82 |
//
|
|
83 |
CBSEngine* CBSEngine::NewLC()
|
|
84 |
{
|
|
85 |
CBSEngine* self = new ( ELeave ) CBSEngine();
|
|
86 |
CleanupStack::PushL( self );
|
|
87 |
self->ConstructL( ) ;
|
|
88 |
return self;
|
|
89 |
}
|
|
90 |
|
|
91 |
// -----------------------------------------------------------------------------
|
|
92 |
//
|
|
93 |
// -----------------------------------------------------------------------------
|
|
94 |
//
|
|
95 |
void CBSEngine::HandleFocusChangeL( const TUid& aApp )
|
|
96 |
{
|
|
97 |
DEBUG(("-> HandleFocusChangeL(0x%X)", aApp.iUid ));
|
|
98 |
// check if application is not in ignored list
|
|
99 |
if ( iConfiguration->IsIgnored( aApp ) )
|
|
100 |
{
|
|
101 |
DEBUG(("\tIgnore the event - application in ignored list"));
|
|
102 |
return;
|
|
103 |
}
|
|
104 |
|
|
105 |
TInt fsCount = iFocusHistory.Count( );
|
|
106 |
if ( fsCount > 0 && iFocusHistory[fsCount - 1] == aApp.iUid )
|
|
107 |
{
|
|
108 |
DEBUG(("\tIgnore the event - application already on top"));
|
|
109 |
iSwap = EFalse;
|
|
110 |
return;
|
|
111 |
}
|
|
112 |
|
|
113 |
// check if we should not reset back stepping stack
|
|
114 |
if ( iConfiguration->IsReset( aApp ) )
|
|
115 |
{
|
|
116 |
iSwap = EFalse;
|
|
117 |
ResetHistory( );
|
|
118 |
}
|
|
119 |
|
|
120 |
// check if we should reset if application was started tru
|
|
121 |
RArray<TInt>& thuApps = iConfiguration->ResetIfThruList( );
|
|
122 |
|
|
123 |
for ( TInt i = 0; i < thuApps.Count( ); i++ )
|
|
124 |
{
|
|
125 |
// position of application - i.e. fast swap
|
|
126 |
if ( aApp.iUid == thuApps[i] )
|
|
127 |
{
|
|
128 |
//mark that there is a fast swap or dialog
|
|
129 |
iSwap = ETrue;
|
|
130 |
return;
|
|
131 |
}
|
|
132 |
else if( iSwap )
|
|
133 |
{
|
|
134 |
iSwap = EFalse;
|
|
135 |
|
|
136 |
TInt pos = iFocusHistory.Count( ) - 1;
|
|
137 |
if ( pos >= 0 )
|
|
138 |
{
|
|
139 |
TInt currentApp = aApp.iUid;
|
|
140 |
TInt prevApp = iFocusHistory[pos];
|
|
141 |
if ( currentApp != prevApp )
|
|
142 |
{
|
|
143 |
//we are here as the result of the fast swap
|
|
144 |
ResetHistory( );
|
|
145 |
iFocusHistory.AppendL( thuApps[i] );
|
|
146 |
break;
|
|
147 |
}
|
|
148 |
}
|
|
149 |
}
|
|
150 |
}
|
|
151 |
// add application to focus history list,
|
|
152 |
iFocusHistory.AppendL( aApp.iUid );
|
|
153 |
}
|
|
154 |
|
|
155 |
// -----------------------------------------------------------------------------
|
|
156 |
//
|
|
157 |
// -----------------------------------------------------------------------------
|
|
158 |
//
|
|
159 |
TInt CBSEngine::HandleActivationEventL( const TUid& aApp,
|
|
160 |
const TDesC8& aState, TBool aItem )
|
|
161 |
{
|
|
162 |
DEBUG(("-> HandleActivationEventL(0x%X, %S, 0x%X)",
|
|
163 |
aApp.iUid, &aState, aItem));
|
|
164 |
TInt result(EBSEngineCommandWasNotConsumed);
|
|
165 |
|
|
166 |
#ifdef _DEBUG
|
|
167 |
// check from which application it was started
|
|
168 |
for ( TInt i = 0; i< iFocusHistory.Count( ); i++ )
|
|
169 |
{
|
|
170 |
DEBUG(("\tiFocusHistory[%d] = %X)", i, iFocusHistory[i]));
|
|
171 |
}
|
|
172 |
#endif
|
|
173 |
|
|
174 |
// is it the same application - i.e. internal state change - ignore
|
|
175 |
CBSApplicationInfo* last(NULL);
|
|
176 |
if ( iAppsStack.Count( ) )
|
|
177 |
last = iAppsStack[iAppsStack.Count() - 1];
|
|
178 |
|
|
179 |
if ( last && last->AppUid( ) == aApp )
|
|
180 |
{
|
|
181 |
DEBUG(("\tIgnore the event, application is already on stack"));
|
|
182 |
}
|
|
183 |
else if ( aItem ) // store only item events
|
|
184 |
{
|
|
185 |
CBSApplicationInfo* newApp = CBSApplicationInfo::NewLC();
|
|
186 |
newApp->SetPrevAppUid( FindPreviousApp( aApp ) );
|
|
187 |
newApp->SetAppUid( aApp );
|
|
188 |
newApp->SetItemStateL( aState );
|
|
189 |
|
|
190 |
DEBUG(("\tAdd to BS stack app:0x%X, state:%S, prevapp:0x%X)",
|
|
191 |
newApp->AppUid().iUid,
|
|
192 |
&newApp->ItemState(),
|
|
193 |
newApp->PrevAppUid().iUid));
|
|
194 |
iAppsStack.AppendL( newApp );
|
|
195 |
CleanupStack::Pop( newApp );
|
|
196 |
result = EBSEngineCommandWasConsumed;
|
|
197 |
}
|
|
198 |
|
|
199 |
return result;
|
|
200 |
}
|
|
201 |
|
|
202 |
// -----------------------------------------------------------------------------
|
|
203 |
//
|
|
204 |
// -----------------------------------------------------------------------------
|
|
205 |
//
|
|
206 |
TInt CBSEngine::HandleBackEventL( const TUid& aApp, const TDesC8& aState,
|
|
207 |
TBool aCheckOnly )
|
|
208 |
{
|
|
209 |
DEBUG(("-> HandleBackEventL(0x%X, %S, 0x%X )",
|
|
210 |
aApp.iUid, &aState, aCheckOnly ));
|
|
211 |
TInt result(EBSEngineCommandWasNotConsumed);
|
|
212 |
// get last application at stack
|
|
213 |
CBSApplicationInfo* info(NULL);
|
|
214 |
if ( iAppsStack.Count( ) )
|
|
215 |
{
|
|
216 |
info = iAppsStack[iAppsStack.Count() - 1];
|
|
217 |
|
|
218 |
DEBUG(("\tcheck UIDs (0x%X-0x%X)", aApp.iUid, info->AppUid() ));
|
|
219 |
DEBUG(("\tcheck states (%S-%S)", &aState, &info->ItemState()));
|
|
220 |
if ( info && info->AppUid( ) == aApp && info->ItemState().Compare( aState ) == 0 )
|
|
221 |
{
|
|
222 |
DEBUG(("\tcheck prev app, if BS to be ignored = %d)",
|
|
223 |
iConfiguration->IsIgnoredIfStartedFrom( info->PrevAppUid() ) ));
|
|
224 |
|
|
225 |
// check what application activated the application in question
|
|
226 |
if ( !iConfiguration->IsIgnoredIfStartedFrom( info->PrevAppUid( ) ) )
|
|
227 |
{
|
|
228 |
// find the task which is directly below the current one
|
|
229 |
// in window group Z-order hierarchy
|
|
230 |
TApaTaskList taskList(iEnv->WsSession( ) );
|
|
231 |
// current task is in "0" position, next one is "1"
|
|
232 |
// NOTE: FindByPos doesn't return hidden tasks
|
|
233 |
TApaTask lowerTask = taskList.FindByPos( KSecondTaskIndex );
|
|
234 |
CApaWindowGroupName* apaWGName = CApaWindowGroupName::NewLC(
|
|
235 |
iEnv->WsSession( ), lowerTask.WgId( ) );
|
|
236 |
TUid lowerTaskUid = apaWGName->AppUid( );
|
|
237 |
CleanupStack::PopAndDestroy( apaWGName );
|
|
238 |
|
|
239 |
DEBUG(("\tcheck task below (0x%X-0x%X)",
|
|
240 |
lowerTaskUid.iUid, info->PrevAppUid().iUid));
|
|
241 |
// if the lower task is the one that activated the current one
|
|
242 |
// send the current one to background.
|
|
243 |
// the condition is false if i.e. the previous active task
|
|
244 |
// has been closed or sent to background (no explicit
|
|
245 |
// activation of the current task occured)
|
|
246 |
if ( lowerTaskUid == info->PrevAppUid( ) )
|
|
247 |
{
|
|
248 |
if ( !aCheckOnly )
|
|
249 |
{
|
|
250 |
SendToBackground( aApp );
|
|
251 |
// remove history for the application
|
|
252 |
RemoveAppRecord( aApp );
|
|
253 |
}
|
|
254 |
result = EBSEngineCommandWasConsumed;
|
|
255 |
}
|
|
256 |
}
|
|
257 |
}
|
|
258 |
}
|
|
259 |
return result;
|
|
260 |
}
|
|
261 |
|
|
262 |
// -----------------------------------------------------------------------------
|
|
263 |
//
|
|
264 |
// -----------------------------------------------------------------------------
|
|
265 |
//
|
|
266 |
void CBSEngine::SendToBackground( const TUid& aApp )
|
|
267 |
{
|
|
268 |
DEBUG(("-> SendToBackgroundL(0x%X)", aApp.iUid ));
|
|
269 |
|
|
270 |
TApaTaskList taskList(iEnv->WsSession( ));
|
|
271 |
|
|
272 |
TApaTask task = taskList.FindApp( aApp );
|
|
273 |
if ( task.Exists( ) )
|
|
274 |
{
|
|
275 |
// Request window server to send application to background
|
|
276 |
task.SendToBackground( );
|
|
277 |
}
|
|
278 |
}
|
|
279 |
|
|
280 |
// -----------------------------------------------------------------------------
|
|
281 |
//
|
|
282 |
// -----------------------------------------------------------------------------
|
|
283 |
//
|
|
284 |
TUid CBSEngine::FindPreviousApp( const TUid& aApp )
|
|
285 |
{
|
|
286 |
TUid result(TUid::Null( ));
|
|
287 |
|
|
288 |
for ( TInt i = iFocusHistory.Count( ) - 1; i >= 0; i-- )
|
|
289 |
{
|
|
290 |
if ( iFocusHistory[i] != aApp.iUid )
|
|
291 |
{
|
|
292 |
result = TUid::Uid( iFocusHistory[i] );
|
|
293 |
break;
|
|
294 |
}
|
|
295 |
}
|
|
296 |
|
|
297 |
return result;
|
|
298 |
}
|
|
299 |
|
|
300 |
// -----------------------------------------------------------------------------
|
|
301 |
//
|
|
302 |
// -----------------------------------------------------------------------------
|
|
303 |
//
|
|
304 |
void CBSEngine::RemoveAppRecord( const TUid& aApp )
|
|
305 |
{
|
|
306 |
DEBUG(("-> RemoveRecord(0x%X)", aApp.iUid ));
|
|
307 |
|
|
308 |
for ( TInt i = iAppsStack.Count( ) - 1; i >= 0; i-- )
|
|
309 |
{
|
|
310 |
CBSApplicationInfo* info = iAppsStack[i];
|
|
311 |
if ( info->AppUid( ) == aApp )
|
|
312 |
{
|
|
313 |
DEBUG(("\tRemove item - [%d]", i));
|
|
314 |
iAppsStack.Remove( i );
|
|
315 |
delete info;
|
|
316 |
break;
|
|
317 |
}
|
|
318 |
}
|
|
319 |
}
|
|
320 |
|
|
321 |
// -----------------------------------------------------------------------------
|
|
322 |
//
|
|
323 |
// -----------------------------------------------------------------------------
|
|
324 |
//
|
|
325 |
void CBSEngine::ResetHistory()
|
|
326 |
{
|
|
327 |
DEBUG(("-> ResetHistory"));
|
|
328 |
iAppsStack.ResetAndDestroy( );
|
|
329 |
iFocusHistory.Reset( );
|
|
330 |
}
|
|
331 |
|
|
332 |
// End of File
|
|
333 |
|
|
334 |
|