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