1 /* |
|
2 * Copyright (c) 2009 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: cadrmscanner.mmp |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <apgwgnam.h> |
|
19 |
|
20 #include "carunningappmonitor.h" |
|
21 #include "cadef.h" |
|
22 #include "castoragetask.h" |
|
23 #include "cainnerquery.h" |
|
24 #include "cainnerentry.h" |
|
25 #include "caarraycleanup.inl" |
|
26 #include "castorageproxy.h" |
|
27 |
|
28 const TInt KRunningAppGranularity(10); |
|
29 // ----------------------------------------------------------------------------- |
|
30 // ExecuteL |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 void CCaRunningAppMonitor::ExecuteL( MCaRunningTaskHandler& aTaskHandler, |
|
34 CCaStorageProxy& aStorage ) |
|
35 { |
|
36 CCaRunningAppMonitor* self = |
|
37 new (ELeave)CCaRunningAppMonitor( aTaskHandler, aStorage ); |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop( self ); |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // ~CCaRunningAppMonitor |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CCaRunningAppMonitor::~CCaRunningAppMonitor() |
|
48 { |
|
49 Cancel(); |
|
50 iWg.Close(); |
|
51 iSession.Close(); |
|
52 iRunningTasks.Close(); |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CCaRunningAppMonitor |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CCaRunningAppMonitor::CCaRunningAppMonitor( MCaRunningTaskHandler& aTaskHandler, |
|
60 CCaStorageProxy& aStorage ) |
|
61 : |
|
62 CActive( EPriorityStandard ), |
|
63 iTaskHandler( aTaskHandler ), |
|
64 iStorage( aStorage ) |
|
65 { |
|
66 CActiveScheduler::Add( this ); |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // ConstructL |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 void CCaRunningAppMonitor::ConstructL() |
|
74 { |
|
75 //Create window server observer |
|
76 ConstractObserverL(); |
|
77 |
|
78 //start listen |
|
79 Subscribe(); |
|
80 |
|
81 //At plugin start mark all entry as "not running" |
|
82 ResetStorageL(); |
|
83 |
|
84 iTaskHandler.RegisterTaskL(this);//this operation has to be as a last one |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // UpdateRunningAppStorageL |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 void CCaRunningAppMonitor::UpdateRunningAppStorageL() |
|
92 { |
|
93 RArray<RWsSession::TWindowGroupChainInfo> |
|
94 windowGroupIds(KRunningAppGranularity, |
|
95 _FOFF( RWsSession::TWindowGroupChainInfo, iId )); |
|
96 CleanupClosePushL( windowGroupIds ); |
|
97 User::LeaveIfError( iSession.WindowGroupList( 0, &windowGroupIds ) ); |
|
98 TInt itemIndex( KErrNotFound ); |
|
99 |
|
100 //Verify what apps has stopped |
|
101 THashMapIter<TInt, TUid> iterator( iRunningTasks ); |
|
102 RWsSession::TWindowGroupChainInfo item = { KErrNotFound, KErrNotFound }; |
|
103 while( 0 != iterator.NextKey() ) |
|
104 { |
|
105 item.iId = *iterator.CurrentKey(); |
|
106 itemIndex = windowGroupIds.Find(item); |
|
107 if(KErrNotFound == itemIndex) |
|
108 { |
|
109 //push new task to register application update in storage |
|
110 CCaStorageTask::ExecuteL( iTaskHandler, |
|
111 iStorage, |
|
112 *iterator.CurrentValue(), |
|
113 KErrNotFound ); |
|
114 iterator.RemoveCurrent(); |
|
115 } |
|
116 else |
|
117 { |
|
118 //application is already registered. |
|
119 //remove entry to skip its processing |
|
120 windowGroupIds.Remove( itemIndex ); |
|
121 } |
|
122 } |
|
123 |
|
124 //Verify what apps has started |
|
125 const TInt count(windowGroupIds.Count()); |
|
126 for(TInt iter(0); iter < count; ++iter) |
|
127 { |
|
128 if( 0 >= windowGroupIds[iter].iParentId ) |
|
129 { |
|
130 //push new task to register application update in storage and |
|
131 //register it running task list |
|
132 CApaWindowGroupName* name = |
|
133 CApaWindowGroupName::NewLC( iSession, windowGroupIds[iter].iId); |
|
134 if( 0 != name->AppUid().iUid ) |
|
135 { |
|
136 CCaStorageTask::ExecuteL( iTaskHandler, |
|
137 iStorage, |
|
138 name->AppUid(), |
|
139 windowGroupIds[iter].iId ); |
|
140 iRunningTasks.Insert( windowGroupIds[iter].iId, |
|
141 name->AppUid() ); |
|
142 } |
|
143 CleanupStack::PopAndDestroy( name ); |
|
144 } |
|
145 } |
|
146 CleanupStack::PopAndDestroy( &windowGroupIds ); |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // Subscribe |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 void CCaRunningAppMonitor::Subscribe() |
|
154 { |
|
155 if( !IsActive() ) |
|
156 { |
|
157 iSession.EventReady( &iStatus ); |
|
158 SetActive(); |
|
159 } |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // ConstractObserverL |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 void CCaRunningAppMonitor::ConstractObserverL() |
|
167 { |
|
168 User::LeaveIfError( iSession.Connect() ); |
|
169 iWg = RWindowGroup( iSession ); |
|
170 User::LeaveIfError( iWg.Construct( |
|
171 reinterpret_cast<TUint32>( &iWg ) ) ); |
|
172 iWg.DisableFocusChangeEvents(); |
|
173 iWg.DisableModifierChangedEvents(); |
|
174 iWg.DisableOnEvents(); |
|
175 iWg.DisableScreenChangeEvents(); |
|
176 |
|
177 //enable notifications about group lists |
|
178 User::LeaveIfError( iWg.EnableGroupListChangeEvents() ); |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // ResetStorageL |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 void CCaRunningAppMonitor::ResetStorageL() |
|
186 { |
|
187 CCaInnerQuery* allAppQuery = CCaInnerQuery::NewLC(); |
|
188 allAppQuery->SetFlagsOn( ERunning ); |
|
189 RPointerArray<CCaInnerEntry> entries; |
|
190 CleanupResetAndDestroyPushL( entries ); |
|
191 iStorage.GetEntriesL( allAppQuery, entries ); |
|
192 for( TInt i(0); i < entries.Count(); ++i ) |
|
193 { |
|
194 CCaStorageTask::ExecuteL( iTaskHandler, |
|
195 iStorage, |
|
196 TUid::Uid(entries[i]->GetUid()), |
|
197 KErrNotFound ); |
|
198 } |
|
199 CleanupStack::PopAndDestroy(&entries); |
|
200 CleanupStack::PopAndDestroy(allAppQuery); |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // RunL |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 void CCaRunningAppMonitor::RunL() |
|
208 { |
|
209 User::LeaveIfError( iStatus.Int() ); |
|
210 TWsEvent event; |
|
211 iSession.GetEvent( event ); |
|
212 Subscribe();//new subscribtion has to be called after picking event |
|
213 if( EEventWindowGroupListChanged == event.Type() ) |
|
214 { |
|
215 UpdateRunningAppStorageL(); |
|
216 } |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // RunError |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 TInt CCaRunningAppMonitor::RunError( TInt /*aError*/ ) |
|
224 { |
|
225 //ignore error |
|
226 Subscribe(); |
|
227 return KErrNone; |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // DoCancel |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 void CCaRunningAppMonitor::DoCancel() |
|
235 { |
|
236 if( IsActive() ) |
|
237 { |
|
238 iSession.EventReadyCancel(); |
|
239 } |
|
240 } |
|